Skip to content

ArachnidAbby/Intro-To-codegen-with-llvmlite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction to Codegen with llvmlite

This is a small introduction to how an AST would use llvmlite to generate llvm-ir (llir).

This is technically turing complete (I think). It is missing features a language would likely want.

There are of course several TODO/exercise comments left in the code as challenges for the reader.

This was shared on the Compilers and Interpreters discord server on 01/06/2024 (M/D/Y) If you see this before that date, come join us to learn more!

Requirements

  • python 3.11.x (uses a 3.11 features + a feature that was removed in 3.12)
  • pip (do pip install -r requirements.txt)

Things not included here

These things are intentionally not included in this example.

  • Lexing
  • Parsing
  • Emitting to a file
  • Identified Struct types
  • "Advanced" llvm instructions like gep or phi
  • Type checking (there is only 1 type present)
  • Optimization passes
  • JIT / the execution engine
  • Emiting object file
  • Linking (to create an executable)

Instructions covered

  • icmp (>, <, & ==. != also kind-of used)
  • alloca
  • store
  • ret (but not ret void)
  • load
  • br (cbranch and branch)
  • add
  • sub
  • mul
  • sdiv
  • zext
  • Function definition
  • Creating blocks & positioning.
  • Doing all allocations at the start of a function.
  • An extremely basic Type system that includes 1 type.

Additional resources.

Reuse of this code

If you wish to reuse this code, you may do so. The only thing I ask is that you credit me on your project's readme or wherever it makes sense to add the attribution.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published