diff --git a/src/codegen.cpp b/src/codegen.cpp index 61f4e20..3d685fd 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -102,6 +102,7 @@ public: llvm::Value* visitLoopStatement(const LoopStatement* l); llvm::Value* visitInputStatement(const InputStatement* s); llvm::Value* visitPrintStatement(const PrintStatement* p); + llvm::Value* visitAbortStatement(const AbortStatement* a); llvm::Value* visitExpressionStatement(const ExpressionStatement* s) { visit(s->getExpression()); return nullptr; @@ -166,6 +167,8 @@ llvm::Value* NestedScopes::lookup(const std::string& name) { } void IRGenerator::declareBuiltins() { + module_->getOrInsertFunction("abort", llvm::FunctionType::get(builder_.getVoidTy(), false)); + llvm::FunctionType* printf_type = llvm::FunctionType::get(builder_.getInt32Ty(), {builder_.getInt8PtrTy()}, true); auto no_alias = llvm::AttributeList().addAttribute(context_, 1, llvm::Attribute::NoAlias); @@ -535,6 +538,13 @@ llvm::Value* IRGenerator::visitPrintStatement(const PrintStatement* p) { return nullptr; } +llvm::Value* IRGenerator::visitAbortStatement(const AbortStatement*) { + auto abort_builtin = module_->getFunction("abort"); + assert(abort_builtin && "Builtin abort was not declared"); + builder_.CreateCall(abort_builtin); + return nullptr; +} + llvm::Value* IRGenerator::visitBinaryExpression(const BinaryExpression* e) { auto lhs = visit(e->getLeft()); auto rhs = visit(e->getRight());