Просмотр исходного кода

JSSpecCompiler: Compare CFG when running regression tests

Dan Klishch 1 год назад
Родитель
Сommit
8126e76e59

+ 50 - 0
Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/simple.cpp.expectation

@@ -132,3 +132,53 @@ TreeList
   ReturnNode
   ReturnNode
     Var b
     Var b
 
 
+===== CFG after cfg-building =====
+f():
+0:
+ControlFlowBranch true=3 false=7
+  UnresolvedReference cond1
+
+1:
+ControlFlowFunctionReturn
+  Var $return
+
+2:
+BinaryOperation Assignment
+  Var $return
+  Var b
+ControlFlowJump jump=1
+
+3:
+BinaryOperation Declaration
+  Var a
+  MathematicalConstant 1
+ControlFlowBranch true=5 false=6
+  UnresolvedReference cond2
+
+4:
+ControlFlowJump jump=2
+
+5:
+BinaryOperation Declaration
+  Var b
+  Var a
+ControlFlowJump jump=4
+
+6:
+BinaryOperation Declaration
+  Var b
+  MathematicalConstant 3
+ControlFlowJump jump=4
+
+7:
+BinaryOperation Declaration
+  Var b
+  MathematicalConstant 4
+ControlFlowJump jump=2
+
+8:
+BinaryOperation Assignment
+  Var $return
+  Error ""
+ControlFlowJump jump=1
+

+ 12 - 2
Tests/JSSpecCompiler/test-runner.cpp

@@ -18,6 +18,7 @@ struct TestDescription {
     struct Flag {
     struct Flag {
         StringView name;
         StringView name;
         bool dump_ast = false;
         bool dump_ast = false;
+        bool dump_cfg = false;
     };
     };
 
 
     Vector<StringView> sources;
     Vector<StringView> sources;
@@ -29,15 +30,16 @@ constexpr StringView stderr_capture_filename = "stderr"sv;
 constexpr StringView compiler_binary_name = "JSSpecCompiler"sv;
 constexpr StringView compiler_binary_name = "JSSpecCompiler"sv;
 constexpr StringView relative_path_to_test = "Tests"sv;
 constexpr StringView relative_path_to_test = "Tests"sv;
 
 
-constexpr TestDescription::Flag always_dump_ast = {
+constexpr TestDescription::Flag always_dump_all = {
     .name = "all"sv,
     .name = "all"sv,
     .dump_ast = true,
     .dump_ast = true,
+    .dump_cfg = true
 };
 };
 
 
 const Array regression_tests = {
 const Array regression_tests = {
     TestDescription {
     TestDescription {
         .sources = { "simple.cpp"sv },
         .sources = { "simple.cpp"sv },
-        .flags = { always_dump_ast },
+        .flags = { always_dump_all },
     },
     },
 };
 };
 
 
@@ -52,6 +54,7 @@ Vector<DeprecatedString> build_command_line_arguments(LexicalPath const& test_so
     Vector<DeprecatedString> result;
     Vector<DeprecatedString> result;
 
 
     StringBuilder dump_ast_option;
     StringBuilder dump_ast_option;
+    StringBuilder dump_cfg_option;
 
 
     for (auto const& flag : description.flags) {
     for (auto const& flag : description.flags) {
         if (flag.dump_ast) {
         if (flag.dump_ast) {
@@ -59,9 +62,16 @@ Vector<DeprecatedString> build_command_line_arguments(LexicalPath const& test_so
                 dump_ast_option.append(","sv);
                 dump_ast_option.append(","sv);
             dump_ast_option.append(flag.name);
             dump_ast_option.append(flag.name);
         }
         }
+        if (flag.dump_cfg) {
+            if (!dump_cfg_option.is_empty())
+                dump_cfg_option.append(","sv);
+            dump_cfg_option.append(flag.name);
+        }
     }
     }
     if (!dump_ast_option.is_empty())
     if (!dump_ast_option.is_empty())
         result.append(DeprecatedString::formatted("--dump-ast={}", dump_ast_option.string_view()));
         result.append(DeprecatedString::formatted("--dump-ast={}", dump_ast_option.string_view()));
+    if (!dump_cfg_option.is_empty())
+        result.append(DeprecatedString::formatted("--dump-cfg={}", dump_cfg_option.string_view()));
 
 
     if (test_source.has_extension(".cpp"sv))
     if (test_source.has_extension(".cpp"sv))
         result.append("-xc++"sv);
         result.append("-xc++"sv);