@@ -50,6 +50,31 @@ ABSL_FLAG(std::string, ast_path, "", "The directory for the AST code in C++.");
5050ABSL_FLAG (std::string, ir_path, " " ,
5151 " The directory for the IR code in TableGen and C++." );
5252
53+ // Flags to support mapping AST nodes to a different target IR dialect
54+ // (e.g. mapping SWC's "jsswc" AST to the standard "jsir" dialect).
55+ ABSL_FLAG (std::string, ir_lang_name, " " ,
56+ " The language name for the IR (e.g. 'js')." );
57+
58+ // Overrides to prevent generated files from overwriting other dialect
59+ // conversions and to use custom names/paths.
60+ ABSL_FLAG (std::string, ast_to_ir_cc_path, " " ,
61+ " Override output path for generated AST to IR C++ source." );
62+
63+ ABSL_FLAG (std::string, ir_to_ast_cc_path, " " ,
64+ " Override output path for generated IR to AST C++ source." );
65+
66+ ABSL_FLAG (std::string, ast_to_ir_header_include_path, " " ,
67+ " Override include path for AST to IR header in generated source." );
68+
69+ ABSL_FLAG (std::string, ir_to_ast_header_include_path, " " ,
70+ " Override include path for IR to AST header in generated source." );
71+
72+ ABSL_FLAG (std::string, ast_to_ir_class_name, " " ,
73+ " Override class name for AST to IR converter." );
74+
75+ ABSL_FLAG (std::string, ir_to_ast_class_name, " " ,
76+ " Override class name for IR to AST converter." );
77+
5378namespace maldoca {
5479namespace {
5580
@@ -58,6 +83,15 @@ absl::Status AstGenMain() {
5883 auto cc_namespace = absl::GetFlag (FLAGS_cc_namespace);
5984 auto ast_path = absl::GetFlag (FLAGS_ast_path);
6085 auto ir_path = absl::GetFlag (FLAGS_ir_path);
86+ auto ir_lang_name = absl::GetFlag (FLAGS_ir_lang_name);
87+ auto ast_to_ir_cc_path_flag = absl::GetFlag (FLAGS_ast_to_ir_cc_path);
88+ auto ir_to_ast_cc_path_flag = absl::GetFlag (FLAGS_ir_to_ast_cc_path);
89+ auto ast_to_ir_header_include_path =
90+ absl::GetFlag (FLAGS_ast_to_ir_header_include_path);
91+ auto ir_to_ast_header_include_path =
92+ absl::GetFlag (FLAGS_ir_to_ast_header_include_path);
93+ auto ast_to_ir_class_name = absl::GetFlag (FLAGS_ast_to_ir_class_name);
94+ auto ir_to_ast_class_name = absl::GetFlag (FLAGS_ir_to_ast_class_name);
6195
6296 AstDefPb ast_def_pb;
6397 MALDOCA_RETURN_IF_ERROR (ParseTextProtoFile (ast_def_path, &ast_def_pb));
@@ -87,27 +121,35 @@ absl::Status AstGenMain() {
87121 SetFileContents (ast_from_json_path, ast_from_json));
88122
89123 if (!ir_path.empty ()) {
90- std::string ir_tablegen = PrintIrTableGen (ast_def, ir_path);
91- auto ir_tablegen_path = JoinPath (
92- ir_path, absl::StrCat (ast_def.lang_name (), " ir_ops.generated.td" ));
93- std::cout << " Writing ir_tablegen to " << ir_tablegen_path << " \n " ;
94- MALDOCA_RETURN_IF_ERROR (
95- SetFileContents (ir_tablegen_path, ir_tablegen));
96-
97- std::string ast_to_ir =
98- PrintAstToIrSource (ast_def, cc_namespace, ast_path, ir_path);
99- auto ast_to_ir_path = JoinPath (
100- ir_path, " conversion" ,
101- absl::StrCat (" ast_to_" , ast_def.lang_name (), " ir.generated.cc" ));
124+ if (ir_lang_name.empty () || ir_lang_name == ast_def.lang_name ()) {
125+ std::string ir_tablegen = PrintIrTableGen (ast_def, ir_path);
126+ auto ir_tablegen_path = JoinPath (
127+ ir_path, absl::StrCat (ast_def.lang_name (), " ir_ops.generated.td" ));
128+ std::cout << " Writing ir_tablegen to " << ir_tablegen_path << " \n " ;
129+ MALDOCA_RETURN_IF_ERROR (SetFileContents (ir_tablegen_path, ir_tablegen));
130+ }
131+
132+ std::string ast_to_ir = PrintAstToIrSource (
133+ ast_def, cc_namespace, ast_path, ir_path, ir_lang_name,
134+ ast_to_ir_header_include_path, ast_to_ir_class_name);
135+ auto ast_to_ir_path =
136+ ast_to_ir_cc_path_flag.empty ()
137+ ? JoinPath (ir_path, " conversion" ,
138+ absl::StrCat (" ast_to_" , ast_def.lang_name (),
139+ " ir.generated.cc" ))
140+ : ast_to_ir_cc_path_flag;
102141 std::cout << " Writing ast_to_ir to " << ast_to_ir_path << " \n " ;
103142 MALDOCA_RETURN_IF_ERROR (
104143 SetFileContents (ast_to_ir_path, ast_to_ir));
105144
106- std::string ir_to_ast =
107- PrintIrToAstSource (ast_def, cc_namespace, ast_path, ir_path);
108- auto ir_to_ast_path = JoinPath (
109- ir_path, " conversion" ,
110- absl::StrCat (ast_def.lang_name (), " ir_to_ast.generated.cc" ));
145+ std::string ir_to_ast = PrintIrToAstSource (
146+ ast_def, cc_namespace, ast_path, ir_path, ir_lang_name,
147+ ir_to_ast_header_include_path, ir_to_ast_class_name);
148+ auto ir_to_ast_path = ir_to_ast_cc_path_flag.empty ()
149+ ? JoinPath (ir_path, " conversion" ,
150+ absl::StrCat (ast_def.lang_name (),
151+ " ir_to_ast.generated.cc" ))
152+ : ir_to_ast_cc_path_flag;
111153 std::cout << " Writing ir_to_ast to " << ir_to_ast_path << " \n " ;
112154 MALDOCA_RETURN_IF_ERROR (
113155 SetFileContents (ir_to_ast_path, ir_to_ast));
0 commit comments