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