diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 0a5a9c83a23aeb087c52889517cfd8f824047f56..1ef3c589de699271a7d50d37ef09aa656dda555d 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -215,6 +215,8 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg opTypeDtsBuiltin("type-dts-builtin", false, "Enable builtin type extractor for .d.ts file"); // compiler + panda::PandArg opEnableAbcInput("enable-abc-input", false, "Support for abc files as input"); + panda::PandArg opDumpAsmProgram("dump-asm-program", false, "Dump pandasm program"); panda::PandArg opDumpAssembly("dump-assembly", false, "Dump pandasm"); panda::PandArg opDebugInfo("debug-info", false, "Compile with debug info"); panda::PandArg opDumpDebugInfo("dump-debug-info", false, "Dump debug info"); @@ -268,6 +270,8 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&opEnableTypeCheck); argparser_->Add(&opTypeExtractor); argparser_->Add(&opTypeDtsBuiltin); + argparser_->Add(&opEnableAbcInput); + argparser_->Add(&opDumpAsmProgram); argparser_->Add(&opDumpAssembly); argparser_->Add(&opDebugInfo); argparser_->Add(&opDumpDebugInfo); @@ -457,6 +461,8 @@ bool Options::Parse(int argc, const char **argv) } compilerOptions_.recordSource = opRecordSource.GetValue(); + compilerOptions_.enableAbcInput = opEnableAbcInput.GetValue(); + compilerOptions_.dumpAsmProgram = opDumpAsmProgram.GetValue(); compilerOptions_.dumpAsm = opDumpAssembly.GetValue(); compilerOptions_.dumpAst = opDumpAst.GetValue(); compilerOptions_.dumpTransformedAst = opDumpTransformedAst.GetValue(); diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index b8136bcb392b88be542b564e92ad6e2a67432d54..8f11cc56012310743c67a85994300faf42366b8a 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -71,6 +71,8 @@ struct PatchFixOptions { }; struct CompilerOptions { + bool enableAbcInput {false}; + bool dumpAsmProgram {false}; bool isDebug {false}; bool dumpAst {false}; bool dumpTransformedAst {false}; diff --git a/es2panda/test/runner.py b/es2panda/test/runner.py index 71736725da5501b18f1a4cac8fd976022686abd4..26c1244dc4f60ada07ba5b62e5428e463d889680 100755 --- a/es2panda/test/runner.py +++ b/es2panda/test/runner.py @@ -80,6 +80,9 @@ def get_args(): parser.add_argument( '--error', action='store_true', dest='error', default=False, help='capture stderr') + parser.add_argument( + '--abc-to-asm', '-abc2asm', action='store_true', dest='abc_to_asm', + default=False, help='run abc2asm tests') parser.add_argument( '--regression', '-r', action='store_true', dest='regression', default=False, help='run regression tests') @@ -560,6 +563,50 @@ class RegressionRunner(Runner): def test_path(self, src): return src +class AbcToAsmRunner(Runner): + def __init__(self, args): + Runner.__init__(self, args, "Abc to asm") + + def add_directory(self, directory, extension, flags, func=Test): + glob_expression = path.join( + self.test_root, directory, "*.%s" % (extension)) + files = glob(glob_expression) + files = fnmatch.filter(files, self.test_root + '**' + self.args.filter) + + self.tests += list(map(lambda f: AbcToAsmTest(f, flags), files)) + + def test_path(self, src): + return src + +class AbcToAsmTest(Test): + def run(self, runner): + output_abc_file = ("%s.abc" % (path.splitext(self.path)[0])).replace("/", "_") + gen_abc_cmd = runner.cmd_prefix + [runner.es2panda] + gen_abc_cmd.extend(["--dump-asm-program", "--output=" + output_abc_file]) + gen_abc_cmd.append(self.path) + self.log_cmd(gen_abc_cmd) + abc_to_asm_cmd = runner.cmd_prefix + [runner.es2panda] + abc_to_asm_cmd.extend(["--dump-asm-program", "--enable-abc-input"]) + abc_to_asm_cmd.extend(output_abc_file) + self.log_cmd.append(abc_to_asm_cmd) + process_gen_abc = subprocess.Popen( + gen_abc_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + gen_abc_out, gen_abc_err = process.communicate() + gen_abc_output = gen_abc_out.decode("utf-8", errors="ignore") + gen_abc_err.decode("utf-8", errors="ignore") + process_abc_to_asm = subprocess.Popen( + abc_to_asm_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + abc_to_asm_out, abc_to_asm_err = process.communicate() + abc_to_asm_output = abc_to_asm_out.decode("utf-8", errors="ignore") + abc_to_asm_err.decode("utf-8", errors="ignore") + try: + self.passed = gen_abc_output == abc_to_asm_output and process.returncode in [0, 1] + except Exception: + self.passed = False + + if os.path.exists(output_abc_file) + os.remove(test_abc_path) + return self + + class Test262Runner(Runner): def __init__(self, args): @@ -1535,6 +1582,13 @@ def main(): runners.append(transformer_runner) + if args.abc_to_asm: + runner = AbcToAsmRunner(args) + runner.add_directory("abc2asm/js", "js" , ["--dump-asm-program"]) + runner.add_directory("abc2asm/ts", "ts", ["--dump-asm-program"]) + runner.add_directory("abc2asm/abc", "abc", ["--enable-abc-input", "--dump-asm-program"]) + runners.append(runner) + if args.test262: runners.append(Test262Runner(args))