summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-08-17 13:09:08 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-08-17 15:20:18 +0200
commitda47da35f268416e1131fa4e107e32fa6a667ae4 (patch)
tree3a0b1919563eb470e327461610fb658fa7126a47
parent99519955fca324cf190116f7fbae5eecbf493077 (diff)
LLVM compiler: Implement IF and support self-evaluating forms.
-rw-r--r--MLKLLVMCompiler.mm53
1 files changed, 53 insertions, 0 deletions
diff --git a/MLKLLVMCompiler.mm b/MLKLLVMCompiler.mm
index 7767d48..81aa764 100644
--- a/MLKLLVMCompiler.mm
+++ b/MLKLLVMCompiler.mm
@@ -18,6 +18,7 @@
#import "MLKLLVMCompiler.h"
#import "globals.h"
+#import "util.h"
#import <Foundation/NSArray.h>
#import <Foundation/NSEnumerator.h>
@@ -606,9 +607,61 @@ static Constant
@implementation MLKQuoteForm (MLKLLVMCompilation)
-(Value *) processForLLVM
{
+ // FIXME: When to release _quotedData? At the same time the code is
+ // released, probably...
+ LRETAIN (_quotedData);
return builder.CreateIntToPtr (ConstantInt::get(Type::Int64Ty,
(uint64_t)_quotedData,
false),
PointerTy);
}
@end
+
+
+@implementation MLKSelfEvaluatingForm (MLKLLVMCompilation)
+-(Value *) processForLLVM
+{
+ // FIXME: When to release _form? At the same time the code is
+ // released, probably...
+ LRETAIN (_form);
+ return builder.CreateIntToPtr (ConstantInt::get(Type::Int64Ty,
+ (uint64_t)_form,
+ false),
+ PointerTy);
+}
+@end
+
+
+@implementation MLKIfForm (MLKLLVMCompilation)
+-(Value *) processForLLVM
+{
+ Function *function = builder.GetInsertBlock()->getParent();
+ BasicBlock *thenBlock = BasicBlock::Create ("if_then", function);
+ BasicBlock *elseBlock = BasicBlock::Create ("if_else");
+ BasicBlock *joinBlock = BasicBlock::Create ("if_join");
+
+ Value *thenValue, *elseValue;
+
+ Value *test = builder.CreateICmpNE ([_conditionForm processForLLVM],
+ ConstantPointerNull::get (PointerTy));
+ builder.CreateCondBr (test, thenBlock, elseBlock);
+
+ builder.SetInsertPoint (thenBlock);
+ thenValue = [_consequentForm processForLLVM];
+ builder.CreateBr (joinBlock);
+
+ builder.SetInsertPoint (elseBlock);
+ function->getBasicBlockList().push_back (elseBlock);
+ elseValue = [_alternativeForm processForLLVM];
+ builder.CreateBr (joinBlock);
+
+ builder.SetInsertPoint (joinBlock);
+ function->getBasicBlockList().push_back (joinBlock);
+
+ PHINode *value = builder.CreatePHI (PointerTy, "if_result");
+ value->addIncoming (thenValue, thenBlock);
+ value->addIncoming (elseValue, elseBlock);
+
+ return value;
+}
+@end