From 1d0ed4882d04c864fed28c9ed07eac3ee6c208b5 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sun, 15 Dec 2013 12:09:28 -0800 Subject: [PATCH] Constant type fixes. --- src/alloy/hir/value.cc | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/alloy/hir/value.cc b/src/alloy/hir/value.cc index ab53318cd..5d1ca80d5 100644 --- a/src/alloy/hir/value.cc +++ b/src/alloy/hir/value.cc @@ -59,7 +59,21 @@ void Value::Cast(TypeName target_type) { } void Value::ZeroExtend(TypeName target_type) { - // TODO(benvanik): big matrix. + switch (type) { + case INT8_TYPE: + type = target_type; + constant.i64 = constant.i64 & ~0xFF; + return; + case INT16_TYPE: + type = target_type; + constant.i64 = constant.i64 & ~0xFFFF; + return; + case INT32_TYPE: + type = target_type; + constant.i64 = constant.i64 & ~0xFFFFFFFF; + return; + } + // Unsupported types. XEASSERTALWAYS(); } @@ -412,19 +426,19 @@ void Value::Not() { } void Value::Shl(Value* other) { - XEASSERT(type == other->type); + XEASSERT(other->type == INT8_TYPE); switch (type) { case INT8_TYPE: constant.i8 <<= other->constant.i8; break; case INT16_TYPE: - constant.i16 <<= other->constant.i16; + constant.i16 <<= other->constant.i8; break; case INT32_TYPE: - constant.i32 <<= other->constant.i32; + constant.i32 <<= other->constant.i8; break; case INT64_TYPE: - constant.i64 <<= other->constant.i64; + constant.i64 <<= other->constant.i8; break; default: XEASSERTALWAYS(); @@ -433,7 +447,7 @@ void Value::Shl(Value* other) { } void Value::Shr(Value* other) { - XEASSERT(type == other->type); + XEASSERT(other->type == INT8_TYPE); switch (type) { case INT8_TYPE: constant.i8 = (uint8_t)constant.i8 >> other->constant.i8; @@ -454,7 +468,7 @@ void Value::Shr(Value* other) { } void Value::Sha(Value* other) { - XEASSERT(type == other->type); + XEASSERT(other->type == INT8_TYPE); switch (type) { case INT8_TYPE: constant.i8 = constant.i8 >> other->constant.i8;