Created
June 8, 2015 19:57
-
-
Save nasser/7e79f125452d91a7fcd0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; https://pauladamsmith.com/blog/2015/01/how-to-get-started-with-llvm-c-api.html | |
(import LLVM | |
LLVMModuleRef | |
LLVMTypeRef | |
Wrap) | |
(let [module (LLVM/ModuleCreateWithName "my_module") | |
params (into-array [(LLVM/Int32Type) (LLVM/Int32Type)]) | |
fntyp (LLVM/FunctionType (LLVM/Int32Type) params false) | |
sum (Wrap/AddFunction module "sum" fntyp) | |
entry (LLVM/AppendBasicBlock sum "entry") | |
builder (LLVM/CreateBuilder) | |
_ (LLVM/PositionBuilderAtEnd builder entry) | |
tmp (LLVM/BuildAdd builder | |
(LLVM/GetParam sum 0) | |
(LLVM/GetParam sum 1) | |
"tmp") | |
_ (LLVM/BuildRet builder tmp) | |
] | |
(LLVM/WriteBitcodeToFile module "sum.bc") | |
sum) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define i32 @sum(i32, i32) { | |
entry: | |
%tmp = add i32 %0, %1 | |
ret i32 %tmp | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment