aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-04-17 18:39:00 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-04-17 18:39:00 -0700
commitf72cf763607f2d69044493e9d1c3a818248ea929 (patch)
treef46bde8fd00104e5074c3d99ee848813e49685ff
parentb48fb4d83121ee776cce12a7be43afed7332bd7d (diff)
finalize parameters in getGetElementPtrIndexes
-rw-r--r--src/jsifier.js13
-rw-r--r--tests/runner.py21
2 files changed, 28 insertions, 6 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 261f5316..8e469c2b 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -835,14 +835,16 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
} });
function getGetElementPtrIndexes(item) {
- var ident = item.ident;
- var type = item.params[0].type; // param 0 == type
+ var type = item.params[0].type;
+ item.params = item.params.map(finalizeLLVMParameter);
+ var ident = item.params[0];
+
// struct pointer, struct*, and getting a ptr to an element in that struct. Param 1 is which struct, then we have items in that
// struct, and possibly further substructures, all embedded
// can also be to 'blocks': [8 x i32]*, not just structs
type = removePointing(type);
var indexes = [makeGetPos(ident)];
- var offset = toNiceIdent(item.params[1].ident);
+ var offset = item.params[1];
if (offset != 0) {
if (isStructType(type)) {
indexes.push(getFastValue(Types.types[type].flatSize, '*', offset));
@@ -851,8 +853,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
}
}
item.params.slice(2, item.params.length).forEach(function(arg) {
- dprint('types', 'GEP type: ' + type);
- var curr = toNiceIdent(arg.ident);
+ var curr = arg;
// TODO: If index is constant, optimize
var typeData = Types.types[type];
if (isStructType(type) && typeData.needsFlattening) {
@@ -893,7 +894,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
function finalizeLLVMFunctionCall(item) {
switch(item.intertype) {
- case 'getelementptr': // TODO finalizeLLVMParameter on the ident and the indexes?
+ case 'getelementptr':
return makePointer(makeGetSlabs(item.ident, item.type)[0], getGetElementPtrIndexes(item), null, item.type);
case 'bitcast':
case 'inttoptr':
diff --git a/tests/runner.py b/tests/runner.py
index 635a4d0f..6e061cd1 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -463,6 +463,27 @@ if 'benchmark' not in sys.argv:
'''
self.do_test(src, '*3.14,-3.14,Infinity*')
+ def test_getgep(self):
+ # Generated code includes getelementptr (getelementptr, 0, 1), i.e., GEP as the first param to GEP
+ src = '''
+ #include <stdio.h>
+ struct {
+ int y[10];
+ int z[10];
+ } commonblock;
+
+ int main()
+ {
+ for (int i = 0; i < 10; ++i) {
+ commonblock.y[i] = 1;
+ commonblock.z[i] = 2;
+ }
+ printf("*%d %d*\\n", commonblock.y[0], commonblock.z[0]);
+ return 0;
+ }
+ '''
+ self.do_test(src, '*1 2*')
+
def test_if(self):
src = '''
#include <stdio.h>