#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "ast.h"
#include "ssa.h"
#define NEW(type) ((type *)malloc(sizeof(type)))
#define DBLINK(from, to) ((from)->next = (to))->prev = (from)
static CGraph cfg, dtree;
static CBlock_t blks[MAX_BLOCK];
static int bcnt; /* block counter */
static int tcnt; /* temporary counter */
static int gbbase;
CBlock_t cblock_create(int inc) {
CBlock_t cblk = NEW(CBlock);
CInst_t dum = NEW(CInst);
CPhi_t pdum = NEW(CPhi);
dum->prev = dum;
dum->next = dum;
pdum->prev = pdum;
pdum->next = pdum;
cblk->insts = dum;
cblk->phis = pdum;
cblk->next = NULL;
if (inc)
cblk->id = bcnt++;
cblk->ref = 0;
return cblk;
}
void cblock_append(CBlock_t cblk, CInst_t inst) {
CInst_t head = cblk->insts;
(inst->prev = head->prev)->next = inst;
(inst->next = head)->prev = inst;
}
void cblock_pushfront(CBlock_t cblk, CInst_t inst) {
CInst_t head = cblk->insts;
(inst->next = head->next)->prev = inst;
(inst->prev = head)->next = inst;
}
void cblock_pappend(CBlock_t cblk, CPhi_t phi) {
CPhi_t head = cblk->phis;
(phi->prev = head->prev)->next = phi;
(phi->next = head)->prev = phi;
}
void cblock_popback(CBlock_t cblk) {
CInst_t last = cblk->insts->prev;
last->next->prev = last->prev;
last->prev->next = last->next;
}
void cblock_popfront(CBlock_t cblk) {
CInst_t first = cblk->insts->next;
first->next->prev = first->prev;
first->prev->next = first->next;
}
CInst_t cblock_getback(CBlock_t cblk) {
CInst_t res = cblk->insts->prev;
return res != cblk->insts ? res : NULL;
}
int cblock_isempty(CBlock_t