on master help sign in
Fixed width SExt and ZExt
commit6a48a25363a89749f763b49380954533a79e01cb authorBenjamin Saunders <besaunde@sfu.ca> dateTue 25 Jun 2013, 20:27 (13 years ago) parent1280aea
1 file changed+9−4
src/IRTS/CodegenLLVM.hs+9−4
src/IRTS/CodegenLLVM.hs+9−4
@@ -742,10 +742,9 @@ cgOp (LAnd ITBig) [x,y] = mpzBin "and" x y
742742cgOp (LOr ITBig) [x,y] = mpzBin "ior" x y
743743cgOp (LXOr ITBig) [x,y] = mpzBin "xor" x y
744744
745−cgOp (LTrunc from to) [x] | itWidth from > itWidth to = do
746− x' <- unbox (FInt from) x
747− tx <- inst $ Trunc x' (IntegerType $ itWidth to) []
748− box (FInt to) tx
745+cgOp (LTrunc from to) [x] | itWidth from > itWidth to = iCoerce Trunc from to x
746+cgOp (LZExt from to) [x] | itWidth from < itWidth to = iCoerce ZExt from to x
747+cgOp (LSExt from to) [x] | itWidth from < itWidth to = iCoerce SExt from to x
749748
750749cgOp (LLt ity) [x,y] = iCmp ity IPred.SLT x y
751750cgOp (LLe ity) [x,y] = iCmp ity IPred.SLE x y
@@ -790,6 +789,12 @@ cgOp LStrConcat [x,y] = cgStrCat x y
790789cgOp prim args = ierror $ "Unimplemented primitive: [" ++ show prim ++ "]("
791790 ++ intersperse ',' (take (length args) ['a'..]) ++ ")"
792791
792+iCoerce :: (Operand -> Type -> InstructionMetadata -> Instruction) -> IntTy -> IntTy -> Operand -> Codegen Operand
793+iCoerce operator from to x = do
794+ x' <- unbox (FInt from) x
795+ x'' <- inst $ operator x' (IntegerType $ itWidth to) []
796+ box (FInt to) x''
797+
793798cgStrCat :: Operand -> Operand -> Codegen Operand
794799cgStrCat x y = do
795800 x' <- unbox FString x