Index: runtime/vm/intermediate_language.h |
=================================================================== |
--- runtime/vm/intermediate_language.h (revision 31282) |
+++ runtime/vm/intermediate_language.h (working copy) |
@@ -669,7 +669,7 @@ |
M(UnaryMintOp) \ |
M(CheckArrayBound) \ |
M(Constraint) \ |
- M(StringFromCharCode) \ |
+ M(StringCharCode) \ |
M(StringInterpolate) \ |
M(InvokeMathCFunction) \ |
M(MergedMath) \ |
@@ -3664,20 +3664,41 @@ |
}; |
-class StringFromCharCodeInstr : public TemplateDefinition<1> { |
+// Either converts a char-code to a string or a string to a charcode (-1 if |
+// string is not of length one). |
+class StringCharCodeInstr : public TemplateDefinition<1> { |
Florian Schneider
2013/12/20 09:29:12
Why packing two different instructions into one? I
srdjan
2013/12/20 19:48:03
Split it up in two instructions.
|
public: |
- StringFromCharCodeInstr(Value* char_code, intptr_t cid) : cid_(cid) { |
- ASSERT(char_code != NULL); |
- ASSERT(char_code->definition()->IsLoadIndexed() && |
- (char_code->definition()->AsLoadIndexed()->class_id() == |
- kOneByteStringCid)); |
- SetInputAt(0, char_code); |
+ enum Kind { |
+ kFromCharCode, |
+ kToCharCode, |
+ }; |
+ StringCharCodeInstr(Value* val, |
+ intptr_t cid, |
+ StringCharCodeInstr::Kind kind) |
+ : cid_(cid), kind_(kind) { |
+ ASSERT(val != NULL); |
+ if (kind == kFromCharCode) { |
+ ASSERT(val->definition()->IsLoadIndexed() && |
+ (val->definition()->AsLoadIndexed()->class_id() == |
+ kOneByteStringCid)); |
+ } else { |
+ ASSERT(kind == kToCharCode); |
+ } |
+ SetInputAt(0, val); |
} |
- DECLARE_INSTRUCTION(StringFromCharCode) |
+ DECLARE_INSTRUCTION(StringCharCode) |
virtual CompileType ComputeType() const; |
- Value* char_code() const { return inputs_[0]; } |
+ Value* char_code() const { |
+ ASSERT(kind_ == kFromCharCode); |
+ return inputs_[0]; |
+ } |
+ Value* str() const { |
+ ASSERT(kind_ == kToCharCode); |
+ return inputs_[0]; |
+ } |
+ StringCharCodeInstr::Kind kind() const { return kind_; } |
virtual bool CanDeoptimize() const { return false; } |
@@ -3685,15 +3706,19 @@ |
virtual EffectSet Effects() const { return EffectSet::None(); } |
virtual EffectSet Dependencies() const { return EffectSet::None(); } |
virtual bool AttributesEqual(Instruction* other) const { |
- return other->AsStringFromCharCode()->cid_ == cid_; |
+ return (other->AsStringCharCode()->cid_ == cid_) && |
+ (other->AsStringCharCode()->kind_ == kind_); |
} |
virtual bool MayThrow() const { return false; } |
+ virtual void PrintTo(BufferFormatter* f) const; |
+ |
private: |
const intptr_t cid_; |
+ const Kind kind_; |
- DISALLOW_COPY_AND_ASSIGN(StringFromCharCodeInstr); |
+ DISALLOW_COPY_AND_ASSIGN(StringCharCodeInstr); |
}; |