summaryrefslogtreecommitdiff
path: root/willow/lib/IR/DiagnosticEngine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'willow/lib/IR/DiagnosticEngine.cpp')
-rw-r--r--willow/lib/IR/DiagnosticEngine.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/willow/lib/IR/DiagnosticEngine.cpp b/willow/lib/IR/DiagnosticEngine.cpp
new file mode 100644
index 0000000..f0cc280
--- /dev/null
+++ b/willow/lib/IR/DiagnosticEngine.cpp
@@ -0,0 +1,28 @@
+#include <willow/IR/DiagnosticEngine.h>
+
+namespace willow {
+
+void DiagnosticEngine::report(Diagnostic d) {
+ if (handler)
+ handler(std::move(d));
+}
+
+DiagnosticBuilder::DiagnosticBuilder(DiagnosticBuilder &&other) noexcept
+ : engine(std::exchange(other.engine, nullptr)), diag(std::move(other.diag)),
+ os(std::move(other.os)) {}
+DiagnosticBuilder::~DiagnosticBuilder() {
+ if (!engine) // was moved from
+ return;
+
+ diag.message += os.str();
+ engine->report(std::move(diag));
+}
+
+DiagnosticBuilder::DiagnosticBuilder(DiagnosticEngine &eng, Severity severity,
+ std::optional<Location> loc)
+ : engine(&eng) {
+ diag.severity = severity;
+ diag.location = loc;
+}
+
+} // namespace willow