on master help sign in
Merge pull request #404 from Ralith/llvm-fixes
7427990Edwin Brady
src/IRTS/CodegenLLVM.hs+15−3
@@ -816,6 +816,13 @@ itWidth :: IntTy -> Word32
816itWidth ITNative = 32
816itWidth ITNative = 32
817itWidth ITChar = 32
817itWidth ITChar = 32
818itWidth (ITFixed x) = fromIntegral $ nativeTyWidth x
818itWidth (ITFixed x) = fromIntegral $ nativeTyWidth x
819+itWidth x = ierror $ "itWidth: " ++ show x
820+
821+itConst :: IntTy -> Integer -> C.Constant
822+itConst (ITFixed n) x = C.Int (fromIntegral $ nativeTyWidth n) x
823+itConst ITNative x = itConst (ITFixed IT32) x
824+itConst ITChar x = itConst (ITFixed IT32) x
825+itConst (ITVec elts size) x = C.Vector (replicate size (itConst (ITFixed elts) x))
819
826
820cgOp :: PrimFn -> [Operand] -> Codegen Operand
827cgOp :: PrimFn -> [Operand] -> Codegen Operand
821cgOp (LTrunc ITBig ity) [x] = do
828cgOp (LTrunc ITBig ity) [x] = do
@@ -842,6 +849,10 @@ cgOp (LSExt from ITBig) [x] = do
842 inst' $ simpleCall "mpz_init_set_sll" [mpz, nx']
849 inst' $ simpleCall "mpz_init_set_sll" [mpz, nx']
843 box (FArith (ATInt ITBig)) mpz
850 box (FArith (ATInt ITBig)) mpz
844
851
852+-- ITChar, ITNative, and IT32 all share representation
853+cgOp (LChInt ITNative) [x] = return x
854+cgOp (LIntCh ITNative) [x] = return x
855+
845cgOp (LLt (ATInt ITBig)) [x,y] = mpzCmp IPred.SLT x y
856cgOp (LLt (ATInt ITBig)) [x,y] = mpzCmp IPred.SLT x y
846cgOp (LLe (ATInt ITBig)) [x,y] = mpzCmp IPred.SLE x y
857cgOp (LLe (ATInt ITBig)) [x,y] = mpzCmp IPred.SLE x y
847cgOp (LEq (ATInt ITBig)) [x,y] = mpzCmp IPred.EQ x y
858cgOp (LEq (ATInt ITBig)) [x,y] = mpzCmp IPred.EQ x y
@@ -893,7 +904,7 @@ cgOp (LURem ity) [x,y] = ibin ity x y URem
893cgOp (LAnd ity) [x,y] = ibin ity x y And
904cgOp (LAnd ity) [x,y] = ibin ity x y And
894cgOp (LOr ity) [x,y] = ibin ity x y Or
905cgOp (LOr ity) [x,y] = ibin ity x y Or
895cgOp (LXOr ity) [x,y] = ibin ity x y Xor
906cgOp (LXOr ity) [x,y] = ibin ity x y Xor
896−cgOp (LCompl ity) [x] = iun ity x (Xor (ConstantOperand (C.Int (itWidth ity) (-1))))
907+cgOp (LCompl ity) [x] = iun ity x (Xor . ConstantOperand $ itConst ity (-1))
897cgOp (LSHL ity) [x,y] = ibin ity x y (Shl False False)
908cgOp (LSHL ity) [x,y] = ibin ity x y (Shl False False)
898cgOp (LLSHR ity) [x,y] = ibin ity x y (LShr False)
909cgOp (LLSHR ity) [x,y] = ibin ity x y (LShr False)
899cgOp (LASHR ity) [x,y] = ibin ity x y (AShr False)
910cgOp (LASHR ity) [x,y] = ibin ity x y (AShr False)
@@ -1029,13 +1040,14 @@ cgOp LStdErr [] = do
1029 ptr <- inst $ loadInv stdErr
1040 ptr <- inst $ loadInv stdErr
1030 box FPtr ptr
1041 box FPtr ptr
1031
1042
1032−cgOp prim args = ierror $ "Unimplemented primitive: [" ++ show prim ++ "]("
1043+cgOp prim args = ierror $ "Unimplemented primitive: <" ++ show prim ++ ">("
1033 ++ intersperse ',' (take (length args) ['a'..]) ++ ")"
1044 ++ intersperse ',' (take (length args) ['a'..]) ++ ")"
1034
1045
1035iCoerce :: (Operand -> Type -> InstructionMetadata -> Instruction) -> NativeTy -> NativeTy -> Operand -> Codegen Operand
1046iCoerce :: (Operand -> Type -> InstructionMetadata -> Instruction) -> NativeTy -> NativeTy -> Operand -> Codegen Operand
1047+iCoerce _ from to x | from == to = return x
1036iCoerce operator from to x = do
1048iCoerce operator from to x = do
1037 x' <- unbox (FArith (ATInt (ITFixed from))) x
1049 x' <- unbox (FArith (ATInt (ITFixed from))) x
1038− x'' <- inst $ operator x' (ftyToTy (FArith (ATInt (ITFixed from)))) []
1050+ x'' <- inst $ operator x' (ftyToTy (FArith (ATInt (ITFixed to)))) []
1039 box (FArith (ATInt (ITFixed to))) x''
1051 box (FArith (ATInt (ITFixed to))) x''
1040
1052
1041cgStrCat :: Operand -> Operand -> Codegen Operand
1053cgStrCat :: Operand -> Operand -> Codegen Operand
src/Idris/Primitives.hs+1−1
@@ -121,7 +121,7 @@ primitives =
121 (1, LStrLen) total,
121 (1, LStrLen) total,
122 -- Conversions
122 -- Conversions
123 Prim (UN "prim__charToInt") (ty [(AType (ATInt ITChar))] (AType (ATInt ITNative))) 1 (c_charToInt)
123 Prim (UN "prim__charToInt") (ty [(AType (ATInt ITChar))] (AType (ATInt ITNative))) 1 (c_charToInt)
124− (1, LChInt ITChar) total,
124+ (1, LChInt ITNative) total,
125 Prim (UN "prim__intToChar") (ty [(AType (ATInt ITNative))] (AType (ATInt ITChar))) 1 (c_intToChar)
125 Prim (UN "prim__intToChar") (ty [(AType (ATInt ITNative))] (AType (ATInt ITChar))) 1 (c_intToChar)
126 (1, LIntCh ITNative) total,
126 (1, LIntCh ITNative) total,
127 Prim (UN "prim__strToFloat") (ty [StrType] (AType ATFloat)) 1 (c_strToFloat)
127 Prim (UN "prim__strToFloat") (ty [StrType] (AType ATFloat)) 1 (c_strToFloat)