@@ -132,6 +132,8 @@ initDefs tgt =
132 , exfun "GC_malloc" ptrI8 [intPtr] False
132 , exfun "GC_malloc" ptrI8 [intPtr] False
133 , exfun "GC_malloc_atomic" ptrI8 [intPtr] False
133 , exfun "GC_malloc_atomic" ptrI8 [intPtr] False
134 , exfun "__gmpz_init" VoidType [pmpz] False
134 , exfun "__gmpz_init" VoidType [pmpz] False
135+ , exfun "__gmpz_init_set_str" (IntegerType 32) [pmpz, ptrI8, IntegerType 32] False
136+ , exfun "__gmpz_get_str" ptrI8 [ptrI8, IntegerType 32, pmpz] False
135 , GlobalDefinition mainDef
137 , GlobalDefinition mainDef
136 ] ++ map mpzBinFun ["add", "sub", "mul", "fdiv_q", "fdiv_r", "and", "ior", "xor"]
138 ] ++ map mpzBinFun ["add", "sub", "mul", "fdiv_q", "fdiv_r", "and", "ior", "xor"]
@@ -668,8 +670,10 @@ cgConst c@(TT.Str s) = do
668cgConst c@(TT.BI i) = do
670cgConst c@(TT.BI i) = do
669 str <- addGlobal' (ArrayType (1 + fromInteger (numDigits 10 i)) (IntegerType 8)) (cgConst' c)
671 str <- addGlobal' (ArrayType (1 + fromInteger (numDigits 10 i)) (IntegerType 8)) (cgConst' c)
670 mpz <- alloc mpzTy
672 mpz <- alloc mpzTy
673+ inst $ simpleCall "__gmpz_init_set_str" [mpz
671− inst $ simpleCall "__gmpz_init_set_str" [mpz, ConstantOperand $ C.GetElementPtr True str [ C.Int 32 0
674+ , ConstantOperand $ C.GetElementPtr True str [ C.Int 32 0, C.Int 32 0]
672− , C.Int 32 0]]
675+ , ConstantOperand $ C.Int 32 10
673 box (FInt ITBig) mpz
677 box (FInt ITBig) mpz
674cgConst x = return $ ConstantOperand nullValue
678cgConst x = return $ ConstantOperand nullValue
@@ -751,7 +755,9 @@ cgOp (LIntStr ITBig) [x] = do
751 x' <- unbox (FInt ITBig) x
755 x' <- unbox (FInt ITBig) x
752 ustr <- inst $ simpleCall "__gmpz_get_str"
756 ustr <- inst $ simpleCall "__gmpz_get_str"
753 [ ConstantOperand (C.Null (PointerType (IntegerType 8) (AddrSpace 0)))
757 [ ConstantOperand (C.Null (PointerType (IntegerType 8) (AddrSpace 0)))
754− , ConstantOperand (C.Int 32 10), x']
758+ , ConstantOperand (C.Int 32 10)
755 box FString ustr
761 box FString ustr
756cgOp (LIntStr ity) [x] = do
762cgOp (LIntStr ity) [x] = do
757 x' <- unbox (FInt ity) x
763 x' <- unbox (FInt ity) x