Fix all the tidy issues on src
This commit is contained in:
parent
737226dbae
commit
55e0788bae
|
@ -32,11 +32,12 @@
|
||||||
#include <llvm/ADT/StringRef.h>
|
#include <llvm/ADT/StringRef.h>
|
||||||
#include <llvm/IR/LLVMContext.h>
|
#include <llvm/IR/LLVMContext.h>
|
||||||
#include <llvm/Support/Host.h>
|
#include <llvm/Support/Host.h>
|
||||||
#include <memory>
|
|
||||||
#include <mlir/Dialect/StandardOps/IR/Ops.h>
|
#include <mlir/Dialect/StandardOps/IR/Ops.h>
|
||||||
#include <mlir/IR/MLIRContext.h>
|
#include <mlir/IR/MLIRContext.h>
|
||||||
#include <mlir/Pass/PassManager.h>
|
#include <mlir/Pass/PassManager.h>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace serene {
|
namespace serene {
|
||||||
|
|
||||||
namespace reader {
|
namespace reader {
|
||||||
|
@ -153,6 +154,9 @@ private:
|
||||||
/// process to store the state
|
/// process to store the state
|
||||||
SERENE_EXPORT std::unique_ptr<SereneContext> makeSereneContext();
|
SERENE_EXPORT std::unique_ptr<SereneContext> makeSereneContext();
|
||||||
|
|
||||||
}; // namespace serene
|
/// Terminates the serene compiler process in a thread safe manner
|
||||||
|
SERENE_EXPORT void terminate(SereneContext &ctx, int exitCode);
|
||||||
|
|
||||||
|
} // namespace serene
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "serene/slir/generatable.h"
|
#include "serene/slir/generatable.h"
|
||||||
|
|
||||||
#include <llvm/Support/FormatVariadic.h>
|
#include <llvm/Support/FormatVariadic.h>
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace serene {
|
namespace serene {
|
||||||
|
@ -100,6 +101,15 @@ NSPtr SereneContext::readNamespace(std::string name,
|
||||||
return sourceManager.readNamespace(*this, std::move(name), loc);
|
return sourceManager.readNamespace(*this, std::move(name), loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void terminate(SereneContext &ctx, int exitCode) {
|
||||||
|
UNUSED(ctx);
|
||||||
|
// TODO: Since we are running in a single thread for now using exit is fine
|
||||||
|
// but we need to adjust and change it to a thread safe termination
|
||||||
|
// process later on.
|
||||||
|
// NOLINTNEXTLINE(concurrency-mt-unsafe)
|
||||||
|
std::exit(exitCode);
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<SereneContext> makeSereneContext() {
|
std::unique_ptr<SereneContext> makeSereneContext() {
|
||||||
return std::make_unique<SereneContext>();
|
return std::make_unique<SereneContext>();
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <llvm/Support/FormatVariadic.h>
|
#include <llvm/Support/FormatVariadic.h>
|
||||||
#include <llvm/Support/WithColor.h>
|
#include <llvm/Support/WithColor.h>
|
||||||
#include <llvm/Support/raw_ostream.h>
|
#include <llvm/Support/raw_ostream.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace serene {
|
namespace serene {
|
||||||
|
@ -57,7 +58,7 @@ void Diagnostic::writeColorByType(llvm::raw_ostream &os, llvm::StringRef str) {
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string Diagnostic::getPrefix(llvm::StringRef prefix) {
|
std::string Diagnostic::getPrefix(llvm::StringRef prefix) {
|
||||||
if (prefix != "") {
|
if (!prefix.empty()) {
|
||||||
return prefix.str();
|
return prefix.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,8 +105,8 @@ void Diagnostic::print(llvm::raw_ostream &os, llvm::StringRef prefix) {
|
||||||
|
|
||||||
s << "\n\n";
|
s << "\n\n";
|
||||||
|
|
||||||
auto &srcBuf = ctx.sourceManager.getBufferInfo(loc.start.ns);
|
const auto &srcBuf = ctx.sourceManager.getBufferInfo(loc.start.ns);
|
||||||
const char *line = srcBuf.getPointerForLineNumber(loc.start.line);
|
const char *line = srcBuf.getPointerForLineNumber(loc.start.line);
|
||||||
|
|
||||||
while (*line != '\n' && line != srcBuf.buffer->getBufferEnd()) {
|
while (*line != '\n' && line != srcBuf.buffer->getBufferEnd()) {
|
||||||
s << *line;
|
s << *line;
|
||||||
|
@ -121,25 +122,25 @@ void Diagnostic::print(llvm::raw_ostream &os, llvm::StringRef prefix) {
|
||||||
s << '\n';
|
s << '\n';
|
||||||
|
|
||||||
s << "[";
|
s << "[";
|
||||||
if (err) {
|
if (err != nullptr) {
|
||||||
writeColorByType(os, err->getErrId());
|
writeColorByType(os, err->getErrId());
|
||||||
}
|
}
|
||||||
s << "] ";
|
s << "] ";
|
||||||
writeColorByType(os, getPrefix(prefix));
|
writeColorByType(os, getPrefix(prefix));
|
||||||
s << ": ";
|
s << ": ";
|
||||||
|
|
||||||
if (err) {
|
if (err != nullptr) {
|
||||||
s << err->description << '\n';
|
s << err->description << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message != "") {
|
if (!message.empty()) {
|
||||||
s.changeColor(llvm::raw_ostream::Colors::YELLOW);
|
s.changeColor(llvm::raw_ostream::Colors::YELLOW);
|
||||||
s << "With message";
|
s << "With message";
|
||||||
s.resetColor();
|
s.resetColor();
|
||||||
s << ": " << message << "\n";
|
s << ": " << message << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err) {
|
if (err != nullptr) {
|
||||||
s << "For more information checkout";
|
s << "For more information checkout";
|
||||||
s.changeColor(llvm::raw_ostream::Colors::CYAN);
|
s.changeColor(llvm::raw_ostream::Colors::CYAN);
|
||||||
s << " `serenec --explain ";
|
s << " `serenec --explain ";
|
||||||
|
@ -151,6 +152,7 @@ DiagnosticEngine::DiagnosticEngine(SereneContext &ctx)
|
||||||
: ctx(ctx), diagEngine(ctx.mlirContext.getDiagEngine()){};
|
: ctx(ctx), diagEngine(ctx.mlirContext.getDiagEngine()){};
|
||||||
|
|
||||||
void DiagnosticEngine::print(llvm::raw_ostream &os, Diagnostic &d) {
|
void DiagnosticEngine::print(llvm::raw_ostream &os, Diagnostic &d) {
|
||||||
|
UNUSED(ctx);
|
||||||
UNUSED(os);
|
UNUSED(os);
|
||||||
UNUSED(d);
|
UNUSED(d);
|
||||||
};
|
};
|
||||||
|
@ -165,7 +167,7 @@ Diagnostic DiagnosticEngine::toDiagnostic(reader::LocationRange loc,
|
||||||
|
|
||||||
void DiagnosticEngine::enqueueError(llvm::StringRef msg) {
|
void DiagnosticEngine::enqueueError(llvm::StringRef msg) {
|
||||||
llvm::errs() << llvm::formatv("FIX ME (better emit error): {0}\n", msg);
|
llvm::errs() << llvm::formatv("FIX ME (better emit error): {0}\n", msg);
|
||||||
exit(1);
|
terminate(ctx, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
void DiagnosticEngine::emitSyntaxError(reader::LocationRange loc,
|
void DiagnosticEngine::emitSyntaxError(reader::LocationRange loc,
|
||||||
|
@ -174,7 +176,7 @@ void DiagnosticEngine::emitSyntaxError(reader::LocationRange loc,
|
||||||
Diagnostic diag(ctx, loc, &e, msg);
|
Diagnostic diag(ctx, loc, &e, msg);
|
||||||
|
|
||||||
diag.print(llvm::errs(), "SyntaxError");
|
diag.print(llvm::errs(), "SyntaxError");
|
||||||
exit(1);
|
terminate(ctx, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
void DiagnosticEngine::panic(llvm::StringRef msg) {
|
void DiagnosticEngine::panic(llvm::StringRef msg) {
|
||||||
|
@ -194,7 +196,7 @@ void DiagnosticEngine::panic(llvm::StringRef msg) {
|
||||||
|
|
||||||
s << msg << "\n";
|
s << msg << "\n";
|
||||||
// TODO: Use a proper error code
|
// TODO: Use a proper error code
|
||||||
std::exit(1);
|
terminate(ctx, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<DiagnosticEngine> makeDiagnosticEngine(SereneContext &ctx) {
|
std::unique_ptr<DiagnosticEngine> makeDiagnosticEngine(SereneContext &ctx) {
|
||||||
|
|
|
@ -91,7 +91,7 @@ FnOpLowering::matchAndRewrite(serene::slir::FnOp op,
|
||||||
|
|
||||||
llvm::SmallVector<mlir::Type, 4> arg_types;
|
llvm::SmallVector<mlir::Type, 4> arg_types;
|
||||||
|
|
||||||
for (auto &arg : args) {
|
for (const auto &arg : args) {
|
||||||
auto attr = std::get<1>(arg).dyn_cast<mlir::TypeAttr>();
|
auto attr = std::get<1>(arg).dyn_cast<mlir::TypeAttr>();
|
||||||
|
|
||||||
if (!attr) {
|
if (!attr) {
|
||||||
|
|
|
@ -167,7 +167,7 @@ exprs::Node Reader::readNumber(bool neg) {
|
||||||
|
|
||||||
if (isdigit(*c) == 0) {
|
if (isdigit(*c) == 0) {
|
||||||
ctx.diagEngine->emitSyntaxError(loc, errors::InvalidDigitForNumber);
|
ctx.diagEngine->emitSyntaxError(loc, errors::InvalidDigitForNumber);
|
||||||
exit(1);
|
terminate(ctx, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -179,7 +179,7 @@ exprs::Node Reader::readNumber(bool neg) {
|
||||||
if (*c == '.' && floatNum) {
|
if (*c == '.' && floatNum) {
|
||||||
loc = LocationRange(getCurrentLocation());
|
loc = LocationRange(getCurrentLocation());
|
||||||
ctx.diagEngine->emitSyntaxError(loc, errors::TwoFloatPoints);
|
ctx.diagEngine->emitSyntaxError(loc, errors::TwoFloatPoints);
|
||||||
exit(1);
|
terminate(ctx, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*c == '.') {
|
if (*c == '.') {
|
||||||
|
@ -196,7 +196,7 @@ exprs::Node Reader::readNumber(bool neg) {
|
||||||
advance();
|
advance();
|
||||||
loc.start = getCurrentLocation();
|
loc.start = getCurrentLocation();
|
||||||
ctx.diagEngine->emitSyntaxError(loc, errors::InvalidDigitForNumber);
|
ctx.diagEngine->emitSyntaxError(loc, errors::InvalidDigitForNumber);
|
||||||
exit(1);
|
terminate(ctx, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
loc.end = getCurrentLocation();
|
loc.end = getCurrentLocation();
|
||||||
|
@ -222,7 +222,7 @@ exprs::Node Reader::readSymbol() {
|
||||||
|
|
||||||
ctx.diagEngine->emitSyntaxError(loc, errors::InvalidCharacterForSymbol,
|
ctx.diagEngine->emitSyntaxError(loc, errors::InvalidCharacterForSymbol,
|
||||||
msg);
|
msg);
|
||||||
exit(1);
|
terminate(ctx, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*c == '-') {
|
if (*c == '-') {
|
||||||
|
@ -280,7 +280,7 @@ exprs::Node Reader::readList() {
|
||||||
list->location.end = getCurrentLocation();
|
list->location.end = getCurrentLocation();
|
||||||
ctx.diagEngine->emitSyntaxError(list->location,
|
ctx.diagEngine->emitSyntaxError(list->location,
|
||||||
errors::EOFWhileScaningAList);
|
errors::EOFWhileScaningAList);
|
||||||
exit(1);
|
terminate(ctx, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (*c) {
|
switch (*c) {
|
||||||
|
|
Loading…
Reference in New Issue