forked from ph7n2ofui/SysyCompiler_Arm
parent
308bcac3fa
commit
1f0928a443
@ -0,0 +1,15 @@
|
||||
#include <sstream>
|
||||
using namespace std;
|
||||
#include "Diagnostic.h"
|
||||
|
||||
namespace sysy {
|
||||
|
||||
Diagnostic error(antlr4::ParserRuleContext *ctx, const std::string &msg) {
|
||||
auto line = ctx->start->getLine();
|
||||
auto col = ctx->start->getCharPositionInLine();
|
||||
ostringstream ss;
|
||||
ss << line << ':' << col << ": error " << msg << '\n';
|
||||
return Diagnostic(ss.str());
|
||||
}
|
||||
|
||||
} // namespace sysy
|
||||
@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "antlr4-runtime.h"
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace sysy {
|
||||
|
||||
class Diagnostic {
|
||||
private:
|
||||
const std::string message;
|
||||
|
||||
public:
|
||||
Diagnostic(const std::string &message) : message(message) {}
|
||||
Diagnostic(std::string &&message) : message(std::move(message)) {}
|
||||
Diagnostic(const Diagnostic &) = default;
|
||||
Diagnostic(Diagnostic &&) = default;
|
||||
|
||||
public:
|
||||
~Diagnostic() {
|
||||
if (not message.empty()) {
|
||||
std::cerr << message << '\n';
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}; // class Diagnostic
|
||||
|
||||
Diagnostic error(antlr4::ParserRuleContext *ctx, const std::string &msg);
|
||||
|
||||
} // namespace sysy
|
||||
@ -0,0 +1,7 @@
|
||||
//test add
|
||||
int main(){
|
||||
int a, b;
|
||||
a = 10;
|
||||
b = 0;
|
||||
return a + b;
|
||||
}
|
||||
Loading…
Reference in new issue