summaryrefslogtreecommitdiff
path: root/MLKLLVMCompiler.mm
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-08-17 12:00:52 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-08-17 12:02:25 +0200
commitf24c4a95ab655cf47bcea1a2f20b6a1f76329c68 (patch)
tree7fb3e930be08cbbcb6583ac616aa51cc7d710d99 /MLKLLVMCompiler.mm
parenta94e4b4aac13cae9dd71a5e7c09ae863b9a7219b (diff)
LLVM compiler: Implement LET.
Diffstat (limited to 'MLKLLVMCompiler.mm')
-rw-r--r--MLKLLVMCompiler.mm42
1 files changed, 37 insertions, 5 deletions
diff --git a/MLKLLVMCompiler.mm b/MLKLLVMCompiler.mm
index 4313ac9..3b011d5 100644
--- a/MLKLLVMCompiler.mm
+++ b/MLKLLVMCompiler.mm
@@ -126,7 +126,7 @@ static Constant
// JIT-compile.
fn = (id (*)()) execution_engine->getPointerToFunction (function);
- module->dump();
+ //module->dump();
NSLog (@"%p", fn);
// Execute.
@@ -314,10 +314,7 @@ static Constant
{
NSEnumerator *e = [_bodyForms objectEnumerator];
MLKForm *form;
- Value *value = NULL;
-
- if ([_bodyForms count] == 0)
- value = ConstantPointerNull::get (PointerTy);
+ Value *value = ConstantPointerNull::get (PointerTy);
while ((form = [e nextObject]))
{
@@ -405,6 +402,9 @@ static Constant
args.push_back ([form processForLLVM]);
}
+ //GlobalVariable *endmarker = module->getGlobalVariable ("MLKEndOfArgumentsMarker", false);
+ //endmarker->setConstant (true);
+ //GlobalVariable *endmarker = new GlobalVariable (PointerTy, true, GlobalValue::ExternalWeakLinkage);
Value *endmarker = builder.CreateIntToPtr (ConstantInt::get(Type::Int64Ty,
(uint64_t)MLKEndOfArgumentsMarker,
false),
@@ -569,3 +569,35 @@ static Constant
return closure;
}
@end
+
+
+@implementation MLKLetForm (MLKLLVMCompilation)
+-(Value *) processForLLVM
+{
+ NSEnumerator *e = [_variableBindingForms objectEnumerator];
+ Value *value = ConstantPointerNull::get (PointerTy);
+ MLKForm *form;
+ MLKVariableBindingForm *binding_form;
+
+ while ((binding_form = [e nextObject]))
+ {
+ // FIXME: Handle heap allocation.
+ Value *binding_value = [[binding_form valueForm] processForLLVM];
+ Value *binding_variable = builder.CreateAlloca (PointerTy,
+ NULL,
+ [(MLKPrintToString([binding_form name]))
+ UTF8String]);
+ builder.CreateStore (binding_value, binding_variable);
+ [_bodyContext setValueValue:binding_variable
+ forSymbol:[binding_form name]];
+ }
+
+ e = [_bodyForms objectEnumerator];
+ while ((form = [e nextObject]))
+ {
+ value = [form processForLLVM];
+ }
+
+ return value;
+}
+@end