aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/analyzer.js2
-rw-r--r--src/compiler.js38
-rw-r--r--src/intertyper.js30
-rw-r--r--src/jsifier.js82
-rw-r--r--src/library.js290
-rw-r--r--src/library_browser.js90
-rw-r--r--src/library_egl.js90
-rw-r--r--src/library_fs.js210
-rw-r--r--src/library_gl.js426
-rw-r--r--src/library_glfw.js4
-rw-r--r--src/library_glut.js15
-rw-r--r--src/library_idbfs.js28
-rw-r--r--src/library_memfs.js106
-rw-r--r--src/library_nodefs.js12
-rw-r--r--src/library_openal.js8
-rw-r--r--src/library_path.js22
-rw-r--r--src/library_sdl.js341
-rw-r--r--src/library_sockfs.js10
-rw-r--r--src/modules.js55
-rw-r--r--src/parseTools.js211
-rw-r--r--src/preamble.js60
-rw-r--r--src/proxyClient.js2
-rw-r--r--src/proxyWorker.js20
-rw-r--r--src/relooper/Relooper.cpp15
-rw-r--r--src/runtime.js35
-rw-r--r--src/settings.js29
-rw-r--r--src/shell.html7
-rw-r--r--src/shell.js24
-rw-r--r--src/struct_info.json24
-rw-r--r--src/utility.js9
30 files changed, 1553 insertions, 742 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index 2b74a83f..253c5505 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -418,7 +418,7 @@ function analyzer(data, sidePass) {
toAdd.push({
intertype: 'value',
assignTo: element.ident,
- type: element.bits,
+ type: 'i' + element.bits,
ident: 'tempRet' + (j - 1)
});
assert(j<10); // TODO: dynamically create more than 10 tempRet-s
diff --git a/src/compiler.js b/src/compiler.js
index e9197a5d..7d768c3d 100644
--- a/src/compiler.js
+++ b/src/compiler.js
@@ -206,12 +206,12 @@ if (phase == 'pre') {
if (VERBOSE) printErr('VERBOSE is on, this generates a lot of output and can slow down compilation');
// Load struct and define information.
-try {
+//try {
var temp = JSON.parse(read(STRUCT_INFO));
-} catch(e) {
- printErr('cannot load struct info at ' + STRUCT_INFO + ' : ' + e + ', trying in current dir');
- temp = JSON.parse(read('struct_info.compiled.json'));
-}
+//} catch(e) {
+// printErr('cannot load struct info at ' + STRUCT_INFO + ' : ' + e + ', trying in current dir');
+// temp = JSON.parse(read('struct_info.compiled.json'));
+//}
C_STRUCTS = temp.structs;
C_DEFINES = temp.defines;
@@ -224,12 +224,12 @@ load('analyzer.js');
load('jsifier.js');
if (phase == 'funcs' && RELOOP) { // XXX handle !singlePhase
RelooperModule = { TOTAL_MEMORY: ceilPowerOfTwo(2*RELOOPER_BUFFER_SIZE) };
- try {
+ //try {
load(RELOOPER);
- } catch(e) {
- printErr('cannot load relooper at ' + RELOOPER + ' : ' + e + ', trying in current dir');
- load('relooper.js');
- }
+ //} catch(e) {
+ // printErr('cannot load relooper at ' + RELOOPER + ' : ' + e + ', trying in current dir');
+ // load('relooper.js');
+ //}
assert(typeof Relooper != 'undefined');
}
globalEval(processMacros(preprocess(read('runtime.js'))));
@@ -267,7 +267,7 @@ function compile(raw) {
function runPhase(currPhase) {
//printErr('// JS compiler in action, phase ' + currPhase + typeof lines + (lines === null));
phase = currPhase;
- if (phase != 'pre') {
+ if (phase != 'pre' && phase != 'glue') {
if (singlePhase) PassManager.load(read(forwardedDataFile));
if (phase == 'funcs') {
@@ -311,12 +311,18 @@ function compile(raw) {
B = new Benchmarker();
-if (ll_file) {
- if (ll_file.indexOf(String.fromCharCode(10)) == -1) {
- compile(read(ll_file));
- } else {
- compile(ll_file); // we are given raw .ll
+try {
+ if (ll_file) {
+ if (phase === 'glue') {
+ compile(';');
+ } else if (ll_file.indexOf(String.fromCharCode(10)) == -1) {
+ compile(read(ll_file));
+ } else {
+ compile(ll_file); // we are given raw .ll
+ }
}
+} catch(err) {
+ printErr('aborting from js compiler due to exception: ' + err + ' | ' + err.stack);
}
//var M = keys(tokenCacheMisses).map(function(m) { return [m, misses[m]] }).sort(function(a, b) { return a[1] - b[1] });
diff --git a/src/intertyper.js b/src/intertyper.js
index 96db6966..940c677f 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -660,9 +660,10 @@ function intertyper(lines, sidePass, baseLineNums) {
var tokensLeft = item.tokens.slice(2);
item.ident = eatLLVMIdent(tokensLeft);
if (item.ident == 'asm') {
+ warnOnce('inline JavaScript using asm() has some oddities due to how gcc asm() syntax works. use EM_ASM where possible (see emscripten.h)');
if (ASM_JS) {
Types.hasInlineJS = true;
- warnOnce('inline JavaScript (asm, EM_ASM) will cause the code to no longer fall in the asm.js subset of JavaScript, which can reduce performance - consider using emscripten_run_script');
+ warnOnce('inline JavaScript using asm() will cause the code to no longer fall in the asm.js subset of JavaScript, which can reduce performance - consider using emscripten_run_script');
}
assert(TARGET_LE32, 'inline js is only supported in le32');
// Inline assembly is just JavaScript that we paste into the code
@@ -672,15 +673,20 @@ function intertyper(lines, sidePass, baseLineNums) {
assert((item.tokens[5].text.match(/=/g) || []).length <= 1, 'we only support at most 1 exported variable from inline js: ' + item.ident);
var i = 0;
var params = [], args = [];
- splitTokenList(tokensLeft[3].tokens).map(function(element) {
- var ident = toNiceIdent(element[1].text);
- var type = element[0].text;
- params.push('$' + (i++));
- args.push(ident);
+ if (tokensLeft[3].tokens) {
+ splitTokenList(tokensLeft[3].tokens).map(function(element) {
+ var ident = toNiceIdent(element[1].text);
+ var type = element[0].text;
+ params.push('$' + (i++));
+ args.push(ident);
+ });
+ }
+ item.ident = expandLLVMString(item.ident).replace(/(#[^\n]*)/g, function(m) {
+ return '/* ' + m.substr(1) + ' */'; // fix asm comments to js comments
});
if (item.assignTo) item.ident = 'return ' + item.ident;
item.ident = '(function(' + params + ') { ' + item.ident + ' })(' + args + ');';
- return { forward: null, ret: item, item: item };
+ return { ret: item, item: item };
}
if (item.ident.substr(-2) == '()') {
// See comment in isStructType()
@@ -703,13 +709,12 @@ function intertyper(lines, sidePass, baseLineNums) {
if (item.indent == 2) {
// standalone call - not in assign
item.standalone = true;
- return { forward: null, ret: item, item: item };
+ return { ret: item, item: item };
}
- return { forward: item, ret: null, item: item };
+ return { ret: null, item: item };
}
function callHandler(item) {
var result = makeCall.call(this, item, 'call');
- if (result.forward) this.forwardItem(result.forward, 'Reintegrator');
return result.ret;
}
function invokeHandler(item) {
@@ -719,10 +724,9 @@ function intertyper(lines, sidePass, baseLineNums) {
finalResults.push({
intertype: 'branch',
label: result.item.toLabel,
- lineNum: (result.forward ? item.parentLineNum : item.lineNum) + 0.5
+ lineNum: item.lineNum + 0.5
});
}
- if (result.forward) this.forwardItem(result.forward, 'Reintegrator');
return result.ret;
}
function atomicHandler(item) {
@@ -839,7 +843,7 @@ function intertyper(lines, sidePass, baseLineNums) {
item.variant = item.tokens[1].text;
item.tokens.splice(1, 1);
}
- if (item.tokens[1].text == 'exact') item.tokens.splice(1, 1); // TODO: Implement trap values
+ while (item.tokens[1].text in LLVM.MATHOP_IGNORABLES) item.tokens.splice(1, 1);
var segments = splitTokenList(item.tokens.slice(1));
item.params = [];
for (var i = 1; i <= 4; i++) {
diff --git a/src/jsifier.js b/src/jsifier.js
index b36e11ed..cb753e57 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -28,7 +28,7 @@ function JSify(data, functionsOnly, givenFunctions) {
if (mainPass) {
var shellFile = SHELL_FILE ? SHELL_FILE : (BUILD_AS_SHARED_LIB || SIDE_MODULE ? 'shell_sharedlib.js' : 'shell.js');
- if (phase == 'pre') {
+ if (phase == 'pre' || phase == 'glue') {
// We will start to print out the data, but must do so carefully - we are
// dealing with potentially *huge* strings. Convenient replacements and
// manipulations may create in-memory copies, and we may OOM.
@@ -72,7 +72,7 @@ function JSify(data, functionsOnly, givenFunctions) {
LibraryManager.load();
//B.stop('jsifier-libload');
- if (phase == 'pre') {
+ if (phase == 'pre' || phase == 'glue') {
var libFuncsToInclude;
if (INCLUDE_FULL_LIBRARY) {
assert(!(BUILD_AS_SHARED_LIB || SIDE_MODULE), 'Cannot have both INCLUDE_FULL_LIBRARY and BUILD_AS_SHARED_LIB/SIDE_MODULE set.')
@@ -474,7 +474,7 @@ function JSify(data, functionsOnly, givenFunctions) {
}
}
if (SIDE_MODULE) return ';'; // we import into the side module js library stuff from the outside parent
- if ((!ASM_JS || phase == 'pre') &&
+ if ((!ASM_JS || phase == 'pre' || phase == 'glue') &&
(EXPORT_ALL || (ident in EXPORTED_FUNCTIONS))) {
contentText += '\nModule["' + ident + '"] = ' + ident + ';';
}
@@ -490,10 +490,19 @@ function JSify(data, functionsOnly, givenFunctions) {
} else {
// If this is not linkable, anything not in the library is definitely missing
var cancel = false;
+ if (item.ident in DEAD_FUNCTIONS) {
+ if (LibraryManager.library[shortident + '__asm']) {
+ warn('cannot kill asm library function ' + item.ident);
+ } else {
+ LibraryManager.library[shortident] = new Function("Module['printErr']('dead function: " + shortident + "'); abort(-1);");
+ delete LibraryManager.library[shortident + '__inline'];
+ delete LibraryManager.library[shortident + '__deps'];
+ }
+ }
if (!LINKABLE && !LibraryManager.library.hasOwnProperty(shortident) && !LibraryManager.library.hasOwnProperty(shortident + '__inline')) {
if (ERROR_ON_UNDEFINED_SYMBOLS) error('unresolved symbol: ' + shortident);
- if (VERBOSE || WARN_ON_UNDEFINED_SYMBOLS) printErr('warning: unresolved symbol: ' + shortident);
- if (ASM_JS || item.ident in DEAD_FUNCTIONS) {
+ else if (VERBOSE || WARN_ON_UNDEFINED_SYMBOLS) warn('unresolved symbol: ' + shortident);
+ if (ASM_JS) {
// emit a stub that will fail during runtime. this allows asm validation to succeed.
LibraryManager.library[shortident] = new Function("Module['printErr']('missing function: " + shortident + "'); abort(-1);");
} else {
@@ -756,14 +765,7 @@ function JSify(data, functionsOnly, givenFunctions) {
if (func.setjmpTable && !ASM_JS) {
ret += ' } catch(e) { if (!e.longjmp || !(e.id in mySetjmpIds)) throw(e); setjmpTable[setjmpLabels[e.id]](e.value) }';
}
- if (ASM_JS && func.returnType !== 'void') {
- // Add a return
- if (func.returnType in Runtime.FLOAT_TYPES) {
- ret += ' return +0;\n';
- } else {
- ret += ' return 0;\n';
- }
- }
+ if (ASM_JS && func.returnType !== 'void') ret += ' return ' + asmInitializer(func.returnType) + ';\n'; // Add a return
} else {
ret += (SHOW_LABELS ? indent + '/* ' + block.entries[0] + ' */' : '') + '\n' + getLabelLines(block.labels[0]);
}
@@ -833,11 +835,7 @@ function JSify(data, functionsOnly, givenFunctions) {
var lastReturn = func.JS.lastIndexOf('return ');
if ((lastCurly < 0 && lastReturn < 0) || // no control flow, no return
(lastCurly >= 0 && lastReturn < lastCurly)) { // control flow, no return past last join
- if (func.returnType in Runtime.FLOAT_TYPES) {
- func.JS += ' return +0;\n';
- } else {
- func.JS += ' return 0;\n';
- }
+ func.JS += ' return ' + asmInitializer(func.returnType) + ';\n';
}
}
func.JS += '}\n';
@@ -948,11 +946,12 @@ function JSify(data, functionsOnly, givenFunctions) {
}
if (item.valueType[item.valueType.length-1] === '>') {
// vector store TODO: move to makeSetValue?
- var base = getVectorBaseType(item.valueType);
- return '(' + makeSetValue(item.ident, 0, value + '.x', base, 0, 0, item.align) + ',' +
- makeSetValue(item.ident, 4, value + '.y', base, 0, 0, item.align) + ',' +
- makeSetValue(item.ident, 8, value + '.z', base, 0, 0, item.align) + ',' +
- makeSetValue(item.ident, 12, value + '.w', base, 0, 0, item.align) + ')';
+ var native = getVectorNativeType(item.valueType);
+ var base = getSIMDName(native);
+ return '(' + makeSetValue(item.ident, 0, value + '.x', native, 0, 0, item.align) + ',' +
+ makeSetValue(item.ident, 4, value + '.y', native, 0, 0, item.align) + ',' +
+ makeSetValue(item.ident, 8, value + '.z', native, 0, 0, item.align) + ',' +
+ makeSetValue(item.ident, 12, value + '.w', native, 0, 0, item.align) + ');';
}
switch (impl) {
case VAR_NATIVIZED:
@@ -1323,11 +1322,12 @@ function JSify(data, functionsOnly, givenFunctions) {
var value = finalizeLLVMParameter(item.pointer);
if (item.valueType[item.valueType.length-1] === '>') {
// vector load
- var base = getVectorBaseType(item.valueType);
- return base + '32x4(' + makeGetValue(value, 0, base, 0, item.unsigned, 0, item.align) + ',' +
- makeGetValue(value, 4, base, 0, item.unsigned, 0, item.align) + ',' +
- makeGetValue(value, 8, base, 0, item.unsigned, 0, item.align) + ',' +
- makeGetValue(value, 12, base, 0, item.unsigned, 0, item.align) + ')';
+ var native = getVectorNativeType(item.valueType);
+ var base = getSIMDName(native);
+ return base + '32x4(' + makeGetValue(value, 0, native, 0, item.unsigned, 0, item.align) + ',' +
+ makeGetValue(value, 4, native, 0, item.unsigned, 0, item.align) + ',' +
+ makeGetValue(value, 8, native, 0, item.unsigned, 0, item.align) + ',' +
+ makeGetValue(value, 12, native, 0, item.unsigned, 0, item.align) + ');';
}
var impl = item.ident ? getVarImpl(item.funcData, item.ident) : VAR_EMULATED;
switch (impl) {
@@ -1335,7 +1335,7 @@ function JSify(data, functionsOnly, givenFunctions) {
if (isNumber(item.ident)) {
// Direct read from a memory address; this may be an intentional segfault, if not, it is a bug in the source
if (ASM_JS) {
- return asmCoercion('abort(' + item.ident + ')', item.type);
+ return asmFFICoercion('abort(' + item.ident + ')', item.type);
} else {
item.assignTo = null;
return 'throw "fault on read from ' + item.ident + '";';
@@ -1489,7 +1489,7 @@ function JSify(data, functionsOnly, givenFunctions) {
}
params.forEach(function(param, i) {
- var val = finalizeParam(param);
+ var val = finalizeLLVMParameter(param);
if (!hasVarArgs || useJSArgs || i < normalArgs) {
args.push(val);
argsTypes.push(param.type);
@@ -1512,8 +1512,10 @@ function JSify(data, functionsOnly, givenFunctions) {
args = args.map(function(arg, i) { return indexizeFunctions(arg, argsTypes[i]) });
if (ASM_JS) {
- if (shortident in Functions.libraryFunctions || simpleIdent in Functions.libraryFunctions || byPointerForced || invoke || extCall || funcData.setjmpTable) {
- args = args.map(function(arg, i) { return asmCoercion(arg, argsTypes[i]) });
+ var ffiCall = (shortident in Functions.libraryFunctions || simpleIdent in Functions.libraryFunctions || byPointerForced || invoke || extCall || funcData.setjmpTable) &&
+ !(simpleIdent in JS_MATH_BUILTINS);
+ if (ffiCall) {
+ args = args.map(function(arg, i) { return asmCoercion(arg, ensureValidFFIType(argsTypes[i])) });
} else {
args = args.map(function(arg, i) { return asmEnsureFloat(arg, argsTypes[i]) });
}
@@ -1590,7 +1592,7 @@ function JSify(data, functionsOnly, givenFunctions) {
returnType = getReturnType(type);
if (callIdent in Functions.implementedFunctions) {
// LLVM sometimes bitcasts for no reason. We must call using the exact same type as the actual function is generated as
- var trueType = Functions.getSignatureReturnType(Functions.implementedFunctions[callIdent]);
+ var trueType = Functions.getSignatureType(Functions.implementedFunctions[callIdent][0]);
if (trueType !== returnType && !isIdenticallyImplemented(trueType, returnType)) {
if (VERBOSE) warnOnce('Fixing function call based on return type from signature, on ' + [callIdent, returnType, trueType]);
returnType = trueType;
@@ -1626,7 +1628,11 @@ function JSify(data, functionsOnly, givenFunctions) {
var ret = callIdent + '(' + args.join(',') + ')';
if (ASM_JS) { // TODO: do only when needed (library functions and Math.*?) XXX && simpleIdent in Functions.libraryFunctions) {
- ret = asmCoercion(ret, returnType);
+ if (ffiCall) {
+ ret = asmFFICoercion(ret, returnType);
+ } else {
+ ret = asmCoercion(ret, returnType);
+ }
if (simpleIdent == 'abort' && funcData.returnType != 'void') {
ret += '; return ' + asmCoercion('0', funcData.returnType); // special case: abort() can happen without return, breaking the return type of asm functions. ensure a return
}
@@ -1698,7 +1704,7 @@ function JSify(data, functionsOnly, givenFunctions) {
//
if (!mainPass) {
- if (phase == 'pre' && !Variables.generatedGlobalBase && !BUILD_AS_SHARED_LIB) {
+ if ((phase == 'pre' || phase == 'glue') && !Variables.generatedGlobalBase && !BUILD_AS_SHARED_LIB) {
Variables.generatedGlobalBase = true;
// Globals are done, here is the rest of static memory
assert((TARGET_LE32 && Runtime.GLOBAL_BASE == 8) || (TARGET_X86 && Runtime.GLOBAL_BASE == 4)); // this is assumed in e.g. relocations for linkable modules
@@ -1713,7 +1719,7 @@ function JSify(data, functionsOnly, givenFunctions) {
var generated = itemsDict.function.concat(itemsDict.type).concat(itemsDict.GlobalVariableStub).concat(itemsDict.GlobalVariable);
print(generated.map(function(item) { return item.JS; }).join('\n'));
- if (phase == 'pre') {
+ if (phase == 'pre' || phase == 'glue') {
if (memoryInitialization.length > 0) {
// apply postsets directly into the big memory initialization
itemsDict.GlobalVariablePostSet = itemsDict.GlobalVariablePostSet.filter(function(item) {
@@ -1736,7 +1742,7 @@ function JSify(data, functionsOnly, givenFunctions) {
});
// write out the singleton big memory initialization value
print('/* memory initializer */ ' + makePointer(memoryInitialization, null, 'ALLOC_NONE', 'i8', 'Runtime.GLOBAL_BASE' + (SIDE_MODULE ? '+H_BASE' : ''), true));
- } else {
+ } else if (phase !== 'glue') {
print('/* no memory initializer */'); // test purposes
}
@@ -1774,7 +1780,7 @@ function JSify(data, functionsOnly, givenFunctions) {
}
// Print out global variables and postsets TODO: batching
- if (phase == 'pre') {
+ if (phase == 'pre' || phase == 'glue') {
var legalizedI64sDefault = legalizedI64s;
legalizedI64s = false;
diff --git a/src/library.js b/src/library.js
index 875d8bab..8425a10f 100644
--- a/src/library.js
+++ b/src/library.js
@@ -847,10 +847,7 @@ LibraryManager.library = {
___setErrNo(ERRNO_CODES.ERANGE);
return 0;
} else {
- for (var i = 0; i < cwd.length; i++) {
- {{{ makeSetValue('buf', 'i', 'cwd.charCodeAt(i)', 'i8') }}}
- }
- {{{ makeSetValue('buf', 'i', '0', 'i8') }}}
+ writeAsciiToMemory(cwd, buf);
return buf;
}
},
@@ -1193,7 +1190,6 @@ LibraryManager.library = {
_exit: function(status) {
// void _exit(int status);
// http://pubs.opengroup.org/onlinepubs/000095399/functions/exit.html
- Module.print('exit(' + status + ') called');
Module['exit'](status);
},
fork__deps: ['__setErrNo', '$ERRNO_CODES'],
@@ -1293,10 +1289,7 @@ LibraryManager.library = {
if (namesize < ret.length + 1) {
return ___setErrNo(ERRNO_CODES.ERANGE);
} else {
- for (var i = 0; i < ret.length; i++) {
- {{{ makeSetValue('name', 'i', 'ret.charCodeAt(i)', 'i8') }}}
- }
- {{{ makeSetValue('name', 'i', '0', 'i8') }}}
+ writeAsciiToMemory(ret, name);
return 0;
}
},
@@ -1579,12 +1572,12 @@ LibraryManager.library = {
// stdio.h
// ==========================================================================
- _isFloat: function(text) {
- return !!(/^[+-]?[0-9]*\.?[0-9]+([eE][+-]?[0-9]+)?$/.exec(text));
+ _getFloat: function(text) {
+ return /^[+-]?[0-9]*\.?[0-9]+([eE][+-]?[0-9]+)?/.exec(text);
},
// TODO: Document.
- _scanString__deps: ['_isFloat'],
+ _scanString__deps: ['_getFloat'],
_scanString: function(format, get, unget, varargs) {
if (!__scanString.whiteSpace) {
__scanString.whiteSpace = {};
@@ -1602,12 +1595,12 @@ LibraryManager.library = {
if (format.indexOf('%n') >= 0) {
// need to track soFar
var _get = get;
- get = function() {
+ get = function get() {
soFar++;
return _get();
}
var _unget = unget;
- unget = function() {
+ unget = function unget() {
soFar--;
return _unget();
}
@@ -1743,15 +1736,13 @@ LibraryManager.library = {
// Read characters according to the format. floats are trickier, they may be in an unfloat state in the middle, then be a valid float later
if (type == 'f' || type == 'e' || type == 'g' ||
type == 'F' || type == 'E' || type == 'G') {
- var last = 0;
next = get();
- while (next > 0) {
+ while (next > 0 && (!(next in __scanString.whiteSpace))) {
buffer.push(String.fromCharCode(next));
- if (__isFloat(buffer.join(''))) {
- last = buffer.length;
- }
next = get();
}
+ var m = __getFloat(buffer.join(''));
+ var last = m ? m[0].length : 0;
for (var i = 0; i < buffer.length - last + 1; i++) {
unget();
}
@@ -1864,7 +1855,11 @@ LibraryManager.library = {
// int x = 4; printf("%c\n", (char)x);
var ret;
if (type === 'double') {
+#if TARGET_LE32 == 2
+ ret = {{{ makeGetValue('varargs', 'argIndex', 'double', undefined, undefined, true, 4) }}};
+#else
ret = {{{ makeGetValue('varargs', 'argIndex', 'double', undefined, undefined, true) }}};
+#endif
#if USE_TYPED_ARRAYS == 2
} else if (type == 'i64') {
@@ -1885,7 +1880,11 @@ LibraryManager.library = {
type = 'i32'; // varargs are always i32, i64, or double
ret = {{{ makeGetValue('varargs', 'argIndex', 'i32', undefined, undefined, true) }}};
}
+#if TARGET_LE32 == 2
+ argIndex += Runtime.getNativeFieldSize(type);
+#else
argIndex += Math.max(Runtime.getNativeFieldSize(type), Runtime.getAlignSize(type, null, true));
+#endif
return ret;
}
@@ -2701,10 +2700,7 @@ LibraryManager.library = {
var result = dir + '/' + name;
if (!_tmpnam.buffer) _tmpnam.buffer = _malloc(256);
if (!s) s = _tmpnam.buffer;
- for (var i = 0; i < result.length; i++) {
- {{{ makeSetValue('s', 'i', 'result.charCodeAt(i)', 'i8') }}};
- }
- {{{ makeSetValue('s', 'i', '0', 'i8') }}};
+ writeAsciiToMemory(result, s);
return s;
},
tempnam__deps: ['tmpnam'],
@@ -2757,12 +2753,12 @@ LibraryManager.library = {
return -1;
}
var buffer = [];
- var get = function() {
+ function get() {
var c = _fgetc(stream);
buffer.push(c);
return c;
};
- var unget = function() {
+ function unget() {
_ungetc(buffer.pop(), stream);
};
return __scanString(format, get, unget, varargs);
@@ -2779,8 +2775,8 @@ LibraryManager.library = {
// int sscanf(const char *restrict s, const char *restrict format, ... );
// http://pubs.opengroup.org/onlinepubs/000095399/functions/scanf.html
var index = 0;
- var get = function() { return {{{ makeGetValue('s', 'index++', 'i8') }}}; };
- var unget = function() { index--; };
+ function get() { return {{{ makeGetValue('s', 'index++', 'i8') }}}; };
+ function unget() { index--; };
return __scanString(format, get, unget, varargs);
},
snprintf__deps: ['_formatString'],
@@ -3042,7 +3038,7 @@ LibraryManager.library = {
},
bsearch: function(key, base, num, size, compar) {
- var cmp = function(x, y) {
+ function cmp(x, y) {
#if ASM_JS
return Module['dynCall_iii'](compar, x, y);
#else
@@ -3205,7 +3201,7 @@ LibraryManager.library = {
}
}
if (!finalBase) finalBase = 10;
- start = str;
+ var start = str;
// Get digits.
var chr;
@@ -3345,10 +3341,7 @@ LibraryManager.library = {
var ptrSize = {{{ Runtime.getNativeTypeSize('i8*') }}};
for (var i = 0; i < strings.length; i++) {
var line = strings[i];
- for (var j = 0; j < line.length; j++) {
- {{{ makeSetValue('poolPtr', 'j', 'line.charCodeAt(j)', 'i8') }}};
- }
- {{{ makeSetValue('poolPtr', 'j', '0', 'i8') }}};
+ writeAsciiToMemory(line, poolPtr);
{{{ makeSetValue('envPtr', 'i * ptrSize', 'poolPtr', 'i8*') }}};
poolPtr += line.length + 1;
}
@@ -3978,10 +3971,7 @@ LibraryManager.library = {
return ___setErrNo(ERRNO_CODES.ERANGE);
} else {
var msg = ERRNO_MESSAGES[errnum];
- for (var i = 0; i < msg.length; i++) {
- {{{ makeSetValue('strerrbuf', 'i', 'msg.charCodeAt(i)', 'i8') }}}
- }
- {{{ makeSetValue('strerrbuf', 'i', 0, 'i8') }}}
+ writeAsciiToMemory(msg, strerrbuf);
return 0;
}
} else {
@@ -4166,6 +4156,11 @@ LibraryManager.library = {
},
// ==========================================================================
+ // GCC/LLVM specifics
+ // ==========================================================================
+ __builtin_prefetch: function(){},
+
+ // ==========================================================================
// LLVM specifics
// ==========================================================================
@@ -5064,10 +5059,7 @@ LibraryManager.library = {
var layout = {{{ JSON.stringify(C_STRUCTS.utsname) }}};
function copyString(element, value) {
var offset = layout[element];
- for (var i = 0; i < value.length; i++) {
- {{{ makeSetValue('name', 'offset + i', 'value.charCodeAt(i)', 'i8') }}}
- }
- {{{ makeSetValue('name', 'offset + i', '0', 'i8') }}}
+ writeAsciiToMemory(value, name + offset);
}
if (name === 0) {
return -1;
@@ -5110,7 +5102,7 @@ LibraryManager.library = {
table[from + i] = {};
sigs.forEach(function(sig) { // TODO: new Function etc.
var full = 'dynCall_' + sig;
- table[from + i][sig] = function() {
+ table[from + i][sig] = function dynCall_sig() {
arguments[0] -= from;
return asm[full].apply(null, arguments);
}
@@ -5134,7 +5126,7 @@ LibraryManager.library = {
// patch js module dynCall_* to use functionTable
sigs.forEach(function(sig) {
- jsModule['dynCall_' + sig] = function() {
+ jsModule['dynCall_' + sig] = function dynCall_sig() {
return table[arguments[0]][sig].apply(null, arguments);
};
});
@@ -5297,6 +5289,16 @@ LibraryManager.library = {
}
},
+ dladdr: function(addr, info) {
+ // report all function pointers as coming from this program itself XXX not really correct in any way
+ var fname = allocate(intArrayFromString("/bin/this.program"), 'i8', ALLOC_NORMAL); // XXX leak
+ {{{ makeSetValue('addr', 0, 'fname', 'i32') }}};
+ {{{ makeSetValue('addr', QUANTUM_SIZE, '0', 'i32') }}};
+ {{{ makeSetValue('addr', QUANTUM_SIZE*2, '0', 'i32') }}};
+ {{{ makeSetValue('addr', QUANTUM_SIZE*3, '0', 'i32') }}};
+ return 1;
+ },
+
// ==========================================================================
// pwd.h
// ==========================================================================
@@ -5598,7 +5600,7 @@ LibraryManager.library = {
var WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
- var leadingSomething = function(value, digits, character) {
+ function leadingSomething(value, digits, character) {
var str = typeof value === 'number' ? value.toString() : (value || '');
while (str.length < digits) {
str = character[0]+str;
@@ -5606,12 +5608,12 @@ LibraryManager.library = {
return str;
};
- var leadingNulls = function(value, digits) {
+ function leadingNulls(value, digits) {
return leadingSomething(value, digits, '0');
};
- var compareByDay = function(date1, date2) {
- var sgn = function(value) {
+ function compareByDay(date1, date2) {
+ function sgn(value) {
return value < 0 ? -1 : (value > 0 ? 1 : 0);
};
@@ -5624,7 +5626,7 @@ LibraryManager.library = {
return compare;
};
- var getFirstWeekStartDate = function(janFourth) {
+ function getFirstWeekStartDate(janFourth) {
switch (janFourth.getDay()) {
case 0: // Sunday
return new Date(janFourth.getFullYear()-1, 11, 29);
@@ -5643,7 +5645,7 @@ LibraryManager.library = {
}
};
- var getWeekBasedYear = function(date) {
+ function getWeekBasedYear(date) {
var thisDate = __addDays(new Date(date.tm_year+1900, 0, 1), date.tm_yday);
var janFourthThisYear = new Date(thisDate.getFullYear(), 0, 4);
@@ -5930,8 +5932,8 @@ LibraryManager.library = {
var matches = new RegExp('^'+pattern).exec(Pointer_stringify(buf))
// Module['print'](Pointer_stringify(buf)+ ' is matched by '+((new RegExp('^'+pattern)).source)+' into: '+JSON.stringify(matches));
- var initDate = function() {
- var fixup = function(value, min, max) {
+ function initDate() {
+ function fixup(value, min, max) {
return (typeof value !== 'number' || isNaN(value)) ? min : (value>=min ? (value<=max ? value: max): min);
};
return {
@@ -5948,7 +5950,7 @@ LibraryManager.library = {
var date = initDate();
var value;
- var getMatch = function(symbol) {
+ function getMatch(symbol) {
var pos = capture.indexOf(symbol);
// check if symbol appears in regexp
if (pos >= 0) {
@@ -6118,16 +6120,23 @@ LibraryManager.library = {
// int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
var seconds = {{{ makeGetValue('rqtp', C_STRUCTS.timespec.tv_sec, 'i32') }}};
var nanoseconds = {{{ makeGetValue('rqtp', C_STRUCTS.timespec.tv_nsec, 'i32') }}};
- {{{ makeSetValue('rmtp', C_STRUCTS.timespec.tv_sec, '0', 'i32') }}}
- {{{ makeSetValue('rmtp', C_STRUCTS.timespec.tv_nsec, '0', 'i32') }}}
+ if (rmtp !== 0) {
+ {{{ makeSetValue('rmtp', C_STRUCTS.timespec.tv_sec, '0', 'i32') }}}
+ {{{ makeSetValue('rmtp', C_STRUCTS.timespec.tv_nsec, '0', 'i32') }}}
+ }