Browse Source

Tweaks in the format of the output (place an empty line between commands)

pull/1/head^2
David Srbecký 18 years ago
parent
commit
35fcc443e6
  1. 25
      src/CodeDomBuilder.cs
  2. 11
      src/CodeDomMetodBodyBuilder.cs

25
src/CodeDomBuilder.cs

@ -37,6 +37,31 @@ namespace Decompiler
code = code.Remove(0, code.IndexOf("\r\n") + "\r\n".Length); code = code.Remove(0, code.IndexOf("\r\n") + "\r\n".Length);
} }
// Post processing commands
while(true) {
int endIndex = code.IndexOf("[JoinLine]") + "[JoinLine]".Length;
if (endIndex != -1) {
int startIndex = code.LastIndexOf("\r\n", endIndex, endIndex);
if (startIndex != -1) {
code = code.Remove(startIndex, endIndex - startIndex);
continue;
}
}
break;
}
while(true) {
int endIndex = code.IndexOf("[Tab]");
if (endIndex != -1) {
int startIndex = code.LastIndexOf("\r\n", endIndex, endIndex);
if (startIndex != -1) {
code = code.Remove(endIndex, "[Tab]".Length);
code = code.Insert(endIndex, new string(' ', 40 - endIndex + startIndex));
continue;
}
}
break;
}
return code; return code;
} }

11
src/CodeDomMetodBodyBuilder.cs

@ -17,16 +17,15 @@ namespace Decompiler
foreach(Instruction instr in methodDef.Body.Instructions) { foreach(Instruction instr in methodDef.Body.Instructions) {
OpCode opCode = instr.OpCode; OpCode opCode = instr.OpCode;
string decription = string decription =
string.Format("IL_{0:X2}: {1, -11} {2, -15} # {3}->{4} {5} {6}", string.Format("IL_{0:X2}: {1, -22} # {2}->{3} {4} {5}",
instr.Offset, instr.Offset,
opCode, opCode + " " + FormatInstructionOperand(instr.Operand),
FormatInstructionOperand(instr.Operand),
opCode.StackBehaviourPop, opCode.StackBehaviourPop,
opCode.StackBehaviourPush, opCode.StackBehaviourPush,
opCode.FlowControl == FlowControl.Next ? string.Empty : "Flow=" + opCode.FlowControl, opCode.FlowControl == FlowControl.Next ? string.Empty : "Flow=" + opCode.FlowControl,
opCode.OpCodeType == OpCodeType.Macro ? "(macro)" : string.Empty); opCode.OpCodeType == OpCodeType.Macro ? "(macro)" : string.Empty);
codeStmtCol.Add(new CodeCommentStatement(decription));
codeStmtCol.Add(new CodeCommentStatement(decription));
try { try {
object codeExpr = MakeCodeDomExpression( object codeExpr = MakeCodeDomExpression(
instr, instr,
@ -39,7 +38,9 @@ namespace Decompiler
codeStmtCol.Add((CodeExpression)codeExpr); codeStmtCol.Add((CodeExpression)codeExpr);
} }
} catch (NotImplementedException) { } catch (NotImplementedException) {
codeStmtCol.Add(new CodeSnippetExpression("/* Not implemented */"));
} }
codeStmtCol.Add(new CodeSnippetStatement(""));
} }
return codeStmtCol; return codeStmtCol;
@ -251,7 +252,7 @@ namespace Decompiler
case Code.Mkrefany: throw new NotImplementedException(); case Code.Mkrefany: throw new NotImplementedException();
case Code.Newobj: throw new NotImplementedException(); case Code.Newobj: throw new NotImplementedException();
case Code.No: throw new NotImplementedException(); case Code.No: throw new NotImplementedException();
case Code.Nop: return new CodeCommentStatement("No-op"); case Code.Nop: return new CodeSnippetExpression("/* No-op */");
case Code.Or: throw new NotImplementedException(); case Code.Or: throw new NotImplementedException();
case Code.Pop: throw new NotImplementedException(); case Code.Pop: throw new NotImplementedException();
case Code.Readonly: throw new NotImplementedException(); case Code.Readonly: throw new NotImplementedException();

Loading…
Cancel
Save