Start generating LLVM code for IR::Call nodes.
authorRoberto Raggi <roberto.raggi@nokia.com>
Tue, 5 Jun 2012 13:26:21 +0000 (15:26 +0200)
committerRoberto Raggi <roberto.raggi@nokia.com>
Tue, 5 Jun 2012 13:26:21 +0000 (15:26 +0200)
llvm_runtime.cpp
qv4isel_llvm.cpp

index 7f5593baead5f21d1b2d26d3a3c665dc89750ebb..288f99a890984b23f9bb3f09462dd8d92dc56333 100644 (file)
@@ -154,4 +154,14 @@ void __qmljs_llvm_not(Context *ctx, Value *result, const Value *value)
     __qmljs_not(ctx, result, value);
 }
 
+String *__qmljs_llvm_get_identifier(Context *ctx, const char *str)
+{
+    return __qmljs_string_from_utf8(ctx, str); // ### make it unique
+}
+
+void __qmljs_llvm_call_activation_property(Context *context, Value *result, String *name, Value *args, int argc)
+{
+    __qmljs_call_activation_property(context, result, name, args, argc);
+}
+
 } // extern "C"
index 1d4f412f0ece5ed91885c4e4d4bf4f0e885dc185..08d2738c8bc614fcf6cfdcd49fdeafd67f6ac62c 100644 (file)
@@ -6,6 +6,7 @@
 #include <llvm/Support/MemoryBuffer.h>
 #include <llvm/Bitcode/ReaderWriter.h>
 #include <llvm/Linker.h>
+#include <cstdio>
 
 using namespace QQmlJS;
 
@@ -354,8 +355,37 @@ void LLVMInstructionSelection::genBinop(llvm::Value *result, IR::Binop *e)
 
 void LLVMInstructionSelection::visitCall(IR::Call *e)
 {
-    llvm::Value *base = getLLVMValue(e->base);
-    Q_UNIMPLEMENTED();
+    llvm::Value *func = 0;
+    llvm::Value *base = 0;
+    if (IR::Temp *t = e->asTemp()) {
+        base = getLLVMTemp(t);
+        func = _llvmModule->getFunction("__qmljs_llvm_call_value");
+    } else if (IR::Name *n = e->asName()) {
+        llvm::Value *str = getStringPtr(*n->id);
+        base = CreateCall2(_llvmModule->getFunction("__qmljs_llvm_get_identifier"),
+                           _llvmFunction->arg_begin(), str);
+        func = _llvmModule->getFunction("__qmljs_llvm_call_activation_property");
+    }
+
+    int argc = 0;
+    for (IR::ExprList *it = e->args; it; it = it->next) {
+        ++argc;
+    }
+
+    llvm::Value *args = argc ? CreateAlloca(_valueTy, getInt32(argc)) : 0;
+
+    int i = 0;
+    for (IR::ExprList *it = e->args; it; it = it->next) {
+        llvm::Value *arg = getLLVMValue(it->expr);
+        CreateStore(arg, CreateConstGEP1_32(args, i++));
+    }
+
+    if (func) {
+        llvm::Value *result = llvm::Constant::getNullValue(_valueTy);
+        CreateCall5(func, _llvmFunction->arg_begin(), result, base, args, getInt32(argc));
+    } else {
+        Q_UNIMPLEMENTED();
+    }
 }
 
 void LLVMInstructionSelection::visitNew(IR::New *e)