aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-05-01 10:01:16 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-05-01 10:01:16 -0700
commit18c03af5f0ee66eb0d75ba3892cd31c72ea6d5c2 (patch)
tree499f1d85ab2a8431a1137cecb8f8fb82d4d41f7c
parent48ae14de71a389f29fdb6542e04e1c805788f5bb (diff)
parentcb42d258c2ca1035cac73e7635992d997f9df735 (diff)
Merge branch 'newtriple' into incoming
-rwxr-xr-xemcc13
-rwxr-xr-xemscripten.py2
-rw-r--r--src/analyzer.js19
-rw-r--r--src/corruptionCheck.js6
-rw-r--r--src/intertyper.js12
-rw-r--r--src/jsifier.js40
-rw-r--r--src/library.js70
-rw-r--r--src/modules.js2
-rw-r--r--src/parseTools.js22
-rw-r--r--src/preamble.js6
-rw-r--r--src/runtime.js32
-rw-r--r--src/settings.js3
-rw-r--r--tests/lua/COPYRIGHT34
-rw-r--r--tests/lua/Makefile250
-rw-r--r--tests/lua/README6
-rw-r--r--tests/lua/doc/contents.html533
-rw-r--r--tests/lua/doc/logo.gifbin0 -> 4232 bytes
-rw-r--r--tests/lua/doc/lua.1116
-rw-r--r--tests/lua/doc/lua.css83
-rw-r--r--tests/lua/doc/luac.1118
-rw-r--r--tests/lua/doc/manual.css26
-rw-r--r--tests/lua/doc/manual.html10507
-rw-r--r--tests/lua/doc/osi-certified-72x60.pngbin0 -> 3774 bytes
-rw-r--r--tests/lua/doc/readme.html412
-rw-r--r--tests/lua/lua.ll78513
-rw-r--r--tests/lua/src/Makefile191
-rw-r--r--tests/lua/src/lapi.c1284
-rw-r--r--tests/lua/src/lapi.h24
-rw-r--r--tests/lua/src/lauxlib.c959
-rw-r--r--tests/lua/src/lauxlib.h212
-rw-r--r--tests/lua/src/lbaselib.c458
-rw-r--r--tests/lua/src/lbitlib.c211
-rw-r--r--tests/lua/src/lcode.c881
-rw-r--r--tests/lua/src/lcode.h83
-rw-r--r--tests/lua/src/lcorolib.c155
-rw-r--r--tests/lua/src/lctype.c52
-rw-r--r--tests/lua/src/lctype.h95
-rw-r--r--tests/lua/src/ldblib.c398
-rw-r--r--tests/lua/src/ldebug.c580
-rw-r--r--tests/lua/src/ldebug.h34
-rw-r--r--tests/lua/src/ldo.c673
-rw-r--r--tests/lua/src/ldo.h46
-rw-r--r--tests/lua/src/ldump.c173
-rw-r--r--tests/lua/src/lfunc.c161
-rw-r--r--tests/lua/src/lfunc.h33
-rw-r--r--tests/lua/src/lgc.c1213
-rw-r--r--tests/lua/src/lgc.h157
-rw-r--r--tests/lua/src/linit.c67
-rw-r--r--tests/lua/src/liolib.c665
-rw-r--r--tests/lua/src/llex.c527
-rw-r--r--tests/lua/src/llex.h78
-rw-r--r--tests/lua/src/llimits.h309
-rw-r--r--tests/lua/src/lmathlib.c279
-rw-r--r--tests/lua/src/lmem.c99
-rw-r--r--tests/lua/src/lmem.h57
-rw-r--r--tests/lua/src/loadlib.c725
-rw-r--r--tests/lua/src/lobject.c287
-rw-r--r--tests/lua/src/lobject.h607
-rw-r--r--tests/lua/src/lopcodes.c107
-rw-r--r--tests/lua/src/lopcodes.h288
-rw-r--r--tests/lua/src/loslib.c323
-rw-r--r--tests/lua/src/lparser.c1638
-rw-r--r--tests/lua/src/lparser.h119
-rw-r--r--tests/lua/src/lstate.c322
-rw-r--r--tests/lua/src/lstate.h228
-rw-r--r--tests/lua/src/lstring.c185
-rw-r--r--tests/lua/src/lstring.h46
-rw-r--r--tests/lua/src/lstrlib.c1019
-rw-r--r--tests/lua/src/ltable.c588
-rw-r--r--tests/lua/src/ltable.h41
-rw-r--r--tests/lua/src/ltablib.c283
-rw-r--r--tests/lua/src/ltm.c77
-rw-r--r--tests/lua/src/ltm.h57
-rw-r--r--tests/lua/src/lua.c497
-rw-r--r--tests/lua/src/lua.h444
-rw-r--r--tests/lua/src/lua.hpp9
-rw-r--r--tests/lua/src/luac.c432
-rw-r--r--tests/lua/src/luaconf.h551
-rw-r--r--tests/lua/src/lualib.h55
-rw-r--r--tests/lua/src/lundump.c258
-rw-r--r--tests/lua/src/lundump.h28
-rw-r--r--tests/lua/src/lvm.c867
-rw-r--r--tests/lua/src/lvm.h44
-rw-r--r--tests/lua/src/lzio.c76
-rw-r--r--tests/lua/src/lzio.h65
-rw-r--r--tests/python/python.le32.bcbin0 -> 7810608 bytes
-rw-r--r--tests/python/readme.txt16
-rwxr-xr-xtests/runner.py183
-rw-r--r--tools/shared.py46
89 files changed, 32683 insertions, 78807 deletions
diff --git a/emcc b/emcc
index 079f6edc..a32089c1 100755
--- a/emcc
+++ b/emcc
@@ -557,6 +557,7 @@ if CONFIGURE_CONFIG or CMAKE_CONFIG:
cmd = [compiler] + list(filter_emscripten_options(sys.argv[1:]))
if not use_js: cmd += shared.EMSDK_OPTS + ['-DEMSCRIPTEN']
+ if use_js: cmd += ['-s', 'ERROR_ON_UNDEFINED_SYMBOLS=1'] # configure tests should fail when an undefined symbol exists
if DEBUG: print >> sys.stderr, 'emcc, just configuring: ', ' '.join(cmd)
if debug_configure: open(tempout, 'a').write('emcc, just configuring: ' + ' '.join(cmd) + '\n\n')
@@ -1032,6 +1033,18 @@ try:
if minify_whitespace is None:
minify_whitespace = opt_level >= 2 and not keep_js_debug
+ assert shared.LLVM_TARGET in shared.COMPILER_OPTS
+ if shared.LLVM_TARGET == 'i386-pc-linux-gnu':
+ shared.Settings.TARGET_X86 = 1
+ shared.Settings.TARGET_LE32 = 0
+ assert 'le32-unknown-nacl' not in shared.COMPILER_OPTS
+ elif shared.LLVM_TARGET == 'le32-unknown-nacl':
+ shared.Settings.TARGET_LE32 = 1
+ shared.Settings.TARGET_X86 = 0
+ assert 'i386-pc-linux-gnu' not in shared.COMPILER_OPTS
+ else:
+ raise Exception('unknown llvm target: ' + str(shared.LLVM_TARGET))
+
## Compile source code to bitcode
if DEBUG: print >> sys.stderr, 'emcc: compiling to bitcode'
diff --git a/emscripten.py b/emscripten.py
index 6c758942..f4bfed82 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -529,7 +529,7 @@ var asm = (function(global, env, buffer) {
var ret = 0;
ret = STACKTOP;
STACKTOP = (STACKTOP + size)|0;
- STACKTOP = ((STACKTOP + 3)>>2)<<2;
+''' + ('STACKTOP = ((STACKTOP + 3)>>2)<<2;' if settings['TARGET_X86'] else 'STACKTOP = ((STACKTOP + 7)>>3)<<3;') + '''
return ret|0;
}
function stackSave() {
diff --git a/src/analyzer.js b/src/analyzer.js
index 7fbdf24d..03d44cb7 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -469,6 +469,23 @@ function analyzer(data, sidePass) {
i++;
continue; // special case, handled in makeComparison
}
+ case 'va_arg': {
+ assert(value.type == 'i64');
+ assert(value.value.type == 'i32*', value.value.type);
+ i += removeAndAdd(label.lines, i, range(2).map(function(x) {
+ return {
+ intertype: 'va_arg',
+ assignTo: value.assignTo + '$' + x,
+ type: 'i32',
+ value: {
+ intertype: 'value',
+ ident: value.value.ident, // We read twice from the same i32* var, incrementing // + '$' + x,
+ type: 'i32*'
+ }
+ };
+ }));
+ continue;
+ }
case 'extractvalue': { // XXX we assume 32-bit alignment in extractvalue/insertvalue,
// but in theory they can run on packed structs too (see use getStructuralTypePartBits)
// potentially legalize the actual extracted value too if it is >32 bits, not just the extraction in general
@@ -1492,7 +1509,7 @@ function analyzer(data, sidePass) {
calcAllocatedSize(item.allocatedType)*item.allocatedNum: 0;
if (USE_TYPED_ARRAYS === 2) {
// We need to keep the stack aligned
- item.allocatedSize = Runtime.forceAlign(item.allocatedSize, QUANTUM_SIZE);
+ item.allocatedSize = Runtime.forceAlign(item.allocatedSize, Runtime.STACK_ALIGN);
}
}
var index = 0;
diff --git a/src/corruptionCheck.js b/src/corruptionCheck.js
index 315f5cf0..8b37120a 100644
--- a/src/corruptionCheck.js
+++ b/src/corruptionCheck.js
@@ -42,7 +42,7 @@ var CorruptionChecker = {
CorruptionChecker.checkAll();
var size = CorruptionChecker.ptrs[ptr];
//Module.printErr('free ' + ptr + ' of size ' + size);
- assert(size);
+ assert(size, ptr);
var allocation = ptr - size*CorruptionChecker.BUFFER_FACTOR;
//Module.printErr('free ' + ptr + ' of size ' + size + ' and allocation ' + allocation);
delete CorruptionChecker.ptrs[ptr];
@@ -67,12 +67,12 @@ var CorruptionChecker = {
},
fillBuffer: function(buffer, size) {
for (var x = buffer; x < buffer + size; x++) {
- {{{ makeSetValue('x', 0, 'CorruptionChecker.canary(x)', 'i8') }}};
+ {{{ makeSetValue('x', 0, 'CorruptionChecker.canary(x)', 'i8', null, null, null, 1) }}};
}
},
checkBuffer: function(buffer, size) {
for (var x = buffer; x < buffer + size; x++) {
- if (({{{ makeGetValue('x', 0, 'i8') }}}&255) != CorruptionChecker.canary(x)) {
+ if (({{{ makeGetValue('x', 0, 'i8', null, null, null, null, 1) }}}&255) != CorruptionChecker.canary(x)) {
assert(0, 'Heap corruption detected!' + [x, buffer, size, {{{ makeGetValue('x', 0, 'i8') }}}&255, CorruptionChecker.canary(x)]);
}
}
diff --git a/src/intertyper.js b/src/intertyper.js
index 57e3011d..445c37f4 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -336,6 +336,8 @@ function intertyper(data, sidePass, baseLineNums) {
return 'InsertValue';
if (tokensLength >= 3 && token0Text == 'phi')
return 'Phi';
+ if (tokensLength >= 3 && token0Text == 'va_arg')
+ return 'va_arg';
if (tokensLength >= 3 && token0Text == 'landingpad')
return 'Landingpad';
if (token0Text == 'fence')
@@ -817,6 +819,16 @@ function intertyper(data, sidePass, baseLineNums) {
this.forwardItem(item, 'Reintegrator');
}
});
+ // 'phi'
+ substrate.addActor('va_arg', {
+ processItem: function(item) {
+ item.intertype = 'va_arg';
+ var segments = splitTokenList(item.tokens.slice(1));
+ item.type = segments[1][0].text;
+ item.value = parseLLVMSegment(segments[0]);
+ this.forwardItem(item, 'Reintegrator');
+ }
+ });
// mathops
substrate.addActor('Mathops', {
processItem: function(item) {
diff --git a/src/jsifier.js b/src/jsifier.js
index 5fcf6b18..9207f65d 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -1295,6 +1295,14 @@ function JSify(data, functionsOnly, givenFunctions) {
return RuntimeGenerator.stackAlloc(getFastValue(calcAllocatedSize(item.allocatedType), '*', item.allocatedNum));
}
});
+ makeFuncLineActor('va_arg', function(item) {
+ assert(TARGET_LE32);
+ var ident = item.value.ident;
+ var move = Runtime.STACK_ALIGN;
+ return '(tempInt=' + makeGetValue(ident, 4, '*') + ',' +
+ makeSetValue(ident, 4, 'tempInt + ' + move, '*') + ',' +
+ makeGetValue(makeGetValue(ident, 0, '*'), 'tempInt', item.type) + ')';
+ });
makeFuncLineActor('mathop', processMathop);
@@ -1318,16 +1326,21 @@ function JSify(data, functionsOnly, givenFunctions) {
ident = Variables.resolveAliasToIdent(ident);
var shortident = ident.slice(1);
var simpleIdent = shortident;
- var callIdent = LibraryManager.getRootIdent(simpleIdent);
- if (callIdent) {
- simpleIdent = callIdent; // ident may not be in library, if all there is is ident__inline, but in this case it is
- if (callIdent.indexOf('.') < 0) {
- callIdent = '_' + callIdent; // Not Math.*, so add the normal prefix
- }
+ if (isLocalVar(ident)) {
+ var callIdent = ident;
} else {
- callIdent = ident;
+ // Not a local var, check if in library
+ var callIdent = LibraryManager.getRootIdent(simpleIdent);
+ if (callIdent) {
+ simpleIdent = callIdent; // ident may not be in library, if all there is is ident__inline, but in this case it is
+ if (callIdent.indexOf('.') < 0) {
+ callIdent = '_' + callIdent; // Not Math.*, so add the normal prefix
+ }
+ } else {
+ callIdent = ident;
+ }
+ if (callIdent == '0') return 'abort(-2)';
}
- if (callIdent == '0') return 'abort(-2)';
var args = [];
var argsTypes = [];
@@ -1358,6 +1371,7 @@ function JSify(data, functionsOnly, givenFunctions) {
} else {
size = Runtime.getNativeFieldSize(param.type);
}
+ size = Runtime.alignMemory(size, Runtime.STACK_ALIGN);
varargs.push(val);
varargs = varargs.concat(zeros(size-1));
// TODO: replace concats like this with push
@@ -1391,15 +1405,14 @@ function JSify(data, functionsOnly, givenFunctions) {
var type = varargsTypes[i];
if (type == 0) return null;
var ret;
+ assert(offset % Runtime.STACK_ALIGN == 0); // varargs must be aligned
if (!varargsByVals[i]) {
ret = makeSetValue(getFastValue('tempInt', '+', offset), 0, arg, type, null, null, QUANTUM_SIZE, null, ',');
- offset += Runtime.getNativeFieldSize(type);
+ offset += Runtime.alignMemory(Runtime.getNativeFieldSize(type), Runtime.STACK_ALIGN);
} else {
- assert(offset % 4 == 0); // varargs must be aligned
var size = calcAllocatedSize(removeAllPointing(type));
- assert(size % 4 == 0); // varargs must stay aligned
ret = makeCopyValues(getFastValue('tempInt', '+', offset), arg, size, null, null, varargsByVals[i], ',');
- offset += size;
+ offset += Runtime.forceAlign(size, Runtime.STACK_ALIGN);
}
return ret;
}).filter(function(arg) {
@@ -1585,10 +1598,11 @@ function JSify(data, functionsOnly, givenFunctions) {
sortGlobals(globalsData.globalVariables).forEach(function(g) {
var ident = g.ident;
if (!isIndexableGlobal(ident)) return;
+ assert(Variables.nextIndexedOffset % Runtime.STACK_ALIGN == 0);
Variables.indexedGlobals[ident] = Variables.nextIndexedOffset;
Variables.nextIndexedOffset += Runtime.alignMemory(calcAllocatedSize(Variables.globals[ident].type));
if (ident.substr(0, 5) == '__ZTV') { // leave room for null-terminating the vtable
- Variables.nextIndexedOffset += Runtime.getNativeTypeSize('i32');
+ Variables.nextIndexedOffset += Runtime.alignMemory(QUANTUM_SIZE);
}
});
}
diff --git a/src/library.js b/src/library.js
index 9b63084f..ade63d45 100644
--- a/src/library.js
+++ b/src/library.js
@@ -2499,7 +2499,7 @@ LibraryManager.library = {
for (var formatIndex = 0; formatIndex < format.length;) {
if (format[formatIndex] === '%' && format[formatIndex+1] == 'n') {
var argPtr = {{{ makeGetValue('varargs', 'argIndex', 'void*') }}};
- argIndex += Runtime.getNativeFieldSize('void*');
+ argIndex += Runtime.getAlignSize('void*', null, true);
{{{ makeSetValue('argPtr', 0, 'soFar', 'i32') }}};
formatIndex += 2;
continue;
@@ -2508,7 +2508,7 @@ LibraryManager.library = {
// TODO: Support strings like "%5c" etc.
if (format[formatIndex] === '%' && format[formatIndex+1] == 'c') {
var argPtr = {{{ makeGetValue('varargs', 'argIndex', 'void*') }}};
- argIndex += Runtime.getNativeFieldSize('void*');
+ argIndex += Runtime.getAlignSize('void*', null, true);
fields++;
next = get();
{{{ makeSetValue('argPtr', 0, 'next', 'i8') }}}
@@ -2600,7 +2600,7 @@ LibraryManager.library = {
var text = buffer.join('');
var argPtr = {{{ makeGetValue('varargs', 'argIndex', 'void*') }}};
- argIndex += Runtime.getNativeFieldSize('void*');
+ argIndex += Runtime.getAlignSize('void*', null, true);
switch (type) {
case 'd': case 'u': case 'i':
if (half) {
@@ -2669,8 +2669,16 @@ LibraryManager.library = {
ret = {{{ makeGetValue('varargs', 'argIndex', 'double', undefined, undefined, true) }}};
#if USE_TYPED_ARRAYS == 2
} else if (type == 'i64') {
+
+#if TARGET_LE32
+ ret = [{{{ makeGetValue('varargs', 'argIndex', 'i32', undefined, undefined, true) }}},
+ {{{ makeGetValue('varargs', 'argIndex+8', 'i32', undefined, undefined, true) }}}];
+ argIndex += {{{ STACK_ALIGN }}}; // each 32-bit chunk is in a 64-bit block
+#else
ret = [{{{ makeGetValue('varargs', 'argIndex', 'i32', undefined, undefined, true) }}},
{{{ makeGetValue('varargs', 'argIndex+4', 'i32', undefined, undefined, true) }}}];
+#endif
+
#else
} else if (type == 'i64') {
ret = {{{ makeGetValue('varargs', 'argIndex', 'i64', undefined, undefined, true) }}};
@@ -2679,7 +2687,7 @@ LibraryManager.library = {
type = 'i32'; // varargs are always i32, i64, or double
ret = {{{ makeGetValue('varargs', 'argIndex', 'i32', undefined, undefined, true) }}};
}
- argIndex += Runtime.getNativeFieldSize(type);
+ argIndex += Math.max(Runtime.getNativeFieldSize(type), Runtime.getAlignSize(type, null, true));
return ret;
}
@@ -3612,6 +3620,9 @@ LibraryManager.library = {
asprintf: function(s, format, varargs) {
return _sprintf(-s, format, varargs);
},
+
+#if TARGET_X86
+ // va_arg is just like our varargs
vfprintf: 'fprintf',
vsnprintf: 'snprintf',
vprintf: 'printf',
@@ -3620,6 +3631,44 @@ LibraryManager.library = {
vscanf: 'scanf',
vfscanf: 'fscanf',
vsscanf: 'sscanf',
+#endif
+
+#if TARGET_LE32
+ // convert va_arg into varargs
+ vfprintf__deps: ['fprintf'],
+ vfprintf: function(s, f, va_arg) {
+ return _fprintf(s, f, {{{ makeGetValue('va_arg', 0, '*') }}});
+ },
+ vsnprintf__deps: ['snprintf'],
+ vsnprintf: function(s, n, format, va_arg) {
+ return _snprintf(s, n, format, {{{ makeGetValue('va_arg', 0, '*') }}});
+ },