-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Roadmap #1
Labels
Comments
Another project https://github.com/episcopus2001/kaleidoscope ? |
First exampleThis C example code has been used #include <stdio.h>
#include <stdlib.h>
#include "llvm-c/Core.h"
#include "llvm-c/ExecutionEngine.h"
#include "llvm-c/Target.h"
int main() {
// Initialize LLVM
LLVMInitializeNativeTarget();
LLVMInitializeNativeAsmPrinter();
LLVMInitializeNativeAsmParser();
// Create a new LLVM module
LLVMModuleRef module = LLVMModuleCreateWithName("sum_module");
// Create a function that computes the sum of two integers
LLVMTypeRef params[] = { LLVMInt32Type(), LLVMInt32Type() };
LLVMTypeRef func_type = LLVMFunctionType(LLVMInt32Type(), params, 2, 0);
LLVMValueRef sum_func = LLVMAddFunction(module, "sum", func_type);
LLVMBasicBlockRef entry = LLVMAppendBasicBlock(sum_func, "entry");
LLVMBuilderRef builder = LLVMCreateBuilder();
LLVMPositionBuilderAtEnd(builder, entry);
LLVMValueRef arg1 = LLVMGetParam(sum_func, 0);
LLVMValueRef arg2 = LLVMGetParam(sum_func, 1);
LLVMValueRef sum = LLVMBuildAdd(builder, arg1, arg2, "sum");
LLVMBuildRet(builder, sum);
// Dump the LLVM module to stdout
LLVMDumpModule(module);
// Clean up LLVM resources
LLVMDisposeBuilder(builder);
LLVMDisposeModule(module);
LLVMShutdown();
return 0;
} llvm-zig/examples/sum_module.zig Lines 7 to 37 in dd08598
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Initially, the LLVM 16 binding is being ported, which may later be extended to older versions for greater compatibility.
Based on the references in the readme will include some examples from the official LLVM-doc tutorial.
Note: Although the project is using the name Kaleidoscope tutorial. Nothing prevents the (
llvm-kaleidoscope-zig
->llvm-zig
) binding from being renamed for practical purposes other than educational purposes only.Contributions are always welcome!!
The text was updated successfully, but these errors were encountered: