summaryrefslogtreecommitdiff
path: root/MLKLLVMCompiler.mm
diff options
context:
space:
mode:
authorMatthias Benkard <mulk@minimulk.mst-plus>2008-10-01 10:32:17 +0200
committerMatthias Benkard <mulk@minimulk.mst-plus>2008-10-01 10:32:17 +0200
commit8c28cc5aaeeb3546e4c113734e18285699bf779e (patch)
tree61a9c97aa9e4c70314daed2f8d17b4f2bd36b39f /MLKLLVMCompiler.mm
parentf3cc34c256ed93e09541d1019e00e45012075920 (diff)
LLVM compiler: Support FUNCTION.
Diffstat (limited to 'MLKLLVMCompiler.mm')
-rw-r--r--MLKLLVMCompiler.mm68
1 files changed, 68 insertions, 0 deletions
diff --git a/MLKLLVMCompiler.mm b/MLKLLVMCompiler.mm
index 137598e..64b2423 100644
--- a/MLKLLVMCompiler.mm
+++ b/MLKLLVMCompiler.mm
@@ -1026,3 +1026,71 @@ static Constant
VoidPointerTy);
}
@end
+
+
+@implementation MLKSimpleFunctionForm (MLKLLVMCompilation)
+-(Value *) reallyProcessForLLVM
+{
+ // For global functions, this is easy. For local functions, we need to create
+ // a new MLKCompiledClosure object.
+ if ([_context functionIsGlobal:_functionName])
+ {
+ Value *mlklexicalenvironment = [_compiler insertClassLookup:@"MLKLexicalEnvironment"];
+ Value *env = [_compiler insertMethodCall:@"globalEnvironment"
+ onObject:mlklexicalenvironment];
+
+ LRETAIN (_functionName); // FIXME: release
+#ifdef __OBJC_GC__
+ // FIXME: proper memory management
+ if (_functionName && MLKInstanceP (_functionName))
+ [[NSGarbageCollector defaultCollector] disableCollectorForPointer:_functionName];
+#endif
+
+ Value *symbolV = builder.CreateIntToPtr (ConstantInt::get(Type::Int64Ty,
+ (uint64_t)_functionName,
+ false),
+ VoidPointerTy);
+
+ vector<Value *> args;
+ args.push_back (symbolV);
+ Value *fun = [_compiler insertMethodCall:@"functionForSymbol:"
+ onObject:env
+ withArgumentVector:&args];
+ return fun;
+ }
+ else
+ {
+ Value *functionCell, *functionPtr;
+ Value *closureDataCell, *closureDataPtr;
+ Value *closureDataLengthCell, *closureDataLength;
+
+ functionCell = builder.Insert ([_context functionCellValueForSymbol:_head]);
+ functionPtr = builder.CreateLoad (functionCell);
+ closureDataCell = builder.Insert ([_context closureDataPointerValueForSymbol:_head]);
+ closureDataPtr = builder.CreateLoad (closureDataCell);
+ closureDataLengthCell = builder.Insert ([_context closureDataLengthValueForSymbol:_head]);
+ closureDataLength = builder.CreateLoad (closureDataLengthCell);
+
+ vector<Value *> argv;
+ argv.push_back (builder.CreateBitCast (functionPtr, VoidPointerTy));
+ argv.push_back (builder.CreateBitCast (closureDataPtr, VoidPointerTy));
+ argv.push_back (builder.CreateBitCast (closureDataLength, VoidPointerTy));
+ Value *mlkcompiledclosure = [_compiler
+ insertClassLookup:@"MLKCompiledClosure"];
+ Value *closure =
+ [_compiler insertMethodCall:@"closureWithCode:data:length:"
+ onObject:mlkcompiledclosure
+ withArgumentVector:&argv];
+
+ return closure;
+ }
+}
+@end
+
+
+@implementation MLKLambdaFunctionForm (MLKLLVMCompilation)
+-(Value *) reallyProcessForLLVM
+{
+ return [_lambdaForm processForLLVM];
+}
+@end