#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