marsc

marsc – compiler for programs written in the Mars language

Synopsis

marsc [-o output-file] [--backend=backend] [-m name] [-h | --help] [--version] [mars-source-file]

Description

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.

Options

-o output-file

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).

--backend=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.

-m name

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.

-d, --destructive

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-analysis = dir

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.

--dump-funcs = a,b,...

Used in conjunction with --dump-analysis. Dumps only the specified functions (given as a comma-separated list).

-h, --help

Display a short help page, then quit.

--version

Display version and copyright information, then quit.

Compiling an executable

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

Exit status

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.

Environment

MARSPATH

Colon-separated list of paths to search for Mars source files. Searched when the import statement is used to import Mars modules.

Bugs

A list of known bugs is available at https://bugs.launchpad.net/mars/. Bugs should be reported using the link on that page.

Table Of Contents

Previous topic

mars

Next topic

Mars Language Reference

This Page