How to read serialized diagnostics in Swift

By setting the -serialize-diagnostics-path option to the compiler, I can get a binary file containing serialized diagnostics. I would like to programmatically process the content using Swift code, but don't know where to start.

I tried reading lib/Frontend/SerializedDiagnosticConsumer.cpp in order to find the data written to the diagnostics file. I somewhat understand what is in the output, but I can't figure out the structure of it. I'm quite bad at reading C++. :(

Could someone point me to the right direction and help me understand it?

.dia files use the LLVM bitstream container format, which is described here:

swiftdeps files also use the bitstream format, so swift-tools-support core recently got support for reading it, you can check out Bitstream.swift in TSCUtility. TSCUtility also has SerializedDiagnostics.swift which builds on it to read the diagnostics format, but that part isn’t as widely used yet so might not be as reliable.

Terms of Service

Privacy Policy

Cookie Policy