Frontends

C3 frontend

This is the c3 language front end.

For the front-end a recursive descent parser is created.

digraph c3 {
rankdir="LR"
1 [label="source text"]
10 [label="lexer" ]
20 [label="parser" ]
40 [label="code generation"]
99 [label="IR-code object"]
1 -> 10
10 -> 20
20 -> 40
40 -> 99
}
class ppci.lang.c3.C3Builder(diag, arch_info)

Generates IR-code from c3 source.

Reports errors to the diagnostics system.

class ppci.lang.c3.Lexer(diag)

Generates a sequence of token from an input stream

class ppci.lang.c3.Parser(diag)

Parses sourcecode into an abstract syntax tree (AST)

class ppci.lang.c3.CodeGenerator(diag)

Generates intermediate (IR) code from a package.

The entry function is ‘genModule’. The main task of this part is to rewrite complex control structures, such as while and for loops into simple conditional jump statements. Also complex conditional statements are simplified. Such as ‘and’ and ‘or’ statements are rewritten in conditional jumps. And structured datatypes are rewritten.

Type checking is done in one run with code generation.

Brainfuck

The compiler has a front-end for the brainfuck language.

class ppci.lang.bf.BrainFuckGenerator(arch)

Brainfuck is a language that is so simple, the entire front-end can be implemented in one pass.

Fortran

This is the fortran frontend.

Currently this front-end is a work in progress.

class ppci.lang.fortran.FortranBuilder
class ppci.lang.fortran.parser.FortranParser

Parse some fortran language

Llvm

Front-end for the LLVM IR-code

This front-end can be used as an enabler for many other languages, for example ADA and C++.

Currently this module a work in progress. The first step is to parse the llvm assembly. The next phase would be to convert that into ppci ir.

Another nice idea is to generate llvm ir code from ppci. When generating and parsing are combined, the llvm optimizers can be used.

class ppci.lang.llvmir.frontend.LlvmIrFrontend
class ppci.lang.llvmir.parser.LlvmIrParser(context)

Recursive descent parser for llvm-ir

Closely modeled after LLParser.cpp at: https://github.com/llvm-mirror/llvm/blob/master/lib/AsmParser/LLParser.cpp

Example usage

An example usage is the following:

$ llvm-stress | ppci-llc.py -m riscv -o my_object.oj -

Here, the llvm-stress tool generates some random llvm source code, and this is piped into the ppci-llc.py command, which takes ll code and turns it into machine code.

Another example is how to use clang together with ppci-llc.py:

$ clang -S -emit-llvm -o - magic2.c | ppci-llc.py -o my_obj.oj -m msp430 -

This will compile the sourcefile magic2.c into my_obj.oj for the msp430 target.