Created
June 29, 2013 00:28
-
-
Save arcanis/5889108 to your computer and use it in GitHub Desktop.
LLVM emscripting
This file contains hidden or 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
--enable-optimized | |
--disable-polly | |
--disable-clang-arcmt | |
--disable-clang-static-analyzer | |
--disable-clang-rewriter | |
--disable-assertions | |
--disable-debug-symbols | |
--disable-jit | |
--disable-docs | |
--disable-threads | |
--disable-pthreads | |
--disable-zlib | |
--disable-pic | |
--disable-timestamps | |
--disable-stacktraces | |
--enable-target=x86 |
This file contains hidden or 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
#ifndef CHAR_BIT | |
# define CHAR_BIT __CHAR_BIT__ | |
#endif | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <llvm/ExecutionEngine/ExecutionEngine.h> | |
#include <llvm/ExecutionEngine/GenericValue.h> | |
#include <llvm/ExecutionEngine/Interpreter.h> | |
#include <llvm/IR/BasicBlock.h> | |
#include <llvm/IR/Constants.h> | |
#include <llvm/IR/Function.h> | |
#include <llvm/IR/IRBuilder.h> | |
#include <llvm/IR/LLVMContext.h> | |
#include <llvm/IR/Module.h> | |
#include <llvm/IR/Type.h> | |
#include <llvm/Support/TargetSelect.h> | |
int main( void ) { | |
llvm::InitializeNativeTarget(); | |
llvm::LLVMContext context; | |
llvm::Module module("foo", context); | |
llvm::Type * dbl = llvm::Type::getDoubleTy(context); | |
llvm::FunctionType * type = llvm::FunctionType::get(dbl, std::vector<llvm::Type*>(), false); | |
llvm::Function * fn = llvm::Function::Create(type, llvm::Function::ExternalLinkage, "fn", &module); | |
llvm::BasicBlock * bb = llvm::BasicBlock::Create(context, "entry", fn); | |
llvm::IRBuilder<> builder(bb); | |
builder.CreateRet(llvm::ConstantFP::get(dbl, 42.0)); | |
llvm::ExecutionEngine * engine = llvm::EngineBuilder(&module).setEngineKind(llvm::EngineKind::Interpreter).create(); | |
std::cout << engine->runFunction(fn, std::vector<llvm::GenericValue>()).DoubleVal << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment