summaryrefslogtreecommitdiff
path: root/MLKLLVMCompiler.mm
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-09-29 01:06:05 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-09-29 01:06:05 +0200
commitfd7702e9b009d2984328b2519db946f82ad834e9 (patch)
treef910466e18eddd34e157c98e01dc5414e3154451 /MLKLLVMCompiler.mm
parentace29d495df89afd2e3251064de91b00da2612da (diff)
parent45e00ec3f4dd6289cd14021ef1ee35568b4928c6 (diff)
Merge /home/mulk/Dropbox/Projekte/Toilet Lisp
Diffstat (limited to 'MLKLLVMCompiler.mm')
-rw-r--r--MLKLLVMCompiler.mm39
1 files changed, 33 insertions, 6 deletions
diff --git a/MLKLLVMCompiler.mm b/MLKLLVMCompiler.mm
index 443bde9..cdb6360 100644
--- a/MLKLLVMCompiler.mm
+++ b/MLKLLVMCompiler.mm
@@ -27,6 +27,11 @@
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSString.h>
+#ifdef __OBJC_GC__
+#import <Foundation/NSGarbageCollector.h>
+#endif
+
+
#include <llvm/Analysis/Verifier.h>
#include <llvm/BasicBlock.h>
#include <llvm/CallingConv.h>
@@ -164,7 +169,7 @@ static Constant
//module->dump();
//NSLog (@"%p", fn);
- [pool release];
+ LRELEASE (pool);
//NSLog (@"Code compiled.");
#if 1
@@ -537,6 +542,9 @@ static Constant
closureDataCell = builder.Insert ([_context closureDataPointerValueForSymbol:_head]);
closureDataPtr = builder.CreateLoad (closureDataCell);
+ //[_compiler insertTrace:[NSString stringWithFormat:@"Call: %@", MLKPrintToString(_head)]];
+ //[_compiler insertPointerTrace:functionPtr];
+
args.push_back (closureDataPtr);
NSEnumerator *e = [_argumentForms objectEnumerator];
@@ -556,7 +564,11 @@ static Constant
PointerTy);
args.push_back (endmarker);
- //[_compiler insertTrace:[NSString stringWithFormat:@"Function call: %@.", MLKPrintToString(_head)]];
+ // If the pointer output here is different from the one above,
+ // there's some stack smashing going on.
+ //[_compiler insertTrace:[NSString stringWithFormat:@"Now calling: %@.", MLKPrintToString(_head)]];
+ //[_compiler insertPointerTrace:functionPtr];
+
CallInst *call = builder.CreateCall (functionPtr,
args.begin(),
args.end(),
@@ -603,7 +615,7 @@ static Constant
builder.SetInsertPoint (outerBlock);
NSArray *freeVariables = [[self freeVariables] allObjects];
- Value *closure_data = builder.CreateMalloc (PointerTy,
+ Value *closure_data = builder.CreateAlloca (PointerTy,
ConstantInt::get(Type::Int32Ty,
(uint32_t)[freeVariables count],
false));
@@ -644,13 +656,14 @@ static Constant
false),
PointerType::get(Type::Int8Ty, 0));
- Value *ap = builder.CreateAlloca (Type::Int8Ty, NULL, "ap");
+ Value *ap = builder.CreateAlloca (PointerTy, NULL, "ap");
+ Value *ap2 = builder.CreateBitCast (ap, PointerTy);
builder.CreateCall (module->getOrInsertFunction ("llvm.va_start",
Type::VoidTy,
PointerTy,
NULL),
- ap);
+ ap2);
Value *mlkcons = [_compiler insertClassLookup:@"MLKCons"];
@@ -707,7 +720,7 @@ static Constant
Type::VoidTy,
PointerTy,
NULL),
- ap);
+ ap2);
if ([_bodyContext variableHeapAllocationForSymbol:_lambdaListName])
{
@@ -826,7 +839,14 @@ static Constant
{
// FIXME: When to release _quotedData? At the same time the code is
// released, probably...
+ // FIXME: In garbage-collected code, _quotedData will be deleted even
+ // though it is referenced by compiled code!
LRETAIN (_quotedData);
+#ifdef __OBJC_GC__
+ if (_quotedData && MLKInstanceP (_quotedData))
+ [[NSGarbageCollector defaultCollector] disableCollectorForPointer:_quotedData];
+#endif
+
return builder.CreateIntToPtr (ConstantInt::get(Type::Int64Ty,
(uint64_t)_quotedData,
false),
@@ -840,7 +860,14 @@ static Constant
{
// FIXME: When to release _form? At the same time the code is
// released, probably...
+ // FIXME: In garbage-collected code, _form will be deleted even
+ // though it is referenced by compiled code!
LRETAIN (_form);
+#ifdef __OBJC_GC__
+ if (_form && MLKInstanceP (_form))
+ [[NSGarbageCollector defaultCollector] disableCollectorForPointer:_form];
+#endif
+
return builder.CreateIntToPtr (ConstantInt::get(Type::Int64Ty,
(uint64_t)_form,
false),