return TEMP(type, function->tempCount++);
}
-Expr *BasicBlock::CONST(double value)
-{
- return CONST(IR::RealType, value);
-}
-
Expr *BasicBlock::CONST(Type type, double value)
{
Const *e = function->pool->New<Const>();
if (left && right) {
if (Const *c1 = left->asConst()) {
if (Const *c2 = right->asConst()) {
+ const IR::Type ty = Binop::typeForOp(op, left, right);
+
switch (op) {
- case OpAdd: return CONST(c1->value + c2->value);
- case OpAnd: return CONST(c1->value ? c2->value : 0);
- case OpBitAnd: return CONST(int(c1->value) & int(c2->value));
- case OpBitOr: return CONST(int(c1->value) | int(c2->value));
- case OpBitXor: return CONST(int(c1->value) ^ int(c2->value));
- case OpDiv: return CONST(c1->value / c2->value);
- case OpEqual: return CONST(c1->value == c2->value);
- case OpGe: return CONST(c1->value >= c2->value);
- case OpGt: return CONST(c1->value > c2->value);
- case OpLe: return CONST(c1->value <= c2->value);
- case OpLShift: return CONST(int(c1->value) << int(c2->value));
- case OpLt: return CONST(c1->value < c2->value);
- case OpMod: return CONST(::fmod(c1->value, c2->value));
- case OpMul: return CONST(c1->value * c2->value);
- case OpNotEqual: return CONST(c1->value != c2->value);
- case OpOr: return CONST(c1->value ? c1->value : c2->value);
- case OpRShift: return CONST(int(c1->value) >> int(c2->value));
- case OpStrictEqual: return CONST(c1->value == c2->value);
- case OpStrictNotEqual: return CONST(c1->value != c2->value);
- case OpSub: return CONST(c1->value - c2->value);
- case OpURShift: return CONST(unsigned(c1->value) >> int(c2->value));
+ case OpAdd: return CONST(ty, c1->value + c2->value);
+ case OpAnd: return CONST(ty, c1->value ? c2->value : 0);
+ case OpBitAnd: return CONST(ty, int(c1->value) & int(c2->value));
+ case OpBitOr: return CONST(ty, int(c1->value) | int(c2->value));
+ case OpBitXor: return CONST(ty, int(c1->value) ^ int(c2->value));
+ case OpDiv: return CONST(ty, c1->value / c2->value);
+ case OpEqual: return CONST(ty, c1->value == c2->value);
+ case OpGe: return CONST(ty, c1->value >= c2->value);
+ case OpGt: return CONST(ty, c1->value > c2->value);
+ case OpLe: return CONST(ty, c1->value <= c2->value);
+ case OpLShift: return CONST(ty, int(c1->value) << int(c2->value));
+ case OpLt: return CONST(ty, c1->value < c2->value);
+ case OpMod: return CONST(ty, ::fmod(c1->value, c2->value));
+ case OpMul: return CONST(ty, c1->value * c2->value);
+ case OpNotEqual: return CONST(ty, c1->value != c2->value);
+ case OpOr: return CONST(ty, c1->value ? c1->value : c2->value);
+ case OpRShift: return CONST(ty, int(c1->value) >> int(c2->value));
+ case OpStrictEqual: return CONST(ty, c1->value == c2->value);
+ case OpStrictNotEqual: return CONST(ty, c1->value != c2->value);
+ case OpSub: return CONST(ty, c1->value - c2->value);
+ case OpURShift: return CONST(ty, unsigned(c1->value) >> int(c2->value));
case OpIfTrue: // unary ops
case OpNot:
_expr.format = ExprResult::cx;
_block->JUMP(ast->value ? _expr.iftrue : _expr.iffalse);
} else {
- _expr.code = _block->CONST(ast->value);
+ _expr.code = _block->CONST(IR::RealType, ast->value);
}
return false;
}
if (expr.isNot(IR::InvalidType)) {
if (IR::Const *c = expr.code->asConst()) {
_expr = expr;
- _expr.code = _block->CONST(-c->value);
+ _expr.code = _block->CONST(expr->type, -c->value);
return false;
}
if (expr.isNot(IR::InvalidType)) {
if (IR::Const *c = expr.code->asConst()) {
_expr = expr;
- _expr.code = _block->CONST(~int(c->value));
+ _expr.code = _block->CONST(expr->type, ~int(c->value));
return false;
}
IR::Expr *code = _block->UNOP(IR::OpCompl, expr);
if (expr.isNot(IR::InvalidType)) {
if (IR::Const *c = expr.code->asConst()) {
_expr = expr;
- _expr.code = _block->CONST(!c->value);
+ _expr.code = _block->CONST(IR::BoolType, !c->value);
return false;
}
IR::Temp *r = _block->TEMP(IR::InvalidType);
_block = iffalse;
- _block->MOVE(r, _block->CONST(0)); // ### use the right null value
+ _block->MOVE(r, _block->CONST(IR::BoolType, 0)); // ### use the right null value
_block->JUMP(endif);
_block = iftrue;