sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 1 | |
| 2 | /*---------------------------------------------------------------*/ |
| 3 | /*--- ---*/ |
| 4 | /*--- This file (test_main.c) is ---*/ |
| 5 | /*--- Copyright (c) 2004 OpenWorks LLP. All rights reserved. ---*/ |
| 6 | /*--- ---*/ |
| 7 | /*---------------------------------------------------------------*/ |
| 8 | |
| 9 | #include <stdio.h> |
| 10 | #include <stdlib.h> |
| 11 | |
| 12 | #include "basictypes.h" |
| 13 | #include "ir_defs.h" |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 14 | #include "host_regs.h" |
| 15 | #include "x86h_defs.h" |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 16 | |
| 17 | |
| 18 | /*---------------------------------------------------------------*/ |
| 19 | /*--- Test ---*/ |
| 20 | /*---------------------------------------------------------------*/ |
| 21 | |
| 22 | /* HACK */ |
| 23 | extern |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 24 | HInstrArray* /* not really, but for the time being ... */ |
| 25 | iselBB ( IRBB* bb ); |
| 26 | |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 27 | /* HACK */ |
| 28 | X86Instr* genSpill_X86 ( HReg rreg, Int offset ) |
| 29 | { |
| 30 | assert(!hregIsVirtual(rreg)); |
| 31 | switch (hregClass(rreg)) { |
| 32 | case HRcInt: |
| 33 | return |
| 34 | X86Instr_Alu32M ( Xalu_MOV, X86RI_Reg(rreg), |
| 35 | X86AMode_IR(offset + 0x1000, |
| 36 | hregX86_EBP())); |
| 37 | default: |
| 38 | ppHRegClass(stderr, hregClass(rreg)); |
| 39 | panic("genSpill_X86: unimplemented regclass"); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /* HACK */ |
| 44 | X86Instr* genReload_X86 ( HReg rreg, Int offset ) |
| 45 | { |
| 46 | assert(!hregIsVirtual(rreg)); |
| 47 | switch (hregClass(rreg)) { |
| 48 | case HRcInt: |
| 49 | return |
| 50 | X86Instr_Alu32R ( Xalu_MOV, |
| 51 | X86RMI_Mem(X86AMode_IR(offset + 0x1000, |
| 52 | hregX86_EBP())), |
| 53 | rreg ); |
| 54 | default: |
| 55 | ppHRegClass(stderr, hregClass(rreg)); |
| 56 | panic("genReload_X86: unimplemented regclass"); |
| 57 | } |
| 58 | } |
| 59 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 60 | |
| 61 | int main ( void ) |
| 62 | { |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 63 | HInstrArray* vcode; |
| 64 | IRBB* bb; |
| 65 | IRTypeEnv* env = newIRTypeEnv(); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 66 | |
| 67 | IRTemp t1 = 1; |
| 68 | IRTemp t2 = 2; |
| 69 | |
| 70 | addToIRTypeEnv ( env, t1, Ity_I32 ); |
| 71 | addToIRTypeEnv ( env, t2, Ity_I32 ); |
| 72 | |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 73 | IRStmt* s10 = IRStmt_Tmp(t1, IRExpr_Const(IRConst_U32(1001))); |
| 74 | IRStmt* s11 = IRStmt_Tmp(t2, IRExpr_Const(IRConst_U32(2002))); |
| 75 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 76 | IRStmt* s1 = IRStmt_Put(8,4, IRExpr_Const(IRConst_U32(99)) ); |
| 77 | IRStmt* s2 = IRStmt_Put(7,4, IRExpr_Binop(Iop_Add32, |
| 78 | IRExpr_Tmp(t1), |
| 79 | IRExpr_Const(IRConst_U32(55)))); |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 80 | s10->link = s11; |
| 81 | s11->link = s1; |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 82 | s1->link = s2; |
| 83 | |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 84 | bb = mk_IRBB(env, s10, IRNext_UJump(IRConst_U32(-65565))); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 85 | |
| 86 | printf("bb is ...\n"); |
| 87 | ppIRBB(stdout, bb); |
| 88 | printf("\n"); |
| 89 | |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 90 | // vcode = iselBB(bb); |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 91 | { |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 92 | Int i; |
| 93 | HReg vr0 = mkHReg(0, HRcInt, True); |
| 94 | HReg vr1 = mkHReg(1, HRcInt, True); |
| 95 | HReg vr2 = mkHReg(2, HRcInt, True); |
| 96 | HReg vr3 = mkHReg(3, HRcInt, True); |
| 97 | HReg eax = hregX86_EAX(); |
| 98 | HReg ebx = hregX86_EBX(); |
| 99 | HReg ecx = hregX86_ECX(); |
| 100 | HReg edx = hregX86_EDX(); |
| 101 | HReg ebp = hregX86_EBP(); |
| 102 | vcode = newHInstrArray(); |
| 103 | |
| 104 | addHInstr(vcode, X86Instr_Alu32R(Xalu_MOV, |
| 105 | X86RMI_Imm(0x10001), vr0)); |
| 106 | addHInstr(vcode, X86Instr_Alu32R(Xalu_MOV, |
| 107 | X86RMI_Imm(0x10101), vr1)); |
| 108 | addHInstr(vcode, X86Instr_Alu32R(Xalu_MOV, |
| 109 | X86RMI_Imm(0x10201), vr2)); |
| 110 | addHInstr(vcode, X86Instr_Alu32R(Xalu_MOV, |
| 111 | X86RMI_Imm(0x10301), vr3)); |
| 112 | |
| 113 | addHInstr(vcode, X86Instr_Alu32R(Xalu_MOV, |
| 114 | X86RMI_Imm(0x99999), eax)); |
| 115 | addHInstr(vcode, X86Instr_Alu32R(Xalu_MOV, |
| 116 | X86RMI_Imm(0x99999), edx)); |
| 117 | |
| 118 | addHInstr(vcode, X86Instr_Alu32M(Xalu_MOV, |
| 119 | X86RI_Reg(vr0), |
| 120 | X86AMode_IR(0x100, ebp))); |
| 121 | addHInstr(vcode, X86Instr_Alu32M(Xalu_MOV, |
| 122 | X86RI_Reg(vr1), |
| 123 | X86AMode_IR(0x101, ebp))); |
| 124 | addHInstr(vcode, X86Instr_Alu32M(Xalu_MOV, |
| 125 | X86RI_Reg(vr2), |
| 126 | X86AMode_IR(0x101, ebp))); |
| 127 | addHInstr(vcode, X86Instr_Alu32M(Xalu_MOV, |
| 128 | X86RI_Reg(vr3), |
| 129 | X86AMode_IR(0x101, ebp))); |
| 130 | printf("\nBefore\n"); |
| 131 | for (i = 0; i < vcode->arr_used; i++) { |
| 132 | ppX86Instr(stdout, vcode->arr[i]); |
| 133 | printf("\n"); |
| 134 | } |
| 135 | printf("\n"); |
| 136 | } |
| 137 | |
| 138 | { |
| 139 | Int i; |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 140 | HInstrArray* rcode; |
| 141 | HReg rregs_to_use[4]; |
| 142 | rregs_to_use[0] = hregX86_EAX(); |
| 143 | rregs_to_use[1] = hregX86_EBX(); |
| 144 | rregs_to_use[2] = hregX86_ECX(); |
| 145 | rregs_to_use[3] = hregX86_EDX(); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 146 | |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 147 | rcode = |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 148 | doRegisterAllocation(vcode, 4, /* vregs */ |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 149 | rregs_to_use, 4, /* rregs */ |
| 150 | NULL, /* ismove */ |
| 151 | getRegUsage_X86Instr, |
| 152 | mapRegs_X86Instr, |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 153 | genSpill_X86, |
| 154 | genReload_X86 |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 155 | ); |
| 156 | |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 157 | printf("\nAfter\n"); |
| 158 | for (i = 0; i < rcode->arr_used; i++) { |
| 159 | ppX86Instr(stdout, rcode->arr[i]); |
| 160 | printf("\n"); |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 161 | } |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 162 | printf("\n"); |
| 163 | } |
| 164 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 165 | return 0; |
| 166 | } |