Files
scriptc/native/llvm-codegen/src/diagnostics.cpp
Chris Tate 401338f437 feat(compiler): add native LLVM object emission (#242)
* feat(compiler): add native LLVM object emission

- ship the pinned macOS arm64 LLVM helper and platform package
- add assembly/object CLI outputs, caching, diagnostics, and runtime ABI checks
- validate helper artifacts through CI, packaging, docs, and differential coverage

* fix(compiler): harden native LLVM emission

* fix(compiler): harden LLVM helper packaging

* fix(compiler): stabilize LLVM helper package size

* fix(compiler): harden native helper validation

* fix(compiler): harden LLVM helper verification

* fix(compiler): harden native object emission
2026-08-27 10:30:40 -05:00

45 lines
1.1 KiB
C++

#include "diagnostics.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/JSON.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdlib>
using namespace llvm;
namespace scriptc {
int reportError(StringRef Code, const Twine &Message,
StringRef DiagnosticFormat) {
if (DiagnosticFormat == "json") {
json::Object Diagnostic{
{"ok", false},
{"code", Code},
{"message", Message.str()},
};
errs() << formatv("{0}\n", json::Value(std::move(Diagnostic)));
} else {
errs() << "scriptc-llvm-codegen: " << Message << '\n';
}
return 1;
}
static void fatalDiagnostic(void *, const char *Reason, bool) {
json::Object Diagnostic{
{"ok", false},
{"code", "llvm_fatal"},
{"message", Reason == nullptr ? "LLVM reported a fatal error" : Reason},
};
errs() << formatv("{0}\n", json::Value(std::move(Diagnostic)));
errs().flush();
std::_Exit(70);
}
void installFatalDiagnosticHandler() {
install_fatal_error_handler(fatalDiagnostic, nullptr);
}
} // namespace scriptc