aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/analyzer.js1
-rw-r--r--src/intertyper.js2
-rw-r--r--src/jsifier.js9
-rw-r--r--src/library.js24
-rw-r--r--src/parseTools.js2
-rw-r--r--tests/runner.py4
-rw-r--r--third_party/gcc_demangler.c8
7 files changed, 44 insertions, 6 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index e7f0dfff..eb9ad555 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -333,6 +333,7 @@ function analyzer(data) {
var line = lines[i];
var item = line.value;
if (!item || item.intertype != 'alloca') continue;
+ assert(item.allocatedNum === 1);
item.allocatedSize = func.variables[line.ident].impl === VAR_EMULATED ?
calcAllocatedSize(item.allocatedType, data.types) : 0;
total += item.allocatedSize;
diff --git a/src/intertyper.js b/src/intertyper.js
index d1778396..7c93750f 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -467,11 +467,13 @@ function intertyper(data) {
this.forwardItem(item, 'Reintegrator');
},
});
+
// 'alloca'
substrate.addZyme('Alloca', {
processItem: function(item) {
item.intertype = 'alloca';
item.allocatedType = item.tokens[1].text;
+ item.allocatedNum = isNumberType(item.tokens[3].text) ? toNiceIdent(item.tokens[4].text) : 1;
item.type = addPointing(item.tokens[1].text); // type of pointer we will get
item.type2 = item.tokens[1].text; // value we will create, and get a pointer to
this.forwardItem(item, 'Reintegrator');
diff --git a/src/jsifier.js b/src/jsifier.js
index 18e1d649..d20409ea 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -612,9 +612,12 @@ function JSify(data) {
return item.ident + '.f' + item.indexes[0][0].text;
});
makeFuncLineZyme('alloca', function(item) {
- assert(typeof item.allocatedIndex === 'number'); // or, return RuntimeGenerator.stackAlloc(calcAllocatedSize(item.allocatedType, TYPES));
- if (item.allocatedSize === 0) return ''; // This will not actually be shown - it's nativized
- return getFastValue('__stackBase__', '+', item.allocatedIndex.toString());
+ if (typeof item.allocatedIndex === 'number') {
+ if (item.allocatedSize === 0) return ''; // This will not actually be shown - it's nativized
+ return getFastValue('__stackBase__', '+', item.allocatedIndex.toString());
+ } else {
+ return RuntimeGenerator.stackAlloc(getFastValue(calcAllocatedSize(item.allocatedType, TYPES), '*', item.allocatedNum));
+ }
});
makeFuncLineZyme('phi', function(item) {
return '__lastLabel__ == ' + getLabelId(item.label1) + ' ? ' + toNiceIdent(item.value1) + ' : ' + toNiceIdent(item.value2);
diff --git a/src/library.js b/src/library.js
index 7d831d20..210b79e1 100644
--- a/src/library.js
+++ b/src/library.js
@@ -119,6 +119,15 @@ var Library = {
return chr >= '0'.charCodeAt(0) && chr <= '9'.charCodeAt(0);
},
+ memcmp: function(p1, p2, num) {
+ for (var i = 0; i < num; i++) {
+ var v1 = IHEAP[p1+i];
+ var v2 = IHEAP[p2+i];
+ if (v1 != v2) return v1 > v2 ? 1 : -1;
+ }
+ return 0;
+ },
+
// LLVM specifics
__assert_fail: function(condition, file, line) {
@@ -153,6 +162,21 @@ var Library = {
};
},
+ llvm_stacksave: function() {
+ var self = _llvm_stacksave;
+ if (!self.LLVM_SAVEDSTACKS) {
+ self.LLVM_SAVEDSTACKS = [];
+ }
+ self.LLVM_SAVEDSTACKS.push(STACKTOP);
+ return self.LLVM_SAVEDSTACKS.length-1;
+ },
+ llvm_stackrestore: function(p) {
+ var self = _llvm_stacksave;
+ var ret = self.LLVM_SAVEDSTACKS[p];
+ self.LLVM_SAVEDSTACKS.splice(p, 1);
+ return ret;
+ },
+
// iostream
_ZNSt8ios_base4InitC1Ev: function() {
diff --git a/src/parseTools.js b/src/parseTools.js
index fe8d1159..6e8f8b47 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -56,7 +56,7 @@ function toNiceIdent(ident) {
assert(ident);
if (parseFloat(ident) == ident) return ident;
if (ident == 'null') return '0'; // see parseNumerical
- return ident.replace(/[" \.@%:<>,\*]/g, '_');
+ return ident.replace(/[" \.@%:<>,\*\[\]]/g, '_');
}
INT_TYPES = searchable('i1', 'i8', 'i16', 'i32', 'i64');
diff --git a/tests/runner.py b/tests/runner.py
index cf7a7b22..793bdb26 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -908,8 +908,8 @@ if 'benchmark' not in sys.argv:
self.do_test(path_from_root(['tests', 'sauer']), '*\nTemp is 33\n9\n5\nhello, everyone\n*', main_file='command.cpp')
- def test_gcc_unmangler(self):
- self.do_test(path_from_root(['third_party']), '*unmangled*', main_file='gcc_demangler.c')
+ def zzztest_gcc_unmangler(self):
+ self.do_test(path_from_root(['third_party']), '*d_demangle(char const*, int, unsigned int*)*', main_file='gcc_demangler.c')
# Generate tests for all our compilers
def make_test(compiler, embetter):
diff --git a/third_party/gcc_demangler.c b/third_party/gcc_demangler.c
index 6cfbb19e..69de5e76 100644
--- a/third_party/gcc_demangler.c
+++ b/third_party/gcc_demangler.c
@@ -1,5 +1,6 @@
#include <string.h>
#include <stdlib.h>
+#define IN_LIBGCC2
/* Demangler for g++ V3 ABI.
Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
@@ -4216,3 +4217,10 @@ is_gnu_v3_mangled_dtor (const char *name)
#endif /* IN_GLIBCPP_V3 */
+int main()
+{
+ int status;
+ printf("*%s*\n", __cxa_demangle("_ZL10d_demanglePKciPj", 0, 0, &status));
+ return 1;
+}
+