diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/intertyper.js | 17 | ||||
-rw-r--r-- | src/jsifier.js | 14 | ||||
-rw-r--r-- | src/library.js | 85 | ||||
-rw-r--r-- | src/settings.js | 2 |
4 files changed, 66 insertions, 52 deletions
diff --git a/src/intertyper.js b/src/intertyper.js index 7bc23653..6b46cdbb 100644 --- a/src/intertyper.js +++ b/src/intertyper.js @@ -366,6 +366,8 @@ function intertyper(data, sidePass, baseLineNums) { return '/dev/null'; if (tokensLength >= 3 && token0Text == 'invoke') return 'Invoke'; + if (tokensLength >= 3 && token0Text == 'atomicrmw' || token0Text == 'cmpxchg') + return 'Atomic'; } else { // Already intertyped if (item.parentSlot) @@ -739,6 +741,21 @@ function intertyper(data, sidePass, baseLineNums) { return result.ret; } }); + substrate.addActor('Atomic', { + processItem: function(item) { + item.intertype = 'atomic'; + if (item.tokens[0].text == 'atomicrmw') { + item.op = item.tokens[1].text; + item.tokens.splice(1, 1); + } else { + assert(item.tokens[0].text == 'cmpxchg') + item.op = 'cmpxchg'; + } + var last = getTokenIndexByText(item.tokens, ';'); + item.params = splitTokenList(item.tokens.slice(1, last)).map(parseLLVMSegment); + this.forwardItem(item, 'Reintegrator'); + } + }); // 'landingpad' - just a stub implementation substrate.addActor('Landingpad', { processItem: function(item) { diff --git a/src/jsifier.js b/src/jsifier.js index db6936f6..69a64d1a 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -944,6 +944,20 @@ function JSify(data, functionsOnly, givenFunctions) { + ' } else { ' + getPhiSetsForLabel(phiSets, item.unwindLabel) + makeBranch(item.unwindLabel, item.currLabelId) + ' }'; return ret; }); + makeFuncLineActor('atomic', function(item) { + var type = item.params[0].type; + var param1 = finalizeLLVMParameter(item.params[0]); + var param2 = finalizeLLVMParameter(item.params[1]); + switch (item.op) { + case 'add': return '(tempValue=' + makeGetValue(param1, 0, type) + ',' + makeSetValue(param1, 0, 'tempValue+' + param2, type) + ',tempValue)'; + case 'xchg': return '(tempValue=' + makeGetValue(param1, 0, type) + ',' + makeSetValue(param1, 0, param2, type) + ',tempValue)'; + case 'cmpxchg': { + var param3 = finalizeLLVMParameter(item.params[2]); + return '(tempValue=' + makeGetValue(param1, 0, type) + ',(' + makeGetValue(param1, 0, type) + '==' + param2 + ' && (' + makeSetValue(param1, 0, param3, type) + ')),tempValue)'; + } + default: throw 'unhandled atomic op: ' + item.op; + } + }); makeFuncLineActor('landingpad', function(item) { // Just a stub return '{ f0: ' + makeGetValue('_llvm_eh_exception.buf', '0', 'void*') + diff --git a/src/library.js b/src/library.js index 2aace0fb..5a429131 100644 --- a/src/library.js +++ b/src/library.js @@ -3683,6 +3683,32 @@ LibraryManager.library = { } }, + mbtowc: function(pwc, pmb, maxx) { + // XXX doesn't really handle multibyte at all + if (!pmb) return 0; + maxx = Math.min({{{ cDefine('_NL_CTYPE_MB_CUR_MAX') }}}, maxx); + var i; + for (i = 0; i < maxx; i++) { + var curr = {{{ makeGetValue('pmb', 0, 'i8') }}}; + if (pwc) { + {{{ makeSetValue('pwc', '0', 'curr', 'i8') }}}; + {{{ makeSetValue('pwc', '1', '0', 'i8') }}}; + pwc += 2; + } + pmb++; + if (!curr) break; + } + return i; + }, + + wcrtomb: function(s, wc, ps) { + // XXX doesn't really handle multibyte at all + if (s) { + {{{ makeSetValue('s', '0', 'wc', 'i8') }}}; + } + return 1; + }, + // ========================================================================== // string.h // ========================================================================== @@ -4465,57 +4491,6 @@ LibraryManager.library = { llvm_lifetime_end: function() {}, // ========================================================================== - // iostream.h - // ========================================================================== - - // libc++ - - $libcxx__postset: 'try { __ZNSt3__14coutE = 1 } catch(e){}; try { __ZNSt3__14cerrE = 2 } catch(e){};', - $libcxx: {}, - - _ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEElsEPKv__deps: ['fputs', '$libcxx'], - _ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEElsEPKv: function(stream, str) { - _fputs(str, _stdout); // XXX stderr etc. - }, - - _ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEElsEi__deps: ['fputs', '$libcxx'], - _ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEElsEi: function(stream, num) { - _fputs(allocate(intArrayFromString(num.toString()), 'i8', ALLOC_STACK), _stdout); - }, - - _ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEElsEPFRS3_S4_E__deps: ['fputc', '$libcxx'], - _ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEElsEPFRS3_S4_E: function(stream, x) { - _fputc('\n'.charCodeAt(0), _stdout); - }, - - // glibc - - _ZNSt8ios_base4InitC1Ev: function() { - // need valid 'file descriptors' for glibc - //__ZSt4cout = 1; - //__ZSt4cerr = 2; - }, - _ZNSt8ios_base4InitD1Ev: '_ZNSt8ios_base4InitC1Ev', - _ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_: 0, // endl - _ZNSolsEd__deps: ['putchar'], - _ZNSolsEd: function(undefined_stream, data) { - _putchar('\n'.charCodeAt(0)); - }, - _ZNSolsEPFRSoS_E: '_ZNSolsEd', - _ZNSolsEi__deps: ['putchar'], - _ZNSolsEi: function(undefined_stream, data) { - var str = String(data); - for (var i = 0; i < str.length; i++) { - _putchar(str.charCodeAt(i)); - } - }, - _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc__deps: ['fputs', 'stdout'], - _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc: function(undefined_stream, data) { - _fputs(data, {{{ makeGetValue('_stdout', '0', 'void*') }}}); - }, - _ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_i: '_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc', - - // ========================================================================== // math.h // ========================================================================== @@ -5265,6 +5240,14 @@ LibraryManager.library = { // locale.h // ========================================================================== + newlocale: function(mask, locale, base) { + return 0; + }, + + uselocale: function(locale) { + return 0; + }, + setlocale: function(category, locale) { if (!_setlocale.ret) _setlocale.ret = allocate([0], 'i8', ALLOC_NORMAL); return _setlocale.ret; diff --git a/src/settings.js b/src/settings.js index 587e2f16..1d62cbbf 100644 --- a/src/settings.js +++ b/src/settings.js @@ -200,7 +200,7 @@ var RUNTIME_TYPE_INFO = 0; // Whether to expose type info to the script at run t // to more easily perform operations from handwritten JS on // objects with structures etc. -var FAKE_X86_FP80 = 0; // Replaces x86_fp80 with double. This loses precision. It is better, +var FAKE_X86_FP80 = 1; // Replaces x86_fp80 with double. This loses precision. It is better, // if you can, to get the original source code to build without x86_fp80 // (which is nonportable anyhow). |