Init LLVM/JIT stuff

This commit is contained in:
Markus Hauschild
2013-06-01 14:29:18 +02:00
parent f0d0d6ec11
commit 9731b93a83
5 changed files with 57 additions and 9 deletions

View File

@@ -1,7 +1,7 @@
#include "AST/CodeGenVisitor.h"
CodeGenVisitor::CodeGenVisitor() {
//
builder_ = new llvm::IRBuilder<>(llvm::getGlobalContext());
}
CodeGenVisitor::~CodeGenVisitor() {

View File

@@ -6,6 +6,19 @@
#include "Token.h"
#include "llvm/DerivedTypes.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/IRBuilder.h"
#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/PassManager.h"
#include "llvm/Analysis/Verifier.h"
#include "llvm/Analysis/Passes.h"
#include "llvm/DataLayout.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Support/TargetSelect.h"
// this file is auto generated from grammar/grammar.y
#include "grammar.h"
@@ -59,7 +72,37 @@ int main() {
lexertl::generator::build(rules, state_machine);
state_machine.minimise();
std::cout << "The scully programming language v0.1" << std::endl;
std::cout << "The scully programming language v0.2" << std::endl;
// Setup LLVM JIT
llvm::InitializeNativeTarget();
llvm::Module* module = new llvm::Module("SCULLY/JIT", llvm::getGlobalContext());
std::string errStr;
llvm::ExecutionEngine* ee = llvm::EngineBuilder(module).setErrorStr(&errStr).create();
if (!ee) {
std::cerr << "Error creating Execution Engine: " << errStr << std::endl;
return 1;
}
// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
llvm::FunctionPassManager* fpm = new llvm::FunctionPassManager(module);
fpm->add(new llvm::DataLayout(*ee->getDataLayout()));
// Provide basic AliasAnalysis support for GVN.
fpm->add(llvm::createBasicAliasAnalysisPass());
// Do simple "peephole" optimizations and bit-twiddling optzns.
fpm->add(llvm::createInstructionCombiningPass());
// Reassociate expressions.
fpm->add(llvm::createReassociatePass());
// Eliminate Common SubExpressions.
fpm->add(llvm::createGVNPass());
// Simplify the control flow graph (deleting unreachable blocks, etc).
fpm->add(llvm::createCFGSimplificationPass());
fpm->doInitialization();
void* parser = scullyParserAlloc(malloc);
@@ -81,9 +124,11 @@ int main() {
std::string s(results.start, results.end);
if (results.id != T_WHITESPACE) {
std::cout << "Id: " << results.id << ", Token: " << s << std::endl;
scullyParser(parser, results.id, new Token(s));
scullyParser(parser, results.id, new Token(s), module);
}
} while (results.id != 0);
module->dump();
}
scullyParserFree(parser, free);