namespace QQmlJS {
namespace Moth {
-union Instr
-{
- struct Param {
- enum {
- ValueType = 0,
- ArgumentType = 1,
- LocalType = 2,
- TempType = 3,
- ScopedLocalType = 4
- };
- QV4::Value value;
- unsigned type : 3;
- unsigned scope : 29;
- unsigned index;
+struct Param {
+ enum {
+ ValueType = 0,
+ ArgumentType = 1,
+ LocalType = 2,
+ TempType = 3,
+ ScopedLocalType = 4
+ };
+ QV4::Value value;
+ unsigned type : 3;
+ unsigned scope : 29;
+ unsigned index;
- bool isValue() const { return type == ValueType; }
- bool isArgument() const { return type == ArgumentType; }
- bool isLocal() const { return type == LocalType; }
- bool isTemp() const { return type == TempType; }
- bool isScopedLocal() const { return type == ScopedLocalType; }
+ bool isValue() const { return type == ValueType; }
+ bool isArgument() const { return type == ArgumentType; }
+ bool isLocal() const { return type == LocalType; }
+ bool isTemp() const { return type == TempType; }
+ bool isScopedLocal() const { return type == ScopedLocalType; }
- static Param createValue(const QV4::Value &v)
- {
- Param p;
- p.type = ValueType;
- p.scope = 0;
- p.value = v;
- return p;
- }
+ static Param createValue(const QV4::Value &v)
+ {
+ Param p;
+ p.type = ValueType;
+ p.scope = 0;
+ p.value = v;
+ return p;
+ }
- static Param createArgument(unsigned idx, uint scope)
- {
- Param p;
- p.type = ArgumentType;
- p.scope = scope;
- p.index = idx;
- return p;
- }
+ static Param createArgument(unsigned idx, uint scope)
+ {
+ Param p;
+ p.type = ArgumentType;
+ p.scope = scope;
+ p.index = idx;
+ return p;
+ }
- static Param createLocal(unsigned idx)
- {
- Param p;
- p.type = LocalType;
- p.scope = 0;
- p.index = idx;
- return p;
- }
+ static Param createLocal(unsigned idx)
+ {
+ Param p;
+ p.type = LocalType;
+ p.scope = 0;
+ p.index = idx;
+ return p;
+ }
- static Param createTemp(unsigned idx)
- {
- Param p;
- p.type = TempType;
- p.scope = 0;
- p.index = idx;
- return p;
- }
+ static Param createTemp(unsigned idx)
+ {
+ Param p;
+ p.type = TempType;
+ p.scope = 0;
+ p.index = idx;
+ return p;
+ }
- static Param createScopedLocal(unsigned idx, uint scope)
- {
- Param p;
- p.type = ScopedLocalType;
- p.scope = scope;
- p.index = idx;
- return p;
- }
+ static Param createScopedLocal(unsigned idx, uint scope)
+ {
+ Param p;
+ p.type = ScopedLocalType;
+ p.scope = scope;
+ p.index = idx;
+ return p;
+ }
- inline bool operator==(const Param &other) const
- { return type == other.type && scope == other.scope && index == other.index; }
+ inline bool operator==(const Param &other) const
+ { return type == other.type && scope == other.scope && index == other.index; }
- inline bool operator!=(const Param &other) const
- { return !(*this == other); }
- };
+ inline bool operator!=(const Param &other) const
+ { return !(*this == other); }
+};
+union Instr
+{
enum Type {
FOR_EACH_MOTH_INSTR(MOTH_INSTR_ENUM)
};
void InstructionSelection::loadString(const QString &str, V4IR::Temp *targetTemp)
{
Instruction::LoadValue load;
- load.value = Instr::Param::createValue(QV4::Value::fromString(identifier(str)));
+ load.value = Param::createValue(QV4::Value::fromString(identifier(str)));
load.result = getResultParam(targetTemp);
addInstruction(load);
}
_vmFunction->generatedValues.append(v);
Instruction::LoadValue load;
- load.value = Instr::Param::createValue(v);
+ load.value = Param::createValue(v);
load.result = getResultParam(targetTemp);
addInstruction(load);
}
binopHelper(oper, leftSource, rightSource, target);
}
-Instr::Param InstructionSelection::binopHelper(V4IR::AluOp oper, V4IR::Expr *leftSource, V4IR::Expr *rightSource, V4IR::Temp *target)
+Param InstructionSelection::binopHelper(V4IR::AluOp oper, V4IR::Expr *leftSource, V4IR::Expr *rightSource, V4IR::Temp *target)
{
#ifdef USE_TYPE_INFO
if (leftSource->type & V4IR::NumberType && rightSource->type & V4IR::NumberType) {
binop.lhs = getParam(leftSource);
binop.rhs = getParam(rightSource);
binop.result = getResultParam(target);
+ Q_ASSERT(binop.alu);
addInstruction(binop);
return binop.result;
} else {
binop.lhs = getParam(leftSource);
binop.rhs = getParam(rightSource);
binop.result = getResultParam(target);
+ Q_ASSERT(binop.alu);
addInstruction(binop);
return binop.result;
}
while (e) {
Instruction::MoveTemp move;
move.source = getParam(e->expr);
- move.result = Instr::Param::createTemp(argLocation);
+ move.result = Param::createTemp(argLocation);
addInstruction(move);
++argLocation;
++argc;
void InstructionSelection::visitCJump(V4IR::CJump *s)
{
- Instr::Param condition;
+ Param condition;
if (V4IR::Temp *t = s->cond->asTemp()) {
condition = getResultParam(t);
} else if (V4IR::Binop *b = s->cond->asBinop()) {
void InstructionSelection::callBuiltinDeleteValue(V4IR::Temp *result)
{
Instruction::LoadValue load;
- load.value = Instr::Param::createValue(QV4::Value::fromBoolean(false));
+ load.value = Param::createValue(QV4::Value::fromBoolean(false));
load.result = getResultParam(result);
addInstruction(load);
}
Instruction::MoveTemp move;
move.source = getParam(it->expr);
- move.result = Instr::Param::createTemp(argLocation);
+ move.result = Param::createTemp(argLocation);
addInstruction(move);
++argLocation;
Instruction::MoveTemp move;
move.source = getParam(it->expr);
- move.result = Instr::Param::createTemp(argLocation);
+ move.result = Param::createTemp(argLocation);
addInstruction(move);
++argLocation;
}
return str;
}
-Instr::Param InstructionSelection::getParam(V4IR::Expr *e) {
- typedef Instr::Param Param;
+Param InstructionSelection::getParam(V4IR::Expr *e) {
+ typedef Param Param;
assert(e);
if (V4IR::Const *c = e->asConst()) {
virtual void inplaceMemberOp(V4IR::AluOp oper, V4IR::Temp *source, V4IR::Temp *targetBase, const QString &targetName);
private:
- Instr::Param binopHelper(V4IR::AluOp oper, V4IR::Expr *leftSource, V4IR::Expr *rightSource, V4IR::Temp *target);
+ Param binopHelper(V4IR::AluOp oper, V4IR::Expr *leftSource, V4IR::Expr *rightSource, V4IR::Temp *target);
struct Instruction {
#define MOTH_INSTR_DATA_TYPEDEF(I, FMT) typedef InstrData<Instr::I> I;
Instruction();
};
- Instr::Param getParam(V4IR::Expr *e);
+ Param getParam(V4IR::Expr *e);
- Instr::Param getResultParam(V4IR::Temp *result)
+ Param getResultParam(V4IR::Temp *result)
{
if (result)
return getParam(result);
else
- return Instr::Param::createTemp(scratchTempIndex());
+ return Param::createTemp(scratchTempIndex());
}
void simpleMove(V4IR::Move *);
static inline QV4::Value *getValueRef(QV4::ExecutionContext *context,
QV4::Value* stack,
- const Instr::Param ¶m
+ const Param ¶m
#if !defined(QT_NO_DEBUG)
, unsigned stackSize
#endif