aboutsummaryrefslogtreecommitdiffstats
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/main.cpp b/main.cpp
index c70c976..fa1a242 100644
--- a/main.cpp
+++ b/main.cpp
@@ -59,7 +59,7 @@ TODO:
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
-#include <cstdio>
+#include <iostream>
#include <string>
#include "ast.hpp"
@@ -80,14 +80,26 @@ int main(int argc, const char *argv[])
auto block = llvm::BasicBlock::Create(state.context, "entry", func);
state.builder.SetInsertPoint(block);
- parser.parse(state);
+ auto astTree = parser.parse();
+ if (parser.hasErrors()) {
+ auto err = parser.describeErrors();
+ std::cout << "Error: " << std::endl << err << std::endl;
+ } else if (!astTree.empty()) {
+ for (auto& node : astTree) {
+ std::cout << node->desc() << std::endl;
- state.builder.CreateRet(state.builder.getInt32(0));
+ node->codegen(state);
+ }
- puts("");
- state.module.print(llvm::errs(), nullptr); // prints everything
+ state.builder.CreateRet(state.builder.getInt32(0));
- compileToObjectFile(state);
+ std::cout << std::endl;
+ state.module.print(llvm::errs(), nullptr); // prints everything
+
+ compileToObjectFile(state);
+ } else {
+ std::cout << "Nothing to do." << std::endl;
+ }
return 0;
}