aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/jsifier.js18
-rw-r--r--src/utility.js9
-rw-r--r--tests/runner.py65
3 files changed, 81 insertions, 11 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index aadc021c..e5ab6b4c 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -137,11 +137,15 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions) {
soFar++;
}
// Add current value(s)
- var currValue = values[i];
+ var currValue = flatten(values[i]);
ret.push(currValue);
i += 1;
soFar += typeof currValue === 'object' ? currValue.length : 1;
}
+ while (soFar < typeData.flatSize) {
+ ret.push(0);
+ soFar++;
+ }
return ret;
}
@@ -215,14 +219,6 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions) {
function parseConst(value, type, ident) {
var constant = makeConst(value, type);
if (typeof constant === 'object') {
- function flatten(x) {
- if (typeof x !== 'object') return x;
- var ret = [];
- for (var i = 0; i < x.length; i++) {
- ret = ret.concat(flatten(x[i]));
- }
- return ret;
- }
constant = flatten(constant).map(function(x) { return parseNumerical(x) })
}
return constant;
@@ -863,12 +859,12 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions) {
function finalizeLLVMFunctionCall(item) {
switch(item.intertype) {
- case 'getelementptr':
+ case 'getelementptr': // XXX finalizeLLVMParameter on the ident and the indexes?
return makePointer(makeGetSlab(item.ident, item.type), getGetElementPtrIndexes(item), null, item.type);
case 'bitcast':
case 'inttoptr':
case 'ptrtoint':
- return item.ident;
+ return finalizeLLVMParameter(item.params[0]);
default:
throw 'Invalid function to finalize: ' + dump(item);
}
diff --git a/src/utility.js b/src/utility.js
index 5020c911..68fab711 100644
--- a/src/utility.js
+++ b/src/utility.js
@@ -227,3 +227,12 @@ function isNumber(x) {
return x == parseFloat(x);
}
+function flatten(x) {
+ if (typeof x !== 'object') return x;
+ var ret = [];
+ for (var i = 0; i < x.length; i++) {
+ ret = ret.concat(flatten(x[i]));
+ }
+ return ret;
+}
+
diff --git a/tests/runner.py b/tests/runner.py
index a931ced9..d523dbba 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -751,6 +751,71 @@ if 'benchmark' not in sys.argv:
'''
self.do_test(src, '*4096,4096,8192,69632*')
+ def test_pystruct(self):
+ if COMPILER != LLVM_GCC: return # TODO: Clang here
+ if F_OPTS: return # TODO: fix
+ src = '''
+ #include <stdio.h>
+
+ // Based on CPython code
+ union PyGC_Head {
+ struct {
+ union PyGC_Head *gc_next;
+ union PyGC_Head *gc_prev;
+ size_t gc_refs;
+ } gc;
+ long double dummy; /* force worst-case alignment */
+ } ;
+
+ struct gc_generation {
+ PyGC_Head head;
+ int threshold; /* collection threshold */
+ int count; /* count of allocations or collections of younger
+ generations */
+ };
+
+ #define NUM_GENERATIONS 3
+ #define GEN_HEAD(n) (&generations[n].head)
+
+ /* linked lists of container objects */
+ static struct gc_generation generations[NUM_GENERATIONS] = {
+ /* PyGC_Head, threshold, count */
+ {{{GEN_HEAD(0), GEN_HEAD(0), 0}}, 700, 0},
+ {{{GEN_HEAD(1), GEN_HEAD(1), 0}}, 10, 0},
+ {{{GEN_HEAD(2), GEN_HEAD(2), 0}}, 10, 0},
+ };
+
+ int main()
+ {
+ gc_generation *n = NULL;
+ printf("*%d,%d,%d,%d,%d,%d,%d,%d*\\n",
+ (int)(&n[0]),
+ (int)(&n[0].head),
+ (int)(&n[0].head.gc.gc_next),
+ (int)(&n[0].head.gc.gc_prev),
+ (int)(&n[0].head.gc.gc_refs),
+ (int)(&n[0].threshold), (int)(&n[0].count), (int)(&n[1])
+ );
+ printf("*%d,%d,%d*\\n",
+ (int)(&generations[0]) ==
+ (int)(&generations[0].head.gc.gc_next),
+ (int)(&generations[0]) ==
+ (int)(&generations[0].head.gc.gc_prev),
+ (int)(&generations[0]) ==
+ (int)(&generations[1])
+ );
+ int x1 = (int)(&generations[0]);
+ int x2 = (int)(&generations[1]);
+ printf("*%d*\\n", x1 == x2);
+ for (int i = 0; i < NUM_GENERATIONS; i++) {
+ PyGC_Head *list = GEN_HEAD(i);
+ printf("%d:%d,%d\\n", i, (int)list == (int)(list->gc.gc_prev), (int)list ==(int)(list->gc.gc_next));
+ }
+ printf("*%d*\\n", int(GEN_HEAD(2)) - int(GEN_HEAD(1)));
+ }
+ '''
+ self.do_test(src, '*0,0,0,4,8,12,16,20*\n*1,0,0*\n*0*\n0:1,1\n1:1,1\n2:1,1\n*20*')
+
def test_ptrtoint(self):
src = '''
#include <stdio.h>