Rename struct insn to struct em (throughout).

This commit is contained in:
David Given 2016-09-25 12:29:03 +02:00
parent bcc74ba18d
commit 67eb21d428
3 changed files with 100 additions and 100 deletions

View file

@ -50,7 +50,7 @@ enum
PARAM_BVALUE, PARAM_BVALUE,
}; };
struct insn struct em
{ {
int opcode; int opcode;
int paramtype; int paramtype;
@ -78,7 +78,7 @@ struct procedure
struct basicblock struct basicblock
{ {
const char* name; const char* name;
ARRAY(struct insn, insns); ARRAY(struct em, ems);
ARRAY(struct ir, irs); ARRAY(struct ir, irs);
bool is_fake : 1; bool is_fake : 1;
bool is_root : 1; bool is_root : 1;

View file

@ -1,6 +1,6 @@
#include "mcg.h" #include "mcg.h"
static struct e_instr insn; static struct e_instr em;
static struct procedure* current_proc; static struct procedure* current_proc;
static struct basicblock* code_bb; static struct basicblock* code_bb;
static struct basicblock* data_bb; static struct basicblock* data_bb;
@ -46,7 +46,7 @@ static void unknown_type(const char* s)
{ {
fatal("%s with unknown type '%s'", fatal("%s with unknown type '%s'",
s, s,
argtype_to_str(insn.em_arg.ema_argtype)); argtype_to_str(em.em_arg.ema_argtype));
} }
static const char* ilabel_to_str(label l) static const char* ilabel_to_str(label l)
@ -66,18 +66,18 @@ static void terminate_block(void)
code_bb = NULL; code_bb = NULL;
} }
static struct insn* new_insn(int opcode) static struct em* new_insn(int opcode)
{ {
struct insn* insn = calloc(sizeof(struct insn), 1); struct em* em = calloc(sizeof(struct em), 1);
insn->opcode = opcode; em->opcode = opcode;
return insn; return em;
} }
static void queue_insn_simple(int opcode) static void queue_insn_simple(int opcode)
{ {
struct insn* insn = new_insn(opcode); struct em* em = new_insn(opcode);
insn->paramtype = PARAM_NONE; em->paramtype = PARAM_NONE;
APPEND(code_bb->insns, insn); APPEND(code_bb->ems, em);
switch (opcode) switch (opcode)
{ {
@ -89,10 +89,10 @@ static void queue_insn_simple(int opcode)
static void queue_insn_value(int opcode, arith value) static void queue_insn_value(int opcode, arith value)
{ {
struct insn* insn = new_insn(opcode); struct em* em = new_insn(opcode);
insn->paramtype = PARAM_IVALUE; em->paramtype = PARAM_IVALUE;
insn->u.ivalue = value; em->u.ivalue = value;
APPEND(code_bb->insns, insn); APPEND(code_bb->ems, em);
switch (opcode) switch (opcode)
{ {
@ -106,11 +106,11 @@ static void queue_insn_value(int opcode, arith value)
static void queue_insn_label(int opcode, const char* label, arith offset) static void queue_insn_label(int opcode, const char* label, arith offset)
{ {
struct insn* insn = new_insn(opcode); struct em* em = new_insn(opcode);
insn->paramtype = PARAM_LVALUE; em->paramtype = PARAM_LVALUE;
insn->u.lvalue.label = label; em->u.lvalue.label = label;
insn->u.lvalue.offset = offset; em->u.lvalue.offset = offset;
APPEND(code_bb->insns, insn); APPEND(code_bb->ems, em);
switch (opcode) switch (opcode)
{ {
@ -122,11 +122,11 @@ static void queue_insn_label(int opcode, const char* label, arith offset)
static void queue_insn_block(int opcode, struct basicblock* left, struct basicblock* right) static void queue_insn_block(int opcode, struct basicblock* left, struct basicblock* right)
{ {
struct insn* insn = new_insn(opcode); struct em* em = new_insn(opcode);
insn->paramtype = PARAM_BVALUE; em->paramtype = PARAM_BVALUE;
insn->u.bvalue.left = left; em->u.bvalue.left = left;
insn->u.bvalue.right = right; em->u.bvalue.right = right;
APPEND(code_bb->insns, insn); APPEND(code_bb->ems, em);
terminate_block(); terminate_block();
} }
@ -143,13 +143,13 @@ static void change_basicblock(struct basicblock* newbb)
static void queue_insn_ilabel(int opcode, int label) static void queue_insn_ilabel(int opcode, int label)
{ {
const char* name = ilabel_to_str(insn.em_ilb); const char* name = ilabel_to_str(em.em_ilb);
struct basicblock* left = bb_get(name); struct basicblock* left = bb_get(name);
switch (opcode) switch (opcode)
{ {
case op_bra: case op_bra:
queue_insn_block(insn.em_opcode, left, NULL); queue_insn_block(em.em_opcode, left, NULL);
break; break;
case op_zeq: case op_zeq:
@ -160,7 +160,7 @@ static void queue_insn_ilabel(int opcode, int label)
case op_zge: case op_zge:
{ {
struct basicblock* bb = bb_get(NULL); struct basicblock* bb = bb_get(NULL);
queue_insn_block(insn.em_opcode, left, bb); queue_insn_block(em.em_opcode, left, bb);
change_basicblock(bb); change_basicblock(bb);
break; break;
} }
@ -178,30 +178,30 @@ static void queue_ilabel(arith label)
static void parse_pseu(void) static void parse_pseu(void)
{ {
switch (insn.em_opcode) switch (em.em_opcode)
{ {
case ps_exp: /* external proc */ case ps_exp: /* external proc */
case ps_exa: /* external array */ case ps_exa: /* external array */
case ps_inp: /* internal proc */ case ps_inp: /* internal proc */
case ps_ina: /* internal array */ case ps_ina: /* internal array */
{ {
bool export = (insn.em_opcode == ps_exp) || (insn.em_opcode == ps_exa); bool export = (em.em_opcode == ps_exp) || (em.em_opcode == ps_exa);
bool proc = (insn.em_opcode == ps_exp) || (insn.em_opcode == ps_inp); bool proc = (em.em_opcode == ps_exp) || (em.em_opcode == ps_inp);
switch (insn.em_arg.ema_argtype) switch (em.em_arg.ema_argtype)
{ {
case pro_ptyp: case pro_ptyp:
symbol_declare(strdup(insn.em_pnam), export, proc); symbol_declare(strdup(em.em_pnam), export, proc);
break; break;
case sof_ptyp: case sof_ptyp:
assert(insn.em_off == 0); assert(em.em_off == 0);
symbol_declare(strdup(insn.em_dnam), export, proc); symbol_declare(strdup(em.em_dnam), export, proc);
break; break;
case nof_ptyp: case nof_ptyp:
assert(insn.em_off == 0); assert(em.em_off == 0);
symbol_declare(dlabel_to_str(insn.em_dlb), export, proc); symbol_declare(dlabel_to_str(em.em_dlb), export, proc);
break; break;
default: default:
@ -213,33 +213,33 @@ static void parse_pseu(void)
case ps_con: /* .data */ case ps_con: /* .data */
case ps_rom: /* .rom */ case ps_rom: /* .rom */
{ {
bool ro = (insn.em_opcode == ps_rom); bool ro = (em.em_opcode == ps_rom);
switch (insn.em_arg.ema_argtype) switch (em.em_arg.ema_argtype)
{ {
case ico_ptyp: case ico_ptyp:
case uco_ptyp: case uco_ptyp:
{ {
arith val = atol(insn.em_string); arith val = atol(em.em_string);
data_int(val, insn.em_size, ro); data_int(val, em.em_size, ro);
break; break;
} }
case str_ptyp: case str_ptyp:
data_block(strdup(insn.em_string), insn.em_size, ro); data_block(strdup(em.em_string), em.em_size, ro);
break; break;
case cst_ptyp: case cst_ptyp:
data_int(insn.em_cst, EM_wordsize, ro); data_int(em.em_cst, EM_wordsize, ro);
break; break;
case nof_ptyp: case nof_ptyp:
data_offset(dlabel_to_str(insn.em_dlb), insn.em_off, ro); data_offset(dlabel_to_str(em.em_dlb), em.em_off, ro);
break; break;
case ilb_ptyp: case ilb_ptyp:
{ {
const char* label = ilabel_to_str(insn.em_ilb); const char* label = ilabel_to_str(em.em_ilb);
/* This is really hacky; to handle basic block flow /* This is really hacky; to handle basic block flow
* descriptor blocks, we need to track which bbs a descriptor * descriptor blocks, we need to track which bbs a descriptor
@ -249,10 +249,10 @@ static void parse_pseu(void)
if (data_bb) if (data_bb)
{ {
struct insn* insn = new_insn(op_bra); struct em* em = new_insn(op_bra);
insn->paramtype = PARAM_BVALUE; em->paramtype = PARAM_BVALUE;
insn->u.bvalue.left = bb_get(label); em->u.bvalue.left = bb_get(label);
APPEND(data_bb->insns, insn); APPEND(data_bb->ems, em);
} }
data_offset(label, 0, ro); data_offset(label, 0, ro);
@ -267,10 +267,10 @@ static void parse_pseu(void)
case ps_bss: case ps_bss:
{ {
switch (insn.em_arg.ema_argtype) switch (em.em_arg.ema_argtype)
{ {
case cst_ptyp: case cst_ptyp:
data_bss(EM_bsssize, insn.em_cst); data_bss(EM_bsssize, em.em_cst);
break; break;
default: default:
@ -284,9 +284,9 @@ static void parse_pseu(void)
struct symbol* symbol; struct symbol* symbol;
current_proc = calloc(sizeof(struct procedure), 1); current_proc = calloc(sizeof(struct procedure), 1);
current_proc->name = strdup(insn.em_pnam); current_proc->name = strdup(em.em_pnam);
current_proc->root_bb = bb_get(current_proc->name); current_proc->root_bb = bb_get(current_proc->name);
current_proc->nlocals = insn.em_nlocals; current_proc->nlocals = em.em_nlocals;
code_bb = current_proc->root_bb; code_bb = current_proc->root_bb;
code_bb->is_root = true; code_bb->is_root = true;
APPEND(current_proc->blocks, code_bb); APPEND(current_proc->blocks, code_bb);
@ -306,22 +306,22 @@ static void parse_pseu(void)
break; break;
default: default:
fatal("unknown pseudo with opcode %d\n", insn.em_opcode); fatal("unknown pseudo with opcode %d\n", em.em_opcode);
} }
} }
static arith mes_get_cst(void) static arith mes_get_cst(void)
{ {
EM_getinstr(&insn); EM_getinstr(&em);
if (insn.em_type != EM_MESARG) if (em.em_type != EM_MESARG)
fatal("malformed MES"); fatal("malformed MES");
return insn.em_cst; return em.em_cst;
} }
static void parse_mes(void) static void parse_mes(void)
{ {
assert(insn.em_arg.ema_argtype == cst_ptyp); assert(em.em_arg.ema_argtype == cst_ptyp);
switch (insn.em_cst) switch (em.em_cst)
{ {
case 0: /* error */ case 0: /* error */
fatal("MES 0 received (explicit halt)"); fatal("MES 0 received (explicit halt)");
@ -337,10 +337,10 @@ static void parse_mes(void)
} }
} }
while ((insn.em_type == EM_STARTMES) || (insn.em_type == EM_MESARG)) while ((em.em_type == EM_STARTMES) || (em.em_type == EM_MESARG))
EM_getinstr(&insn); EM_getinstr(&em);
if (insn.em_type != EM_ENDMES) if (em.em_type != EM_ENDMES)
fatal("malformed MES"); fatal("malformed MES");
} }
@ -357,27 +357,27 @@ static void create_data_label(const char* label)
void parse_em(void) void parse_em(void)
{ {
EM_getinstr(&insn); EM_getinstr(&em);
tb_filestart(); tb_filestart();
while (insn.em_type != EM_EOF) while (em.em_type != EM_EOF)
{ {
switch (insn.em_type) switch (em.em_type)
{ {
case EM_PSEU: case EM_PSEU:
parse_pseu(); parse_pseu();
break; break;
case EM_DEFILB: case EM_DEFILB:
queue_ilabel(insn.em_ilb); queue_ilabel(em.em_ilb);
break; break;
case EM_DEFDLB: case EM_DEFDLB:
create_data_label(dlabel_to_str(insn.em_dlb)); create_data_label(dlabel_to_str(em.em_dlb));
break; break;
case EM_DEFDNAM: case EM_DEFDNAM:
create_data_label(strdup(insn.em_dnam)); create_data_label(strdup(em.em_dnam));
break; break;
case EM_STARTMES: case EM_STARTMES:
@ -387,36 +387,36 @@ void parse_em(void)
case EM_MNEM: case EM_MNEM:
if (code_bb) if (code_bb)
{ {
int flags = em_flag[insn.em_opcode - sp_fmnem]; int flags = em_flag[em.em_opcode - sp_fmnem];
if (flags & EM_PAR) if (flags & EM_PAR)
{ {
switch (insn.em_argtype) switch (em.em_argtype)
{ {
case ilb_ptyp: case ilb_ptyp:
queue_insn_ilabel(insn.em_opcode, insn.em_ilb); queue_insn_ilabel(em.em_opcode, em.em_ilb);
break; break;
case nof_ptyp: case nof_ptyp:
queue_insn_label(insn.em_opcode, queue_insn_label(em.em_opcode,
dlabel_to_str(insn.em_dlb), insn.em_off); dlabel_to_str(em.em_dlb), em.em_off);
break; break;
case sof_ptyp: case sof_ptyp:
queue_insn_label(insn.em_opcode, queue_insn_label(em.em_opcode,
strdup(insn.em_dnam), insn.em_off); strdup(em.em_dnam), em.em_off);
break; break;
case pro_ptyp: case pro_ptyp:
queue_insn_label(insn.em_opcode, queue_insn_label(em.em_opcode,
strdup(insn.em_pnam), 0); strdup(em.em_pnam), 0);
break; break;
case cst_ptyp: case cst_ptyp:
if ((flags & EM_PAR) == PAR_B) if ((flags & EM_PAR) == PAR_B)
queue_insn_ilabel(insn.em_opcode, insn.em_ilb); queue_insn_ilabel(em.em_opcode, em.em_ilb);
else else
queue_insn_value(insn.em_opcode, insn.em_cst); queue_insn_value(em.em_opcode, em.em_cst);
break; break;
default: default:
@ -424,15 +424,15 @@ void parse_em(void)
} }
} }
else else
queue_insn_simple(insn.em_opcode); queue_insn_simple(em.em_opcode);
} }
break; break;
default: default:
fatal("unrecognised instruction type '%d'", insn.em_type); fatal("unrecognised instruction type '%d'", em.em_type);
} }
EM_getinstr(&insn); EM_getinstr(&em);
} }
tb_fileend(); tb_fileend();

View file

@ -323,15 +323,15 @@ static struct ir* extract_block_refs(struct basicblock* bb)
struct ir* outir = NULL; struct ir* outir = NULL;
int i; int i;
for (i=0; i<bb->insns_count; i++) for (i=0; i<bb->ems_count; i++)
{ {
struct insn* insn = bb->insns[i]; struct em* em = bb->ems[i];
assert(insn->opcode == op_bra); assert(em->opcode == op_bra);
assert(insn->paramtype == PARAM_BVALUE); assert(em->paramtype == PARAM_BVALUE);
outir = new_ir2( outir = new_ir2(
IR_PAIR, 0, IR_PAIR, 0,
new_bbir(insn->u.bvalue.left), new_bbir(em->u.bvalue.left),
outir outir
); );
} }
@ -651,34 +651,34 @@ static void generate_tree(struct basicblock* bb)
current_bb = bb; current_bb = bb;
reset_stack(); reset_stack();
for (i=0; i<bb->insns_count; i++) for (i=0; i<bb->ems_count; i++)
{ {
struct insn* insn = bb->insns[i]; struct em* em = bb->ems[i];
tracef('E', "E: read %s ", em_mnem[insn->opcode - sp_fmnem]); tracef('E', "E: read %s ", em_mnem[em->opcode - sp_fmnem]);
switch (insn->paramtype) switch (em->paramtype)
{ {
case PARAM_NONE: case PARAM_NONE:
tracef('E', "\n"); tracef('E', "\n");
insn_simple(insn->opcode); insn_simple(em->opcode);
break; break;
case PARAM_IVALUE: case PARAM_IVALUE:
tracef('E', "value=%d\n", insn->u.ivalue); tracef('E', "value=%d\n", em->u.ivalue);
insn_ivalue(insn->opcode, insn->u.ivalue); insn_ivalue(em->opcode, em->u.ivalue);
break; break;
case PARAM_LVALUE: case PARAM_LVALUE:
tracef('E', "label=%s offset=%d\n", tracef('E', "label=%s offset=%d\n",
insn->u.lvalue.label, insn->u.lvalue.offset); em->u.lvalue.label, em->u.lvalue.offset);
insn_lvalue(insn->opcode, insn->u.lvalue.label, insn->u.lvalue.offset); insn_lvalue(em->opcode, em->u.lvalue.label, em->u.lvalue.offset);
break; break;
case PARAM_BVALUE: case PARAM_BVALUE:
tracef('E', "true=%s", insn->u.bvalue.left->name); tracef('E', "true=%s", em->u.bvalue.left->name);
if (insn->u.bvalue.right) if (em->u.bvalue.right)
tracef('E', " false=%s", insn->u.bvalue.right->name); tracef('E', " false=%s", em->u.bvalue.right->name);
tracef('E', "\n"); tracef('E', "\n");
insn_bvalue(insn->opcode, insn->u.bvalue.left, insn->u.bvalue.right); insn_bvalue(em->opcode, em->u.bvalue.left, em->u.bvalue.right);
break; break;
default: default: