aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xemcc2
-rw-r--r--src/library.js23
-rw-r--r--src/parseTools.js2
-rw-r--r--src/preamble.js4
-rwxr-xr-xtests/runner.py20
-rw-r--r--tools/js-optimizer.js11
6 files changed, 41 insertions, 21 deletions
diff --git a/emcc b/emcc
index 689e5a94..bd6350a5 100755
--- a/emcc
+++ b/emcc
@@ -1046,7 +1046,7 @@ try:
if shared.Settings.CORRECT_SIGNS >= 2 or shared.Settings.CORRECT_OVERFLOWS >= 2 or shared.Settings.CORRECT_ROUNDINGS >= 2:
debug_level = 4 # must keep debug info to do line-by-line operations
- if debug_level > 0 and closure:
+ if debug_level > 1 and closure:
logging.warning('disabling closure because debug info was requested')
closure = False
diff --git a/src/library.js b/src/library.js
index 3ed0771e..83da2faf 100644
--- a/src/library.js
+++ b/src/library.js
@@ -559,25 +559,28 @@ LibraryManager.library = {
};
}
var utf8 = new Runtime.UTF8Processor();
- function simpleOutput(val) {
- if (val === null || val === {{{ charCode('\n') }}}) {
- output.printer(output.buffer.join(''));
- output.buffer = [];
- } else {
- output.buffer.push(utf8.processCChar(val));
- }
+ function createSimpleOutput() {
+ var fn = function (val) {
+ if (val === null || val === {{{ charCode('\n') }}}) {
+ fn.printer(fn.buffer.join(''));
+ fn.buffer = [];
+ } else {
+ fn.buffer.push(utf8.processCChar(val));
+ }
+ };
+ return fn;
}
if (!output) {
stdoutOverridden = false;
- output = simpleOutput;
+ output = createSimpleOutput();
}
if (!output.printer) output.printer = Module['print'];
if (!output.buffer) output.buffer = [];
if (!error) {
stderrOverridden = false;
- error = simpleOutput;
+ error = createSimpleOutput();
}
- if (!error.printer) error.printer = Module['print'];
+ if (!error.printer) error.printer = Module['printErr'];
if (!error.buffer) error.buffer = [];
// Create the temporary folder, if not already created
diff --git a/src/parseTools.js b/src/parseTools.js
index eb200c65..a5785e27 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -1231,7 +1231,7 @@ function indexizeFunctions(value, type) {
// add signature to library functions that we now know need indexing
var sig = Functions.implementedFunctions[value] || Functions.unimplementedFunctions[value];
if (!sig) {
- sig = Functions.unimplementedFunctions[value] = Functions.getSignature(out.returnType, out.segments ? out.segments.map(function(segment) { return segment[0].text }) : []);
+ sig = Functions.unimplementedFunctions[value] = Functions.getSignature(out.returnType, out.segments ? out.segments.map(function(segment) { return segment[0].text }) : [], isVarArgsFunctionType(type));
}
return Functions.getIndex(value, undefined, sig);
}
diff --git a/src/preamble.js b/src/preamble.js
index c9e7e4eb..41017676 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -784,7 +784,7 @@ Module['writeArrayToMemory'] = writeArrayToMemory;
{{{ reSign }}}
#if PRECISE_I32_MUL
-if (!Math['imul']) Math['imul'] = function(a, b) {
+if (!Math.imul) Math.imul = function(a, b) {
var ah = a >>> 16;
var al = a & 0xffff;
var bh = b >>> 16;
@@ -792,7 +792,7 @@ if (!Math['imul']) Math['imul'] = function(a, b) {
return (al*bl + ((ah*bl + al*bh) << 16))|0;
};
#else
-Math['imul'] = function(a, b) {
+Math.imul = function(a, b) {
return (a*b)|0; // fast but imprecise
};
#endif
diff --git a/tests/runner.py b/tests/runner.py
index 729ac63e..c31a22e6 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -4522,6 +4522,22 @@ The current address of a is: 0x12345678
The current type of b is: 9
''')
+ def test_functionpointer_libfunc_varargs(self):
+ src = r'''
+ #include <stdio.h>
+ #include <fcntl.h>
+ typedef int (*fp_t)(int, int, ...);
+ int main(int argc, char **argv) {
+ fp_t fp = &fcntl;
+ if (argc == 1337) fp = (fp_t)&main;
+ (*fp)(0, 10);
+ (*fp)(0, 10, 5);
+ printf("waka\n");
+ return 0;
+ }
+ '''
+ self.do_run(src, '''waka''')
+
def test_structbyval(self):
Settings.INLINING_LIMIT = 50
@@ -7029,7 +7045,7 @@ def process(filename):
other.close()
src = open(path_from_root('tests', 'files.cpp'), 'r').read()
- self.do_run(src, 'size: 7\ndata: 100,-56,50,25,10,77,123\nloop: 100 -56 50 25 10 77 123 \ninput:hi there!\ntexto\ntexte\n$\n5 : 10,30,20,11,88\nother=some data.\nseeked=me da.\nseeked=ata.\nseeked=ta.\nfscanfed: 10 - hello\nok.\n',
+ self.do_run(src, 'size: 7\ndata: 100,-56,50,25,10,77,123\nloop: 100 -56 50 25 10 77 123 \ninput:hi there!\ntexto\n$\n5 : 10,30,20,11,88\nother=some data.\nseeked=me da.\nseeked=ata.\nseeked=ta.\nfscanfed: 10 - hello\nok.\ntexte\n',
post_build=post, extra_emscripten_args=['-H', 'libc/fcntl.h'])
def test_files_m(self):
@@ -7061,7 +7077,7 @@ def process(filename):
return 0;
}
'''
- self.do_run(src, 'isatty? 0,0,1\ngot: 35\ngot: 45\ngot: 25\ngot: 15\n', post_build=post)
+ self.do_run(src, 'got: 35\ngot: 45\ngot: 25\ngot: 15\nisatty? 0,0,1\n', post_build=post)
def test_fwrite_0(self):
src = r'''
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 46b9c731..ddad28ed 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -3120,9 +3120,11 @@ function outline(ast) {
var sizeToOutline = extraInfo.sizeToOutline;
var level = 0;
- var costs = {}; // new function name => overhead cost of outlining
+ var outliningsLeft = {}; // function name => counter of how many more outlinings to allow
+ var outliningParents = {}; // function name => parent it was outlined from
function doOutline(func, asmData, stats, start, end) {
+ if (!outliningsLeft[func[1]]) return [];
if (!extraInfo.allowCostlyOutlines) var originalStats = copy(stats);
var code = stats.slice(start, end+1);
var funcSize = measureSize(func);
@@ -3327,10 +3329,8 @@ function outline(ast) {
getStatements(func).push(['stat', ['return', makeAsmCoercion(['num', 0], allCodeInfo.hasReturnInt ? ASM_INT : ASM_DOUBLE)]]);
}
}
- // the cost is the total size increase of all code, after the outlining operation. We also
- // inherit the outlining cost of the parent function, if any, so the repeated outlining
- // cannot infinitely recurse.
- costs[newIdent] = measureSize(func) + measureSize(newFunc) - funcSize + (costs[func[1]] || 0);
+ outliningsLeft[func[1]]--;
+ outliningParents[newIdent] = func[1];
return [newFunc];
}
@@ -3435,6 +3435,7 @@ function outline(ast) {
var size = measureSize(func);
if (size >= sizeToOutline) {
printErr('trying to reduce the size of ' + func[1] + ' which is ' + size + ' (>= ' + sizeToOutline + ')');
+ outliningsLeft[func[1]] = Math.round(1.5*size/sizeToOutline);
aggressiveVariableElimination(func, asmData);
analyzeFunction(func, asmData);
var stats = getStatements(func);