Difference between revisions of "Toolchain"
m |
m |
||
Line 1: | Line 1: | ||
− | The nu+ toolchain is based on the LLVM project and includes a custom version of the [[Frontend | Clang frontend]] and a native [[Backend | nu+ backend]]. The nu+ linker is based on MCLinker. In addition, | + | The nu+ toolchain is based on the LLVM project and includes a custom version of the [[Frontend | Clang frontend]] and a native [[Backend | nu+ backend]]. The nu+ linker is based on MCLinker. In addition, nu+ comes with an ELFtoHEX tool that takes in input the ELF file and builds memory images that can be loaded into memory. |
− | == Requirements for | + | == Requirements for nu+ toolchain== |
* cmake (we tested cmake 3.7.2 downloaded from https://cmake.org/download/) | * cmake (we tested cmake 3.7.2 downloaded from https://cmake.org/download/) | ||
* flex (we tested flex 2.6.0 downloaded using the advanced packaging tool, i.e. apt-get) | * flex (we tested flex 2.6.0 downloaded using the advanced packaging tool, i.e. apt-get) | ||
Line 7: | Line 7: | ||
* libz-dev (downloaded using the advanced packaging tool, i.e. apt-get) | * libz-dev (downloaded using the advanced packaging tool, i.e. apt-get) | ||
− | == How to compile the the | + | == How to compile the the nu+ toolchain== |
To build the nu+ toolchain, you must launch '''./setup_new.sh -n''' from a terminal in the compiler root folder. The script will create a new directory called ''build'' and will start building the compiler. By default the script tries to build the compiler using '''4''' threads. If you want to modify that, especially if your machine have less than 8GB of RAM, you can use the '''-t''' flag to specify the number of threads to use. Other information can be obtained by using the '''-h''' flag. | To build the nu+ toolchain, you must launch '''./setup_new.sh -n''' from a terminal in the compiler root folder. The script will create a new directory called ''build'' and will start building the compiler. By default the script tries to build the compiler using '''4''' threads. If you want to modify that, especially if your machine have less than 8GB of RAM, you can use the '''-t''' flag to specify the number of threads to use. Other information can be obtained by using the '''-h''' flag. | ||
− | == How to compile a kernel for the | + | == How to compile a kernel for the nu+ architecture == |
− | Some kernels are provided with the standard release of the | + | Some kernels are provided with the standard release of the nu+ toolchain. We provide a makefile to compile these kernels for nu+. In case you want to add a new kernel, it is suggested to copy a kernel folder and replace C/C++ files with your own source code. Then, remember to modify the makefile updating the SRCS variable with the names of the C/C++ files you want to compile. When using these makefiles, different tools are called: |
* Clang to emit the LLVM IR and the object files | * Clang to emit the LLVM IR and the object files | ||
* MCLINKER to handle the job of linking | * MCLINKER to handle the job of linking | ||
Line 18: | Line 18: | ||
In order to change the optimization level of the compiler or any other flag, it is possible to modify the misc/NuPlus.mk (or misc/Makefile.nuplus if you are compiling a kernel for the [http://www.mango-project.eu/ MANGO project] ) makefile. | In order to change the optimization level of the compiler or any other flag, it is possible to modify the misc/NuPlus.mk (or misc/Makefile.nuplus if you are compiling a kernel for the [http://www.mango-project.eu/ MANGO project] ) makefile. | ||
− | == How to compile the libraries for the | + | == How to compile the libraries for the nu+ architecture == |
− | To compile the libraries you only have to execute '''./setup_new.sh -l''' from a terminal in the NuPlusLLVM root folder. The script will automatically build the libraries. Note that you must have compiled the | + | To compile the libraries you only have to execute '''./setup_new.sh -l''' from a terminal in the NuPlusLLVM root folder. The script will automatically build the libraries. Note that you must have compiled the nu+ compiler first. |
== The nu+ LLVM == | == The nu+ LLVM == | ||
− | The nu+ toolchain is based on the LLVM project and | + | The nu+ toolchain is based on the LLVM project and includes: |
# [[Frontend | A custom version of the Clang frontend]] | # [[Frontend | A custom version of the Clang frontend]] | ||
# [[Backend | A native nu+ backend]] | # [[Backend | A native nu+ backend]] | ||
Line 32: | Line 32: | ||
To test the code generation process, the [https://llvm.org/docs/TestingGuide.html LLVM testing infrastructure] has been used. | To test the code generation process, the [https://llvm.org/docs/TestingGuide.html LLVM testing infrastructure] has been used. | ||
− | The script "run_tests" can be used to run the nu+ testing suite. The main purpose is to perform regression | + | The script "run_tests" can be used to run the nu+ testing suite. The main purpose is to perform regression tests, so that it is possible to determine if a change in the back-end has any negative consequence. |
The tool used is the "llvm-lit", a python script that parses the test files and executes the testing commands. | The tool used is the "llvm-lit", a python script that parses the test files and executes the testing commands. | ||
− | The '''code generation tests''' are contained in "compiler/test/CodeGen/NuPlus" and cover the main LLVM IR operations. A code generation test file is a collection of | + | The '''code generation tests''' are contained in "compiler/test/CodeGen/NuPlus" and cover the main LLVM IR operations. A code generation test file is a collection of functions written in LLVM IR with commands directed to the llvm-lit and [https://llvm.org/docs/CommandGuide/FileCheck.html FileCheck] tools. These commands are written as comments. The main commands used are '''RUN''', '''CHECK''', and '''CHECK-LABEL'''. |
− | The '''RUN''' line tells lit how to run the test. If there are no RUN lines, lit will issue an error while running a test. The line syntax is similar to a shell’s syntax for pipelines. To examine output | + | The '''RUN''' line tells lit how to run the test. If there are no RUN lines, lit will issue an error while running a test. The line syntax is similar to a shell’s syntax for pipelines. To examine the output and check if the test has been passed, the FileCheck tool must be used. |
The RUN line used for all the tests is: | The RUN line used for all the tests is: | ||
Line 46: | Line 46: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | This tells lit to run '''llc''' with | + | This tells lit to run '''llc''' with nu+ architecture as target, to give the output file to the FileCheck tool. |
− | The '''CHECK_LABEL''' and the '''CHECK''' lines are interpreted by the FileCheck tool. It compares the llc output file with the '''CHECK_LABEL''' and '''CHECK''' lines. The comparison is done in sequence, although there are directives that let the checking in | + | The '''CHECK_LABEL''' and the '''CHECK''' lines are interpreted by the FileCheck tool. It compares the llc output file with the '''CHECK_LABEL''' and '''CHECK''' lines. The comparison is done in sequence, although there are directives that let the checking not be performed in sequential order, see [https://llvm.org/docs/CommandGuide/FileCheck.html] for further details. |
== Libraries == | == Libraries == | ||
− | + | nu+ is provided with different kind of libraries that are contained in the libs/ folder. For more information, check [[libraries|The nu+ libraries]] | |
== Makefiles and linker scripts == | == Makefiles and linker scripts == |
Revision as of 16:22, 4 June 2018
The nu+ toolchain is based on the LLVM project and includes a custom version of the Clang frontend and a native nu+ backend. The nu+ linker is based on MCLinker. In addition, nu+ comes with an ELFtoHEX tool that takes in input the ELF file and builds memory images that can be loaded into memory.
Contents
Requirements for nu+ toolchain
- cmake (we tested cmake 3.7.2 downloaded from https://cmake.org/download/)
- flex (we tested flex 2.6.0 downloaded using the advanced packaging tool, i.e. apt-get)
- bison (we tested bison 3.0.4 downloaded using the advanced packaging tool, i.e. apt-get)
- libz-dev (downloaded using the advanced packaging tool, i.e. apt-get)
How to compile the the nu+ toolchain
To build the nu+ toolchain, you must launch ./setup_new.sh -n from a terminal in the compiler root folder. The script will create a new directory called build and will start building the compiler. By default the script tries to build the compiler using 4 threads. If you want to modify that, especially if your machine have less than 8GB of RAM, you can use the -t flag to specify the number of threads to use. Other information can be obtained by using the -h flag.
How to compile a kernel for the nu+ architecture
Some kernels are provided with the standard release of the nu+ toolchain. We provide a makefile to compile these kernels for nu+. In case you want to add a new kernel, it is suggested to copy a kernel folder and replace C/C++ files with your own source code. Then, remember to modify the makefile updating the SRCS variable with the names of the C/C++ files you want to compile. When using these makefiles, different tools are called:
- Clang to emit the LLVM IR and the object files
- MCLINKER to handle the job of linking
- elf2hex to generate the HEX file from the ELF file
- llvm-objdump to generate the dump from the elf file
In order to change the optimization level of the compiler or any other flag, it is possible to modify the misc/NuPlus.mk (or misc/Makefile.nuplus if you are compiling a kernel for the MANGO project ) makefile.
How to compile the libraries for the nu+ architecture
To compile the libraries you only have to execute ./setup_new.sh -l from a terminal in the NuPlusLLVM root folder. The script will automatically build the libraries. Note that you must have compiled the nu+ compiler first.
The nu+ LLVM
The nu+ toolchain is based on the LLVM project and includes:
- A custom version of the Clang frontend
- A native nu+ backend
- Some external tools that are used by llvm, i.e. linker, disassembler, etc..
In addition, in order add the nu+ architecture inside llvm, a registration phase was required.
Testing
To test the code generation process, the LLVM testing infrastructure has been used.
The script "run_tests" can be used to run the nu+ testing suite. The main purpose is to perform regression tests, so that it is possible to determine if a change in the back-end has any negative consequence.
The tool used is the "llvm-lit", a python script that parses the test files and executes the testing commands.
The code generation tests are contained in "compiler/test/CodeGen/NuPlus" and cover the main LLVM IR operations. A code generation test file is a collection of functions written in LLVM IR with commands directed to the llvm-lit and FileCheck tools. These commands are written as comments. The main commands used are RUN, CHECK, and CHECK-LABEL.
The RUN line tells lit how to run the test. If there are no RUN lines, lit will issue an error while running a test. The line syntax is similar to a shell’s syntax for pipelines. To examine the output and check if the test has been passed, the FileCheck tool must be used.
The RUN line used for all the tests is:
; RUN: llc -march=nuplus < %s | FileCheck %s
This tells lit to run llc with nu+ architecture as target, to give the output file to the FileCheck tool.
The CHECK_LABEL and the CHECK lines are interpreted by the FileCheck tool. It compares the llc output file with the CHECK_LABEL and CHECK lines. The comparison is done in sequence, although there are directives that let the checking not be performed in sequential order, see [1] for further details.
Libraries
nu+ is provided with different kind of libraries that are contained in the libs/ folder. For more information, check The nu+ libraries