Merged.
[cacao.git] / src / vm / jit / intrp / disass.cpp
1 /* src/vm/jit/intrp/disass.c - disassembler wrapper for interpreter
2
3    Copyright (C) 1996-2005, 2006, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <stdio.h>
29
30 #include "vm/types.h"
31
32 #include "vm/jit/intrp/intrp.h"
33
34
35 /* function disassinstr ********************************************************
36
37         outputs a disassembler listing of one machine code instruction on 'stdout'
38         c:   instructions machine code
39
40 *******************************************************************************/
41
42 u1 *intrp_disassinstr(u1 *code)
43 {
44         FILE *savedout;
45         u1   *r;
46
47         savedout = vm_out;
48         vm_out = stdout;
49         r = (u1 *) vm_disassemble_inst((Inst *) code, vm_prim);
50         vm_out = savedout;
51
52         return r;
53 }
54
55
56 /* function disassemble ********************************************************
57
58         outputs a disassembler listing of some machine code on 'stdout'
59         code: pointer to first instruction
60         len:  code size (number of instructions * 4)
61
62 *******************************************************************************/
63
64 void intrp_disassemble(u1 *start, u1 *end)
65 {
66         FILE *savedout;
67
68         printf("  --- disassembler listing ---\n");
69         savedout = vm_out;
70         vm_out = stdout;
71         vm_disassemble((Inst *) start, (Inst *) end, vm_prim);
72         vm_out = savedout;
73 }
74
75
76 void printarg_ui      (u4                 ui      )
77 {
78         fprintf(vm_out, "%ud", ui);
79 }
80
81 void printarg_v       (Cell               v       )
82 {
83         fprintf(vm_out, "%lld", (long long)v);
84 }
85
86 void printarg_Cell    (Cell               x       )
87 {
88         fprintf(vm_out, "%lld", (long long)x);
89 }
90
91
92 void printarg_b       (s4                 b       )
93 {
94         fprintf(vm_out, "%d", b);
95 }
96
97 void printarg_s       (s4                 s       )
98 {
99         fprintf(vm_out, "%d", s);
100 }
101
102 void printarg_i       (s4                 i       )
103 {
104         fprintf(vm_out, "%d", i);
105 }
106
107 void printarg_l       (s8                 l       )
108 {
109         fprintf(vm_out, "%lld", (long long)l);
110 }
111
112 void printarg_f       (float              f       )
113 {
114         fprintf(vm_out, "%f", (double)f);
115 }
116
117 void printarg_d       (double             d       )
118 {
119         fprintf(vm_out, "%f", d);
120 }
121
122 void printarg_aRef    (java_objectheader *aRef    )
123 {
124         fprintf(vm_out, "obj: %p", (void *)aRef);
125 }
126
127 void printarg_aArray  (java_arrayheader * aArray  )
128 {
129         fprintf(vm_out, "array %p", (void *)aArray);
130 }
131
132 void printarg_aaTarget(Inst **            aaTarget)
133 {
134         if (aaTarget) {
135                 methodinfo *m=((methodinfo **)aaTarget)[3];
136                 printarg_am(m);
137         } else
138                 fprintf(vm_out, "NULL");
139 }
140
141 void printarg_aClass  (classinfo *        aClass  )
142 {
143         if (aClass)
144                 utf_fprint_printable_ascii_classname(vm_out, aClass->name);
145         else
146                 fprintf(vm_out, "NULL");
147 }
148
149 void printarg_acr     (constant_classref *acr     )
150 {
151         fprintf(vm_out, "cr: %p", (void *)acr);
152 }
153
154 void printarg_addr    (u1 *               addr    )
155 {
156         fprintf(vm_out, "%p", (void *)addr);
157 }
158
159 void printarg_af      (functionptr        af      )
160 {
161         fprintf(vm_out, "f: %p", (void *)af);
162 }
163
164 void printarg_afi     (fieldinfo *        afi      )
165 {
166         if (afi) {
167                 utf_fprint_printable_ascii_classname(vm_out, afi->clazz->name);
168                 fprintf(vm_out, ".");
169                 utf_fprint_printable_ascii(vm_out, afi->name);
170                 utf_fprint_printable_ascii(vm_out, afi->descriptor);
171         } else
172                 fprintf(vm_out, "fi=NULL");
173 }
174
175 void printarg_am      (methodinfo *       am      )
176 {
177         if (am) {
178                 utf_fprint_printable_ascii_classname(vm_out, am->clazz->name);
179                 fprintf(vm_out, ".");
180                 utf_fprint_printable_ascii(vm_out, am->name);
181                 utf_fprint_printable_ascii(vm_out, am->descriptor);
182         } else
183                 fprintf(vm_out, "m=NULL");
184 }
185
186 void printarg_acell   (Cell *             acell   )
187 {
188         fprintf(vm_out, "%p", (void *)acell);
189 }
190
191 void printarg_ainst   (Inst *             ainst   )
192 {
193         fprintf(vm_out, "%p", (void *)ainst);
194 }
195
196 void printarg_auf     (unresolved_field * auf     )
197 {
198         if (auf) {
199                 utf_fprint_printable_ascii(vm_out, auf->fieldref->name);
200                 fprintf(vm_out, " (type ");
201                 utf_fprint_printable_ascii(vm_out, auf->fieldref->descriptor);
202                 fprintf(vm_out, ")");
203         } else
204                 fprintf(vm_out, "NULL");
205 }
206
207 void printarg_aum     (unresolved_method *aum     )
208 {
209         if (aum) {
210                 utf_fprint_printable_ascii_classname(vm_out, METHODREF_CLASSNAME(aum->methodref));
211                 fprintf(vm_out, ".");
212                 utf_fprint_printable_ascii(vm_out, aum->methodref->name);
213                 utf_fprint_printable_ascii(vm_out, aum->methodref->descriptor);
214         } else
215                 fprintf(vm_out, "NULL");
216 }
217
218 void printarg_avftbl  (vftbl_t *          avftbl  )
219 {
220         if (avftbl) {
221                 fprintf(vm_out, "vftbl: ");
222                 utf_fprint_printable_ascii_classname(vm_out, avftbl->class->name);
223         } else
224                 fprintf(vm_out, "NULL");
225 }
226
227
228 /*
229  * These are local overrides for various environment variables in Emacs.
230  * Please do not remove this and leave it at the end of the file, where
231  * Emacs will automagically detect them.
232  * ---------------------------------------------------------------------
233  * Local variables:
234  * mode: c++
235  * indent-tabs-mode: t
236  * c-basic-offset: 4
237  * tab-width: 4
238  * End:
239  * vim:noexpandtab:sw=4:ts=4:
240  */