diff options
author | John Hodge <tpg@mutabah.net> | 2016-09-28 20:42:45 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-09-28 20:42:45 +0800 |
commit | f556e9fe473e3a04ad6e09ca2fce96ff9b7ead8b (patch) | |
tree | f5de620dae2a0709419619d8c8335a8f89683fea /src | |
parent | e80c6c12e6a09773b152c268c090aa09d0fc7701 (diff) | |
download | mrust-f556e9fe473e3a04ad6e09ca2fce96ff9b7ead8b.tar.gz |
Const Eval - Rough MIR casts
Diffstat (limited to 'src')
-rw-r--r-- | src/hir_conv/constant_evaluation.cpp | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/hir_conv/constant_evaluation.cpp b/src/hir_conv/constant_evaluation.cpp index b133fbc9..909c70da 100644 --- a/src/hir_conv/constant_evaluation.cpp +++ b/src/hir_conv/constant_evaluation.cpp @@ -754,7 +754,45 @@ namespace { ), (Cast, auto inval = read_lval(e.val); - TODO(sp, "RValue::Cast to " << e.type << ", val = " << inval); + TU_MATCH_DEF(::HIR::TypeRef::Data, (e.type.m_data), (te), + ( + TODO(sp, "RValue::Cast to " << e.type << ", val = " << inval); + ), + (Primitive, + uint64_t mask; + switch(te) + { + case ::HIR::CoreType::I8: + case ::HIR::CoreType::U8: + mask = 0xFF; + if(0) + case ::HIR::CoreType::I16: + case ::HIR::CoreType::U16: + mask = 0xFFFF; + if(0) + case ::HIR::CoreType::I32: + case ::HIR::CoreType::U32: + mask = 0xFFFFFFFF; + if(0) + case ::HIR::CoreType::I64: + case ::HIR::CoreType::U64: + mask = 0xFFFFFFFFFFFFFFFF; + + TU_IFLET( ::HIR::Literal, inval, Integer, i, + val = ::HIR::Literal(i & mask); + ) + else TU_IFLET( ::HIR::Literal, inval, Float, i, + val = ::HIR::Literal( static_cast<uint64_t>(i) & mask); + ) + else { + BUG(sp, "Invalid cast of " << inval.tag_str() << " to " << e.type); + } + break; + default: + TODO(sp, "RValue::Cast to " << e.type << ", val = " << inval); + } + ) + ) ), (BinOp, TODO(sp, "RValue::BinOp"); |