blob: a68f126221b57d7b93690d08bd12bf9e195a4710 [file] [log] [blame]
sewardjc97096c2004-06-30 09:28:04 +00001
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
sewardjc97096c2004-06-30 09:28:04 +000012
13
14/*---------------------------------------------------------------*/
15/*--- Test ---*/
16/*---------------------------------------------------------------*/
17
sewardj887a11a2004-07-05 17:26:47 +000018#include "libvex_basictypes.h"
19#include "libvex.h"
sewardjce605f92004-07-05 14:39:15 +000020
21void failure_exit ( void )
22{
23 fprintf(stdout, "VEX did failure_exit. Bye.\n");
24 exit(1);
25}
26
27void log_bytes ( Char* bytes, Int nbytes )
28{
29 fwrite ( bytes, 1, nbytes, stdout );
30}
31
32int main ( void )
33{
34 Int* p;
35 Int i, j, n = 0;
sewardj887a11a2004-07-05 17:26:47 +000036 LibVEX_Init ( &failure_exit, &log_bytes,
sewardjce605f92004-07-05 14:39:15 +000037 1, 1, False, 10 );
38 for (j = 0; j < 5000; j++) {
sewardj887a11a2004-07-05 17:26:47 +000039 LibVEX_Clear(False);
sewardjce605f92004-07-05 14:39:15 +000040 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 }
sewardj887a11a2004-07-05 17:26:47 +000046 LibVEX_Clear(True);
sewardjce605f92004-07-05 14:39:15 +000047 printf("Did %d allocs\n", n);
48 return 0;
49}
50
51/*---------------------------------------------------------------*/
52/*--- Test (old) ---*/
53/*---------------------------------------------------------------*/
54
55#if 0
56
sewardj887a11a2004-07-05 17:26:47 +000057#include "libvex_basictypes.h"
sewardjce605f92004-07-05 14:39:15 +000058#include "ir_defs.h"
59#include "host_regs.h"
60#include "x86h_defs.h"
61
62
sewardjc97096c2004-06-30 09:28:04 +000063/* HACK */
64extern
sewardj2cd80dc2004-07-02 15:20:40 +000065HInstrArray* /* not really, but for the time being ... */
sewardj194d54a2004-07-03 19:08:18 +000066 iselBB_X86Instr ( IRBB* bb );
sewardj0ec33252004-07-03 13:30:00 +000067
sewardjc97096c2004-06-30 09:28:04 +000068
69int main ( void )
70{
sewardj2cd80dc2004-07-02 15:20:40 +000071 HInstrArray* vcode;
72 IRBB* bb;
73 IRTypeEnv* env = newIRTypeEnv();
sewardjc97096c2004-06-30 09:28:04 +000074
sewardj12952ef2004-07-03 14:52:19 +000075 IRTemp t0 = 0;
sewardjc97096c2004-06-30 09:28:04 +000076 IRTemp t1 = 1;
77 IRTemp t2 = 2;
78
sewardj12952ef2004-07-03 14:52:19 +000079 addToIRTypeEnv ( env, t0, Ity_I32 );
sewardjc97096c2004-06-30 09:28:04 +000080 addToIRTypeEnv ( env, t1, Ity_I32 );
81 addToIRTypeEnv ( env, t2, Ity_I32 );
82
sewardj12952ef2004-07-03 14:52:19 +000083 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)));
sewardj0ec33252004-07-03 13:30:00 +000086
sewardjc97096c2004-06-30 09:28:04 +000087 IRStmt* s1 = IRStmt_Put(8,4, IRExpr_Const(IRConst_U32(99)) );
sewardj12952ef2004-07-03 14:52:19 +000088#if 0
sewardjc97096c2004-06-30 09:28:04 +000089 IRStmt* s2 = IRStmt_Put(7,4, IRExpr_Binop(Iop_Add32,
90 IRExpr_Tmp(t1),
91 IRExpr_Const(IRConst_U32(55))));
sewardj12952ef2004-07-03 14:52:19 +000092#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
sewardj0ec33252004-07-03 13:30:00 +0000102 s10->link = s11;
sewardj12952ef2004-07-03 14:52:19 +0000103 s11->link = s12;
104 s12->link = s1;
sewardjc97096c2004-06-30 09:28:04 +0000105 s1->link = s2;
106
sewardj0ec33252004-07-03 13:30:00 +0000107 bb = mk_IRBB(env, s10, IRNext_UJump(IRConst_U32(-65565)));
sewardjc97096c2004-06-30 09:28:04 +0000108
109 printf("bb is ...\n");
110 ppIRBB(stdout, bb);
111 printf("\n");
112
sewardj3b9d65e2004-07-03 19:52:16 +0000113 if (0)
sewardj194d54a2004-07-03 19:08:18 +0000114 vcode = iselBB_X86Instr(bb);
sewardj12952ef2004-07-03 14:52:19 +0000115 else
sewardj2cd80dc2004-07-02 15:20:40 +0000116 {
sewardj0ec33252004-07-03 13:30:00 +0000117 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();
sewardj3b9d65e2004-07-03 19:52:16 +0000128 vcode->n_vregs = 4;
sewardj0ec33252004-07-03 13:30:00 +0000129
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;
sewardj2cd80dc2004-07-02 15:20:40 +0000166 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();
sewardjc97096c2004-06-30 09:28:04 +0000172
sewardj2cd80dc2004-07-02 15:20:40 +0000173 rcode =
sewardj194d54a2004-07-03 19:08:18 +0000174 doRegisterAllocation(vcode,
sewardj3b9d65e2004-07-03 19:52:16 +0000175 rregs_to_use, 3, /* rregs */
sewardj12952ef2004-07-03 14:52:19 +0000176 isMove_X86Instr,
sewardj2cd80dc2004-07-02 15:20:40 +0000177 getRegUsage_X86Instr,
178 mapRegs_X86Instr,
sewardj0ec33252004-07-03 13:30:00 +0000179 genSpill_X86,
180 genReload_X86
sewardj2cd80dc2004-07-02 15:20:40 +0000181 );
182
sewardj0ec33252004-07-03 13:30:00 +0000183 printf("\nAfter\n");
184 for (i = 0; i < rcode->arr_used; i++) {
185 ppX86Instr(stdout, rcode->arr[i]);
186 printf("\n");
sewardj2cd80dc2004-07-02 15:20:40 +0000187 }
sewardj0ec33252004-07-03 13:30:00 +0000188 printf("\n");
189 }
190
sewardjc97096c2004-06-30 09:28:04 +0000191 return 0;
192}
sewardjce605f92004-07-05 14:39:15 +0000193#endif