@@ -49,19 +49,47 @@ namespace jit {
49
49
50
50
info_.set_state (state);
51
51
info_.set_args (args);
52
- // TODO: CallFrame
53
- // info_.set_previous(prev);
54
52
info_.set_entry (block);
55
53
56
54
alloc_frame (" block_body" );
57
55
58
- check_arity ();
56
+ // Push the new CallFrame
57
+ Signature sig (ctx_, ctx_->VoidTy );
58
+ sig << " State"
59
+ << " CallFrame"
60
+ << " StackVariables"
61
+ << " BlockEnvironment"
62
+ << " Arguments"
63
+ << " BlockInvocation" ;
59
64
60
- initialize_frame (machine_code_->stack_size );
65
+ Value* call_args[] = {
66
+ state,
67
+ call_frame,
68
+ info_.variables (),
69
+ block_env,
70
+ args,
71
+ block_inv
72
+ };
61
73
62
- nil_stack (machine_code_-> stack_size , constant (cNil, obj_type ));
74
+ sig. call ( " rbx_block_frame_initialize " , call_args, 6 , " " , b ( ));
63
75
64
- setup_block_scope ();
76
+ // TODO: de-dup
77
+ {
78
+ b ().SetInsertPoint (info_.return_pad ());
79
+
80
+ Signature sig (ctx_, ctx_->VoidTy );
81
+ sig << " State" ;
82
+
83
+ Value* call_args[] = {
84
+ state
85
+ };
86
+
87
+ sig.call (" rbx_pop_call_frame" , call_args, 1 , " " , b ());
88
+
89
+ b ().SetInsertPoint (block);
90
+ }
91
+
92
+ check_arity ();
65
93
66
94
import_args ();
67
95
@@ -100,111 +128,6 @@ namespace jit {
100
128
b ().SetInsertPoint (body_);
101
129
}
102
130
103
- void BlockBuilder::setup_block_scope () {
104
- b ().CreateStore (ConstantExpr::getNullValue (llvm::PointerType::getUnqual (vars_type)),
105
- get_field (vars, offset::StackVariables::on_heap));
106
- Value* self = b ().CreateLoad (
107
- get_field (block_inv, offset::BlockInvocation::self),
108
- " invocation.self" );
109
-
110
- b ().CreateStore (self, get_field (vars, offset::StackVariables::self));
111
-
112
- Value* inv_mod = b ().CreateLoad (
113
- get_field (block_inv, offset::BlockInvocation::module),
114
- " invocation.module" );
115
-
116
- Value* creation_mod = b ().CreateLoad (
117
- get_field (block_env, offset::BlockEnvironment::module),
118
- " env.module" );
119
-
120
- Value* mod = b ().CreateSelect (
121
- b ().CreateICmpNE (inv_mod, ConstantExpr::getNullValue (inv_mod->getType ())),
122
- inv_mod,
123
- creation_mod);
124
-
125
- module_ = mod;
126
-
127
- b ().CreateStore (mod, get_field (vars, offset::StackVariables::module));
128
-
129
- Value* blk = b ().CreateLoad (get_field (top_scope, offset::VariableScope::block),
130
- " args.block" );
131
- b ().CreateStore (blk, get_field (vars, offset::StackVariables::block));
132
-
133
-
134
- // We don't use top_scope here because of nested blocks. Parent MUST be
135
- // the scope the block was created in, not the top scope for depth
136
- // variables to work.
137
- Value* be_scope = b ().CreateLoad (
138
- get_field (block_env, offset::BlockEnvironment::scope),
139
- " env.scope" );
140
-
141
- b ().CreateStore (be_scope, get_field (vars, offset::StackVariables::parent));
142
- b ().CreateStore (constant (cNil, obj_type), get_field (vars, offset::StackVariables::last_match));
143
-
144
- nil_locals ();
145
- }
146
-
147
- void BlockBuilder::initialize_frame (int stack_size) {
148
- Value* code_gep = get_field (call_frame, offset::CallFrame::compiled_code);
149
-
150
- method = b ().CreateLoad (get_field (block_env, offset::BlockEnvironment::code),
151
- " env.code" );
152
-
153
- // previous
154
- b ().CreateStore (info_.previous (), get_field (call_frame, offset::CallFrame::previous));
155
-
156
- // constant_scope
157
- Value* cs = b ().CreateLoad (get_field (block_inv, offset::BlockInvocation::constant_scope),
158
- " invocation.constant_scope" );
159
-
160
- b ().CreateStore (cs, get_field (call_frame, offset::CallFrame::constant_scope));
161
-
162
- // arguments
163
- b ().CreateStore (info_.args (), get_field (call_frame, offset::CallFrame::arguments));
164
-
165
- // msg
166
- b ().CreateStore (Constant::getNullValue (ctx_->Int8PtrTy ),
167
- get_field (call_frame, offset::CallFrame::dispatch_data));
168
-
169
- // compiled_code
170
- b ().CreateStore (method, code_gep);
171
-
172
- // flags
173
- inv_flags_ = b ().CreateLoad (get_field (block_inv, offset::BlockInvocation::flags),
174
- " invocation.flags" );
175
-
176
- int block_flags = CallFrame::cMultipleScopes |
177
- CallFrame::cBlock |
178
- CallFrame::cJITed;
179
-
180
- if (!use_full_scope_) block_flags |= CallFrame::cClosedScope;
181
-
182
- Value* flags = b ().CreateOr (inv_flags_,
183
- cint (block_flags), " flags" );
184
-
185
- b ().CreateStore (flags, get_field (call_frame, offset::CallFrame::flags));
186
-
187
- // ip
188
- b ().CreateStore (cint (0 ),
189
- get_field (call_frame, offset::CallFrame::ip));
190
-
191
- // scope
192
- b ().CreateStore (vars, get_field (call_frame, offset::CallFrame::scope));
193
-
194
- // top_scope
195
- top_scope = b ().CreateLoad (
196
- get_field (block_env, offset::BlockEnvironment::top_scope),
197
- " env.top_scope" );
198
-
199
- b ().CreateStore (top_scope, get_field (call_frame, offset::CallFrame::top_scope));
200
-
201
- // jit_data
202
- b ().CreateStore (
203
- constant (ctx_->runtime_data_holder (), ctx_->Int8PtrTy ),
204
- get_field (call_frame, offset::CallFrame::jit_data));
205
-
206
- }
207
-
208
131
void BlockBuilder::check_arity () {
209
132
BasicBlock* destruct_check = info_.new_block (" destruct_check" );
210
133
BasicBlock* arg_error = info_.new_block (" arg_error" );
0 commit comments