2 Building Projects and Solutions
2.1 Build Command Syntax
cminor build [build-options] { SOLUTION.cminors | PROJECT.cminorp } | system
Builds each given solution and project, or builds system libraries.
2.2 Setting the Configuration
To use the debug configuration (default) give the following option:
--config=debug
To use the release configuration give the following option:
--config=release
For example, to build project examples/dc/dc.cminorp using the release configuration, give the following command:
> cminor build --config=release examples/dc/dc.cminorp
2.3 Compiling to Native Object Code
To compile a project to native object code give the following option:
--native
When compiling to native code, the compiler first compiles the given project to intermediate code and then converts the intermediate instructions to native code using
LLVM libraries. Compiling to native code generates DLL's on Windows and shared objects on Linux.
For example, to compile system libraries to native code using debug configuration, give the following command:
> cminor build --native system
2.3.1 Native Code Options
To set the optimization level use the following option:
--optimization-level=LEVEL
where LEVEL can be 0-3. Defaults are: 0 for debug configuration, 2 for release configuration.
To set the inline limit use the following option:
--inline-limit=LIMIT
where LIMIT is the number of intermediate instructions for a function to have to select it as an inline candidate.
Defaults are: 0 (no inlining) for optimization levels 0 and 1, 16 instructions for optimization level 2, and 32 instructions for optimization level 3.
Eventually LLVM will decide which functions to inline.
To set maximum number of locals an inline function will have, use the following option:
--inline-locals=NUMLOCALS
where NUMLOCALS is the number of locals. Defaults are: 0 (no inlining) for optimization levels 0 and 1, 4 locals for optimization level 2, and 8 locals for optimization level 3.
2.3.2 Native Code Debugging Options
To generate debug listing containing intermediate code functions and corresponding LLVM intermediate code functions, use the following option:
--list
For example, to compile project hello.cminorp to native code using debug configuration, and generate a listing give the following command:
> cminor build --native --list hello.cminorp
The following listing file will be generated to the assembly/debug directory:
MODULE hello : C:/Users/Seppo/cminor/examples/hello/assembly/debug/hello.cminora
target triple: x86_64-pc-windows-msvc
optimization level: 0
inline limit: 0 or fewer intermediate instructions (0 = no inlining)
inline locals: 0
before removing unreachable instructions:
FUNCTION #0
call name: main()
group name: main
full name: internal export System.Void main()
mangled name: main_entry_point
flags: exported canThrow
source file path: C:/Users/Seppo/cminor/examples/hello/hello.cminor
0 parameters:
0 locals:
returns: System.Void
code:
{
0 BC receive
1 F2 gcpoll
2 C3 enterblock
3 BA loadconstant.s 643
4 E3 slit2s
5 C0 call System.Console.WriteLine(System.String)
6 C4 exitblock
}
after removing unreachable instructions:
FUNCTION #0
call name: main()
group name: main
full name: internal export System.Void main()
mangled name: main_entry_point
flags: exported canThrow
source file path: C:/Users/Seppo/cminor/examples/hello/hello.cminor
0 parameters:
0 locals:
returns: System.Void
code:
{
0 BC receive
1 F2 gcpoll
2 C3 enterblock
3 BA loadconstant.s 643
4 E3 slit2s
5 C0 call System.Console.WriteLine(System.String)
6 C4 exitblock
}
; Function Attrs: norecurse uwtable
define dllexport void @main_entry_point() #0 {
entry:
%0 = alloca i64
%1 = alloca { i64* }
%2 = alloca { i8*, i8*, i32, i32, i64** }
store i64 0, i64* %0
%3 = getelementptr { i64* }, { i64* }* %1, i32 0, i32 0
store i64* %0, i64** %3
%4 = getelementptr { i8*, i8*, i32, i32, i64** }, { i8*, i8*, i32, i32, i64** }* %2, i32 0, i32 1
%5 = load i8*, i8** @__F0
store i8* %5, i8** %4
%6 = getelementptr { i8*, i8*, i32, i32, i64** }, { i8*, i8*, i32, i32, i64** }* %2, i32 0, i32 2
store i32 4, i32* %6
%7 = getelementptr { i8*, i8*, i32, i32, i64** }, { i8*, i8*, i32, i32, i64** }* %2, i32 0, i32 3
store i32 1, i32* %7
%8 = getelementptr { i8*, i8*, i32, i32, i64** }, { i8*, i8*, i32, i32, i64** }* %2, i32 0, i32 4
%9 = bitcast { i64* }* %1 to i64**
store i64** %9, i64*** %8
%10 = bitcast { i8*, i8*, i32, i32, i64** }* %2 to i8*
call void @RtEnterFunction(i8* %10)
call void @RtPollGc()
%11 = load i8*, i8** @__constant_pool
%12 = call i32* @RtLoadStringLiteral(i8* %11, i32 643)
%13 = call i64 @RtStrLitToString(i32* %12)
store i64 %13, i64* %0
%14 = getelementptr { i8*, i8*, i32, i32, i64** }, { i8*, i8*, i32, i32, i64** }* %2, i32 0, i32 2
store i32 5, i32* %14
call void @WriteLine_Console_BE58CCFEB8D919E3373B8B3AE9D44E04755263CE(i64 %13)
%15 = bitcast { i8*, i8*, i32, i32, i64** }* %2 to i8*
call void @RtLeaveFunction(i8* %15)
ret void
}
; Function Attrs: nounwind uwtable
define dllexport x86_64_win64cc i32 @DllMain(i8*, i64, i8*) #1 {
entry:
ret i32 1
}
To generate LLVM intermediate code to an .ll file, use the following option:
--emit-llvm
To generate optimized LLVM intermediate code to an .opt.ll file, use the following option:
--emit-opt-llvm
For example, to emit LLVM intermediate code and optimized LLVM intermediate code for project dc.cminorp for release configuration, use the following command:
> cminor build --native --config=release --emit-llvm --emit-opt-llvm dc.cminorp
The .ll files will be generated to the assembly/release directory.
To generate debug output for LLVM passes to stderr, use the following option:
--debug-pass=VALUE
where VALUE can be Arguments, Structure, Executions, or Details.
Arguments prints pass arguments, Structure prints pass structure before run(), Executions prints pass name before it is executed, and Details prints pass details when it is executed.
To generate LLVM debug output to stderr, use the following option:
--debug-llvm
2.4 Compiler Debugging Options
To run debug version of the compiler, give the following option:
--debug
To generate debugging output for parsing to stdout, give the following option:
--debug-parse