void X86_Operand_print (O o) { Assert_ASSERT(o); switch (o->kind){ case X86_OP_INT: print ("$"); print (Int_toString (o->u.intlit)); return; case X86_OP_GLOBAL: print ("$"); print (Id_toString (o->u.global)); return; case X86_OP_INSTACK: print (Int_toString (o->u.index)); print ("(%ebp)"); return; case X86_OP_REG: X86_Register_print (o->u.reg); return; case X86_OP_MEM: print (Int_toString (4*(o->u.mem.offset))); print ("("); X86_Register_print (o->u.mem.base); print (")"); return; default: Error_impossible(); return; } Error_impossible(); return; }
File_t X86_Mask_print (File_t file, M m) { List_t p; Assert_ASSERT(m); fprintf (file, "%s", Id_toString (m->name)); fprintf (file, ":\n\t.int "); fprintf (file, "%s", Int_toString (m->size)); if (List_isEmpty (m->index)){ fprintf (file, "\n"); return file; } fprintf (file, ", "); p = List_getFirst (m->index); while (p){ fprintf (file, "%s", Int_toString ((int)p->data)); if (p->next) fprintf (file, ", "); p = p->next; } fprintf (file, "\n"); return file; }
void X86_Fun_print (F f) { Assert_ASSERT(f); print ("\t.text\n"); print ("\t.globl _"); print (Id_toString (f->name)); print ("\n_"); print (Id_toString (f->name)); print (":\n"); print ("\tpushl %ebp\n"); print ("\tmovl %esp, %ebp\n"); { int i = List_size (f->decs); if (i){ print ("\tsubl $"); print (Int_toString (4*i)); print (", %esp\n"); } } List_foreach (f->stms, (Poly_tyVoid)X86_Stm_print); print ("\n\n"); return; }
int64_t* _toString_(_DECL_1DARRAY_PARAM(c), _DECL_1DARRAYSIZE_PARAM_CALLBYREFERENCE){ _DECL_DEALLOC(c); _DECL_1DARRAY(_1); _DECL_DEALLOC(_1); _DECL_1DARRAY(r); _DECL_DEALLOC(r); bool firstTime; int64_t i; int64_t amt; void* _6; size_t _6_size = 0; _DECL_DEALLOC(_6); bool _7; int64_t _8; int64_t _9; int64_t _10; int64_t _11; bool _12; _DECL_1DARRAY(_13); _DECL_DEALLOC(_13); _DECL_1DARRAY(_14); _DECL_DEALLOC(_14); bool _15; _DECL_1DARRAY(_16); _DECL_DEALLOC(_16); _DECL_1DARRAY(_17); _DECL_DEALLOC(_17); _DECL_1DARRAY(_18); _DECL_DEALLOC(_18); _DECL_1DARRAY(_19); _DECL_DEALLOC(_19); _DECL_1DARRAY(_20); _DECL_DEALLOC(_20); _DECL_2DARRAY(_21); _DECL_DEALLOC(_21); _DECL_1DARRAY(_22); _DECL_DEALLOC(_22); int64_t _23; int64_t _24; void* _25; size_t _25_size = 0; _DECL_DEALLOC(_25); _DECL_1DARRAY(_26); _DECL_DEALLOC(_26); //const %6 = [] : void[] _DEALLOC(_6); _NEW_1DARRAY_int64_t(_6, 0, 0); _6_dealloc = true; //assign %2 = %6 : void[] _DEALLOC(r); _COPY_1DARRAY_int64_t(r, _6); _ADD_DEALLOC_POST(r, _6); //const %7 = true : bool _7 = true; //assign %3 = %7 : bool firstTime = _7; //const %8 = 0 : int _8 = 0; //assign %4 = %8 : int i = _8; //loop (%2, %3, %4, %5, %9, %10, %11, %12, %13, %14, %15, %16, %17, %18, %19, %20, %21, %22, %23, %24) while(true){ //lengthof %9 = %0 : int[] _9 = c_size; //ifge %4, %9 goto blklab2 : int if(i>=_9){goto blklab2;} //indexof %10 = %0, %4 : int[] _10=c[i]; //assign %5 = %10 : int amt = _10; //const %11 = 0 : int _11 = 0; //ifeq %5, %11 goto blklab4 : int if(amt==_11){goto blklab4;} //const %12 = true : bool _12 = true; //ifeq %3, %12 goto blklab5 : bool if(firstTime==_12){goto blklab5;} //const %14 = [44,32] : int[] _DEALLOC(_14); _NEW_1DARRAY_int64_t(_14, 2, 0); _14[0] = 44; _14[1] = 32; _14_dealloc = true; //invoke (%13) = (%2, %14) whiley/lang/Array:append : function(int[],int[])->(int[]) { _DEALLOC(_13); _13 = Array_Append(r, r_size , _14, _14_size, _1DARRAYSIZE_PARAM_CALLBYREFERENCE(_13)); _13_dealloc = true; } //assign %2 = %13 : int[] _DEALLOC(r); _COPY_1DARRAY_int64_t(r, _13); _ADD_DEALLOC_POST(r, _13); //.blklab5 blklab5:; //const %15 = false : bool _15 = false; //assign %3 = %15 : bool firstTime = _15; //invoke (%17) = (%5) whiley/lang/Int:toString : function(int)->(whiley/lang/ASCII:string) { _DEALLOC(_17); _17 = Int_toString(amt, _1DARRAYSIZE_PARAM_CALLBYREFERENCE(_17)); _17_dealloc = true; } //invoke (%16) = (%2, %17) whiley/lang/Array:append : function(int[],int[])->(int[]) { _DEALLOC(_16); _16 = Array_Append(r, r_size , _17, _17_size, _1DARRAYSIZE_PARAM_CALLBYREFERENCE(_16)); _16_dealloc = true; } //assign %2 = %16 : int[] _DEALLOC(r); _COPY_1DARRAY_int64_t(r, _16); _ADD_DEALLOC_POST(r, _16); //const %19 = [32,120,32] : int[] _DEALLOC(_19); _NEW_1DARRAY_int64_t(_19, 3, 0); _19[0] = 32; _19[1] = 120; _19[2] = 32; _19_dealloc = true; //invoke (%18) = (%2, %19) whiley/lang/Array:append : function(int[],int[])->(int[]) { _DEALLOC(_18); _18 = Array_Append(r, r_size , _19, _19_size, _1DARRAYSIZE_PARAM_CALLBYREFERENCE(_18)); _18_dealloc = true; } //assign %2 = %18 : int[] _DEALLOC(r); _COPY_1DARRAY_int64_t(r, _18); _ADD_DEALLOC_POST(r, _18); //const %21 = [[49,99],[53,99],[49,48,99],[50,48,99],[53,48,99],[36,49],[36,53],[36,49,48]] : int[][] _DEALLOC_2DARRAY(_21); _NEW_2DARRAY_int64_t_EMPTY(_21, 8, 3); { int64_t tmp[] = {49, 99, '\0'}; memcpy(_21[0], tmp, 3*sizeof(int64_t)); } { int64_t tmp[] = {53, 99, '\0'}; memcpy(_21[1], tmp, 3*sizeof(int64_t)); } { int64_t tmp[] = {49, 48, 99}; memcpy(_21[2], tmp, 3*sizeof(int64_t)); } { int64_t tmp[] = {50, 48, 99}; memcpy(_21[3], tmp, 3*sizeof(int64_t)); } { int64_t tmp[] = {53, 48, 99}; memcpy(_21[4], tmp, 3*sizeof(int64_t)); } { int64_t tmp[] = {36, 49, '\0'}; memcpy(_21[5], tmp, 3*sizeof(int64_t)); } { int64_t tmp[] = {36, 53, '\0'}; memcpy(_21[6], tmp, 3*sizeof(int64_t)); } { int64_t tmp[] = {36, 49, 48}; memcpy(_21[7], tmp, 3*sizeof(int64_t)); } _21_dealloc = true; //indexof %22 = %21, %4 : int[][] _22=_21[i]; _22_size = _21_size_size; _22_dealloc = false; //invoke (%20) = (%2, %22) whiley/lang/Array:append : function(int[],int[])->(int[]) { _DEALLOC(_20); _20 = Array_Append(r, r_size , _22, _22_size, _1DARRAYSIZE_PARAM_CALLBYREFERENCE(_20)); _20_dealloc = true; } //assign %2 = %20 : int[] _DEALLOC(r); _COPY_1DARRAY_int64_t(r, _20); _ADD_DEALLOC_POST(r, _20); //.blklab4 blklab4:; //const %23 = 1 : int _23 = 1; //add %24 = %4, %23 : int _24=i+_23; //assign %4 = %24 : int i = _24; //.blklab3 blklab3:; } //.blklab2 blklab2:; //const %25 = [] : void[] _DEALLOC(_25); _NEW_1DARRAY_int64_t(_25, 0, 0); _25_dealloc = true; //ifne %2, %25 goto blklab6 : int[] if(r!=_25){goto blklab6;} //const %26 = [40,110,111,116,104,105,110,103,41] : int[] _DEALLOC(_26); _NEW_1DARRAY_int64_t(_26, 9, 0); _26[0] = 40; _26[1] = 110; _26[2] = 111; _26[3] = 116; _26[4] = 104; _26[5] = 105; _26[6] = 110; _26[7] = 103; _26[8] = 41; _26_dealloc = true; //assign %2 = %26 : int[] _DEALLOC(r); _COPY_1DARRAY_int64_t(r, _26); _ADD_DEALLOC_POST(r, _26); //.blklab6 blklab6:; //return %2 _DEALLOC(c); _DEALLOC(_1); _DEALLOC(_6); _DEALLOC(_13); _DEALLOC(_14); _DEALLOC(_16); _DEALLOC(_17); _DEALLOC(_18); _DEALLOC(_19); _DEALLOC(_20); _DEALLOC_2DARRAY(_21); _DEALLOC(_22); _DEALLOC(_25); _DEALLOC(_26); _UPDATE_1DARRAYSZIE_PARAM_CALLBYREFERENCE(r); return r; //return }
void X86_Stm_print (S s) { Assert_ASSERT(s); switch (s->kind){ case X86_STM_MOVERR: space4 (); print ("movl "); X86_Register_print (s->u.moverr.src); print (", "); X86_Register_print (s->u.moverr.dest); break; case X86_STM_MOVERI: space4 (); print ("movl $"); print (Int_toString (s->u.moveri.src)); print (", "); X86_Register_print (s->u.moveri.dest); break; case X86_STM_LOAD: space4 (); print ("movl "); X86_Operand_print (s->u.load.src); print (", "); X86_Register_print (s->u.load.dest); break; case X86_STM_STORE: space4 (); print ("movl "); X86_Register_print (s->u.store.src); print (", "); X86_Operand_print (s->u.store.dest); break; case X86_STM_BOP: space4 (); X86_Operator_print (s->u.bop.op); X86_Register_print (s->u.bop.src); print (", "); X86_Register_print (s->u.bop.dest); break; case X86_STM_UOP: space4 (); X86_Operator_print (s->u.uop.op); X86_Register_print (s->u.uop.dest); break; case X86_STM_CALL: space4 (); print ("call "); print (Id_toString (s->u.call.name)); break; case X86_STM_CMP: space4 (); print ("cmpl "); X86_Register_print (s->u.cmp.src); print (", "); X86_Register_print (s->u.cmp.dest); break; case X86_STM_LABEL: space2(); print (Label_toString (s->u.label)); print (":"); break; case X86_STM_JE: space4 (); print ("je "); print (Label_toString (s->u.je)); break; case X86_STM_JL: space4 (); print ("jl "); print (Label_toString (s->u.je)); break; case X86_STM_JUMP: space4 (); print ("jmp "); print (Label_toString (s->u.jump)); break; case X86_STM_PUSH: space4 (); print ("pushl "); X86_Register_print (s->u.push); break; case X86_STM_NEG: space4 (); print ("negl "); X86_Register_print (s->u.neg); break; case X86_STM_SETL: space4 (); print ("setl "); X86_Register_print (s->u.setAny); break; case X86_STM_SETLE: space4 (); print ("setle "); X86_Register_print (s->u.setAny); break; case X86_STM_SETG: space4 (); print ("setg "); X86_Register_print (s->u.setAny); break; case X86_STM_SETGE: space4 (); print ("setge "); X86_Register_print (s->u.setAny); break; case X86_STM_SETE: space4 (); print ("sete "); X86_Register_print (s->u.setAny); break; case X86_STM_SETNE: space4 (); print ("setne "); X86_Register_print (s->u.setAny); break; case X86_STM_XOR: space4 (); print ("xorl "); X86_Register_print (s->u.xor.src); print (", "); X86_Register_print (s->u.xor.dest); break; case X86_STM_EXTENDAL: space4 (); print ("cbtw\n"); space4 (); print ("cwtl"); break; case X86_STM_NOT:{ space4 (); print ("notl "); X86_Register_print (s->u.not); break; } case X86_STM_RETURN: space4 (); print ("leave\n\tret"); break; case X86_STM_CLTD: space4 (); print ("cltd"); break; case X86_STM_INC: space4 (); print ("incl "); X86_Register_print (s->u.inc); break; default: Error_impossible(); break; } print ("\n"); return; }