LLVMSwift is a set of Swifty API wrappers for the LLVM C API. It makes compiler development feel great from Swift!

Usage

To start emitting IR, you’ll want to create a Module object, with an optional Context parameter, and an IRBuilder that will build instructions for that module.

let module = Module(name: "main")
let builder = IRBuilder(module: module)Copy the code

Once you do that, you can start adding functions, global variables, and generating instructions!

let main = builder.addFunction(name: "main".type: FunctionType(argTypes: [].returnType: VoidType())
let entry = builder.appendBasicBlock(named: "entry")
builder.positionAtEnd(of: entry)

builder.buildRetVoid()

module.dump(a)Copy the code

The IRBuilder class has methods for almost all functions from the LLVM C API, like:

  • builder.buildAdd
  • builder.buildSub
  • builder.buildMul
  • builder.buildCondBr
  • builder.addSwitch

and so many more.

Plus, it provides common wrappers around oft-used types like Function, Global, Switch, and PhiNode.

Authors

License

This project is released under the MIT license, a copy of which is available in this repo.