Code Monkey home page Code Monkey logo

toycompiler's Introduction

Toy Compiler

整体设计

前端

整体采用go语言实现,前端使用lex+goyacc,生成ast,然后从ast翻译成LLVM IR。

后端

后端直接LLVM将LLVM IR编译为机器码。

进度

理论

看了一部分哈工大网课,熟悉基本词法语法分析知识。优化参考中科大网课,CFG学习参考龙书(TODO)

实验

已实现词法语法分析,能够生成LLVM IR,大体满足C0文法(太麻烦了

符号表、AST设计、interface多态等具体实现等参考代码

具体的测试用例在test/toylang_test文件夹中

  • variable
    • int
    • double
    • char
    • array
      • one dimension
      • more
  • declare
    • with init
    • without init
  • if
  • while
  • function
    • define
    • call
    • recurse
  • print
  • scan
  • const(global)

优化

参考LLVM CookBook,测试了dead code emit, early-cse等前端优化,未来加入寄存器相关使用llc的后端优化。

优化的测试用例在test/ssa_test, 还有很多TODO

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.