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-09-27 21:38:47 +00:00
|
|
|
void hop_add_reg_insel(struct hop* hop, struct hop* reg)
|
2016-09-26 22:19:45 +00:00
|
|
|
{
|
2016-09-27 21:38:47 +00:00
|
|
|
struct insel* insel = new_insel(INSEL_REG);
|
|
|
|
insel->u.reg = reg;
|
|
|
|
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-09-27 21:38:47 +00:00
|
|
|
int i;
|
|
|
|
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-09-27 21:38:47 +00:00
|
|
|
tracef(k, "%c: %d: ", k, hop->id);
|
|
|
|
soi = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (insel->type)
|
|
|
|
{
|
|
|
|
case INSEL_EOI:
|
|
|
|
tracef(k, "\n");
|
|
|
|
soi = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INSEL_REG:
|
|
|
|
tracef(k, "%%%d", insel->u.reg->id);
|
|
|
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|