Implement "avvertite don ulrico" statement.

This commit is contained in:
Stefano Sanfilippo 2020-02-23 09:53:14 +01:00
parent 6c86720a1d
commit 5bd3ac2be5

View File

@ -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());