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

Side by Side Diff: vm/intermediate_language.h

Issue 10537051: Add type testers to all IL Computation classes. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 6 months 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_ 5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_
6 #define VM_INTERMEDIATE_LANGUAGE_H_ 6 #define VM_INTERMEDIATE_LANGUAGE_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/ast.h" 9 #include "vm/ast.h"
10 #include "vm/growable_array.h" 10 #include "vm/growable_array.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 // Create a location summary for this computation. 132 // Create a location summary for this computation.
133 // TODO(fschneider): Temporarily returns NULL for instructions 133 // TODO(fschneider): Temporarily returns NULL for instructions
134 // that are not yet converted to the location based code generation. 134 // that are not yet converted to the location based code generation.
135 virtual LocationSummary* MakeLocationSummary() const = 0; 135 virtual LocationSummary* MakeLocationSummary() const = 0;
136 136
137 // TODO(fschneider): Make EmitNativeCode and locs const. 137 // TODO(fschneider): Make EmitNativeCode and locs const.
138 virtual void EmitNativeCode(FlowGraphCompiler* compiler) = 0; 138 virtual void EmitNativeCode(FlowGraphCompiler* compiler) = 0;
139 139
140 static LocationSummary* MakeCallSummary(); 140 static LocationSummary* MakeCallSummary();
141 141
142 // Declare an enum value used to define type-test predicates.
143 enum ComputationType {
144 #define DECLARE_COMPUTATION_TYPE(ShortName, ClassName) k##ShortName,
145
146 FOR_EACH_COMPUTATION(DECLARE_COMPUTATION_TYPE)
147
148 #undef DECLARE_COMPUTATION_TYPE
149 };
150
151 virtual ComputationType computation_type() const = 0;
152
153 // Declare predicate for each computation.
154 #define DECLARE_PREDICATE(ShortName, ClassName) \
155 bool Is##ShortName() const { return computation_type() == k##ShortName; } \
156 ClassName* As##ShortName() { \
157 if (!Is##ShortName()) return NULL; \
158 return reinterpret_cast<ClassName*>(this); \
Vyacheslav Egorov (Google) 2012/06/07 12:07:16 this should be static_cast.
Florian Schneider 2012/06/07 12:31:47 Done.
159 }
160
161 FOR_EACH_COMPUTATION(DECLARE_PREDICATE)
162
163 #undef DECLARE_PREDICATE
164
142 private: 165 private:
143 friend class Instruction; 166 friend class Instruction;
144 static intptr_t GetNextCid(Isolate* isolate) { 167 static intptr_t GetNextCid(Isolate* isolate) {
145 intptr_t tmp = isolate->computation_id(); 168 intptr_t tmp = isolate->computation_id();
146 isolate->set_computation_id(tmp + 1); 169 isolate->set_computation_id(tmp + 1);
147 return tmp; 170 return tmp;
148 } 171 }
149 static ICData* GetICDataForCid(intptr_t cid, Isolate* isolate) { 172 static ICData* GetICDataForCid(intptr_t cid, Isolate* isolate) {
150 if (isolate->ic_data_array() == Array::null()) { 173 if (isolate->ic_data_array() == Array::null()) {
151 return NULL; 174 return NULL;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 252
230 protected: 253 protected:
231 EmbeddedArray<Value*, N> inputs_; 254 EmbeddedArray<Value*, N> inputs_;
232 }; 255 };
233 256
234 257
235 class Value : public TemplateComputation<0> { 258 class Value : public TemplateComputation<0> {
236 public: 259 public:
237 Value() { } 260 Value() { }
238 261
239 #define DEFINE_TESTERS(ShortName, ClassName) \
240 virtual ClassName* As##ShortName() { return NULL; } \
241 bool Is##ShortName() { return As##ShortName() != NULL; }
242
243 FOR_EACH_VALUE(DEFINE_TESTERS)
244 #undef DEFINE_TESTERS
245
246 private: 262 private:
247 DISALLOW_COPY_AND_ASSIGN(Value); 263 DISALLOW_COPY_AND_ASSIGN(Value);
248 }; 264 };
249 265
250 266
251 // Functions defined in all concrete computation classes. 267 // Functions defined in all concrete computation classes.
252 #define DECLARE_COMPUTATION(ShortName) \ 268 #define DECLARE_COMPUTATION(ShortName) \
253 virtual void Accept(FlowGraphVisitor* visitor); \ 269 virtual void Accept(FlowGraphVisitor* visitor); \
270 virtual ComputationType computation_type() const { \
271 return Computation::k##ShortName; \
272 } \
254 virtual const char* DebugName() const { return #ShortName; } \ 273 virtual const char* DebugName() const { return #ShortName; } \
255 virtual RawAbstractType* StaticType() const; \ 274 virtual RawAbstractType* StaticType() const; \
256 virtual LocationSummary* MakeLocationSummary() const; \ 275 virtual LocationSummary* MakeLocationSummary() const; \
257 virtual void EmitNativeCode(FlowGraphCompiler* compiler); 276 virtual void EmitNativeCode(FlowGraphCompiler* compiler);
258 277
259 // Functions defined in all concrete value classes. 278 // Functions defined in all concrete value classes.
260 #define DECLARE_VALUE(ShortName) \ 279 #define DECLARE_VALUE(ShortName) \
261 DECLARE_COMPUTATION(ShortName) \ 280 DECLARE_COMPUTATION(ShortName) \
262 virtual ShortName##Val* As##ShortName() { return this; } \
263 virtual void PrintTo(BufferFormatter* f) const; 281 virtual void PrintTo(BufferFormatter* f) const;
264 282
265 283
266 class BindInstr; 284 class BindInstr;
267 285
268 class UseVal : public Value { 286 class UseVal : public Value {
269 public: 287 public:
270 explicit UseVal(BindInstr* definition) : definition_(definition) {} 288 explicit UseVal(BindInstr* definition) : definition_(definition) {}
271 289
272 DECLARE_VALUE(Use) 290 DECLARE_VALUE(Use)
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 Value* left, 527 Value* left,
510 Value* right) 528 Value* right)
511 : token_index_(token_index), 529 : token_index_(token_index),
512 try_index_(try_index) { 530 try_index_(try_index) {
513 ASSERT(left != NULL); 531 ASSERT(left != NULL);
514 ASSERT(right != NULL); 532 ASSERT(right != NULL);
515 inputs_[0] = left; 533 inputs_[0] = left;
516 inputs_[1] = right; 534 inputs_[1] = right;
517 } 535 }
518 536
519 DECLARE_COMPUTATION(EqualityCompareComp) 537 DECLARE_COMPUTATION(EqualityCompare)
520 538
521 intptr_t token_index() const { return token_index_; } 539 intptr_t token_index() const { return token_index_; }
522 intptr_t try_index() const { return try_index_; } 540 intptr_t try_index() const { return try_index_; }
523 Value* left() const { return inputs_[0]; } 541 Value* left() const { return inputs_[0]; }
524 Value* right() const { return inputs_[1]; } 542 Value* right() const { return inputs_[1]; }
525 543
526 virtual void PrintOperandsTo(BufferFormatter* f) const; 544 virtual void PrintOperandsTo(BufferFormatter* f) const;
527 545
528 private: 546 private:
529 const intptr_t token_index_; 547 const intptr_t token_index_;
(...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after
1999 const GrowableArray<BlockEntryInstr*>& block_order_; 2017 const GrowableArray<BlockEntryInstr*>& block_order_;
2000 2018
2001 private: 2019 private:
2002 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 2020 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
2003 }; 2021 };
2004 2022
2005 2023
2006 } // namespace dart 2024 } // namespace dart
2007 2025
2008 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 2026 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698