Skip to content

Commit 781977d

Browse files
joshuawarner32Joshua Warner
authored andcommitted
add debug-util for printing java bytecode as it's compiled
1 parent 2e40d38 commit 781977d

File tree

4 files changed

+675
-1
lines changed

4 files changed

+675
-1
lines changed

makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,7 @@ embed-objects = $(call cpp-objects,$(embed-sources),$(src),$(build-embed))
11251125
compiler-sources = \
11261126
$(src)/codegen/compiler.cpp \
11271127
$(wildcard $(src)/codegen/compiler/*.cpp) \
1128+
$(src)/debug-util.cpp \
11281129
$(src)/codegen/registers.cpp \
11291130
$(src)/codegen/runtime.cpp \
11301131
$(src)/codegen/targets.cpp \

src/compile.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include <avian/util/slice.h>
2828
#include <avian/util/fixed-allocator.h>
2929

30+
#include "debug-util.h"
31+
3032
using namespace vm;
3133

3234
extern "C" uint64_t
@@ -56,6 +58,7 @@ const bool DebugNatives = false;
5658
const bool DebugCallTable = false;
5759
const bool DebugMethodTree = false;
5860
const bool DebugFrameMaps = false;
61+
const bool DebugInstructions = false;
5962

6063
const bool CheckArrayBounds = true;
6164

@@ -4189,9 +4192,35 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
41894192
1,
41904193
c->threadRegister());
41914194
}
4192-
4195+
41934196
// fprintf(stderr, "ip: %d map: %ld\n", ip, *(frame->map));
41944197

4198+
if (DebugInstructions) {
4199+
unsigned startingIp = ip;
4200+
// TODO: fix stack printing
4201+
fprintf(stderr, " stack: [");
4202+
for (size_t i = frame->localSize(); i < frame->sp; i++) {
4203+
switch (frame->get(i)) {
4204+
case Frame::Integer:
4205+
fprintf(stderr, "I");
4206+
break;
4207+
case Frame::Long:
4208+
fprintf(stderr, "L");
4209+
break;
4210+
case Frame::Object:
4211+
fprintf(stderr, "O");
4212+
break;
4213+
default:
4214+
fprintf(stderr, "?");
4215+
break;
4216+
}
4217+
}
4218+
fprintf(stderr, "]\n");
4219+
fprintf(stderr, "% 5d: ", startingIp);
4220+
avian::jvm::debug::printInstruction(&codeBody(t, code, 0), startingIp);
4221+
fprintf(stderr, "\n");
4222+
}
4223+
41954224
unsigned instruction = codeBody(t, code, ip++);
41964225

41974226
switch (instruction) {

0 commit comments

Comments
 (0)