From abbd13ea90d990a4bed45cb2768374844780bcf0 Mon Sep 17 00:00:00 2001 From: zhuoli72 Date: Tue, 26 Jul 2022 21:19:07 +0800 Subject: [PATCH] Move dumper in a separate file Issue: I5ITZD Signed-off-by: zhuoli72 Change-Id: I8658439ac9c0413dc049143946f45b3bd42a3576 --- es2panda/BUILD.gn | 1 + es2panda/aot/main.cpp | 19 +++++++++++++------ es2panda/aot/options.cpp | 3 +++ es2panda/es2panda.h | 1 + es2panda/util/dumper.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ es2panda/util/dumper.h | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 es2panda/util/dumper.cpp create mode 100644 es2panda/util/dumper.h diff --git a/es2panda/BUILD.gn b/es2panda/BUILD.gn index 31eda11e1f..b6f2a746ef 100644 --- a/es2panda/BUILD.gn +++ b/es2panda/BUILD.gn @@ -234,6 +234,7 @@ es2panda_src = [ "typescript/types/unknownType.cpp", "typescript/types/voidType.cpp", "util/bitset.cpp", + "util/dumper.cpp", "util/helpers.cpp", "util/ustring.cpp", ] diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index 79c5131dec..467bff4775 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -22,10 +22,11 @@ #include #include #endif +#include #include #include #include -#include +#include #include #include @@ -54,9 +55,12 @@ public: } }; -static int GenerateProgram(panda::pandasm::Program *prog, const std::string &output, int optLevel, bool dumpAsm, - bool dumpSize) +static int GenerateProgram(panda::pandasm::Program *prog, std::unique_ptr &options) { + const std::string output = options->CompilerOutput(); + int optLevel = options->OptLevel(); + const es2panda::CompilerOptions compilerOptions = options->CompilerOptions(); + bool dumpSize = options->SizeStat(); std::map stat; std::map *statp = optLevel != 0 ? &stat : nullptr; panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps maps {}; @@ -78,7 +82,7 @@ static int GenerateProgram(panda::pandasm::Program *prog, const std::string &out } #endif - if (dumpAsm) { + if (compilerOptions.dumpAsm) { es2panda::Compiler::DumpAsm(prog); } @@ -86,6 +90,10 @@ static int GenerateProgram(panda::pandasm::Program *prog, const std::string &out return 1; } + if (compilerOptions.dumpLiteralBuffer) { + panda::es2panda::util::Dumper::DumpLiterals(prog->literalarray_table); + } + if (dumpSize && optLevel != 0) { size_t totalSize = 0; std::cout << "Panda file size statistic:" << std::endl; @@ -136,8 +144,7 @@ int Run(int argc, const char **argv) return err.ErrorCode(); } - GenerateProgram(program, options->CompilerOutput(), options->OptLevel(), options->CompilerOptions().dumpAsm, - options->SizeStat()); + GenerateProgram(program, options); delete program; return 0; diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 9f72eac598..ba5c41e505 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -62,6 +62,7 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg opOptLevel("opt-level", 0, "Compiler optimization level (options: 0 | 1 | 2)"); panda::PandArg opThreadCount("thread", 0, "Number of worker theads"); panda::PandArg opSizeStat("dump-size-stat", false, "Dump size statistics"); + panda::PandArg opDumpLiteralBuffer("dump-literal-buffer", false, "Dump literal buffer"); panda::PandArg outputFile("output", "", "Compiler binary output (.abc)"); // tail arguments @@ -78,6 +79,7 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&opOptLevel); argparser_->Add(&opThreadCount); argparser_->Add(&opSizeStat); + argparser_->Add(&opDumpLiteralBuffer); argparser_->Add(&inputExtension); argparser_->Add(&outputFile); @@ -157,6 +159,7 @@ bool Options::Parse(int argc, const char **argv) compilerOptions_.dumpDebugInfo = opDumpDebugInfo.GetValue(); compilerOptions_.isDebug = opDebugInfo.GetValue(); compilerOptions_.parseOnly = opParseOnly.GetValue(); + compilerOptions_.dumpLiteralBuffer = opDumpLiteralBuffer.GetValue(); return true; } diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index f68866c0ca..488d2fb422 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -54,6 +54,7 @@ struct CompilerOptions { bool dumpAsm {false}; bool dumpDebugInfo {false}; bool parseOnly {false}; + bool dumpLiteralBuffer {false}; }; enum class ErrorType { diff --git a/es2panda/util/dumper.cpp b/es2panda/util/dumper.cpp new file mode 100644 index 0000000000..8fd3ff4e6b --- /dev/null +++ b/es2panda/util/dumper.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "dumper.h" + +namespace panda::es2panda::util { + +void Dumper::DumpLiterals(std::map &literalTable) +{ + std::cout << "======> literal array buffer <======" << std::endl; + for (auto it : literalTable) { + std::cout << "------------------------------------" << std::endl; + std::cout << "slot " << it.first << std::endl; + int count = 0; + for (auto literal : it.second.literals_) { + std::cout << "{" << std::endl; + std::cout << " index: " << count++ << std::endl; + std::cout << " tag: " << + static_cast::type>(literal.tag_) << std::endl; + std::visit([](auto&& element) { + std::cout << " val: " << element << std::endl; + }, literal.value_); + std::cout << "}," << std::endl; + } + } +} + +} // namespace panda::es2panda::util + diff --git a/es2panda/util/dumper.h b/es2panda/util/dumper.h new file mode 100644 index 0000000000..4024fb0c25 --- /dev/null +++ b/es2panda/util/dumper.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ES2PANDA_UTIL_DUMPER_H +#define ES2PANDA_UTIL_DUMPER_H + +#include +#include +#include +#include + +namespace panda::es2panda::util { + +class Dumper { +public: + static void DumpLiterals(std::map &literalTable); +}; + +} // namespace panda::es2panda::util + +#endif \ No newline at end of file -- Gitee