2014-11-25 10:53:35 +03:00
|
|
|
///<reference path='build/j2me.d.ts' />
|
2014-11-18 03:29:19 +03:00
|
|
|
|
|
|
|
var jsGlobal = (function() { return this || (1, eval)('this'); })();
|
2014-11-18 12:03:00 +03:00
|
|
|
var CC = {};
|
2014-11-18 03:29:19 +03:00
|
|
|
|
|
|
|
jsGlobal.window = {
|
|
|
|
setZeroTimeout: function(callback) {
|
|
|
|
callback();
|
|
|
|
},
|
|
|
|
addEventListener: function() {
|
|
|
|
},
|
|
|
|
crypto: {
|
|
|
|
getRandomValues: function() {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
jsGlobal.navigator = {
|
|
|
|
language: "en-US",
|
|
|
|
};
|
|
|
|
|
|
|
|
jsGlobal.document = {
|
|
|
|
documentElement: {
|
|
|
|
classList: {
|
|
|
|
add: function() {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
querySelector: function() {
|
|
|
|
return {
|
|
|
|
addEventListener: function() {
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
getElementById: function() {
|
|
|
|
return {
|
|
|
|
addEventListener: function() {
|
|
|
|
},
|
|
|
|
getContext: function() {
|
|
|
|
},
|
2014-11-18 03:34:02 +03:00
|
|
|
getBoundingClientRect: function() {
|
|
|
|
return { top: 0, left: 0, width: 0, height: 0 };
|
|
|
|
}
|
2014-11-18 03:29:19 +03:00
|
|
|
};
|
|
|
|
},
|
2014-11-18 03:34:02 +03:00
|
|
|
addEventListener: function() {
|
|
|
|
},
|
2014-11-18 03:29:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
jsGlobal.urlParams = {
|
|
|
|
logConsole: "native",
|
|
|
|
args: "",
|
|
|
|
};
|
|
|
|
|
|
|
|
module J2ME {
|
|
|
|
declare var load: (string) => void;
|
|
|
|
declare var process, require, global, quit, help, scriptArgs, arguments, snarf;
|
2014-11-18 12:03:00 +03:00
|
|
|
declare var JVM, Runtime, CLASSES, Context, release;
|
2014-11-18 03:29:19 +03:00
|
|
|
|
|
|
|
var isNode = typeof process === 'object';
|
|
|
|
var writer: IndentingWriter;
|
|
|
|
var rootPath = "";
|
|
|
|
|
|
|
|
function loadFiles(...files: string[]) {
|
|
|
|
for (var i = 0; i < files.length; i++) {
|
|
|
|
load(rootPath + files[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-29 13:23:10 +03:00
|
|
|
loadFiles("libs/zipfile.js", "blackBox.js", "build/j2me.js", "classfile/classfile.js",
|
2014-11-25 10:53:35 +03:00
|
|
|
"classfile/reader.js", "classfile/tags.js", "classfile/attributetypes.js",
|
2014-11-26 12:21:11 +03:00
|
|
|
"libs/encoding.js", "util.js", "frame.js",
|
2014-11-27 12:15:46 +03:00
|
|
|
"classfile/accessflags.js", "instrument.js", "signature.js", "opcodes.js",
|
2014-11-18 03:29:19 +03:00
|
|
|
"override.js", "native.js", "string.js", "libs/console.js", "midp/midp.js",
|
2014-11-24 08:30:33 +03:00
|
|
|
"libs/long.js", "midp/crypto.js", "libs/forge/md5.js", "libs/forge/util.js");
|
2014-11-18 03:29:19 +03:00
|
|
|
|
2014-11-25 09:14:11 +03:00
|
|
|
phase = ExecutionPhase.Compiler;
|
2014-11-25 07:16:34 +03:00
|
|
|
|
2014-11-18 03:29:19 +03:00
|
|
|
writer = new IndentingWriter();
|
|
|
|
|
|
|
|
var verboseOption: Options.Option;
|
2014-11-18 12:03:00 +03:00
|
|
|
var classpathOption: Options.Option;
|
2014-11-19 05:20:20 +03:00
|
|
|
var callGraphOption: Options.Option;
|
2014-11-18 12:03:00 +03:00
|
|
|
var classFilterOption: Options.Option;
|
2014-12-08 21:55:05 +03:00
|
|
|
var fileFilterOption: Options.Option;
|
2014-11-18 12:03:00 +03:00
|
|
|
var debuggerOption: Options.Option;
|
|
|
|
var releaseOption: Options.Option;
|
2014-11-25 13:30:33 +03:00
|
|
|
var definitionOption: Options.Option;
|
2014-11-18 12:03:00 +03:00
|
|
|
|
2014-11-18 03:29:19 +03:00
|
|
|
|
|
|
|
function main(commandLineArguments: string []) {
|
|
|
|
var options = new Options.OptionSet("J2ME");
|
|
|
|
var shellOptions = options.register(new Options.OptionSet(""));
|
|
|
|
|
|
|
|
verboseOption = shellOptions.register(new Options.Option("v", "verbose", "boolean", false, "Verbose"));
|
2014-11-18 12:03:00 +03:00
|
|
|
classpathOption = shellOptions.register(new Options.Option("cp", "classpath", "string []", [], "Compile ClassPath"));
|
2014-11-19 05:20:20 +03:00
|
|
|
callGraphOption = shellOptions.register(new Options.Option("cg", "callGraph", "string []", [], "Call Grpah Files"));
|
|
|
|
|
|
|
|
|
2014-12-08 21:55:05 +03:00
|
|
|
classFilterOption = shellOptions.register(new Options.Option("cf", "classFilter", "string", ".*", "Compile Class Filter"));
|
|
|
|
fileFilterOption = shellOptions.register(new Options.Option("ff", "fileFilter", "string", ".*", "Compile File Filter"));
|
2014-11-18 12:03:00 +03:00
|
|
|
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"));
|
2014-11-25 13:30:33 +03:00
|
|
|
definitionOption = shellOptions.register(new Options.Option("t", "definition", "boolean", false, "Emit Definition"));
|
2014-11-18 03:29:19 +03:00
|
|
|
|
|
|
|
var argumentParser = new Options.ArgumentParser();
|
|
|
|
argumentParser.addBoundOptionSet(shellOptions);
|
|
|
|
|
|
|
|
function printUsage() {
|
|
|
|
writer.enter("J2ME Command Line Interface");
|
|
|
|
options.trace(writer);
|
|
|
|
writer.leave("");
|
|
|
|
}
|
|
|
|
|
|
|
|
argumentParser.addArgument("h", "help", "boolean", {
|
|
|
|
parse: function (x) {
|
|
|
|
printUsage();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var files = [];
|
|
|
|
|
|
|
|
// Try and parse command line arguments.
|
|
|
|
|
|
|
|
try {
|
2014-11-18 12:03:00 +03:00
|
|
|
argumentParser.parse(commandLineArguments);
|
|
|
|
classpathOption.value.filter(function (value, index, array) {
|
2014-11-18 03:29:19 +03:00
|
|
|
if (value.endsWith(".jar")) {
|
|
|
|
files.push(value);
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2014-11-19 05:20:20 +03:00
|
|
|
|
|
|
|
callGraphOption.value.filter(function (value, index, array) {
|
|
|
|
if (value.endsWith(".json")) {
|
|
|
|
var calls = JSON.parse(snarf(value));
|
2014-11-19 05:33:22 +03:00
|
|
|
var Y = {};
|
|
|
|
Y["java/io/ByteArrayOutputStream.write.(I)V"] = true;
|
|
|
|
var changed = true;
|
|
|
|
while (changed) {
|
|
|
|
changed = false;
|
|
|
|
for (var k in calls) {
|
|
|
|
if (Y[k]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (var z in Y) {
|
|
|
|
if (calls[k].indexOf(z) >= 0) {
|
|
|
|
Y[k] = true;
|
|
|
|
changed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
writer.writeLn(JSON.stringify(Y, null, 2));
|
2014-11-19 05:20:20 +03:00
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2014-11-18 03:29:19 +03:00
|
|
|
} catch (x) {
|
|
|
|
writer.writeLn(x.message);
|
2014-11-18 12:03:00 +03:00
|
|
|
writer.writeLns(x.stack);
|
2014-11-18 03:29:19 +03:00
|
|
|
quit();
|
|
|
|
}
|
|
|
|
|
2014-11-18 12:03:00 +03:00
|
|
|
release = releaseOption.value;
|
2014-11-18 03:29:19 +03:00
|
|
|
var jvm = new JVM();
|
|
|
|
for (var i = 0; i < files.length; i++) {
|
|
|
|
var file = files[i];
|
|
|
|
if (file.endsWith(".jar")) {
|
2014-11-18 12:03:00 +03:00
|
|
|
if (verboseOption.value) {
|
2014-11-18 03:29:19 +03:00
|
|
|
writer.writeLn("Loading: " + file);
|
|
|
|
}
|
2014-11-26 12:21:11 +03:00
|
|
|
CLASSES.addPath(file, snarf(file, "binary").buffer);
|
2014-11-18 03:29:19 +03:00
|
|
|
}
|
|
|
|
}
|
2014-12-01 03:21:34 +03:00
|
|
|
CLASSES.initializeBuiltinClasses();
|
2014-12-08 21:55:05 +03:00
|
|
|
if (verboseOption.value) {
|
|
|
|
writer.writeLn("Compiling Pattern: " + classFilterOption.value);
|
|
|
|
}
|
|
|
|
compile(jvm, classFilterOption.value, fileFilterOption.value, debuggerOption.value, definitionOption.value);
|
|
|
|
if (verboseOption.value) {
|
|
|
|
printResults();
|
2014-11-18 03:29:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var commandLineArguments: string [];
|
|
|
|
// Shell Entry Point
|
|
|
|
if (typeof help === "function") {
|
|
|
|
// SpiderMonkey
|
|
|
|
if (typeof scriptArgs === "undefined") {
|
|
|
|
commandLineArguments = arguments;
|
|
|
|
} else {
|
|
|
|
commandLineArguments = scriptArgs;
|
|
|
|
}
|
|
|
|
} else if (isNode) {
|
|
|
|
// node.js
|
|
|
|
var commandLineArguments: string[] =
|
|
|
|
Array.prototype.slice.call(process.argv, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
main(commandLineArguments);
|
2014-11-18 12:03:00 +03:00
|
|
|
}
|