Permalink
Browse files

Merge branch 'incoming'

  • Loading branch information...
2 parents 2f4401a + e97f48a commit ada59f0a9d23d8ec19ee6a1326977ddf6e93f5f9 @kripken committed Dec 31, 2012
View
@@ -1050,7 +1050,6 @@ try:
if not LEAVE_INPUTS_RAW:
link_opts = [] if keep_debug else ['-strip-debug']
if llvm_opts > 0:
- if DEBUG: print >> sys.stderr, 'emcc: LLVM -O%d' % llvm_opts
shared.Building.llvm_opt(in_temp(target_basename + '.bc'), llvm_opts)
if DEBUG: save_intermediate('opt', 'bc')
# Do LTO in a separate pass to work around LLVM bug XXX (see failure e.g. in cubescript)
@@ -1063,7 +1062,6 @@ try:
else:
# At minimum remove dead functions etc., this potentially saves a lot in the size of the generated code (and the time to compile it)
link_opts += shared.Building.get_safe_internalize() + ['-globaldce']
- if DEBUG: print >> sys.stderr, 'emcc: LLVM linktime:', link_opts
shared.Building.llvm_opt(in_temp(target_basename + '.bc'), link_opts)
if DEBUG: save_intermediate('linktime', 'bc')
View
@@ -5,16 +5,44 @@
<hr>
<pre id="output"></pre>
<script>
- arguments = ['', '../freetype.ll'];
- //arguments = ['', '../tests/cases/phicubed.ll'];
+ arguments = [];
var outputElement = document.getElementById('output');
+ var compilerOutput = '';
print = function(x) {
//outputElement.innerHTML += x;
+ compilerOutput += x;
+ };
+
+ // For generated code
+ var Module = {
+ print: function(x) {
+ outputElement.innerHTML += x;
+ }
};
</script>
<script src="compiler.js">
</script>
+<textarea id="the_input" cols=50 rows=30>
+; ModuleID = 'tests/hello_world.bc'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128"
+target triple = "i386-pc-linux-gnu"
+
+@.str = private unnamed_addr constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*]
+
+; [#uses=0]
+define i32 @main() {
+entry:
+ %retval = alloca i32, align 4 ; [#uses=1 type=i32*]
+ store i32 0, i32* %retval
+ %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0 type=i32]
+ ret i32 1
+}
+
+; [#uses=1]
+declare i32 @printf(i8*, ...)
+</textarea>
+<input type="button" value="run!" onclick="compile(document.getElementById('the_input').value); eval(compilerOutput)">
</body>
</html>
View
@@ -76,10 +76,12 @@ if (ENVIRONMENT_IS_NODE) {
}
} else if (ENVIRONMENT_IS_WEB) {
- this['print'] = printErr = function(x) {
+ printErr = function(x) {
console.log(x);
};
+ if (!this['print']) this['print'] = printErr;
+
this['read'] = function(url) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, false);
@@ -213,42 +215,66 @@ NECESSARY_BLOCKADDRS = temp;
// Read llvm
-var raw = read(ll_file);
-if (FAKE_X86_FP80) {
- raw = raw.replace(/x86_fp80/g, 'double');
-}
-if (raw.search('\r\n') >= 0) {
- raw = raw.replace(/\r\n/g, '\n'); // fix windows line endings
-}
-var lines = raw.split('\n');
-raw = null;
+function compile(raw) {
+ if (FAKE_X86_FP80) {
+ raw = raw.replace(/x86_fp80/g, 'double');
+ }
+ if (raw.search('\r\n') >= 0) {
+ raw = raw.replace(/\r\n/g, '\n'); // fix windows line endings
+ }
+ var lines = raw.split('\n');
+ raw = null;
+
+ // Pre-process the LLVM assembly
+
+ Debugging.handleMetadata(lines);
-// Pre-process the LLVM assembly
+ function runPhase(currPhase) {
+ //printErr('// JS compiler in action, phase ' + currPhase + typeof lines + (lines === null));
+ phase = currPhase;
+ if (phase != 'pre') {
+ if (singlePhase) PassManager.load(read(forwardedDataFile));
-//printErr('JS compiler in action, phase ' + phase);
+ if (phase == 'funcs') {
+ PreProcessor.eliminateUnneededIntrinsics(lines);
+ }
+ }
-Debugging.handleMetadata(lines);
+ // Do it
-if (phase != 'pre') {
- PassManager.load(read(forwardedDataFile));
+ var intertyped = intertyper(lines);
+ if (singlePhase) lines = null;
+ var analyzed = analyzer(intertyped);
+ intertyped = null;
+ JSify(analyzed);
- if (phase == 'funcs') {
- PreProcessor.eliminateUnneededIntrinsics(lines);
+ phase = null;
+
+ if (DEBUG_MEMORY) {
+ print('zzz. last gc: ' + gc());
+ MemoryDebugger.dump();
+ print('zzz. hanging now!');
+ while(1){};
+ }
}
-}
-// Do it
+ // Normal operation is for each execution of compiler.js to run a single phase. The calling script sends us exactly the information we need, and it is easy to parallelize operation that way. However, it is also possible to run in an unoptimal multiphase mode, where a single invocation goes from ll to js directly. This is not recommended and will likely do a lot of duplicate processing.
+ singlePhase = !!phase;
-var intertyped = intertyper(lines);
-lines = null;
-var analyzed = analyzer(intertyped);
-intertyped = null;
-JSify(analyzed);
+ if (singlePhase) {
+ runPhase(phase);
+ } else {
+ runPhase('pre');
+ runPhase('funcs');
+ runPhase('post');
+ }
+}
-if (DEBUG_MEMORY) {
- print('zzz. last gc: ' + gc());
- MemoryDebugger.dump();
- print('zzz. hanging now!');
- while(1){};
+if (ll_file) {
+ if (ll_file.indexOf(String.fromCharCode(10)) == -1) {
+ compile(read(ll_file));
+ } else {
+ compile(ll_file); // we are given raw .ll
+ }
}
View
@@ -61,7 +61,7 @@ function intertyper(data, sidePass, baseLineNums) {
var baseLineNumPosition = 0;
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
- lines[i] = null; // lines may be very very large. Allow GCing to occur in the loop by releasing refs here
+ if (singlePhase) lines[i] = null; // lines may be very very large. Allow GCing to occur in the loop by releasing refs here
while (baseLineNumPosition < baseLineNums.length-1 && i >= baseLineNums[baseLineNumPosition+1][0]) {
baseLineNumPosition++;
View
@@ -417,8 +417,8 @@ function JSify(data, functionsOnly, givenFunctions) {
// name the function; overwrite if it's already named
snippet = snippet.replace(/function(?:\s+([^(]+))?\s*\(/, 'function _' + ident + '(');
if (LIBRARY_DEBUG) {
- snippet = snippet.replace('{', '{ var ret = (function() { if (Runtime.debug) Module.printErr("[library call:' + ident + ': " + Array.prototype.slice.call(arguments).map(Runtime.prettyPrint) + "]"); ');
- snippet = snippet.substr(0, snippet.length-1) + '}).apply(this, arguments); if (Runtime.debug && typeof ret !== "undefined") Module.printErr(" [ return:" + Runtime.prettyPrint(ret)); return ret; }';
+ snippet = snippet.replace('{', '{ var ret = (function() { if (Runtime.debug) Module.print("[library call:' + ident + ': " + Array.prototype.slice.call(arguments).map(Runtime.prettyPrint) + "]"); ');
+ snippet = snippet.substr(0, snippet.length-1) + '}).apply(this, arguments); if (Runtime.debug && typeof ret !== "undefined") Module.print(" [ return:" + Runtime.prettyPrint(ret)); return ret; }';
}
}
@@ -1310,6 +1310,7 @@ function JSify(data, functionsOnly, givenFunctions) {
// Print out global variables and postsets TODO: batching
if (phase == 'pre') {
+ var legalizedI64sDefault = legalizedI64s;
legalizedI64s = false;
var globalsData = analyzer(intertyper(data.unparsedGlobalss[0].lines, true), true);
@@ -1332,9 +1333,13 @@ function JSify(data, functionsOnly, givenFunctions) {
var generated = itemsDict.functionStub.concat(itemsDict.GlobalVariablePostSet);
generated.forEach(function(item) { print(indentify(item.JS || '', 2)); });
+
+ legalizedI64s = legalizedI64sDefault;
} else {
- assert(data.unparsedGlobalss[0].lines.length == 0, dump([phase, data.unparsedGlobalss]));
- assert(itemsDict.functionStub.length == 0, dump([phase, itemsDict.functionStub]));
+ if (singlePhase) {
+ assert(data.unparsedGlobalss[0].lines.length == 0, dump([phase, data.unparsedGlobalss]));
+ assert(itemsDict.functionStub.length == 0, dump([phase, itemsDict.functionStub]));
+ }
}
if (phase == 'pre' || phase == 'funcs') {
Oops, something went wrong.

0 comments on commit ada59f0

Please sign in to comment.