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 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 12 | |
| 13 | |
| 14 | /*---------------------------------------------------------------*/ |
| 15 | /*--- Test ---*/ |
| 16 | /*---------------------------------------------------------------*/ |
| 17 | |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame^] | 18 | #include "libvex_basictypes.h" |
| 19 | #include "libvex.h" |
sewardj | ce605f9 | 2004-07-05 14:39:15 +0000 | [diff] [blame] | 20 | |
| 21 | void failure_exit ( void ) |
| 22 | { |
| 23 | fprintf(stdout, "VEX did failure_exit. Bye.\n"); |
| 24 | exit(1); |
| 25 | } |
| 26 | |
| 27 | void log_bytes ( Char* bytes, Int nbytes ) |
| 28 | { |
| 29 | fwrite ( bytes, 1, nbytes, stdout ); |
| 30 | } |
| 31 | |
| 32 | int main ( void ) |
| 33 | { |
| 34 | Int* p; |
| 35 | Int i, j, n = 0; |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame^] | 36 | LibVEX_Init ( &failure_exit, &log_bytes, |
sewardj | ce605f9 | 2004-07-05 14:39:15 +0000 | [diff] [blame] | 37 | 1, 1, False, 10 ); |
| 38 | for (j = 0; j < 5000; j++) { |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame^] | 39 | LibVEX_Clear(False); |
sewardj | ce605f9 | 2004-07-05 14:39:15 +0000 | [diff] [blame] | 40 | for (i = 0; i < 2000; i++) { |
| 41 | n++; |
| 42 | p = LibVEX_Alloc(16); |
| 43 | p[0] = p[1] = p[2] = p[3] = 44; |
| 44 | } |
| 45 | } |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame^] | 46 | LibVEX_Clear(True); |
sewardj | ce605f9 | 2004-07-05 14:39:15 +0000 | [diff] [blame] | 47 | printf("Did %d allocs\n", n); |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | /*---------------------------------------------------------------*/ |
| 52 | /*--- Test (old) ---*/ |
| 53 | /*---------------------------------------------------------------*/ |
| 54 | |
| 55 | #if 0 |
| 56 | |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame^] | 57 | #include "libvex_basictypes.h" |
sewardj | ce605f9 | 2004-07-05 14:39:15 +0000 | [diff] [blame] | 58 | #include "ir_defs.h" |
| 59 | #include "host_regs.h" |
| 60 | #include "x86h_defs.h" |
| 61 | |
| 62 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 63 | /* HACK */ |
| 64 | extern |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 65 | HInstrArray* /* not really, but for the time being ... */ |
sewardj | 194d54a | 2004-07-03 19:08:18 +0000 | [diff] [blame] | 66 | iselBB_X86Instr ( IRBB* bb ); |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 67 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 68 | |
| 69 | int main ( void ) |
| 70 | { |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 71 | HInstrArray* vcode; |
| 72 | IRBB* bb; |
| 73 | IRTypeEnv* env = newIRTypeEnv(); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 74 | |
sewardj | 12952ef | 2004-07-03 14:52:19 +0000 | [diff] [blame] | 75 | IRTemp t0 = 0; |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 76 | IRTemp t1 = 1; |
| 77 | IRTemp t2 = 2; |
| 78 | |
sewardj | 12952ef | 2004-07-03 14:52:19 +0000 | [diff] [blame] | 79 | addToIRTypeEnv ( env, t0, Ity_I32 ); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 80 | addToIRTypeEnv ( env, t1, Ity_I32 ); |
| 81 | addToIRTypeEnv ( env, t2, Ity_I32 ); |
| 82 | |
sewardj | 12952ef | 2004-07-03 14:52:19 +0000 | [diff] [blame] | 83 | IRStmt* s10 = IRStmt_Tmp(t0, IRExpr_Const(IRConst_U32(0x2000))); |
| 84 | IRStmt* s11 = IRStmt_Tmp(t1, IRExpr_Const(IRConst_U32(0x2001))); |
| 85 | IRStmt* s12 = IRStmt_Tmp(t2, IRExpr_Const(IRConst_U32(0x2002))); |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 86 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 87 | IRStmt* s1 = IRStmt_Put(8,4, IRExpr_Const(IRConst_U32(99)) ); |
sewardj | 12952ef | 2004-07-03 14:52:19 +0000 | [diff] [blame] | 88 | #if 0 |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 89 | IRStmt* s2 = IRStmt_Put(7,4, IRExpr_Binop(Iop_Add32, |
| 90 | IRExpr_Tmp(t1), |
| 91 | IRExpr_Const(IRConst_U32(55)))); |
sewardj | 12952ef | 2004-07-03 14:52:19 +0000 | [diff] [blame] | 92 | #endif |
| 93 | |
| 94 | IRStmt* s2 = IRStmt_Put(9,4, |
| 95 | IRExpr_Binop(Iop_Shl32, |
| 96 | IRExpr_Tmp(t0), |
| 97 | IRExpr_Binop(Iop_Add32, |
| 98 | IRExpr_Tmp(t1), |
| 99 | IRExpr_Tmp(t2)))); |
| 100 | |
| 101 | |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 102 | s10->link = s11; |
sewardj | 12952ef | 2004-07-03 14:52:19 +0000 | [diff] [blame] | 103 | s11->link = s12; |
| 104 | s12->link = s1; |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 105 | s1->link = s2; |
| 106 | |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 107 | bb = mk_IRBB(env, s10, IRNext_UJump(IRConst_U32(-65565))); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 108 | |
| 109 | printf("bb is ...\n"); |
| 110 | ppIRBB(stdout, bb); |
| 111 | printf("\n"); |
| 112 | |
sewardj | 3b9d65e | 2004-07-03 19:52:16 +0000 | [diff] [blame] | 113 | if (0) |
sewardj | 194d54a | 2004-07-03 19:08:18 +0000 | [diff] [blame] | 114 | vcode = iselBB_X86Instr(bb); |
sewardj | 12952ef | 2004-07-03 14:52:19 +0000 | [diff] [blame] | 115 | else |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 116 | { |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 117 | Int i; |
| 118 | HReg vr0 = mkHReg(0, HRcInt, True); |
| 119 | HReg vr1 = mkHReg(1, HRcInt, True); |
| 120 | HReg vr2 = mkHReg(2, HRcInt, True); |
| 121 | HReg vr3 = mkHReg(3, HRcInt, True); |
| 122 | HReg eax = hregX86_EAX(); |
| 123 | HReg ebx = hregX86_EBX(); |
| 124 | HReg ecx = hregX86_ECX(); |
| 125 | HReg edx = hregX86_EDX(); |
| 126 | HReg ebp = hregX86_EBP(); |
| 127 | vcode = newHInstrArray(); |
sewardj | 3b9d65e | 2004-07-03 19:52:16 +0000 | [diff] [blame] | 128 | vcode->n_vregs = 4; |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 129 | |
| 130 | addHInstr(vcode, X86Instr_Alu32R(Xalu_MOV, |
| 131 | X86RMI_Imm(0x10001), vr0)); |
| 132 | addHInstr(vcode, X86Instr_Alu32R(Xalu_MOV, |
| 133 | X86RMI_Imm(0x10101), vr1)); |
| 134 | addHInstr(vcode, X86Instr_Alu32R(Xalu_MOV, |
| 135 | X86RMI_Imm(0x10201), vr2)); |
| 136 | addHInstr(vcode, X86Instr_Alu32R(Xalu_MOV, |
| 137 | X86RMI_Imm(0x10301), vr3)); |
| 138 | |
| 139 | addHInstr(vcode, X86Instr_Alu32R(Xalu_MOV, |
| 140 | X86RMI_Imm(0x99999), eax)); |
| 141 | addHInstr(vcode, X86Instr_Alu32R(Xalu_MOV, |
| 142 | X86RMI_Imm(0x99999), edx)); |
| 143 | |
| 144 | addHInstr(vcode, X86Instr_Alu32M(Xalu_MOV, |
| 145 | X86RI_Reg(vr0), |
| 146 | X86AMode_IR(0x100, ebp))); |
| 147 | addHInstr(vcode, X86Instr_Alu32M(Xalu_MOV, |
| 148 | X86RI_Reg(vr1), |
| 149 | X86AMode_IR(0x101, ebp))); |
| 150 | addHInstr(vcode, X86Instr_Alu32M(Xalu_MOV, |
| 151 | X86RI_Reg(vr2), |
| 152 | X86AMode_IR(0x101, ebp))); |
| 153 | addHInstr(vcode, X86Instr_Alu32M(Xalu_MOV, |
| 154 | X86RI_Reg(vr3), |
| 155 | X86AMode_IR(0x101, ebp))); |
| 156 | printf("\nBefore\n"); |
| 157 | for (i = 0; i < vcode->arr_used; i++) { |
| 158 | ppX86Instr(stdout, vcode->arr[i]); |
| 159 | printf("\n"); |
| 160 | } |
| 161 | printf("\n"); |
| 162 | } |
| 163 | |
| 164 | { |
| 165 | Int i; |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 166 | HInstrArray* rcode; |
| 167 | HReg rregs_to_use[4]; |
| 168 | rregs_to_use[0] = hregX86_EAX(); |
| 169 | rregs_to_use[1] = hregX86_EBX(); |
| 170 | rregs_to_use[2] = hregX86_ECX(); |
| 171 | rregs_to_use[3] = hregX86_EDX(); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 172 | |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 173 | rcode = |
sewardj | 194d54a | 2004-07-03 19:08:18 +0000 | [diff] [blame] | 174 | doRegisterAllocation(vcode, |
sewardj | 3b9d65e | 2004-07-03 19:52:16 +0000 | [diff] [blame] | 175 | rregs_to_use, 3, /* rregs */ |
sewardj | 12952ef | 2004-07-03 14:52:19 +0000 | [diff] [blame] | 176 | isMove_X86Instr, |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 177 | getRegUsage_X86Instr, |
| 178 | mapRegs_X86Instr, |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 179 | genSpill_X86, |
| 180 | genReload_X86 |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 181 | ); |
| 182 | |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 183 | printf("\nAfter\n"); |
| 184 | for (i = 0; i < rcode->arr_used; i++) { |
| 185 | ppX86Instr(stdout, rcode->arr[i]); |
| 186 | printf("\n"); |
sewardj | 2cd80dc | 2004-07-02 15:20:40 +0000 | [diff] [blame] | 187 | } |
sewardj | 0ec3325 | 2004-07-03 13:30:00 +0000 | [diff] [blame] | 188 | printf("\n"); |
| 189 | } |
| 190 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 191 | return 0; |
| 192 | } |
sewardj | ce605f9 | 2004-07-05 14:39:15 +0000 | [diff] [blame] | 193 | #endif |