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

Unified Diff: vm/intermediate_language.h

Issue 10407031: Add IR printing into a supplied buffer. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: vm/intermediate_language.h
===================================================================
--- vm/intermediate_language.h (revision 7724)
+++ vm/intermediate_language.h (working copy)
@@ -68,6 +68,11 @@
FOR_EACH_COMPUTATION(FORWARD_DECLARATION)
#undef FORWARD_DECLARATION
+// Forward declarations.
+class BufferFormatter;
+class Value;
+
+
class Computation : public ZoneAllocated {
public:
static const int kNoCid = -1;
@@ -87,6 +92,7 @@
virtual void Accept(FlowGraphVisitor* visitor) = 0;
virtual intptr_t InputCount() const = 0;
+ virtual Value* InputAt(intptr_t i) const = 0;
// Static type of the computation.
virtual RawAbstractType* StaticType() const = 0;
@@ -95,6 +101,13 @@
// frame-allocated locals assigned to by the computation.
virtual void RecordAssignedVars(BitVector* assigned_vars);
+ virtual const char* DebugName() const = 0;
+
+ // Printing support. These functions are sometimes overridden for custom
+ // formatting. Otherwise, it prints in the format "opcode(op1, op2, op3)".
+ virtual void PrintTo(BufferFormatter* f) const;
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
friend class Instruction;
static intptr_t GetNextCid(Isolate* isolate) {
@@ -147,16 +160,25 @@
template<typename T>
class EmbeddedArray<T, 0> {
public:
- int length() const { return 0; }
+ intptr_t length() const { return 0; }
+ const T& operator[](intptr_t i) const {
+ UNREACHABLE();
+ static T sentinel = 0;
+ return sentinel;
+ }
+ T& operator[](intptr_t i) {
+ UNREACHABLE();
+ static T sentinel = 0;
+ return sentinel;
+ }
};
-class Value;
-
template<intptr_t N>
class TemplateComputation : public Computation {
public:
virtual intptr_t InputCount() const { return N; }
+ virtual Value* InputAt(intptr_t i) const { return inputs_[i]; }
protected:
EmbeddedArray<Value*, N> inputs_;
@@ -182,12 +204,14 @@
// Functions defined in all concrete computation classes.
#define DECLARE_COMPUTATION(ShortName) \
virtual void Accept(FlowGraphVisitor* visitor); \
- virtual RawAbstractType* StaticType() const; \
+ virtual const char* DebugName() const { return #ShortName; } \
+ virtual RawAbstractType* StaticType() const;
// Functions defined in all concrete value classes.
#define DECLARE_VALUE(ShortName) \
DECLARE_COMPUTATION(ShortName) \
- virtual ShortName##Val* As##ShortName() { return this; }
+ virtual ShortName##Val* As##ShortName() { return this; } \
+ virtual void PrintTo(BufferFormatter* f) const;
// Definitions and uses are mutually recursive.
@@ -258,7 +282,14 @@
const String& dst_name() const { return dst_name_; }
virtual intptr_t InputCount() const;
+ virtual Value* InputAt(intptr_t i) const {
+ if (i == 0) return value();
+ if (i == 1) return instantiator_type_arguments();
+ return NULL;
+ }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const intptr_t token_index_;
const intptr_t try_index_;
@@ -349,7 +380,12 @@
Value* ArgumentAt(intptr_t index) const { return (*arguments_)[index]; }
virtual intptr_t InputCount() const;
+ virtual Value* InputAt(intptr_t i) const {
+ return i == 0 ? context() : ArgumentAt(i - 1);
+ }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const ClosureCallNode& ast_node_;
const intptr_t try_index_;
@@ -390,7 +426,10 @@
intptr_t checked_argument_count() const { return checked_argument_count_; }
virtual intptr_t InputCount() const;
+ virtual Value* InputAt(intptr_t i) const { return ArgumentAt(i); }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const intptr_t token_index_;
const intptr_t try_index_;
@@ -418,6 +457,8 @@
Value* left() const { return inputs_[0]; }
Value* right() const { return inputs_[1]; }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const Token::Kind kind_;
@@ -446,6 +487,8 @@
Value* left() const { return inputs_[0]; }
Value* right() const { return inputs_[1]; }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const intptr_t token_index_;
const intptr_t try_index_;
@@ -482,7 +525,10 @@
Value* ArgumentAt(intptr_t index) const { return (*arguments_)[index]; }
virtual intptr_t InputCount() const;
+ virtual Value* InputAt(intptr_t i) const { return ArgumentAt(i); }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const intptr_t token_index_;
const intptr_t try_index_;
@@ -504,6 +550,8 @@
const LocalVariable& local() const { return local_; }
intptr_t context_level() const { return context_level_; }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const LocalVariable& local_;
const intptr_t context_level_;
@@ -529,6 +577,8 @@
virtual void RecordAssignedVars(BitVector* assigned_vars);
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const LocalVariable& local_;
const intptr_t context_level_;
@@ -561,6 +611,8 @@
return ast_node_.has_optional_parameters();
}
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const NativeBodyNode& ast_node_;
const intptr_t try_index_;
@@ -583,6 +635,8 @@
Value* instance() const { return inputs_[0]; }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const LoadInstanceFieldNode& ast_node_;
@@ -610,6 +664,8 @@
Value* instance() const { return inputs_[0]; }
Value* value() const { return inputs_[1]; }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const StoreInstanceFieldNode& ast_node_;
@@ -625,6 +681,8 @@
const Field& field() const { return field_; }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const Field& field_;
@@ -646,6 +704,8 @@
const Field& field() const { return field_; }
Value* value() const { return inputs_[0]; }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const Field& field_;
@@ -792,7 +852,14 @@
intptr_t try_index() const { return try_index_; }
virtual intptr_t InputCount() const;
+ virtual Value* InputAt(intptr_t i) const {
+ if (i == 0) return value();
+ if (i == 1) return type_arguments();
+ return NULL;
+ }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const intptr_t token_index_;
const intptr_t try_index_;
@@ -823,7 +890,10 @@
const ZoneGrowableArray<Value*>& arguments() const { return *arguments_; }
virtual intptr_t InputCount() const;
+ virtual Value* InputAt(intptr_t i) const { return arguments()[i]; }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const ConstructorCallNode& ast_node_;
const intptr_t try_index_;
@@ -850,7 +920,10 @@
const ZoneGrowableArray<Value*>& arguments() const { return *arguments_; }
virtual intptr_t InputCount() const;
+ virtual Value* InputAt(intptr_t i) const { return arguments()[i]; }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const ConstructorCallNode& ast_node_;
const intptr_t try_index_;
@@ -886,7 +959,10 @@
Value* element_type() const { return element_type_; }
virtual intptr_t InputCount() const;
+ virtual Value* InputAt(intptr_t i) const { return ElementAt(i); }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const intptr_t token_index_;
const intptr_t try_index_;
@@ -915,7 +991,12 @@
Value* type_arguments() const { return type_arguments_; }
virtual intptr_t InputCount() const;
+ virtual Value* InputAt(intptr_t i) const {
+ return i == 0 ? type_arguments() : NULL;
+ }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const ClosureNode& ast_node_;
const intptr_t try_index_;
@@ -942,6 +1023,8 @@
intptr_t offset_in_bytes() const { return offset_in_bytes_; }
const AbstractType& type() const { return type_; }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const intptr_t offset_in_bytes_;
const AbstractType& type_;
@@ -970,6 +1053,8 @@
intptr_t offset_in_bytes() const { return offset_in_bytes_; }
const AbstractType& type() const { return type_; }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const intptr_t offset_in_bytes_;
const AbstractType& type_;
@@ -1000,6 +1085,8 @@
intptr_t token_index() const { return token_index_; }
intptr_t try_index() const { return try_index_; }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const intptr_t token_index_;
const intptr_t try_index_;
@@ -1032,6 +1119,8 @@
intptr_t token_index() const { return token_index_; }
intptr_t try_index() const { return try_index_; }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const intptr_t token_index_;
const intptr_t try_index_;
@@ -1081,6 +1170,8 @@
intptr_t try_index() const { return try_index_; }
intptr_t num_context_variables() const { return num_context_variables_; }
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const intptr_t token_index_;
const intptr_t try_index_;
@@ -1142,6 +1233,8 @@
DECLARE_COMPUTATION(CatchEntry)
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
private:
const LocalVariable& exception_var_;
const LocalVariable& stacktrace_var_;
@@ -1179,6 +1272,8 @@
// Forward declarations for Instruction classes.
class BlockEntryInstr;
+class FlowGraphBuilder;
+
#define FORWARD_DECLARATION(type) class type##Instr;
FOR_EACH_INSTRUCTION(FORWARD_DECLARATION)
#undef FORWARD_DECLARATION
@@ -1190,6 +1285,8 @@
virtual bool Is##type() const { return true; } \
virtual type##Instr* As##type() { return this; } \
virtual intptr_t InputCount() const; \
+ virtual const char* DebugName() const { return #type; } \
+ virtual void PrintTo(BufferFormatter* f) const;
class Instruction : public ZoneAllocated {
@@ -1251,6 +1348,9 @@
// frame-allocated locals assigned to by the instruction.
virtual void RecordAssignedVars(BitVector* assigned_vars);
+ // Printing support.
+ virtual void PrintTo(BufferFormatter* f) const = 0;
+
#define INSTRUCTION_TYPE_CHECK(type) \
virtual bool Is##type() const { return false; } \
virtual type##Instr* As##type() { return NULL; }
@@ -1289,6 +1389,9 @@
intptr_t postorder_number() const { return postorder_number_; }
void set_postorder_number(intptr_t number) { postorder_number_ = number; }
+ intptr_t block_id() const { return block_id_; }
+ void set_block_id(intptr_t value) { block_id_ = value; }
+
BlockEntryInstr* dominator() const { return dominator_; }
void set_dominator(BlockEntryInstr* instr) { dominator_ = instr; }
@@ -1307,12 +1410,14 @@
BlockEntryInstr()
: preorder_number_(-1),
postorder_number_(-1),
+ block_id_(-1),
dominator_(NULL),
last_instruction_(NULL) { }
private:
intptr_t preorder_number_;
intptr_t postorder_number_;
+ intptr_t block_id_;
BlockEntryInstr* dominator_; // Immediate dominator, NULL for graph entry.
Instruction* last_instruction_;
« vm/il_printer.h ('K') | « vm/il_printer.cc ('k') | vm/intermediate_language.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698