Permalink
Browse files

write instructions to a file a.m1 to use INS infrastructure.

  • Loading branch information...
1 parent 7a77d4d commit b452fa2cee884157d994bbc67867cbad2eac62e4 @kjs kjs committed Jun 27, 2012
Showing with 11 additions and 5 deletions.
  1. +9 −5 src/instr.c
  2. +2 −0 src/main.c
View
@@ -72,7 +72,7 @@ char const * const m0_instr_names[] = {
static const char regs[REG_TYPE_NUM + 2] = {'I', 'N', 'S', 'P', ' ', 'L'};
-#define OUT stdout
+#define OUT comp->outfile
@@ -81,8 +81,11 @@ write_instr(M1_compiler *comp, m0_instr *i) {
assert(comp != NULL);
- if (i->label != 0)
- fprintf(OUT, "L%d:\n", i->label);
+ if (i->label != 0 && i->opcode == M0_NOOP)
+ fprintf(OUT, "L%d:\n", i->label);
+
+ if (i->opcode == M0_NOOP)
+ return;
switch (i->numops) {
case 0:
@@ -259,7 +262,7 @@ mk_instr(M1_compiler *comp, m0_opcode opcode, char const * const format, ...) {
- //write_instr(comp, ins);
+ write_instr(comp, ins);
return ins;
}
@@ -274,7 +277,8 @@ mk_label(M1_compiler *comp, unsigned labelno) {
/* set this instruction's opcode to "noop", which is a signal to mk_instr
that this node can be used for the next instruction.
*/
- ins->opcode = M0_NOOP;
+ ins->opcode = M0_NOOP;
+ write_instr(comp, ins);
}
m0_chunk *
View
@@ -90,7 +90,9 @@ main(int argc, char *argv[]) {
if (comp.errors == 0)
{
fprintf(stderr, "generating code...\n");
+ comp.outfile = fopen("a.m1", "w");
gencode(&comp, comp.ast);
+ fclose(comp.outfile);
}
else {
fprintf(stderr, "%d errors and %d warnings\n", comp.errors, comp.warnings);

0 comments on commit b452fa2

Please sign in to comment.