public void Process(File file, TextWriter writer) { var decoder = new Decoder(file); var program = new ScriptProgram(decoder); var analyzer = new ControlFlowAnalyzer(program); analyzer.Analyze(); // Dump the code paths foreach (Function function in program.Functions) { writer.WriteLine("function " + function.Name); foreach (CodePath path in function.CodePaths) { writer.WriteLine(" " + path.Name + ":"); writer.WriteLine(string.Format(" 0x{0:x} --> 0x{1:x}", path.StartOffset, path.EndOffset)); if (path.ParentCodePath != null) { writer.WriteLine(" parent: {0}, exit: 0x{1:x}, reentry: 0x{2:x}", path.ParentCodePath.Name, path.ParentExitInstruction.Instruction.Offset, path.ParentEntryTargetInstruction.Instruction.Offset); } } writer.WriteLine(); } }
public void Process(File file, TextWriter writer) { var decoder = new Decoder(file); var program = new ScriptProgram(decoder); var analyzer = new ControlFlowAnalyzer(program); analyzer.Analyze(); foreach (Function function in program.Functions) { writer.WriteLine(string.Format(".function {0} (params={1}, vars={2}, return={3})", function.Name, function.ParameterCount, function.VariableCount, function.ReturnCount)); ProcessCodePath(writer, function.MainCodePath, " "); writer.WriteLine(".endfunction"); writer.WriteLine(); } }
public void Process(File file, TextWriter writer) { var decoder = new Decoder(file); var program = new ScriptProgram(decoder); var analyzer = new ControlFlowAnalyzer(program); analyzer.Analyze(); var stackAnalyzer = new StackUseAnalyzer(program); stackAnalyzer.Analyze(); foreach (Function function in program.Functions) { var sb = new StringBuilder(); for (int i = 0; i < function.ParameterCount; i++) { if (i != 0) { sb.Append(", "); } sb.Append("var"); sb.Append(i); } writer.WriteLine(string.Format("{0} {1}({2})", function.ReturnCount > 0 ? "function" : "void", function.Name, sb)); writer.WriteLine("{"); if (function.VariableCount > 2) { writer.Write(" auto "); for (int i = 2; i < function.VariableCount; i++) { if (i != 2) { writer.Write(", "); } writer.Write("var" + (i + function.ParameterCount)); } writer.WriteLine(";"); } if (function.TemporaryCount > 0) { writer.Write(" auto "); for (int i = 0; i < function.TemporaryCount; i++) { if (i != 0) { writer.Write(", "); } writer.Write("temp" + i); } writer.WriteLine(";"); } if (function.TemporaryCount > 0 || function.VariableCount > 2) { writer.WriteLine(); } ProcessCodePath(writer, function.MainCodePath, " "); writer.WriteLine("}"); writer.WriteLine(); } }