Skip to content

The Latte compiler translates Latte language files into LLVM; Latte is an imperative programming language closely resembling a subset of Java's imperative features.

Notifications You must be signed in to change notification settings

MarcinBrojek/mrjp-latte

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MRJP - Latte compiler

The Latte compiler is implemented in Haskell and translates Latte language files into LLVM intermediate representation (IR). Latte is an imperative programming language, closely resembling a subset of the imperative features of Java. For a detailed definition of Latte, refer to the MRJP course page https://www.mimuw.edu.pl/~ben/Zajecia/Mrj2021/Latte/.

Project structure:

  • README.md (this)
  • Makefile
  • src/
    • file with gramma: Latte.cf
    • files generated by BNFC: AbsLatte.hs, LexLatte.hs, ParLatte.hs, ErrM.hs
    • module with helper functions for stream: StreamHelper.hs
    • type checker module: TypeChecker.hs
    • llvm compiler module: LLVMCompiler.hs
    • main modules: TCMain.hs, LLVMMain.hs
  • lib/
    • predefined functions in runtime.(ext)- bc, ll, c

where BNFC files were generated with commands:

> bnfc --functor -m Latte.cf
> alex --ghc LexLatte.x 
> happy --ghc --coerce --array --info ParLatte.y

How to run?

1. Make your own lib - runtime (in lib directory)

  • create runtime.ll from runtime.c
clang -emit-llvm -S runtime.c -o runtime.ll
  • create runtime.bc from runtime.ll
llvm-as runtime.ll

2. Build latc and latc_llvm using:

make

3. Import tests

  • Import tests (lattests directory) from MRJP labs into main directory.

4. (Use specific test) Simple case

Running latc (in main directory, runs type checker):

> ./latc foo/bar/baz.lat

in return we get ERROR / OK answer in stderr,
if ERROR there is additonal line with information about its location in latte code


Running latc_llvm (in main directory, runs compiller with type checker):

> ./latc_llvm foo/bar/baz.lat

creates files baz.ll and baz.bc

4. (Alternative) Run script from Makefile - for chossen tests

For type checker:

make latc_tests

For compiller:

make latc_llvm_tests

Progress in following iterations:

  1. First iteration - frontend, type checker
  2. Second iteration - backend (base) in LLVM
  3. Third iteration - latte extensions:
    • registers and phi (2)
    • optimisations: LCSE (3)
    • extensions: arrays, structures, objects (6)

Used technology (versions)

  • xcode-select version 2408.
  • The GHCup Haskell installer, version 0.1.30.0
  • The Glorious Glasgow Haskell Compilation System, version 9.10.1
  • Homebrew clang version 17.0.6
  • Homebrew LLVM version 17.0.6
  • bnfc 2.9.4
  • Alex version 3.2.7.1, (c) 2003 Chris Dornan and Simon Marlow
  • Happy Version 1.20.0 Copyright (c) 1993-1996 Andy Gill, Simon Marlow (c) 1997-2005 Simon Marlow

About

The Latte compiler translates Latte language files into LLVM; Latte is an imperative programming language closely resembling a subset of Java's imperative features.

Topics

Resources

Stars

Watchers

Forks

Languages