Init LLVM/JIT stuff
This commit is contained in:
@@ -7,9 +7,9 @@ CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
|
|||||||
PROJECT (scully)
|
PROJECT (scully)
|
||||||
|
|
||||||
SET (SCULLY_VERSION_MAJOR 0)
|
SET (SCULLY_VERSION_MAJOR 0)
|
||||||
SET (SCULLY_VERSION_MINOR 1)
|
SET (SCULLY_VERSION_MINOR 2)
|
||||||
SET (SCULLY_VERSION_RELEASE 0)
|
SET (SCULLY_VERSION_RELEASE 0)
|
||||||
SET (SCULLY_VERSION_EXTRA "WoC Friday Night")
|
SET (SCULLY_VERSION_EXTRA "WoC Caturday")
|
||||||
|
|
||||||
SET (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/)
|
SET (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/)
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "AST/ASTElement.h"
|
#include "AST/ASTElement.h"
|
||||||
#include "AST/AssignmentExpression.h"
|
#include "AST/AssignmentExpression.h"
|
||||||
#include "AST/BinOpExpression.h"
|
#include "AST/BinOpExpression.h"
|
||||||
|
#include "AST/CodeGenVisitor.h"
|
||||||
#include "AST/ConstantExpression.h"
|
#include "AST/ConstantExpression.h"
|
||||||
#include "AST/Expression.h"
|
#include "AST/Expression.h"
|
||||||
#include "AST/ExpressionStatement.h"
|
#include "AST/ExpressionStatement.h"
|
||||||
@@ -29,11 +30,14 @@
|
|||||||
#include "AST/ValueList.h"
|
#include "AST/ValueList.h"
|
||||||
#include "AST/VariableDefinition.h"
|
#include "AST/VariableDefinition.h"
|
||||||
|
|
||||||
|
#include "llvm/Module.h"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%name scullyParser
|
%name scullyParser
|
||||||
|
|
||||||
%token_type {Token*}
|
%token_type {Token*}
|
||||||
|
%extra_argument{llvm::Module* mod}
|
||||||
|
|
||||||
// whitespace and comments
|
// whitespace and comments
|
||||||
%type T_WHITESPACE {int}
|
%type T_WHITESPACE {int}
|
||||||
|
|||||||
@@ -2,11 +2,8 @@
|
|||||||
#define CODEGENVISITOR_H
|
#define CODEGENVISITOR_H
|
||||||
|
|
||||||
#include "ASTVisitor.h"
|
#include "ASTVisitor.h"
|
||||||
#include "llvm/DerivedTypes.h"
|
|
||||||
#include "llvm/IRBuilder.h"
|
#include "llvm/IRBuilder.h"
|
||||||
#include "llvm/LLVMContext.h"
|
#include <map>
|
||||||
#include "llvm/Module.h"
|
|
||||||
#include "llvm/Analysis/Verifier.h"
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class CodeGenVisitor : public ASTVisitor {
|
class CodeGenVisitor : public ASTVisitor {
|
||||||
@@ -31,6 +28,8 @@ public:
|
|||||||
virtual void visit(ValueList* e);
|
virtual void visit(ValueList* e);
|
||||||
virtual void visit(VariableDefinition* e);
|
virtual void visit(VariableDefinition* e);
|
||||||
private:
|
private:
|
||||||
|
llvm::IRBuilder<>* builder_;
|
||||||
|
std::map<std::string, llvm::Value*> namedValues_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CODEGENVISITOR_H
|
#endif // CODEGENVISITOR_H
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "AST/CodeGenVisitor.h"
|
#include "AST/CodeGenVisitor.h"
|
||||||
|
|
||||||
CodeGenVisitor::CodeGenVisitor() {
|
CodeGenVisitor::CodeGenVisitor() {
|
||||||
//
|
builder_ = new llvm::IRBuilder<>(llvm::getGlobalContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeGenVisitor::~CodeGenVisitor() {
|
CodeGenVisitor::~CodeGenVisitor() {
|
||||||
|
|||||||
49
src/test.cpp
49
src/test.cpp
@@ -6,6 +6,19 @@
|
|||||||
|
|
||||||
#include "Token.h"
|
#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
|
// this file is auto generated from grammar/grammar.y
|
||||||
#include "grammar.h"
|
#include "grammar.h"
|
||||||
|
|
||||||
@@ -59,7 +72,37 @@ int main() {
|
|||||||
lexertl::generator::build(rules, state_machine);
|
lexertl::generator::build(rules, state_machine);
|
||||||
state_machine.minimise();
|
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);
|
void* parser = scullyParserAlloc(malloc);
|
||||||
|
|
||||||
@@ -81,9 +124,11 @@ int main() {
|
|||||||
std::string s(results.start, results.end);
|
std::string s(results.start, results.end);
|
||||||
if (results.id != T_WHITESPACE) {
|
if (results.id != T_WHITESPACE) {
|
||||||
std::cout << "Id: " << results.id << ", Token: " << s << std::endl;
|
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);
|
} while (results.id != 0);
|
||||||
|
|
||||||
|
module->dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
scullyParserFree(parser, free);
|
scullyParserFree(parser, free);
|
||||||
|
|||||||
Reference in New Issue
Block a user