Skip to content

Commit

Permalink
[Reflect] Add accessor method to get list of instructions from a pack…
Browse files Browse the repository at this point in the history
…file.
  • Loading branch information
Whiteknight committed Feb 24, 2012
1 parent 74612ad commit c913d45
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/reflect/Deserializer.winxed
Expand Up @@ -32,10 +32,25 @@ class Rosella.Reflect.Deserializer
function get_bytecode_raw(var bc_seg, int start_offs, int end_offs)
{
int bc[] = [];
for (int i = start_offs; i < elements(bc_seg) && i < end_offs; i++) {
int val = bc_seg[i];
bc[i - start_offs] = val;

if (start_offs > end_offs ||
(start_offs == end_offs && start_offs != 0) ||
start_offs > elements(bc_seg) || end_offs > elements(bc_seg) ||
start_offs < 0 || end_offs < 0)
Rosella.Error.invalid(__FUNCTION__, "Cannot get bytecode from offset range [%d, %d]", start_offs, end_offs);

if (start_offs == 0 && end_offs == 0) {
for (int i = start_offs; i < elements(bc_seg); i++) {
int val = bc_seg[i];
bc[i - start_offs] = val;
}
} else if (start_offs != end_offs) {
for (int i = start_offs; i < elements(bc_seg) && i < end_offs; i++) {
int val = bc_seg[i];
bc[i - start_offs] = val;
}
}

return bc;
}

Expand Down
7 changes: 7 additions & 0 deletions src/reflect/Module.winxed
Expand Up @@ -31,6 +31,7 @@ class Rosella.Reflect.Module
var classes; // A list of all classes defined at compile-time
var namespaces; // A list of all namespaces defined at compile-time
var functions_by_ns; // A hash of functions arranged by namespace
var instructions; // A listing of disassembled opcodes

// Constructor. Take an existing PackfileView
function Module(var pf)
Expand Down Expand Up @@ -153,4 +154,10 @@ class Rosella.Reflect.Module
self.functions = functions;
self.functions_by_ns = functions_by_ns;
}

function get_instructions()
{
var d = new Rosella.Reflect.Deserializer();
return d.get_instructions(self.pf, 0, 0);
}
}

0 comments on commit c913d45

Please sign in to comment.