From b1e62cc60749e3a55805df7ed493ec84587dc3bd Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Wed, 6 Jun 2012 11:30:56 +0200 Subject: [PATCH] Generate LLVM code for member expressions --- llvm_runtime.cpp | 5 +++++ qv4isel_llvm.cpp | 26 ++++++++++++++++++++------ qv4isel_llvm_p.h | 1 + 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/llvm_runtime.cpp b/llvm_runtime.cpp index e70240484b..2cb043ff59 100644 --- a/llvm_runtime.cpp +++ b/llvm_runtime.cpp @@ -170,4 +170,9 @@ void __qmljs_llvm_construct_activation_property(Context *context, Value *result, __qmljs_construct_activation_property(context, result, name, args, argc); } +void __qmljs_llvm_get_property(Context *ctx, Value *result, Value *object, String *name) +{ + __qmljs_get_property(ctx, result, object, name); +} + } // extern "C" diff --git a/qv4isel_llvm.cpp b/qv4isel_llvm.cpp index f193979ea8..4be0da1ebc 100644 --- a/qv4isel_llvm.cpp +++ b/qv4isel_llvm.cpp @@ -188,6 +188,14 @@ llvm::Value *LLVMInstructionSelection::getStringPtr(const QString &s) return value; } +llvm::Value *LLVMInstructionSelection::getIdentifier(const QString &s) +{ + llvm::Value *str = getStringPtr(s); + llvm::Value *id = CreateCall2(_llvmModule->getFunction("__qmljs_llvm_get_identifier"), + _llvmFunction->arg_begin(), str); + return id; +} + void LLVMInstructionSelection::visitExp(IR::Exp *s) { getLLVMValue(s->expr); @@ -378,9 +386,7 @@ void LLVMInstructionSelection::visitCall(IR::Call *e) func = _llvmModule->getFunction("__qmljs_llvm_call_value"); } else if (IR::Name *n = e->base->asName()) { if (n->id) { - llvm::Value *str = getStringPtr(*n->id); - base = CreateCall2(_llvmModule->getFunction("__qmljs_llvm_get_identifier"), - _llvmFunction->arg_begin(), str); + base = getIdentifier(*n->id); func = _llvmModule->getFunction("__qmljs_llvm_call_activation_property"); } } @@ -460,8 +466,16 @@ void LLVMInstructionSelection::visitSubscript(IR::Subscript *) Q_UNIMPLEMENTED(); } -void LLVMInstructionSelection::visitMember(IR::Member *) +void LLVMInstructionSelection::visitMember(IR::Member *e) { - Q_UNIMPLEMENTED(); -} + IR::Temp *t = e->base->asTemp(); + assert(t); + llvm::Value *result = newLLVMTemp(_valueTy); + llvm::Value *base = getLLVMTemp(t); + llvm::Value *name = getIdentifier(*e->name); + + CreateCall4(_llvmModule->getFunction("__qmljs_llvm_get_property"), + _llvmFunction->arg_begin(), result, base, name); + _llvmValue = CreateLoad(result); +} diff --git a/qv4isel_llvm_p.h b/qv4isel_llvm_p.h index 67cbb7f16f..292421eeec 100644 --- a/qv4isel_llvm_p.h +++ b/qv4isel_llvm_p.h @@ -23,6 +23,7 @@ public: llvm::Value *getLLVMCondition(IR::Expr *expr); llvm::Value *getLLVMTemp(IR::Temp *temp); llvm::Value *getStringPtr(const QString &s); + llvm::Value *getIdentifier(const QString &s); void genUnop(llvm::Value *result, IR::Unop *e); void genBinop(llvm::Value *result, IR::Binop *e); llvm::AllocaInst *newLLVMTemp(llvm::Type *type, llvm::Value *size = 0);