aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralon@honor <none@none>2010-10-01 20:58:15 -0700
committeralon@honor <none@none>2010-10-01 20:58:15 -0700
commit9a60dd64cdccc60d7a789ffa1f16536f8b106a0b (patch)
treee74085575573ccdcacc2a3b43f18c545eb265395
parent73a87bedee8b225ed76c8efebe1a032d0bf91ec5 (diff)
test+fix for modifying fields of global structures
-rw-r--r--src/analyzer.js3
-rw-r--r--src/jsifier.js33
-rw-r--r--src/library.js5
-rw-r--r--tests/runner.py22
4 files changed, 46 insertions, 17 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index 13c5c648..aa9a8031 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -682,6 +682,9 @@ function analyzer(data) {
});
// Optimizer
+ // XXX: load, store and gep now have pointer/value/data from which we copy the ident into a toplevel ident.
+ // However, we later read the non-toplevel ident in some cases, so optimizer changes can lead to bugs.
+ // Need to remove the toplevel, work entirely with the non-toplevel. Single location.
substrate.addZyme('Optimizer', {
processItem: function(item) {
var that = this;
diff --git a/src/jsifier.js b/src/jsifier.js
index 7f5a86cd..057130e8 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -384,27 +384,28 @@ function JSify(data) {
});
}
makeFuncLineZyme('store', function(item) {
- var ident = toNiceIdent(item.ident);
- var value;
- value = finalizeLLVMParameter(item.value);
+ var value = finalizeLLVMParameter(item.value);
if (pointingLevels(item.pointerType.text) == 1) {
value = parseNumerical(value, removePointing(item.pointerType.text));
}
- //print("// zz seek " + ident + ',' + dump(item));
- var impl = getVarData(item.funcData, item.ident);
- var ret;
- switch (impl) {
- case VAR_NATIVIZED: ret = ident + ' = ' + value + ';'; break; // We have the actual value here
- case VAR_EMULATED: ret = makeSetValue(ident, 0, value) + ';'; break;
- default: print('zz unknown [store] impl: ' + impl);
+ var impl = VAR_EMULATED;
+ if (item.pointer.intertype == 'value') {
+ impl = getVarData(item.funcData, item.ident);
}
-/*
- if (LINEDEBUG && value) {
- ret += '\nprint(INDENT + "' + ident + ' == " + JSON.stringify(' + ident + '));';
- ret += '\nprint(INDENT + "' + ident + ' == " + (' + ident + ' && ' + ident + '.toString ? ' + ident + '.toString() : ' + ident + '));';
+ switch (impl) {
+ case VAR_NATIVIZED:
+ return item.ident + ' = ' + value + ';'; // We have the actual value here
+ break;
+ case VAR_EMULATED:
+ if (item.pointer.intertype == 'value') {
+ return makeSetValue(item.ident, 0, value) + ';';
+ } else {
+ return makeSetValue(0, getGetElementPtrIndexes(item.pointer), value) + ';';
+ }
+ break;
+ default:
+ throw 'unknown [store] impl: ' + impl;
}
-*/
- return ret;
});
var LABEL_IDs = {};
diff --git a/src/library.js b/src/library.js
index a6fbcf02..72d7f599 100644
--- a/src/library.js
+++ b/src/library.js
@@ -139,7 +139,7 @@ var Library = {
},
llvm_eh_exception: function() {
- return Error();
+ return 'code-generated exception';
},
llvm_eh_selector: function(exception, personality, num) {
@@ -149,6 +149,9 @@ var Library = {
throw exception;
},
+ __gxx_personality_v0: function() {
+ },
+
// iostream
_ZNSt8ios_base4InitC1Ev: function() {
diff --git a/tests/runner.py b/tests/runner.py
index d2c5e4f1..08bb8648 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -541,6 +541,28 @@ class T(unittest.TestCase):
'''
self.do_test(src, '*70,97,15,3,3029,90*')
+ def test_mod_globalstruct(self):
+ src = '''
+ #include <stdio.h>
+
+ struct malloc_params {
+ size_t magic, page_size;
+ };
+
+ malloc_params mparams;
+
+ #define SIZE_T_ONE ((size_t)1)
+ #define page_align(S) (((S) + (mparams.page_size - SIZE_T_ONE)) & ~(mparams.page_size - SIZE_T_ONE))
+
+ int main()
+ {
+ mparams.page_size = 4096;
+ printf("*%d,%d,%d,%d*\\n", mparams.page_size, page_align(1000), page_align(6000), page_align(66474));
+ return 0;
+ }
+ '''
+ self.do_test(src, '*4096,4096,8192,69632*')
+
def test_ptrtoint(self):
src = '''
#include <stdio.h>