mirror of
https://github.com/idris-lang/Idris2.git
synced 2025-01-03 00:55:00 +03:00
Split RefC CC functions into their own file
This commit is contained in:
parent
a538736d0c
commit
735b5bef98
@ -22,6 +22,7 @@ modules =
|
||||
Compiler.ES.RemoveUnused,
|
||||
Compiler.ES.TailRec,
|
||||
|
||||
Compiler.RefC.CC,
|
||||
Compiler.RefC.RefC,
|
||||
|
||||
Compiler.Scheme.Chez,
|
||||
|
65
src/Compiler/RefC/CC.idr
Normal file
65
src/Compiler/RefC/CC.idr
Normal file
@ -0,0 +1,65 @@
|
||||
module Compiler.RefC.CC
|
||||
|
||||
import Core.Context
|
||||
import Core.Options
|
||||
|
||||
import System
|
||||
|
||||
import Idris.Version
|
||||
import Libraries.Utils.Path
|
||||
|
||||
findCC : IO String
|
||||
findCC
|
||||
= do Nothing <- getEnv "IDRIS2_CC"
|
||||
| Just cc => pure cc
|
||||
Nothing <- getEnv "CC"
|
||||
| Just cc => pure cc
|
||||
pure "cc"
|
||||
|
||||
fullprefix_dir : Dirs -> String -> String
|
||||
fullprefix_dir dirs sub
|
||||
= prefix_dir dirs </> "idris2-" ++ showVersion False version </> sub
|
||||
|
||||
export
|
||||
compileCObjectFile : {auto c : Ref Ctxt Defs}
|
||||
-> (outn : String)
|
||||
-> (outobj : String)
|
||||
-> Core (Maybe String)
|
||||
compileCObjectFile outn outobj =
|
||||
do cc <- coreLift findCC
|
||||
dirs <- getDirs
|
||||
|
||||
let runccobj = cc ++ " -c " ++ outn ++ " -o " ++ outobj ++ " " ++
|
||||
"-I" ++ fullprefix_dir dirs "refc " ++
|
||||
"-I" ++ fullprefix_dir dirs "include"
|
||||
|
||||
coreLift $ putStrLn runccobj
|
||||
0 <- coreLift $ system runccobj
|
||||
| _ => pure Nothing
|
||||
|
||||
pure (Just outobj)
|
||||
|
||||
export
|
||||
compileCFile : {auto c : Ref Ctxt Defs}
|
||||
-> (outobj : String)
|
||||
-> (outexec : String)
|
||||
-> Core (Maybe String)
|
||||
compileCFile outobj outexec =
|
||||
do cc <- coreLift findCC
|
||||
dirs <- getDirs
|
||||
|
||||
let runcc = cc ++ " " ++ outobj ++ " -o " ++ outexec ++ " " ++
|
||||
fullprefix_dir dirs "lib" </> "libidris2_support.a" ++ " " ++
|
||||
"-lidris2_refc " ++
|
||||
"-L" ++ fullprefix_dir dirs "refc " ++
|
||||
clibdirs (lib_dirs dirs)
|
||||
|
||||
coreLift $ putStrLn runcc
|
||||
0 <- coreLift $ system runcc
|
||||
| _ => pure Nothing
|
||||
|
||||
pure (Just outexec)
|
||||
|
||||
where
|
||||
clibdirs : List String -> String
|
||||
clibdirs ds = concat (map (\d => "-L" ++ d ++ " ") ds)
|
@ -1,42 +1,26 @@
|
||||
module Compiler.RefC.RefC
|
||||
|
||||
import Compiler.RefC.CC
|
||||
|
||||
import Compiler.Common
|
||||
import Compiler.CompileExpr
|
||||
import Compiler.LambdaLift
|
||||
import Compiler.ANF
|
||||
import Compiler.Inline
|
||||
|
||||
import Core.Context
|
||||
import Core.Directory
|
||||
import Core.Name
|
||||
import Core.Options
|
||||
import Core.TT
|
||||
|
||||
import Data.IORef
|
||||
import Data.List
|
||||
import Libraries.Data.DList
|
||||
import Libraries.Data.NameMap
|
||||
import Data.Nat
|
||||
import Data.Strings
|
||||
import Data.Vect
|
||||
|
||||
import System
|
||||
import System.Info
|
||||
import System.File
|
||||
|
||||
import Idris.Env
|
||||
import Idris.Version
|
||||
import Libraries.Utils.Hex
|
||||
import Libraries.Utils.Path
|
||||
|
||||
findCC : IO String
|
||||
findCC
|
||||
= do Nothing <- idrisGetEnv "IDRIS2_CC"
|
||||
| Just cc => pure cc
|
||||
Nothing <- idrisGetEnv "CC"
|
||||
| Just cc => pure cc
|
||||
pure "cc"
|
||||
|
||||
showcCleanStringChar : Char -> String -> String
|
||||
showcCleanStringChar '+' = ("_plus" ++)
|
||||
showcCleanStringChar '-' = ("__" ++)
|
||||
@ -1043,10 +1027,6 @@ executeExpr c _ tm
|
||||
= do coreLift_ $ putStrLn "Execute expression not yet implemented for refc"
|
||||
coreLift_ $ system "false"
|
||||
|
||||
fullprefix_dir : Dirs -> String -> String
|
||||
fullprefix_dir dirs sub
|
||||
= prefix_dir dirs </> "idris2-" ++ showVersion False version </> sub
|
||||
|
||||
export
|
||||
generateCSourceFile : {auto c : Ref Ctxt Defs}
|
||||
-> List (Name, ANFDef)
|
||||
@ -1068,50 +1048,6 @@ generateCSourceFile defs outn =
|
||||
coreLift_ $ writeFile outn code
|
||||
coreLift_ $ putStrLn $ "Generated C file " ++ outn
|
||||
|
||||
export
|
||||
compileCObjectFile : {auto c : Ref Ctxt Defs}
|
||||
-> (outn : String)
|
||||
-> (outobj : String)
|
||||
-> Core (Maybe String)
|
||||
compileCObjectFile outn outobj =
|
||||
do cc <- coreLift findCC
|
||||
dirs <- getDirs
|
||||
|
||||
let runccobj = cc ++ " -c " ++ outn ++ " -o " ++ outobj ++ " " ++
|
||||
"-I" ++ fullprefix_dir dirs "refc " ++
|
||||
"-I" ++ fullprefix_dir dirs "include"
|
||||
|
||||
coreLift $ putStrLn runccobj
|
||||
0 <- coreLift $ system runccobj
|
||||
| _ => pure Nothing
|
||||
|
||||
pure (Just outobj)
|
||||
|
||||
export
|
||||
compileCFile : {auto c : Ref Ctxt Defs}
|
||||
-> (outobj : String)
|
||||
-> (outexec : String)
|
||||
-> Core (Maybe String)
|
||||
compileCFile outobj outexec =
|
||||
do cc <- coreLift findCC
|
||||
dirs <- getDirs
|
||||
|
||||
let runcc = cc ++ " " ++ outobj ++ " -o " ++ outexec ++ " " ++
|
||||
fullprefix_dir dirs "lib" </> "libidris2_support.a" ++ " " ++
|
||||
"-lidris2_refc " ++
|
||||
"-L" ++ fullprefix_dir dirs "refc " ++
|
||||
clibdirs (lib_dirs dirs)
|
||||
|
||||
coreLift $ putStrLn runcc
|
||||
0 <- coreLift $ system runcc
|
||||
| _ => pure Nothing
|
||||
|
||||
pure (Just outexec)
|
||||
|
||||
where
|
||||
clibdirs : List String -> String
|
||||
clibdirs ds = concat (map (\d => "-L" ++ d ++ " ") ds)
|
||||
|
||||
export
|
||||
compileExpr : UsePhase
|
||||
-> Ref Ctxt Defs
|
||||
|
Loading…
Reference in New Issue
Block a user