#include <stdio.h>
#include <assert.h>
#include <string.h>
#include "ast.h"
#include "ssa.h"
#include "mips.h"
int reg_v0 = 2;
int reg_v1 = 3;
void mips_prologue() {
CVList_t v;
CSList_t s;
printf(".data 0x10000000\n");
for (v = gvars; v; v = v->next)
{
CVar_t var = v->var;
printf("\t.align 2\n");
printf("_%s:\n", var->name);
var->start = -1;
if (var->initr)
{
CNode *initr = var->initr->chd;
assert(var->initr->rec.subtype == INITR_NORM);
switch (initr->ext.type->type)
{
case CINT:
printf("\t.word %d\n", initr->ext.const_val);
break;
case CCHAR:
printf("\t.byte %d\n", initr->ext.const_val);
break;
case CPTR:
{
CType_t ref = initr->ext.type->rec.ref;
printf("\t.word ");
switch (ref->type)
{
case CFUNC:
printf("%s\n", initr->rec.strval);
break;
case CCHAR:
printf("_str_%d\n", ((CSList_t)initr->ext.const_val)->id);
break;
default: assert(0);
}
}
break;
default: assert(0);
}
}
else
printf("\t.space %d\n", calc_size(var->type));
}
for (s = cstrs; s; s = s->next)
{
printf("_str_%d:\n", s->id);
printf("\t.asciiz \"%s\"\n", s->str);
}
/* pre-calc done */
printf(".text\n");
}
void mips_load(int reg, COpr_t opr) {
CVar_t var = cinterv_repr(opr)->info.var;
CType_t type = opr->type;
if (type->type == CSTRUCT ||
type->type == CUNION ||
type->type == CARR)
{
if (var->global)
printf("\tla $%d, _%s\n", reg, var->name);
else
printf("\taddi $%d, $sp, %d\n", reg, var->start);
}
else
{
const char