|
|
@@ -400,7 +400,7 @@ auto Driver::Compile(const CompileOptions& options) -> bool {
|
|
|
CARBON_VLOG() << "*** SourceBuffer::CreateFromFile done ***\n";
|
|
|
// Require flushing the consumer before the source buffer is destroyed,
|
|
|
// because diagnostics may reference the buffer.
|
|
|
- auto flush = llvm::make_scope_exit([&]() { consumer->Flush(); });
|
|
|
+ auto flush_for_source = llvm::make_scope_exit([&]() { consumer->Flush(); });
|
|
|
if (!source.ok()) {
|
|
|
error_stream_ << "ERROR: Unable to open input source file: "
|
|
|
<< source.error();
|
|
|
@@ -410,6 +410,8 @@ auto Driver::Compile(const CompileOptions& options) -> bool {
|
|
|
|
|
|
CARBON_VLOG() << "*** TokenizedBuffer::Lex ***\n";
|
|
|
auto tokenized_source = TokenizedBuffer::Lex(*source, *consumer);
|
|
|
+ // Diagnostics may reference the tokenized buffer.
|
|
|
+ auto flush_for_tokens = llvm::make_scope_exit([&]() { consumer->Flush(); });
|
|
|
bool has_errors = tokenized_source.has_errors();
|
|
|
CARBON_VLOG() << "*** TokenizedBuffer::Lex done ***\n";
|
|
|
if (options.dump_tokens) {
|
|
|
@@ -424,6 +426,8 @@ auto Driver::Compile(const CompileOptions& options) -> bool {
|
|
|
|
|
|
CARBON_VLOG() << "*** ParseTree::Parse ***\n";
|
|
|
auto parse_tree = ParseTree::Parse(tokenized_source, *consumer, vlog_stream_);
|
|
|
+ // Diagnostics may reference the parse tree.
|
|
|
+ auto flush_for_parse = llvm::make_scope_exit([&]() { consumer->Flush(); });
|
|
|
has_errors |= parse_tree.has_errors();
|
|
|
CARBON_VLOG() << "*** ParseTree::Parse done ***\n";
|
|
|
if (options.dump_parse_tree) {
|
|
|
@@ -439,6 +443,8 @@ auto Driver::Compile(const CompileOptions& options) -> bool {
|
|
|
CARBON_VLOG() << "*** SemanticsIR::MakeFromParseTree ***\n";
|
|
|
const SemanticsIR semantics_ir = SemanticsIR::MakeFromParseTree(
|
|
|
builtin_ir, tokenized_source, parse_tree, *consumer, vlog_stream_);
|
|
|
+ // Diagnostics may reference the semantics IR.
|
|
|
+ auto flush_for_ir = llvm::make_scope_exit([&]() { consumer->Flush(); });
|
|
|
has_errors |= semantics_ir.has_errors();
|
|
|
CARBON_VLOG() << "*** SemanticsIR::MakeFromParseTree done ***\n";
|
|
|
if (options.dump_raw_semantics_ir) {
|
|
|
@@ -463,6 +469,11 @@ auto Driver::Compile(const CompileOptions& options) -> bool {
|
|
|
CARBON_VLOG() << "*** Stopping before lowering due to syntax errors ***";
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+ // Emit diagnostics now, so that the developer sees them sooner and doesn't
|
|
|
+ // need to wait for code generation.
|
|
|
+ // TODO: If we allow lowering to produce warnings, should we interleave them
|
|
|
+ // with diagnostics produced by earlier steps?
|
|
|
consumer->Flush();
|
|
|
|
|
|
CARBON_VLOG() << "*** LowerToLLVM ***\n";
|