Error: Add a throw_error variant to report compiler bugs :)
This commit is contained in:
parent
a0945e54b2
commit
179294a91a
@ -1,10 +1,14 @@
|
||||
#include "MulNode.h"
|
||||
#include "../IRBuilder.h"
|
||||
#include "../Error.h"
|
||||
|
||||
MulNode::MulNode(std::shared_ptr<ExprNode> left, std::shared_ptr<ExprNode> right, char op)
|
||||
: BinaryOpNode(left, right), op(op)
|
||||
{
|
||||
assert(op == '*' || op == '/');
|
||||
if(op != '*' && op != '/')
|
||||
{
|
||||
Error::throw_error(CURRENT_LOCATION, "BUG: MulNode expects op to be either * or /");
|
||||
}
|
||||
}
|
||||
|
||||
MulNode::~MulNode()
|
||||
@ -20,7 +24,6 @@ llvm::Value* MulNode::codegen(IRBuilder* generator)
|
||||
case '/':
|
||||
return generator->getBuilder()->CreateSDiv(left->codegen(generator), right->codegen(generator));
|
||||
default:
|
||||
assert(0 && "unreachable");
|
||||
return nullptr;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
@ -1,10 +1,14 @@
|
||||
#include "SumNode.h"
|
||||
#include "../IRBuilder.h"
|
||||
#include "../Error.h"
|
||||
|
||||
SumNode::SumNode(std::shared_ptr<ExprNode> left, std::shared_ptr<ExprNode> right, char op)
|
||||
: BinaryOpNode(left, right), op(op)
|
||||
{
|
||||
assert(op == '+' || op == '-');
|
||||
if(op != '+' && op != '-')
|
||||
{
|
||||
Error::throw_error(CURRENT_LOCATION, "BUG: SumNode expects op to be either + or -");
|
||||
}
|
||||
}
|
||||
|
||||
SumNode::~SumNode()
|
||||
@ -20,7 +24,6 @@ llvm::Value* SumNode::codegen(IRBuilder* generator)
|
||||
case '-':
|
||||
return generator->getBuilder()->CreateSub(left->codegen(generator), right->codegen(generator));
|
||||
default:
|
||||
assert(0 && "unreachable");
|
||||
return nullptr;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
@ -72,6 +72,23 @@ void Error::show_import_lines(const Location& loc, void (*import_line_printer)(c
|
||||
exit(1);
|
||||
}
|
||||
|
||||
[[noreturn]] void Error::throw_error(const Location& loc, const std::string& details)
|
||||
{
|
||||
std::cerr << "\033[1;1m";
|
||||
std::cerr << loc.str();
|
||||
|
||||
std::cerr << ": ";
|
||||
|
||||
std::cerr << "\033[31;49m";
|
||||
std::cerr << "error: ";
|
||||
|
||||
std::cerr << "\033[0;0m";
|
||||
std::cerr << details;
|
||||
std::cerr << std::endl;
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
[[noreturn]] void Error::throw_error_without_location(const std::string& details)
|
||||
{
|
||||
std::cerr << "\033[1;1m";
|
||||
|
@ -7,6 +7,8 @@ void show_import_line(const Location& loc, std::ostream& output_stream);
|
||||
|
||||
[[noreturn]] void throw_error(const Location& loc, const std::string line_text, const std::string& details);
|
||||
|
||||
[[noreturn]] void throw_error(const Location& loc, const std::string& details);
|
||||
|
||||
[[noreturn]] void throw_error_without_location(const std::string& details);
|
||||
|
||||
void throw_warning(const Location& loc, const std::string line_text, const std::string& details);
|
||||
|
@ -36,3 +36,5 @@ struct Location
|
||||
/* Returns a copy of the original Location. */
|
||||
static Location copy(const Location& other);
|
||||
};
|
||||
|
||||
#define CURRENT_LOCATION (Location {__LINE__, 0, __FILE__})
|
Loading…
Reference in New Issue
Block a user