3 Hello World in Cminor
Here's the contents of hello.cminor:
And here's the contents of the project file hello.cminorp:
3.1 Building the Project
Besides to intermediate code, Cminor programs can also be compiled to native object code by using the --native switch:
> cminor build --native hello.cminorp
3.2 Running the Hello World Program
Programs compiled to native object code can be run either by interpreting the intermediate instructions:
> cminor run assembly/debug/hello.cminora
Hello, world!
or by executing native object code in the virtual machine by giving the --native switch to the run command:
> cminor run --native assembly/debug/hello.cminora
Hello, world!
Executing large programs by interpreting the intermediate instructions takes about twice as long as executing the native object code with runtime support.
3.3 Inspecting the Contents of an Assembly
Cminor assembly file contains intermediate representation of compiled functions, a constant pool, a hierarchical symbol table and
mappings between native and intermediate functions.
To inspect the contents of an assembly file,
we use the cminor dump command.
By giving --header switch we can print general information about an assembly:
> cminor dump --header assembly/debug/hello.cminora hello.header
> type hello.header
ASSEMBLY HEADER
assembly name: hello
assembly format: 1
assembly flags: native
original file path: C:/Users/Seppo/cminor/doc/code/hello/assembly/debug/hello.cminora
file path read from: C:/Users/Seppo/cminor/doc/code/hello/assembly/debug/hello.cminora
native target triple: x86_64-pc-windows-msvc
native shared library file name: hello.dll
native import library file name: hello.lib
...
By giving the --functions switch we can print just the function table:
> cminor dump --functions assembly/debug/hello.cminora hello.functions
> type hello.functions
FUNCTION TABLE
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/doc/code/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
}