hoppy-generator-0.8.0: C++ FFI generator - Code generator
Safe HaskellNone
LanguageHaskell2010

Foreign.Hoppy.Generator.Compiler

Description

Data types for compilers and functions for invoking them.

Synopsis

Typeclass

class Show a => Compiler a where Source #

A compiler that exists on the system for compiling C++ code.

Methods

compileProgram :: a -> FilePath -> FilePath -> IO Bool Source #

compileProgram compiler infile outfile invokes the given compiler in the input file, to produce the output file. If the compiler fails or can't be called for whatever reason, then an error message is printed to standard error, and false is returned.

prependIncludePath :: [FilePath] -> a -> a Source #

Modifies the compiler to prepend the given paths to the header search path.

data SomeCompiler Source #

An existential data type for Compilers.

Constructors

forall a.Compiler a => SomeCompiler a 

Data types

data SimpleCompiler Source #

A compiler that can compile a source file into a binary with a single program invocation.

Within the strings in this data type, including the program path, all occurences of {in} and {out} are expanded to the input and desired output files, respectively.

Constructors

SimpleCompiler 

Fields

  • scProgram :: FilePath

    The name of the compiler program to call. Lookup is subject to the regular search path rules of your operating system.

  • scArguments :: [String]

    Arguments to pass to the compiler. Each string is passed as a separate argument. No further word splitting is done.

prependArguments :: [String] -> SimpleCompiler -> SimpleCompiler Source #

Adds arguments to the start of a compiler's argument list.

appendArguments :: [String] -> SimpleCompiler -> SimpleCompiler Source #

Adds arguments to the end of a compiler's argument list.

overrideCompilerFromEnvironment :: SimpleCompiler -> IO SimpleCompiler Source #

Modifies a SimpleCompiler based on environment variables.

If CXX is set and non-empty, it will override the compiler's scProgram.

If CXXFLAGS is set and non-empty, it will be split into words and each word will be prepended as an argument to scArguments. Quoting is not supported.

data CustomCompiler Source #

A Compiler that allows plugging arbitary logic into the compilation process.

Constructors

CustomCompiler 

Fields

  • ccLabel :: String

    A label to display when the compiler is shown. The string is "<CustomCompiler " ++ label ++ ">".

  • ccCompile :: CustomCompiler -> FilePath -> FilePath -> IO Bool

    Given a source file path and an output path, compiles the source file, producing a binary at the output path. Returns true on success. Logs to standard error and returns false on failure.

    This should inspect the compiler argument to make use of its ccHeaderSearchPath.

    The first argument is the CustomCompiler object that this function was pulled out of. This is passed in explicitly by compileProgram because due to the presence of prependIncludePath it's not always possible to have access to the final compiler object ahead of time.

  • ccHeaderSearchPath :: [FilePath]

    Paths to be searched for C++ header files, in addition to the compiler's default search directories.

Standard compilers

defaultCompiler :: SimpleCompiler Source #

The default compiler, used by an Interface that doesn't specify its own. This will be gppCompiler, however if the environment variables CXX or CXXFLAGS are set and nonempty, they will be used. CXX will override the path to the compiler used, and CXXFLAGS will be split on spaces and appended to the compiler's argument list.

Specifically, this is defined as:

unsafePerformIO $ overrideCompilerFromEnvironment gppCompiler

gppCompiler :: SimpleCompiler Source #

The GNU C++ compiler, invoked as g++ -o {out} {in}.