aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compiler.js2
-rw-r--r--src/intertyper.js2
-rw-r--r--src/library.js23
-rw-r--r--src/preamble.js19
-rw-r--r--src/runtime.js9
5 files changed, 35 insertions, 20 deletions
diff --git a/src/compiler.js b/src/compiler.js
index 2dea5797..33f0e1fb 100644
--- a/src/compiler.js
+++ b/src/compiler.js
@@ -152,7 +152,7 @@ if (!MICRO_OPTS || !RELOOP || ASSERTIONS || CHECK_SIGNS || CHECK_OVERFLOWS || IN
print('// Note: For maximum-speed code, see "Optimizing Code" on the Emscripten wiki, https://github.com/kripken/emscripten/wiki/Optimizing-Code');
}
-if (CORRECT_SIGNS || CORRECT_OVERFLOWS || CORRECT_ROUNDINGS) {
+if (DOUBLE_MODE || I64_MODE || CORRECT_SIGNS || CORRECT_OVERFLOWS || CORRECT_ROUNDINGS) {
print('// Note: Some Emscripten settings may limit the speed of the generated code.');
}
diff --git a/src/intertyper.js b/src/intertyper.js
index ba9e3f0d..4b4544ae 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -801,7 +801,7 @@ function intertyper(data, sidePass, baseLineNums) {
var segments = splitTokenList(item.tokens.slice(1));
for (var i = 1; i <= 4; i++) {
if (segments[i-1]) {
- if (i > 1 && segments[i-1].length == 1 && segments[0].length > 1) {
+ if (i > 1 && segments[i-1].length == 1 && segments[0].length > 1 && !isType(segments[i-1][0].text)) {
segments[i-1].unshift(segments[0][0]); // Add the type from the first segment, they are all alike
}
item['param'+i] = parseLLVMSegment(segments[i-1]);
diff --git a/src/library.js b/src/library.js
index 2a4a5e7d..1747155f 100644
--- a/src/library.js
+++ b/src/library.js
@@ -2111,15 +2111,12 @@ LibraryManager.library = {
// TODO: We could in theory slice off the top of the HEAP when
// sbrk gets a negative increment in |bytes|...
var self = _sbrk;
- if (!self.STATICTOP) {
- STATICTOP = alignMemoryPage(STATICTOP);
- self.STATICTOP = STATICTOP;
- self.DATASIZE = 0;
- } else {
- assert(self.STATICTOP == STATICTOP, "No one should touch the heap!");
+ if (!self.called) {
+ STATICTOP = alignMemoryPage(STATICTOP); // make sure we start out aligned
+ self.called = true;
}
- var ret = STATICTOP + self.DATASIZE;
- self.DATASIZE += alignMemoryPage(bytes);
+ var ret = STATICTOP;
+ if (bytes != 0) Runtime.staticAlloc(bytes);
return ret; // Previous break location.
},
open64: 'open',
@@ -4323,6 +4320,16 @@ LibraryManager.library = {
_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() {
diff --git a/src/preamble.js b/src/preamble.js
index cd9138d4..51e22390 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -23,6 +23,15 @@ var ACCEPTABLE_SAFE_HEAP_ERRORS = 0;
function SAFE_HEAP_ACCESS(dest, type, store, ignore) {
//if (dest === A_NUMBER) print ([dest, type, store] + ' ' + new Error().stack); // Something like this may be useful, in debugging
+
+#if USE_TYPED_ARRAYS
+ // When using typed arrays, reads over the top of TOTAL_MEMORY will fail silently, so we must
+ // correct that by growing TOTAL_MEMORY as needed. Without typed arrays, memory is a normal
+ // JS array so it will work (potentially slowly, depending on the engine).
+ assert(dest < STATICTOP);
+ assert(STATICTOP <= TOTAL_MEMORY);
+#endif
+
#if USE_TYPED_ARRAYS == 2
return; // It is legitimate to violate the load-store assumption in this case
#endif
@@ -452,10 +461,10 @@ function allocate(slab, types, allocator) {
size = slab.length;
}
- var ret = [_malloc, Runtime.stackAlloc, Runtime.staticAlloc][allocator === undefined ? ALLOC_STATIC : allocator](Math.max(size, 1));
-
var singleType = typeof types === 'string' ? types : null;
+ var ret = [_malloc, Runtime.stackAlloc, Runtime.staticAlloc][allocator === undefined ? ALLOC_STATIC : allocator](Math.max(size, singleType ? 1 : types.length));
+
var i = 0, type;
while (i < size) {
var curr = zeroinit ? 0 : slab[i];
@@ -533,12 +542,11 @@ var HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32;
var STACK_ROOT, STACKTOP, STACK_MAX;
var STATICTOP;
#if USE_TYPED_ARRAYS
-var LAST_STATICTOP;
function enlargeMemory() {
- // LAST_STATICTOP is the previous top, TOTAL_MEMORY is the current size of the actual array, and STATICTOP is the new top.
+ // TOTAL_MEMORY is the current size of the actual array, and STATICTOP is the new top.
#if ASSERTIONS
printErr('Warning: Enlarging memory arrays, this is not fast! ' + [STATICTOP, TOTAL_MEMORY]);
- assert(STATICTOP >= TOTAL_MEMORY && LAST_STATICTOP < TOTAL_MEMORY);
+ assert(STATICTOP >= TOTAL_MEMORY);
assert(TOTAL_MEMORY > 4); // So the loop below will not be infinite
#endif
while (TOTAL_MEMORY <= STATICTOP) { // Simple heuristic. Override enlargeMemory() if your program has something more optimal for it
@@ -610,6 +618,7 @@ var FAST_MEMORY = Module['FAST_MEMORY'] || {{{ FAST_MEMORY }}};
var base = intArrayFromString('(null)'); // So printing %s of NULL gives '(null)'
// Also this ensures we leave 0 as an invalid address, 'NULL'
+STATICTOP = base.length;
for (var i = 0; i < base.length; i++) {
{{{ makeSetValue(0, 'i', 'base[i]', 'i8') }}}
}
diff --git a/src/runtime.js b/src/runtime.js
index 0b36f967..e1a6db39 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -10,7 +10,7 @@ var RuntimeGenerator = {
alloc: function(size, type, init) {
var ret = type + 'TOP';
if (ASSERTIONS) {
- ret += '; assert(' + size + ' > 0, "Trying to allocate 0")';
+ ret += '; assert(' + size + ' != 0, "Trying to allocate 0")';
}
if (init) {
ret += '; _memset(' + type + 'TOP, 0, ' + size + ')';
@@ -54,11 +54,10 @@ var RuntimeGenerator = {
return ret += 'STACKTOP = __stackBase__';
},
- // An allocation that cannot be free'd
+ // An allocation that cannot normally be free'd (except through sbrk, which once
+ // called, takes control of STATICTOP)
staticAlloc: function(size) {
- var ret = '';
- if (USE_TYPED_ARRAYS) ret += 'LAST_STATICTOP = STATICTOP;'
- ret += RuntimeGenerator.alloc(size, 'STATIC', INIT_HEAP);
+ var ret = RuntimeGenerator.alloc(size, 'STATIC', INIT_HEAP);
if (USE_TYPED_ARRAYS) ret += '; if (STATICTOP >= TOTAL_MEMORY) enlargeMemory();'
return ret;
},