Giter VIP home page Giter VIP logo

mrjp-latte's Introduction

latte

Features

The compiler supports the complete Latte language including arrays. LLVM IR and x86_64 backends are available.

Optimisations

The code is transformed to SSA first. The following optimisations are applied:

  • removal of unreachable blocks,
  • removal of unused assignments,
  • removal of unreachable instructions inside blocks,
  • copy propagation (thanks to transformation to SSA),
  • compile time calculation of constant expressions,
  • removal of trivial phi instructions.

Register allocation

x86_64 backend stores commonly used values in processor registers. The implemented algorithm bases on SSA. Interference graph of SSA registers is built and coloured. Registers with the same colour are assigned to the same register or address in memory.

Moreover, if a function argument is passed by register and register allocation algorithm decides to keep it in register (rather than on the stack), it will preserve its original register. Similarly, if a function argument is passed on stack and the algorithm decides to keep it in memory, the argument's colour is granted the argument's place in memory.

Before function calls, all caller preserved registers are backed up on stack and restored after the called function returns.

Design

Library functions

lattelib.c defines library functions and auxiliary builtins like string concatenation.

Name mangling

Functions (apart from main) are appended a prefix latte_, so that they do not conflict with functions from the standard library.

Project structure

The following files are of particular interest:

  • CompileLatte - translates Latte AST to LLVM,
  • CompilerErr - listing of possible compiler errors,
  • CompilerState - monads used in the compiler,
  • LLVM - definition of LLVM IR AST and pretty printing,
  • TransLLVM - transformations on LLVM including optimisations and mem2reg algorithm.
  • X86_64 - translates LLVM to x86_64.

Moreover, lattelib.c contains Latte library functions like printInt.

mrjp-latte's People

Contributors

mluszczyk avatar

Watchers

James Cloos avatar  avatar Krzysztof Pszeniczny avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.