Skip to content

Instantly share code, notes, and snippets.

@andrewrk
Created October 19, 2014 18:03
Show Gist options
  • Save andrewrk/1558b3a1c4dd1c130bbf to your computer and use it in GitHub Desktop.
Save andrewrk/1558b3a1c4dd1c130bbf to your computer and use it in GitHub Desktop.
clang -o test test.c -I/usr/lib/llvm-3.5/include -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -lLLVM-3.5
#include <stdio.h>
#include "llvm-c/Core.h"
int main(int argc, char *argv[]) {
LLVMBuilderRef builder = LLVMCreateBuilder();
LLVMModuleRef module = LLVMModuleCreateWithName("main_module");
LLVMTypeRef main_type = LLVMFunctionType(LLVMVoidType(), NULL, 0, 0);
LLVMValueRef main_fn = LLVMAddFunction(module, "main", main_type);
LLVMSetFunctionCallConv(main_fn, LLVMCCallConv);
char *module_string = LLVMPrintModuleToString(module);
puts(module_string);
LLVMDisposeMessage(module_string);
LLVMDisposeModule(module);
LLVMDisposeBuilder(builder);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment