Refactor errors and update post draft.

This commit is contained in:
2020-09-11 21:29:49 -07:00
parent 725958137a
commit 6b8d3b0f8a
8 changed files with 431 additions and 42 deletions

View File

@@ -20,7 +20,7 @@
#include "llvm/Target/TargetMachine.h"
void yy::parser::error(const yy::location& loc, const std::string& msg) {
std::cout << "An error occured: " << msg << std::endl;
std::cerr << "An error occured: " << msg << std::endl;
}
void prelude_types(definition_group& defs, type_env_ptr env) {
@@ -110,12 +110,12 @@ void output_llvm(llvm_context& ctx, const std::string& filename) {
std::error_code ec;
llvm::raw_fd_ostream file(filename, ec, llvm::sys::fs::F_None);
if (ec) {
throw std::runtime_error("failed to open object file for writing");
throw compiler_error("failed to open object file for writing");
} else {
llvm::CodeGenFileType type = llvm::CGFT_ObjectFile;
llvm::legacy::PassManager pm;
if (targetMachine->addPassesToEmitFile(pm, file, NULL, type)) {
throw std::runtime_error("failed to add passes to pass manager");
throw compiler_error("failed to add passes to pass manager");
} else {
pm.run(ctx.module);
file.close();
@@ -177,10 +177,11 @@ void gen_llvm(global_scope& scope) {
int main(int argc, char** argv) {
if(argc != 2) {
std::cerr << "please enter a file to compile." << std::endl;
exit(1);
}
parse_driver driver(argv[1]);
if(!driver.run_parse()) {
std::cerr << "failed to open file " << argv[1] << std::endl;
std::cerr << "failed to parse file " << argv[1] << std::endl;
exit(1);
}
@@ -207,7 +208,7 @@ int main(int argc, char** argv) {
err.pretty_print(std::cerr, driver, mgr);
} catch(type_error& err) {
err.pretty_print(std::cerr, driver);
} catch(std::runtime_error& err) {
std::cerr << err.what() << std::endl;
} catch (compiler_error& err) {
err.pretty_print(std::cerr, driver);
}
}