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