2016-09-25 21:29:59 +00:00
|
|
|
#include "mcg.h"
|
|
|
|
|
2016-09-27 21:38:47 +00:00
|
|
|
static int hop_count = 1;
|
2016-09-26 22:19:45 +00:00
|
|
|
static struct hop* current_hop;
|
|
|
|
|
|
|
|
static const struct burm_emitter_data emitter_data;
|
|
|
|
|
2016-09-25 21:29:59 +00:00
|
|
|
struct hop* new_hop(int insn_no, struct ir* ir)
|
|
|
|
{
|
|
|
|
struct hop* hop = calloc(1, sizeof *hop);
|
2016-09-27 21:38:47 +00:00
|
|
|
hop->id = hop_count++;
|
2016-09-25 21:29:59 +00:00
|
|
|
hop->insn_no = insn_no;
|
|
|
|
hop->ir = ir;
|
2016-09-26 22:19:45 +00:00
|
|
|
return hop;
|
2016-09-25 21:29:59 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 21:38:47 +00:00
|
|
|
static struct insel* new_insel(enum insel_type type)
|
2016-09-25 21:29:59 +00:00
|
|
|
{
|
2016-09-27 21:38:47 +00:00
|
|
|
struct insel* insel = calloc(1, sizeof(*insel));
|
|
|
|
insel->type = type;
|
|
|
|
return insel;
|
2016-09-26 22:19:45 +00:00
|
|
|
}
|
2016-09-25 21:29:59 +00:00
|
|
|
|
2016-09-27 21:38:47 +00:00
|
|
|
void hop_add_string_insel(struct hop* hop, const char* string)
|
2016-09-26 22:19:45 +00:00
|
|
|
{
|
2016-09-27 21:38:47 +00:00
|
|
|
struct insel* insel = new_insel(INSEL_STRING);
|
|
|
|
insel->u.string = string;
|
|
|
|
array_append(&hop->insels, insel);
|
2016-09-26 22:19:45 +00:00
|
|
|
}
|
2016-09-25 21:29:59 +00:00
|
|
|
|
2016-10-02 21:25:54 +00:00
|
|
|
void hop_add_vreg_insel(struct hop* hop, struct vreg* vreg)
|
2016-09-26 22:19:45 +00:00
|
|
|
{
|
2016-10-02 21:25:54 +00:00
|
|
|
struct insel* insel = new_insel(INSEL_VREG);
|
|
|
|
insel->u.vreg = vreg;
|
2016-09-27 21:38:47 +00:00
|
|
|
array_append(&hop->insels, insel);
|
2016-09-25 21:29:59 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 21:38:47 +00:00
|
|
|
void hop_add_value_insel(struct hop* hop, struct ir* ir)
|
2016-09-25 21:29:59 +00:00
|
|
|
{
|
2016-09-27 21:38:47 +00:00
|
|
|
struct insel* insel = new_insel(INSEL_VALUE);
|
|
|
|
insel->u.value = ir;
|
|
|
|
array_append(&hop->insels, insel);
|
2016-09-25 21:29:59 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 21:38:47 +00:00
|
|
|
void hop_add_eoi_insel(struct hop* hop)
|
2016-09-25 21:29:59 +00:00
|
|
|
{
|
2016-09-27 21:38:47 +00:00
|
|
|
struct insel* insel = new_insel(INSEL_EOI);
|
|
|
|
array_append(&hop->insels, insel);
|
2016-09-25 21:29:59 +00:00
|
|
|
}
|
|
|
|
|
2016-09-26 22:19:45 +00:00
|
|
|
void hop_print(char k, struct hop* hop)
|
|
|
|
{
|
2016-10-05 20:56:25 +00:00
|
|
|
int i, j;
|
2016-09-27 21:38:47 +00:00
|
|
|
bool soi = true;
|
2016-09-26 22:19:45 +00:00
|
|
|
|
2016-09-27 21:38:47 +00:00
|
|
|
i = 0;
|
|
|
|
for (i=0; i<hop->insels.count; i++)
|
2016-09-26 22:19:45 +00:00
|
|
|
{
|
2016-09-27 21:38:47 +00:00
|
|
|
struct insel* insel = hop->insels.item[i];
|
2016-09-26 22:19:45 +00:00
|
|
|
|
2016-09-27 21:38:47 +00:00
|
|
|
if (soi)
|
2016-09-26 22:19:45 +00:00
|
|
|
{
|
2016-10-05 20:56:25 +00:00
|
|
|
tracef(k, "%c: %d from $%d:", k, hop->id, hop->ir->id);
|
|
|
|
|
|
|
|
for (j=0; j<hop->ins.count; j++)
|
|
|
|
tracef(k, " <%%%d", hop->ins.item[j]->id);
|
|
|
|
for (j=0; j<hop->outs.count; j++)
|
|
|
|
tracef(k, " >%%%d", hop->outs.item[j]->id);
|
|
|
|
tracef(k, " ");
|
|
|
|
|
2016-09-27 21:38:47 +00:00
|
|
|
soi = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (insel->type)
|
|
|
|
{
|
|
|
|
case INSEL_EOI:
|
|
|
|
tracef(k, "\n");
|
|
|
|
soi = true;
|
|
|
|
break;
|
|
|
|
|
2016-10-02 21:25:54 +00:00
|
|
|
case INSEL_VREG:
|
|
|
|
tracef(k, "%%%d", insel->u.vreg->id);
|
2016-09-27 21:38:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case INSEL_STRING:
|
|
|
|
tracef(k, "%s", insel->u.string);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INSEL_VALUE:
|
|
|
|
{
|
|
|
|
struct ir* ir = insel->u.value;
|
|
|
|
switch (ir->opcode)
|
|
|
|
{
|
|
|
|
case IR_BLOCK:
|
|
|
|
tracef(k, "%s", ir->u.bvalue->name);
|
|
|
|
break;
|
|
|
|
|
2016-10-01 11:56:52 +00:00
|
|
|
case IR_LABEL:
|
|
|
|
tracef(k, "%s", ir->u.lvalue);
|
|
|
|
break;
|
|
|
|
|
2016-09-27 21:38:47 +00:00
|
|
|
case IR_LOCAL:
|
|
|
|
case IR_CONST:
|
|
|
|
tracef(k, "0x%d", ir->u.ivalue);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-09-26 22:19:45 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-27 21:38:47 +00:00
|
|
|
|
|
|
|
if (!soi)
|
|
|
|
tracef(k, "\n", k);
|
2016-09-25 21:29:59 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 19:07:29 +00:00
|
|
|
/* vim: set sw=4 ts=4 expandtab : */
|
|
|
|
|