Skip to content

Instantly share code, notes, and snippets.

@arcanis
Created June 29, 2013 00:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arcanis/5889108 to your computer and use it in GitHub Desktop.
Save arcanis/5889108 to your computer and use it in GitHub Desktop.
LLVM emscripting
--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
#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