|
|
@@ -24,9 +24,6 @@
|
|
|
#include "toolchain/lower/lower.h"
|
|
|
#include "toolchain/parse/parse.h"
|
|
|
#include "toolchain/parse/tree_and_subtrees.h"
|
|
|
-#include "toolchain/sem_ir/formatter.h"
|
|
|
-#include "toolchain/sem_ir/import_ir.h"
|
|
|
-#include "toolchain/sem_ir/inst_namer.h"
|
|
|
#include "toolchain/source/source_buffer.h"
|
|
|
|
|
|
namespace Carbon {
|
|
|
@@ -196,6 +193,7 @@ prints full SemIR.
|
|
|
)""",
|
|
|
},
|
|
|
[&](auto& arg_b) {
|
|
|
+ using DumpSemIRRanges = Check::CheckParseTreesOptions::DumpSemIRRanges;
|
|
|
arg_b.SetOneOf(
|
|
|
{
|
|
|
arg_b.OneOfValue("if-present", DumpSemIRRanges::IfPresent)
|
|
|
@@ -432,9 +430,6 @@ class CompilationUnit {
|
|
|
// significant overhead. Avoid constructing it when unused.
|
|
|
auto GetParseTreeAndSubtrees() -> const Parse::TreeAndSubtrees&;
|
|
|
|
|
|
- // Handles printing of formatted SemIR.
|
|
|
- auto MaybePrintFormattedSemIR() -> void;
|
|
|
-
|
|
|
// Wraps a call with log statements to indicate start and end. Typically logs
|
|
|
// with the actual function name, but marks timings with the appropriate
|
|
|
// phase.
|
|
|
@@ -609,17 +604,16 @@ auto CompilationUnit::RunLex() -> void {
|
|
|
LogCall("Lex::Lex", "lex", [&] {
|
|
|
Lex::LexOptions options;
|
|
|
options.consumer = consumer_;
|
|
|
+ options.vlog_stream = vlog_stream_;
|
|
|
+ if (options_->dump_tokens && IncludeInDumps()) {
|
|
|
+ options.dump_stream = driver_env_->output_stream;
|
|
|
+ options.omit_file_boundary_tokens = options_->omit_file_boundary_tokens;
|
|
|
+ }
|
|
|
tokens_ = Lex::Lex(value_stores_, *source_, options);
|
|
|
});
|
|
|
- if (options_->dump_tokens && IncludeInDumps()) {
|
|
|
- consumer_->Flush();
|
|
|
- tokens_->Print(*driver_env_->output_stream,
|
|
|
- options_->omit_file_boundary_tokens);
|
|
|
- }
|
|
|
if (mem_usage_) {
|
|
|
mem_usage_->Collect("tokens_", *tokens_);
|
|
|
}
|
|
|
- CARBON_VLOG("*** Lex::TokenizedBuffer ***\n{0}", tokens_);
|
|
|
if (tokens_->has_errors()) {
|
|
|
success_ = false;
|
|
|
}
|
|
|
@@ -630,21 +624,15 @@ auto CompilationUnit::RunParse() -> void {
|
|
|
Parse::ParseOptions options;
|
|
|
options.consumer = consumer_;
|
|
|
options.vlog_stream = vlog_stream_;
|
|
|
+ if (options_->dump_parse_tree && IncludeInDumps()) {
|
|
|
+ options.dump_stream = driver_env_->output_stream;
|
|
|
+ options.dump_preorder_parse_tree = options_->preorder_parse_tree;
|
|
|
+ }
|
|
|
parse_tree_ = Parse::Parse(*tokens_, options);
|
|
|
});
|
|
|
- if (options_->dump_parse_tree && IncludeInDumps()) {
|
|
|
- consumer_->Flush();
|
|
|
- const auto& tree_and_subtrees = GetParseTreeAndSubtrees();
|
|
|
- if (options_->preorder_parse_tree) {
|
|
|
- tree_and_subtrees.PrintPreorder(*driver_env_->output_stream);
|
|
|
- } else {
|
|
|
- tree_and_subtrees.Print(*driver_env_->output_stream);
|
|
|
- }
|
|
|
- }
|
|
|
if (mem_usage_) {
|
|
|
mem_usage_->Collect("parse_tree_", *parse_tree_);
|
|
|
}
|
|
|
- CARBON_VLOG("*** Parse::Tree ***\n{0}", parse_tree_);
|
|
|
if (parse_tree_->has_errors()) {
|
|
|
success_ = false;
|
|
|
}
|
|
|
@@ -667,33 +655,6 @@ auto CompilationUnit::GetCheckUnit() -> Check::Unit {
|
|
|
.cpp_ast = &cpp_ast_};
|
|
|
}
|
|
|
|
|
|
-auto CompilationUnit::MaybePrintFormattedSemIR() -> void {
|
|
|
- bool print = options_->dump_sem_ir && IncludeInDumps();
|
|
|
- if (!vlog_stream_ && !print) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (options_->dump_sem_ir_ranges == CompileOptions::DumpSemIRRanges::Only &&
|
|
|
- !tokens_->has_dump_sem_ir_ranges()) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- bool use_dump_sem_ir_ranges =
|
|
|
- options_->dump_sem_ir_ranges != CompileOptions::DumpSemIRRanges::Ignore &&
|
|
|
- tokens_->has_dump_sem_ir_ranges();
|
|
|
- SemIR::Formatter formatter(&*sem_ir_, *tree_and_subtrees_getter_,
|
|
|
- cache_->include_in_dumps(),
|
|
|
- use_dump_sem_ir_ranges);
|
|
|
- formatter.Format();
|
|
|
- if (vlog_stream_) {
|
|
|
- CARBON_VLOG("*** SemIR::File ***\n");
|
|
|
- formatter.Write(*vlog_stream_);
|
|
|
- }
|
|
|
- if (print) {
|
|
|
- formatter.Write(*driver_env_->output_stream);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
auto CompilationUnit::PostCheck() -> void {
|
|
|
CARBON_CHECK(sem_ir_, "Must call GetCheckUnit first");
|
|
|
|
|
|
@@ -706,15 +667,6 @@ auto CompilationUnit::PostCheck() -> void {
|
|
|
mem_usage_->Collect("sem_ir_", *sem_ir_);
|
|
|
}
|
|
|
|
|
|
- if (options_->dump_raw_sem_ir && IncludeInDumps()) {
|
|
|
- CARBON_VLOG("*** Raw SemIR::File ***\n{0}\n", *sem_ir_);
|
|
|
- sem_ir_->Print(*driver_env_->output_stream, options_->builtin_sem_ir);
|
|
|
- if (options_->dump_sem_ir) {
|
|
|
- *driver_env_->output_stream << "\n";
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- MaybePrintFormattedSemIR();
|
|
|
if (sem_ir_->has_errors()) {
|
|
|
success_ = false;
|
|
|
}
|
|
|
@@ -728,20 +680,13 @@ auto CompilationUnit::RunLower() -> void {
|
|
|
options_->run_llvm_verifier ? driver_env_->error_stream : nullptr;
|
|
|
options.want_debug_info = options_->include_debug_info;
|
|
|
options.vlog_stream = vlog_stream_;
|
|
|
+ if (options_->dump_llvm_ir && IncludeInDumps()) {
|
|
|
+ options.dump_stream = driver_env_->output_stream;
|
|
|
+ }
|
|
|
module_ = Lower::LowerToLLVM(*llvm_context_, driver_env_->fs,
|
|
|
cache_->tree_and_subtrees_getters(), *sem_ir_,
|
|
|
options);
|
|
|
});
|
|
|
- if (vlog_stream_) {
|
|
|
- CARBON_VLOG("*** llvm::Module ***\n");
|
|
|
- module_->print(*vlog_stream_, /*AAW=*/nullptr,
|
|
|
- /*ShouldPreserveUseListOrder=*/false,
|
|
|
- /*IsForDebug=*/true);
|
|
|
- }
|
|
|
- if (options_->dump_llvm_ir && IncludeInDumps()) {
|
|
|
- module_->print(*driver_env_->output_stream, /*AAW=*/nullptr,
|
|
|
- /*ShouldPreserveUseListOrder=*/true);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
auto CompilationUnit::RunCodeGen() -> void {
|
|
|
@@ -985,6 +930,19 @@ auto CompileSubcommand::Run(DriverEnv& driver_env) -> DriverResult {
|
|
|
options.prelude_import = options_.prelude_import;
|
|
|
options.vlog_stream = driver_env.vlog_stream;
|
|
|
options.fuzzing = driver_env.fuzzing;
|
|
|
+ if (options.vlog_stream || options_.dump_sem_ir || options_.dump_raw_sem_ir) {
|
|
|
+ options.include_in_dumps = cache.include_in_dumps();
|
|
|
+ if (options_.dump_sem_ir) {
|
|
|
+ options.dump_stream = driver_env.output_stream;
|
|
|
+ }
|
|
|
+ if (options.vlog_stream || options_.dump_sem_ir) {
|
|
|
+ options.dump_sem_ir_ranges = options_.dump_sem_ir_ranges;
|
|
|
+ }
|
|
|
+ if (options_.dump_raw_sem_ir) {
|
|
|
+ options.raw_dump_stream = driver_env.output_stream;
|
|
|
+ options.dump_raw_sem_ir_builtins = options_.builtin_sem_ir;
|
|
|
+ }
|
|
|
+ }
|
|
|
Check::CheckParseTrees(check_units, cache.tree_and_subtrees_getters(),
|
|
|
driver_env.fs, options_.codegen_options.target,
|
|
|
options);
|