Commit 8610cb5a authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

[torque] Always run all ImplementationVisitor steps

The language server and unit tests pass in an empty output directory
to signal that no C++ files should be generated. As these
generation steps include some validations, they should also be
included in language server and unit test compilation runs.

This CL introduces a "dry run" flag on the ImplementationVisitor.
Additionaly, the implementation visitor wraps the file writing
functionality. In case of a dry-run, file writing becomes a no-op.

R=sigurds@chromium.org

Bug: v8:7793
Change-Id: Id699fdf0b35311ddd3c1f5419baa0237b40ddce4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1617244Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61599}
parent 1b77e7e9
......@@ -1541,10 +1541,10 @@ void ImplementationVisitor::GenerateImplementation(const std::string& dir,
"builtins-" + DashifyString(nspace->name()) + "-gen-tq";
std::string source_file_name = dir + "/" + base_file_name + ".cc";
ReplaceFileContentsIfDifferent(source_file_name, new_source);
WriteFile(source_file_name, new_source);
std::string new_header(nspace->header());
std::string header_file_name = dir + "/" + base_file_name + ".h";
ReplaceFileContentsIfDifferent(header_file_name, new_header);
WriteFile(header_file_name, new_header);
}
void ImplementationVisitor::GenerateMacroFunctionDeclaration(
......@@ -2795,8 +2795,7 @@ void ImplementationVisitor::GenerateBuiltinDefinitions(
new_contents_stream << "\n";
}
std::string new_contents(new_contents_stream.str());
ReplaceFileContentsIfDifferent(output_directory + "/" + file_name,
new_contents);
WriteFile(output_directory + "/" + file_name, new_contents);
}
namespace {
......@@ -3057,9 +3056,9 @@ void ImplementationVisitor::GenerateClassDefinitions(
g.GenerateClass();
}
}
ReplaceFileContentsIfDifferent(file_basename + ".h", header.str());
ReplaceFileContentsIfDifferent(file_basename + "-inl.h", inline_header.str());
ReplaceFileContentsIfDifferent(file_basename + ".cc", implementation.str());
WriteFile(file_basename + ".h", header.str());
WriteFile(file_basename + "-inl.h", inline_header.str());
WriteFile(file_basename + ".cc", implementation.str());
}
void ImplementationVisitor::GenerateClassFieldOffsets(
......@@ -3129,7 +3128,7 @@ void ImplementationVisitor::GenerateClassFieldOffsets(
}
const std::string output_header_path = output_directory + "/" + file_name;
std::string new_contents(new_contents_stream.str());
ReplaceFileContentsIfDifferent(output_header_path, new_contents);
WriteFile(output_header_path, new_contents);
}
namespace {
......@@ -3188,8 +3187,7 @@ void ImplementationVisitor::GeneratePrintDefinitions(
}
std::string new_contents(impl.str());
ReplaceFileContentsIfDifferent(output_directory + "/" + file_name,
new_contents);
WriteFile(output_directory + "/" + file_name, new_contents);
}
namespace {
......@@ -3350,10 +3348,8 @@ void ImplementationVisitor::GenerateClassVerifiers(
h_contents << "};\n";
}
ReplaceFileContentsIfDifferent(output_directory + "/" + file_name + ".h",
h_contents.str());
ReplaceFileContentsIfDifferent(output_directory + "/" + file_name + ".cc",
cc_contents.str());
WriteFile(output_directory + "/" + file_name + ".h", h_contents.str());
WriteFile(output_directory + "/" + file_name + ".cc", cc_contents.str());
}
} // namespace torque
......
......@@ -388,6 +388,8 @@ class ImplementationVisitor {
LabelBindingsManager::Scope label_bindings_manager;
};
void SetDryRun(bool is_dry_run) { is_dry_run_ = is_dry_run; }
private:
base::Optional<Block*> GetCatchBlock();
void GenerateCatchBlock(base::Optional<Block*> catch_block);
......@@ -593,8 +595,14 @@ class ImplementationVisitor {
return return_value;
}
void WriteFile(const std::string& file, const std::string& content) {
if (is_dry_run_) return;
ReplaceFileContentsIfDifferent(file, content);
}
base::Optional<CfgAssembler> assembler_;
NullOStream null_stream_;
bool is_dry_run_;
};
} // namespace torque
......
......@@ -67,25 +67,26 @@ void CompileCurrentAst(TorqueCompilerOptions options) {
// mutually refer to each others.
TypeOracle::FinalizeClassTypes();
std::string output_directory = options.output_directory;
ImplementationVisitor implementation_visitor;
implementation_visitor.SetDryRun(output_directory.length() == 0);
for (Namespace* n : GlobalContext::Get().GetNamespaces()) {
implementation_visitor.BeginNamespaceFile(n);
}
implementation_visitor.VisitAllDeclarables();
std::string output_directory = options.output_directory;
if (output_directory.length() != 0) {
implementation_visitor.GenerateBuiltinDefinitions(output_directory);
implementation_visitor.GenerateClassFieldOffsets(output_directory);
implementation_visitor.GeneratePrintDefinitions(output_directory);
implementation_visitor.GenerateClassDefinitions(output_directory);
implementation_visitor.GenerateClassVerifiers(output_directory);
for (Namespace* n : GlobalContext::Get().GetNamespaces()) {
implementation_visitor.EndNamespaceFile(n);
implementation_visitor.GenerateImplementation(output_directory, n);
}
implementation_visitor.GenerateBuiltinDefinitions(output_directory);
implementation_visitor.GenerateClassFieldOffsets(output_directory);
implementation_visitor.GeneratePrintDefinitions(output_directory);
implementation_visitor.GenerateClassDefinitions(output_directory);
implementation_visitor.GenerateClassVerifiers(output_directory);
for (Namespace* n : GlobalContext::Get().GetNamespaces()) {
implementation_visitor.EndNamespaceFile(n);
implementation_visitor.GenerateImplementation(output_directory, n);
}
if (GlobalContext::collect_language_server_data()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment