mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-11 16:32:59 +00:00
Basic string literal & value support
This commit is contained in:
parent
7a2b37e397
commit
7030042c20
@ -146,6 +146,14 @@ namespace ICG {
|
||||
return dest;
|
||||
}
|
||||
|
||||
Register ICodeGenerator::loadString(String &value)
|
||||
{
|
||||
Register dest = getRegister();
|
||||
LoadString *instr = new LoadString(dest, &value);
|
||||
iCode->push_back(instr);
|
||||
return dest;
|
||||
}
|
||||
|
||||
Register ICodeGenerator::newObject()
|
||||
{
|
||||
Register dest = getRegister();
|
||||
|
@ -196,6 +196,7 @@ namespace ICG {
|
||||
Register compare(ICodeOp op, Register source1, Register source2);
|
||||
|
||||
Register loadImmediate(double value);
|
||||
Register loadString(String &value);
|
||||
|
||||
Register newObject();
|
||||
Register newArray();
|
||||
|
@ -72,6 +72,9 @@ Formatter& operator<<(Formatter& f, const JSValue& value)
|
||||
case JSValue::function_tag:
|
||||
printFormat(stdOut, "0x%08X", value.object);
|
||||
break;
|
||||
case JSValue::string_tag:
|
||||
f << *value.string;
|
||||
break;
|
||||
default:
|
||||
f << "undefined";
|
||||
break;
|
||||
|
@ -43,6 +43,7 @@
|
||||
|
||||
/* forward declare classes from JavaScript::ICG */
|
||||
namespace JavaScript {
|
||||
class StringAtom;
|
||||
namespace ICG {
|
||||
class ICodeModule;
|
||||
} /* namespace ICG */
|
||||
@ -74,6 +75,7 @@ namespace JSTypes {
|
||||
JSObject* object;
|
||||
JSArray* array;
|
||||
JSFunction *function;
|
||||
String *string;
|
||||
};
|
||||
|
||||
enum {
|
||||
@ -82,7 +84,7 @@ namespace JSTypes {
|
||||
i32_tag, u32_tag,
|
||||
i64_tag, u64_tag,
|
||||
f32_tag, f64_tag,
|
||||
object_tag, array_tag, function_tag,
|
||||
object_tag, array_tag, function_tag, string_tag,
|
||||
undefined_tag
|
||||
} tag;
|
||||
|
||||
@ -92,12 +94,14 @@ namespace JSTypes {
|
||||
explicit JSValue(JSObject* object) : object(object), tag(object_tag) {}
|
||||
explicit JSValue(JSArray* array) : array(array), tag(array_tag) {}
|
||||
explicit JSValue(JSFunction* function) : function(function), tag(function_tag) {}
|
||||
explicit JSValue(String* string) : string(string), tag(string_tag) {}
|
||||
|
||||
int32& operator=(int32 i32) { return (tag = i32_tag, this->i32 = i32); }
|
||||
float64& operator=(float64 f64) { return (tag = f64_tag, this->f64 = f64); }
|
||||
JSObject*& operator=(JSObject* object) { return (tag = object_tag, this->object = object); }
|
||||
JSArray*& operator=(JSArray* array) { return (tag = array_tag, this->array = array); }
|
||||
JSFunction*& operator=(JSFunction* function) { return (tag = function_tag, this->function = function); }
|
||||
const String*& operator=(String* string) { return (tag = string_tag, this->string = string); }
|
||||
|
||||
int operator==(const JSValue& value) const;
|
||||
};
|
||||
|
@ -70,6 +70,7 @@ namespace VM {
|
||||
JSR, /* target */
|
||||
LOAD_IMMEDIATE, /* dest, immediate value (double) */
|
||||
LOAD_NAME, /* dest, name */
|
||||
LOAD_STRING, /* dest, immediate value (string) */
|
||||
MOVE, /* dest, source */
|
||||
MULTIPLY, /* dest, source1, source2 */
|
||||
NEGATE, /* dest, source */
|
||||
@ -129,6 +130,7 @@ namespace VM {
|
||||
"JSR ",
|
||||
"LOAD_IMMEDIATE",
|
||||
"LOAD_NAME ",
|
||||
"LOAD_STRING ",
|
||||
"MOVE ",
|
||||
"MULTIPLY ",
|
||||
"NEGATE ",
|
||||
@ -635,6 +637,22 @@ namespace VM {
|
||||
}
|
||||
};
|
||||
|
||||
class LoadString : public Instruction_2<Register, String *> {
|
||||
public:
|
||||
/* dest, immediate value (string) */
|
||||
LoadString (Register aOp1, String *aOp2) :
|
||||
Instruction_2<Register, String *>
|
||||
(LOAD_STRING, aOp1, aOp2) {};
|
||||
virtual Formatter& print(Formatter& f) {
|
||||
f << opcodeNames[LOAD_STRING] << "\t" << "R" << mOp1 << ", " << "'" << *mOp2 << "'";
|
||||
return f;
|
||||
}
|
||||
virtual Formatter& printOperands(Formatter& f, const JSValues& registers) {
|
||||
f << "R" << mOp1 << '=' << registers[mOp1];
|
||||
return f;
|
||||
}
|
||||
};
|
||||
|
||||
class Move : public Instruction_2<Register, Register> {
|
||||
public:
|
||||
/* dest, source */
|
||||
|
@ -146,6 +146,14 @@ namespace ICG {
|
||||
return dest;
|
||||
}
|
||||
|
||||
Register ICodeGenerator::loadString(String &value)
|
||||
{
|
||||
Register dest = getRegister();
|
||||
LoadString *instr = new LoadString(dest, &value);
|
||||
iCode->push_back(instr);
|
||||
return dest;
|
||||
}
|
||||
|
||||
Register ICodeGenerator::newObject()
|
||||
{
|
||||
Register dest = getRegister();
|
||||
|
@ -196,6 +196,7 @@ namespace ICG {
|
||||
Register compare(ICodeOp op, Register source1, Register source2);
|
||||
|
||||
Register loadImmediate(double value);
|
||||
Register loadString(String &value);
|
||||
|
||||
Register newObject();
|
||||
Register newArray();
|
||||
|
@ -72,6 +72,9 @@ Formatter& operator<<(Formatter& f, const JSValue& value)
|
||||
case JSValue::function_tag:
|
||||
printFormat(stdOut, "0x%08X", value.object);
|
||||
break;
|
||||
case JSValue::string_tag:
|
||||
f << *value.string;
|
||||
break;
|
||||
default:
|
||||
f << "undefined";
|
||||
break;
|
||||
|
@ -43,6 +43,7 @@
|
||||
|
||||
/* forward declare classes from JavaScript::ICG */
|
||||
namespace JavaScript {
|
||||
class StringAtom;
|
||||
namespace ICG {
|
||||
class ICodeModule;
|
||||
} /* namespace ICG */
|
||||
@ -74,6 +75,7 @@ namespace JSTypes {
|
||||
JSObject* object;
|
||||
JSArray* array;
|
||||
JSFunction *function;
|
||||
String *string;
|
||||
};
|
||||
|
||||
enum {
|
||||
@ -82,7 +84,7 @@ namespace JSTypes {
|
||||
i32_tag, u32_tag,
|
||||
i64_tag, u64_tag,
|
||||
f32_tag, f64_tag,
|
||||
object_tag, array_tag, function_tag,
|
||||
object_tag, array_tag, function_tag, string_tag,
|
||||
undefined_tag
|
||||
} tag;
|
||||
|
||||
@ -92,12 +94,14 @@ namespace JSTypes {
|
||||
explicit JSValue(JSObject* object) : object(object), tag(object_tag) {}
|
||||
explicit JSValue(JSArray* array) : array(array), tag(array_tag) {}
|
||||
explicit JSValue(JSFunction* function) : function(function), tag(function_tag) {}
|
||||
explicit JSValue(String* string) : string(string), tag(string_tag) {}
|
||||
|
||||
int32& operator=(int32 i32) { return (tag = i32_tag, this->i32 = i32); }
|
||||
float64& operator=(float64 f64) { return (tag = f64_tag, this->f64 = f64); }
|
||||
JSObject*& operator=(JSObject* object) { return (tag = object_tag, this->object = object); }
|
||||
JSArray*& operator=(JSArray* array) { return (tag = array_tag, this->array = array); }
|
||||
JSFunction*& operator=(JSFunction* function) { return (tag = function_tag, this->function = function); }
|
||||
const String*& operator=(String* string) { return (tag = string_tag, this->string = string); }
|
||||
|
||||
int operator==(const JSValue& value) const;
|
||||
};
|
||||
|
@ -70,6 +70,7 @@ namespace VM {
|
||||
JSR, /* target */
|
||||
LOAD_IMMEDIATE, /* dest, immediate value (double) */
|
||||
LOAD_NAME, /* dest, name */
|
||||
LOAD_STRING, /* dest, immediate value (string) */
|
||||
MOVE, /* dest, source */
|
||||
MULTIPLY, /* dest, source1, source2 */
|
||||
NEGATE, /* dest, source */
|
||||
@ -129,6 +130,7 @@ namespace VM {
|
||||
"JSR ",
|
||||
"LOAD_IMMEDIATE",
|
||||
"LOAD_NAME ",
|
||||
"LOAD_STRING ",
|
||||
"MOVE ",
|
||||
"MULTIPLY ",
|
||||
"NEGATE ",
|
||||
@ -635,6 +637,22 @@ namespace VM {
|
||||
}
|
||||
};
|
||||
|
||||
class LoadString : public Instruction_2<Register, String *> {
|
||||
public:
|
||||
/* dest, immediate value (string) */
|
||||
LoadString (Register aOp1, String *aOp2) :
|
||||
Instruction_2<Register, String *>
|
||||
(LOAD_STRING, aOp1, aOp2) {};
|
||||
virtual Formatter& print(Formatter& f) {
|
||||
f << opcodeNames[LOAD_STRING] << "\t" << "R" << mOp1 << ", " << "'" << *mOp2 << "'";
|
||||
return f;
|
||||
}
|
||||
virtual Formatter& printOperands(Formatter& f, const JSValues& registers) {
|
||||
f << "R" << mOp1 << '=' << registers[mOp1];
|
||||
return f;
|
||||
}
|
||||
};
|
||||
|
||||
class Move : public Instruction_2<Register, Register> {
|
||||
public:
|
||||
/* dest, source */
|
||||
|
Loading…
Reference in New Issue
Block a user