summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Benkard <mulk@minimulk.mst-plus>2008-10-01 17:12:28 +0200
committerMatthias Benkard <mulk@minimulk.mst-plus>2008-10-01 17:12:28 +0200
commitae56a5092dd6a39042a0518c59736cd9dbbeb0ba (patch)
tree60e825da33bd8dd759c4c991cd40da22dc1d7526
parent8f594f969b0c495b098c833dba26d5cad93f7cd8 (diff)
LLVM compiler: Split function compilation from %LAMBDA form handling.
-rw-r--r--MLKForm.h2
-rw-r--r--MLKForm.m10
-rw-r--r--MLKLLVMCompiler.mm49
3 files changed, 47 insertions, 14 deletions
diff --git a/MLKForm.h b/MLKForm.h
index 24d4920..60b5428 100644
--- a/MLKForm.h
+++ b/MLKForm.h
@@ -99,6 +99,8 @@
-(void) splitDeclarationsAndBody:(id)object;
-(void) processBody:(id)object inContext:(MLKLexicalContext *)context;
-(void) processBody:(id)object;
+-(NSArray *) bodyForms;
+-(MLKLexicalContext *) bodyContext;
@end
diff --git a/MLKForm.m b/MLKForm.m
index c7ee3f5..30ae6ee 100644
--- a/MLKForm.m
+++ b/MLKForm.m
@@ -318,6 +318,16 @@
return _bodyForms;
}
+-(NSArray *) bodyForms
+{
+ return _bodyForms;
+}
+
+-(MLKLexicalContext *) bodyContext
+{
+ return _bodyContext;
+}
+
-(void) dealloc
{
LDESTROY (_body);
diff --git a/MLKLLVMCompiler.mm b/MLKLLVMCompiler.mm
index 64b2423..281c50b 100644
--- a/MLKLLVMCompiler.mm
+++ b/MLKLLVMCompiler.mm
@@ -594,15 +594,24 @@ static Constant
@end
-@implementation MLKSimpleLambdaForm (MLKLLVMCompilation)
--(Value *) reallyProcessForLLVM
+static void
+build_simple_function_definition (MLKBodyForm *processed_form,
+ id _lambdaListName,
+ Function*& function,
+ Value*& closure_data,
+ intptr_t& closure_data_size)
{
+ NSArray *_bodyForms = [processed_form bodyForms];
+ MLKLexicalContext *_bodyContext = [processed_form bodyContext];
+ MLKLexicalContext *_context = [processed_form context];
+ id _compiler = [MLKLLVMCompiler class];
+
vector <const Type *> argtypes (1, PointerPointerTy);
FunctionType *ftype = FunctionType::get (VoidPointerTy, argtypes, true);
- Function *function = Function::Create (ftype,
- Function::InternalLinkage,
- "a_lisp_closure_body",
- module);
+ function = Function::Create (ftype,
+ Function::InternalLinkage,
+ "a_lisp_closure_body",
+ module);
Function::arg_iterator args = function->arg_begin();
Value *closure_data_arg = args++;
@@ -619,12 +628,12 @@ static Constant
// ***** HANDLE CLOSURE VARIABLES *****
builder.SetInsertPoint (outerBlock);
- NSArray *freeVariables = [[self freeVariables] allObjects];
- Value *closure_data = builder.CreateAlloca (VoidPointerTy,
- ConstantInt::get(Type::Int32Ty,
- (uint32_t)[freeVariables count],
- false));
- int closure_data_size = 0;
+ NSArray *freeVariables = [[processed_form freeVariables] allObjects];
+ closure_data = builder.CreateAlloca (VoidPointerTy,
+ ConstantInt::get(Type::Int32Ty,
+ (uint32_t)[freeVariables count],
+ false));
+ closure_data_size = 0;
unsigned int i;
for (i = 0; i < [freeVariables count]; i++)
{
@@ -774,9 +783,21 @@ static Constant
//NSLog (@"Function built.");
builder.SetInsertPoint (outerBlock);
+}
+
+
+@implementation MLKSimpleLambdaForm (MLKLLVMCompilation)
+-(Value *) reallyProcessForLLVM
+{
+ intptr_t closure_data_size;
+ Function *function;
+ Value *closure_data;
+
+ build_simple_function_definition (self, _lambdaListName, function, closure_data, closure_data_size);
- argv[0] = function;
- argv[1] = builder.CreateBitCast (closure_data, VoidPointerTy);
+ vector<Value *> argv;
+ argv.push_back (function);
+ argv.push_back (builder.CreateBitCast (closure_data, VoidPointerTy));
argv.push_back (builder.CreateIntToPtr (ConstantInt::get(Type::Int32Ty,
closure_data_size,
false),