Difference between revisions of "Compiler"

From NaplesPU Documentation
Jump to: navigation, search
(Testing)
(Replaced content with "not more needed")
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
<strong>This is the main nu+ compiler documentation page</strong>
+
not more needed
 
 
== How to compile the Nu+ LLVM ==
 
To build the nu+ compiler, 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 NuPlus architecture ==
 
Some kernels are provided with the standard release of the NuPlus toolchain. We provide makefile to compile these kernels for NuPlus. In case you want to add a new kernel, it is suggested to copy a kernel folder and replace C/CPP files with your own source code. Then, remember to modify the makefile updating the SRCS variable with the current main C/CPP filename. When using these makefiles, different tools are called:
 
* Clang to emit the LLVM IR and the object files
 
* LLD/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 file.
 
 
 
== How to compile the libraries for the NuPlus 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 NuPlus compiler first.
 
 
 
== Backend for a custom target architecture ==
 
Adding a new target architecture, i.e. nu+, to llvm requires four steps:
 
* [[Backend|write all backend files and place them into the lib/Target/NuPlus folder]]
 
* [[Frontend|modify the Clang frontend]]
 
* [[How to add a new backend to llvm|register and add the new backend to llvm]]
 
* [[Tools|modify and/or add all the external tools that are used by llvm, i.e. linker, disassembler, etc..]]
 
 
 
== Testing ==
 
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 test, so that it is possible to determine if a change in the back-end has negative consequences.
 
 
 
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 function 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 to figure out if the test passes the FileCheck tool must be used.
 
 
 
The RUN line used for all the tests is:
 
 
 
<syntaxhighlight lang="c" line='line'>
 
; RUN: llc -march=nuplus < %s | FileCheck %s
 
</syntaxhighlight>
 
 
 
This tells lit to run '''llc''' with nuplus 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 not sequential order, see [https://llvm.org/docs/CommandGuide/FileCheck.html] for further informations.
 
 
 
== Compiler Extensions ==
 
* [[OpenCL|OpenCL extension for the nu+ architecture]]
 
* [[OpenMP|OpenMP extension for the nu+ architecture]]
 

Latest revision as of 19:26, 25 May 2018

not more needed