@@ -143,6 +143,10 @@ initDefs tgt =
143 , exfun "mpz_init_set_ull" VoidType [pmpz, IntegerType 64] False
143 , exfun "mpz_init_set_ull" VoidType [pmpz, IntegerType 64] False
144 , exfun "mpz_init_set_sll" VoidType [pmpz, IntegerType 64] False
144 , exfun "mpz_init_set_sll" VoidType [pmpz, IntegerType 64] False
145 , exfun "__idris_strCons" ptrI8 [IntegerType 8, ptrI8] False
145 , exfun "__idris_strCons" ptrI8 [IntegerType 8, ptrI8] False
146+ , exfun "__idris_readStr" ptrI8 [ptrI8] False -- Actually pointer to FILE, but it's opaque anyway
147+ , exVar "stdin" ptrI8
148+ , exVar "stdout" ptrI8
149+ , exVar "stderr" ptrI8
146 , GlobalDefinition mainDef
150 , GlobalDefinition mainDef
147 ] ++ map mpzBinFun ["add", "sub", "mul", "fdiv_q", "fdiv_r", "and", "ior", "xor"]
151 ] ++ map mpzBinFun ["add", "sub", "mul", "fdiv_q", "fdiv_r", "and", "ior", "xor"]
@@ -169,6 +173,8 @@ initDefs tgt =
169 , G.name = Name name
173 , G.name = Name name
170 , G.parameters = (flip map argtys $ \ty -> Parameter ty (UnName 0) [], vari)
174 , G.parameters = (flip map argtys $ \ty -> Parameter ty (UnName 0) [], vari)
176+ exVar :: String -> Type -> Definition
177+ exVar name ty = GlobalDefinition $ globalVariableDefaults { G.name = Name name, G.type' = ty }
173codegen :: String -> [SDecl] -> Module
179codegen :: String -> [SDecl] -> Module
174codegen tgt defs = Module "idris" Nothing Nothing (initDefs tgt ++ globals ++ gendefs)
180codegen tgt defs = Module "idris" Nothing Nothing (initDefs tgt ++ globals ++ gendefs)
@@ -829,6 +835,22 @@ cgOp LStrTail [c] = do
829 c <- inst $ GetElementPtr True s [ConstantOperand $ C.Int 32 1] []
835 c <- inst $ GetElementPtr True s [ConstantOperand $ C.Int 32 1] []
830 box FString c
836 box FString c
838+cgOp LReadStr [p] = do
840+ s <- inst $ simpleCall "__idris_readStr" [np]
844+ ptr <- inst $ Load False (ConstantOperand . C.GlobalReference . Name $ "stdin") Nothing 0 []
847+ ptr <- inst $ Load False (ConstantOperand . C.GlobalReference . Name $ "stdout") Nothing 0 []
850+ ptr <- inst $ Load False (ConstantOperand . C.GlobalReference . Name $ "stderr") Nothing 0 []
832cgOp prim args = ierror $ "Unimplemented primitive: [" ++ show prim ++ "]("
854cgOp prim args = ierror $ "Unimplemented primitive: [" ++ show prim ++ "]("
833 ++ intersperse ',' (take (length args) ['a'..]) ++ ")"
855 ++ intersperse ',' (take (length args) ['a'..]) ++ ")"