Bug 495028. nanojit: add opcode checks to all LIR get/set methods. r=edwsmith

This commit is contained in:
Nicholas Nethercote 2009-06-06 12:58:11 -04:00
parent f44a576277
commit 96dd8702a9
2 changed files with 113 additions and 8 deletions

View File

@ -396,6 +396,90 @@ namespace nanojit
}
}
#if defined(_DEBUG)
bool LIns::isOp1() const {
switch (firstWord.code) {
case LIR_skip:
case LIR_ret:
case LIR_live:
case LIR_neg:
#if !defined NANOJIT_64BIT
case LIR_callh:
#endif
case LIR_not:
case LIR_qlo:
case LIR_qhi:
case LIR_ov:
case LIR_cs:
case LIR_file:
case LIR_line:
case LIR_fret:
case LIR_fneg:
case LIR_i2f:
case LIR_u2f:
return true;
default:
return false;
}
}
bool LIns::isOp2() const {
switch (firstWord.code) {
case LIR_ld:
case LIR_loop:
case LIR_x:
case LIR_jt:
case LIR_jf:
case LIR_ldcs:
case LIR_feq:
case LIR_flt:
case LIR_fgt:
case LIR_fle:
case LIR_fge:
case LIR_cmov:
case LIR_add:
case LIR_sub:
case LIR_mul:
case LIR_and:
case LIR_or:
case LIR_xor:
case LIR_lsh:
case LIR_rsh:
case LIR_ush:
case LIR_xt:
case LIR_xf:
case LIR_ldcb:
case LIR_eq:
case LIR_lt:
case LIR_gt:
case LIR_le:
case LIR_ge:
case LIR_ult:
case LIR_ugt:
case LIR_ule:
case LIR_uge:
case LIR_2:
case LIR_xbarrier:
case LIR_xtbl:
case LIR_ldq:
case LIR_qiand:
case LIR_qiadd:
case LIR_qcmov:
case LIR_fadd:
case LIR_fsub:
case LIR_fmul:
case LIR_fdiv:
case LIR_qior:
case LIR_qilsh:
return true;
default:
return false;
}
}
#endif // defined(_DEBUG)
bool LIns::isCmp() const {
LOpcode op = firstWord.code;
return (op >= LIR_eq && op <= LIR_uge) || (op >= LIR_feq && op <= LIR_fge);
@ -507,6 +591,7 @@ namespace nanojit
const CallInfo* LIns::callInfo() const
{
NanoAssert(isCall());
return c.ci;
}
@ -514,6 +599,7 @@ namespace nanojit
// Nb: this must be kept in sync with insCall().
LInsp LIns::arg(uint32_t i)
{
NanoAssert(isCall());
NanoAssert(i < argc());
LInsp* offs = (LInsp*)this - (i+1);
return *offs;

View File

@ -242,12 +242,18 @@ namespace nanojit
};
public:
LIns* oprnd1() const { return u.oprnd_1; }
LIns* oprnd2() const { return u.oprnd_2; }
LIns* oprnd1() const {
NanoAssert(isOp1() || isOp2() || isStore());
return u.oprnd_1;
}
LIns* oprnd2() const {
NanoAssert(isOp2() || isStore());
return u.oprnd_2;
}
inline LOpcode opcode() const { return firstWord.code; }
inline uint8_t imm8() const { return c.imm8a; }
inline uint8_t imm8b() const { return c.imm8b; }
inline uint8_t imm8() const { NanoAssert(isop(LIR_param)); return c.imm8a; }
inline uint8_t imm8b() const { NanoAssert(isop(LIR_param)); return c.imm8b; }
inline int32_t imm32() const { NanoAssert(isconst()); return i.imm32; }
inline int32_t imm64_0() const { NanoAssert(isconstq()); return i64.imm64_0; }
inline int32_t imm64_1() const { NanoAssert(isconstq()); return i64.imm64_1; }
@ -285,6 +291,10 @@ namespace nanojit
bool isCse(const CallInfo *functions) const;
bool isRet() const { return nanojit::isRetOpcode(firstWord.code); }
bool isop(LOpcode o) const { return firstWord.code == o; }
#if defined(_DEBUG)
bool isOp1() const; // true for unary ops
bool isOp2() const; // true for binary ops
#endif
bool isQuad() const;
bool isCond() const;
bool isFloat() const;
@ -319,16 +329,25 @@ namespace nanojit
bool isBranch() const {
return isop(LIR_jt) || isop(LIR_jf) || isop(LIR_j);
}
void setimm32(int32_t x) { i.imm32 = x; }
void setimm32(int32_t x) { NanoAssert(isconst()); i.imm32 = x; }
// Set the opcode and clear resv.
void initOpcodeAndClearResv(LOpcode);
Reservation* initResv();
void clearResv();
// operand-setting methods
void setOprnd1(LIns* r) { u.oprnd_1 = r; }
void setOprnd2(LIns* r) { u.oprnd_2 = r; }
void setDisp(int32_t d) { sti.disp = d; }
void setOprnd1(LIns* r) {
NanoAssert(isOp1() || isOp2() || isStore());
u.oprnd_1 = r;
}
void setOprnd2(LIns* r) {
NanoAssert(isOp2() || isStore());
u.oprnd_2 = r;
}
void setDisp(int32_t d) {
NanoAssert(isStore());
sti.disp = d;
}
void setTarget(LIns* t);
LIns* getTarget();