aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@mozilla.com>2010-12-02 22:28:38 -0800
committerAlon Zakai <azakai@mozilla.com>2010-12-02 22:28:38 -0800
commit1f70fe65a943f3867c12895986bfbc63190981de (patch)
treee9e76a4256cd1fbfd3b325efae53a44ba6eb5d19
parent70a93a3622a27ddbf26771dfe2cac8153686e036 (diff)
handle bitcasts etc. of call() idents +test
-rw-r--r--src/intertyper.js7
-rw-r--r--src/parseTools.js18
-rw-r--r--tests/cases/sillybitcast.ll35
-rw-r--r--tests/runner.py1
4 files changed, 58 insertions, 3 deletions
diff --git a/src/intertyper.js b/src/intertyper.js
index 8c0136a3..b4c009f5 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -524,11 +524,12 @@ function intertyper(data, parseFunctions, baseLineNum) {
}
item.type = item.tokens[1].text;
item.functionType = '';
- while (['@', '%'].indexOf(item.tokens[2].text[0]) == -1) {
+ while (['@', '%'].indexOf(item.tokens[2].text[0]) == -1 && !(item.tokens[2].text in PARSABLE_LLVM_FUNCTIONS)) {
item.functionType += item.tokens[2].text;
item.tokens.splice(2, 1);
}
- item.ident = item.tokens[2].text;
+ var tokensLeft = item.tokens.slice(2);
+ item.ident = eatLLVMIdent(tokensLeft);
if (item.ident.substr(-2) == '()') {
// See comment in isStructType()
item.ident = item.ident.substr(0, item.ident.length-2);
@@ -538,7 +539,7 @@ function intertyper(data, parseFunctions, baseLineNum) {
}
item.params = [];
} else {
- item.params = parseParamTokens(item.tokens[3].item.tokens);
+ item.params = parseParamTokens(tokensLeft[0].item.tokens);
}
if (item.indent == 2) {
// standalone call - not in assign
diff --git a/src/parseTools.js b/src/parseTools.js
index d2e746ca..968550e1 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -341,6 +341,24 @@ function parseLLVMFunctionCall(segment) {
return ret;
}
+// Gets an array of tokens, we parse out the first
+// 'ident' - either a simple ident of one token, or
+// an LLVM internal function that generates an ident.
+// We shift out of the array list the tokens that
+// we ate.
+function eatLLVMIdent(tokens) {
+ var ret;
+ if (tokens[0].text in PARSABLE_LLVM_FUNCTIONS) {
+ ret = parseLLVMFunctionCall([{text: 'i0'}].concat(tokens.slice(0,2))).ident; // TODO: Handle more cases, return a full object, process it later
+ tokens.shift();
+ tokens.shift();
+ } else {
+ ret = tokens[0].text;
+ tokens.shift();
+ }
+ return ret;
+}
+
function cleanOutTokens(filterOut, tokens, index) {
while (filterOut.indexOf(tokens[index].text) != -1) {
tokens.splice(index, 1);
diff --git a/tests/cases/sillybitcast.ll b/tests/cases/sillybitcast.ll
new file mode 100644
index 00000000..c5ca4f9a
--- /dev/null
+++ b/tests/cases/sillybitcast.ll
@@ -0,0 +1,35 @@
+; ModuleID = '/tmp/emscripten/tmp/src.cpp.o'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
+target triple = "i386-pc-linux-gnu"
+
+@.str = private constant [14 x i8] c"hello, world!\00", align 1 ; [#uses=1]
+
+; [#uses=2]
+define void @"\01_Z5hellov"() {
+entry:
+ %0 = call i32 bitcast (i32 (i8*)* @puts to i32 (i32*)*)(i8* getelementptr inbounds ([14 x i8]* @.str, i32 0, i32 0)) ; [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+; [#uses=1]
+declare i32 @puts(i8*)
+
+; [#uses=0]
+define i32 @main() {
+entry:
+ %retval = alloca i32 ; [#uses=2]
+ %0 = alloca i32 ; [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; [#uses=0]
+ call void @"\01_Z5hellov"()
+ store i32 0, i32* %0, align 4
+ %1 = load i32* %0, align 4 ; [#uses=1]
+ store i32 %1, i32* %retval, align 4
+ br label %return
+
+return: ; preds = %entry
+ %retval1 = load i32* %retval ; [#uses=1]
+ ret i32 %retval1
+}
diff --git a/tests/runner.py b/tests/runner.py
index aa22e06c..59e44102 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -1110,6 +1110,7 @@ if 'benchmark' not in sys.argv:
def test_cases(self):
for name in os.listdir(path_from_root(['tests', 'cases'])):
+ print "Testing case '%s'..." % name.replace('.ll', '')
self.do_ll_test(path_from_root(['tests', 'cases', name]), 'hello, world!')
### Integration tests