diff --git a/es2panda/BUILD.gn b/es2panda/BUILD.gn index e937a3e2f55d0726be656ed54acc5a308fc57ea0..672d226ca32ca8201797a89a4faf10b63a4b49bb 100644 --- a/es2panda/BUILD.gn +++ b/es2panda/BUILD.gn @@ -299,6 +299,7 @@ config("es2abc_config_common") { "$ark_root/libpandafile:arkfile_public_config", "$ark_root/libpandabase:arkbase_public_config", "$ark_root/assembler:arkassembler_public_config", + "$ark_root/abc2program:abc2program_public_config", ":es2abc_config_src", ] @@ -411,6 +412,7 @@ ohos_static_library("es2panda_lib") { external_deps = [] if (!is_arkui_x) { external_deps += [ + "runtime_core:abc2program_frontend_static", "runtime_core:libarkassembler_frontend_static", "runtime_core:libarkbase_frontend_static", "runtime_core:libarkfile_frontend_static", @@ -425,6 +427,7 @@ ohos_static_library("es2panda_lib") { } } else { deps += [ + "$ark_root/abc2program:abc2program_frontend_static", "$ark_root/assembler:libarkassembler_frontend_static", "$ark_root/libpandabase:libarkbase_frontend_static", "$ark_root/libpandafile:libarkfile_frontend_static", diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index 755287c87c89aa90a2f062322e718f9cda1537ff..633c959815f2689b445eea169445848658fa8efc 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -106,8 +107,13 @@ static void DumpProgramInfos(const std::map &options) { const es2panda::CompilerOptions &compilerOptions = options->CompilerOptions(); - if (compilerOptions.dumpAsm || compilerOptions.dumpLiteralBuffer) { + if (compilerOptions.dumpAsm || compilerOptions.dumpLiteralBuffer || compilerOptions.dumpAsmProgram) { for (const auto &progInfo : programsInfo) { + if (compilerOptions.dumpAsmProgram) { + panda::abc2program::PandasmProgramDumper dumper; + dumper.Dump(std::cout, progInfo.second->program); + } + if (compilerOptions.dumpAsm) { es2panda::Compiler::DumpAsm(&(progInfo.second->program)); } diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index 7b325899ca1e103678d50c13b20007262e1db49b..96a46f0f92480ac1d7e2540ba205adc57858ad4a 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -35,7 +35,8 @@ constexpr size_t DEFAULT_THREAD_COUNT = 2; Compiler::Compiler(ScriptExtension ext) : Compiler(ext, DEFAULT_THREAD_COUNT) {} Compiler::Compiler(ScriptExtension ext, size_t threadCount) - : parser_(new parser::ParserImpl(ext)), compiler_(new compiler::CompilerImpl(threadCount)) + : parser_(new parser::ParserImpl(ext)), compiler_(new compiler::CompilerImpl(threadCount)), + abcToAsmCompiler_(new panda::abc2program::Abc2ProgramCompiler) { if (parser_->Extension() == ScriptExtension::TS) { transformer_ = std::make_unique(parser_->Allocator()); @@ -46,6 +47,7 @@ Compiler::~Compiler() { delete parser_; delete compiler_; + delete abcToAsmCompiler_; } panda::pandasm::Program *CreateJsonContentProgram(std::string src, std::string rname, util::PatchFix *patchFixHelper) @@ -56,6 +58,20 @@ panda::pandasm::Program *CreateJsonContentProgram(std::string src, std::string r return context.GetEmitter()->Finalize(false, nullptr); } +panda::pandasm::Program *Compiler::AbcToAsmProgram(const std::string &fname, const CompilerOptions &options) +{ + if (!options.enableAbcInput) { + throw Error(ErrorType::GENERIC, "\"--enable-abc-input\" is not enabled, abc file " + fname + + "could not be used as the input."); + } + if (!abcToAsmCompiler_->OpenAbcFile(fname)) { + return nullptr; + } + panda::pandasm::Program *prog = new panda::pandasm::Program(); + (void)abcToAsmCompiler_->FillProgramData(*prog); + return prog; +} + panda::pandasm::Program *Compiler::Compile(const SourceFile &input, const CompilerOptions &options, util::SymbolTable *symbolTable) { @@ -74,6 +90,9 @@ panda::pandasm::Program *Compiler::Compile(const SourceFile &input, const Compil } try { + if (fname.substr(fname.find_last_of(".") + 1) == "abc") { + return AbcToAsmProgram(fname, options); + } auto ast = parser_->Parse(fname, src, rname, options, kind); ast.Binder()->SetProgram(&ast); diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index 8f11cc56012310743c67a85994300faf42366b8a..42c85ccaa11c513a119a7ee2e179bf5ae1c931aa 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -204,9 +205,11 @@ private: util::PatchFix *InitPatchFixHelper(const SourceFile &input, const CompilerOptions &options, util::SymbolTable *symbolTable); static void CleanPatchFixHelper(const util::PatchFix *patchFixHelper); + panda::pandasm::Program *AbcToAsmProgram(const std::string &fname, const CompilerOptions &options); parser::ParserImpl *parser_; compiler::CompilerImpl *compiler_; + panda::abc2program::Abc2ProgramCompiler *abcToAsmCompiler_; std::unique_ptr transformer_ {nullptr}; Error error_; }; diff --git a/es2panda/test/runner.py b/es2panda/test/runner.py index af80fcb764f800ee999bc76807b4747015723402..e0490c3ec31b1d6e3098c89d990c840c94cb659b 100755 --- a/es2panda/test/runner.py +++ b/es2panda/test/runner.py @@ -590,11 +590,11 @@ class AbcToAsmTest(Test): gen_abc_output = gen_abc_out.decode("utf-8", errors="ignore") + gen_abc_err.decode("utf-8", errors="ignore") # If no abc file is generated, an error occurs during parser, but abc2asm function is normal. if not os.path.exists(output_abc_file): - self.passed = true + self.passed = True return self 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) + abc_to_asm_cmd.append(output_abc_file) self.log_cmd(abc_to_asm_cmd) 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_abc_to_asm.communicate() @@ -604,8 +604,17 @@ class AbcToAsmTest(Test): self.passed = gen_abc_output == abc_to_asm_output and process_abc_to_asm.returncode in [0, 1] except Exception: self.passed = False - - os.remove(test_abc_path) + + if not self.passed: + print("**********Error testcase**********") + print(self.path) + print("**********Gen abc cmd**********") + print(gen_abc_cmd) + print(gen_abc_output) + print("**********Abc to asm cmd***********") + print(abc_to_asm_cmd) + print(abc_to_asm_output) + os.remove(output_abc_file) return self class Test262Runner(Runner): @@ -1586,7 +1595,29 @@ def main(): runner = AbcToAsmRunner(args) runner.add_directory("abc2asm/js", "js", []) runner.add_directory("abc2asm/ts", "ts", []) - runner.add_directory("abc2asm/abc", "abc", []) + runner.add_directory("compiler/js", "js", []) + runner.add_directory("compiler/ts/cases/compiler", "ts", []) + runner.add_directory("compiler/ts/projects", "ts", ["--module"]) + runner.add_directory("compiler/ts/projects", "ts", ["--module", "--merge-abc"]) + runner.add_directory("compiler/dts", "d.ts", ["--module", "--opt-level=0"]) + runner.add_directory("compiler/commonjs", "js", ["--commonjs"]) + runner.add_directory("compiler/recordsource/with-on", "js", ["--record-source"]) + runner.add_directory("compiler/recordsource/with-off", "js", []) + runner.add_directory("parser/concurrent", "js", ["--module"]) + runner.add_directory("parser/js", "js", []) + runner.add_directory("parser/script", "ts", []) + runner.add_directory("parser/ts", "ts", ["--module"]) + runner.add_directory("parser/ts/type_checker", "ts", ["--enable-type-check", "--module"]) + runner.add_directory("parser/commonjs", "js", ["--commonjs"]) + runner.add_directory("parser/binder", "js", []) + runner.add_directory("parser/js/emptySource", "js", []) + runner.add_directory("parser/js/language/arguments-object", "js", []) + runner.add_directory("parser/js/language/statements/for-statement", "js", []) + runner.add_directory("parser/js/language/expressions/optional-chain", "js", []) + runner.add_directory("parser/sendable_class", "ts", ["--module"]) + runner.add_directory("parser/unicode", "js", []) + runner.add_directory("parser/ts/stack_overflow", "ts", []) + runners.append(runner) if args.test262: