Merge pull request #766 from mokshasoft/gambit-cg

Gambit cg
This commit is contained in:
Edwin Brady 2020-12-04 15:51:22 +00:00 committed by GitHub
commit bfea7d785a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 3 deletions

View File

@ -66,3 +66,23 @@ Gambit Directives
.. code-block::
$ idris2 --codegen chez --directive extraRuntime=/path/to/extensions.scm -o main Main.idr
* ``--directive C``
Compile to C.
Gambit Environment Configurations
=================================
* ``GAMBIT_GSC_BACKEND``
The ``GAMBIT_GSC_BACKEND`` variable controls which C compiler Gambit will use during compilation. E.g. to use clang:
::
$ export GAMBIT_GSC_BACKEND=clang
Gambit after version v4.9.3 supports the ``-cc`` option, which configures
the compiler backend Gambit will use to build the binary. Currently to
get this functionality Gambit needs to be built from source, since it is
not yet available in a released version.

View File

@ -38,6 +38,13 @@ findGSC =
do env <- getEnv "GAMBIT_GSC"
pure $ fromMaybe "/usr/bin/env gsc" env
findGSCBackend : IO String
findGSCBackend =
do env <- getEnv "GAMBIT_GSC_BACKEND"
pure $ case env of
Nothing => ""
Just e => " -cc " ++ e
schHeader : String
schHeader = "; @generated\n
(declare (block)
@ -387,9 +394,15 @@ compileExpr c tmpDir outputDir tm outfile
libsname <- compileToSCM c tm srcPath
libsfile <- traverse findLibraryFile $ map (<.> "a") (nub libsname)
gsc <- coreLift findGSC
let cmd = gsc ++
" -exe -cc-options \"-Wno-implicit-function-declaration\" -ld-options \"" ++
(showSep " " libsfile) ++ "\" -o \"" ++ execPath ++ "\" \"" ++ srcPath ++ "\""
gscBackend <- coreLift findGSCBackend
ds <- getDirectives Gambit
let gscCompileOpts =
case find (== "C") ds of
Nothing => gscBackend ++ " -exe -cc-options \"-Wno-implicit-function-declaration\" -ld-options \"" ++
(showSep " " libsfile) ++ "\""
Just _ => " -c"
let cmd =
gsc ++ gscCompileOpts ++ " -o \"" ++ execPath ++ "\" \"" ++ srcPath ++ "\""
ok <- coreLift $ system cmd
if ok == 0
then pure (Just execPath)