Git Product home page Git Product logo

compiler-playground's Introduction

Compiler Playground

The goal of this project is to play around with various compilation techniques. Real languages tend to be very complex and their compilers then have to deal with a lot of complexity. Here, I am trying to keep the language simple. Various features can be gradually added, but only if:

  • they are necessary for the experiment I am working on at the moment or
  • I want to implement them as an exercise :)

Language

The goal here is NOT a language design, at least not at the moment. There is nothing really special about the language right now. It is a fairly minimal subset of C with:

  • only integer types
  • basic arithmetic operations
  • if and for statements
  • functions
  • no semicolons :)

Current status

I've implemented enough infrastructure to parse the fibonacci example into AST, transform it to lower level IR and interpret it. Now I am considering what to do next.

Next steps

  • IR - Transform the AST into more low level IR on which basic optimization passes can be implemented.
  • IR interpreter - Write an interpreter for the IR - mainly for performance comparisons with other forms of interpretation/compilation. And also for fun :) I could of course do an AST interepreter, but I've already implemented some in the past, so I would rather try something new.
  • Control flow analysis - Extract basic blocks and create control-flow-graphs. Will be useful both for optimizations and visualizations.
  • Graph visualizations for the CFG
  • Introduce optimization passes.
  • Constant propagation inside basic blocks
  • Assert statement/call. Mainly to verify test programs without having to diff their stdout.
  • More test programs to verify the current infrastructure (and extend/fix if necessary).
  • Create the backend - generate real assembly
  • Extend the backend to support all programs in the test suite.
  • Data-flow analysis
  • SSA form
  • Figure out how to output and debug optimization passes so that the output does not get out of hands.
  • Bytecode interpreter - Once there is a low level IR which is executable, the next logical step seems to be a bytecode interpreter. I'm interested in the performance differences compared to the IR interpreter.
  • Semantic analysis - At least differentiate void and int functions.
  • Basic arrays algorithms
    • Find min
    • Selection sort
    • Quicksort

Other Ideas and Side Tasks

  • Support for constants directly in the IR. The extra variables like $i = 1 just for $j = $k + $i are not necessary make the code longer
  • Get rid of unnecessary NOT ops before conditionals. Conditionals can be inverted instead.
  • Restructure main and provide proper option handling for various modes of the compiler.
  • Command line build command and launcher.
  • Implement removal of variables with zero usages (no data flow necessary).
  • Propagate constants with single definitions (again no data flow necessary).
  • Support for measuring performance.
  • Clear and formalize the representation for values for interpreters
  • Nicer error reporting, ideally showing the code the threw failed.
  • Design and implement appropriate testing infrastructure that would help you fix bugs and prevent from regressions. But make sure it is as loosely coupled with the actual compiler and language as possible, because anything from internal representation all the way to the syntax can change.
  • Support for arrays. Once arrays are in place, basic algorithms can be written as test programs :)
  • AST interpreter - I've already implemented some, so it is not a priority at the moment. I'd rather focused on later stages of compilation.
  • Minimize the amount of boolean instructions for comparisons. Currently, I have all of them, but it is of course not necessary. I could choose a minimal subset and convert the others to it.

compiler-playground's People

Contributors

d-kozak avatar

Watchers

 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.