Skip to content

A Compiler for the C/Java oriented Programming Language Snips that ouputs ARM Assembly.

License

NotificationsYou must be signed in to change notification settings

PhilipJonasFranz/SnipsCompilerGen2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Snips Compiler Gen.2 versionstatus

sizesize

Some words in advance

This project was started for educational purposes. The programming language Snips, the Compiler and all included modules are not following any standards and are built to function well only for this project. Results produced by the compiler and included modules may contain errors and are not thought for any production environment. The project and all its included modules are still under development and are subject to change.

Contents

What is Snips?

Short introduction

Snips is a lightweight C/Java oriented programming language. This brings familiar programming concepts to the table, like functions, conditionals, loops, arrays, references, global variables and a wide roster of built in operators. Also, more advanced features like imports, interfaces, structs, polymorphism, templating, heap functionality, namespaces, exception handling, predicates and inline assembly are supported.

Snips is mainly a procedural language, but through interfaces, struct polymorphism and struct nesting, an object-oriented programming style can be achieved.

Currently supported data types are:

  • Primitive types : int, bool, char, float
  • Custom types : interface, struct, enum
  • Special types : func, proviso, void, auto

as well as pointers and arrays of said types. Structs can be created capsuling fields of any type. The Void Type can be used as a type wildcard. Provisos act as a special, dynamic type that can take the shape of any other type. The can f.E. be used to re-use the same struct with different field types. Also, functions can pass and receive proviso types, allowing them to handle various types.

Some of the core features of Snips are shown in this little code example below:

struct X<T> {
    T val;
  
    T get() {
        return self->val;
    }
  
    /* Construct a new struct instance */
    static X<T> create<T>(T val) {
        return X<T>::(val);
    }
}
  
int main() {
    // Push the struct on the heap and create a pointer
    X<int>* x = init<>(X::create<int>(12));
    return (x->get<>() == 12)? 25 : 5;
}

You can find more information about the language in the Snips Language Guide. For a more in-depth guide and information about the included libraries, see Full Documentation.

The compiler

The compiler pipeline consists out of these stages:

  • Reading the code to compile
  • Pre Processing and resolving static imports
  • Scanning the code and converting it into a token stream
  • Parsing the token stream, creating an AST
  • Processing dynamic imports
  • Context checking and creating the DAST
  • Linter, spot potential problems with rule-based static code analysis (Optional)
  • AST Optimizer, rule-based AST transformations (Optional)
  • Code Generation, create list of Assembly instructions
  • Assembly Optimizer, rule-based optimizations (Optional)
  • Linker, resolves assembly imports of output (Optional)

The compiler uses a built-in System Library, located at release/lib.

The compiler will output ARM Assembly. See ARM Instruction Set for more information.

Usage and Setup

Running the compiler executable

The compiler executable can be run with snips [Path to file] ARGS. The possible arguments can be found below:

ArgumentFunctionalityDefault Value
-helpPrint argument listfalse
-infoPrint compiler versionfalse
-logPrint log in consolefalse
-comRemove comments from outputfalse
-lntEnable the linter pipeline stagefalse
-warnDisable warnings in consolefalse
-impPrint out imported librariesfalse
-optDisable all optimizersfalse
-opt0Disable AST optimizerfalse
-opt1Disable ASM optimizerfalse
-ofsOptimize for filesizefalse
-rovIgnore errors from modifiersfalse
-sidDisable Struct IDsfalse
-immPrint out immediate datafalse
-vizDisable ANSI colors in logfalse
-OBuild the object file only, do not link outputfalse
-rRecursively re-compile all included modulesfalse
-RSame as -r, but prune all existing module dumpsfalse
-LLink given program, requires input to be .s filefalse
-F [Args]Pass Pre-Processor directive flags[]
-o [Path]Specify output pathDirectory of input

Running the code

If you want to run the code, you can run either the CompilerDriver.java with the same arguments as up below, or you can run the TestDriver.java. This will run all the tests and verify the correct functionality of the compiler. The Arguments here are either a path to a file name, f.E.res/Test/Arith/Static/test_00.txt or a list of directories, f.E. res/Test/Arith/ res/Test/Stack/.

Code Examples, Tests

Code Examples can be found under release/examples, Testcases can be found under res/Test/.

Included Modules

Assembler

Under src/REv/Modules/RAsm/ you can find an Assembler that is used by the test driver to assemble the outputted program and run it on the SWARM32Pc. The Assembler will work with the code that the Compiler outputs, but it does not fully support all instructions and does not follow any compilation conventions. I do not recommend to use it anywhere else than in combination with this project.

SWARM32Pc

Under src/REv/CPU/ you can find a Virtual Machine, which implements a subset of the ARM Instruction Set. Again, this is used to test the output of the Compiler. Since the processor does not support all instructions i would not recommend to use it somewhere else. Supported instructions are:

  • b, bl, bx
  • All data processing operations
  • mrs, msr
  • mul, mla
  • ldr, str
  • ldm, stm

Additionally, a VFP-Coprocessor can handle floating point arithmetic.

All instructions do support the condition field. If you compile your assembly code with the Assembler mentioned up below you can be sure for it to work since the Assembler roughly implements the feature set of the Processor.

XML-Parser

Uses my XML-Parser implementation which can be found here: XML-Parser.

Utility

Under src/REv/Modules/Tools/Util.java you can find some Utility Functions for binary arithmetic, as well as File-I/O and a method that sets up the Processor with a provided configuration file. This is used by the TestDriver.java to set up the runtime environment.

Known Issues

  • Merging Header file with implementation discards global variables and imports from implementation file

License and Copyright

© Philip Jonas Franz

Licensed under Apache License 2.0.

About

A Compiler for the C/Java oriented Programming Language Snips that ouputs ARM Assembly.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages