Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: src/codegen-arm.h

Issue 9328: Initial (stub) port of jump targets to the ARM platform.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/toiger/
Patch Set: '' Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/ast.h ('k') | src/codegen-arm.cc » ('j') | src/jump-target.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 25 matching lines...) Expand all
36 class DeferredCode; 36 class DeferredCode;
37 37
38 // Mode to overwrite BinaryExpression values. 38 // Mode to overwrite BinaryExpression values.
39 enum OverwriteMode { NO_OVERWRITE, OVERWRITE_LEFT, OVERWRITE_RIGHT }; 39 enum OverwriteMode { NO_OVERWRITE, OVERWRITE_LEFT, OVERWRITE_RIGHT };
40 40
41 enum InitState { CONST_INIT, NOT_CONST_INIT }; 41 enum InitState { CONST_INIT, NOT_CONST_INIT };
42 enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF }; 42 enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF };
43 43
44 44
45 // ------------------------------------------------------------------------- 45 // -------------------------------------------------------------------------
46 // Virtual frame
47
48 class VirtualFrame BASE_EMBEDDED {
49 public:
50 explicit VirtualFrame(CodeGenerator* cgen);
51
52 MemOperand Top() const { return MemOperand(sp, 0); }
53
54 MemOperand Element(int index) const {
55 return MemOperand(sp, index * kPointerSize);
56 }
57
58 MemOperand Local(int index) const {
59 ASSERT(0 <= index && index < frame_local_count_);
60 return MemOperand(fp, kLocal0Offset - index * kPointerSize);
61 }
62
63 MemOperand Function() const { return MemOperand(fp, kFunctionOffset); }
64
65 MemOperand Context() const { return MemOperand(fp, kContextOffset); }
66
67 MemOperand Parameter(int index) const {
68 // Index -1 corresponds to the receiver.
69 ASSERT(-1 <= index && index <= parameter_count_);
70 return MemOperand(fp, (1 + parameter_count_ - index) * kPointerSize);
71 }
72
73 private:
74 static const int kLocal0Offset = JavaScriptFrameConstants::kLocal0Offset;
75 static const int kFunctionOffset = JavaScriptFrameConstants::kFunctionOffset;
76 static const int kContextOffset = StandardFrameConstants::kContextOffset;
77
78 MacroAssembler* masm_;
79 int frame_local_count_;
80 int parameter_count_;
81 };
82
83
84 // -------------------------------------------------------------------------
85 // Reference support 46 // Reference support
86 47
87 // A reference is a C++ stack-allocated object that keeps an ECMA 48 // A reference is a C++ stack-allocated object that keeps an ECMA
88 // reference on the execution stack while in scope. For variables 49 // reference on the execution stack while in scope. For variables
89 // the reference is empty, indicating that it isn't necessary to 50 // the reference is empty, indicating that it isn't necessary to
90 // store state on the stack for keeping track of references to those. 51 // store state on the stack for keeping track of references to those.
91 // For properties, we keep either one (named) or two (indexed) values 52 // For properties, we keep either one (named) or two (indexed) values
92 // on the execution stack to represent the reference. 53 // on the execution stack to represent the reference.
93 54
94 class Reference BASE_EMBEDDED { 55 class Reference BASE_EMBEDDED {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 public: 106 public:
146 // Create an initial code generator state. Destroying the initial state 107 // Create an initial code generator state. Destroying the initial state
147 // leaves the code generator with a NULL state. 108 // leaves the code generator with a NULL state.
148 explicit CodeGenState(CodeGenerator* owner); 109 explicit CodeGenState(CodeGenerator* owner);
149 110
150 // Create a code generator state based on a code generator's current 111 // Create a code generator state based on a code generator's current
151 // state. The new state has its own typeof state and pair of branch 112 // state. The new state has its own typeof state and pair of branch
152 // labels. 113 // labels.
153 CodeGenState(CodeGenerator* owner, 114 CodeGenState(CodeGenerator* owner,
154 TypeofState typeof_state, 115 TypeofState typeof_state,
155 Label* true_target, 116 JumpTarget* true_target,
156 Label* false_target); 117 JumpTarget* false_target);
157 118
158 // Destroy a code generator state and restore the owning code generator's 119 // Destroy a code generator state and restore the owning code generator's
159 // previous state. 120 // previous state.
160 ~CodeGenState(); 121 ~CodeGenState();
161 122
162 TypeofState typeof_state() const { return typeof_state_; } 123 TypeofState typeof_state() const { return typeof_state_; }
163 Label* true_target() const { return true_target_; } 124 JumpTarget* true_target() const { return true_target_; }
164 Label* false_target() const { return false_target_; } 125 JumpTarget* false_target() const { return false_target_; }
165 126
166 private: 127 private:
167 CodeGenerator* owner_; 128 CodeGenerator* owner_;
168 TypeofState typeof_state_; 129 TypeofState typeof_state_;
169 Label* true_target_; 130 JumpTarget* true_target_;
170 Label* false_target_; 131 JumpTarget* false_target_;
171 CodeGenState* previous_; 132 CodeGenState* previous_;
172 }; 133 };
173 134
174 135
175 // ------------------------------------------------------------------------- 136 // -------------------------------------------------------------------------
176 // CodeGenerator 137 // CodeGenerator
177 138
178 class CodeGenerator: public Visitor { 139 class CodeGenerator: public Visitor {
179 public: 140 public:
180 // Takes a function literal, generates code for it. This function should only 141 // Takes a function literal, generates code for it. This function should only
(...skipping 27 matching lines...) Expand all
208 // Accessors 169 // Accessors
209 Scope* scope() const { return scope_; } 170 Scope* scope() const { return scope_; }
210 171
211 void ProcessDeferred(); 172 void ProcessDeferred();
212 173
213 bool is_eval() { return is_eval_; } 174 bool is_eval() { return is_eval_; }
214 175
215 // State 176 // State
216 bool has_cc() const { return cc_reg_ != al; } 177 bool has_cc() const { return cc_reg_ != al; }
217 TypeofState typeof_state() const { return state_->typeof_state(); } 178 TypeofState typeof_state() const { return state_->typeof_state(); }
218 Label* true_target() const { return state_->true_target(); } 179 JumpTarget* true_target() const { return state_->true_target(); }
219 Label* false_target() const { return state_->false_target(); } 180 JumpTarget* false_target() const { return state_->false_target(); }
220 181
221 182
222 // Node visitors. 183 // Node visitors.
223 #define DEF_VISIT(type) \ 184 #define DEF_VISIT(type) \
224 void Visit##type(type* node); 185 void Visit##type(type* node);
225 NODE_LIST(DEF_VISIT) 186 NODE_LIST(DEF_VISIT)
226 #undef DEF_VISIT 187 #undef DEF_VISIT
227 188
228 // Main code generation function 189 // Main code generation function
229 void GenCode(FunctionLiteral* fun); 190 void GenCode(FunctionLiteral* fun);
230 191
231 // The following are used by class Reference. 192 // The following are used by class Reference.
232 void LoadReference(Reference* ref); 193 void LoadReference(Reference* ref);
233 void UnloadReference(Reference* ref); 194 void UnloadReference(Reference* ref);
234 195
235 MemOperand ContextOperand(Register context, int index) const { 196 MemOperand ContextOperand(Register context, int index) const {
236 return MemOperand(context, Context::SlotOffset(index)); 197 return MemOperand(context, Context::SlotOffset(index));
237 } 198 }
238 199
239 MemOperand SlotOperand(Slot* slot, Register tmp); 200 MemOperand SlotOperand(Slot* slot, Register tmp);
240 201
241 // Expressions 202 // Expressions
242 MemOperand GlobalObject() const { 203 MemOperand GlobalObject() const {
243 return ContextOperand(cp, Context::GLOBAL_INDEX); 204 return ContextOperand(cp, Context::GLOBAL_INDEX);
244 } 205 }
245 206
246 void LoadCondition(Expression* x, 207 void LoadCondition(Expression* x,
247 TypeofState typeof_state, 208 TypeofState typeof_state,
248 Label* true_target, 209 JumpTarget* true_target,
249 Label* false_target, 210 JumpTarget* false_target,
250 bool force_cc); 211 bool force_cc);
251 void Load(Expression* x, TypeofState typeof_state = NOT_INSIDE_TYPEOF); 212 void Load(Expression* x, TypeofState typeof_state = NOT_INSIDE_TYPEOF);
252 void LoadGlobal(); 213 void LoadGlobal();
253 void LoadGlobalReceiver(Register scratch); 214 void LoadGlobalReceiver(Register scratch);
254 215
255 // Read a value from a slot and leave it on top of the expression stack. 216 // Read a value from a slot and leave it on top of the expression stack.
256 void LoadFromSlot(Slot* slot, TypeofState typeof_state); 217 void LoadFromSlot(Slot* slot, TypeofState typeof_state);
257 218
258 // Special code for typeof expressions: Unfortunately, we must 219 // Special code for typeof expressions: Unfortunately, we must
259 // be careful when loading the expression in 'typeof' 220 // be careful when loading the expression in 'typeof'
260 // expressions. We are not allowed to throw reference errors for 221 // expressions. We are not allowed to throw reference errors for
261 // non-existing properties of the global object, so we must make it 222 // non-existing properties of the global object, so we must make it
262 // look like an explicit property access, instead of an access 223 // look like an explicit property access, instead of an access
263 // through the context chain. 224 // through the context chain.
264 void LoadTypeofExpression(Expression* x); 225 void LoadTypeofExpression(Expression* x);
265 226
266 void ToBoolean(Label* true_target, Label* false_target); 227 void ToBoolean(JumpTarget* true_target, JumpTarget* false_target);
267 228
268 void GenericBinaryOperation(Token::Value op); 229 void GenericBinaryOperation(Token::Value op);
269 void Comparison(Condition cc, bool strict = false); 230 void Comparison(Condition cc, bool strict = false);
270 231
271 void SmiOperation(Token::Value op, Handle<Object> value, bool reversed); 232 void SmiOperation(Token::Value op, Handle<Object> value, bool reversed);
272 233
273 void CallWithArguments(ZoneList<Expression*>* arguments, int position); 234 void CallWithArguments(ZoneList<Expression*>* arguments, int position);
274 235
275 // Control flow 236 // Control flow
276 void Branch(bool if_true, Label* L); 237 void Branch(bool if_true, JumpTarget* target);
277 void CheckStack(); 238 void CheckStack();
278 void CleanStack(int num_bytes); 239 void CleanStack(int num_bytes);
279 240
280 bool CheckForInlineRuntimeCall(CallRuntime* node); 241 bool CheckForInlineRuntimeCall(CallRuntime* node);
281 Handle<JSFunction> BuildBoilerplate(FunctionLiteral* node); 242 Handle<JSFunction> BuildBoilerplate(FunctionLiteral* node);
282 void ProcessDeclarations(ZoneList<Declaration*>* declarations); 243 void ProcessDeclarations(ZoneList<Declaration*>* declarations);
283 244
284 Handle<Code> ComputeCallInitialize(int argc); 245 Handle<Code> ComputeCallInitialize(int argc);
285 246
286 // Declare global variables and functions in the given array of 247 // Declare global variables and functions in the given array of
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // is optimal compared to the default code generated for a switch statement 294 // is optimal compared to the default code generated for a switch statement
334 // on that platform. 295 // on that platform.
335 int FastCaseSwitchMinCaseCount(); 296 int FastCaseSwitchMinCaseCount();
336 297
337 // Allocate a jump table and create code to jump through it. 298 // Allocate a jump table and create code to jump through it.
338 // Should call GenerateFastCaseSwitchCases to generate the code for 299 // Should call GenerateFastCaseSwitchCases to generate the code for
339 // all the cases at the appropriate point. 300 // all the cases at the appropriate point.
340 void GenerateFastCaseSwitchJumpTable(SwitchStatement* node, 301 void GenerateFastCaseSwitchJumpTable(SwitchStatement* node,
341 int min_index, 302 int min_index,
342 int range, 303 int range,
343 Label* fail_label, 304 JumpTarget* fail_label,
344 Vector<Label*> case_targets, 305 Vector<JumpTarget*> case_targets,
345 Vector<Label> case_labels); 306 Vector<JumpTarget> case_labels);
346 307
347 // Generate the code for cases for the fast case switch. 308 // Generate the code for cases for the fast case switch.
348 // Called by GenerateFastCaseSwitchJumpTable. 309 // Called by GenerateFastCaseSwitchJumpTable.
349 void GenerateFastCaseSwitchCases(SwitchStatement* node, 310 void GenerateFastCaseSwitchCases(SwitchStatement* node,
350 Vector<Label> case_labels); 311 Vector<JumpTarget> case_labels,
312 JumpTarget* table_start);
351 313
352 // Fast support for constant-Smi switches. 314 // Fast support for constant-Smi switches.
353 void GenerateFastCaseSwitchStatement(SwitchStatement* node, 315 void GenerateFastCaseSwitchStatement(SwitchStatement* node,
354 int min_index, 316 int min_index,
355 int range, 317 int range,
356 int default_index); 318 int default_index);
357 319
358 // Fast support for constant-Smi switches. Tests whether switch statement 320 // Fast support for constant-Smi switches. Tests whether switch statement
359 // permits optimization and calls GenerateFastCaseSwitch if it does. 321 // permits optimization and calls GenerateFastCaseSwitch if it does.
360 // Returns true if the fast-case switch was generated, and false if not. 322 // Returns true if the fast-case switch was generated, and false if not.
(...skipping 18 matching lines...) Expand all
379 MacroAssembler* masm_; // to generate code 341 MacroAssembler* masm_; // to generate code
380 342
381 // Code generation state 343 // Code generation state
382 Scope* scope_; 344 Scope* scope_;
383 VirtualFrame* frame_; 345 VirtualFrame* frame_;
384 Condition cc_reg_; 346 Condition cc_reg_;
385 CodeGenState* state_; 347 CodeGenState* state_;
386 bool is_inside_try_; 348 bool is_inside_try_;
387 int break_stack_height_; 349 int break_stack_height_;
388 350
389 // Labels 351 // Jump targets
390 Label function_return_; 352 JumpTarget function_return_;
391 353
392 friend class VirtualFrame; 354 friend class VirtualFrame;
393 friend class Reference; 355 friend class Reference;
394 356
395 DISALLOW_COPY_AND_ASSIGN(CodeGenerator); 357 DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
396 }; 358 };
397 359
398 } } // namespace v8::internal 360 } } // namespace v8::internal
399 361
400 #endif // V8_CODEGEN_ARM_H_ 362 #endif // V8_CODEGEN_ARM_H_
OLDNEW
« no previous file with comments | « src/ast.h ('k') | src/codegen-arm.cc » ('j') | src/jump-target.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698