summaryrefslogtreecommitdiff
path: root/MLKLLVMCompiler.mm
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-09-02 10:22:24 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-09-02 10:22:24 +0200
commit1e1bbbf51144d68dcef7d1abf8dab0f3ade3fb1a (patch)
tree36601b862fa547ac51e253cf0456c8e0f0e021f3 /MLKLLVMCompiler.mm
parent1dc0cdf8416eb0e98017d1f833ac1e9e6077fda5 (diff)
LLVM compiler: Access closure variables through the closure data pointer.
Diffstat (limited to 'MLKLLVMCompiler.mm')
-rw-r--r--MLKLLVMCompiler.mm63
1 files changed, 39 insertions, 24 deletions
diff --git a/MLKLLVMCompiler.mm b/MLKLLVMCompiler.mm
index 17186e7..83246c1 100644
--- a/MLKLLVMCompiler.mm
+++ b/MLKLLVMCompiler.mm
@@ -589,8 +589,46 @@ static Constant
BasicBlock *lambdaListNewBlock = BasicBlock::Create ("lambda_list_new");
BasicBlock *lambdaListUpdateBlock = BasicBlock::Create ("lambda_list_update");
- builder.SetInsertPoint (initBlock);
+ // ***** HANDLE CLOSURE VARIABLES *****
+ builder.SetInsertPoint (outerBlock);
+ NSArray *freeVariables = [[self freeVariables] allObjects];
+ Value *closure_data = builder.CreateMalloc (PointerTy,
+ ConstantInt::get(Type::Int32Ty,
+ (uint32_t)[freeVariables count],
+ false));
+ int closure_data_size = 0;
+ unsigned int i;
+ for (i = 0; i < [freeVariables count]; i++)
+ {
+ // FIXME: We assume heap allocation for all closure variables.
+ MLKSymbol *symbol = [freeVariables objectAtIndex:i];
+ if (![_context variableIsGlobal:symbol])
+ {
+ Constant *position = ConstantInt::get(Type::Int32Ty, closure_data_size, false);
+
+ // Fill in the closure data array.
+ builder.SetInsertPoint (outerBlock);
+ Value *binding = [_context bindingValueForSymbol:symbol];
+ Value *closure_value_ptr = builder.CreateGEP (closure_data, position);
+ builder.CreateStore (binding, closure_value_ptr);
+
+ // Access the closure data array from within the closure.
+ builder.SetInsertPoint (initBlock);
+ Value *local_closure_var = builder.CreateAlloca (PointerTy, NULL, "closure_variable");
+ Value *local_closure_value_ptr = builder.CreateGEP (closure_data_arg,
+ position);
+ builder.CreateStore (local_closure_value_ptr, local_closure_var);
+ [_bodyContext locallySetBindingValue:local_closure_var
+ forSymbol:symbol];
+
+ closure_data_size++;
+ }
+ }
+
+
+ // ***** HANDLE ARGUMENTS *****
+ builder.SetInsertPoint (initBlock);
Value *endmarker = builder.CreateIntToPtr (ConstantInt::get(Type::Int64Ty,
(uint64_t)MLKEndOfArgumentsMarker,
false),
@@ -696,29 +734,6 @@ static Constant
builder.SetInsertPoint (outerBlock);
- NSArray *freeVariables = [[self freeVariables] allObjects];
- Value *closure_data = builder.CreateMalloc (PointerTy,
- ConstantInt::get(Type::Int32Ty,
- (uint32_t)[freeVariables count],
- false));
- int closure_data_size = 0;
- unsigned int i;
- for (i = 0; i < [freeVariables count]; i++)
- {
- // FIXME: We assume heap allocation for all closure variables.
- MLKSymbol *symbol = [freeVariables objectAtIndex:i];
- if (![_context variableIsGlobal:symbol])
- {
- Value *binding = [_context bindingValueForSymbol:symbol];
- Value *closure_value_ptr = builder.CreateGEP (closure_data,
- ConstantInt::get(Type::Int32Ty,
- closure_data_size,
- false));
- builder.CreateStore (binding, closure_value_ptr);
- closure_data_size++;
- }
- }
-
argv[0] = function;
argv[1] = closure_data;
argv.push_back (builder.CreateIntToPtr (ConstantInt::get(Type::Int32Ty,