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 ... */ |
sewardj | 194d54a | 2004-07-03 19:08:18 +0000 | [diff] [blame] | 25 | iselBB_X86Instr ( IRBB* bb ); |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 26 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 27 | |
| 28 | int main ( void ) |
| 29 | { |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 30 | HInstrArray* vcode; |
| 31 | IRBB* bb; |
| 32 | IRTypeEnv* env = newIRTypeEnv(); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 33 | |
sewardj | 12952ef | 2004-07-03 14:52:19 +0000 | [diff] [blame] | 34 | IRTemp t0 = 0; |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 35 | IRTemp t1 = 1; |
| 36 | IRTemp t2 = 2; |
| 37 | |
sewardj | 12952ef | 2004-07-03 14:52:19 +0000 | [diff] [blame] | 38 | addToIRTypeEnv ( env, t0, Ity_I32 ); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 39 | addToIRTypeEnv ( env, t1, Ity_I32 ); |
| 40 | addToIRTypeEnv ( env, t2, Ity_I32 ); |
| 41 | |
sewardj | 12952ef | 2004-07-03 14:52:19 +0000 | [diff] [blame] | 42 | IRStmt* s10 = IRStmt_Tmp(t0, IRExpr_Const(IRConst_U32(0x2000))); |
| 43 | IRStmt* s11 = IRStmt_Tmp(t1, IRExpr_Const(IRConst_U32(0x2001))); |
| 44 | IRStmt* s12 = IRStmt_Tmp(t2, IRExpr_Const(IRConst_U32(0x2002))); |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 45 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 46 | IRStmt* s1 = IRStmt_Put(8,4, IRExpr_Const(IRConst_U32(99)) ); |
sewardj | 12952ef | 2004-07-03 14:52:19 +0000 | [diff] [blame] | 47 | #if 0 |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 48 | IRStmt* s2 = IRStmt_Put(7,4, IRExpr_Binop(Iop_Add32, |
| 49 | IRExpr_Tmp(t1), |
| 50 | IRExpr_Const(IRConst_U32(55)))); |
sewardj | 12952ef | 2004-07-03 14:52:19 +0000 | [diff] [blame] | 51 | #endif |
| 52 | |
| 53 | IRStmt* s2 = IRStmt_Put(9,4, |
| 54 | IRExpr_Binop(Iop_Shl32, |
| 55 | IRExpr_Tmp(t0), |
| 56 | IRExpr_Binop(Iop_Add32, |
| 57 | IRExpr_Tmp(t1), |
| 58 | IRExpr_Tmp(t2)))); |
| 59 | |
| 60 | |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 61 | s10->link = s11; |
sewardj | 12952ef | 2004-07-03 14:52:19 +0000 | [diff] [blame] | 62 | s11->link = s12; |
| 63 | s12->link = s1; |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 64 | s1->link = s2; |
| 65 | |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 66 | bb = mk_IRBB(env, s10, IRNext_UJump(IRConst_U32(-65565))); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 67 | |
| 68 | printf("bb is ...\n"); |
| 69 | ppIRBB(stdout, bb); |
| 70 | printf("\n"); |
| 71 | |
sewardj | 12952ef | 2004-07-03 14:52:19 +0000 | [diff] [blame] | 72 | if (1) |
sewardj | 194d54a | 2004-07-03 19:08:18 +0000 | [diff] [blame] | 73 | vcode = iselBB_X86Instr(bb); |
sewardj | 12952ef | 2004-07-03 14:52:19 +0000 | [diff] [blame] | 74 | else |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 75 | { |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 76 | Int i; |
| 77 | HReg vr0 = mkHReg(0, HRcInt, True); |
| 78 | HReg vr1 = mkHReg(1, HRcInt, True); |
| 79 | HReg vr2 = mkHReg(2, HRcInt, True); |
| 80 | HReg vr3 = mkHReg(3, HRcInt, True); |
| 81 | HReg eax = hregX86_EAX(); |
| 82 | HReg ebx = hregX86_EBX(); |
| 83 | HReg ecx = hregX86_ECX(); |
| 84 | HReg edx = hregX86_EDX(); |
| 85 | HReg ebp = hregX86_EBP(); |
| 86 | vcode = newHInstrArray(); |
| 87 | |
| 88 | addHInstr(vcode, X86Instr_Alu32R(Xalu_MOV, |
| 89 | X86RMI_Imm(0x10001), vr0)); |
| 90 | addHInstr(vcode, X86Instr_Alu32R(Xalu_MOV, |
| 91 | X86RMI_Imm(0x10101), vr1)); |
| 92 | addHInstr(vcode, X86Instr_Alu32R(Xalu_MOV, |
| 93 | X86RMI_Imm(0x10201), vr2)); |
| 94 | addHInstr(vcode, X86Instr_Alu32R(Xalu_MOV, |
| 95 | X86RMI_Imm(0x10301), vr3)); |
| 96 | |
| 97 | addHInstr(vcode, X86Instr_Alu32R(Xalu_MOV, |
| 98 | X86RMI_Imm(0x99999), eax)); |
| 99 | addHInstr(vcode, X86Instr_Alu32R(Xalu_MOV, |
| 100 | X86RMI_Imm(0x99999), edx)); |
| 101 | |
| 102 | addHInstr(vcode, X86Instr_Alu32M(Xalu_MOV, |
| 103 | X86RI_Reg(vr0), |
| 104 | X86AMode_IR(0x100, ebp))); |
| 105 | addHInstr(vcode, X86Instr_Alu32M(Xalu_MOV, |
| 106 | X86RI_Reg(vr1), |
| 107 | X86AMode_IR(0x101, ebp))); |
| 108 | addHInstr(vcode, X86Instr_Alu32M(Xalu_MOV, |
| 109 | X86RI_Reg(vr2), |
| 110 | X86AMode_IR(0x101, ebp))); |
| 111 | addHInstr(vcode, X86Instr_Alu32M(Xalu_MOV, |
| 112 | X86RI_Reg(vr3), |
| 113 | X86AMode_IR(0x101, ebp))); |
| 114 | printf("\nBefore\n"); |
| 115 | for (i = 0; i < vcode->arr_used; i++) { |
| 116 | ppX86Instr(stdout, vcode->arr[i]); |
| 117 | printf("\n"); |
| 118 | } |
| 119 | printf("\n"); |
| 120 | } |
| 121 | |
| 122 | { |
| 123 | Int i; |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 124 | HInstrArray* rcode; |
| 125 | HReg rregs_to_use[4]; |
| 126 | rregs_to_use[0] = hregX86_EAX(); |
| 127 | rregs_to_use[1] = hregX86_EBX(); |
| 128 | rregs_to_use[2] = hregX86_ECX(); |
| 129 | rregs_to_use[3] = hregX86_EDX(); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 130 | |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 131 | rcode = |
sewardj | 194d54a | 2004-07-03 19:08:18 +0000 | [diff] [blame] | 132 | doRegisterAllocation(vcode, |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 133 | rregs_to_use, 4, /* rregs */ |
sewardj | 12952ef | 2004-07-03 14:52:19 +0000 | [diff] [blame] | 134 | isMove_X86Instr, |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 135 | getRegUsage_X86Instr, |
| 136 | mapRegs_X86Instr, |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 137 | genSpill_X86, |
| 138 | genReload_X86 |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 139 | ); |
| 140 | |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 141 | printf("\nAfter\n"); |
| 142 | for (i = 0; i < rcode->arr_used; i++) { |
| 143 | ppX86Instr(stdout, rcode->arr[i]); |
| 144 | printf("\n"); |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 145 | } |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 146 | printf("\n"); |
| 147 | } |
| 148 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 149 | return 0; |
| 150 | } |