* Removed all Id tags.
[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 */
35
36
37 #include "config.h"
38
39 #include <stdio.h>
40
41 #include "vm/types.h"
42
43 #include "vm/jit/intrp/intrp.h"
44
45
46 /* function disassinstr ********************************************************
47
48         outputs a disassembler listing of one machine code instruction on 'stdout'
49         c:   instructions machine code
50
51 *******************************************************************************/
52
53 u1 *intrp_disassinstr(u1 *code)
54 {
55         FILE *savedout;
56         u1   *r;
57
58         savedout = vm_out;
59         vm_out = stdout;
60         r = (u1 *) vm_disassemble_inst((Inst *) code, vm_prim);
61         vm_out = savedout;
62
63         return r;
64 }
65
66
67 /* function disassemble ********************************************************
68
69         outputs a disassembler listing of some machine code on 'stdout'
70         code: pointer to first instruction
71         len:  code size (number of instructions * 4)
72
73 *******************************************************************************/
74
75 void intrp_disassemble(u1 *start, u1 *end)
76 {
77         FILE *savedout;
78
79         printf("  --- disassembler listing ---\n");
80         savedout = vm_out;
81         vm_out = stdout;
82         vm_disassemble((Inst *) start, (Inst *) end, vm_prim);
83         vm_out = savedout;
84 }
85
86
87 void printarg_ui      (u4                 ui      )
88 {
89         fprintf(vm_out, "%ud", ui);
90 }
91
92 void printarg_v       (Cell               v       )
93 {
94         fprintf(vm_out, "%lld", (long long)v);
95 }
96
97 void printarg_Cell    (Cell               x       )
98 {
99         fprintf(vm_out, "%lld", (long long)x);
100 }
101
102
103 void printarg_b       (s4                 b       )
104 {
105         fprintf(vm_out, "%d", b);
106 }
107
108 void printarg_s       (s4                 s       )
109 {
110         fprintf(vm_out, "%d", s);
111 }
112
113 void printarg_i       (s4                 i       )
114 {
115         fprintf(vm_out, "%d", i);
116 }
117
118 void printarg_l       (s8                 l       )
119 {
120         fprintf(vm_out, "%lld", (long long)l);
121 }
122
123 void printarg_f       (float              f       )
124 {
125         fprintf(vm_out, "%f", (double)f);
126 }
127
128 void printarg_d       (double             d       )
129 {
130         fprintf(vm_out, "%f", d);
131 }
132
133 void printarg_aRef    (java_objectheader *aRef    )
134 {
135         fprintf(vm_out, "obj: %p", (void *)aRef);
136 }
137
138 void printarg_aArray  (java_arrayheader * aArray  )
139 {
140         fprintf(vm_out, "array %p", (void *)aArray);
141 }
142
143 void printarg_aaTarget(Inst **            aaTarget)
144 {
145         if (aaTarget) {
146                 methodinfo *m=((methodinfo **)aaTarget)[3];
147                 printarg_am(m);
148         } else
149                 fprintf(vm_out, "NULL");
150 }
151
152 void printarg_aClass  (classinfo *        aClass  )
153 {
154         if (aClass)
155                 utf_fprint_printable_ascii_classname(vm_out, aClass->name);
156         else
157                 fprintf(vm_out, "NULL");
158 }
159
160 void printarg_acr     (constant_classref *acr     )
161 {
162         fprintf(vm_out, "cr: %p", (void *)acr);
163 }
164
165 void printarg_addr    (u1 *               addr    )
166 {
167         fprintf(vm_out, "%p", (void *)addr);
168 }
169
170 void printarg_af      (functionptr        af      )
171 {
172         fprintf(vm_out, "f: %p", (void *)af);
173 }
174
175 void printarg_afi     (fieldinfo *        afi      )
176 {
177         if (afi) {
178                 utf_fprint_printable_ascii_classname(vm_out, afi->class->name);
179                 fprintf(vm_out, ".");
180                 utf_fprint_printable_ascii(vm_out, afi->name);
181                 utf_fprint_printable_ascii(vm_out, afi->descriptor);
182         } else
183                 fprintf(vm_out, "fi=NULL");
184 }
185
186 void printarg_am      (methodinfo *       am      )
187 {
188         if (am) {
189                 utf_fprint_printable_ascii_classname(vm_out, am->class->name);
190                 fprintf(vm_out, ".");
191                 utf_fprint_printable_ascii(vm_out, am->name);
192                 utf_fprint_printable_ascii(vm_out, am->descriptor);
193         } else
194                 fprintf(vm_out, "m=NULL");
195 }
196
197 void printarg_acell   (Cell *             acell   )
198 {
199         fprintf(vm_out, "%p", (void *)acell);
200 }
201
202 void printarg_ainst   (Inst *             ainst   )
203 {
204         fprintf(vm_out, "%p", (void *)ainst);
205 }
206
207 void printarg_auf     (unresolved_field * auf     )
208 {
209         if (auf) {
210                 utf_fprint_printable_ascii(vm_out, auf->fieldref->name);
211                 fprintf(vm_out, " (type ");
212                 utf_fprint_printable_ascii(vm_out, auf->fieldref->descriptor);
213                 fprintf(vm_out, ")");
214         } else
215                 fprintf(vm_out, "NULL");
216 }
217
218 void printarg_aum     (unresolved_method *aum     )
219 {
220         if (aum) {
221                 utf_fprint_printable_ascii_classname(vm_out, METHODREF_CLASSNAME(aum->methodref));
222                 fprintf(vm_out, ".");
223                 utf_fprint_printable_ascii(vm_out, aum->methodref->name);
224                 utf_fprint_printable_ascii(vm_out, aum->methodref->descriptor);
225         } else
226                 fprintf(vm_out, "NULL");
227 }
228
229 void printarg_avftbl  (vftbl_t *          avftbl  )
230 {
231         if (avftbl) {
232                 fprintf(vm_out, "vftbl: ");
233                 utf_fprint_printable_ascii_classname(vm_out, avftbl->class->name);
234         } else
235                 fprintf(vm_out, "NULL");
236 }
237
238
239 /*
240  * These are local overrides for various environment variables in Emacs.
241  * Please do not remove this and leave it at the end of the file, where
242  * Emacs will automagically detect them.
243  * ---------------------------------------------------------------------
244  * Local variables:
245  * mode: c
246  * indent-tabs-mode: t
247  * c-basic-offset: 4
248  * tab-width: 4
249  * End:
250  * vim:noexpandtab:sw=4:ts=4:
251  */