marsc – compiler for programs written in the Mars language
marsc [-o output-file] [--backend=backend] [-m name] [-h | --help] [--version] [mars-source-file]
marsc is the compiler for the Mars programming language. This command takes a single Mars program, and compiles it with a particular backend.
By default, Mars code is compiled into LLVM bitcode (.bc) files. With LLVM installed, these can be interpreted with lli or compiled into native executables using llc and clang. Other backends are primarily used for debugging.
Compile to the given output filename. If unspecified, the output filename will be based on the input filename, but with a different extension (depending on the backend).
Use a specific backend. This determines what format the output file will be in.
The default backend is llvm.
Backends available: pretty, asm, llvm.
Specify the name of the main function (program entrypoint). This names the function which will be executed upon program startup. It must have type () -> Num.
If unspecified, there will be no function called at startup, and the program will serve as a library only.
Perform uniqueness analysis and make certain operations destructive, where possible. This does not change the semantics; it is merely an optimisation. This makes use of functions like array_replace and array_concat use constant time in some cases, rather than linear time.
This is switched on by default. It can be disabled with -d- or --no-destructive.
Dump logs of any static analysis in HTML form to this directory. Note that this is for debugging purposes, and could generate a huge amount of data.
If unspecified, no logs will be dumped.
Used in conjunction with --dump-analysis. Dumps only the specified functions (given as a comma-separated list).
Display a short help page, then quit.
Display version and copyright information, then quit.
Compiling Mars programs into an executable is currently a bit laborious. marsc itself only outputs LLVM bitcode. You need to manually optimize the bitcode using opt, use llc to compile the output into native code, and use gcc or clang to link it into an executable.
Here is an example of compiling a single-module Mars program:
marsc -m main hello.mar
opt -std-compile-opts hello.bc -o hello-opt.bc
llc -filetype=obj hello-opt.bc -o hello.o
clang -o hello hello.o -lgc -lm
marsc will exit with a status of 1 if any fatal errors occur, including compiler errors or illegal main functions.
Otherwise, marsc will set its exit status to 0.
A list of known bugs is available at https://bugs.launchpad.net/mars/. Bugs should be reported using the link on that page.