private BlockStatement DecompileObject(CodeObject obj) { var context = new DecompileContext(obj); var m = Script.Methods[obj]; m.Compact(); context.BuildCFG(m.Instructions); var pass1 = new RegMemberPass(); var entry = pass1.Process(context, new BlockStatement()); var pass2 = new ExpressionPass(); entry = pass2.Process(context, entry); var pass3 = new ControlFlowPass(); entry = pass3.Process(context, entry); var pass4 = new StatementCollectPass(); entry = pass4.Process(context, entry); m.Vars = context.Vars; return(entry); }
public void TestDecompileBlock() { var path = "..\\..\\Res\\Initialize.tjs.comp"; Module md = new Module(path); var mt = md.TopLevel.ResolveMethod(); mt.Compact(); DecompileContext context = new DecompileContext(md.TopLevel); context.ScanBlocks(mt.Instructions); context.ComputeDominators(); context.ComputeNaturalLoops(); context.FillInBlocks(mt.Instructions); var pass1 = new RegMemberPass(); var entry = pass1.Process(context, new BlockStatement()); var pass2 = new ExpressionPass(); entry = pass2.Process(context, entry); var b = context.Blocks[1]; var s1 = b.Statements.FirstOrDefault(); var pass3 = new ControlFlowPass(); entry = pass3.Process(context, entry); var c = entry.Statements.Count; foreach (var st in entry.Statements) { var s = st; } var pass4 = new StatementCollectPass(); entry = pass4.Process(context, entry); foreach (var statement in entry.Statements) { var s = statement; } var sWriter = new StringWriter(); TjsWriter writer = new TjsWriter(sWriter); writer.WriteBlock(entry); sWriter.Flush(); var result = sWriter.ToString(); }