From 9cbb5aa1b21f2c8f38987ffdeda78ea6befe145d Mon Sep 17 00:00:00 2001 From: Michael Bebenita Date: Tue, 18 Nov 2014 18:20:20 -0800 Subject: [PATCH] Dump call graphs. --- opt/builder.ts | 9 +++++++++ opt/shell.ts | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/opt/builder.ts b/opt/builder.ts index da6aac1c..c74917f1 100644 --- a/opt/builder.ts +++ b/opt/builder.ts @@ -8,6 +8,7 @@ module J2ME { export function printResults() { counter.trace(new IndentingWriter()); + consoleWriter.writeLn(JSON.stringify(staticCallGraph, null, 2)); } import Block = Bytecode.Block; @@ -45,6 +46,8 @@ module J2ME { } + var staticCallGraph = Object.create(null); + declare var CLASSES: any; declare var Long: any; declare var VM: any; @@ -1162,6 +1165,12 @@ module J2ME { } genInvoke(methodInfo: MethodInfo, opcode: Bytecodes, nextBCI: number) { + var callees = staticCallGraph[this.methodInfo.implKey]; + if (!callees) { + callees = staticCallGraph[this.methodInfo.implKey] = []; + } + ArrayUtilities.pushUnique(callees, methodInfo.implKey); + var signature = SignatureDescriptor.makeSignatureDescriptor(methodInfo.signature); var types = signature.typeDescriptors; var args: Value [] = []; diff --git a/opt/shell.ts b/opt/shell.ts index 6255eb2f..2513e3c1 100644 --- a/opt/shell.ts +++ b/opt/shell.ts @@ -78,6 +78,7 @@ module J2ME { var verboseOption: Options.Option; var classpathOption: Options.Option; + var callGraphOption: Options.Option; var classFilterOption: Options.Option; var debuggerOption: Options.Option; var releaseOption: Options.Option; @@ -89,6 +90,9 @@ module J2ME { verboseOption = shellOptions.register(new Options.Option("v", "verbose", "boolean", false, "Verbose")); classpathOption = shellOptions.register(new Options.Option("cp", "classpath", "string []", [], "Compile ClassPath")); + callGraphOption = shellOptions.register(new Options.Option("cg", "callGraph", "string []", [], "Call Grpah Files")); + + classFilterOption = shellOptions.register(new Options.Option("f", "filter", "string", ".*", "Compile Filter")); debuggerOption = shellOptions.register(new Options.Option("d", "debugger", "boolean", false, "Emit Debug Information")); releaseOption = shellOptions.register(new Options.Option("r", "release", "boolean", false, "Release mode")); @@ -121,6 +125,16 @@ module J2ME { return true; } }); + + callGraphOption.value.filter(function (value, index, array) { + if (value.endsWith(".json")) { + var calls = JSON.parse(snarf(value)); + + writer.writeLn(JSON.stringify(calls, null, 2)); + } else { + return true; + } + }); } catch (x) { writer.writeLn(x.message); writer.writeLns(x.stack);