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

[torque] Add DashifyString function for module names.

Module names in torque are allowed to have underscores but not dashes.
To stay consistent with C++ file naming conventions, the underscores
in module names are replaced by dashes for file names.

Example:

module typed_array {} would now generate:
builtins-typed-array-from-dsl-gen.(cc|h)

instead of:
builtins-typed_array-from-dsl-gen.(cc|h)

R=danno@chromium.org

Change-Id: Iff42d7b9b5f65c378ee30f9d884ab6a3a3cd42a7
Reviewed-on: https://chromium-review.googlesource.com/1016460Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Daniel Clifford <danno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52686}
parent 29b65c39
......@@ -55,7 +55,8 @@ void ImplementationVisitor::Visit(ModuleDeclaration* decl) {
if (decl->IsDefault()) {
source << "#include \"src/code-stub-assembler.h\"";
} else {
source << "#include \"src/builtins/builtins-" + module->name() + "-gen.h\"";
source << "#include \"src/builtins/builtins-" +
DashifyString(module->name()) + "-gen.h\"";
}
source << std::endl;
source << "#include \"src/builtins/builtins-utils-gen.h\"" << std::endl;
......@@ -64,7 +65,8 @@ void ImplementationVisitor::Visit(ModuleDeclaration* decl) {
source << "#include \"src/heap/factory-inl.h\"" << std::endl;
source << "#include \"src/objects.h\"" << std::endl;
source << "#include \"builtins-" + module->name() + "-from-dsl-gen.h\"";
source << "#include \"builtins-" + DashifyString(module->name()) +
"-from-dsl-gen.h\"";
source << std::endl << std::endl;
source << "namespace v8 {" << std::endl
......@@ -83,7 +85,8 @@ void ImplementationVisitor::Visit(ModuleDeclaration* decl) {
if (decl->IsDefault()) {
header << "#include \"src/code-stub-assembler.h\"";
} else {
header << "#include \"src/builtins/builtins-" + module->name() + "-gen.h\""
header << "#include \"src/builtins/builtins-" +
DashifyString(module->name()) + "-gen.h\""
<< std::endl;
}
header << std::endl << std::endl;
......@@ -809,12 +812,13 @@ Label* ImplementationVisitor::GetLabel(SourcePosition pos,
void ImplementationVisitor::GenerateImplementation(const std::string& dir,
Module* module) {
std::string new_source(module->source());
std::string source_file_name =
dir + "/builtins-" + module->name() + "-from-dsl-gen.cc";
std::string base_file_name =
"builtins-" + DashifyString(module->name()) + "-from-dsl-gen";
std::string source_file_name = dir + "/" + base_file_name + ".cc";
ReplaceFileContentsIfDifferent(source_file_name, new_source);
std::string new_header(module->header());
std::string header_file_name =
dir + "/builtins-" + module->name() + "-from-dsl-gen.h";
std::string header_file_name = dir + "/" + base_file_name + ".h";
ReplaceFileContentsIfDifferent(header_file_name, new_header);
}
......
......@@ -34,6 +34,12 @@ std::string CamelifyString(const std::string& underscore_string) {
return result;
}
std::string DashifyString(const std::string& underscore_string) {
std::string result = underscore_string;
std::replace(result.begin(), result.end(), '_', '-');
return result;
}
void ReplaceFileContentsIfDifferent(const std::string& file_path,
const std::string& contents) {
std::ifstream old_contents_stream(file_path.c_str());
......
......@@ -18,6 +18,7 @@ typedef std::vector<std::string> NameVector;
void ReportError(const std::string& error);
std::string CamelifyString(const std::string& underscore_string);
std::string DashifyString(const std::string& underscore_string);
void ReplaceFileContentsIfDifferent(const std::string& file_path,
const std::string& contents);
......
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