blob: 9b949707b2afc2a6424bdd601d9c7c238a01b5d3 [file] [log] [blame]
sewardj35421a32004-07-05 13:12:34 +00001
2/*---------------------------------------------------------------*/
3/*--- ---*/
sewardjc0ee2ed2004-07-27 10:29:41 +00004/*--- This file (main/vex_main.c) is ---*/
sewardj35421a32004-07-05 13:12:34 +00005/*--- Copyright (c) 2004 OpenWorks LLP. All rights reserved. ---*/
6/*--- ---*/
7/*---------------------------------------------------------------*/
8
sewardjf8ed9d82004-11-12 17:40:23 +00009/*
10 This file is part of LibVEX, a library for dynamic binary
11 instrumentation and translation.
12
13 Copyright (C) 2004 OpenWorks, LLP.
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; Version 2 dated June 1991 of the
18 license.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or liability
23 for damages. See the GNU General Public License for more details.
24
25 Neither the names of the U.S. Department of Energy nor the
26 University of California nor the names of its contributors may be
27 used to endorse or promote products derived from this software
28 without prior written permission.
29
30 You should have received a copy of the GNU General Public License
31 along with this program; if not, write to the Free Software
32 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
33 USA.
34*/
35
sewardj887a11a2004-07-05 17:26:47 +000036#include "libvex.h"
sewardj81ec4182004-10-25 23:15:52 +000037#include "libvex_guest_x86.h"
sewardj2a9ad022004-11-25 02:46:58 +000038#include "libvex_guest_arm.h"
sewardjf13a16a2004-07-05 17:10:14 +000039
sewardjc0ee2ed2004-07-27 10:29:41 +000040#include "main/vex_globals.h"
41#include "main/vex_util.h"
42#include "host-generic/h_generic_regs.h"
sewardjedf4d692004-08-17 13:52:58 +000043#include "ir/iropt.h"
sewardj35421a32004-07-05 13:12:34 +000044
sewardj2a9ad022004-11-25 02:46:58 +000045#include "host-x86/hdefs.h"
46
47#include "guest-x86/gdefs.h"
48#include "guest-arm/gdefs.h"
49
sewardj35421a32004-07-05 13:12:34 +000050
51/* This file contains the top level interface to the library. */
52
53/* --------- Initialise the library. --------- */
54
55/* Exported to library client. */
56
sewardj08613742004-10-25 13:01:45 +000057void LibVEX_default_VexControl ( /*OUT*/ VexControl* vcon )
58{
59 vcon->iropt_verbosity = 0;
60 vcon->iropt_level = 2;
61 vcon->iropt_precise_memory_exns = False;
62 vcon->iropt_unroll_thresh = 120;
63 vcon->guest_max_insns = 50;
64 vcon->guest_chase_thresh = 10;
65}
66
67
68/* Exported to library client. */
69
sewardj887a11a2004-07-05 17:26:47 +000070void LibVEX_Init (
sewardj35421a32004-07-05 13:12:34 +000071 /* failure exit function */
sewardj2b515872004-07-05 20:50:45 +000072 __attribute__ ((noreturn))
sewardj35421a32004-07-05 13:12:34 +000073 void (*failure_exit) ( void ),
74 /* logging output function */
75 void (*log_bytes) ( Char*, Int nbytes ),
76 /* debug paranoia level */
77 Int debuglevel,
sewardj35421a32004-07-05 13:12:34 +000078 /* Are we supporting valgrind checking? */
79 Bool valgrind_support,
sewardj08613742004-10-25 13:01:45 +000080 /* Control ... */
81 /*READONLY*/VexControl* vcon
sewardj35421a32004-07-05 13:12:34 +000082)
83{
sewardj08613742004-10-25 13:01:45 +000084 /* First off, do enough minimal setup so that the following
85 assertions can fail in a sane fashion, if need be. */
sewardjea602bc2004-10-14 21:40:12 +000086 vex_failure_exit = failure_exit;
87 vex_log_bytes = log_bytes;
88
89 /* Now it's safe to check parameters for sanity. */
sewardj35421a32004-07-05 13:12:34 +000090 vassert(!vex_initdone);
91 vassert(failure_exit);
sewardj35421a32004-07-05 13:12:34 +000092 vassert(log_bytes);
sewardj35421a32004-07-05 13:12:34 +000093 vassert(debuglevel >= 0);
sewardj08613742004-10-25 13:01:45 +000094
95 vassert(vcon->iropt_verbosity >= 0);
96 vassert(vcon->iropt_level >= 0);
97 vassert(vcon->iropt_level <= 2);
98 vassert(vcon->iropt_unroll_thresh >= 0);
99 vassert(vcon->iropt_unroll_thresh <= 400);
100 vassert(vcon->guest_max_insns >= 1);
101 vassert(vcon->guest_max_insns <= 100);
102 vassert(vcon->guest_chase_thresh >= 0);
103 vassert(vcon->guest_chase_thresh < vcon->guest_max_insns);
sewardj443cd9d2004-07-18 23:06:45 +0000104
sewardj81ec4182004-10-25 23:15:52 +0000105 /* All the guest state structs must have an 8-aligned size. */
106 vassert(0 == sizeof(VexGuestX86State) % 8);
107
sewardjea602bc2004-10-14 21:40:12 +0000108 /* Check that Vex has been built with sizes of basic types as
109 stated in priv/libvex_basictypes.h. Failure of any of these is
110 a serious configuration error and should be corrected
111 immediately. If any of these assertions fail you can fully
112 expect Vex not to work properly, if at all. */
113
114 vassert(1 == sizeof(UChar));
115 vassert(1 == sizeof(Char));
116 vassert(2 == sizeof(UShort));
117 vassert(2 == sizeof(Short));
118 vassert(4 == sizeof(UInt));
119 vassert(4 == sizeof(Int));
120 vassert(8 == sizeof(ULong));
121 vassert(8 == sizeof(Long));
122 vassert(4 == sizeof(Float));
123 vassert(8 == sizeof(Double));
124 vassert(1 == sizeof(Bool));
125 vassert(4 == sizeof(Addr32));
126 vassert(8 == sizeof(Addr64));
127
128 vassert(sizeof(void*) == 4 || sizeof(void*) == 8);
129 vassert(sizeof(void*) == sizeof(int*));
130 vassert(sizeof(void*) == sizeof(HWord));
131
132 /* Really start up .. */
sewardj443cd9d2004-07-18 23:06:45 +0000133 vex_debuglevel = debuglevel;
sewardj443cd9d2004-07-18 23:06:45 +0000134 vex_valgrind_support = valgrind_support;
sewardj08613742004-10-25 13:01:45 +0000135 vex_control = *vcon;
sewardj443cd9d2004-07-18 23:06:45 +0000136 vex_initdone = True;
137 LibVEX_SetAllocMode ( AllocModeTEMPORARY );
sewardj35421a32004-07-05 13:12:34 +0000138}
139
140
141/* --------- Make a translation. --------- */
142
143/* Exported to library client. */
144
sewardj887a11a2004-07-05 17:26:47 +0000145TranslateResult LibVEX_Translate (
sewardj35421a32004-07-05 13:12:34 +0000146 /* The instruction sets we are translating from and to. */
147 InsnSet iset_guest,
148 InsnSet iset_host,
149 /* IN: the block to translate, and its guest address. */
sewardj81bd5502004-07-21 18:49:27 +0000150 UChar* guest_bytes,
sewardj35421a32004-07-05 13:12:34 +0000151 Addr64 guest_bytes_addr,
sewardj5bd4d162004-11-10 13:02:48 +0000152 Bool (*chase_into_ok) ( Addr64 ),
sewardj35421a32004-07-05 13:12:34 +0000153 /* OUT: the number of bytes actually read */
154 Int* guest_bytes_read,
155 /* IN: a place to put the resulting code, and its size */
sewardj81bd5502004-07-21 18:49:27 +0000156 UChar* host_bytes,
157 Int host_bytes_size,
sewardj35421a32004-07-05 13:12:34 +0000158 /* OUT: how much of the output area is used. */
159 Int* host_bytes_used,
sewardj49651f42004-10-28 22:11:04 +0000160 /* IN: optionally, two instrumentation functions. */
sewardjcf787902004-11-03 09:08:33 +0000161 IRBB* (*instrument1) ( IRBB*, VexGuestLayout*, IRType hWordTy ),
162 IRBB* (*instrument2) ( IRBB*, VexGuestLayout*, IRType hWordTy ),
sewardj9578a8b2004-11-04 19:44:48 +0000163 Bool cleanup_after_instrumentation,
sewardj35421a32004-07-05 13:12:34 +0000164 /* IN: optionally, an access check function for guest code. */
sewardj58800ff2004-07-28 01:51:10 +0000165 Bool (*byte_accessible) ( Addr64 ),
sewardjf48ac192004-10-29 00:41:29 +0000166 /* IN: debug: trace vex activity at various points */
167 Int traceflags
sewardj35421a32004-07-05 13:12:34 +0000168)
169{
sewardj81bd5502004-07-21 18:49:27 +0000170 /* This the bundle of functions we need to do the back-end stuff
171 (insn selection, reg-alloc, assembly) whilst being insulated
172 from the target instruction set. */
sewardjf13a16a2004-07-05 17:10:14 +0000173 HReg* available_real_regs;
174 Int n_available_real_regs;
sewardj443cd9d2004-07-18 23:06:45 +0000175 Bool (*isMove) (HInstr*, HReg*, HReg*);
176 void (*getRegUsage) (HRegUsage*, HInstr*);
177 void (*mapRegs) (HRegRemap*, HInstr*);
178 HInstr* (*genSpill) ( HReg, Int );
179 HInstr* (*genReload) ( HReg, Int );
180 void (*ppInstr) ( HInstr* );
181 void (*ppReg) ( HReg );
sewardj8ea867b2004-10-30 19:03:02 +0000182 HInstrArray* (*iselBB) ( IRBB* );
sewardj443cd9d2004-07-18 23:06:45 +0000183 IRBB* (*bbToIR) ( UChar*, Addr64, Int*,
sewardj5bd4d162004-11-10 13:02:48 +0000184 Bool(*)(Addr64),
185 Bool(*)(Addr64), Bool );
sewardj81bd5502004-07-21 18:49:27 +0000186 Int (*emit) ( UChar*, Int, HInstr* );
sewardj84ff0652004-08-23 16:16:08 +0000187 IRExpr* (*specHelper) ( Char*, IRExpr** );
sewardj8d2291c2004-10-25 14:50:21 +0000188 Bool (*preciseMemExnsFn) ( Int, Int );
sewardjf13a16a2004-07-05 17:10:14 +0000189
sewardjeeac8412004-11-02 00:26:55 +0000190 VexGuestLayout* guest_layout;
191 Bool host_is_bigendian = False;
192 IRBB* irbb;
193 HInstrArray* vcode;
194 HInstrArray* rcode;
195 Int i, j, k, out_used, guest_sizeB;
196 UChar insn_bytes[32];
sewardjcf787902004-11-03 09:08:33 +0000197 IRType guest_word_type;
198 IRType host_word_type;
sewardjf13a16a2004-07-05 17:10:14 +0000199
sewardj49651f42004-10-28 22:11:04 +0000200 guest_layout = NULL;
sewardj36ca5132004-07-24 13:12:23 +0000201 available_real_regs = NULL;
202 n_available_real_regs = 0;
203 isMove = NULL;
204 getRegUsage = NULL;
205 mapRegs = NULL;
206 genSpill = NULL;
207 genReload = NULL;
208 ppInstr = NULL;
209 ppReg = NULL;
210 iselBB = NULL;
211 bbToIR = NULL;
212 emit = NULL;
sewardj84ff0652004-08-23 16:16:08 +0000213 specHelper = NULL;
sewardj8d2291c2004-10-25 14:50:21 +0000214 preciseMemExnsFn = NULL;
sewardjcf787902004-11-03 09:08:33 +0000215 guest_word_type = Ity_INVALID;
216 host_word_type = Ity_INVALID;
sewardj36ca5132004-07-24 13:12:23 +0000217
sewardjf48ac192004-10-29 00:41:29 +0000218 vex_traceflags = traceflags;
sewardj58800ff2004-07-28 01:51:10 +0000219
sewardj35421a32004-07-05 13:12:34 +0000220 vassert(vex_initdone);
sewardj443cd9d2004-07-18 23:06:45 +0000221 LibVEX_ClearTemporary(False);
sewardjf13a16a2004-07-05 17:10:14 +0000222
sewardj2a9ad022004-11-25 02:46:58 +0000223
sewardjf13a16a2004-07-05 17:10:14 +0000224 /* First off, check that the guest and host insn sets
225 are supported. */
sewardj2a9ad022004-11-25 02:46:58 +0000226
sewardjf13a16a2004-07-05 17:10:14 +0000227 switch (iset_host) {
sewardj2a9ad022004-11-25 02:46:58 +0000228
sewardjf13a16a2004-07-05 17:10:14 +0000229 case InsnSetX86:
230 getAllocableRegs_X86 ( &n_available_real_regs,
231 &available_real_regs );
232 isMove = (Bool(*)(HInstr*,HReg*,HReg*)) isMove_X86Instr;
233 getRegUsage = (void(*)(HRegUsage*,HInstr*)) getRegUsage_X86Instr;
234 mapRegs = (void(*)(HRegRemap*,HInstr*)) mapRegs_X86Instr;
235 genSpill = (HInstr*(*)(HReg,Int)) genSpill_X86;
236 genReload = (HInstr*(*)(HReg,Int)) genReload_X86;
sewardj2b515872004-07-05 20:50:45 +0000237 ppInstr = (void(*)(HInstr*)) ppX86Instr;
238 ppReg = (void(*)(HReg)) ppHRegX86;
sewardjf13a16a2004-07-05 17:10:14 +0000239 iselBB = iselBB_X86;
sewardj81bd5502004-07-21 18:49:27 +0000240 emit = (Int(*)(UChar*,Int,HInstr*)) emit_X86Instr;
sewardjc9a65702004-07-07 16:32:57 +0000241 host_is_bigendian = False;
sewardjcf787902004-11-03 09:08:33 +0000242 host_word_type = Ity_I32;
sewardjf13a16a2004-07-05 17:10:14 +0000243 break;
sewardj2a9ad022004-11-25 02:46:58 +0000244
sewardjf13a16a2004-07-05 17:10:14 +0000245 default:
sewardj887a11a2004-07-05 17:26:47 +0000246 vpanic("LibVEX_Translate: unsupported target insn set");
sewardjf13a16a2004-07-05 17:10:14 +0000247 }
248
sewardj2a9ad022004-11-25 02:46:58 +0000249
sewardjf13a16a2004-07-05 17:10:14 +0000250 switch (iset_guest) {
sewardj2a9ad022004-11-25 02:46:58 +0000251
sewardjf13a16a2004-07-05 17:10:14 +0000252 case InsnSetX86:
sewardj8d2291c2004-10-25 14:50:21 +0000253 preciseMemExnsFn = guest_x86_state_requires_precise_mem_exns;
sewardj2a9ad022004-11-25 02:46:58 +0000254 bbToIR = bbToIR_X86;
255 specHelper = guest_x86_spechelper;
sewardj81ec4182004-10-25 23:15:52 +0000256 guest_sizeB = sizeof(VexGuestX86State);
sewardjcf787902004-11-03 09:08:33 +0000257 guest_word_type = Ity_I32;
sewardj49651f42004-10-28 22:11:04 +0000258 guest_layout = &x86guest_layout;
sewardjf13a16a2004-07-05 17:10:14 +0000259 break;
sewardj2a9ad022004-11-25 02:46:58 +0000260
261 case InsnSetARM:
262 preciseMemExnsFn = guest_arm_state_requires_precise_mem_exns;
263 bbToIR = NULL; /*bbToIR_ARM;*/
264 specHelper = guest_arm_spechelper;
265 guest_sizeB = sizeof(VexGuestARMState);
266 guest_word_type = Ity_I32;
267 guest_layout = &armGuest_layout;
268 break;
269
sewardjf13a16a2004-07-05 17:10:14 +0000270 default:
sewardj887a11a2004-07-05 17:26:47 +0000271 vpanic("LibVEX_Translate: unsupported guest insn set");
sewardjf13a16a2004-07-05 17:10:14 +0000272 }
273
sewardj2a9ad022004-11-25 02:46:58 +0000274
sewardjf48ac192004-10-29 00:41:29 +0000275 if (vex_traceflags & VEX_TRACE_FE)
276 vex_printf("\n------------------------"
277 " Front end "
278 "------------------------\n\n");
279
sewardjf13a16a2004-07-05 17:10:14 +0000280 irbb = bbToIR ( guest_bytes,
281 guest_bytes_addr,
282 guest_bytes_read,
sewardjc9a65702004-07-07 16:32:57 +0000283 byte_accessible,
sewardj5bd4d162004-11-10 13:02:48 +0000284 chase_into_ok,
sewardjc9a65702004-07-07 16:32:57 +0000285 host_is_bigendian );
sewardjf13a16a2004-07-05 17:10:14 +0000286
287 if (irbb == NULL) {
288 /* Access failure. */
sewardj443cd9d2004-07-18 23:06:45 +0000289 LibVEX_ClearTemporary(False);
sewardjf48ac192004-10-29 00:41:29 +0000290 vex_traceflags = 0;
sewardjf13a16a2004-07-05 17:10:14 +0000291 return TransAccessFail;
292 }
sewardjaa59f942004-10-09 09:34:36 +0000293
294 /* If debugging, show the raw guest bytes for this bb. */
sewardjf48ac192004-10-29 00:41:29 +0000295 if (vex_traceflags & VEX_TRACE_FE) {
sewardjaa59f942004-10-09 09:34:36 +0000296 UChar* p = guest_bytes;
sewardjaa59f942004-10-09 09:34:36 +0000297 vex_printf(". 0 %llx %d\n.", guest_bytes_addr, *guest_bytes_read );
298 for (i = 0; i < *guest_bytes_read; i++)
299 vex_printf(" %02x", (Int)p[i] );
sewardjf48ac192004-10-29 00:41:29 +0000300 vex_printf("\n\n");
sewardjaa59f942004-10-09 09:34:36 +0000301 }
302
303 /* Sanity check the initial IR. */
sewardjcf787902004-11-03 09:08:33 +0000304 sanityCheckIRBB(irbb, guest_word_type);
sewardje8e9d732004-07-16 21:03:45 +0000305
sewardjedf4d692004-08-17 13:52:58 +0000306 /* Clean it up, hopefully a lot. */
sewardj8d2291c2004-10-25 14:50:21 +0000307 irbb = do_iropt_BB ( irbb, specHelper, preciseMemExnsFn,
308 guest_bytes_addr );
sewardjcf787902004-11-03 09:08:33 +0000309 sanityCheckIRBB(irbb, guest_word_type);
sewardjedf4d692004-08-17 13:52:58 +0000310
sewardjf48ac192004-10-29 00:41:29 +0000311 if (vex_traceflags & VEX_TRACE_OPT1) {
312 vex_printf("\n------------------------"
313 " After pre-instr IR optimisation "
314 "------------------------\n\n");
sewardjedf4d692004-08-17 13:52:58 +0000315 ppIRBB ( irbb );
316 vex_printf("\n");
317 }
318
sewardjf13a16a2004-07-05 17:10:14 +0000319 /* Get the thing instrumented. */
sewardj49651f42004-10-28 22:11:04 +0000320 if (instrument1)
sewardjcf787902004-11-03 09:08:33 +0000321 irbb = (*instrument1)(irbb, guest_layout, host_word_type);
sewardj49651f42004-10-28 22:11:04 +0000322 if (instrument2)
sewardjcf787902004-11-03 09:08:33 +0000323 irbb = (*instrument2)(irbb, guest_layout, host_word_type);
sewardj49651f42004-10-28 22:11:04 +0000324
sewardjf48ac192004-10-29 00:41:29 +0000325 if (vex_traceflags & VEX_TRACE_INST) {
326 vex_printf("\n------------------------"
327 " After instrumentation "
328 "------------------------\n\n");
329 ppIRBB ( irbb );
330 vex_printf("\n");
331 }
332
sewardj49651f42004-10-28 22:11:04 +0000333 if (instrument1 || instrument2)
sewardjcf787902004-11-03 09:08:33 +0000334 sanityCheckIRBB(irbb, guest_word_type);
sewardjf13a16a2004-07-05 17:10:14 +0000335
sewardj9578a8b2004-11-04 19:44:48 +0000336 /* Do a post-instrumentation cleanup pass. */
337 if (cleanup_after_instrumentation) {
338 do_deadcode_BB( irbb );
339 irbb = cprop_BB( irbb );
340 do_deadcode_BB( irbb );
341 sanityCheckIRBB(irbb, guest_word_type);
342 }
343
344 if (vex_traceflags & VEX_TRACE_OPT2) {
345 vex_printf("\n------------------------"
346 " After post-instr IR optimisation "
347 "------------------------\n\n");
348 ppIRBB ( irbb );
349 vex_printf("\n");
350 }
351
sewardjf13a16a2004-07-05 17:10:14 +0000352 /* Turn it into virtual-registerised code. */
sewardj49651f42004-10-28 22:11:04 +0000353 do_deadcode_BB( irbb );
354 do_treebuild_BB( irbb );
sewardjf48ac192004-10-29 00:41:29 +0000355
356 if (vex_traceflags & VEX_TRACE_TREES) {
357 vex_printf("\n------------------------"
358 " After tree-building "
359 "------------------------\n\n");
360 ppIRBB ( irbb );
361 vex_printf("\n");
362 }
363
364 if (vex_traceflags & VEX_TRACE_VCODE)
365 vex_printf("\n------------------------"
366 " Instruction selection "
367 "------------------------\n");
368
sewardj8ea867b2004-10-30 19:03:02 +0000369 vcode = iselBB ( irbb );
sewardjf13a16a2004-07-05 17:10:14 +0000370
sewardjf48ac192004-10-29 00:41:29 +0000371 if (vex_traceflags & VEX_TRACE_VCODE)
372 vex_printf("\n");
373
sewardjf48ac192004-10-29 00:41:29 +0000374 if (vex_traceflags & VEX_TRACE_VCODE) {
sewardj1f40a0a2004-07-21 12:28:07 +0000375 for (i = 0; i < vcode->arr_used; i++) {
376 vex_printf("%3d ", i);
377 ppInstr(vcode->arr[i]);
378 vex_printf("\n");
379 }
sewardjfbcaf332004-07-08 01:46:01 +0000380 vex_printf("\n");
381 }
sewardjfbcaf332004-07-08 01:46:01 +0000382
sewardjf13a16a2004-07-05 17:10:14 +0000383 /* Register allocate. */
384 rcode = doRegisterAllocation ( vcode, available_real_regs,
385 n_available_real_regs,
386 isMove, getRegUsage, mapRegs,
sewardj81ec4182004-10-25 23:15:52 +0000387 genSpill, genReload, guest_sizeB,
sewardj2b515872004-07-05 20:50:45 +0000388 ppInstr, ppReg );
sewardjf13a16a2004-07-05 17:10:14 +0000389
sewardjf48ac192004-10-29 00:41:29 +0000390 if (vex_traceflags & VEX_TRACE_RCODE) {
391 vex_printf("\n------------------------"
392 " Register-allocated code "
393 "------------------------\n\n");
sewardj1f40a0a2004-07-21 12:28:07 +0000394 for (i = 0; i < rcode->arr_used; i++) {
395 vex_printf("%3d ", i);
396 ppInstr(rcode->arr[i]);
397 vex_printf("\n");
398 }
sewardjfbcaf332004-07-08 01:46:01 +0000399 vex_printf("\n");
400 }
sewardjfbcaf332004-07-08 01:46:01 +0000401
sewardj81bd5502004-07-21 18:49:27 +0000402 /* Assemble */
sewardjf48ac192004-10-29 00:41:29 +0000403 if (vex_traceflags & VEX_TRACE_ASM) {
404 vex_printf("\n------------------------"
405 " Assembly "
406 "------------------------\n\n");
407 }
408
sewardj81bd5502004-07-21 18:49:27 +0000409 out_used = 0; /* tracks along the host_bytes array */
410 for (i = 0; i < rcode->arr_used; i++) {
sewardjf48ac192004-10-29 00:41:29 +0000411 if (vex_traceflags & VEX_TRACE_ASM) {
sewardjbad34a92004-07-22 01:14:11 +0000412 ppInstr(rcode->arr[i]);
413 vex_printf("\n");
414 }
sewardj81bd5502004-07-21 18:49:27 +0000415 j = (*emit)( insn_bytes, 32, rcode->arr[i] );
sewardjf48ac192004-10-29 00:41:29 +0000416 if (vex_traceflags & VEX_TRACE_ASM) {
sewardjbad34a92004-07-22 01:14:11 +0000417 for (k = 0; k < j; k++)
sewardj86898e82004-07-22 17:26:12 +0000418 if (insn_bytes[k] < 16)
419 vex_printf("0%x ", (UInt)insn_bytes[k]);
420 else
421 vex_printf("%x ", (UInt)insn_bytes[k]);
sewardjbad34a92004-07-22 01:14:11 +0000422 vex_printf("\n\n");
423 }
sewardj81bd5502004-07-21 18:49:27 +0000424 if (out_used + j > host_bytes_size) {
425 LibVEX_ClearTemporary(False);
sewardjf48ac192004-10-29 00:41:29 +0000426 vex_traceflags = 0;
sewardj81bd5502004-07-21 18:49:27 +0000427 return TransOutputFull;
428 }
429 for (k = 0; k < j; k++) {
430 host_bytes[out_used] = insn_bytes[k];
431 out_used++;
432 }
433 vassert(out_used <= host_bytes_size);
434 }
435 *host_bytes_used = out_used;
436
sewardj1f40a0a2004-07-21 12:28:07 +0000437 LibVEX_ClearTemporary(False);
sewardjf13a16a2004-07-05 17:10:14 +0000438
sewardjf48ac192004-10-29 00:41:29 +0000439 vex_traceflags = 0;
sewardj35421a32004-07-05 13:12:34 +0000440 return TransOK;
441}
442
443
444
445/*---------------------------------------------------------------*/
sewardjc0ee2ed2004-07-27 10:29:41 +0000446/*--- end main/vex_main.c ---*/
sewardj35421a32004-07-05 13:12:34 +0000447/*---------------------------------------------------------------*/