From ae56a5092dd6a39042a0518c59736cd9dbbeb0ba Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Wed, 1 Oct 2008 17:12:28 +0200 Subject: LLVM compiler: Split function compilation from %LAMBDA form handling. --- MLKLLVMCompiler.mm | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) (limited to 'MLKLLVMCompiler.mm') 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 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 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), -- cgit v1.2.3