aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormax99x <max99x@gmail.com>2011-06-27 21:27:19 +0300
committermax99x <max99x@gmail.com>2011-06-27 21:27:19 +0300
commit5824029a7ccabe7f59f2015fb860cbfadc547c35 (patch)
treead046587a634273f27cef181df00f886ae303884
parenta0ac176b22bbcf252dff23b89583bb077fafe371 (diff)
parent30c5db3696ff9b45da570eb9d5c19cc1cbb1d01c (diff)
Merge remote-tracking branch 'upstream/master'
-rw-r--r--src/analyzer.js17
-rw-r--r--src/jsifier.js25
-rw-r--r--src/library_sdl.js11
-rw-r--r--src/parseTools.js12
4 files changed, 38 insertions, 27 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index bae05ec8..9b8af51b 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -1124,21 +1124,6 @@ function analyzer(data) {
}, 'Sorter');
// Solve it
- var ret = substrate.solve();
-
- // Add additional necessary items
- if (INCLUDE_FULL_LIBRARY) {
- assert(!BUILD_AS_SHARED_LIB, 'Cannot have both INCLUDE_FULL_LIBRARY and BUILD_AS_SHARED_LIB set.')
- var libFuncsToInclude = keys(Library);
- } else {
- var libFuncsToInclude = ['memset', 'malloc', 'free'];
- }
- libFuncsToInclude.forEach(function(ident) {
- ret.functionStubs.push({
- intertype: 'functionStub',
- ident: '_' + ident
- });
- });
- return ret;
+ return substrate.solve();
}
diff --git a/src/jsifier.js b/src/jsifier.js
index a0c6ec72..3f7698ef 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -3,6 +3,23 @@
// Main function
function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
+ // Add additional necessary items for the main pass
+ if (!functionsOnly) {
+ var libFuncsToInclude;
+ if (INCLUDE_FULL_LIBRARY) {
+ assert(!BUILD_AS_SHARED_LIB, 'Cannot have both INCLUDE_FULL_LIBRARY and BUILD_AS_SHARED_LIB set.')
+ libFuncsToInclude = keys(Library);
+ } else {
+ libFuncsToInclude = ['memset', 'malloc', 'free'];
+ }
+ libFuncsToInclude.forEach(function(ident) {
+ data.functionStubs.push({
+ intertype: 'functionStub',
+ ident: '_' + ident
+ });
+ });
+ }
+
// Does simple 'macro' substitution, using Django-like syntax,
// {{{ code }}} will be replaced with |eval(code)|.
function processMacros(text) {
@@ -511,7 +528,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
});
}
makeFuncLineActor('store', function(item) {
- var value = indexizeFunctions(finalizeLLVMParameter(item.value));
+ var value = finalizeLLVMParameter(item.value);
if (pointingLevels(item.pointerType) == 1) {
value = parseNumerical(value, removePointing(item.pointerType));
}
@@ -527,7 +544,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
if (item.pointer.intertype == 'value') {
return makeSetValue(item.ident, 0, value, item.valueType);
} else {
- return makeSetValue(0, indexizeFunctions(finalizeLLVMParameter(item.pointer)), value, item.valueType);
+ return makeSetValue(0, finalizeLLVMParameter(item.pointer), value, item.valueType);
}
break;
default:
@@ -671,10 +688,10 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
var params = item.params;
function makeOne(i) {
if (i === params.length-1) {
- return indexizeFunctions(finalizeLLVMParameter(params[i].value));
+ return finalizeLLVMParameter(params[i].value);
}
return '__lastLabel__ == ' + getLabelId(params[i].label) + ' ? ' +
- indexizeFunctions(finalizeLLVMParameter(params[i].value)) + ' : (' + makeOne(i+1) + ')';
+ finalizeLLVMParameter(params[i].value) + ' : (' + makeOne(i+1) + ')';
}
return makeOne(0);
});
diff --git a/src/library_sdl.js b/src/library_sdl.js
index 6a984c43..b7e25e95 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -62,6 +62,8 @@
// Other stuff to take into account:
//
+// * Make sure alpha values are proper in your input. If they are all 0, everything will be transparent!
+//
// * It's best to set the ctx stuff in your html file, as above. Otherwise you will need
// to edit the generated .js file each time you generate it.
//
@@ -297,8 +299,12 @@ mergeInto(Library, {
// Copy pixel data to image
var num = surfData.image.data.length;
if (!surfData.colors) {
+ var data = surfData.image.data;
+ var buffer = surfData.buffer;
for (var i = 0; i < num; i++) {
- surfData.image.data[i] = {{{ makeGetValue('surfData.buffer', 'i', 'i8') }}}; // XXX - make sure alpha values are proper in your input
+ // We may need to correct signs here. Potentially you can hardcode a write of 255 to alpha, say, and
+ // the compiler may decide to write -1 in the llvm bitcode...
+ data[i] = {{{ makeGetValue('buffer', 'i', 'i8') + (CORRECT_SIGNS ? '&0xff' : '') }}};
}
} else {
var width = Module['canvas'].width;
@@ -309,7 +315,8 @@ mergeInto(Library, {
for (var y = 0; y < height; y++) {
var base = y*width*4;
for (var x = 0; x < width; x++) {
- var val = {{{ makeGetValue('s++', '0', 'i8') }}};
+ // See comment above about signs
+ var val = {{{ makeGetValue('s++', '0', 'i8') + (CORRECT_SIGNS ? '&0xff' : '') }}};
var color = colors[val] || [Math.floor(Math.random()*255),Math.floor(Math.random()*255),Math.floor(Math.random()*255)]; // XXX
var start = base + x*4;
data[start] = color[0];
diff --git a/src/parseTools.js b/src/parseTools.js
index fd021166..3855c633 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -1040,19 +1040,21 @@ function handleOverflow(text, bits) {
// From parseLLVMSegment
function finalizeLLVMParameter(param) {
+ var ret;
if (isNumber(param)) {
return param;
} else if (typeof param === 'string') {
- return toNiceIdentCarefully(param);
+ ret = toNiceIdentCarefully(param);
} else if (param.intertype in PARSABLE_LLVM_FUNCTIONS) {
- return finalizeLLVMFunctionCall(param);
+ ret = finalizeLLVMFunctionCall(param);
} else if (param.intertype == 'value') {
- return parseNumerical(param.ident);
+ ret = parseNumerical(param.ident);
} else if (param.intertype == 'structvalue') {
- return param.values.map(finalizeLLVMParameter);
+ ret = param.values.map(finalizeLLVMParameter);
} else {
throw 'invalid llvm parameter: ' + param.intertype;
}
+ return indexizeFunctions(ret);
}
function makeSignOp(value, type, op) {
@@ -1104,7 +1106,7 @@ function isSignedOp(op, variant) {
function processMathop(item) { with(item) {
for (var i = 1; i <= 4; i++) {
if (item['param'+i]) {
- item['ident'+i] = indexizeFunctions(finalizeLLVMParameter(item['param'+i]));
+ item['ident'+i] = finalizeLLVMParameter(item['param'+i]);
if (!isNumber(item['ident'+i])) {
item['ident'+i] = '(' + item['ident'+i] + ')'; // we may have nested expressions. So enforce the order of operations we want
}