1 Star 0 Fork 0

舞叶枫/PlayWithCompiler

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
PlayScript.cpp 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
Richard Gong 提交于 2019-08-04 19:40 +08:00 . added JIT feature.
#include <iostream>
#include "antlr4-runtime.h"
#include "PlayScriptLexer.h"
#include "PlayScriptParser.h"
#include "IRGen.h"
#include "ASTEvaluator.h"
#include "PlayScriptJIT.h"
using namespace play;
using namespace antlr4;
int main(int, const char **) {
InitializeNativeTarget();
InitializeNativeTargetAsmPrinter();
InitializeNativeTargetAsmParser();
//ANTLRInputStream input("double a = 3.0; double foo(double x, double y){return x + y + 2.0;}; foo(3.0, 6.0); a+10.0;");
ANTLRInputStream input("double foo(double x) { return (1.0+2.0+x)*(x+(1.0+2.0));} foo(3.0);");
PlayScriptLexer lexer(&input);
CommonTokenStream tokens(&lexer);
tokens.fill();
for (auto token : tokens.getTokens()) {
std::cout << token->toString() << std::endl;
}
PlayScriptParser parser(&tokens);
tree::ParseTree *tree = parser.prog();
std::cout << tree->toStringTree(&parser) << std::endl;
//ASTEvaluator astEvaluator;
//astEvaluator.visit(tree);
IRGen irGen;
// TheJIT = llvm::make_unique<PlayScriptJIT>();
irGen.InitializeModuleAndPassManager();
// std::unique_ptr<PlayScriptJIT> TheJIT;
// DataLayout dl = TheJIT->getTargetMachine().createDataLayout();
// TheModule->setDataLayout(dl);
irGen.visit(tree);
irGen.PrintIR();
irGen.ExecuteJIT();
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LinkSystem/PlayWithCompiler.git
git@gitee.com:LinkSystem/PlayWithCompiler.git
LinkSystem
PlayWithCompiler
PlayWithCompiler
master

搜索帮助