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

Unified Diff: runtime/vm/intermediate_language.h

Issue 10829451: Make Value not a subclass of Computation. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: rebased Created 8 years, 4 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: runtime/vm/intermediate_language.h
===================================================================
--- runtime/vm/intermediate_language.h (revision 11037)
+++ runtime/vm/intermediate_language.h (working copy)
@@ -59,7 +59,6 @@
// M is a two argument macro. It is applied to each concrete instruction's
// (including the values) typename and classname.
#define FOR_EACH_COMPUTATION(M) \
- FOR_EACH_VALUE(M) \
M(AssertAssignable, AssertAssignableComp) \
M(AssertBoolean, AssertBooleanComp) \
M(CurrentContext, CurrentContextComp) \
@@ -102,11 +101,13 @@
M(CheckStackOverflow, CheckStackOverflowComp) \
M(DoubleToDouble, DoubleToDoubleComp) \
M(SmiToDouble, SmiToDoubleComp) \
- M(CheckClass, CheckClassComp)
+ M(CheckClass, CheckClassComp) \
+ M(Materialize, MaterializeComp)
#define FORWARD_DECLARATION(ShortName, ClassName) class ClassName;
FOR_EACH_COMPUTATION(FORWARD_DECLARATION)
+FOR_EACH_VALUE(FORWARD_DECLARATION)
#undef FORWARD_DECLARATION
// Forward declarations.
@@ -312,10 +313,32 @@
};
-class Value : public TemplateComputation<0> {
+class Value : public ZoneAllocated {
public:
Value() { }
+ // Declare an enum value used to define kind-test predicates.
+ enum ValueKind {
+#define DECLARE_VALUE_KIND(ShortName, ClassName) k##ShortName,
+ FOR_EACH_VALUE(DECLARE_VALUE_KIND)
+#undef DECLARE_VALUE_KIND
+ };
+
+ // Declare predicate for each value.
+#define DECLARE_PREDICATE(ShortName, ClassName) \
+ inline bool Is##ShortName() const; \
+ inline const ClassName* As##ShortName() const; \
+ inline ClassName* As##ShortName();
+FOR_EACH_VALUE(DECLARE_PREDICATE)
srdjan 2012/08/21 22:14:53 Is it worth going through all this for just two su
Florian Schneider 2012/08/22 10:59:00 Yes, maybe we can get rid of ConstantVal completel
+#undef DECLARE_PREDICATE
+
+ virtual ValueKind value_kind() const = 0;
+
+ virtual RawAbstractType* CompileType() const = 0;
+ virtual intptr_t ResultCid() const = 0;
+
+ virtual void PrintTo(BufferFormatter* f) const = 0;
+
// Returns true if the value represents a constant.
virtual bool BindsToConstant() const = 0;
@@ -331,6 +354,8 @@
virtual void RemoveFromUseList() = 0;
+ virtual bool Equals(Value* other) const = 0;
+
private:
DISALLOW_COPY_AND_ASSIGN(Value);
};
@@ -350,7 +375,12 @@
// Functions defined in all concrete value classes.
#define DECLARE_VALUE(ShortName) \
- DECLARE_COMPUTATION(ShortName) \
+ virtual ValueKind value_kind() const { \
+ return Value::k##ShortName; \
+ } \
+ virtual const char* DebugName() const { return #ShortName; } \
+ virtual RawAbstractType* CompileType() const; \
+ virtual bool Equals(Value* other) const; \
virtual void PrintTo(BufferFormatter* f) const;
@@ -394,8 +424,6 @@
virtual intptr_t ResultCid() const;
- virtual bool AttributesEqual(Computation* other) const;
-
private:
void AddToUseList();
Definition* definition_;
@@ -433,8 +461,6 @@
virtual intptr_t ResultCid() const;
- virtual bool AttributesEqual(Computation* other) const;
-
private:
const Object& value_;
@@ -444,6 +470,26 @@
#undef DECLARE_VALUE
+class MaterializeComp : public TemplateComputation<0> {
+ public:
+ explicit MaterializeComp(ConstantVal* constant_val)
+ : constant_val_(constant_val) { }
+
+ DECLARE_COMPUTATION(Materialize)
+
+ virtual void PrintOperandsTo(BufferFormatter* f) const;
+
+ virtual bool CanDeoptimize() const { return false; }
+
+ ConstantVal* constant_val() const { return constant_val_; }
+
+ virtual intptr_t ResultCid() const;
+
+ private:
+ ConstantVal* constant_val_;
+};
+
+
class AssertAssignableComp : public TemplateComputation<3> {
public:
AssertAssignableComp(intptr_t token_pos,
@@ -1830,7 +1876,7 @@
// Implementation of type testers and cast functins.
-#define DEFINE_PREDICATE(ShortName, ClassName) \
+#define DEFINE_COMPUTATION_PREDICATE(ShortName, ClassName) \
bool Computation::Is##ShortName() const { \
return computation_kind() == k##ShortName; \
} \
@@ -1842,9 +1888,23 @@
if (!Is##ShortName()) return NULL; \
return static_cast<ClassName*>(this); \
}
-FOR_EACH_COMPUTATION(DEFINE_PREDICATE)
-#undef DEFINE_PREDICATE
+FOR_EACH_COMPUTATION(DEFINE_COMPUTATION_PREDICATE)
+#undef DEFINE_COMPUTATION_PREDICATE
+#define DEFINE_VALUE_PREDICATE(ShortName, ClassName) \
+bool Value::Is##ShortName() const { \
+ return value_kind() == k##ShortName; \
+} \
+const ClassName* Value::As##ShortName() const { \
+ if (!Is##ShortName()) return NULL; \
+ return static_cast<const ClassName*>(this); \
+} \
+ClassName* Value::As##ShortName() { \
+ if (!Is##ShortName()) return NULL; \
+ return static_cast<ClassName*>(this); \
+}
+FOR_EACH_VALUE(DEFINE_VALUE_PREDICATE)
+#undef DEFINE_VALUE_PREDICATE
// Instructions.

Powered by Google App Engine
This is Rietveld 408576698