Skip to content

Commit

Permalink
Keep track of the Sub start and end offsets. While dumping bytecode, …
Browse files Browse the repository at this point in the history
…print out where the individual subroutines start/stop. This helps give us some valuable landmarks while reading the bytecode dump
  • Loading branch information
Whiteknight committed Nov 17, 2011
1 parent fb2b25d commit 53bd5d5
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/disasm.winxed
Expand Up @@ -18,6 +18,7 @@ namespace PACT {
var nums;
var pmcs;
var strings;
var subs;

// Debug mappings
var debug_files;
Expand Down Expand Up @@ -115,9 +116,23 @@ namespace PACT {

size = constants.pmc_count();
var pmcs = new 'FixedPMCArray'(size);
var subs = [];
self.pmcs = pmcs;
for (i = 0; i < size; ++i)
pmcs[i] = var(constants[i]);
self.subs = subs;
for (i = 0; i < size; ++i) {
var c = var(constants[i]);
pmcs[i] = c;
if (c instanceof 'Sub')
push(subs, c);
}
// Make sure the subs are sorted according to the code offsets
subs.sort(function(a, b) {
int a_i = a.start_offs();
int b_i = b.start_offs();
if (a_i == b_i) return 0;
if (a_i < b_i) return -1;
return 1;
});

size = constants.str_count();
var strings = new 'FixedStringArray'(size);
Expand Down Expand Up @@ -252,7 +267,8 @@ function print_arg(var packfile, int type, int arg, int pc, int had_named) {
}

function bytecode_segment(var packfile) {
int i, size;
int i, size, sub_idx = -1, sub_start_idx, sub_end_idx = -1;
var current_sub;

say( ' Oplibs:' );
var oplibs = packfile.oplibs;
Expand All @@ -276,6 +292,14 @@ function bytecode_segment(var packfile) {
size = elements(bytecode);

for (i = 0; i < size; ++i) {
if (i >= sub_end_idx) {
sub_idx++;
current_sub = packfile.subs[sub_idx];
sub_start_idx = current_sub.start_offs();
sub_end_idx = current_sub.end_offs();
}
if (i == sub_start_idx) say(sprintf(' Subroutine: %s (%d - %d)', [current_sub, sub_start_idx, sub_end_idx]));

var op = opmap[bytecode[i]];
string name = op.family_name();
print( ' ', sprintf('%3d', [i] ), ': ', name );
Expand Down

0 comments on commit 53bd5d5

Please sign in to comment.