Skip to content

Commit

Permalink
Emit commented-out method body with raw hex bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberShadow committed May 11, 2011
1 parent e6f54db commit a766cf5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions abcfile.d
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class ABCFile
TraitsInfo[] traits;

string error;
ubyte[] rawBytes;
}

/// Destination for a jump or exception block boundary
Expand Down Expand Up @@ -1280,6 +1281,7 @@ private final class ABCReader

size_t len = readU30();
uint[] instructionAtOffset = new uint[len];
r.rawBytes = buf[pos..pos+len];

void translateLabel(ref ABCFile.Label label)
{
Expand Down
2 changes: 2 additions & 0 deletions asprogram.d
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ final class ASProgram
Trait[] traits;

string error;
ubyte[] rawBytes;
}

struct Instruction
Expand Down Expand Up @@ -581,6 +582,7 @@ private final class ABCtoAS
}
n.traits = convertTraits(vbody.traits);
n.error = vbody.error;
n.rawBytes = vbody.rawBytes;
return n;
}

Expand Down
23 changes: 19 additions & 4 deletions disassembler.d
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ final class StringBuilder

int indent;
bool indented;
string linePrefix;

void newLine()
{
Expand All @@ -91,6 +92,8 @@ final class StringBuilder
for (int i=0; i<indent; i++)
this ~= ' ';
indented = true;
if (linePrefix)
this ~= linePrefix;
}
}
}
Expand Down Expand Up @@ -1148,6 +1151,13 @@ final class Disassembler

void dumpMethodBody(StringBuilder sb, ASProgram.MethodBody mbody)
{
if (mbody.error)
{
sb ~= "; Error while disassembling method: " ~ mbody.error;
sb.newLine();
sb.linePrefix = "; ";
}

sb ~= "body";
sb.indent++; sb.newLine();
dumpUIntField(sb, "maxstack", mbody.maxStack);
Expand All @@ -1164,10 +1174,14 @@ final class Disassembler

sb.indent++;
if (mbody.error)
{
sb ~= "; Error while disassembling method: " ~ mbody.error;
sb.newLine();
}
foreach (i, b; mbody.rawBytes)
{
sb ~= format("0x%02X", b);
if (i%16==15 || i==mbody.rawBytes.length-1)
sb.newLine();
else
sb ~= " ";
}
else
dumpInstructions(sb, mbody.instructions, labels);
sb.indent--;
Expand All @@ -1191,6 +1205,7 @@ final class Disassembler
}
dumpTraits(sb, mbody.traits);
sb.indent--; sb ~= "end ; body"; sb.newLine();
sb.linePrefix = null;
}

void dumpInstructions(StringBuilder sb, ASProgram.Instruction[] instructions, bool[] labels)
Expand Down

0 comments on commit a766cf5

Please sign in to comment.