aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
5 files changed, 34 insertions, 4 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');