From 95b9c412a85de4d60646077c3b32d206233719b4 Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Fri, 12 Aug 2022 09:20:06 +0800 Subject: [PATCH 01/23] Support serialize program Signed-off-by: zhangrengao Change-Id: I98a5a478953a9743c9e03943cad5da0e6ba35f92 --- es2panda/BUILD.gn | 10 +- es2panda/aot/main.cpp | 7 + es2panda/aot/options.cpp | 8 ++ es2panda/aot/options.h | 6 + merge_abc/BUILD.gn | 145 ++++++++++++++++++++ merge_abc/protos/annotation.proto | 64 +++++++++ merge_abc/protos/assemblyDebug.proto | 34 +++++ merge_abc/protos/assemblyField.proto | 31 +++++ merge_abc/protos/assemblyFileLocation.proto | 25 ++++ merge_abc/protos/assemblyFunction.proto | 78 +++++++++++ merge_abc/protos/assemblyIns.proto | 36 +++++ merge_abc/protos/assemblyLabel.proto | 24 ++++ merge_abc/protos/assemblyLiterals.proto | 47 +++++++ merge_abc/protos/assemblyProgram.proto | 48 +++++++ merge_abc/protos/assemblyRecord.proto | 35 +++++ merge_abc/protos/assemblyType.proto | 24 ++++ merge_abc/protos/ideHelpers.proto | 27 ++++ merge_abc/protos/meta.proto | 57 ++++++++ merge_abc/script/build_proto.sh | 27 ++++ merge_abc/src/annotation.cpp | 117 ++++++++++++++++ merge_abc/src/annotation.h | 45 ++++++ merge_abc/src/assemblyDebug.cpp | 38 +++++ merge_abc/src/assemblyDebug.h | 34 +++++ merge_abc/src/assemblyField.cpp | 33 +++++ merge_abc/src/assemblyField.h | 30 ++++ merge_abc/src/assemblyFileLocation.cpp | 26 ++++ merge_abc/src/assemblyFileLocation.h | 29 ++++ merge_abc/src/assemblyFunction.cpp | 93 +++++++++++++ merge_abc/src/assemblyFunction.h | 46 +++++++ merge_abc/src/assemblyIns.cpp | 46 +++++++ merge_abc/src/assemblyIns.h | 29 ++++ merge_abc/src/assemblyLabel.cpp | 28 ++++ merge_abc/src/assemblyLabel.h | 29 ++++ merge_abc/src/assemblyLiterals.cpp | 75 ++++++++++ merge_abc/src/assemblyLiterals.h | 39 ++++++ merge_abc/src/assemblyProgram.cpp | 51 +++++++ merge_abc/src/assemblyProgram.h | 31 +++++ merge_abc/src/assemblyRecord.cpp | 42 ++++++ merge_abc/src/assemblyRecord.h | 31 +++++ merge_abc/src/assemblyType.cpp | 26 ++++ merge_abc/src/assemblyType.h | 28 ++++ merge_abc/src/ideHelpers.cpp | 36 +++++ merge_abc/src/ideHelpers.h | 37 +++++ merge_abc/src/meta.cpp | 82 +++++++++++ merge_abc/src/meta.h | 63 +++++++++ merge_abc/src/protobufSnapshotGenerator.cpp | 31 +++++ merge_abc/src/protobufSnapshotGenerator.h | 27 ++++ 47 files changed, 1953 insertions(+), 2 deletions(-) create mode 100644 merge_abc/BUILD.gn create mode 100644 merge_abc/protos/annotation.proto create mode 100644 merge_abc/protos/assemblyDebug.proto create mode 100644 merge_abc/protos/assemblyField.proto create mode 100644 merge_abc/protos/assemblyFileLocation.proto create mode 100644 merge_abc/protos/assemblyFunction.proto create mode 100644 merge_abc/protos/assemblyIns.proto create mode 100644 merge_abc/protos/assemblyLabel.proto create mode 100644 merge_abc/protos/assemblyLiterals.proto create mode 100644 merge_abc/protos/assemblyProgram.proto create mode 100644 merge_abc/protos/assemblyRecord.proto create mode 100644 merge_abc/protos/assemblyType.proto create mode 100644 merge_abc/protos/ideHelpers.proto create mode 100644 merge_abc/protos/meta.proto create mode 100755 merge_abc/script/build_proto.sh create mode 100644 merge_abc/src/annotation.cpp create mode 100644 merge_abc/src/annotation.h create mode 100644 merge_abc/src/assemblyDebug.cpp create mode 100644 merge_abc/src/assemblyDebug.h create mode 100644 merge_abc/src/assemblyField.cpp create mode 100644 merge_abc/src/assemblyField.h create mode 100644 merge_abc/src/assemblyFileLocation.cpp create mode 100644 merge_abc/src/assemblyFileLocation.h create mode 100644 merge_abc/src/assemblyFunction.cpp create mode 100644 merge_abc/src/assemblyFunction.h create mode 100644 merge_abc/src/assemblyIns.cpp create mode 100644 merge_abc/src/assemblyIns.h create mode 100644 merge_abc/src/assemblyLabel.cpp create mode 100644 merge_abc/src/assemblyLabel.h create mode 100644 merge_abc/src/assemblyLiterals.cpp create mode 100644 merge_abc/src/assemblyLiterals.h create mode 100644 merge_abc/src/assemblyProgram.cpp create mode 100644 merge_abc/src/assemblyProgram.h create mode 100644 merge_abc/src/assemblyRecord.cpp create mode 100644 merge_abc/src/assemblyRecord.h create mode 100644 merge_abc/src/assemblyType.cpp create mode 100644 merge_abc/src/assemblyType.h create mode 100644 merge_abc/src/ideHelpers.cpp create mode 100644 merge_abc/src/ideHelpers.h create mode 100644 merge_abc/src/meta.cpp create mode 100644 merge_abc/src/meta.h create mode 100644 merge_abc/src/protobufSnapshotGenerator.cpp create mode 100644 merge_abc/src/protobufSnapshotGenerator.h diff --git a/es2panda/BUILD.gn b/es2panda/BUILD.gn index 6bd30c9e88..6f1898c92a 100644 --- a/es2panda/BUILD.gn +++ b/es2panda/BUILD.gn @@ -398,9 +398,15 @@ ohos_executable("es2panda") { include_dirs = [ "./aot" ] - configs = [ ":es2abc_config_common" ] + configs = [ + ":es2abc_config_common", + "//arkcompiler/ets_frontend/merge_abc:panda_assembly_proto_public_config" + ] - deps = [ ":es2panda_lib" ] + deps = [ + ":es2panda_lib", + "//arkcompiler/ets_frontend/merge_abc:panda_assembly_proto_static" + ] ldflags = [] if (is_linux) { diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index 3bc260f815..5247ab9d72 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -31,6 +31,8 @@ #include #include +#include + namespace panda::es2panda::aot { using mem::MemConfig; @@ -123,6 +125,11 @@ static int GenerateProgram(panda::pandasm::Program *prog, std::unique_ptrcompilerProtoOutput().size() > 0) { + proto::ProtobufSnapshotGenerator::GenerateSnapshot(*prog, options->compilerProtoOutput()); + return 0; + } + if (!panda::pandasm::AsmEmitter::Emit(output, *prog, statp, mapsp, true)) { return 1; } diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 6ad7b2a8a9..45e34b66d2 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -72,6 +72,7 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg base64Output("base64Output", false, "output panda file content as base64 to std out"); panda::PandArg sourceFile("source-file", "", "specify the file path info recorded in generated abc"); + panda::PandArg outputProto("outputProto", "", "Compiler proto serialize binary output (.bin)"); // tail arguments panda::PandArg inputFile("input", "", "input file"); @@ -97,6 +98,7 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&inputExtension); argparser_->Add(&outputFile); argparser_->Add(&sourceFile); + argparser_->Add(&outputProto); argparser_->PushBackTail(&inputFile); argparser_->EnableTail(); @@ -148,6 +150,12 @@ bool Options::Parse(int argc, const char **argv) parserInput_ = ss.str(); sourceFile_ = BaseName(sourceFile_); + + if (!outputProto.GetValue().empty()) { + compilerProtoOutput_ = outputProto.GetValue(); + } else { + compilerProtoOutput_ = ""; + } } else { // input content is base64 string parserInput_ = ExtractContentFromBase64Input(base64Input.GetValue()); diff --git a/es2panda/aot/options.h b/es2panda/aot/options.h index 49286015ae..8ea4f47073 100644 --- a/es2panda/aot/options.h +++ b/es2panda/aot/options.h @@ -118,6 +118,11 @@ public: std::string ExtractContentFromBase64Input(const std::string &inputBase64String); + const std::string &compilerProtoOutput() const + { + return compilerProtoOutput_; + } + private: es2panda::ScriptExtension extension_ {es2panda::ScriptExtension::JS}; es2panda::CompilerOptions compilerOptions_ {}; @@ -129,6 +134,7 @@ private: std::string result_; std::string sourceFile_; std::string errorMsg_; + std::string compilerProtoOutput_; int optLevel_ {0}; int threadCount_ {0}; }; diff --git a/merge_abc/BUILD.gn b/merge_abc/BUILD.gn new file mode 100644 index 0000000000..8ba34522c5 --- /dev/null +++ b/merge_abc/BUILD.gn @@ -0,0 +1,145 @@ +# 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. + +import("//arkcompiler/runtime_core/ark_config.gni") +import("//build/config/clang/clang.gni") +import("//build/ohos.gni") +import("//developtools/profiler/build/config.gni") + +proto_base_dir = "protos" +proto_out_dir = "$target_gen_dir" + "/protos_generated" + +protobuf_snapshot_generator_sources = [ + "src/annotation.cpp", + "src/assemblyDebug.cpp", + "src/assemblyField.cpp", + "src/assemblyFileLocation.cpp", + "src/assemblyFunction.cpp", + "src/assemblyIns.cpp", + "src/assemblyLabel.cpp", + "src/assemblyLiterals.cpp", + "src/assemblyProgram.cpp", + "src/assemblyRecord.cpp", + "src/assemblyType.cpp", + "src/ideHelpers.cpp", + "src/meta.cpp", + "src/protobufSnapshotGenerator.cpp", +] + +config("panda_assembly_proto_public_config") { + include_dirs = [ + "$ark_root/assembler", + "$ark_root", + "src", + "$proto_out_dir", + "//third_party/protobuf/src", + "//third_party/protobuf/src/google", + "//third_party/protobuf/src/google/protobuf", + ] +} + +assembly_proto_configs = [ + sdk_libc_secshared_config, + "$ark_root:ark_config", + ":panda_assembly_proto_public_config", + "$ark_root/assembler:arkassembler_public_config", + "$ark_root/libpandabase:arkbase_public_config", + "$ark_root/libpandafile:arkfile_public_config", +] + +proto_file_defines = [ + # add your proto file here + "annotation", + "assemblyDebug", + "assemblyField", + "assemblyFileLocation", + "assemblyFunction", + "assemblyIns", + "assemblyLabel", + "assemblyLiterals", + "assemblyProgram", + "assemblyRecord", + "assemblyType", + "ideHelpers", + "meta", +] + +proto_file_sources = [] +proto_generated_header = [] +proto_generated_source = [] + +foreach(proto_file, proto_file_defines) { + proto_generated_header += [ "$proto_out_dir" + "/" + "$proto_file.pb.h" ] + proto_generated_source += [ "$proto_out_dir" + "/" + "$proto_file.pb.cc" ] + proto_file_sources += [ "$proto_base_dir" + "/" + "$proto_file.proto" ] +} + +protoc_binary_out_path = + "${OHOS_PROFILER_SUBSYS_NAME}/${OHOS_PROFILER_PART_NAME}" + +if (default_toolchain == current_toolchain) { + #if target build + host_out_path = "/" + get_label_info(host_toolchain, "name") +} else { + #if host build (for some linke mingw) + host_out_path = "/../" + get_label_info(host_toolchain, "name") +} + +host_protoc_path = + root_out_dir + host_out_path + "/" + protoc_binary_out_path + "/protoc" + +action("arkcompiler_generate_proto") { + deps = [ "//third_party/protobuf:protoc($host_toolchain)" ] + args = [] + sources = [] + outputs = proto_generated_header + proto_generated_source + script = "./script/build_proto.sh" + + args += [ rebase_path(host_protoc_path) ] + args += [ + "--proto_path", + rebase_path(proto_base_dir), + "--cpp_out", + rebase_path(proto_out_dir), + "--experimental_allow_proto3_optional", + ] + + foreach(proto_file_source, proto_file_sources) { + #tell gn to check which files as source time + sources += [ rebase_path(proto_file_source) ] + args += [ rebase_path(proto_file_source) ] + } +} + +config("proto_file_cpp_config") { + include_dirs = [ proto_out_dir ] +} + +ohos_source_set("assembly_proto_static") { + cflags = [ "-Wno-error=zero-length-array" ] + + deps = [ + ":arkcompiler_generate_proto", + "//third_party/protobuf:protobuf_lite_static", + "//third_party/protobuf:protobuf_static", + ] + + sources = proto_generated_header + proto_generated_source + + protobuf_snapshot_generator_sources + public_configs = assembly_proto_configs + public_configs += [ ":proto_file_cpp_config" ] +} + +ohos_static_library("panda_assembly_proto_static") { + deps = [ ":assembly_proto_static" ] +} diff --git a/merge_abc/protos/annotation.proto b/merge_abc/protos/annotation.proto new file mode 100644 index 0000000000..848e7e30ba --- /dev/null +++ b/merge_abc/protos/annotation.proto @@ -0,0 +1,64 @@ +/** + * 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. + */ + +syntax = "proto3"; +package proto_panda; + +import "assemblyType.proto"; + +message Value { + uint32 type = 1; +} + +message ScalarValue { + enum VariantValueType { + UINT64 = 0; + FLOAT = 1; + DOUBLE = 2; + STRING = 3; + PANDASM_TYPE = 4; + ANNOTATION_DATA = 5; + } + Value father = 1; + oneof value { + uint64 value_u64 = 2; + float value_f = 3; + double value_d = 4; + bytes value_str = 5; + Type value_type = 6; + AnnotationData value_anno = 7; + } + VariantValueType type = 8; +} + +message ArrayValue { + Value father = 1; + uint32 component_type = 2; + repeated ScalarValue values = 3; +} + +message AnnotationElement { + bytes name = 1; + oneof value { + ScalarValue scalar = 2; + ArrayValue array = 3; + } + bool is_array = 4; +} + +message AnnotationData { + bytes record_name = 1; + repeated AnnotationElement elements = 2; +} diff --git a/merge_abc/protos/assemblyDebug.proto b/merge_abc/protos/assemblyDebug.proto new file mode 100644 index 0000000000..3d56843809 --- /dev/null +++ b/merge_abc/protos/assemblyDebug.proto @@ -0,0 +1,34 @@ +/** + * 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. + */ + +syntax = "proto3"; +package proto_panda; + +message DebuginfoIns { + uint64 line_number = 1; + uint32 column_number = 2; + bytes whole_line = 3; + uint64 bound_left = 4; + uint64 bound_right = 5; +} + +message LocalVariable { + bytes name = 1; + bytes signature = 2; + bytes signature_type = 3; + int32 reg = 4; + uint32 start = 5; + uint32 length = 6; +} diff --git a/merge_abc/protos/assemblyField.proto b/merge_abc/protos/assemblyField.proto new file mode 100644 index 0000000000..e3cf2daa81 --- /dev/null +++ b/merge_abc/protos/assemblyField.proto @@ -0,0 +1,31 @@ +/** + * 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. + */ + +syntax = "proto3"; +package proto_panda; + +import "assemblyType.proto"; +import "meta.proto"; + +message Field { + Type type = 1; + bytes name = 2; + FieldMetadata metadata = 3; + uint64 line_of_def = 4; + bytes whole_line = 5; + uint64 bound_left = 6; + uint64 bound_right = 7; + bool is_defined = 8; +} diff --git a/merge_abc/protos/assemblyFileLocation.proto b/merge_abc/protos/assemblyFileLocation.proto new file mode 100644 index 0000000000..500239f743 --- /dev/null +++ b/merge_abc/protos/assemblyFileLocation.proto @@ -0,0 +1,25 @@ +/** + * 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. + */ + +syntax = "proto3"; +package proto_panda; + +message FileLocation { + bytes whole_line = 1; + uint64 bound_left = 2; + uint64 bound_right = 3; + uint64 line_number = 4; + bool is_defined = 5; +} diff --git a/merge_abc/protos/assemblyFunction.proto b/merge_abc/protos/assemblyFunction.proto new file mode 100644 index 0000000000..0c77062368 --- /dev/null +++ b/merge_abc/protos/assemblyFunction.proto @@ -0,0 +1,78 @@ +/** + * 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. + */ + +syntax = "proto3"; +package proto_panda; + +import "assemblyIns.proto"; +import "assemblyLabel.proto"; +import "assemblyType.proto"; +import "assemblyDebug.proto"; +import "assemblyFileLocation.proto"; +import "ideHelpers.proto"; +import "meta.proto"; + +message CatchBlock { + bytes whole_line = 1; + bytes exception_record = 2; + bytes try_begin_label = 3; + bytes try_end_label = 4; + bytes catch_begin_label = 5; + bytes catch_end_label = 6; +} + +message TryCatchInfo { + message TryCatchLabel { + bytes key = 1; + uint64 value = 2; + } + message TryCatchUnit { + bytes key = 1; + repeated CatchBlock catch_blocks = 2; + } + repeated TryCatchLabel try_catch_labels = 1; + repeated TryCatchUnit try_catch_map = 2; + repeated bytes try_catch_order = 3; +} + +message Parameter { + Type type = 1; + ParamMetadata metadata = 2; +} + +message Function { + message LabelUnit { + bytes key = 1; + Label value = 2; + } + + bytes name = 1; + uint32 language = 2; + FunctionMetadata metadata = 3; + repeated LabelUnit label_table = 4; + repeated Ins ins = 5; + repeated LocalVariable local_variable_debug = 6; + bytes source_file = 7; + bytes source_code = 8; + repeated CatchBlock catch_blocks = 9; + int64 value_of_first_param = 10; + uint64 regs_num = 11; + repeated Parameter params = 12; + bool body_presence = 13; + Type return_type = 14; + SourceLocation body_location = 15; + optional FileLocation file_location = 16; +} + diff --git a/merge_abc/protos/assemblyIns.proto b/merge_abc/protos/assemblyIns.proto new file mode 100644 index 0000000000..2dc81a675c --- /dev/null +++ b/merge_abc/protos/assemblyIns.proto @@ -0,0 +1,36 @@ +/** + * 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. + */ + +syntax = "proto3"; +package proto_panda; + +import "assemblyDebug.proto"; + +message Ins { + message IType { + oneof type { + int64 value_int = 1; + double value_double = 2; + } + } + + uint32 opcode = 1; + repeated uint32 regs = 2; + repeated bytes ids = 3; + repeated IType imms = 4; + bytes label = 5; + bool set_label = 6; + DebuginfoIns ins_debug = 7; +} diff --git a/merge_abc/protos/assemblyLabel.proto b/merge_abc/protos/assemblyLabel.proto new file mode 100644 index 0000000000..1ada1f4287 --- /dev/null +++ b/merge_abc/protos/assemblyLabel.proto @@ -0,0 +1,24 @@ +/** + * 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. + */ + +syntax = "proto3"; +package proto_panda; + +import "assemblyFileLocation.proto"; + +message Label { + bytes name = 1; + optional FileLocation file_location = 2; +} diff --git a/merge_abc/protos/assemblyLiterals.proto b/merge_abc/protos/assemblyLiterals.proto new file mode 100644 index 0000000000..cfcc582c85 --- /dev/null +++ b/merge_abc/protos/assemblyLiterals.proto @@ -0,0 +1,47 @@ +/** + * 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. + */ + +syntax = "proto3"; +package proto_panda; + +message VariantValue { + enum VariantValueType { + BOOL = 0; + U8 = 1; + U16 = 2; + U32 = 3; + U64 = 4; + F32 = 5; + F64 = 6; + STRING = 7; + } + + oneof value { + uint64 value_int = 1; + float value_f = 2; + double value_d = 3; + bytes value_str = 4; + } + VariantValueType type = 5; +} + +message Literal { + uint32 tag = 1; // LiteralTag + VariantValue value = 2; +} + +message LiteralArray { + repeated Literal literals = 1; +} diff --git a/merge_abc/protos/assemblyProgram.proto b/merge_abc/protos/assemblyProgram.proto new file mode 100644 index 0000000000..f18ef7d7e9 --- /dev/null +++ b/merge_abc/protos/assemblyProgram.proto @@ -0,0 +1,48 @@ +/** + * 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. + */ + +syntax = "proto3"; +package proto_panda; + +import "assemblyFunction.proto"; +import "assemblyRecord.proto"; +import "assemblyType.proto"; +import "assemblyLiterals.proto"; + +message Program { + message RecordUnit { + bytes key = 1; + Record value = 2; + } + message FunctionUnit { + bytes key = 1; + Function value = 2; + } + message FunctionSynnoym { + bytes key = 1; + repeated bytes value = 2; + } + message LiteralUnit { + bytes key = 1; + LiteralArray value = 2; + } + uint32 lang = 1; + repeated RecordUnit record_table = 2; + repeated FunctionUnit function_table = 3; + repeated FunctionSynnoym function_synonyms = 4; + repeated LiteralUnit literalarray_table = 5; + repeated bytes strings = 6; + repeated Type array_types = 7; +} diff --git a/merge_abc/protos/assemblyRecord.proto b/merge_abc/protos/assemblyRecord.proto new file mode 100644 index 0000000000..dd341edee1 --- /dev/null +++ b/merge_abc/protos/assemblyRecord.proto @@ -0,0 +1,35 @@ +/** + * 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. + */ + +syntax = "proto3"; +package proto_panda; + +import "assemblyField.proto"; +import "assemblyFileLocation.proto"; +import "ideHelpers.proto"; +import "meta.proto"; + +message Record { + bytes name = 1; + bool conflict = 2; + uint32 language = 3; + RecordMetadata metadata = 4; + repeated Field field_list = 5; + uint64 params_num = 6; + bool body_presence = 7; + SourceLocation body_location = 8; + bytes source_file = 9; + optional FileLocation file_location = 10; +} diff --git a/merge_abc/protos/assemblyType.proto b/merge_abc/protos/assemblyType.proto new file mode 100644 index 0000000000..b0a29eace2 --- /dev/null +++ b/merge_abc/protos/assemblyType.proto @@ -0,0 +1,24 @@ +/** + * 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. + */ + +syntax = "proto3"; +package proto_panda; + +message Type { + bytes component_name = 1; + uint64 rank = 2; + bytes name = 3; + uint32 type_id = 4; +} diff --git a/merge_abc/protos/ideHelpers.proto b/merge_abc/protos/ideHelpers.proto new file mode 100644 index 0000000000..6fb77d8bfd --- /dev/null +++ b/merge_abc/protos/ideHelpers.proto @@ -0,0 +1,27 @@ +/** + * 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. + */ + +syntax = "proto3"; +package proto_panda; + +message SourcePosition { + uint64 line = 1; + uint64 column = 2; +} + +message SourceLocation { + SourcePosition begin = 1; + SourcePosition end = 2; +} diff --git a/merge_abc/protos/meta.proto b/merge_abc/protos/meta.proto new file mode 100644 index 0000000000..a4ffc18095 --- /dev/null +++ b/merge_abc/protos/meta.proto @@ -0,0 +1,57 @@ +/** + * 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. + */ + +syntax = "proto3"; +package proto_panda; + +import "annotation.proto"; +import "assemblyType.proto"; + +message Metadata { + repeated bytes set_attributes = 1; + message Attributes { + bytes key = 1; + repeated bytes value = 2; + } + repeated Attributes attributes = 2; +} + +message AnnotationMetadata { + Metadata father = 1; + repeated AnnotationData annotations = 2; +} + +message ItemMetadata { + AnnotationMetadata father = 1; + uint32 access_flags = 2; +} + +message RecordMetadata { + ItemMetadata father = 1; +} + +message FieldMetadata { + ItemMetadata father = 1; + Type field_type = 2; + optional ScalarValue value = 3; +} + +message FunctionMetadata { + ItemMetadata father = 1; +} + +message ParamMetadata { + AnnotationMetadata father = 1; +} diff --git a/merge_abc/script/build_proto.sh b/merge_abc/script/build_proto.sh new file mode 100755 index 0000000000..6f51316045 --- /dev/null +++ b/merge_abc/script/build_proto.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# 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. + +set -e + +echo "use protoc to do the prebuild" + +echo "pwd $(pwd)" + +protoc_cmdline=$* +echo protoc_cmdline $protoc_cmdline + +cmd="$protoc_cmdline" +echo $cmd +$cmd + \ No newline at end of file diff --git a/merge_abc/src/annotation.cpp b/merge_abc/src/annotation.cpp new file mode 100644 index 0000000000..3257f31b84 --- /dev/null +++ b/merge_abc/src/annotation.cpp @@ -0,0 +1,117 @@ +/** + * 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. + */ + +#include "annotation.h" + +namespace panda::proto { +void AnnotationData::Serialize(const panda::pandasm::AnnotationData &anno, proto_panda::AnnotationData &protoAnno) +{ + protoAnno.set_record_name(anno.GetName()); + for (const auto &element : anno.GetElements()) { + auto *protoElement = protoAnno.add_elements(); + AnnotationElement::Serialize(element, *protoElement); + } +} + +void AnnotationElement::Serialize(const panda::pandasm::AnnotationElement &element, + proto_panda::AnnotationElement &protoElement) +{ + protoElement.set_name(element.GetName()); + bool is_array = element.GetValue()->IsArray(); + protoElement.set_is_array(is_array); + if (is_array) { + auto *protoArray = protoElement.mutable_array(); + ArrayValue::Serialize(*(element.GetValue()->GetAsArray()), *protoArray); + } else { + auto *protoScalar = protoElement.mutable_scalar(); + ScalarValue::Serialize(*(element.GetValue()->GetAsScalar()), *protoScalar); + } +} + +void ScalarValue::Serialize(const panda::pandasm::ScalarValue &scalar, proto_panda::ScalarValue &protoScalar) +{ + const auto &value_type = scalar.GetType(); + protoScalar.mutable_father()->set_type(static_cast(value_type)); + auto type = proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_UINT64; + switch (value_type) { + case panda::pandasm::Value::Type::U1: + case panda::pandasm::Value::Type::U8: + protoScalar.set_value_u64(static_cast(scalar.GetValue())); + break; + case panda::pandasm::Value::Type::U16: + protoScalar.set_value_u64(static_cast(scalar.GetValue())); + break; + case panda::pandasm::Value::Type::STRING_NULLPTR: + case panda::pandasm::Value::Type::U32: + protoScalar.set_value_u64(static_cast(scalar.GetValue())); + break; + case panda::pandasm::Value::Type::U64: + protoScalar.set_value_u64(scalar.GetValue()); + break; + case panda::pandasm::Value::Type::I8: + protoScalar.set_value_u64(static_cast(scalar.GetValue())); + break; + case panda::pandasm::Value::Type::I16: + protoScalar.set_value_u64(static_cast(scalar.GetValue())); + break; + case panda::pandasm::Value::Type::I32: + protoScalar.set_value_u64(static_cast(scalar.GetValue())); + break; + case panda::pandasm::Value::Type::I64: + protoScalar.set_value_u64(static_cast(scalar.GetValue())); + break; + case panda::pandasm::Value::Type::F32: + type = proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_FLOAT; + protoScalar.set_value_f(scalar.GetValue()); + break; + case panda::pandasm::Value::Type::F64: + type = proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_DOUBLE; + protoScalar.set_value_d(scalar.GetValue()); + break; + case panda::pandasm::Value::Type::STRING: + case panda::pandasm::Value::Type::METHOD: + case panda::pandasm::Value::Type::ENUM: + type = proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_STRING; + protoScalar.set_value_str(scalar.GetValue()); + break; + case panda::pandasm::Value::Type::RECORD: { + type = proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_PANDASM_TYPE; + auto *protoType = protoScalar.mutable_value_type(); + Type::Serialize(scalar.GetValue(), *protoType); + break; + } + case panda::pandasm::Value::Type::ANNOTATION: { + type = proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_ANNOTATION_DATA; + auto *protoAnno = protoScalar.mutable_value_anno(); + AnnotationData::Serialize(scalar.GetValue(), *protoAnno); + break; + } + default: + UNREACHABLE(); + } + protoScalar.set_type(type); +} + +void ArrayValue::Serialize(const panda::pandasm::ArrayValue &array, proto_panda::ArrayValue &protoArray) +{ + protoArray.mutable_father()->set_type(static_cast(array.GetType())); + protoArray.set_component_type(static_cast(array.GetComponentType())); + for (const auto &val : array.GetValues()) { + auto *protoScalar = protoArray.add_values(); + ScalarValue::Serialize(val, *protoScalar); + } +} + +} // panda::proto \ No newline at end of file diff --git a/merge_abc/src/annotation.h b/merge_abc/src/annotation.h new file mode 100644 index 0000000000..fdae663fe6 --- /dev/null +++ b/merge_abc/src/annotation.h @@ -0,0 +1,45 @@ +/** + * 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 MERGE_ABC_ANNOTATION_H +#define MERGE_ABC_ANNOTATION_H + +#include "assembly-program.h" +#include "assemblyType.h" +#include "annotation.pb.h" + +namespace panda::proto { +class AnnotationData { +public: + static void Serialize(const panda::pandasm::AnnotationData &anno, proto_panda::AnnotationData &protoAnno); +}; + +class AnnotationElement { +public: + static void Serialize(const panda::pandasm::AnnotationElement &element, + proto_panda::AnnotationElement &protoElement); +}; + +class ScalarValue { +public: + static void Serialize(const panda::pandasm::ScalarValue &scalar, proto_panda::ScalarValue &protoScalar); +}; + +class ArrayValue { +public: + static void Serialize(const panda::pandasm::ArrayValue &array, proto_panda::ArrayValue &protoArray); +}; +} // panda::proto +#endif \ No newline at end of file diff --git a/merge_abc/src/assemblyDebug.cpp b/merge_abc/src/assemblyDebug.cpp new file mode 100644 index 0000000000..7141d9e862 --- /dev/null +++ b/merge_abc/src/assemblyDebug.cpp @@ -0,0 +1,38 @@ +/** + * 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. + */ + +#include "assemblyDebug.h" + +namespace panda::proto { +void DebuginfoIns::Serialize(const panda::pandasm::debuginfo::Ins &debug, proto_panda::DebuginfoIns &protoDebug) +{ + protoDebug.set_line_number(debug.line_number); + protoDebug.set_column_number(debug.column_number); + protoDebug.set_whole_line(debug.whole_line); + protoDebug.set_bound_left(debug.bound_left); + protoDebug.set_bound_right(debug.bound_right); +} + +void LocalVariable::Serialize(const panda::pandasm::debuginfo::LocalVariable &debug, + proto_panda::LocalVariable &protoDebug) +{ + protoDebug.set_name(debug.name); + protoDebug.set_signature(debug.signature); + protoDebug.set_signature_type(debug.signature_type); + protoDebug.set_reg(debug.reg); + protoDebug.set_start(debug.start); + protoDebug.set_length(debug.length); +} +} // panda::proto \ No newline at end of file diff --git a/merge_abc/src/assemblyDebug.h b/merge_abc/src/assemblyDebug.h new file mode 100644 index 0000000000..edb6445b67 --- /dev/null +++ b/merge_abc/src/assemblyDebug.h @@ -0,0 +1,34 @@ +/** + * 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 MERGE_ABC_ASSEMBLY_DEBUG_H +#define MERGE_ABC_ASSEMBLY_DEBUG_H + +#include "assembly-program.h" +#include "assemblyDebug.pb.h" + +namespace panda::proto { +class DebuginfoIns { +public: + static void Serialize(const panda::pandasm::debuginfo::Ins &debug, proto_panda::DebuginfoIns &protoDebug); +}; + +class LocalVariable { +public: + static void Serialize(const panda::pandasm::debuginfo::LocalVariable &debug, + proto_panda::LocalVariable &protoDebug); +}; +} // panda::proto +#endif \ No newline at end of file diff --git a/merge_abc/src/assemblyField.cpp b/merge_abc/src/assemblyField.cpp new file mode 100644 index 0000000000..0c64e917ac --- /dev/null +++ b/merge_abc/src/assemblyField.cpp @@ -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. + */ + +#include "assemblyField.h" + +namespace panda::proto { + +void Field::Serialize(const panda::pandasm::Field &field, proto_panda::Field &protoField) +{ + auto *protoType = protoField.mutable_type(); + Type::Serialize(field.type, *protoType); + protoField.set_name(field.name); + auto *protoFieldmeta = protoField.mutable_metadata(); + FieldMetadata::Serialize(*field.metadata, *protoFieldmeta); + protoField.set_line_of_def(field.line_of_def); + protoField.set_whole_line(field.whole_line); + protoField.set_bound_left(field.bound_left); + protoField.set_bound_right(field.bound_right); + protoField.set_is_defined(field.is_defined); +} +} // panda::proto \ No newline at end of file diff --git a/merge_abc/src/assemblyField.h b/merge_abc/src/assemblyField.h new file mode 100644 index 0000000000..381d32b0bf --- /dev/null +++ b/merge_abc/src/assemblyField.h @@ -0,0 +1,30 @@ +/** + * 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 MERGE_ABC_ASSEMBLY_FIELD_H +#define MERGE_ABC_ASSEMBLY_FIELD_H + +#include "assembly-program.h" +#include "assemblyField.pb.h" +#include "meta.h" +#include "assemblyType.h" + +namespace panda::proto { +class Field { +public: + static void Serialize(const panda::pandasm::Field &field, proto_panda::Field &protoField); +}; +} // panda::proto +#endif \ No newline at end of file diff --git a/merge_abc/src/assemblyFileLocation.cpp b/merge_abc/src/assemblyFileLocation.cpp new file mode 100644 index 0000000000..f2014192c5 --- /dev/null +++ b/merge_abc/src/assemblyFileLocation.cpp @@ -0,0 +1,26 @@ +/** + * 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. + */ + +#include "assemblyFileLocation.h" + +namespace panda::proto { +void FileLocation::Serialize(const panda::pandasm::FileLocation &location, proto_panda::FileLocation &protoLocation) +{ + protoLocation.set_whole_line(location.whole_line); + protoLocation.set_bound_left(location.bound_left); + protoLocation.set_bound_right(location.bound_right); + protoLocation.set_is_defined(location.is_defined); +} +} // panda::proto diff --git a/merge_abc/src/assemblyFileLocation.h b/merge_abc/src/assemblyFileLocation.h new file mode 100644 index 0000000000..0800c2851c --- /dev/null +++ b/merge_abc/src/assemblyFileLocation.h @@ -0,0 +1,29 @@ +/** + * 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 MERGE_ABC_ASSEMBLY_FILE_LOCATION_H +#define MERGE_ABC_ASSEMBLY_FILE_LOCATION_H + +#include "assembly-program.h" +#include "assemblyFileLocation.pb.h" + + +namespace panda::proto { +class FileLocation { +public: + static void Serialize(const panda::pandasm::FileLocation &location, proto_panda::FileLocation &protoLocation); +}; +} // panda::proto +#endif \ No newline at end of file diff --git a/merge_abc/src/assemblyFunction.cpp b/merge_abc/src/assemblyFunction.cpp new file mode 100644 index 0000000000..97eccfbe40 --- /dev/null +++ b/merge_abc/src/assemblyFunction.cpp @@ -0,0 +1,93 @@ +/** + * 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. + */ + +#include "assemblyFunction.h" + +namespace panda::proto { +void CatchBlock::Serialize(const panda::pandasm::Function::CatchBlock &block, proto_panda::CatchBlock &protoBlock) +{ + protoBlock.set_whole_line(block.whole_line); + protoBlock.set_exception_record(block.exception_record); + protoBlock.set_try_begin_label(block.try_begin_label); + protoBlock.set_try_end_label(block.try_end_label); + protoBlock.set_catch_begin_label(block.catch_begin_label); + protoBlock.set_catch_end_label(block.catch_end_label); +} + +void Parameter::Serialize(const panda::pandasm::Function::Parameter ¶m, proto_panda::Parameter &protoParam) +{ + auto *type = protoParam.mutable_type(); + Type::Serialize(param.type, *type); + auto *metadata = protoParam.mutable_metadata(); + ParamMetadata::Serialize(*(param.metadata), *metadata); +} + +void Function::Serialize(const panda::pandasm::Function &function, proto_panda::Function &protoFunction) +{ + protoFunction.set_name(function.name); + protoFunction.set_language(static_cast(function.language)); + + auto *protoFuncMeta = protoFunction.mutable_metadata(); + FunctionMetadata::Serialize(*function.metadata, *protoFuncMeta); + + + for (const auto &[name, label] : function.label_table) { + auto *labelMap = protoFunction.add_label_table(); + labelMap->set_key(name); + auto *protoLabel = labelMap->mutable_value(); + Label::Serialize(label, *protoLabel); + } + + for (const auto &insn : function.ins) { + auto *protoIns = protoFunction.add_ins(); + Ins::Serialize(insn, *protoIns); + } + + for (const auto &debug : function.local_variable_debug) { + auto *protoDebug = protoFunction.add_local_variable_debug(); + LocalVariable::Serialize(debug, *protoDebug); + } + + protoFunction.set_source_file(function.source_file); + protoFunction.set_source_code(function.source_code); + + for (const auto &block : function.catch_blocks) { + auto *protoBlock = protoFunction.add_catch_blocks(); + CatchBlock::Serialize(block, *protoBlock); + } + + protoFunction.set_value_of_first_param(function.value_of_first_param); + protoFunction.set_regs_num(function.regs_num); + + for (const auto ¶m : function.params) { + auto *protoParam = protoFunction.add_params(); + Parameter::Serialize(param, *protoParam); + } + + protoFunction.set_body_presence(function.body_presence); + + auto *protoReturnType = protoFunction.mutable_return_type(); + Type::Serialize(function.return_type, *protoReturnType); + + auto *protoBodyLocation = protoFunction.mutable_body_location(); + SourceLocation::Serialize(function.body_location, *protoBodyLocation); + + const auto &fileLocation = function.file_location; + if (fileLocation.has_value()) { + auto *protoFileLocation = protoFunction.mutable_file_location(); + FileLocation::Serialize(fileLocation.value(), *protoFileLocation); + } +} +} // panda::proto \ No newline at end of file diff --git a/merge_abc/src/assemblyFunction.h b/merge_abc/src/assemblyFunction.h new file mode 100644 index 0000000000..ba3f42bd53 --- /dev/null +++ b/merge_abc/src/assemblyFunction.h @@ -0,0 +1,46 @@ +/** + * 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 MERGE_ABC_ASSEMBLY_FUNCTION_H +#define MERGE_ABC_ASSEMBLY_FUNCTION_H + +#include "assembly-program.h" +#include "assemblyLabel.h" +#include "assemblyType.h" +#include "assemblyIns.h" +#include "assemblyDebug.h" +#include "ideHelpers.h" +#include "assemblyFileLocation.h" +#include "meta.h" +#include "assemblyFunction.pb.h" + +namespace panda::proto { +class CatchBlock { +public: + static void Serialize(const panda::pandasm::Function::CatchBlock &block, proto_panda::CatchBlock &protoBlock); +}; + +class Parameter { +public: + static void Serialize(const panda::pandasm::Function::Parameter ¶m, proto_panda::Parameter &protoParam); +}; + +class Function { +public: + static void Serialize(const panda::pandasm::Function &function, proto_panda::Function &protoFunction); +}; +} // panda::proto +#endif + diff --git a/merge_abc/src/assemblyIns.cpp b/merge_abc/src/assemblyIns.cpp new file mode 100644 index 0000000000..0805c0c509 --- /dev/null +++ b/merge_abc/src/assemblyIns.cpp @@ -0,0 +1,46 @@ +/** + * 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. + */ + +#include "assemblyIns.h" + +namespace panda::proto { +void Ins::Serialize(const panda::pandasm::Ins &insn, proto_panda::Ins &protoInsn) +{ + protoInsn.set_opcode(static_cast(insn.opcode)); + for (const auto ® : insn.regs) { + protoInsn.add_regs(static_cast(reg)); + } + for (const auto &str : insn.ids) { + protoInsn.add_ids(str); + } + for (const auto imm : insn.imms) { + auto *protoImm = protoInsn.add_imms(); + switch (static_cast(imm.index() + 1)) { // 1: enum TypeCase start from 1 + case proto_panda::Ins_IType::kValueInt: + protoImm->set_value_int(std::get(imm)); + break; + case proto_panda::Ins_IType::kValueDouble: + protoImm->set_value_double(std::get(imm)); + break; + default: + UNREACHABLE(); + } + } + protoInsn.set_label(insn.label); + protoInsn.set_set_label(insn.set_label); + auto *protoDebug = protoInsn.mutable_ins_debug(); + DebuginfoIns::Serialize(insn.ins_debug, *protoDebug); +} +} // panda::proto \ No newline at end of file diff --git a/merge_abc/src/assemblyIns.h b/merge_abc/src/assemblyIns.h new file mode 100644 index 0000000000..607ab0be6f --- /dev/null +++ b/merge_abc/src/assemblyIns.h @@ -0,0 +1,29 @@ +/** + * 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 MERGE_ABC_ASSEMBLY_INS_H +#define MERGE_ABC_ASSEMBLY_INS_H + +#include "assembly-program.h" +#include "assemblyDebug.h" +#include "assemblyIns.pb.h" + +namespace panda::proto { +class Ins { +public: + static void Serialize(const panda::pandasm::Ins &insn, proto_panda::Ins &protoInsn); +}; +} // panda::proto +#endif \ No newline at end of file diff --git a/merge_abc/src/assemblyLabel.cpp b/merge_abc/src/assemblyLabel.cpp new file mode 100644 index 0000000000..2000002ad6 --- /dev/null +++ b/merge_abc/src/assemblyLabel.cpp @@ -0,0 +1,28 @@ +/** + * 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. + */ + +#include "assemblyLabel.h" + +namespace panda::proto { +void Label::Serialize(const panda::pandasm::Label &label, proto_panda::Label &protoLabel) +{ + protoLabel.set_name(label.name); + const auto &fileLocation = label.file_location; + if (fileLocation.has_value()) { + auto *protoLocation = protoLabel.mutable_file_location(); + FileLocation::Serialize(fileLocation.value(), *protoLocation); + } +} +} // panda::proto \ No newline at end of file diff --git a/merge_abc/src/assemblyLabel.h b/merge_abc/src/assemblyLabel.h new file mode 100644 index 0000000000..0beb0c15dd --- /dev/null +++ b/merge_abc/src/assemblyLabel.h @@ -0,0 +1,29 @@ +/** + * 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 MERGE_ABC_ASSEMBLY_LABEL_H +#define MERGE_ABC_ASSEMBLY_LABEL_H + +#include "assembly-program.h" +#include "assemblyFileLocation.h" +#include "assemblyLabel.pb.h" + +namespace panda::proto { +class Label { +public: + static void Serialize(const panda::pandasm::Label &label, proto_panda::Label &protoLabel); +}; +} // panda::proto +#endif \ No newline at end of file diff --git a/merge_abc/src/assemblyLiterals.cpp b/merge_abc/src/assemblyLiterals.cpp new file mode 100644 index 0000000000..84e2ab1d06 --- /dev/null +++ b/merge_abc/src/assemblyLiterals.cpp @@ -0,0 +1,75 @@ +/** + * 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. + */ + +#include "assemblyLiterals.h" + +namespace panda::proto { +void VariantValue::Serialize(const LiteralValueType &value, proto_panda::VariantValue &protoValue) +{ + const auto type = static_cast(value.index()); + protoValue.set_type(type); + switch(type) { + case proto_panda::VariantValue_VariantValueType_BOOL: { + protoValue.set_value_int(static_cast(std::get(value))); + return; + } + case proto_panda::VariantValue_VariantValueType_U8: { + protoValue.set_value_int(static_cast(std::get(value))); + return; + } + case proto_panda::VariantValue_VariantValueType_U16: { + protoValue.set_value_int(static_cast(std::get(value))); + return; + } + case proto_panda::VariantValue_VariantValueType_U32: { + protoValue.set_value_int(static_cast(std::get(value))); + return; + } + case proto_panda::VariantValue_VariantValueType_U64: { + protoValue.set_value_int(std::get(value)); + return; + } + case proto_panda::VariantValue_VariantValueType_F32: { + protoValue.set_value_f(std::get(value)); + return; + } + case proto_panda::VariantValue_VariantValueType_F64: { + protoValue.set_value_d(std::get(value)); + return; + } + case proto_panda::VariantValue_VariantValueType_STRING: { + protoValue.set_value_str(std::get(value)); + return;; + } + default: + UNREACHABLE(); + } +} + +void LiteralArray::Serialize(const panda::pandasm::LiteralArray &array, proto_panda::LiteralArray &protoArray) +{ + for (const auto &literal : array.literals_) { + auto *protoLiteral = protoArray.add_literals(); + Literal::Serialize(literal, *protoLiteral); + } +} + +void Literal::Serialize(const panda::pandasm::LiteralArray::Literal &literal, proto_panda::Literal &protoLiteral) +{ + protoLiteral.set_tag(static_cast(literal.tag_)); + auto *value = protoLiteral.mutable_value(); + VariantValue::Serialize(literal.value_, *value); +} +} // panda::proto diff --git a/merge_abc/src/assemblyLiterals.h b/merge_abc/src/assemblyLiterals.h new file mode 100644 index 0000000000..9d23d237fc --- /dev/null +++ b/merge_abc/src/assemblyLiterals.h @@ -0,0 +1,39 @@ +/** + * 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 MERGE_ABC_ASSEMBLY_LITERALS_H +#define MERGE_ABC_ASSEMBLY_LITERALS_H + +#include "assembly-program.h" +#include "assemblyLiterals.pb.h" + +namespace panda::proto { +class VariantValue { +public: + using LiteralValueType = std::variant; + static void Serialize(const LiteralValueType &value, proto_panda::VariantValue &protoValue); +}; + +class LiteralArray { +public: + static void Serialize(const panda::pandasm::LiteralArray &array, proto_panda::LiteralArray &protoArray); +}; + +class Literal { +public: + static void Serialize(const panda::pandasm::LiteralArray::Literal &literal, proto_panda::Literal &protoLiteral); +}; +} // panda::proto +#endif \ No newline at end of file diff --git a/merge_abc/src/assemblyProgram.cpp b/merge_abc/src/assemblyProgram.cpp new file mode 100644 index 0000000000..dc627b0e68 --- /dev/null +++ b/merge_abc/src/assemblyProgram.cpp @@ -0,0 +1,51 @@ +/** + * 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. + */ + +#include "assemblyProgram.h" + +namespace panda::proto { +void Program::Serialize(const panda::pandasm::Program &program, proto_panda::Program &protoProgram) +{ + protoProgram.set_lang(static_cast(program.lang)); + + for (const auto &[name, record] : program.record_table) { + auto *recordMap = protoProgram.add_record_table(); + recordMap->set_key(name); + auto *protoRecord = recordMap->mutable_value(); + Record::Serialize(record, *protoRecord); + } + + for (const auto &[name, func] : program.function_table) { + auto *functionMap = protoProgram.add_function_table(); + functionMap->set_key(name); + auto *protoFunc = functionMap->mutable_value(); + Function::Serialize(func, *protoFunc); + } + // TODO: support function_synonyms + for (const auto &[name, array] : program.literalarray_table) { + auto *literalarrayMap = protoProgram.add_literalarray_table(); + literalarrayMap->set_key(name); + auto *protoArray = literalarrayMap->mutable_value(); + LiteralArray::Serialize(array, *protoArray); + } + for (const auto &str : program.strings) { + protoProgram.add_strings(str); + } + for (const auto &type : program.array_types) { + auto *protoType = protoProgram.add_array_types(); + Type::Serialize(type, *protoType); + } +} +} // panda::proto \ No newline at end of file diff --git a/merge_abc/src/assemblyProgram.h b/merge_abc/src/assemblyProgram.h new file mode 100644 index 0000000000..cb36aadfaf --- /dev/null +++ b/merge_abc/src/assemblyProgram.h @@ -0,0 +1,31 @@ +/** + * 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 MERGE_ABC_ASSEMBLY_PROGRAM_H +#define MERGE_ABC_ASSEMBLY_PROGRAM_H + +#include "assembly-program.h" +#include "assemblyRecord.h" +#include "assemblyFunction.h" +#include "assemblyLiterals.h" +#include "assemblyProgram.pb.h" + +namespace panda::proto { +class Program { +public: + static void Serialize(const panda::pandasm::Program &program, proto_panda::Program &protoProgram); +}; +} // panda::proto +#endif \ No newline at end of file diff --git a/merge_abc/src/assemblyRecord.cpp b/merge_abc/src/assemblyRecord.cpp new file mode 100644 index 0000000000..4609968741 --- /dev/null +++ b/merge_abc/src/assemblyRecord.cpp @@ -0,0 +1,42 @@ +/** + * 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. + */ + +#include "assemblyRecord.h" + +namespace panda::proto { +void Record::Serialize(const panda::pandasm::Record &record, proto_panda::Record &protoRecord) +{ + protoRecord.set_name(record.name); + protoRecord.set_conflict(record.conflict); + protoRecord.set_language(static_cast(record.language)); + auto *proto_record_meta = protoRecord.mutable_metadata(); + RecordMetadata::Serialize(*record.metadata, *proto_record_meta); + + for (const auto &field : record.field_list) { + auto *proto_field = protoRecord.add_field_list(); + Field::Serialize(field, *proto_field); + } + + protoRecord.set_params_num(record.params_num); + protoRecord.set_body_presence(record.body_presence); + protoRecord.set_source_file(record.source_file); + + const auto &location = record.file_location; + if (location.has_value()) { + auto *proto_location = protoRecord.mutable_file_location(); + FileLocation::Serialize(location.value(), *proto_location); + } +} +} // panda::proto \ No newline at end of file diff --git a/merge_abc/src/assemblyRecord.h b/merge_abc/src/assemblyRecord.h new file mode 100644 index 0000000000..aabc4dc424 --- /dev/null +++ b/merge_abc/src/assemblyRecord.h @@ -0,0 +1,31 @@ +/** + * 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 MERGE_ABC_ASSEMBLY_RECORD_H +#define MERGE_ABC_ASSEMBLY_RECORD_H + +#include "assembly-program.h" +#include "meta.h" +#include "assemblyField.h" +#include "assemblyFunction.h" +#include "assemblyRecord.pb.h" + +namespace panda::proto { +class Record { +public: + static void Serialize(const panda::pandasm::Record &record, proto_panda::Record &protoRecord); +}; +} // panda::proto +#endif \ No newline at end of file diff --git a/merge_abc/src/assemblyType.cpp b/merge_abc/src/assemblyType.cpp new file mode 100644 index 0000000000..ec1954e9a0 --- /dev/null +++ b/merge_abc/src/assemblyType.cpp @@ -0,0 +1,26 @@ +/** + * 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. + */ + +#include "assemblyType.h" + +namespace panda::proto { +void Type::Serialize(const panda::pandasm::Type type, proto_panda::Type &protoType) +{ + protoType.set_component_name(type.GetComponentName()); + protoType.set_rank(type.GetRank()); + protoType.set_name(type.GetName()); + protoType.set_type_id(static_cast(type.GetId())); +} +} // panda::proto \ No newline at end of file diff --git a/merge_abc/src/assemblyType.h b/merge_abc/src/assemblyType.h new file mode 100644 index 0000000000..00ae8652e7 --- /dev/null +++ b/merge_abc/src/assemblyType.h @@ -0,0 +1,28 @@ +/** + * 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 MERGE_ABC_ASSEMBLY_TYPE_H +#define MERGE_ABC_ASSEMBLY_TYPE_H + +#include "assembly-program.h" +#include "assemblyType.pb.h" + +namespace panda::proto { +class Type { +public: + static void Serialize(const panda::pandasm::Type type, proto_panda::Type &protoType); +}; +} // panda::proto +#endif \ No newline at end of file diff --git a/merge_abc/src/ideHelpers.cpp b/merge_abc/src/ideHelpers.cpp new file mode 100644 index 0000000000..5eb2384286 --- /dev/null +++ b/merge_abc/src/ideHelpers.cpp @@ -0,0 +1,36 @@ +/** + * 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. + */ + +#include "ideHelpers.h" + +namespace panda::proto { + +void SourceLocation::Serialize(const panda::pandasm::SourceLocation &location, + proto_panda::SourceLocation &protoLocation) +{ + auto *protoBegin = protoLocation.mutable_begin(); + SourcePosition::Serialize(location.begin, *protoBegin); + auto *protoEnd = protoLocation.mutable_end(); + SourcePosition::Serialize(location.end, *protoEnd); +} + +void SourcePosition::Serialize(const panda::pandasm::SourcePosition &position, + proto_panda::SourcePosition &protoPosition) +{ + protoPosition.set_line(position.line); + protoPosition.set_column(position.column); +} + +} // panda::proto \ No newline at end of file diff --git a/merge_abc/src/ideHelpers.h b/merge_abc/src/ideHelpers.h new file mode 100644 index 0000000000..ff0323c891 --- /dev/null +++ b/merge_abc/src/ideHelpers.h @@ -0,0 +1,37 @@ +/** + * 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 MERGE_ABC_IDE_HELPERS_H +#define MERGE_ABC_IDE_HELPERS_H + +#include "assembly-program.h" +#include "ideHelpers.pb.h" + +namespace panda::proto { + +class SourceLocation { +public: + static void Serialize(const panda::pandasm::SourceLocation &location, + proto_panda::SourceLocation &protoLocation); +}; + +class SourcePosition { +public: + static void Serialize(const panda::pandasm::SourcePosition &position, + proto_panda::SourcePosition &protoPosition); +}; + +} // panda::proto +#endif \ No newline at end of file diff --git a/merge_abc/src/meta.cpp b/merge_abc/src/meta.cpp new file mode 100644 index 0000000000..176d358b06 --- /dev/null +++ b/merge_abc/src/meta.cpp @@ -0,0 +1,82 @@ +/** + * 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. + */ +#include "meta.h" + +namespace panda::proto { + +void RecordMetadata::Serialize(const panda::pandasm::RecordMetadata &meta, proto_panda::RecordMetadata &protoMeta) +{ + auto *protoItemmetadata = protoMeta.mutable_father(); + ItemMetadata::Serialize(static_cast(meta), *protoItemmetadata); +} + +void FunctionMetadata::Serialize(const panda::pandasm::FunctionMetadata &meta, + proto_panda::FunctionMetadata &protoMeta) +{ + auto *protoItemmetadata = protoMeta.mutable_father(); + ItemMetadata::Serialize(static_cast(meta), *protoItemmetadata); +} + +void FieldMetadata::Serialize(const panda::pandasm::FieldMetadata &meta, proto_panda::FieldMetadata &protoMeta) +{ + auto *protoItemmetadata = protoMeta.mutable_father(); + ItemMetadata::Serialize(meta, *protoItemmetadata); + auto *protoType = protoMeta.mutable_field_type(); + Type::Serialize(meta.GetFieldType(), *protoType); + const auto val = meta.GetValue(); + if (val.has_value()) { + auto *protoValue = protoMeta.mutable_value(); + ScalarValue::Serialize(val.value(), *protoValue); + } +} + +void ParamMetadata::Serialize(const panda::pandasm::ParamMetadata &meta, proto_panda::ParamMetadata &protoMeta) +{ + auto *protoAnnometadata = protoMeta.mutable_father(); + AnnotationMetadata::Serialize(static_cast(meta), *protoAnnometadata); +} + +void ItemMetadata::Serialize(const panda::pandasm::ItemMetadata &meta, proto_panda::ItemMetadata &protoMeta) +{ + auto *protoAnnometadata = protoMeta.mutable_father(); + AnnotationMetadata::Serialize(static_cast(meta), *protoAnnometadata); + protoMeta.set_access_flags(meta.GetAccessFlags()); +} + +void AnnotationMetadata::Serialize(const panda::pandasm::AnnotationMetadata &meta, + proto_panda::AnnotationMetadata &protoMeta) +{ + auto *protoMetadata = protoMeta.mutable_father(); + Metadata::Serialize(static_cast(meta), *protoMetadata); + for (const auto &anno : meta.GetAnnotations()) { + auto *proto_anno = protoMeta.add_annotations(); + AnnotationData::Serialize(anno, *proto_anno); + } +} + +void Metadata::Serialize(const panda::pandasm::Metadata &meta, proto_panda::Metadata &protoMeta) +{ + for (const auto &attr : meta.GetBoolAttributes()) { + protoMeta.add_set_attributes(attr); + } + for (const auto &[name, attrs] : meta.GetAttributes()) { + auto *protoKeyVal = protoMeta.add_attributes(); + protoKeyVal->set_key(name); + for (const auto &attr : attrs) { + protoKeyVal->add_value(attr); + } + } +} +} // panda::proto diff --git a/merge_abc/src/meta.h b/merge_abc/src/meta.h new file mode 100644 index 0000000000..5561a473c7 --- /dev/null +++ b/merge_abc/src/meta.h @@ -0,0 +1,63 @@ +/** + * 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 MERGE_ABC_META_H +#define MERGE_ABC_META_H + +#include "assembly-program.h" +#include "annotation.h" +#include "assemblyType.h" +#include "meta.pb.h" + +namespace panda::proto { + +class RecordMetadata { +public: + static void Serialize(const panda::pandasm::RecordMetadata &meta, proto_panda::RecordMetadata &protoMeta); +}; + +class FunctionMetadata { +public: + static void Serialize(const panda::pandasm::FunctionMetadata &meta, + proto_panda::FunctionMetadata &protoMeta); +}; + +class FieldMetadata { +public: + static void Serialize(const panda::pandasm::FieldMetadata &meta, proto_panda::FieldMetadata &protoMeta); +}; + +class ParamMetadata { +public: + static void Serialize(const panda::pandasm::ParamMetadata &meta, proto_panda::ParamMetadata &protoMeta); +}; + +class ItemMetadata { +public: + static void Serialize(const panda::pandasm::ItemMetadata &meta, proto_panda::ItemMetadata &protoMeta); +}; + +class AnnotationMetadata { +public: + static void Serialize(const panda::pandasm::AnnotationMetadata &meta, + proto_panda::AnnotationMetadata &protoMeta); +}; + +class Metadata { +public: + static void Serialize(const panda::pandasm::Metadata &meta, proto_panda::Metadata &protoMeta); +}; +} // panda::proto +#endif \ No newline at end of file diff --git a/merge_abc/src/protobufSnapshotGenerator.cpp b/merge_abc/src/protobufSnapshotGenerator.cpp new file mode 100644 index 0000000000..9be9cf84e2 --- /dev/null +++ b/merge_abc/src/protobufSnapshotGenerator.cpp @@ -0,0 +1,31 @@ +/** + * 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. + */ + +#include "protobufSnapshotGenerator.h" +#include "assembly-program.h" +#include "assemblyProgram.h" + +namespace panda::proto { +void ProtobufSnapshotGenerator::GenerateSnapshot(const panda::pandasm::Program &program, const std::string &outputName) +{ + proto_panda::Program protoProgram; + + panda::proto::Program::Serialize(program, protoProgram); + + std::ofstream output(outputName, std::ios::out | std::ios::trunc | std::ios::binary); + protoProgram.SerializeToOstream(&output); + output.close(); +} +} // panda::proto diff --git a/merge_abc/src/protobufSnapshotGenerator.h b/merge_abc/src/protobufSnapshotGenerator.h new file mode 100644 index 0000000000..3d375e4159 --- /dev/null +++ b/merge_abc/src/protobufSnapshotGenerator.h @@ -0,0 +1,27 @@ +/** + * 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 MERGE_ABC_POROBUFSNAPSHOTGENERATOR_H +#define MERGE_ABC_POROBUFSNAPSHOTGENERATOR_H + +#include "assemblyProgram.h" + +namespace panda::proto { +class ProtobufSnapshotGenerator { +public: + static void GenerateSnapshot(const panda::pandasm::Program &prog, const std::string &outputName); +}; +} // panda::proto +#endif \ No newline at end of file -- Gitee From 63f6f627101e914766cddad6296c792f30a9cf66 Mon Sep 17 00:00:00 2001 From: gavin1012_hw Date: Thu, 18 Aug 2022 16:06:35 +0800 Subject: [PATCH 02/23] Support merge abc file via protobuf Signed-off-by: gavin1012_hw Change-Id: I52d1da4e92b978ca5a7b102a932d857ce3d2714e --- es2panda/aot/main.cpp | 12 +- merge_abc/BUILD.gn | 1 + merge_abc/src/annotation.cpp | 153 ++++++++++++++++++++ merge_abc/src/annotation.h | 28 +++- merge_abc/src/assemblyDebug.cpp | 20 +++ merge_abc/src/assemblyDebug.h | 3 + merge_abc/src/assemblyField.cpp | 15 ++ merge_abc/src/assemblyField.h | 1 + merge_abc/src/assemblyFileLocation.cpp | 8 + merge_abc/src/assemblyFileLocation.h | 1 + merge_abc/src/assemblyFunction.cpp | 70 +++++++++ merge_abc/src/assemblyFunction.h | 10 ++ merge_abc/src/assemblyIns.cpp | 29 ++++ merge_abc/src/assemblyIns.h | 1 + merge_abc/src/assemblyLabel.cpp | 9 ++ merge_abc/src/assemblyLabel.h | 1 + merge_abc/src/assemblyLiterals.cpp | 56 +++++++ merge_abc/src/assemblyLiterals.h | 3 + merge_abc/src/assemblyProgram.cpp | 44 ++++++ merge_abc/src/assemblyProgram.h | 8 + merge_abc/src/assemblyRecord.cpp | 19 +++ merge_abc/src/assemblyRecord.h | 1 + merge_abc/src/assemblyType.cpp | 8 +- merge_abc/src/assemblyType.h | 8 + merge_abc/src/ideHelpers.cpp | 18 +++ merge_abc/src/ideHelpers.h | 2 + merge_abc/src/meta.cpp | 88 +++++++++++ merge_abc/src/meta.h | 18 +++ merge_abc/src/protobufSnapshotGenerator.cpp | 18 +++ merge_abc/src/protobufSnapshotGenerator.h | 1 + 30 files changed, 647 insertions(+), 7 deletions(-) diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index 5247ab9d72..2f681e6077 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -125,12 +125,14 @@ static int GenerateProgram(panda::pandasm::Program *prog, std::unique_ptrcompilerProtoOutput().size() > 0) { - proto::ProtobufSnapshotGenerator::GenerateSnapshot(*prog, options->compilerProtoOutput()); - return 0; - } + std::string protoFileName = output.substr(0, output.rfind(".")) + ".bin"; + proto::ProtobufSnapshotGenerator::GenerateSnapshot(*prog, protoFileName); + + // std::cout << "protoFileName: " << protoFileName << std::endl; + panda::pandasm::Program deserializedProgram; + proto::ProtobufSnapshotGenerator::GenerateProgram(protoFileName, deserializedProgram); - if (!panda::pandasm::AsmEmitter::Emit(output, *prog, statp, mapsp, true)) { + if (!panda::pandasm::AsmEmitter::Emit(output, deserializedProgram, statp, mapsp, true)) { return 1; } diff --git a/merge_abc/BUILD.gn b/merge_abc/BUILD.gn index 8ba34522c5..8286935dde 100644 --- a/merge_abc/BUILD.gn +++ b/merge_abc/BUILD.gn @@ -39,6 +39,7 @@ protobuf_snapshot_generator_sources = [ config("panda_assembly_proto_public_config") { include_dirs = [ "$ark_root/assembler", + "$ark_root/libpandabase/mem", "$ark_root", "src", "$proto_out_dir", diff --git a/merge_abc/src/annotation.cpp b/merge_abc/src/annotation.cpp index 3257f31b84..bfb321bd4b 100644 --- a/merge_abc/src/annotation.cpp +++ b/merge_abc/src/annotation.cpp @@ -25,6 +25,15 @@ void AnnotationData::Serialize(const panda::pandasm::AnnotationData &anno, proto } } +void AnnotationData::Deserialize(const proto_panda::AnnotationData &protoAnno, panda::pandasm::AnnotationData &anno) +{ + AnnotationElement annotationElement; + for (const auto &protoElement : protoAnno.elements()) { + panda::pandasm::AnnotationElement element = annotationElement.Deserialize(protoElement); + anno.AddElement(std::move(element)); + } +} + void AnnotationElement::Serialize(const panda::pandasm::AnnotationElement &element, proto_panda::AnnotationElement &protoElement) { @@ -40,6 +49,22 @@ void AnnotationElement::Serialize(const panda::pandasm::AnnotationElement &eleme } } +panda::pandasm::AnnotationElement &AnnotationElement::Deserialize(const proto_panda::AnnotationElement &protoElement) +{ + if (protoElement.is_array()) { + ArrayValue arrayValue; + panda::pandasm::ArrayValue array = arrayValue.Deserialize(protoElement.array()); + auto element = allocator_->New(protoElement.name(), + std::make_unique(array)); + return *element; + } + ScalarValue scalarValue; + panda::pandasm::ScalarValue scalar = scalarValue.Deserialize(protoElement.scalar()); + auto element = allocator_->New(protoElement.name(), + std::make_unique(scalar)); + return *element; +} + void ScalarValue::Serialize(const panda::pandasm::ScalarValue &scalar, proto_panda::ScalarValue &protoScalar) { const auto &value_type = scalar.GetType(); @@ -104,6 +129,122 @@ void ScalarValue::Serialize(const panda::pandasm::ScalarValue &scalar, proto_pan protoScalar.set_type(type); } +panda::pandasm::ScalarValue ScalarValue::Deserialize(const proto_panda::ScalarValue &protoScalar) +{ + proto_panda::ScalarValue_VariantValueType scalarType = protoScalar.type(); + std::variant value; + switch (scalarType) + { + case proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_UINT64: { + value = static_cast(protoScalar.value_u64()); + break; + } + case proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_FLOAT: { + value = static_cast(protoScalar.value_f()); + break; + } + case proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_DOUBLE: { + value = static_cast(protoScalar.value_d()); + break; + } + case proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_STRING: { + value = static_cast(protoScalar.value_str()); + break; + } + case proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_PANDASM_TYPE: { + Type type; + value = static_cast(type.Deserialize(protoScalar.value_type())); + break; + } + case proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_ANNOTATION_DATA: { + auto protoAnnotationData = protoScalar.value_anno(); + auto value = allocator_->New(protoAnnotationData.record_name()); + AnnotationData::Deserialize(protoAnnotationData, *value); + break; + } + default: + UNREACHABLE(); + } + auto scalar = ScalarValue::CreateScalarValue(static_cast( + protoScalar.father().type()), value); + return scalar; +} + +panda::pandasm::ScalarValue ScalarValue::CreateScalarValue(const panda::pandasm::Value::Type &type, + std::variant &value) +{ + switch (type) + { + case panda::pandasm::Value::Type::U1: { + return panda::pandasm::ScalarValue::Create(static_cast( + std::get(value))); + } + case panda::pandasm::Value::Type::U8: { + return panda::pandasm::ScalarValue::Create(static_cast( + std::get(value))); + } + case panda::pandasm::Value::Type::U16: { + return panda::pandasm::ScalarValue::Create(static_cast( + std::get(value))); + } + case panda::pandasm::Value::Type::STRING_NULLPTR: { + return panda::pandasm::ScalarValue::Create( + static_cast(std::get(value))); + } + case panda::pandasm::Value::Type::U32: { + return panda::pandasm::ScalarValue::Create(static_cast( + std::get(value))); + } + case panda::pandasm::Value::Type::U64: { + return panda::pandasm::ScalarValue::Create(static_cast( + std::get(value))); + } + case panda::pandasm::Value::Type::I8: { + return panda::pandasm::ScalarValue::Create(static_cast( + std::get(value))); + } + case panda::pandasm::Value::Type::I16: { + return panda::pandasm::ScalarValue::Create(static_cast( + std::get(value))); + } + case panda::pandasm::Value::Type::I32: { + return panda::pandasm::ScalarValue::Create(static_cast( + std::get(value))); + } + case panda::pandasm::Value::Type::I64: { + return panda::pandasm::ScalarValue::Create(static_cast( + std::get(value))); + } + case panda::pandasm::Value::Type::F32: { + return panda::pandasm::ScalarValue::Create(std::get(value)); + } + case panda::pandasm::Value::Type::F64: { + return panda::pandasm::ScalarValue::Create(std::get(value)); + } + case panda::pandasm::Value::Type::STRING: { + return panda::pandasm::ScalarValue::Create( + std::get(value)); + } + case panda::pandasm::Value::Type::METHOD: { + return panda::pandasm::ScalarValue::Create( + std::get(value)); + } + case panda::pandasm::Value::Type::ENUM: { + return panda::pandasm::ScalarValue::Create(std::get(value)); + } + case panda::pandasm::Value::Type::RECORD: { + return panda::pandasm::ScalarValue::Create( + std::get(value)); + } + case panda::pandasm::Value::Type::ANNOTATION: { + return panda::pandasm::ScalarValue::Create( + std::get(value)); + } + default: + UNREACHABLE(); + } +} + void ArrayValue::Serialize(const panda::pandasm::ArrayValue &array, proto_panda::ArrayValue &protoArray) { protoArray.mutable_father()->set_type(static_cast(array.GetType())); @@ -114,4 +255,16 @@ void ArrayValue::Serialize(const panda::pandasm::ArrayValue &array, proto_panda: } } +panda::pandasm::ArrayValue &ArrayValue::Deserialize(const proto_panda::ArrayValue &protoArray) +{ + std::vector values; + ScalarValue scalarValue; + for (const auto &protoValue : protoArray.values()) { + panda::pandasm::ScalarValue scalar = scalarValue.Deserialize(protoValue); + values.emplace_back(std::move(scalar)); + } + auto array = allocator_->New( + static_cast(protoArray.component_type()), values); + return *array; +} } // panda::proto \ No newline at end of file diff --git a/merge_abc/src/annotation.h b/merge_abc/src/annotation.h index fdae663fe6..59ffa5ea7f 100644 --- a/merge_abc/src/annotation.h +++ b/merge_abc/src/annotation.h @@ -19,27 +19,53 @@ #include "assembly-program.h" #include "assemblyType.h" #include "annotation.pb.h" +#include "arena_allocator.h" namespace panda::proto { class AnnotationData { public: static void Serialize(const panda::pandasm::AnnotationData &anno, proto_panda::AnnotationData &protoAnno); + static void Deserialize(const proto_panda::AnnotationData &protoAnno, panda::pandasm::AnnotationData &anno); }; class AnnotationElement { public: + explicit AnnotationElement() + : allocator_(std::make_unique(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true)) + { + } static void Serialize(const panda::pandasm::AnnotationElement &element, proto_panda::AnnotationElement &protoElement); + panda::pandasm::AnnotationElement &Deserialize(const proto_panda::AnnotationElement &protoElement); +private: + std::unique_ptr allocator_ {}; }; class ScalarValue { public: + explicit ScalarValue() + : allocator_(std::make_unique(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true)) + { + } static void Serialize(const panda::pandasm::ScalarValue &scalar, proto_panda::ScalarValue &protoScalar); + panda::pandasm::ScalarValue Deserialize(const proto_panda::ScalarValue &protoScalar); + static panda::pandasm::ScalarValue CreateScalarValue(const panda::pandasm::Value::Type &type, + std::variant + &value); +private: + std::unique_ptr allocator_ {}; }; class ArrayValue { public: + explicit ArrayValue() + : allocator_(std::make_unique(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true)) + { + } static void Serialize(const panda::pandasm::ArrayValue &array, proto_panda::ArrayValue &protoArray); + panda::pandasm::ArrayValue &Deserialize(const proto_panda::ArrayValue &protoArray); +private: + std::unique_ptr allocator_ {}; }; } // panda::proto -#endif \ No newline at end of file +#endif diff --git a/merge_abc/src/assemblyDebug.cpp b/merge_abc/src/assemblyDebug.cpp index 7141d9e862..7d12ea809c 100644 --- a/merge_abc/src/assemblyDebug.cpp +++ b/merge_abc/src/assemblyDebug.cpp @@ -25,6 +25,15 @@ void DebuginfoIns::Serialize(const panda::pandasm::debuginfo::Ins &debug, proto_ protoDebug.set_bound_right(debug.bound_right); } +void DebuginfoIns::Deserialize(const proto_panda::DebuginfoIns &protoDebug, panda::pandasm::debuginfo::Ins &debug) +{ + debug.line_number = protoDebug.line_number(); + debug.column_number = protoDebug.column_number(); + debug.whole_line = protoDebug.whole_line(); + debug.bound_left = protoDebug.bound_left(); + debug.bound_right = protoDebug.bound_right(); +} + void LocalVariable::Serialize(const panda::pandasm::debuginfo::LocalVariable &debug, proto_panda::LocalVariable &protoDebug) { @@ -35,4 +44,15 @@ void LocalVariable::Serialize(const panda::pandasm::debuginfo::LocalVariable &de protoDebug.set_start(debug.start); protoDebug.set_length(debug.length); } + +void LocalVariable::Deserialize(const proto_panda::LocalVariable &protoDebug, + panda::pandasm::debuginfo::LocalVariable &debug) +{ + debug.name = protoDebug.name(); + debug.signature = protoDebug.signature(); + debug.signature_type = protoDebug.signature_type(); + debug.reg = protoDebug.reg(); + debug.start = protoDebug.start(); + debug.length = protoDebug.length(); +} } // panda::proto \ No newline at end of file diff --git a/merge_abc/src/assemblyDebug.h b/merge_abc/src/assemblyDebug.h index edb6445b67..7e705a32cb 100644 --- a/merge_abc/src/assemblyDebug.h +++ b/merge_abc/src/assemblyDebug.h @@ -23,12 +23,15 @@ namespace panda::proto { class DebuginfoIns { public: static void Serialize(const panda::pandasm::debuginfo::Ins &debug, proto_panda::DebuginfoIns &protoDebug); + static void Deserialize(const proto_panda::DebuginfoIns &protoDebug, panda::pandasm::debuginfo::Ins &debug); }; class LocalVariable { public: static void Serialize(const panda::pandasm::debuginfo::LocalVariable &debug, proto_panda::LocalVariable &protoDebug); + static void Deserialize(const proto_panda::LocalVariable &protoDebug, + panda::pandasm::debuginfo::LocalVariable &debug); }; } // panda::proto #endif \ No newline at end of file diff --git a/merge_abc/src/assemblyField.cpp b/merge_abc/src/assemblyField.cpp index 0c64e917ac..dbafa41518 100644 --- a/merge_abc/src/assemblyField.cpp +++ b/merge_abc/src/assemblyField.cpp @@ -30,4 +30,19 @@ void Field::Serialize(const panda::pandasm::Field &field, proto_panda::Field &pr protoField.set_bound_right(field.bound_right); protoField.set_is_defined(field.is_defined); } + +void Field::Deserialize(const proto_panda::Field &protoField, panda::pandasm::Field &field) +{ + Type type; + FieldMetadata fieldMetadata; + + field.type = type.Deserialize(protoField.type()); + field.name = protoField.name(); + fieldMetadata.Deserialize(protoField.metadata(), field.metadata); + field.line_of_def = protoField.line_of_def(); + field.whole_line = protoField.whole_line(); + field.bound_left = protoField.bound_left(); + field.bound_right = protoField.bound_right(); + field.is_defined = protoField.is_defined(); +} } // panda::proto \ No newline at end of file diff --git a/merge_abc/src/assemblyField.h b/merge_abc/src/assemblyField.h index 381d32b0bf..8101141cfa 100644 --- a/merge_abc/src/assemblyField.h +++ b/merge_abc/src/assemblyField.h @@ -25,6 +25,7 @@ namespace panda::proto { class Field { public: static void Serialize(const panda::pandasm::Field &field, proto_panda::Field &protoField); + static void Deserialize(const proto_panda::Field &protoField, panda::pandasm::Field &field); }; } // panda::proto #endif \ No newline at end of file diff --git a/merge_abc/src/assemblyFileLocation.cpp b/merge_abc/src/assemblyFileLocation.cpp index f2014192c5..83b328bd8d 100644 --- a/merge_abc/src/assemblyFileLocation.cpp +++ b/merge_abc/src/assemblyFileLocation.cpp @@ -23,4 +23,12 @@ void FileLocation::Serialize(const panda::pandasm::FileLocation &location, proto protoLocation.set_bound_right(location.bound_right); protoLocation.set_is_defined(location.is_defined); } + +void FileLocation::Deserialize(const proto_panda::FileLocation &protoLocation, panda::pandasm::FileLocation &location) +{ + location.whole_line = protoLocation.whole_line(); + location.bound_left = protoLocation.bound_left(); + location.bound_right = protoLocation.bound_right(); + location.is_defined = protoLocation.is_defined(); +} } // panda::proto diff --git a/merge_abc/src/assemblyFileLocation.h b/merge_abc/src/assemblyFileLocation.h index 0800c2851c..b289fc20e8 100644 --- a/merge_abc/src/assemblyFileLocation.h +++ b/merge_abc/src/assemblyFileLocation.h @@ -24,6 +24,7 @@ namespace panda::proto { class FileLocation { public: static void Serialize(const panda::pandasm::FileLocation &location, proto_panda::FileLocation &protoLocation); + static void Deserialize(const proto_panda::FileLocation &protoLocation, panda::pandasm::FileLocation &location); }; } // panda::proto #endif \ No newline at end of file diff --git a/merge_abc/src/assemblyFunction.cpp b/merge_abc/src/assemblyFunction.cpp index 97eccfbe40..e64878515e 100644 --- a/merge_abc/src/assemblyFunction.cpp +++ b/merge_abc/src/assemblyFunction.cpp @@ -26,6 +26,16 @@ void CatchBlock::Serialize(const panda::pandasm::Function::CatchBlock &block, pr protoBlock.set_catch_end_label(block.catch_end_label); } +void CatchBlock::Deserialize(const proto_panda::CatchBlock &protoBlock, panda::pandasm::Function::CatchBlock &block) +{ + block.whole_line = protoBlock.whole_line(); + block.exception_record = protoBlock.exception_record(); + block.try_begin_label = protoBlock.try_begin_label(); + block.try_end_label = protoBlock.try_end_label(); + block.catch_begin_label = protoBlock.catch_begin_label(); + block.catch_end_label = protoBlock.catch_end_label(); +} + void Parameter::Serialize(const panda::pandasm::Function::Parameter ¶m, proto_panda::Parameter &protoParam) { auto *type = protoParam.mutable_type(); @@ -34,6 +44,12 @@ void Parameter::Serialize(const panda::pandasm::Function::Parameter ¶m, prot ParamMetadata::Serialize(*(param.metadata), *metadata); } +void Parameter::Deserialize(const proto_panda::Parameter &protoParam, panda::pandasm::Function::Parameter ¶m) +{ + ParamMetadata paramMetadata; + paramMetadata.Deserialize(protoParam.metadata(), param.metadata); +} + void Function::Serialize(const panda::pandasm::Function &function, proto_panda::Function &protoFunction) { protoFunction.set_name(function.name); @@ -90,4 +106,58 @@ void Function::Serialize(const panda::pandasm::Function &function, proto_panda:: FileLocation::Serialize(fileLocation.value(), *protoFileLocation); } } + +void Function::Deserialize(const proto_panda::Function &protoFunction, panda::pandasm::Function &function) +{ + FunctionMetadata functionMetadata; + functionMetadata.Deserialize(protoFunction.metadata(), function.metadata); + for (const auto &labelUnit : protoFunction.label_table()) { + auto name = labelUnit.key(); + auto protoLabel = labelUnit.value(); + panda::pandasm::Label label(name); + Label::Deserialize(protoLabel, label); + function.label_table.insert({name, label}); + } + + for (const auto &protoIns : protoFunction.ins()) { + panda::pandasm::Ins ins; + Ins::Deserialize(protoIns, ins); + function.ins.emplace_back(std::move(ins)); + } + + for (const auto &protoLocalVariable : protoFunction.local_variable_debug()) { + panda::pandasm::debuginfo::LocalVariable localVariable; + LocalVariable::Deserialize(protoLocalVariable, localVariable); + function.local_variable_debug.emplace_back(std::move(localVariable)); + } + + function.source_file = protoFunction.source_file(); + function.source_file = protoFunction.source_code(); + + for (const auto &protoCatchBlock : protoFunction.catch_blocks()) { + auto catchBlock = allocator_->New(); + CatchBlock::Deserialize(protoCatchBlock, *catchBlock); + function.catch_blocks.emplace_back(std::move(*catchBlock)); + } + + function.value_of_first_param = protoFunction.value_of_first_param(); + function.regs_num = protoFunction.regs_num(); + + Type type; + + for (const auto &protoParam : protoFunction.params()) { + auto paramType = type.Deserialize(protoParam.type()); + panda::pandasm::Function::Parameter param(paramType, panda::panda_file::SourceLang::ECMASCRIPT); + Parameter::Deserialize(protoParam, param); + function.params.emplace_back(std::move(param)); + } + + function.body_presence = protoFunction.body_presence(); + function.return_type = type.Deserialize(protoFunction.return_type()); + SourceLocation::Deserialize(protoFunction.body_location(), function.body_location); + + if (protoFunction.has_file_location()) { + FileLocation::Deserialize(protoFunction.file_location(), function.file_location.value()); + } +} } // panda::proto \ No newline at end of file diff --git a/merge_abc/src/assemblyFunction.h b/merge_abc/src/assemblyFunction.h index ba3f42bd53..bf9dcb643c 100644 --- a/merge_abc/src/assemblyFunction.h +++ b/merge_abc/src/assemblyFunction.h @@ -25,21 +25,31 @@ #include "assemblyFileLocation.h" #include "meta.h" #include "assemblyFunction.pb.h" +#include "arena_allocator.h" namespace panda::proto { class CatchBlock { public: static void Serialize(const panda::pandasm::Function::CatchBlock &block, proto_panda::CatchBlock &protoBlock); + static void Deserialize(const proto_panda::CatchBlock &protoBlock, panda::pandasm::Function::CatchBlock &block); }; class Parameter { public: static void Serialize(const panda::pandasm::Function::Parameter ¶m, proto_panda::Parameter &protoParam); + static void Deserialize(const proto_panda::Parameter &protoParam, panda::pandasm::Function::Parameter ¶m); }; class Function { public: + explicit Function() + : allocator_(std::make_unique(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true)) + { + } static void Serialize(const panda::pandasm::Function &function, proto_panda::Function &protoFunction); + void Deserialize(const proto_panda::Function &protoFunction, panda::pandasm::Function &function); +private: + std::unique_ptr allocator_ {}; }; } // panda::proto #endif diff --git a/merge_abc/src/assemblyIns.cpp b/merge_abc/src/assemblyIns.cpp index 0805c0c509..465b7a8fbc 100644 --- a/merge_abc/src/assemblyIns.cpp +++ b/merge_abc/src/assemblyIns.cpp @@ -43,4 +43,33 @@ void Ins::Serialize(const panda::pandasm::Ins &insn, proto_panda::Ins &protoInsn auto *protoDebug = protoInsn.mutable_ins_debug(); DebuginfoIns::Serialize(insn.ins_debug, *protoDebug); } + +void Ins::Deserialize(const proto_panda::Ins &protoInsn, panda::pandasm::Ins &insn) +{ + insn.opcode = static_cast(protoInsn.opcode()); + for (const auto &protoReg : protoInsn.regs()) { + insn.regs.push_back(static_cast(protoReg)); + } + for (const auto &protoId : protoInsn.ids()) { + insn.ids.push_back(protoId); + } + for (const auto &protoImm : protoInsn.imms()) { + switch (protoImm.type_case()) { + case proto_panda::Ins_IType::kValueInt: { + insn.imms.push_back(protoImm.value_int()); + break; + } + case proto_panda::Ins_IType::kValueDouble: { + insn.imms.push_back(protoImm.value_double()); + break; + } + default: + UNREACHABLE(); + } + } + insn.label = protoInsn.label(); + insn.set_label = protoInsn.set_label(); + const proto_panda::DebuginfoIns protoDebugInfoIns = protoInsn.ins_debug(); + DebuginfoIns::Deserialize(protoDebugInfoIns, insn.ins_debug); +} } // panda::proto \ No newline at end of file diff --git a/merge_abc/src/assemblyIns.h b/merge_abc/src/assemblyIns.h index 607ab0be6f..6c53425a21 100644 --- a/merge_abc/src/assemblyIns.h +++ b/merge_abc/src/assemblyIns.h @@ -24,6 +24,7 @@ namespace panda::proto { class Ins { public: static void Serialize(const panda::pandasm::Ins &insn, proto_panda::Ins &protoInsn); + static void Deserialize(const proto_panda::Ins &protoInsn, panda::pandasm::Ins &insn); }; } // panda::proto #endif \ No newline at end of file diff --git a/merge_abc/src/assemblyLabel.cpp b/merge_abc/src/assemblyLabel.cpp index 2000002ad6..4514dd4e0d 100644 --- a/merge_abc/src/assemblyLabel.cpp +++ b/merge_abc/src/assemblyLabel.cpp @@ -25,4 +25,13 @@ void Label::Serialize(const panda::pandasm::Label &label, proto_panda::Label &pr FileLocation::Serialize(fileLocation.value(), *protoLocation); } } + +void Label::Deserialize(const proto_panda::Label &protoLabel, panda::pandasm::Label &label) +{ + label.name = protoLabel.name(); + if (protoLabel.has_file_location()) { + proto_panda::FileLocation protoLocation = protoLabel.file_location(); + FileLocation::Deserialize(protoLocation, label.file_location.value()); + } +} } // panda::proto \ No newline at end of file diff --git a/merge_abc/src/assemblyLabel.h b/merge_abc/src/assemblyLabel.h index 0beb0c15dd..91cb08dc7f 100644 --- a/merge_abc/src/assemblyLabel.h +++ b/merge_abc/src/assemblyLabel.h @@ -24,6 +24,7 @@ namespace panda::proto { class Label { public: static void Serialize(const panda::pandasm::Label &label, proto_panda::Label &protoLabel); + static void Deserialize(const proto_panda::Label &protoLabel, panda::pandasm::Label &label); }; } // panda::proto #endif \ No newline at end of file diff --git a/merge_abc/src/assemblyLiterals.cpp b/merge_abc/src/assemblyLiterals.cpp index 84e2ab1d06..3a3b6c05f1 100644 --- a/merge_abc/src/assemblyLiterals.cpp +++ b/merge_abc/src/assemblyLiterals.cpp @@ -58,6 +58,47 @@ void VariantValue::Serialize(const LiteralValueType &value, proto_panda::Variant } } +void VariantValue::Deserialize(const proto_panda::VariantValue &protoValue, LiteralValueType &value) +{ + auto type = protoValue.type(); + switch(type) { + case proto_panda::VariantValue_VariantValueType_BOOL: { + value = static_cast(protoValue.value_int()); + return; + } + case proto_panda::VariantValue_VariantValueType_U8: { + value = static_cast(protoValue.value_int()); + return; + } + case proto_panda::VariantValue_VariantValueType_U16: { + value = static_cast(protoValue.value_int()); + return; + } + case proto_panda::VariantValue_VariantValueType_U32: { + value = static_cast(protoValue.value_int()); + return; + } + case proto_panda::VariantValue_VariantValueType_U64: { + value = static_cast(protoValue.value_int()); + return; + } + case proto_panda::VariantValue_VariantValueType_F32: { + value = protoValue.value_f(); + return; + } + case proto_panda::VariantValue_VariantValueType_F64: { + value = protoValue.value_d(); + return; + } + case proto_panda::VariantValue_VariantValueType_STRING: { + value = protoValue.value_str(); + return; + } + default: + UNREACHABLE(); + } +} + void LiteralArray::Serialize(const panda::pandasm::LiteralArray &array, proto_panda::LiteralArray &protoArray) { for (const auto &literal : array.literals_) { @@ -66,10 +107,25 @@ void LiteralArray::Serialize(const panda::pandasm::LiteralArray &array, proto_pa } } +void LiteralArray::Deserialize(const proto_panda::LiteralArray &protoArray, panda::pandasm::LiteralArray &array) +{ + for (const auto &protoLiteral : protoArray.literals()) { + panda::pandasm::LiteralArray::Literal literal; + Literal::Deserialize(protoLiteral, literal); + array.literals_.emplace_back(literal); + } +} + void Literal::Serialize(const panda::pandasm::LiteralArray::Literal &literal, proto_panda::Literal &protoLiteral) { protoLiteral.set_tag(static_cast(literal.tag_)); auto *value = protoLiteral.mutable_value(); VariantValue::Serialize(literal.value_, *value); } + +void Literal::Deserialize(const proto_panda::Literal &protoLiteral, panda::pandasm::LiteralArray::Literal &literal) +{ + literal.tag_ = static_cast(protoLiteral.tag()); + VariantValue::Deserialize(protoLiteral.value(), literal.value_); +} } // panda::proto diff --git a/merge_abc/src/assemblyLiterals.h b/merge_abc/src/assemblyLiterals.h index 9d23d237fc..9d3ada71ea 100644 --- a/merge_abc/src/assemblyLiterals.h +++ b/merge_abc/src/assemblyLiterals.h @@ -24,16 +24,19 @@ class VariantValue { public: using LiteralValueType = std::variant; static void Serialize(const LiteralValueType &value, proto_panda::VariantValue &protoValue); + static void Deserialize(const proto_panda::VariantValue &protoValue, LiteralValueType &value); }; class LiteralArray { public: static void Serialize(const panda::pandasm::LiteralArray &array, proto_panda::LiteralArray &protoArray); + static void Deserialize(const proto_panda::LiteralArray &protoArray, panda::pandasm::LiteralArray &array); }; class Literal { public: static void Serialize(const panda::pandasm::LiteralArray::Literal &literal, proto_panda::Literal &protoLiteral); + static void Deserialize(const proto_panda::Literal &protoLiteral, panda::pandasm::LiteralArray::Literal &literal); }; } // panda::proto #endif \ No newline at end of file diff --git a/merge_abc/src/assemblyProgram.cpp b/merge_abc/src/assemblyProgram.cpp index dc627b0e68..324d02be63 100644 --- a/merge_abc/src/assemblyProgram.cpp +++ b/merge_abc/src/assemblyProgram.cpp @@ -48,4 +48,48 @@ void Program::Serialize(const panda::pandasm::Program &program, proto_panda::Pro Type::Serialize(type, *protoType); } } + +void Program::Deserialize(const proto_panda::Program &protoProgram, panda::pandasm::Program &program) +{ + program.lang = static_cast(protoProgram.lang()); + + for (const auto &recordUnit : protoProgram.record_table()) { + auto name = recordUnit.key(); + auto protoRecord = recordUnit.value(); + auto record = panda::pandasm::Record(protoRecord.name(), + static_cast(protoRecord.language())); + Record::Deserialize(protoRecord, record); + program.record_table.insert({name, std::move(record)}); + } + + Function functionDeserialization; + for (const auto &functionUnit : protoProgram.function_table()) { + auto name = functionUnit.key(); + auto protoFunction = functionUnit.value(); + auto function = allocator_->New(protoFunction.name(), + static_cast(protoFunction.language())); + functionDeserialization.Deserialize(protoFunction, *function); + program.function_table.insert({name, std::move(*function)}); + } + + // TODO: support function_synonyms + + for (const auto &literalUnit : protoProgram.literalarray_table()) { + auto name = literalUnit.key(); + auto protoLiteralArray = literalUnit.value(); + panda::pandasm::LiteralArray literalArray; + LiteralArray::Deserialize(protoLiteralArray, literalArray); + program.literalarray_table.insert({name, std::move(literalArray)}); + } + + for (const auto &protoString : protoProgram.strings()) { + program.strings.insert(protoString); + } + + Type type; + for (const auto &protoArrayType : protoProgram.array_types()) { + auto arrayType = type.Deserialize(protoArrayType); + program.array_types.insert(std::move(arrayType)); + } +} } // panda::proto \ No newline at end of file diff --git a/merge_abc/src/assemblyProgram.h b/merge_abc/src/assemblyProgram.h index cb36aadfaf..d19279ad1b 100644 --- a/merge_abc/src/assemblyProgram.h +++ b/merge_abc/src/assemblyProgram.h @@ -21,11 +21,19 @@ #include "assemblyFunction.h" #include "assemblyLiterals.h" #include "assemblyProgram.pb.h" +#include "arena_allocator.h" namespace panda::proto { class Program { public: + explicit Program() + : allocator_(std::make_unique(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true)) + { + } static void Serialize(const panda::pandasm::Program &program, proto_panda::Program &protoProgram); + void Deserialize(const proto_panda::Program &protoProgram, panda::pandasm::Program &program); +private: + std::unique_ptr allocator_ {}; }; } // panda::proto #endif \ No newline at end of file diff --git a/merge_abc/src/assemblyRecord.cpp b/merge_abc/src/assemblyRecord.cpp index 4609968741..e7bf95d037 100644 --- a/merge_abc/src/assemblyRecord.cpp +++ b/merge_abc/src/assemblyRecord.cpp @@ -39,4 +39,23 @@ void Record::Serialize(const panda::pandasm::Record &record, proto_panda::Record FileLocation::Serialize(location.value(), *proto_location); } } + +void Record::Deserialize(const proto_panda::Record &protoRecord, panda::pandasm::Record &record) +{ + record.conflict = protoRecord.conflict(); + RecordMetadata recordMetadata; + recordMetadata.Deserialize(protoRecord.metadata(), record.metadata); + for (const auto &protoField : protoRecord.field_list()) { + auto recordField = panda::pandasm::Field(panda::panda_file::SourceLang::ECMASCRIPT); + Field::Deserialize(protoField, recordField); + record.field_list.emplace_back(std::move(recordField)); + } + record.params_num = protoRecord.params_num(); + record.body_presence = protoRecord.body_presence(); + record.source_file = protoRecord.source_file(); + if (protoRecord.has_file_location()) { + const auto &protoLocation = protoRecord.file_location(); + FileLocation::Deserialize(protoLocation, record.file_location.value()); + } +} } // panda::proto \ No newline at end of file diff --git a/merge_abc/src/assemblyRecord.h b/merge_abc/src/assemblyRecord.h index aabc4dc424..60f6caf2f8 100644 --- a/merge_abc/src/assemblyRecord.h +++ b/merge_abc/src/assemblyRecord.h @@ -26,6 +26,7 @@ namespace panda::proto { class Record { public: static void Serialize(const panda::pandasm::Record &record, proto_panda::Record &protoRecord); + static void Deserialize(const proto_panda::Record &protoRecord, panda::pandasm::Record &record); }; } // panda::proto #endif \ No newline at end of file diff --git a/merge_abc/src/assemblyType.cpp b/merge_abc/src/assemblyType.cpp index ec1954e9a0..d3bddd2b45 100644 --- a/merge_abc/src/assemblyType.cpp +++ b/merge_abc/src/assemblyType.cpp @@ -17,10 +17,16 @@ namespace panda::proto { void Type::Serialize(const panda::pandasm::Type type, proto_panda::Type &protoType) -{ +{ protoType.set_component_name(type.GetComponentName()); protoType.set_rank(type.GetRank()); protoType.set_name(type.GetName()); protoType.set_type_id(static_cast(type.GetId())); } + +panda::pandasm::Type &Type::Deserialize(const proto_panda::Type &protoType) +{ + auto type = allocator_->New(protoType.component_name(), protoType.rank()); + return *type; +} } // panda::proto \ No newline at end of file diff --git a/merge_abc/src/assemblyType.h b/merge_abc/src/assemblyType.h index 00ae8652e7..f744609568 100644 --- a/merge_abc/src/assemblyType.h +++ b/merge_abc/src/assemblyType.h @@ -18,11 +18,19 @@ #include "assembly-program.h" #include "assemblyType.pb.h" +#include "arena_allocator.h" namespace panda::proto { class Type { public: + explicit Type() + : allocator_(std::make_unique(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true)) + { + } static void Serialize(const panda::pandasm::Type type, proto_panda::Type &protoType); + panda::pandasm::Type &Deserialize(const proto_panda::Type &protoType); +private: + std::unique_ptr allocator_ {}; }; } // panda::proto #endif \ No newline at end of file diff --git a/merge_abc/src/ideHelpers.cpp b/merge_abc/src/ideHelpers.cpp index 5eb2384286..143d722751 100644 --- a/merge_abc/src/ideHelpers.cpp +++ b/merge_abc/src/ideHelpers.cpp @@ -26,6 +26,17 @@ void SourceLocation::Serialize(const panda::pandasm::SourceLocation &location, SourcePosition::Serialize(location.end, *protoEnd); } +void SourceLocation::Deserialize(const proto_panda::SourceLocation &protoLocation, + panda::pandasm::SourceLocation &location) +{ + if (protoLocation.has_begin()) { + SourcePosition::Deserialize(protoLocation.begin(), location.begin); + } + if (protoLocation.has_end()) { + SourcePosition::Deserialize(protoLocation.end(), location.end); + } +} + void SourcePosition::Serialize(const panda::pandasm::SourcePosition &position, proto_panda::SourcePosition &protoPosition) { @@ -33,4 +44,11 @@ void SourcePosition::Serialize(const panda::pandasm::SourcePosition &position, protoPosition.set_column(position.column); } +void SourcePosition::Deserialize(const proto_panda::SourcePosition &protoPosition, + panda::pandasm::SourcePosition &position) +{ + position.line = protoPosition.line(); + position.column = protoPosition.column(); +} + } // panda::proto \ No newline at end of file diff --git a/merge_abc/src/ideHelpers.h b/merge_abc/src/ideHelpers.h index ff0323c891..8212f960ea 100644 --- a/merge_abc/src/ideHelpers.h +++ b/merge_abc/src/ideHelpers.h @@ -25,12 +25,14 @@ class SourceLocation { public: static void Serialize(const panda::pandasm::SourceLocation &location, proto_panda::SourceLocation &protoLocation); + static void Deserialize(const proto_panda::SourceLocation &protoLocation, panda::pandasm::SourceLocation &location); }; class SourcePosition { public: static void Serialize(const panda::pandasm::SourcePosition &position, proto_panda::SourcePosition &protoPosition); + static void Deserialize(const proto_panda::SourcePosition &protoPosition, panda::pandasm::SourcePosition &position); }; } // panda::proto diff --git a/merge_abc/src/meta.cpp b/merge_abc/src/meta.cpp index 176d358b06..21d046fd87 100644 --- a/merge_abc/src/meta.cpp +++ b/merge_abc/src/meta.cpp @@ -22,6 +22,20 @@ void RecordMetadata::Serialize(const panda::pandasm::RecordMetadata &meta, proto ItemMetadata::Serialize(static_cast(meta), *protoItemmetadata); } +void RecordMetadata::Deserialize(const proto_panda::RecordMetadata &protoMeta, + std::unique_ptr &meta) +{ + auto protoItemMetadata = protoMeta.father(); + ItemMetadata::Deserialize(protoItemMetadata, *meta); + + auto protoAnnoMetadata = protoItemMetadata.father(); + AnnotationMetadata annotationMetadata; + annotationMetadata.Deserialize(protoAnnoMetadata, *meta); + + auto protoMetadata = protoAnnoMetadata.father(); + Metadata::Deserialize(protoMetadata, *meta); +} + void FunctionMetadata::Serialize(const panda::pandasm::FunctionMetadata &meta, proto_panda::FunctionMetadata &protoMeta) { @@ -29,6 +43,20 @@ void FunctionMetadata::Serialize(const panda::pandasm::FunctionMetadata &meta, ItemMetadata::Serialize(static_cast(meta), *protoItemmetadata); } +void FunctionMetadata::Deserialize(const proto_panda::FunctionMetadata &protoMeta, + std::unique_ptr &meta) +{ + auto protoItemMetadata = protoMeta.father(); + ItemMetadata::Deserialize(protoItemMetadata, *meta); + + auto protoAnnoMetadata = protoItemMetadata.father(); + AnnotationMetadata annotationMetadata; + annotationMetadata.Deserialize(protoAnnoMetadata, *meta); + + auto protoMetadata = protoAnnoMetadata.father(); + Metadata::Deserialize(protoMetadata, *meta); +} + void FieldMetadata::Serialize(const panda::pandasm::FieldMetadata &meta, proto_panda::FieldMetadata &protoMeta) { auto *protoItemmetadata = protoMeta.mutable_father(); @@ -42,12 +70,41 @@ void FieldMetadata::Serialize(const panda::pandasm::FieldMetadata &meta, proto_p } } +void FieldMetadata::Deserialize(const proto_panda::FieldMetadata &protoMeta, + std::unique_ptr &meta) +{ + auto protoItemMetadata = protoMeta.father(); + ItemMetadata::Deserialize(protoItemMetadata, *meta); + auto protoAnnoMetadata = protoItemMetadata.father(); + AnnotationMetadata annotationMetadata; + annotationMetadata.Deserialize(protoAnnoMetadata, *meta); + auto protoMetadata = protoAnnoMetadata.father(); + Metadata::Deserialize(protoMetadata, *meta); + + Type type; + auto fieldType = type.Deserialize(protoMeta.field_type()); + meta->SetFieldType(fieldType); + ScalarValue scalarValue; + if (protoMeta.has_value()) { + auto scalar = scalarValue.Deserialize(protoMeta.value()); + meta->SetValue(scalar); + } +} + void ParamMetadata::Serialize(const panda::pandasm::ParamMetadata &meta, proto_panda::ParamMetadata &protoMeta) { auto *protoAnnometadata = protoMeta.mutable_father(); AnnotationMetadata::Serialize(static_cast(meta), *protoAnnometadata); } +void ParamMetadata::Deserialize(const proto_panda::ParamMetadata &protoMeta, + std::unique_ptr &meta) +{ + auto protoAnnoMetadata = protoMeta.father(); + AnnotationMetadata annotationMetadata; + annotationMetadata.Deserialize(protoAnnoMetadata, *meta); +} + void ItemMetadata::Serialize(const panda::pandasm::ItemMetadata &meta, proto_panda::ItemMetadata &protoMeta) { auto *protoAnnometadata = protoMeta.mutable_father(); @@ -55,6 +112,11 @@ void ItemMetadata::Serialize(const panda::pandasm::ItemMetadata &meta, proto_pan protoMeta.set_access_flags(meta.GetAccessFlags()); } +void ItemMetadata::Deserialize(const proto_panda::ItemMetadata &protoMeta, panda::pandasm::ItemMetadata &meta) +{ + meta.SetAccessFlags(protoMeta.access_flags()); +} + void AnnotationMetadata::Serialize(const panda::pandasm::AnnotationMetadata &meta, proto_panda::AnnotationMetadata &protoMeta) { @@ -66,6 +128,19 @@ void AnnotationMetadata::Serialize(const panda::pandasm::AnnotationMetadata &met } } +void AnnotationMetadata::Deserialize(const proto_panda::AnnotationMetadata &protoMeta, + panda::pandasm::AnnotationMetadata &meta) +{ + std::vector annotations; + AnnotationData annotationData; + for (const auto &protoAnnotation : protoMeta.annotations()) { + auto annotation = allocator_->New(protoAnnotation.record_name()); + annotationData.Deserialize(protoAnnotation, *annotation); + annotations.emplace_back(std::move(*annotation)); + } + meta.AddAnnotations(annotations); +} + void Metadata::Serialize(const panda::pandasm::Metadata &meta, proto_panda::Metadata &protoMeta) { for (const auto &attr : meta.GetBoolAttributes()) { @@ -79,4 +154,17 @@ void Metadata::Serialize(const panda::pandasm::Metadata &meta, proto_panda::Meta } } } + +void Metadata::Deserialize(const proto_panda::Metadata &protoMeta, panda::pandasm::Metadata &meta) +{ + for (const auto &attr : protoMeta.set_attributes()) { + meta.SetAttribute(attr); + } + for (const auto &protoKeyVal: protoMeta.attributes()) { + auto key = protoKeyVal.key(); + for (const auto &attr : protoKeyVal.value()) { + meta.SetAttributeValue(protoKeyVal.key(), attr); + } + } +} } // panda::proto diff --git a/merge_abc/src/meta.h b/merge_abc/src/meta.h index 5561a473c7..df160290e0 100644 --- a/merge_abc/src/meta.h +++ b/merge_abc/src/meta.h @@ -20,44 +20,62 @@ #include "annotation.h" #include "assemblyType.h" #include "meta.pb.h" +#include "arena_allocator.h" namespace panda::proto { class RecordMetadata { public: static void Serialize(const panda::pandasm::RecordMetadata &meta, proto_panda::RecordMetadata &protoMeta); + static void Deserialize(const proto_panda::RecordMetadata &protoMeta, + std::unique_ptr &meta); }; class FunctionMetadata { public: static void Serialize(const panda::pandasm::FunctionMetadata &meta, proto_panda::FunctionMetadata &protoMeta); + static void Deserialize(const proto_panda::FunctionMetadata &protoMeta, + std::unique_ptr &meta); }; class FieldMetadata { public: static void Serialize(const panda::pandasm::FieldMetadata &meta, proto_panda::FieldMetadata &protoMeta); + static void Deserialize(const proto_panda::FieldMetadata &protoMeta, + std::unique_ptr &meta); }; class ParamMetadata { public: static void Serialize(const panda::pandasm::ParamMetadata &meta, proto_panda::ParamMetadata &protoMeta); + static void Deserialize(const proto_panda::ParamMetadata &protoMeta, + std::unique_ptr &meta); }; class ItemMetadata { public: static void Serialize(const panda::pandasm::ItemMetadata &meta, proto_panda::ItemMetadata &protoMeta); + static void Deserialize(const proto_panda::ItemMetadata &protoMeta, panda::pandasm::ItemMetadata &meta); }; class AnnotationMetadata { public: + explicit AnnotationMetadata() + : allocator_(std::make_unique(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true)) + { + } static void Serialize(const panda::pandasm::AnnotationMetadata &meta, proto_panda::AnnotationMetadata &protoMeta); + void Deserialize(const proto_panda::AnnotationMetadata &protoMeta, panda::pandasm::AnnotationMetadata &meta); +private: + std::unique_ptr allocator_ {}; }; class Metadata { public: static void Serialize(const panda::pandasm::Metadata &meta, proto_panda::Metadata &protoMeta); + static void Deserialize(const proto_panda::Metadata &protoMeta, panda::pandasm::Metadata &meta); }; } // panda::proto #endif \ No newline at end of file diff --git a/merge_abc/src/protobufSnapshotGenerator.cpp b/merge_abc/src/protobufSnapshotGenerator.cpp index 9be9cf84e2..fafe19dfd5 100644 --- a/merge_abc/src/protobufSnapshotGenerator.cpp +++ b/merge_abc/src/protobufSnapshotGenerator.cpp @@ -18,6 +18,7 @@ #include "assemblyProgram.h" namespace panda::proto { + void ProtobufSnapshotGenerator::GenerateSnapshot(const panda::pandasm::Program &program, const std::string &outputName) { proto_panda::Program protoProgram; @@ -28,4 +29,21 @@ void ProtobufSnapshotGenerator::GenerateSnapshot(const panda::pandasm::Program & protoProgram.SerializeToOstream(&output); output.close(); } + +void ProtobufSnapshotGenerator::GenerateProgram(const std::string &inputName, panda::pandasm::Program &prog) +{ + std::fstream input(inputName, std::ios::in | std::ios::binary); + if (!input) { + std::cout << ": File not found" << std::endl; + return; + } + proto_panda::Program proto_program; + if (!proto_program.ParseFromIstream(&input)) { + std::cerr << "Failed to parse program proto." << std::endl; + return; + } + Program program; + program.Deserialize(proto_program, prog); +} + } // panda::proto diff --git a/merge_abc/src/protobufSnapshotGenerator.h b/merge_abc/src/protobufSnapshotGenerator.h index 3d375e4159..eeef68ab27 100644 --- a/merge_abc/src/protobufSnapshotGenerator.h +++ b/merge_abc/src/protobufSnapshotGenerator.h @@ -22,6 +22,7 @@ namespace panda::proto { class ProtobufSnapshotGenerator { public: static void GenerateSnapshot(const panda::pandasm::Program &prog, const std::string &outputName); + static void GenerateProgram(const std::string &inputName, panda::pandasm::Program &prog); }; } // panda::proto #endif \ No newline at end of file -- Gitee From a601dab71106f9cbc98084a300e0ac487b4cb53d Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Thu, 18 Aug 2022 16:34:26 +0800 Subject: [PATCH 03/23] Fix code format Signed-off-by: zhangrengao Change-Id: I608cbc898c6ddc8fdc5d8173cdb18997ed40e3c2 --- es2panda/BUILD.gn | 10 +++++----- es2panda/aot/options.cpp | 12 ++++++------ merge_abc/protos/assemblyFunction.proto | 8 ++++---- merge_abc/protos/assemblyProgram.proto | 16 ++++++++-------- merge_abc/src/annotation.cpp | 8 +++----- merge_abc/src/assemblyDebug.cpp | 2 +- merge_abc/src/assemblyDebug.h | 2 +- merge_abc/src/assemblyField.cpp | 1 - merge_abc/src/assemblyFunction.cpp | 1 - merge_abc/src/assemblyIns.cpp | 2 +- merge_abc/src/assemblyLiterals.cpp | 6 +++--- merge_abc/src/assemblyProgram.cpp | 4 +--- merge_abc/src/ideHelpers.cpp | 6 ++---- merge_abc/src/ideHelpers.h | 6 ++---- merge_abc/src/meta.cpp | 5 ++--- merge_abc/src/meta.h | 3 +-- merge_abc/src/protobufSnapshotGenerator.cpp | 8 +++++--- 17 files changed, 45 insertions(+), 55 deletions(-) diff --git a/es2panda/BUILD.gn b/es2panda/BUILD.gn index 6f1898c92a..a67ebbd94c 100644 --- a/es2panda/BUILD.gn +++ b/es2panda/BUILD.gn @@ -398,14 +398,14 @@ ohos_executable("es2panda") { include_dirs = [ "./aot" ] - configs = [ + configs = [ ":es2abc_config_common", - "//arkcompiler/ets_frontend/merge_abc:panda_assembly_proto_public_config" - ] + "//arkcompiler/ets_frontend/merge_abc:panda_assembly_proto_public_config", + ] - deps = [ + deps = [ ":es2panda_lib", - "//arkcompiler/ets_frontend/merge_abc:panda_assembly_proto_static" + "//arkcompiler/ets_frontend/merge_abc:panda_assembly_proto_static", ] ldflags = [] diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 45e34b66d2..828ee541a8 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -150,12 +150,6 @@ bool Options::Parse(int argc, const char **argv) parserInput_ = ss.str(); sourceFile_ = BaseName(sourceFile_); - - if (!outputProto.GetValue().empty()) { - compilerProtoOutput_ = outputProto.GetValue(); - } else { - compilerProtoOutput_ = ""; - } } else { // input content is base64 string parserInput_ = ExtractContentFromBase64Input(base64Input.GetValue()); @@ -173,6 +167,12 @@ bool Options::Parse(int argc, const char **argv) compilerOutput_ = RemoveExtension(sourceFile_).append(".abc"); } + if (!outputProto.GetValue().empty()) { + compilerProtoOutput_ = outputProto.GetValue(); + } else { + compilerProtoOutput_ = ""; + } + std::string extension = inputExtension.GetValue(); if (!extension.empty()) { diff --git a/merge_abc/protos/assemblyFunction.proto b/merge_abc/protos/assemblyFunction.proto index 0c77062368..8e2ab5bc9b 100644 --- a/merge_abc/protos/assemblyFunction.proto +++ b/merge_abc/protos/assemblyFunction.proto @@ -38,12 +38,12 @@ message TryCatchInfo { bytes key = 1; uint64 value = 2; } - message TryCatchUnit { + message TryCatchMap { bytes key = 1; repeated CatchBlock catch_blocks = 2; } repeated TryCatchLabel try_catch_labels = 1; - repeated TryCatchUnit try_catch_map = 2; + repeated TryCatchMap try_catch_map = 2; repeated bytes try_catch_order = 3; } @@ -53,7 +53,7 @@ message Parameter { } message Function { - message LabelUnit { + message LabelTable { bytes key = 1; Label value = 2; } @@ -61,7 +61,7 @@ message Function { bytes name = 1; uint32 language = 2; FunctionMetadata metadata = 3; - repeated LabelUnit label_table = 4; + repeated LabelTable label_table = 4; repeated Ins ins = 5; repeated LocalVariable local_variable_debug = 6; bytes source_file = 7; diff --git a/merge_abc/protos/assemblyProgram.proto b/merge_abc/protos/assemblyProgram.proto index f18ef7d7e9..fb30ab1bbc 100644 --- a/merge_abc/protos/assemblyProgram.proto +++ b/merge_abc/protos/assemblyProgram.proto @@ -22,27 +22,27 @@ import "assemblyType.proto"; import "assemblyLiterals.proto"; message Program { - message RecordUnit { + message RecordTable { bytes key = 1; Record value = 2; } - message FunctionUnit { + message FunctionTable { bytes key = 1; Function value = 2; } - message FunctionSynnoym { + message FunctionSynnoyms { bytes key = 1; repeated bytes value = 2; } - message LiteralUnit { + message LiteralArrayTable { bytes key = 1; LiteralArray value = 2; } uint32 lang = 1; - repeated RecordUnit record_table = 2; - repeated FunctionUnit function_table = 3; - repeated FunctionSynnoym function_synonyms = 4; - repeated LiteralUnit literalarray_table = 5; + repeated RecordTable record_table = 2; + repeated FunctionTable function_table = 3; + repeated FunctionSynnoyms function_synonyms = 4; + repeated LiteralArrayTable literalarray_table = 5; repeated bytes strings = 6; repeated Type array_types = 7; } diff --git a/merge_abc/src/annotation.cpp b/merge_abc/src/annotation.cpp index bfb321bd4b..be5167058c 100644 --- a/merge_abc/src/annotation.cpp +++ b/merge_abc/src/annotation.cpp @@ -35,7 +35,7 @@ void AnnotationData::Deserialize(const proto_panda::AnnotationData &protoAnno, p } void AnnotationElement::Serialize(const panda::pandasm::AnnotationElement &element, - proto_panda::AnnotationElement &protoElement) + proto_panda::AnnotationElement &protoElement) { protoElement.set_name(element.GetName()); bool is_array = element.GetValue()->IsArray(); @@ -133,8 +133,7 @@ panda::pandasm::ScalarValue ScalarValue::Deserialize(const proto_panda::ScalarVa { proto_panda::ScalarValue_VariantValueType scalarType = protoScalar.type(); std::variant value; - switch (scalarType) - { + switch (scalarType) { case proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_UINT64: { value = static_cast(protoScalar.value_u64()); break; @@ -173,8 +172,7 @@ panda::pandasm::ScalarValue ScalarValue::Deserialize(const proto_panda::ScalarVa panda::pandasm::ScalarValue ScalarValue::CreateScalarValue(const panda::pandasm::Value::Type &type, std::variant &value) { - switch (type) - { + switch (type) { case panda::pandasm::Value::Type::U1: { return panda::pandasm::ScalarValue::Create(static_cast( std::get(value))); diff --git a/merge_abc/src/assemblyDebug.cpp b/merge_abc/src/assemblyDebug.cpp index 7d12ea809c..57f561410a 100644 --- a/merge_abc/src/assemblyDebug.cpp +++ b/merge_abc/src/assemblyDebug.cpp @@ -35,7 +35,7 @@ void DebuginfoIns::Deserialize(const proto_panda::DebuginfoIns &protoDebug, pand } void LocalVariable::Serialize(const panda::pandasm::debuginfo::LocalVariable &debug, - proto_panda::LocalVariable &protoDebug) + proto_panda::LocalVariable &protoDebug) { protoDebug.set_name(debug.name); protoDebug.set_signature(debug.signature); diff --git a/merge_abc/src/assemblyDebug.h b/merge_abc/src/assemblyDebug.h index 7e705a32cb..e0e2dbb205 100644 --- a/merge_abc/src/assemblyDebug.h +++ b/merge_abc/src/assemblyDebug.h @@ -29,7 +29,7 @@ public: class LocalVariable { public: static void Serialize(const panda::pandasm::debuginfo::LocalVariable &debug, - proto_panda::LocalVariable &protoDebug); + proto_panda::LocalVariable &protoDebug); static void Deserialize(const proto_panda::LocalVariable &protoDebug, panda::pandasm::debuginfo::LocalVariable &debug); }; diff --git a/merge_abc/src/assemblyField.cpp b/merge_abc/src/assemblyField.cpp index dbafa41518..00806ba870 100644 --- a/merge_abc/src/assemblyField.cpp +++ b/merge_abc/src/assemblyField.cpp @@ -16,7 +16,6 @@ #include "assemblyField.h" namespace panda::proto { - void Field::Serialize(const panda::pandasm::Field &field, proto_panda::Field &protoField) { auto *protoType = protoField.mutable_type(); diff --git a/merge_abc/src/assemblyFunction.cpp b/merge_abc/src/assemblyFunction.cpp index e64878515e..b630c508a0 100644 --- a/merge_abc/src/assemblyFunction.cpp +++ b/merge_abc/src/assemblyFunction.cpp @@ -58,7 +58,6 @@ void Function::Serialize(const panda::pandasm::Function &function, proto_panda:: auto *protoFuncMeta = protoFunction.mutable_metadata(); FunctionMetadata::Serialize(*function.metadata, *protoFuncMeta); - for (const auto &[name, label] : function.label_table) { auto *labelMap = protoFunction.add_label_table(); labelMap->set_key(name); diff --git a/merge_abc/src/assemblyIns.cpp b/merge_abc/src/assemblyIns.cpp index 465b7a8fbc..17f45e623b 100644 --- a/merge_abc/src/assemblyIns.cpp +++ b/merge_abc/src/assemblyIns.cpp @@ -25,7 +25,7 @@ void Ins::Serialize(const panda::pandasm::Ins &insn, proto_panda::Ins &protoInsn for (const auto &str : insn.ids) { protoInsn.add_ids(str); } - for (const auto imm : insn.imms) { + for (const auto &imm : insn.imms) { auto *protoImm = protoInsn.add_imms(); switch (static_cast(imm.index() + 1)) { // 1: enum TypeCase start from 1 case proto_panda::Ins_IType::kValueInt: diff --git a/merge_abc/src/assemblyLiterals.cpp b/merge_abc/src/assemblyLiterals.cpp index 3a3b6c05f1..85af1eec96 100644 --- a/merge_abc/src/assemblyLiterals.cpp +++ b/merge_abc/src/assemblyLiterals.cpp @@ -20,7 +20,7 @@ void VariantValue::Serialize(const LiteralValueType &value, proto_panda::Variant { const auto type = static_cast(value.index()); protoValue.set_type(type); - switch(type) { + switch (type) { case proto_panda::VariantValue_VariantValueType_BOOL: { protoValue.set_value_int(static_cast(std::get(value))); return; @@ -51,7 +51,7 @@ void VariantValue::Serialize(const LiteralValueType &value, proto_panda::Variant } case proto_panda::VariantValue_VariantValueType_STRING: { protoValue.set_value_str(std::get(value)); - return;; + return; } default: UNREACHABLE(); @@ -61,7 +61,7 @@ void VariantValue::Serialize(const LiteralValueType &value, proto_panda::Variant void VariantValue::Deserialize(const proto_panda::VariantValue &protoValue, LiteralValueType &value) { auto type = protoValue.type(); - switch(type) { + switch (type) { case proto_panda::VariantValue_VariantValueType_BOOL: { value = static_cast(protoValue.value_int()); return; diff --git a/merge_abc/src/assemblyProgram.cpp b/merge_abc/src/assemblyProgram.cpp index 324d02be63..8478e8c648 100644 --- a/merge_abc/src/assemblyProgram.cpp +++ b/merge_abc/src/assemblyProgram.cpp @@ -33,7 +33,7 @@ void Program::Serialize(const panda::pandasm::Program &program, proto_panda::Pro auto *protoFunc = functionMap->mutable_value(); Function::Serialize(func, *protoFunc); } - // TODO: support function_synonyms + for (const auto &[name, array] : program.literalarray_table) { auto *literalarrayMap = protoProgram.add_literalarray_table(); literalarrayMap->set_key(name); @@ -72,8 +72,6 @@ void Program::Deserialize(const proto_panda::Program &protoProgram, panda::panda program.function_table.insert({name, std::move(*function)}); } - // TODO: support function_synonyms - for (const auto &literalUnit : protoProgram.literalarray_table()) { auto name = literalUnit.key(); auto protoLiteralArray = literalUnit.value(); diff --git a/merge_abc/src/ideHelpers.cpp b/merge_abc/src/ideHelpers.cpp index 143d722751..3b3e84bdfa 100644 --- a/merge_abc/src/ideHelpers.cpp +++ b/merge_abc/src/ideHelpers.cpp @@ -16,9 +16,8 @@ #include "ideHelpers.h" namespace panda::proto { - void SourceLocation::Serialize(const panda::pandasm::SourceLocation &location, - proto_panda::SourceLocation &protoLocation) + proto_panda::SourceLocation &protoLocation) { auto *protoBegin = protoLocation.mutable_begin(); SourcePosition::Serialize(location.begin, *protoBegin); @@ -38,7 +37,7 @@ void SourceLocation::Deserialize(const proto_panda::SourceLocation &protoLocatio } void SourcePosition::Serialize(const panda::pandasm::SourcePosition &position, - proto_panda::SourcePosition &protoPosition) + proto_panda::SourcePosition &protoPosition) { protoPosition.set_line(position.line); protoPosition.set_column(position.column); @@ -50,5 +49,4 @@ void SourcePosition::Deserialize(const proto_panda::SourcePosition &protoPositio position.line = protoPosition.line(); position.column = protoPosition.column(); } - } // panda::proto \ No newline at end of file diff --git a/merge_abc/src/ideHelpers.h b/merge_abc/src/ideHelpers.h index 8212f960ea..1f8608a5b6 100644 --- a/merge_abc/src/ideHelpers.h +++ b/merge_abc/src/ideHelpers.h @@ -20,20 +20,18 @@ #include "ideHelpers.pb.h" namespace panda::proto { - class SourceLocation { public: static void Serialize(const panda::pandasm::SourceLocation &location, - proto_panda::SourceLocation &protoLocation); + proto_panda::SourceLocation &protoLocation); static void Deserialize(const proto_panda::SourceLocation &protoLocation, panda::pandasm::SourceLocation &location); }; class SourcePosition { public: static void Serialize(const panda::pandasm::SourcePosition &position, - proto_panda::SourcePosition &protoPosition); + proto_panda::SourcePosition &protoPosition); static void Deserialize(const proto_panda::SourcePosition &protoPosition, panda::pandasm::SourcePosition &position); }; - } // panda::proto #endif \ No newline at end of file diff --git a/merge_abc/src/meta.cpp b/merge_abc/src/meta.cpp index 21d046fd87..385d2e5d97 100644 --- a/merge_abc/src/meta.cpp +++ b/merge_abc/src/meta.cpp @@ -15,7 +15,6 @@ #include "meta.h" namespace panda::proto { - void RecordMetadata::Serialize(const panda::pandasm::RecordMetadata &meta, proto_panda::RecordMetadata &protoMeta) { auto *protoItemmetadata = protoMeta.mutable_father(); @@ -37,7 +36,7 @@ void RecordMetadata::Deserialize(const proto_panda::RecordMetadata &protoMeta, } void FunctionMetadata::Serialize(const panda::pandasm::FunctionMetadata &meta, - proto_panda::FunctionMetadata &protoMeta) + proto_panda::FunctionMetadata &protoMeta) { auto *protoItemmetadata = protoMeta.mutable_father(); ItemMetadata::Serialize(static_cast(meta), *protoItemmetadata); @@ -118,7 +117,7 @@ void ItemMetadata::Deserialize(const proto_panda::ItemMetadata &protoMeta, panda } void AnnotationMetadata::Serialize(const panda::pandasm::AnnotationMetadata &meta, - proto_panda::AnnotationMetadata &protoMeta) + proto_panda::AnnotationMetadata &protoMeta) { auto *protoMetadata = protoMeta.mutable_father(); Metadata::Serialize(static_cast(meta), *protoMetadata); diff --git a/merge_abc/src/meta.h b/merge_abc/src/meta.h index df160290e0..a2ada87942 100644 --- a/merge_abc/src/meta.h +++ b/merge_abc/src/meta.h @@ -23,7 +23,6 @@ #include "arena_allocator.h" namespace panda::proto { - class RecordMetadata { public: static void Serialize(const panda::pandasm::RecordMetadata &meta, proto_panda::RecordMetadata &protoMeta); @@ -66,7 +65,7 @@ public: { } static void Serialize(const panda::pandasm::AnnotationMetadata &meta, - proto_panda::AnnotationMetadata &protoMeta); + proto_panda::AnnotationMetadata &protoMeta); void Deserialize(const proto_panda::AnnotationMetadata &protoMeta, panda::pandasm::AnnotationMetadata &meta); private: std::unique_ptr allocator_ {}; diff --git a/merge_abc/src/protobufSnapshotGenerator.cpp b/merge_abc/src/protobufSnapshotGenerator.cpp index fafe19dfd5..4fdda6065e 100644 --- a/merge_abc/src/protobufSnapshotGenerator.cpp +++ b/merge_abc/src/protobufSnapshotGenerator.cpp @@ -18,14 +18,17 @@ #include "assemblyProgram.h" namespace panda::proto { - void ProtobufSnapshotGenerator::GenerateSnapshot(const panda::pandasm::Program &program, const std::string &outputName) { proto_panda::Program protoProgram; panda::proto::Program::Serialize(program, protoProgram); - std::ofstream output(outputName, std::ios::out | std::ios::trunc | std::ios::binary); + std::fstream output(outputName, std::ios::out | std::ios::trunc | std::ios::binary); + if (!output) { + std::cout << ": Fail to create file" << std::endl; + return; + } protoProgram.SerializeToOstream(&output); output.close(); } @@ -45,5 +48,4 @@ void ProtobufSnapshotGenerator::GenerateProgram(const std::string &inputName, pa Program program; program.Deserialize(proto_program, prog); } - } // panda::proto -- Gitee From 9cefa7d8c03b858807a2fe2491e9b1e39a02df08 Mon Sep 17 00:00:00 2001 From: gavin1012_hw Date: Thu, 18 Aug 2022 21:43:13 +0800 Subject: [PATCH 04/23] Provide merge_abc binary with options Signed-off-by: gavin1012_hw Change-Id: I106daa2adb82215e2918da187f0b9827a1e76e0f --- BUILD.gn | 1 + es2panda/aot/main.cpp | 10 +- merge_abc/BUILD.gn | 154 ++++++++++++-- .../{annotation.cpp => annotationProto.cpp} | 40 ++-- .../src/{annotation.h => annotationProto.h} | 32 +-- ...semblyDebug.cpp => assemblyDebugProto.cpp} | 2 +- .../{assemblyDebug.h => assemblyDebugProto.h} | 0 ...semblyField.cpp => assemblyFieldProto.cpp} | 12 +- .../{assemblyField.h => assemblyFieldProto.h} | 7 +- ...tion.cpp => assemblyFileLocationProto.cpp} | 2 +- ...Location.h => assemblyFileLocationProto.h} | 1 - ...Function.cpp => assemblyFunctionProto.cpp} | 24 +-- ...mblyFunction.h => assemblyFunctionProto.h} | 26 +-- .../{assemblyIns.cpp => assemblyInsProto.cpp} | 2 +- .../src/{assemblyIns.h => assemblyInsProto.h} | 2 +- ...semblyLabel.cpp => assemblyLabelProto.cpp} | 2 +- .../{assemblyLabel.h => assemblyLabelProto.h} | 2 +- ...Literals.cpp => assemblyLiteralsProto.cpp} | 2 +- ...mblyLiterals.h => assemblyLiteralsProto.h} | 0 ...lyProgram.cpp => assemblyProgramProto.cpp} | 15 +- ...semblyProgram.h => assemblyProgramProto.h} | 15 +- ...mblyRecord.cpp => assemblyRecordProto.cpp} | 10 +- ...assemblyRecord.h => assemblyRecordProto.h} | 9 +- ...assemblyType.cpp => assemblyTypeProto.cpp} | 7 +- .../{assemblyType.h => assemblyTypeProto.h} | 9 +- .../{ideHelpers.cpp => ideHelpersProto.cpp} | 2 +- .../src/{ideHelpers.h => ideHelpersProto.h} | 0 merge_abc/src/mergeOptions.cpp | 66 ++++++ merge_abc/src/mergeOptions.h | 61 ++++++ merge_abc/src/mergeProgramProto.cpp | 201 ++++++++++++++++++ merge_abc/src/mergeProgramProto.h | 44 ++++ merge_abc/src/{meta.cpp => metaProto.cpp} | 39 ++-- merge_abc/src/{meta.h => metaProto.h} | 25 ++- merge_abc/src/protobufSnapshotGenerator.cpp | 11 +- merge_abc/src/protobufSnapshotGenerator.h | 5 +- 35 files changed, 653 insertions(+), 187 deletions(-) rename merge_abc/src/{annotation.cpp => annotationProto.cpp} (87%) rename merge_abc/src/{annotation.h => annotationProto.h} (62%) rename merge_abc/src/{assemblyDebug.cpp => assemblyDebugProto.cpp} (98%) rename merge_abc/src/{assemblyDebug.h => assemblyDebugProto.h} (100%) rename merge_abc/src/{assemblyField.cpp => assemblyFieldProto.cpp} (83%) rename merge_abc/src/{assemblyField.h => assemblyFieldProto.h} (85%) rename merge_abc/src/{assemblyFileLocation.cpp => assemblyFileLocationProto.cpp} (97%) rename merge_abc/src/{assemblyFileLocation.h => assemblyFileLocationProto.h} (99%) rename merge_abc/src/{assemblyFunction.cpp => assemblyFunctionProto.cpp} (87%) rename merge_abc/src/{assemblyFunction.h => assemblyFunctionProto.h} (72%) rename merge_abc/src/{assemblyIns.cpp => assemblyInsProto.cpp} (98%) rename merge_abc/src/{assemblyIns.h => assemblyInsProto.h} (96%) rename merge_abc/src/{assemblyLabel.cpp => assemblyLabelProto.cpp} (97%) rename merge_abc/src/{assemblyLabel.h => assemblyLabelProto.h} (96%) rename merge_abc/src/{assemblyLiterals.cpp => assemblyLiteralsProto.cpp} (99%) rename merge_abc/src/{assemblyLiterals.h => assemblyLiteralsProto.h} (100%) rename merge_abc/src/{assemblyProgram.cpp => assemblyProgramProto.cpp} (87%) rename merge_abc/src/{assemblyProgram.h => assemblyProgramProto.h} (70%) rename merge_abc/src/{assemblyRecord.cpp => assemblyRecordProto.cpp} (87%) rename merge_abc/src/{assemblyRecord.h => assemblyRecordProto.h} (82%) rename merge_abc/src/{assemblyType.cpp => assemblyTypeProto.cpp} (81%) rename merge_abc/src/{assemblyType.h => assemblyTypeProto.h} (76%) rename merge_abc/src/{ideHelpers.cpp => ideHelpersProto.cpp} (98%) rename merge_abc/src/{ideHelpers.h => ideHelpersProto.h} (100%) create mode 100644 merge_abc/src/mergeOptions.cpp create mode 100644 merge_abc/src/mergeOptions.h create mode 100644 merge_abc/src/mergeProgramProto.cpp create mode 100644 merge_abc/src/mergeProgramProto.h rename merge_abc/src/{meta.cpp => metaProto.cpp} (82%) rename merge_abc/src/{meta.h => metaProto.h} (79%) diff --git a/BUILD.gn b/BUILD.gn index f8c78ee6cc..bbe7d8a453 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -17,6 +17,7 @@ import("//build/ohos.gni") group("ets_frontend_build") { deps = [ "./es2panda:es2panda_build", + "./merge_abc:merge_proto_abc_build", "./ts2panda:ark_ts2abc_build", ] } diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index 2f681e6077..c24cface12 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -32,6 +32,7 @@ #include #include +#include namespace panda::es2panda::aot { @@ -125,14 +126,9 @@ static int GenerateProgram(panda::pandasm::Program *prog, std::unique_ptr &&allocator) { - AnnotationElement annotationElement; for (const auto &protoElement : protoAnno.elements()) { - panda::pandasm::AnnotationElement element = annotationElement.Deserialize(protoElement); + panda::pandasm::AnnotationElement element = AnnotationElement::Deserialize(protoElement, std::move(allocator)); anno.AddElement(std::move(element)); } } @@ -49,18 +49,17 @@ void AnnotationElement::Serialize(const panda::pandasm::AnnotationElement &eleme } } -panda::pandasm::AnnotationElement &AnnotationElement::Deserialize(const proto_panda::AnnotationElement &protoElement) +panda::pandasm::AnnotationElement &AnnotationElement::Deserialize(const proto_panda::AnnotationElement &protoElement, + std::unique_ptr &&allocator) { if (protoElement.is_array()) { - ArrayValue arrayValue; - panda::pandasm::ArrayValue array = arrayValue.Deserialize(protoElement.array()); - auto element = allocator_->New(protoElement.name(), + panda::pandasm::ArrayValue array = ArrayValue::Deserialize(protoElement.array(), std::move(allocator)); + auto element = allocator->New(protoElement.name(), std::make_unique(array)); return *element; } - ScalarValue scalarValue; - panda::pandasm::ScalarValue scalar = scalarValue.Deserialize(protoElement.scalar()); - auto element = allocator_->New(protoElement.name(), + panda::pandasm::ScalarValue scalar = ScalarValue::Deserialize(protoElement.scalar(), std::move(allocator)); + auto element = allocator->New(protoElement.name(), std::make_unique(scalar)); return *element; } @@ -129,7 +128,8 @@ void ScalarValue::Serialize(const panda::pandasm::ScalarValue &scalar, proto_pan protoScalar.set_type(type); } -panda::pandasm::ScalarValue ScalarValue::Deserialize(const proto_panda::ScalarValue &protoScalar) +panda::pandasm::ScalarValue ScalarValue::Deserialize(const proto_panda::ScalarValue &protoScalar, + std::unique_ptr &&allocator) { proto_panda::ScalarValue_VariantValueType scalarType = protoScalar.type(); std::variant value; @@ -151,14 +151,14 @@ panda::pandasm::ScalarValue ScalarValue::Deserialize(const proto_panda::ScalarVa break; } case proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_PANDASM_TYPE: { - Type type; - value = static_cast(type.Deserialize(protoScalar.value_type())); + value = static_cast(Type::Deserialize(protoScalar.value_type(), + std::move(allocator))); break; } case proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_ANNOTATION_DATA: { auto protoAnnotationData = protoScalar.value_anno(); - auto value = allocator_->New(protoAnnotationData.record_name()); - AnnotationData::Deserialize(protoAnnotationData, *value); + auto value = allocator->New(protoAnnotationData.record_name()); + AnnotationData::Deserialize(protoAnnotationData, *value, std::move(allocator)); break; } default: @@ -253,15 +253,15 @@ void ArrayValue::Serialize(const panda::pandasm::ArrayValue &array, proto_panda: } } -panda::pandasm::ArrayValue &ArrayValue::Deserialize(const proto_panda::ArrayValue &protoArray) +panda::pandasm::ArrayValue &ArrayValue::Deserialize(const proto_panda::ArrayValue &protoArray, + std::unique_ptr &&allocator) { std::vector values; - ScalarValue scalarValue; for (const auto &protoValue : protoArray.values()) { - panda::pandasm::ScalarValue scalar = scalarValue.Deserialize(protoValue); + panda::pandasm::ScalarValue scalar = ScalarValue::Deserialize(protoValue, std::move(allocator)); values.emplace_back(std::move(scalar)); } - auto array = allocator_->New( + auto array = allocator->New( static_cast(protoArray.component_type()), values); return *array; } diff --git a/merge_abc/src/annotation.h b/merge_abc/src/annotationProto.h similarity index 62% rename from merge_abc/src/annotation.h rename to merge_abc/src/annotationProto.h index 59ffa5ea7f..3e2bc2270e 100644 --- a/merge_abc/src/annotation.h +++ b/merge_abc/src/annotationProto.h @@ -17,7 +17,7 @@ #define MERGE_ABC_ANNOTATION_H #include "assembly-program.h" -#include "assemblyType.h" +#include "assemblyTypeProto.h" #include "annotation.pb.h" #include "arena_allocator.h" @@ -25,47 +25,33 @@ namespace panda::proto { class AnnotationData { public: static void Serialize(const panda::pandasm::AnnotationData &anno, proto_panda::AnnotationData &protoAnno); - static void Deserialize(const proto_panda::AnnotationData &protoAnno, panda::pandasm::AnnotationData &anno); + static void Deserialize(const proto_panda::AnnotationData &protoAnno, panda::pandasm::AnnotationData &anno, + std::unique_ptr &&allocator); }; class AnnotationElement { public: - explicit AnnotationElement() - : allocator_(std::make_unique(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true)) - { - } static void Serialize(const panda::pandasm::AnnotationElement &element, proto_panda::AnnotationElement &protoElement); - panda::pandasm::AnnotationElement &Deserialize(const proto_panda::AnnotationElement &protoElement); -private: - std::unique_ptr allocator_ {}; + static panda::pandasm::AnnotationElement &Deserialize(const proto_panda::AnnotationElement &protoElement, + std::unique_ptr &&allocator); }; class ScalarValue { public: - explicit ScalarValue() - : allocator_(std::make_unique(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true)) - { - } static void Serialize(const panda::pandasm::ScalarValue &scalar, proto_panda::ScalarValue &protoScalar); - panda::pandasm::ScalarValue Deserialize(const proto_panda::ScalarValue &protoScalar); + static panda::pandasm::ScalarValue Deserialize(const proto_panda::ScalarValue &protoScalar, + std::unique_ptr &&allocator); static panda::pandasm::ScalarValue CreateScalarValue(const panda::pandasm::Value::Type &type, std::variant &value); -private: - std::unique_ptr allocator_ {}; }; class ArrayValue { public: - explicit ArrayValue() - : allocator_(std::make_unique(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true)) - { - } static void Serialize(const panda::pandasm::ArrayValue &array, proto_panda::ArrayValue &protoArray); - panda::pandasm::ArrayValue &Deserialize(const proto_panda::ArrayValue &protoArray); -private: - std::unique_ptr allocator_ {}; + static panda::pandasm::ArrayValue &Deserialize(const proto_panda::ArrayValue &protoArray, + std::unique_ptr &&allocator); }; } // panda::proto #endif diff --git a/merge_abc/src/assemblyDebug.cpp b/merge_abc/src/assemblyDebugProto.cpp similarity index 98% rename from merge_abc/src/assemblyDebug.cpp rename to merge_abc/src/assemblyDebugProto.cpp index 57f561410a..6f6d162aa7 100644 --- a/merge_abc/src/assemblyDebug.cpp +++ b/merge_abc/src/assemblyDebugProto.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "assemblyDebug.h" +#include "assemblyDebugProto.h" namespace panda::proto { void DebuginfoIns::Serialize(const panda::pandasm::debuginfo::Ins &debug, proto_panda::DebuginfoIns &protoDebug) diff --git a/merge_abc/src/assemblyDebug.h b/merge_abc/src/assemblyDebugProto.h similarity index 100% rename from merge_abc/src/assemblyDebug.h rename to merge_abc/src/assemblyDebugProto.h diff --git a/merge_abc/src/assemblyField.cpp b/merge_abc/src/assemblyFieldProto.cpp similarity index 83% rename from merge_abc/src/assemblyField.cpp rename to merge_abc/src/assemblyFieldProto.cpp index 00806ba870..3b32eb2941 100644 --- a/merge_abc/src/assemblyField.cpp +++ b/merge_abc/src/assemblyFieldProto.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "assemblyField.h" +#include "assemblyFieldProto.h" namespace panda::proto { void Field::Serialize(const panda::pandasm::Field &field, proto_panda::Field &protoField) @@ -30,14 +30,12 @@ void Field::Serialize(const panda::pandasm::Field &field, proto_panda::Field &pr protoField.set_is_defined(field.is_defined); } -void Field::Deserialize(const proto_panda::Field &protoField, panda::pandasm::Field &field) +void Field::Deserialize(const proto_panda::Field &protoField, panda::pandasm::Field &field, + std::unique_ptr &&allocator) { - Type type; - FieldMetadata fieldMetadata; - - field.type = type.Deserialize(protoField.type()); + field.type = Type::Deserialize(protoField.type(), std::move(allocator)); field.name = protoField.name(); - fieldMetadata.Deserialize(protoField.metadata(), field.metadata); + FieldMetadata::Deserialize(protoField.metadata(), field.metadata, std::move(allocator)); field.line_of_def = protoField.line_of_def(); field.whole_line = protoField.whole_line(); field.bound_left = protoField.bound_left(); diff --git a/merge_abc/src/assemblyField.h b/merge_abc/src/assemblyFieldProto.h similarity index 85% rename from merge_abc/src/assemblyField.h rename to merge_abc/src/assemblyFieldProto.h index 8101141cfa..7f885b706f 100644 --- a/merge_abc/src/assemblyField.h +++ b/merge_abc/src/assemblyFieldProto.h @@ -18,14 +18,15 @@ #include "assembly-program.h" #include "assemblyField.pb.h" -#include "meta.h" -#include "assemblyType.h" +#include "metaProto.h" +#include "assemblyTypeProto.h" namespace panda::proto { class Field { public: static void Serialize(const panda::pandasm::Field &field, proto_panda::Field &protoField); - static void Deserialize(const proto_panda::Field &protoField, panda::pandasm::Field &field); + static void Deserialize(const proto_panda::Field &protoField, panda::pandasm::Field &field, + std::unique_ptr &&allocator); }; } // panda::proto #endif \ No newline at end of file diff --git a/merge_abc/src/assemblyFileLocation.cpp b/merge_abc/src/assemblyFileLocationProto.cpp similarity index 97% rename from merge_abc/src/assemblyFileLocation.cpp rename to merge_abc/src/assemblyFileLocationProto.cpp index 83b328bd8d..d0d0da38ed 100644 --- a/merge_abc/src/assemblyFileLocation.cpp +++ b/merge_abc/src/assemblyFileLocationProto.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "assemblyFileLocation.h" +#include "assemblyFileLocationProto.h" namespace panda::proto { void FileLocation::Serialize(const panda::pandasm::FileLocation &location, proto_panda::FileLocation &protoLocation) diff --git a/merge_abc/src/assemblyFileLocation.h b/merge_abc/src/assemblyFileLocationProto.h similarity index 99% rename from merge_abc/src/assemblyFileLocation.h rename to merge_abc/src/assemblyFileLocationProto.h index b289fc20e8..52eb8af33f 100644 --- a/merge_abc/src/assemblyFileLocation.h +++ b/merge_abc/src/assemblyFileLocationProto.h @@ -19,7 +19,6 @@ #include "assembly-program.h" #include "assemblyFileLocation.pb.h" - namespace panda::proto { class FileLocation { public: diff --git a/merge_abc/src/assemblyFunction.cpp b/merge_abc/src/assemblyFunctionProto.cpp similarity index 87% rename from merge_abc/src/assemblyFunction.cpp rename to merge_abc/src/assemblyFunctionProto.cpp index b630c508a0..ad570b86bb 100644 --- a/merge_abc/src/assemblyFunction.cpp +++ b/merge_abc/src/assemblyFunctionProto.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "assemblyFunction.h" +#include "assemblyFunctionProto.h" namespace panda::proto { void CatchBlock::Serialize(const panda::pandasm::Function::CatchBlock &block, proto_panda::CatchBlock &protoBlock) @@ -44,10 +44,10 @@ void Parameter::Serialize(const panda::pandasm::Function::Parameter ¶m, prot ParamMetadata::Serialize(*(param.metadata), *metadata); } -void Parameter::Deserialize(const proto_panda::Parameter &protoParam, panda::pandasm::Function::Parameter ¶m) +void Parameter::Deserialize(const proto_panda::Parameter &protoParam, panda::pandasm::Function::Parameter ¶m, + std::unique_ptr &&allocator) { - ParamMetadata paramMetadata; - paramMetadata.Deserialize(protoParam.metadata(), param.metadata); + ParamMetadata::Deserialize(protoParam.metadata(), param.metadata, std::move(allocator)); } void Function::Serialize(const panda::pandasm::Function &function, proto_panda::Function &protoFunction) @@ -106,10 +106,10 @@ void Function::Serialize(const panda::pandasm::Function &function, proto_panda:: } } -void Function::Deserialize(const proto_panda::Function &protoFunction, panda::pandasm::Function &function) +void Function::Deserialize(const proto_panda::Function &protoFunction, panda::pandasm::Function &function, + std::unique_ptr &&allocator) { - FunctionMetadata functionMetadata; - functionMetadata.Deserialize(protoFunction.metadata(), function.metadata); + FunctionMetadata::Deserialize(protoFunction.metadata(), function.metadata, std::move(allocator)); for (const auto &labelUnit : protoFunction.label_table()) { auto name = labelUnit.key(); auto protoLabel = labelUnit.value(); @@ -134,7 +134,7 @@ void Function::Deserialize(const proto_panda::Function &protoFunction, panda::pa function.source_file = protoFunction.source_code(); for (const auto &protoCatchBlock : protoFunction.catch_blocks()) { - auto catchBlock = allocator_->New(); + auto catchBlock = allocator->New(); CatchBlock::Deserialize(protoCatchBlock, *catchBlock); function.catch_blocks.emplace_back(std::move(*catchBlock)); } @@ -142,17 +142,15 @@ void Function::Deserialize(const proto_panda::Function &protoFunction, panda::pa function.value_of_first_param = protoFunction.value_of_first_param(); function.regs_num = protoFunction.regs_num(); - Type type; - for (const auto &protoParam : protoFunction.params()) { - auto paramType = type.Deserialize(protoParam.type()); + auto paramType = Type::Deserialize(protoParam.type(), std::move(allocator)); panda::pandasm::Function::Parameter param(paramType, panda::panda_file::SourceLang::ECMASCRIPT); - Parameter::Deserialize(protoParam, param); + Parameter::Deserialize(protoParam, param, std::move(allocator)); function.params.emplace_back(std::move(param)); } function.body_presence = protoFunction.body_presence(); - function.return_type = type.Deserialize(protoFunction.return_type()); + function.return_type = Type::Deserialize(protoFunction.return_type(), std::move(allocator)); SourceLocation::Deserialize(protoFunction.body_location(), function.body_location); if (protoFunction.has_file_location()) { diff --git a/merge_abc/src/assemblyFunction.h b/merge_abc/src/assemblyFunctionProto.h similarity index 72% rename from merge_abc/src/assemblyFunction.h rename to merge_abc/src/assemblyFunctionProto.h index bf9dcb643c..48d0496565 100644 --- a/merge_abc/src/assemblyFunction.h +++ b/merge_abc/src/assemblyFunctionProto.h @@ -17,13 +17,13 @@ #define MERGE_ABC_ASSEMBLY_FUNCTION_H #include "assembly-program.h" -#include "assemblyLabel.h" -#include "assemblyType.h" -#include "assemblyIns.h" -#include "assemblyDebug.h" -#include "ideHelpers.h" -#include "assemblyFileLocation.h" -#include "meta.h" +#include "assemblyLabelProto.h" +#include "assemblyTypeProto.h" +#include "assemblyInsProto.h" +#include "assemblyDebugProto.h" +#include "ideHelpersProto.h" +#include "assemblyFileLocationProto.h" +#include "metaProto.h" #include "assemblyFunction.pb.h" #include "arena_allocator.h" @@ -37,19 +37,15 @@ public: class Parameter { public: static void Serialize(const panda::pandasm::Function::Parameter ¶m, proto_panda::Parameter &protoParam); - static void Deserialize(const proto_panda::Parameter &protoParam, panda::pandasm::Function::Parameter ¶m); + static void Deserialize(const proto_panda::Parameter &protoParam, panda::pandasm::Function::Parameter ¶m, + std::unique_ptr &&allocator_); }; class Function { public: - explicit Function() - : allocator_(std::make_unique(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true)) - { - } static void Serialize(const panda::pandasm::Function &function, proto_panda::Function &protoFunction); - void Deserialize(const proto_panda::Function &protoFunction, panda::pandasm::Function &function); -private: - std::unique_ptr allocator_ {}; + static void Deserialize(const proto_panda::Function &protoFunction, panda::pandasm::Function &function, + std::unique_ptr &&allocator_); }; } // panda::proto #endif diff --git a/merge_abc/src/assemblyIns.cpp b/merge_abc/src/assemblyInsProto.cpp similarity index 98% rename from merge_abc/src/assemblyIns.cpp rename to merge_abc/src/assemblyInsProto.cpp index 17f45e623b..de982b4bb6 100644 --- a/merge_abc/src/assemblyIns.cpp +++ b/merge_abc/src/assemblyInsProto.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "assemblyIns.h" +#include "assemblyInsProto.h" namespace panda::proto { void Ins::Serialize(const panda::pandasm::Ins &insn, proto_panda::Ins &protoInsn) diff --git a/merge_abc/src/assemblyIns.h b/merge_abc/src/assemblyInsProto.h similarity index 96% rename from merge_abc/src/assemblyIns.h rename to merge_abc/src/assemblyInsProto.h index 6c53425a21..a4a5365639 100644 --- a/merge_abc/src/assemblyIns.h +++ b/merge_abc/src/assemblyInsProto.h @@ -17,7 +17,7 @@ #define MERGE_ABC_ASSEMBLY_INS_H #include "assembly-program.h" -#include "assemblyDebug.h" +#include "assemblyDebugProto.h" #include "assemblyIns.pb.h" namespace panda::proto { diff --git a/merge_abc/src/assemblyLabel.cpp b/merge_abc/src/assemblyLabelProto.cpp similarity index 97% rename from merge_abc/src/assemblyLabel.cpp rename to merge_abc/src/assemblyLabelProto.cpp index 4514dd4e0d..45cd2efe19 100644 --- a/merge_abc/src/assemblyLabel.cpp +++ b/merge_abc/src/assemblyLabelProto.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "assemblyLabel.h" +#include "assemblyLabelProto.h" namespace panda::proto { void Label::Serialize(const panda::pandasm::Label &label, proto_panda::Label &protoLabel) diff --git a/merge_abc/src/assemblyLabel.h b/merge_abc/src/assemblyLabelProto.h similarity index 96% rename from merge_abc/src/assemblyLabel.h rename to merge_abc/src/assemblyLabelProto.h index 91cb08dc7f..8a2a4a2466 100644 --- a/merge_abc/src/assemblyLabel.h +++ b/merge_abc/src/assemblyLabelProto.h @@ -17,7 +17,7 @@ #define MERGE_ABC_ASSEMBLY_LABEL_H #include "assembly-program.h" -#include "assemblyFileLocation.h" +#include "assemblyFileLocationProto.h" #include "assemblyLabel.pb.h" namespace panda::proto { diff --git a/merge_abc/src/assemblyLiterals.cpp b/merge_abc/src/assemblyLiteralsProto.cpp similarity index 99% rename from merge_abc/src/assemblyLiterals.cpp rename to merge_abc/src/assemblyLiteralsProto.cpp index 85af1eec96..95dabfe5e2 100644 --- a/merge_abc/src/assemblyLiterals.cpp +++ b/merge_abc/src/assemblyLiteralsProto.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "assemblyLiterals.h" +#include "assemblyLiteralsProto.h" namespace panda::proto { void VariantValue::Serialize(const LiteralValueType &value, proto_panda::VariantValue &protoValue) diff --git a/merge_abc/src/assemblyLiterals.h b/merge_abc/src/assemblyLiteralsProto.h similarity index 100% rename from merge_abc/src/assemblyLiterals.h rename to merge_abc/src/assemblyLiteralsProto.h diff --git a/merge_abc/src/assemblyProgram.cpp b/merge_abc/src/assemblyProgramProto.cpp similarity index 87% rename from merge_abc/src/assemblyProgram.cpp rename to merge_abc/src/assemblyProgramProto.cpp index 8478e8c648..382e0d1599 100644 --- a/merge_abc/src/assemblyProgram.cpp +++ b/merge_abc/src/assemblyProgramProto.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "assemblyProgram.h" +#include "assemblyProgramProto.h" namespace panda::proto { void Program::Serialize(const panda::pandasm::Program &program, proto_panda::Program &protoProgram) @@ -49,7 +49,8 @@ void Program::Serialize(const panda::pandasm::Program &program, proto_panda::Pro } } -void Program::Deserialize(const proto_panda::Program &protoProgram, panda::pandasm::Program &program) +void Program::Deserialize(const proto_panda::Program &protoProgram, panda::pandasm::Program &program, + std::unique_ptr &&allocator) { program.lang = static_cast(protoProgram.lang()); @@ -58,17 +59,16 @@ void Program::Deserialize(const proto_panda::Program &protoProgram, panda::panda auto protoRecord = recordUnit.value(); auto record = panda::pandasm::Record(protoRecord.name(), static_cast(protoRecord.language())); - Record::Deserialize(protoRecord, record); + Record::Deserialize(protoRecord, record, std::move(allocator)); program.record_table.insert({name, std::move(record)}); } - Function functionDeserialization; for (const auto &functionUnit : protoProgram.function_table()) { auto name = functionUnit.key(); auto protoFunction = functionUnit.value(); - auto function = allocator_->New(protoFunction.name(), + auto function = allocator->New(protoFunction.name(), static_cast(protoFunction.language())); - functionDeserialization.Deserialize(protoFunction, *function); + Function::Deserialize(protoFunction, *function, std::move(allocator)); program.function_table.insert({name, std::move(*function)}); } @@ -84,9 +84,8 @@ void Program::Deserialize(const proto_panda::Program &protoProgram, panda::panda program.strings.insert(protoString); } - Type type; for (const auto &protoArrayType : protoProgram.array_types()) { - auto arrayType = type.Deserialize(protoArrayType); + auto arrayType = Type::Deserialize(protoArrayType, std::move(allocator)); program.array_types.insert(std::move(arrayType)); } } diff --git a/merge_abc/src/assemblyProgram.h b/merge_abc/src/assemblyProgramProto.h similarity index 70% rename from merge_abc/src/assemblyProgram.h rename to merge_abc/src/assemblyProgramProto.h index d19279ad1b..5017257853 100644 --- a/merge_abc/src/assemblyProgram.h +++ b/merge_abc/src/assemblyProgramProto.h @@ -17,23 +17,18 @@ #define MERGE_ABC_ASSEMBLY_PROGRAM_H #include "assembly-program.h" -#include "assemblyRecord.h" -#include "assemblyFunction.h" -#include "assemblyLiterals.h" +#include "assemblyRecordProto.h" +#include "assemblyFunctionProto.h" +#include "assemblyLiteralsProto.h" #include "assemblyProgram.pb.h" #include "arena_allocator.h" namespace panda::proto { class Program { public: - explicit Program() - : allocator_(std::make_unique(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true)) - { - } static void Serialize(const panda::pandasm::Program &program, proto_panda::Program &protoProgram); - void Deserialize(const proto_panda::Program &protoProgram, panda::pandasm::Program &program); -private: - std::unique_ptr allocator_ {}; + static void Deserialize(const proto_panda::Program &protoProgram, panda::pandasm::Program &program, + std::unique_ptr &&allocator); }; } // panda::proto #endif \ No newline at end of file diff --git a/merge_abc/src/assemblyRecord.cpp b/merge_abc/src/assemblyRecordProto.cpp similarity index 87% rename from merge_abc/src/assemblyRecord.cpp rename to merge_abc/src/assemblyRecordProto.cpp index e7bf95d037..b3e31b118e 100644 --- a/merge_abc/src/assemblyRecord.cpp +++ b/merge_abc/src/assemblyRecordProto.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "assemblyRecord.h" +#include "assemblyRecordProto.h" namespace panda::proto { void Record::Serialize(const panda::pandasm::Record &record, proto_panda::Record &protoRecord) @@ -40,14 +40,14 @@ void Record::Serialize(const panda::pandasm::Record &record, proto_panda::Record } } -void Record::Deserialize(const proto_panda::Record &protoRecord, panda::pandasm::Record &record) +void Record::Deserialize(const proto_panda::Record &protoRecord, panda::pandasm::Record &record, + std::unique_ptr &&allocator) { record.conflict = protoRecord.conflict(); - RecordMetadata recordMetadata; - recordMetadata.Deserialize(protoRecord.metadata(), record.metadata); + RecordMetadata::Deserialize(protoRecord.metadata(), record.metadata, std::move(allocator)); for (const auto &protoField : protoRecord.field_list()) { auto recordField = panda::pandasm::Field(panda::panda_file::SourceLang::ECMASCRIPT); - Field::Deserialize(protoField, recordField); + Field::Deserialize(protoField, recordField, std::move(allocator)); record.field_list.emplace_back(std::move(recordField)); } record.params_num = protoRecord.params_num(); diff --git a/merge_abc/src/assemblyRecord.h b/merge_abc/src/assemblyRecordProto.h similarity index 82% rename from merge_abc/src/assemblyRecord.h rename to merge_abc/src/assemblyRecordProto.h index 60f6caf2f8..683719d933 100644 --- a/merge_abc/src/assemblyRecord.h +++ b/merge_abc/src/assemblyRecordProto.h @@ -17,16 +17,17 @@ #define MERGE_ABC_ASSEMBLY_RECORD_H #include "assembly-program.h" -#include "meta.h" -#include "assemblyField.h" -#include "assemblyFunction.h" +#include "metaProto.h" +#include "assemblyFieldProto.h" +#include "assemblyFunctionProto.h" #include "assemblyRecord.pb.h" namespace panda::proto { class Record { public: static void Serialize(const panda::pandasm::Record &record, proto_panda::Record &protoRecord); - static void Deserialize(const proto_panda::Record &protoRecord, panda::pandasm::Record &record); + static void Deserialize(const proto_panda::Record &protoRecord, panda::pandasm::Record &record, + std::unique_ptr &&allocator); }; } // panda::proto #endif \ No newline at end of file diff --git a/merge_abc/src/assemblyType.cpp b/merge_abc/src/assemblyTypeProto.cpp similarity index 81% rename from merge_abc/src/assemblyType.cpp rename to merge_abc/src/assemblyTypeProto.cpp index d3bddd2b45..27a275c52e 100644 --- a/merge_abc/src/assemblyType.cpp +++ b/merge_abc/src/assemblyTypeProto.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "assemblyType.h" +#include "assemblyTypeProto.h" namespace panda::proto { void Type::Serialize(const panda::pandasm::Type type, proto_panda::Type &protoType) @@ -24,9 +24,10 @@ void Type::Serialize(const panda::pandasm::Type type, proto_panda::Type &protoTy protoType.set_type_id(static_cast(type.GetId())); } -panda::pandasm::Type &Type::Deserialize(const proto_panda::Type &protoType) +panda::pandasm::Type &Type::Deserialize(const proto_panda::Type &protoType, + std::unique_ptr &&allocator) { - auto type = allocator_->New(protoType.component_name(), protoType.rank()); + auto type = allocator->New(protoType.component_name(), protoType.rank()); return *type; } } // panda::proto \ No newline at end of file diff --git a/merge_abc/src/assemblyType.h b/merge_abc/src/assemblyTypeProto.h similarity index 76% rename from merge_abc/src/assemblyType.h rename to merge_abc/src/assemblyTypeProto.h index f744609568..866c295838 100644 --- a/merge_abc/src/assemblyType.h +++ b/merge_abc/src/assemblyTypeProto.h @@ -23,14 +23,9 @@ namespace panda::proto { class Type { public: - explicit Type() - : allocator_(std::make_unique(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true)) - { - } static void Serialize(const panda::pandasm::Type type, proto_panda::Type &protoType); - panda::pandasm::Type &Deserialize(const proto_panda::Type &protoType); -private: - std::unique_ptr allocator_ {}; + static panda::pandasm::Type &Deserialize(const proto_panda::Type &protoType, + std::unique_ptr &&allocator); }; } // panda::proto #endif \ No newline at end of file diff --git a/merge_abc/src/ideHelpers.cpp b/merge_abc/src/ideHelpersProto.cpp similarity index 98% rename from merge_abc/src/ideHelpers.cpp rename to merge_abc/src/ideHelpersProto.cpp index 3b3e84bdfa..894ee7fd75 100644 --- a/merge_abc/src/ideHelpers.cpp +++ b/merge_abc/src/ideHelpersProto.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "ideHelpers.h" +#include "ideHelpersProto.h" namespace panda::proto { void SourceLocation::Serialize(const panda::pandasm::SourceLocation &location, diff --git a/merge_abc/src/ideHelpers.h b/merge_abc/src/ideHelpersProto.h similarity index 100% rename from merge_abc/src/ideHelpers.h rename to merge_abc/src/ideHelpersProto.h diff --git a/merge_abc/src/mergeOptions.cpp b/merge_abc/src/mergeOptions.cpp new file mode 100644 index 0000000000..0dca2fd898 --- /dev/null +++ b/merge_abc/src/mergeOptions.cpp @@ -0,0 +1,66 @@ +/** + * 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. + */ + +#include "mergeOptions.h" + +#include + +namespace panda::proto { +// Options +Options::Options() : argparser_(new panda::PandArgParser()) {} + +Options::~Options() +{ + delete argparser_; +} + +bool Options::Parse(int argc, const char **argv) { + panda::PandArg opHelp("help", false, "Print this message and exit"); + + panda::PandArg protoBinPath("protoBinPath", "", "path of proto bin files"); + panda::PandArg protoBinSuffix("protoBinSuffix", "", "suffix of proto bin file"); + panda::PandArg outputPandaFile("outputPandaFile", "", "name of merged panda file"); + + argparser_->Add(&opHelp); + argparser_->Add(&protoBinPath); + argparser_->Add(&protoBinSuffix); + argparser_->Add(&outputPandaFile); + + if (!argparser_->Parse(argc, argv) || opHelp.GetValue() || protoBinPath.GetValue().empty()) { + std::stringstream ss; + + ss << argparser_->GetErrorString() << std::endl; + ss << "Usage: " + << "merge_abc" + << " [OPTIONS]" << std::endl; + ss << std::endl; + ss << "optional arguments:" << std::endl; + ss << argparser_->GetHelpString() << std::endl; + + errorMsg_ = ss.str(); + return false; + } + + protoBinPath_ = protoBinPath.GetValue(); + if (!protoBinSuffix.GetValue().empty()) { + protoBinSuffix_ = protoBinSuffix.GetValue(); + } + if (!outputPandaFile.GetValue().empty()) { + outputPandaFile_ = outputPandaFile.GetValue(); + } + + return true; +} +} diff --git a/merge_abc/src/mergeOptions.h b/merge_abc/src/mergeOptions.h new file mode 100644 index 0000000000..4e91135856 --- /dev/null +++ b/merge_abc/src/mergeOptions.h @@ -0,0 +1,61 @@ +/** + * 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 MERGE_ABC_MERGE_OPTIONS_H +#define MERGE_ABC_MERGE_OPTIONS_H + +#include +#include +#include + +namespace panda::proto { +class Options { +public: + Options(); + NO_COPY_SEMANTIC(Options); + NO_MOVE_SEMANTIC(Options); + ~Options(); + + bool Parse(int argc, const char **argv); + + const std::string &protoBinPath() const + { + return protoBinPath_; + } + + const std::string &protoBinSuffix() const + { + return protoBinSuffix_; + } + + const std::string &outputPandaFile() const + { + return outputPandaFile_; + } + + const std::string &ErrorMsg() const + { + return errorMsg_; + } + +private: + panda::PandArgParser *argparser_; + std::string errorMsg_; + std::string protoBinSuffix_ {"protoBin"}; + std::string protoBinPath_; + std::string outputPandaFile_ {"merge.abc"}; +}; +} +#endif diff --git a/merge_abc/src/mergeProgramProto.cpp b/merge_abc/src/mergeProgramProto.cpp new file mode 100644 index 0000000000..6482b24138 --- /dev/null +++ b/merge_abc/src/mergeProgramProto.cpp @@ -0,0 +1,201 @@ +/** + * 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. + */ + +#include "mergeProgramProto.h" +#include "protobufSnapshotGenerator.h" +#include "arena_allocator.h" +#include "mergeOptions.h" +#include "assembler/assembly-function.h" +#include "libpandafile/literal_data_accessor.h" +#include + +#include +#include + +namespace panda::proto { + +using mem::MemConfig; + +class ProtoMemManager { +public: + explicit ProtoMemManager() + { + constexpr auto COMPILER_SIZE = 512_MB; + + MemConfig::Initialize(0, 0, COMPILER_SIZE, 0); + PoolManager::Initialize(PoolType::MMAP); + } + + NO_COPY_SEMANTIC(ProtoMemManager); + NO_MOVE_SEMANTIC(ProtoMemManager); + + ~ProtoMemManager() + { + PoolManager::Finalize(); + MemConfig::Finalize(); + } +}; + +int TraverseProtoBinPath(const std::string &protoBinPath, const std::string &protoBinSuffix, MergeProgram *mergeProgram, + std::unique_ptr &&allocator) +{ + panda::pandasm::Program program; + + const std::filesystem::path fsPath(protoBinPath); + if (!std::filesystem::exists(fsPath)) { + return 1; + } + for (auto &itr : std::filesystem::directory_iterator(fsPath)) { + if (std::filesystem::is_directory(itr.status())) { + if (TraverseProtoBinPath(itr.path().string(), protoBinSuffix, mergeProgram, std::move(allocator)) != 0) { + return 1; + } + } else { + auto fileName = itr.path().string(); + std::string suffixStr = fileName.substr(fileName.find_last_of(".") + 1); + if (suffixStr.compare(protoBinSuffix) == 0) { + proto::ProtobufSnapshotGenerator::GenerateProgram(fileName, program, std::move(allocator)); + mergeProgram->Merge(&program); + } + } + } + return 0; +} + +void MergeProgram::Merge(panda::pandasm::Program *src) { + CorrectLiteraArrayId(src); + + bool hasTypeAnnoRecord = false; + for (auto &iter : src->record_table) { + auto &name = iter.first; + bool isTypeAnnoRecord = name == std::string(TYPE_ANNOTATION_RECORD.data()); + if (hasTypeAnnoRecord && isTypeAnnoRecord) { + continue; + } + ASSERT(prog_->record_table.find(name) == prog_->record_table.end()); + prog_->record_table.insert(std::move(iter)); + hasTypeAnnoRecord = hasTypeAnnoRecord || isTypeAnnoRecord; + } + + for (auto &[name, func] : src->function_table) { + ASSERT(prog_->function_table.find(name) == prog_->function_table.end()); + prog_->function_table.emplace(name, std::move(func)); + } + + ASSERT(src->function_synonyms.empty()); + + const auto base = prog_->literalarray_table.size(); + size_t count = 0; + for (auto &[id, litArray] : src->literalarray_table) { + prog_->literalarray_table.emplace(std::to_string(base + count), std::move(litArray)); + count++; + } + + for (const auto &str : src->strings) { + prog_->strings.insert(str); + } + + for (const auto &type: src->array_types) { + prog_->array_types.insert(type); + } +} + +void MergeProgram::CorrectLiteraArrayId(panda::pandasm::Program *src) +{ + const auto base = prog_->literalarray_table.size(); + + for (auto &[name, litArray] : src->literalarray_table) { + for (auto &lit : litArray.literals_) { + if (lit.tag_ == panda_file::LiteralTag::TYPEINDEX) { + lit.value_ = std::get(lit.value_) + base; + } + } + } + + for (auto &[name, func] : src->function_table) { + for (auto &insn : func.ins) { + IncreaseInsLiteralArrayIdByBase(insn, base); + } + } + + for (auto &[name, record] : src->record_table) { + for (auto &field : record.field_list) { + if (field.type.GetId() != panda_file::Type::TypeId::U32) { + continue; + } + auto addedVal = static_cast(base) + field.metadata->GetValue().value().GetValue(); + field.metadata->SetValue(panda::pandasm::ScalarValue::Create(addedVal)); + } + } +} + +// TODO: let it be auto-generated after isa-refactoring +void MergeProgram::IncreaseInsLiteralArrayIdByBase(panda::pandasm::Ins &insn, size_t base) +{ + switch (insn.opcode) { + case panda::pandasm::Opcode::ECMA_CREATEARRAYWITHBUFFER: + case panda::pandasm::Opcode::ECMA_CREATEOBJECTWITHBUFFER: + case panda::pandasm::Opcode::ECMA_CREATEOBJECTHAVINGMETHOD: + case panda::pandasm::Opcode::ECMA_DEFINECLASSWITHBUFFER: + insn.imms[0] = std::get(insn.imms[0]) + static_cast(base); + return; + case panda::pandasm::Opcode::ECMA_NEWLEXENVWITHNAMEDYN: + insn.imms[1] = std::get(insn.imms[1]) + static_cast(base); + return; + default: + return; + } +} + +int Run(int argc, const char **argv) +{ + auto options = std::make_unique(); + if (!options->Parse(argc, argv)) { + std::cerr << options->ErrorMsg() << std::endl; + return 1; + } + + std::string protoBinPath = options->protoBinPath(); + std::string protoBinSuffix = options->protoBinSuffix(); + + std::unique_ptr allocator = std::make_unique( + panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true); + + panda::pandasm::Program program; + MergeProgram mergeProgram(&program); + if (panda::proto::TraverseProtoBinPath(protoBinPath, protoBinSuffix, &mergeProgram, std::move(allocator))) { + return 1; + } + + std::map stat; + std::map *statp = nullptr; + panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps maps {}; + panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps *mapsp = nullptr; + + std::string outputPandaFile = options->outputPandaFile(); + outputPandaFile = std::filesystem::path(protoBinPath).append(outputPandaFile); + if (!panda::pandasm::AsmEmitter::Emit(outputPandaFile, *(mergeProgram.GetResult()), statp, mapsp, true)) { + return 1; + } + + return 0; +} +} + +int main(int argc, const char **argv) +{ + panda::proto::ProtoMemManager mm; + return panda::proto::Run(argc, argv); +} diff --git a/merge_abc/src/mergeProgramProto.h b/merge_abc/src/mergeProgramProto.h new file mode 100644 index 0000000000..67a9e1e472 --- /dev/null +++ b/merge_abc/src/mergeProgramProto.h @@ -0,0 +1,44 @@ +/** + * 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 MERGE_ABC_MERGE_PROGRAM_H +#define MERGE_ABC_MERGE_PROGRAM_H + +#include "assembly-ins.h" +#include "assembly-program.h" +#include "assembler/assembly-function.h" + +namespace panda::proto { +class MergeProgram { +public: + explicit MergeProgram(panda::pandasm::Program *program) : prog_(program) {} + ~MergeProgram() = default; + + const panda::pandasm::Program *GetResult() const + { + return prog_; + } + + void Merge(panda::pandasm::Program *src); + + constexpr static std::string_view TYPE_ANNOTATION_RECORD = "_ESTypeAnnotation"; + +private: + void CorrectLiteraArrayId(panda::pandasm::Program *src); + void IncreaseInsLiteralArrayIdByBase(panda::pandasm::Ins &insn, size_t base); + panda::pandasm::Program *prog_; +}; +} // namespace panda::proto +#endif // MERGE_ABC_MERGE_PROGRAM_H diff --git a/merge_abc/src/meta.cpp b/merge_abc/src/metaProto.cpp similarity index 82% rename from merge_abc/src/meta.cpp rename to merge_abc/src/metaProto.cpp index 385d2e5d97..b4b724d8b7 100644 --- a/merge_abc/src/meta.cpp +++ b/merge_abc/src/metaProto.cpp @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "meta.h" +#include "metaProto.h" namespace panda::proto { void RecordMetadata::Serialize(const panda::pandasm::RecordMetadata &meta, proto_panda::RecordMetadata &protoMeta) @@ -22,14 +22,14 @@ void RecordMetadata::Serialize(const panda::pandasm::RecordMetadata &meta, proto } void RecordMetadata::Deserialize(const proto_panda::RecordMetadata &protoMeta, - std::unique_ptr &meta) + std::unique_ptr &meta, + std::unique_ptr &&allocator) { auto protoItemMetadata = protoMeta.father(); ItemMetadata::Deserialize(protoItemMetadata, *meta); auto protoAnnoMetadata = protoItemMetadata.father(); - AnnotationMetadata annotationMetadata; - annotationMetadata.Deserialize(protoAnnoMetadata, *meta); + AnnotationMetadata::Deserialize(protoAnnoMetadata, *meta, std::move(allocator)); auto protoMetadata = protoAnnoMetadata.father(); Metadata::Deserialize(protoMetadata, *meta); @@ -43,14 +43,14 @@ void FunctionMetadata::Serialize(const panda::pandasm::FunctionMetadata &meta, } void FunctionMetadata::Deserialize(const proto_panda::FunctionMetadata &protoMeta, - std::unique_ptr &meta) + std::unique_ptr &meta, + std::unique_ptr &&allocator) { auto protoItemMetadata = protoMeta.father(); ItemMetadata::Deserialize(protoItemMetadata, *meta); auto protoAnnoMetadata = protoItemMetadata.father(); - AnnotationMetadata annotationMetadata; - annotationMetadata.Deserialize(protoAnnoMetadata, *meta); + AnnotationMetadata::Deserialize(protoAnnoMetadata, *meta, std::move(allocator)); auto protoMetadata = protoAnnoMetadata.father(); Metadata::Deserialize(protoMetadata, *meta); @@ -70,22 +70,21 @@ void FieldMetadata::Serialize(const panda::pandasm::FieldMetadata &meta, proto_p } void FieldMetadata::Deserialize(const proto_panda::FieldMetadata &protoMeta, - std::unique_ptr &meta) + std::unique_ptr &meta, + std::unique_ptr &&allocator) { auto protoItemMetadata = protoMeta.father(); ItemMetadata::Deserialize(protoItemMetadata, *meta); auto protoAnnoMetadata = protoItemMetadata.father(); - AnnotationMetadata annotationMetadata; - annotationMetadata.Deserialize(protoAnnoMetadata, *meta); + AnnotationMetadata::Deserialize(protoAnnoMetadata, *meta, std::move(allocator)); auto protoMetadata = protoAnnoMetadata.father(); Metadata::Deserialize(protoMetadata, *meta); - Type type; - auto fieldType = type.Deserialize(protoMeta.field_type()); + auto fieldType = Type::Deserialize(protoMeta.field_type(), std::move(allocator)); meta->SetFieldType(fieldType); ScalarValue scalarValue; if (protoMeta.has_value()) { - auto scalar = scalarValue.Deserialize(protoMeta.value()); + auto scalar = scalarValue.Deserialize(protoMeta.value(), std::move(allocator)); meta->SetValue(scalar); } } @@ -97,11 +96,11 @@ void ParamMetadata::Serialize(const panda::pandasm::ParamMetadata &meta, proto_p } void ParamMetadata::Deserialize(const proto_panda::ParamMetadata &protoMeta, - std::unique_ptr &meta) + std::unique_ptr &meta, + std::unique_ptr &&allocator) { auto protoAnnoMetadata = protoMeta.father(); - AnnotationMetadata annotationMetadata; - annotationMetadata.Deserialize(protoAnnoMetadata, *meta); + AnnotationMetadata::Deserialize(protoAnnoMetadata, *meta, std::move(allocator)); } void ItemMetadata::Serialize(const panda::pandasm::ItemMetadata &meta, proto_panda::ItemMetadata &protoMeta) @@ -128,13 +127,13 @@ void AnnotationMetadata::Serialize(const panda::pandasm::AnnotationMetadata &met } void AnnotationMetadata::Deserialize(const proto_panda::AnnotationMetadata &protoMeta, - panda::pandasm::AnnotationMetadata &meta) + panda::pandasm::AnnotationMetadata &meta, + std::unique_ptr &&allocator) { std::vector annotations; - AnnotationData annotationData; for (const auto &protoAnnotation : protoMeta.annotations()) { - auto annotation = allocator_->New(protoAnnotation.record_name()); - annotationData.Deserialize(protoAnnotation, *annotation); + auto annotation = allocator->New(protoAnnotation.record_name()); + AnnotationData::Deserialize(protoAnnotation, *annotation, std::move(allocator)); annotations.emplace_back(std::move(*annotation)); } meta.AddAnnotations(annotations); diff --git a/merge_abc/src/meta.h b/merge_abc/src/metaProto.h similarity index 79% rename from merge_abc/src/meta.h rename to merge_abc/src/metaProto.h index a2ada87942..995644f0aa 100644 --- a/merge_abc/src/meta.h +++ b/merge_abc/src/metaProto.h @@ -17,8 +17,8 @@ #define MERGE_ABC_META_H #include "assembly-program.h" -#include "annotation.h" -#include "assemblyType.h" +#include "annotationProto.h" +#include "assemblyTypeProto.h" #include "meta.pb.h" #include "arena_allocator.h" @@ -27,7 +27,8 @@ class RecordMetadata { public: static void Serialize(const panda::pandasm::RecordMetadata &meta, proto_panda::RecordMetadata &protoMeta); static void Deserialize(const proto_panda::RecordMetadata &protoMeta, - std::unique_ptr &meta); + std::unique_ptr &meta, + std::unique_ptr &&allocator); }; class FunctionMetadata { @@ -35,21 +36,24 @@ public: static void Serialize(const panda::pandasm::FunctionMetadata &meta, proto_panda::FunctionMetadata &protoMeta); static void Deserialize(const proto_panda::FunctionMetadata &protoMeta, - std::unique_ptr &meta); + std::unique_ptr &meta, + std::unique_ptr &&allocator); }; class FieldMetadata { public: static void Serialize(const panda::pandasm::FieldMetadata &meta, proto_panda::FieldMetadata &protoMeta); static void Deserialize(const proto_panda::FieldMetadata &protoMeta, - std::unique_ptr &meta); + std::unique_ptr &meta, + std::unique_ptr &&allocator); }; class ParamMetadata { public: static void Serialize(const panda::pandasm::ParamMetadata &meta, proto_panda::ParamMetadata &protoMeta); static void Deserialize(const proto_panda::ParamMetadata &protoMeta, - std::unique_ptr &meta); + std::unique_ptr &meta, + std::unique_ptr &&allocator); }; class ItemMetadata { @@ -60,15 +64,10 @@ public: class AnnotationMetadata { public: - explicit AnnotationMetadata() - : allocator_(std::make_unique(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true)) - { - } static void Serialize(const panda::pandasm::AnnotationMetadata &meta, proto_panda::AnnotationMetadata &protoMeta); - void Deserialize(const proto_panda::AnnotationMetadata &protoMeta, panda::pandasm::AnnotationMetadata &meta); -private: - std::unique_ptr allocator_ {}; + static void Deserialize(const proto_panda::AnnotationMetadata &protoMeta, panda::pandasm::AnnotationMetadata &meta, + std::unique_ptr &&allocator); }; class Metadata { diff --git a/merge_abc/src/protobufSnapshotGenerator.cpp b/merge_abc/src/protobufSnapshotGenerator.cpp index 4fdda6065e..c9cfd31f20 100644 --- a/merge_abc/src/protobufSnapshotGenerator.cpp +++ b/merge_abc/src/protobufSnapshotGenerator.cpp @@ -15,7 +15,7 @@ #include "protobufSnapshotGenerator.h" #include "assembly-program.h" -#include "assemblyProgram.h" +#include "assemblyProgramProto.h" namespace panda::proto { void ProtobufSnapshotGenerator::GenerateSnapshot(const panda::pandasm::Program &program, const std::string &outputName) @@ -33,19 +33,20 @@ void ProtobufSnapshotGenerator::GenerateSnapshot(const panda::pandasm::Program & output.close(); } -void ProtobufSnapshotGenerator::GenerateProgram(const std::string &inputName, panda::pandasm::Program &prog) +void ProtobufSnapshotGenerator::GenerateProgram(const std::string &inputName, panda::pandasm::Program &prog, + std::unique_ptr &&allocator) { std::fstream input(inputName, std::ios::in | std::ios::binary); if (!input) { - std::cout << ": File not found" << std::endl; + std::cerr << "Failed to open " << inputName << std::endl; return; } proto_panda::Program proto_program; if (!proto_program.ParseFromIstream(&input)) { - std::cerr << "Failed to parse program proto." << std::endl; + std::cerr << "Failed to parse " << inputName << std::endl; return; } Program program; - program.Deserialize(proto_program, prog); + program.Deserialize(proto_program, prog, std::move(allocator)); } } // panda::proto diff --git a/merge_abc/src/protobufSnapshotGenerator.h b/merge_abc/src/protobufSnapshotGenerator.h index eeef68ab27..9cd7ddccca 100644 --- a/merge_abc/src/protobufSnapshotGenerator.h +++ b/merge_abc/src/protobufSnapshotGenerator.h @@ -16,13 +16,14 @@ #ifndef MERGE_ABC_POROBUFSNAPSHOTGENERATOR_H #define MERGE_ABC_POROBUFSNAPSHOTGENERATOR_H -#include "assemblyProgram.h" +#include "assemblyProgramProto.h" namespace panda::proto { class ProtobufSnapshotGenerator { public: static void GenerateSnapshot(const panda::pandasm::Program &prog, const std::string &outputName); - static void GenerateProgram(const std::string &inputName, panda::pandasm::Program &prog); + static void GenerateProgram(const std::string &inputName, panda::pandasm::Program &prog, + std::unique_ptr &&allocator); }; } // panda::proto #endif \ No newline at end of file -- Gitee From 8822cd26827fc7e787844a9461c1599a4fa73d85 Mon Sep 17 00:00:00 2001 From: hufeng Date: Thu, 11 Aug 2022 20:34:38 +0800 Subject: [PATCH 05/23] Generate record Signed-off-by: hufeng Change-Id: Ib1cde6352afe9b2a256da7de47739e847e7a8b69 --- es2panda/aot/main.cpp | 3 +- es2panda/aot/options.cpp | 7 ++ es2panda/aot/options.h | 6 ++ es2panda/binder/binder.cpp | 4 +- es2panda/compiler/core/emitter/commonjs.cpp | 12 +-- es2panda/compiler/core/emitter/emitter.cpp | 54 +++------- es2panda/compiler/core/emitter/emitter.h | 6 +- es2panda/es2panda.cpp | 3 +- es2panda/es2panda.h | 5 +- es2panda/ir/expressions/literal.h | 4 +- es2panda/parser/commonjs.cpp | 2 +- es2panda/parser/parserImpl.cpp | 14 +-- es2panda/parser/parserImpl.h | 9 +- es2panda/parser/program/program.h | 11 +++ ts2panda/src/base/literal.ts | 3 + ts2panda/src/base/typeSystem.ts | 30 +++--- ts2panda/src/cmdOptions.ts | 8 ++ ts2panda/src/compilerDriver.ts | 15 +-- ts2panda/src/index.ts | 31 ++++-- ts2panda/src/pandasm.ts | 16 +-- ts2panda/src/ts2panda.ts | 18 +++- ts2panda/ts2abc/ts2abc.cpp | 104 ++++++-------------- 22 files changed, 173 insertions(+), 192 deletions(-) diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index c24cface12..34406d15bc 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -153,7 +153,8 @@ int Run(int argc, const char **argv) } es2panda::Compiler compiler(options->Extension(), options->ThreadCount()); - es2panda::SourceFile input(options->SourceFile(), options->ParserInput(), options->ScriptKind()); + es2panda::SourceFile input(options->SourceFile(), options->ParserInput(), + options->RecordName(), options->ScriptKind()); auto *program = compiler.Compile(input, options->CompilerOptions()); diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 828ee541a8..163704a49f 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -66,6 +66,7 @@ bool Options::Parse(int argc, const char **argv) 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)"); + panda::PandArg recordName("record-name", "", "Specify the record name"); panda::PandArg debuggerEvaluateExpression("debugger-evaluate-expression", false, "evaluate expression in debugger mode"); panda::PandArg base64Input("base64Input", "", "base64 input of js content"); @@ -98,6 +99,7 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&inputExtension); argparser_->Add(&outputFile); argparser_->Add(&sourceFile); + argparser_->Add(&recordName); argparser_->Add(&outputProto); argparser_->PushBackTail(&inputFile); @@ -167,6 +169,11 @@ bool Options::Parse(int argc, const char **argv) compilerOutput_ = RemoveExtension(sourceFile_).append(".abc"); } + recordName_ = recordName.GetValue(); + if (recordName_.empty()) { + recordName_ = compilerOutput_.empty() ? "Base64Output" : RemoveExtension(BaseName(compilerOutput_)); + } + if (!outputProto.GetValue().empty()) { compilerProtoOutput_ = outputProto.GetValue(); } else { diff --git a/es2panda/aot/options.h b/es2panda/aot/options.h index 8ea4f47073..4cbef85454 100644 --- a/es2panda/aot/options.h +++ b/es2panda/aot/options.h @@ -91,6 +91,11 @@ public: return sourceFile_; } + const std::string &RecordName() const + { + return recordName_; + } + const std::string &ErrorMsg() const { return errorMsg_; @@ -133,6 +138,7 @@ private: std::string compilerOutput_; std::string result_; std::string sourceFile_; + std::string recordName_; std::string errorMsg_; std::string compilerProtoOutput_; int optLevel_ {0}; diff --git a/es2panda/binder/binder.cpp b/es2panda/binder/binder.cpp index dc63199470..f3a024bea2 100644 --- a/es2panda/binder/binder.cpp +++ b/es2panda/binder/binder.cpp @@ -200,11 +200,13 @@ void Binder::BuildFunction(FunctionScope *funcScope, util::StringView name) bool funcNameWithoutDot = (name.Find(".") == std::string::npos); bool funcNameWithoutBackslash = (name.Find("\\") == std::string::npos); if (name != ANONYMOUS_FUNC_NAME && funcNameWithoutDot && funcNameWithoutBackslash && !functionNames_.count(name)) { + auto internalName = program_->RecordName().Mutf8() + "." + name.Mutf8(); functionNames_.insert(name); - funcScope->BindName(name, name); + funcScope->BindName(name, util::UString(internalName, Allocator()).View()); return; } std::stringstream ss; + ss << program_->RecordName().Mutf8() << "."; uint32_t idx = functionNameIndex_++; ss << "#" << std::to_string(idx) << "#"; if (funcNameWithoutDot && funcNameWithoutBackslash) { diff --git a/es2panda/compiler/core/emitter/commonjs.cpp b/es2panda/compiler/core/emitter/commonjs.cpp index aa4a5ce538..ddf5ec3e16 100644 --- a/es2panda/compiler/core/emitter/commonjs.cpp +++ b/es2panda/compiler/core/emitter/commonjs.cpp @@ -20,17 +20,13 @@ namespace panda::es2panda::compiler { constexpr const auto LANG_EXT = panda::pandasm::extensions::Language::ECMASCRIPT; -void Emitter::GenCommonjsRecord() const +void Emitter::SetCommonjsField(bool isCommonjs) { - auto commonjsRecord = panda::pandasm::Record("_CommonJsRecord", LANG_EXT); - commonjsRecord.metadata->SetAccessFlags(panda::ACC_PUBLIC); auto isCommonJsField = panda::pandasm::Field(LANG_EXT); - isCommonJsField.name = "isCommonJs"; + isCommonJsField.name = "isCommonjs"; isCommonJsField.type = panda::pandasm::Type("u8", 0); isCommonJsField.metadata->SetValue( - panda::pandasm::ScalarValue::Create(static_cast(true))); - commonjsRecord.field_list.emplace_back(std::move(isCommonJsField)); - - prog_->record_table.emplace(commonjsRecord.name, std::move(commonjsRecord)); + panda::pandasm::ScalarValue::Create(static_cast(isCommonjs))); + rec_->field_list.emplace_back(std::move(isCommonJsField)); } } // namespace panda::es2panda::compiler \ No newline at end of file diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index 166fe985de..e03ee13bbf 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -61,7 +61,6 @@ void FunctionEmitter::Generate() GenVariablesDebugInfo(); GenSourceFileDebugInfo(); GenFunctionCatchTables(); - GenFunctionICSize(); GenLiteralBuffers(); } @@ -243,29 +242,6 @@ void FunctionEmitter::GenFunctionInstructions() } } -void FunctionEmitter::GenFunctionICSize() -{ - panda::pandasm::AnnotationData funcAnnotationData("_ESAnnotation"); - panda::pandasm::AnnotationElement icSizeAnnotationElement( - "icSize", std::make_unique( - panda::pandasm::ScalarValue::Create(pg_->IcSize()))); - funcAnnotationData.AddElement(std::move(icSizeAnnotationElement)); - - panda::pandasm::AnnotationElement parameterLengthAnnotationElement( - "parameterLength", - std::make_unique( - panda::pandasm::ScalarValue::Create(pg_->FormalParametersCount()))); - funcAnnotationData.AddElement(std::move(parameterLengthAnnotationElement)); - - panda::pandasm::AnnotationElement funcNameAnnotationElement( - "funcName", - std::make_unique( - panda::pandasm::ScalarValue::Create(pg_->FunctionName().Mutf8()))); - funcAnnotationData.AddElement(std::move(funcNameAnnotationElement)); - - func_->metadata->AddAnnotations({funcAnnotationData}); -} - void FunctionEmitter::GenFunctionCatchTables() { func_->catch_blocks.reserve(pg_->CatchList().size()); @@ -356,13 +332,13 @@ void FunctionEmitter::GenVariablesDebugInfo() Emitter::Emitter(const CompilerContext *context) { prog_ = new panda::pandasm::Program(); - prog_->lang = panda::pandasm::extensions::Language::ECMASCRIPT; + prog_->lang = LANG_EXT; + + rec_ = new panda::pandasm::Record(context->Binder()->Program()->RecordName().Mutf8(), LANG_EXT); prog_->function_table.reserve(context->Binder()->Functions().size()); - GenESAnnoatationRecord(); - if (context->Binder()->Program()->Kind() == parser::ScriptKind::COMMONJS) { - GenCommonjsRecord(); - } + + SetCommonjsField(context->Binder()->Program()->Kind() == parser::ScriptKind::COMMONJS); } Emitter::~Emitter() @@ -370,14 +346,6 @@ Emitter::~Emitter() delete prog_; } -void Emitter::GenESAnnoatationRecord() -{ - auto annotationRecord = panda::pandasm::Record("_ESAnnotation", LANG_EXT); - annotationRecord.metadata->SetAttribute("external"); - annotationRecord.metadata->SetAccessFlags(panda::ACC_ANNOTATION); - prog_->record_table.emplace(annotationRecord.name, std::move(annotationRecord)); -} - void Emitter::AddFunction(FunctionEmitter *func) { std::lock_guard lock(m_); @@ -399,16 +367,12 @@ void Emitter::AddSourceTextModuleRecord(ModuleRecordEmitter *module, const Compi { std::lock_guard lock(m_); - auto ecmaModuleRecord = panda::pandasm::Record("_ESModuleRecord", LANG_EXT); - ecmaModuleRecord.metadata->SetAccessFlags(panda::ACC_PUBLIC); - auto moduleIdxField = panda::pandasm::Field(LANG_EXT); - moduleIdxField.name = std::string {context->Binder()->Program()->SourceFile()}; + moduleIdxField.name = "moduleRecordIdx"; moduleIdxField.type = panda::pandasm::Type("u32", 0); moduleIdxField.metadata->SetValue(panda::pandasm::ScalarValue::Create( static_cast(module->Index()))); - ecmaModuleRecord.field_list.emplace_back(std::move(moduleIdxField)); - prog_->record_table.emplace(ecmaModuleRecord.name, std::move(ecmaModuleRecord)); + rec_->field_list.emplace_back(std::move(moduleIdxField)); auto &moduleLiteralsBuffer = module->Buffer(); auto literalArrayInstance = panda::pandasm::LiteralArray(std::move(moduleLiteralsBuffer)); @@ -457,6 +421,10 @@ panda::pandasm::Program *Emitter::Finalize(bool dumpDebugInfo) dumper.Dump(); } + prog_->record_table.emplace(rec_->name, std::move(*rec_)); + delete rec_; + rec_ = nullptr; + auto *prog = prog_; prog_ = nullptr; return prog; diff --git a/es2panda/compiler/core/emitter/emitter.h b/es2panda/compiler/core/emitter/emitter.h index 8c7a865f88..9b632c3d5f 100644 --- a/es2panda/compiler/core/emitter/emitter.h +++ b/es2panda/compiler/core/emitter/emitter.h @@ -34,6 +34,7 @@ namespace panda::pandasm { struct Program; struct Function; struct Ins; +struct Record; } // namespace panda::pandasm namespace panda::es2panda::ir { @@ -76,7 +77,6 @@ private: void GenInstructionDebugInfo(const IRNode *ins, panda::pandasm::Ins *pandaIns); void GenFunctionInstructions(); void GenFunctionCatchTables(); - void GenFunctionICSize(); void GenScopeVariableInfo(const binder::Scope *scope); void GenSourceFileDebugInfo(); void GenVariablesDebugInfo(); @@ -105,11 +105,11 @@ public: panda::pandasm::Program *Finalize(bool dumpDebugInfo); private: - void GenESAnnoatationRecord(); - void GenCommonjsRecord() const; + void SetCommonjsField(bool isCommonjs); std::mutex m_; panda::pandasm::Program *prog_; + panda::pandasm::Record *rec_; }; } // namespace panda::es2panda::compiler diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index 3e384a3354..b423c8dd47 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -47,10 +47,11 @@ panda::pandasm::Program *Compiler::Compile(const SourceFile &input, const Compil /* TODO(dbatyai): pass string view */ std::string fname(input.fileName); std::string src(input.source); + std::string rname(input.recordName); parser::ScriptKind kind(input.scriptKind); try { - auto ast = parser_->Parse(fname, src, kind); + auto ast = parser_->Parse(fname, src, rname, kind); if (options.dumpAst) { std::cout << ast.Dump() << std::endl; diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index 9a82c093ed..18127c3109 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -41,13 +41,14 @@ enum class ScriptExtension { }; struct SourceFile { - SourceFile(std::string_view fn, std::string_view s, parser::ScriptKind sk) - : fileName(fn), source(s), scriptKind(sk) + SourceFile(std::string_view fn, std::string_view s, std::string_view rn, parser::ScriptKind sk) + : fileName(fn), source(s), recordName(rn), scriptKind(sk) { } std::string_view fileName {}; std::string_view source {}; + std::string_view recordName {}; parser::ScriptKind scriptKind {}; }; diff --git a/es2panda/ir/expressions/literal.h b/es2panda/ir/expressions/literal.h index c38869152d..86c3256f5b 100644 --- a/es2panda/ir/expressions/literal.h +++ b/es2panda/ir/expressions/literal.h @@ -41,7 +41,9 @@ enum class LiteralTag { GENERATOR_METHOD, ACCESSOR, METHODAFFILIATE, - ASYNC_GENERATOR_METHOD, + // 0x0a - 0x15 for ARRAY_Type + ASYNC_GENERATOR_METHOD = 22, + TYPEINDEX = 23, NULL_VALUE = 255, }; diff --git a/es2panda/parser/commonjs.cpp b/es2panda/parser/commonjs.cpp index 110c378c26..cd28c9d198 100644 --- a/es2panda/parser/commonjs.cpp +++ b/es2panda/parser/commonjs.cpp @@ -53,7 +53,7 @@ void ParserImpl::AddCommonjsArgs(ArenaVector &args) } } -void ParserImpl::ParseCommonjs(const std::string &fileName, const std::string &source) +void ParserImpl::ParseCommonjs() { // create FunctionExpression as callee ir::FunctionExpression *funcExpr = nullptr; diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index 99ca9bd404..d6bfecb3bf 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -108,9 +108,11 @@ std::unique_ptr ParserImpl::InitLexer(const std::string &fileName, return lexer; } -Program ParserImpl::Parse(const std::string &fileName, const std::string &source, ScriptKind kind) +Program ParserImpl::Parse(const std::string &fileName, const std::string &source, + const std::string &recordName, ScriptKind kind) { program_.SetKind(kind); + program_.SetRecordName(recordName); /* * In order to make the lexer's memory alive, the return value 'lexer' can not be omitted. @@ -118,15 +120,15 @@ Program ParserImpl::Parse(const std::string &fileName, const std::string &source auto lexer = InitLexer(fileName, source); switch (kind) { case ScriptKind::SCRIPT: { - ParseScript(fileName, source); + ParseScript(); break; } case ScriptKind::MODULE: { - ParseModule(fileName, source); + ParseModule(); break; } case ScriptKind::COMMONJS: { - ParseCommonjs(fileName, source); + ParseCommonjs(); break; } default: { @@ -137,12 +139,12 @@ Program ParserImpl::Parse(const std::string &fileName, const std::string &source return std::move(program_); } -void ParserImpl::ParseScript(const std::string &fileName, const std::string &source) +void ParserImpl::ParseScript() { ParseProgram(ScriptKind::SCRIPT); } -void ParserImpl::ParseModule(const std::string &fileName, const std::string &source) +void ParserImpl::ParseModule() { context_.Status() |= (ParserStatus::MODULE); ParseProgram(ScriptKind::MODULE); diff --git a/es2panda/parser/parserImpl.h b/es2panda/parser/parserImpl.h index 1c27794daf..0a70e8e116 100644 --- a/es2panda/parser/parserImpl.h +++ b/es2panda/parser/parserImpl.h @@ -176,7 +176,8 @@ public: NO_MOVE_SEMANTIC(ParserImpl); ~ParserImpl() = default; - Program Parse(const std::string &fileName, const std::string &source, ScriptKind kind); + Program Parse(const std::string &fileName, const std::string &source, + const std::string &recordName, ScriptKind kind); ScriptExtension Extension() const; @@ -205,15 +206,15 @@ private: } [[nodiscard]] std::unique_ptr InitLexer(const std::string &fileName, const std::string &source); - void ParseScript(const std::string &fileName, const std::string &source); - void ParseModule(const std::string &fileName, const std::string &source); + void ParseScript(); + void ParseModule(); /* * Transform the commonjs's AST by wrapping the sourceCode * e.g. (function (exports, require, module, __filename, __dirname) { * [Origin_SourceCode] * })(exports, require, module, __filename, __dirname); */ - void ParseCommonjs(const std::string &fileName, const std::string &source); + void ParseCommonjs(); void AddCommonjsParams(ArenaVector ¶ms); void AddCommonjsArgs(ArenaVector &args); void ParseProgram(ScriptKind kind); diff --git a/es2panda/parser/program/program.h b/es2panda/parser/program/program.h index 667d38cffe..54a68dcdb8 100644 --- a/es2panda/parser/program/program.h +++ b/es2panda/parser/program/program.h @@ -84,6 +84,11 @@ public: return sourceFile_.View(); } + util::StringView RecordName() const + { + return recordName_.View(); + } + const lexer::LineIndex &GetLineIndex() const { return lineIndex_; @@ -111,6 +116,11 @@ public: lineIndex_ = lexer::LineIndex(SourceCode()); } + void SetRecordName(const std::string &recordName) + { + recordName_ = util::UString(recordName, Allocator()); + } + std::string Dump() const; void SetKind(ScriptKind kind); @@ -120,6 +130,7 @@ private: ir::BlockStatement *ast_ {}; util::UString sourceCode_ {}; util::UString sourceFile_ {}; + util::UString recordName_ {}; ScriptKind kind_ {}; ScriptExtension extension_ {}; lexer::LineIndex lineIndex_ {}; diff --git a/ts2panda/src/base/literal.ts b/ts2panda/src/base/literal.ts index a372ef0050..79c1c0169a 100644 --- a/ts2panda/src/base/literal.ts +++ b/ts2panda/src/base/literal.ts @@ -22,6 +22,9 @@ export enum LiteralTag { GENERATOR = 7, ACCESSOR = 8, METHODAFFILIATE = 9, + // 0x0a - 0x15 for ARRAY_Type + ASYNCGENERATOR = 22, + TYPEINDEX = 23, NULLVALUE = 255 } diff --git a/ts2panda/src/base/typeSystem.ts b/ts2panda/src/base/typeSystem.ts index 3920efbff3..a4fa806c5b 100644 --- a/ts2panda/src/base/typeSystem.ts +++ b/ts2panda/src/base/typeSystem.ts @@ -407,7 +407,7 @@ export class ClassType extends BaseType { classTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.extendsHeritage)); classTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.implementsHeritages.length)); this.implementsHeritages.forEach(heritage => { - classTypeLiterals.push(new Literal(LiteralTag.INTEGER, heritage)); + classTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, heritage)); }); // record unstatic fields and methods @@ -428,7 +428,7 @@ export class ClassType extends BaseType { classTypeLiterals.push(new Literal(LiteralTag.INTEGER, transferredTarget.size)); transferredTarget.forEach((typeInfo, name) => { classTypeLiterals.push(new Literal(LiteralTag.STRING, name)); - classTypeLiterals.push(new Literal(LiteralTag.INTEGER, typeInfo[0])); // typeIndex + classTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, typeInfo[0])); // typeIndex classTypeLiterals.push(new Literal(LiteralTag.INTEGER, typeInfo[1])); // accessFlag classTypeLiterals.push(new Literal(LiteralTag.INTEGER, typeInfo[2])); // readonly }); @@ -440,7 +440,7 @@ export class ClassType extends BaseType { classTypeLiterals.push(new Literal(LiteralTag.INTEGER, transferredTarget.size)); transferredTarget.forEach((typeInfo, name) => { classTypeLiterals.push(new Literal(LiteralTag.STRING, name)); - classTypeLiterals.push(new Literal(LiteralTag.INTEGER, typeInfo)); + classTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, typeInfo)); }); } } @@ -462,7 +462,7 @@ export class ClassInstType extends BaseType { let classInstLiterals: Array = new Array(); classInstLiterals.push(new Literal(LiteralTag.INTEGER, L2Type.CLASSINST)); - classInstLiterals.push(new Literal(LiteralTag.INTEGER, this.shiftedReferredClassIndex)); + classInstLiterals.push(new Literal(LiteralTag.TYPEINDEX, this.shiftedReferredClassIndex)); classInstBuf.addLiterals(...classInstLiterals); return classInstBuf; @@ -570,17 +570,17 @@ export class FunctionType extends BaseType { funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.parameters[0])); funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.parameters.length - 1)); for (let i = 1; i < this.parameters.length; i++) { - funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.parameters[i])); + funcTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, this.parameters[i])); } } else { funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, 0)); // marker for not having 'this' param funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.parameters.length)); for (let i = 0; i < this.parameters.length; i++) { - funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.parameters[i])); + funcTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, this.parameters[i])); } } - funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.returnType)); + funcTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, this.returnType)); funcTypeBuf.addLiterals(...funcTypeLiterals); return funcTypeBuf; } @@ -657,7 +657,7 @@ export class UnionType extends BaseType { UnionTypeLiterals.push(new Literal(LiteralTag.INTEGER, L2Type.UNION)); UnionTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.unionedTypeArray.length)); for (let type of this.unionedTypeArray) { - UnionTypeLiterals.push(new Literal(LiteralTag.INTEGER, type)); + UnionTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, type)); } UnionTypeBuf.addLiterals(...UnionTypeLiterals); return UnionTypeBuf; @@ -702,7 +702,7 @@ export class ArrayType extends BaseType { let arrayBuf = new LiteralBuffer(); let arrayLiterals: Array = new Array(); arrayLiterals.push(new Literal(LiteralTag.INTEGER, L2Type.ARRAY)); - arrayLiterals.push(new Literal(LiteralTag.INTEGER, this.referedTypeIndex)); + arrayLiterals.push(new Literal(LiteralTag.TYPEINDEX, this.referedTypeIndex)); arrayBuf.addLiterals(...arrayLiterals); return arrayBuf; } @@ -737,7 +737,7 @@ export class ObjectType extends BaseType { objLiterals.push(new Literal(LiteralTag.INTEGER, this.properties.size)); this.properties.forEach((typeIndex, name) => { objLiterals.push(new Literal(LiteralTag.STRING, name)); - objLiterals.push(new Literal(LiteralTag.INTEGER, typeIndex)); + objLiterals.push(new Literal(LiteralTag.TYPEINDEX, typeIndex)); }); objTypeBuf.addLiterals(...objLiterals); return objTypeBuf; @@ -847,7 +847,7 @@ export class InterfaceType extends BaseType { interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.heritages.length)); this.heritages.forEach(heritage => { - interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, heritage)); + interfaceTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, heritage)); }); // record fields and methods @@ -864,7 +864,7 @@ export class InterfaceType extends BaseType { interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, transferredTarget.size)); transferredTarget.forEach((typeInfo, name) => { interfaceTypeLiterals.push(new Literal(LiteralTag.STRING, name)); - interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, typeInfo[0])); // typeIndex + interfaceTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, typeInfo[0])); // typeIndex interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, typeInfo[1])); // accessFlag interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, typeInfo[2])); // readonly }); @@ -875,7 +875,7 @@ export class InterfaceType extends BaseType { interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, transferredTarget.length)); transferredTarget.forEach(method => { - interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, method)); + interfaceTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, method)); }); } } @@ -904,10 +904,10 @@ export class BuiltinContainerType extends BaseType { let UnionTypeBuf = new LiteralBuffer(); let UnionTypeLiterals: Array = new Array(); UnionTypeLiterals.push(new Literal(LiteralTag.INTEGER, L2Type.BUILTINCONTAINER)); - UnionTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.builtinTypeIndex)); + UnionTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, this.builtinTypeIndex)); UnionTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.containerArray.length)); for (let type of this.containerArray) { - UnionTypeLiterals.push(new Literal(LiteralTag.INTEGER, type)); + UnionTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, type)); } UnionTypeBuf.addLiterals(...UnionTypeLiterals); return UnionTypeBuf; diff --git a/ts2panda/src/cmdOptions.ts b/ts2panda/src/cmdOptions.ts index 87064a12c1..68440a46f5 100644 --- a/ts2panda/src/cmdOptions.ts +++ b/ts2panda/src/cmdOptions.ts @@ -50,6 +50,7 @@ const ts2pandaOptions = [ { name: 'function-sourcecode', type: Boolean, defaultValue: false, description: "Record functions' sourceCode to support the feature of [function].toString()" }, { name: 'expression-watch-toolchain', type: String, defaultValue: "es2panda", description: "Specify the tool chain used to transform the expression" }, { name: 'source-file', type: String, defaultValue: "", description: "specify the file path info recorded in generated abc" }, + { name: 'record-name', type: String, defaultValue: "", description: "specify the record name." } ] @@ -208,6 +209,13 @@ export class CmdOptions { return outputFile; } + static getRecordName(): string { + if (!this.options) { + return ""; + } + return this.options["record-name"]; + } + static getTimeOut(): Number { if (!this.options) { return 0; diff --git a/ts2panda/src/compilerDriver.ts b/ts2panda/src/compilerDriver.ts index 66747fbe58..ac3c7a8110 100644 --- a/ts2panda/src/compilerDriver.ts +++ b/ts2panda/src/compilerDriver.ts @@ -61,6 +61,7 @@ export class PendingCompilationUnit { export class CompilerDriver { static isTsFile: boolean = false; private fileName: string; + private recordName: string; private passes: Pass[] = []; private compilationUnits: PandaGen[]; pendingCompilationUnits: PendingCompilationUnit[]; @@ -70,8 +71,9 @@ export class CompilerDriver { private needDumpHeader: boolean = true; private ts2abcProcess: any = undefined; - constructor(fileName: string) { + constructor(fileName: string, recordName: string) { this.fileName = fileName; + this.recordName = recordName; // register passes here this.passes = [ new CacheExpander(), @@ -175,6 +177,7 @@ export class CompilerDriver { listenErrorEvent(ts2abcProc); try { + Ts2Panda.dumpRecord(ts2abcProc, this.recordName); Ts2Panda.dumpCmdOptions(ts2abcProc); for (let i = 0; i < this.pendingCompilationUnits.length; i++) { @@ -360,13 +363,13 @@ export class CompilerDriver { if (name == '') { if ((ts.isFunctionDeclaration(node) && hasExportKeywordModifier(node) && hasDefaultKeywordModifier(node)) || ts.isExportAssignment(findOuterNodeOfParenthesis(node))) { - return 'default'; + return `${this.recordName}.default`; } - return `#${this.getFuncId(funcNode)}#`; + return `${this.recordName}.#${this.getFuncId(funcNode)}#`; } if (name == "func_main_0") { - return `#${this.getFuncId(funcNode)}#${name}`; + return `${this.recordName}.#${this.getFuncId(funcNode)}#${name}`; } let funcNameMap = recorder.getFuncNameMap(); @@ -383,7 +386,7 @@ export class CompilerDriver { name = `#${this.getFuncId(funcNode)}#` } } - return name; + return `${this.recordName}.${name}`; } getInternalNameForCtor(node: ts.ClassLikeDeclaration, ctor: ts.ConstructorDeclaration) { @@ -392,7 +395,7 @@ export class CompilerDriver { if (name.lastIndexOf(".") != -1) { name = `#${this.getFuncId(ctor)}#` } - return name; + return `${this.recordName}.${name}`; } writeBinaryFile(pandaGen: PandaGen) { diff --git a/ts2panda/src/index.ts b/ts2panda/src/index.ts index 944570172b..8cae20dcff 100644 --- a/ts2panda/src/index.ts +++ b/ts2panda/src/index.ts @@ -45,7 +45,7 @@ function checkIsGlobalDeclaration(sourceFile: ts.SourceFile) { function generateDTs(node: ts.SourceFile, options: ts.CompilerOptions) { let outputBinName = getOutputBinName(node); - let compilerDriver = new CompilerDriver(outputBinName); + let compilerDriver = new CompilerDriver(outputBinName, getRecordName(node)); setGlobalStrict(jshelpers.isEffectiveStrictModeSourceFile(node, options)); compilerDriver.compile(node); compilerDriver.showStatistics(); @@ -81,7 +81,7 @@ function main(fileNames: string[], options: ts.CompilerOptions) { (ctx: ts.TransformationContext) => { return (node: ts.SourceFile) => { let outputBinName = getOutputBinName(node); - let compilerDriver = new CompilerDriver(outputBinName); + let compilerDriver = new CompilerDriver(outputBinName, getRecordName(node)); compilerDriver.compileForSyntaxCheck(node); return node; } @@ -109,7 +109,7 @@ function main(fileNames: string[], options: ts.CompilerOptions) { node = transformCommonjsModule(node); } let outputBinName = getOutputBinName(node); - let compilerDriver = new CompilerDriver(outputBinName); + let compilerDriver = new CompilerDriver(outputBinName, getRecordName(node)); setGlobalStrict(jshelpers.isEffectiveStrictModeSourceFile(node, options)); compilerDriver.compile(node); compilerDriver.showStatistics(); @@ -148,6 +148,17 @@ function getOutputBinName(node: ts.SourceFile) { return outputBinName; } +function getRecordName(node: ts.SourceFile): string { + let recordName = CmdOptions.getRecordName(); + + if (recordName == "") { + let outputBinName = getOutputBinName(node); + recordName = path.basename(outputBinName, path.extname(outputBinName)); + } + + return recordName; +} + function getDtsFiles(libDir: string): string[] { let dtsFiles:string[] = []; function finDtsFile(dir){ @@ -170,6 +181,7 @@ function getDtsFiles(libDir: string): string[] { const stopWatchingStr = "####"; const watchAbcFileDefaultTimeOut = 10; const watchFileName = "watch_expressions"; +const watchOutputFileName = "Base64Output"; // this path is only available in sdk const es2abcBinaryPath = path["join"](__dirname, "..", "bin", path.sep); const es2abcBinaryName = /^win/.test(require('os').platform()) ? "es2abc.exe" : "es2abc"; @@ -273,7 +285,7 @@ function compileWatchExpression(jsFileName: string, errorMsgFileName: string, op return (node: ts.SourceFile) => { if (path.basename(node.fileName) == fileName) { node = sourceFile; } let outputBinName = getOutputBinName(node); - let compilerDriver = new CompilerDriver(outputBinName); + let compilerDriver = new CompilerDriver(outputBinName, watchOutputFileName); compilerDriver.compileForSyntaxCheck(node); return node; } @@ -298,7 +310,7 @@ function compileWatchExpression(jsFileName: string, errorMsgFileName: string, op node = ts.factory.updateSourceFile(node, newStatements); } let outputBinName = getOutputBinName(node); - let compilerDriver = new CompilerDriver(outputBinName); + let compilerDriver = new CompilerDriver(outputBinName, watchOutputFileName); setGlobalStrict(jshelpers.isEffectiveStrictModeSourceFile(node, options)); compilerDriver.compile(node); return node; @@ -314,10 +326,11 @@ function launchWatchEvaluateDeamon(parsed: ts.ParsedCommandLine | undefined) { console.log("startWatchingSuccess supportTimeout"); return; } - let deamonFilePrefix = CmdOptions.getEvaluateDeamonPath() + path.sep + watchFileName; - let jsFileName = deamonFilePrefix + ".js"; - let abcFileName = deamonFilePrefix + ".abc"; - let errorMsgFileName = deamonFilePrefix + ".err"; + let deamonJSFilePrefix = CmdOptions.getEvaluateDeamonPath() + path.sep + watchFileName; + let deamonABCFilePrefix = CmdOptions.getEvaluateDeamonPath() + path.sep + watchOutputFileName; + let jsFileName = deamonJSFilePrefix + ".js"; + let abcFileName = deamonABCFilePrefix + ".abc"; + let errorMsgFileName = deamonJSFilePrefix + ".err"; if (fs.existsSync(jsFileName)) { console.log("watchFileServer has been initialized supportTimeout"); diff --git a/ts2panda/src/pandasm.ts b/ts2panda/src/pandasm.ts index da58e906a6..549c9a6a3d 100644 --- a/ts2panda/src/pandasm.ts +++ b/ts2panda/src/pandasm.ts @@ -109,24 +109,10 @@ export class Function { export class Record { public name: string; - public whole_line: string; - public bound_left: number; - public bound_right: number; - public line_number: number; public metadata: Metadata; - constructor( - name: string, - whole_line: string, - bound_left: number, - bound_right: number, - line_number: number - ) { + constructor(name: string) { this.name = name; - this.whole_line = whole_line; - this.bound_left = bound_left; - this.bound_right = bound_right; - this.line_number = line_number; this.metadata = new Metadata(); } } diff --git a/ts2panda/src/ts2panda.ts b/ts2panda/src/ts2panda.ts index 384f5fb0dc..ad08af2d99 100644 --- a/ts2panda/src/ts2panda.ts +++ b/ts2panda/src/ts2panda.ts @@ -36,7 +36,8 @@ import { ModuleRecord, NamespaceImportEntry, RegularImportEntry, - Signature + Signature, + Record } from "./pandasm"; import { generateCatchTables } from "./statement/tryStatement"; import { @@ -207,6 +208,19 @@ export class Ts2Panda { ts2abc.stdio[3].write(jsonOpt + '\n'); } + static dumpRecord(ts2abc: any, recordName: string): void { + let record = { + "t": JsonType.record, + "rb": new Record(recordName) + } + let jsonRecord = escapeUnicode(JSON.stringify(record, null, 2)); + jsonRecord = "$" + jsonRecord.replace(dollarSign, '#$') + "$"; + if (CmdOptions.isEnableDebugLog()) { + Ts2Panda.jsonString += jsonRecord; + } + ts2abc.stdio[3].write(jsonRecord + '\n'); + } + // @ts-ignore static dumpPandaGen(pg: PandaGen, ts2abc: any, recordType?: boolean): void { let funcName = pg.internalName; @@ -230,7 +244,7 @@ export class Ts2Panda { } }); - if (funcName == "func_main_0") { + if (funcName.indexOf("func_main_0") !== -1) { let exportedTypes = PandaGen.getExportedTypes(); let declareddTypes = PandaGen.getDeclaredTypes(); if (exportedTypes.size != 0) { diff --git a/ts2panda/ts2abc/ts2abc.cpp b/ts2panda/ts2abc/ts2abc.cpp index 2af75f2967..fbd3e5f21f 100644 --- a/ts2panda/ts2abc/ts2abc.cpp +++ b/ts2panda/ts2abc/ts2abc.cpp @@ -52,6 +52,7 @@ constexpr std::size_t BOUND_RIGHT = 0; constexpr std::size_t LINE_NUMBER = 0; constexpr bool IS_DEFINED = true; int g_opCodeIndex = 0; +std::string g_recordName = ""; std::unordered_map g_opcodeMap = { #define OPLIST(opcode, name, optype, width, flags, def_idx, use_idxs) {g_opCodeIndex++, panda::pandasm::Opcode::opcode}, PANDA_INSTRUCTION_LIST(OPLIST) @@ -60,17 +61,9 @@ std::unordered_map g_opcodeMap = { }; // pandasm helpers -static panda::pandasm::Record MakeRecordDefinition(const std::string &name, const std::string &wholeLine, - size_t boundLeft, size_t boundRight, size_t lineNumber) +static panda::pandasm::Record MakeRecordDefinition(const std::string &name) { - auto record = panda::pandasm::Record( - name, - LANG_EXT, - boundLeft, - boundRight, - wholeLine, - IS_DEFINED, - lineNumber); + auto record = panda::pandasm::Record(name, LANG_EXT); return record; } @@ -270,6 +263,11 @@ static void ParseLiteral(const Json::Value &literal, std::vector(literal["v"].asUInt()); break; } + case static_cast(panda::panda_file::LiteralTag::TYPEINDEX): { + valueLiteral.tag_ = panda::panda_file::LiteralTag::TYPEINDEX; + valueLiteral.value_ = static_cast(literal["v"].asInt()); + break; + } case static_cast(panda::panda_file::LiteralTag::NULLVALUE): { valueLiteral.tag_ = panda::panda_file::LiteralTag::NULLVALUE; valueLiteral.value_ = static_cast(0); @@ -289,28 +287,7 @@ static panda::pandasm::Record ParseRecord(const Json::Value &record) recordName = record["name"].asString(); } - std::string wholeLine = ""; - if (record.isMember("whole_line") && record["whole_line"].isString()) { - wholeLine = ParseString(record["whole_line"].asString()); - } - - int boundLeft = -1; - if (record.isMember("bound_left") && record["bound_left"].isInt()) { - boundLeft = record["bound_left"].asInt(); - } - - int boundRight = -1; - if (record.isMember("bound_right") && record["bound_right"].isInt()) { - boundRight = record["bound_right"].asInt(); - } - - int lineNumber = -1; - if (record.isMember("line_number") && record["line_number"].isInt()) { - lineNumber = record["line_number"].asInt(); - } - - auto pandaRecord = MakeRecordDefinition(recordName, wholeLine, static_cast(boundLeft), - static_cast(boundRight), static_cast(lineNumber)); + auto pandaRecord = MakeRecordDefinition(recordName); if (record.isMember("metadata") && record["metadata"].isObject()) { auto metadata = record["metadata"]; @@ -800,35 +777,27 @@ static void GenerateESTypeAnnotationRecord(panda::pandasm::Program &prog) prog.record_table.emplace(tsTypeAnnotationRecord.name, std::move(tsTypeAnnotationRecord)); } -static void GenerateCommonJsRecord(panda::pandasm::Program &prog, bool isCommonJs) +static void SetCommonjsField(panda::pandasm::Program &prog, bool isCommonjs) { - // when multi-abc file get merged, field should be inserted in abc's own record - auto commonjsRecord = panda::pandasm::Record("_CommonJsRecord", LANG_EXT); - commonjsRecord.metadata->SetAccessFlags(panda::ACC_PUBLIC); - auto isCommonJsField = panda::pandasm::Field(LANG_EXT); - isCommonJsField.name = "isCommonJs"; - isCommonJsField.type = panda::pandasm::Type("u8", 0); - isCommonJsField.metadata->SetValue(panda::pandasm::ScalarValue::Create( - static_cast(isCommonJs))); - commonjsRecord.field_list.emplace_back(std::move(isCommonJsField)); - - prog.record_table.emplace(commonjsRecord.name, std::move(commonjsRecord)); -} - -static void GenerateESModuleRecord(panda::pandasm::Program &prog) -{ - auto ecmaModuleRecord = panda::pandasm::Record("_ESModuleRecord", LANG_EXT); - ecmaModuleRecord.metadata->SetAccessFlags(panda::ACC_PUBLIC); - prog.record_table.emplace(ecmaModuleRecord.name, std::move(ecmaModuleRecord)); + auto iter = prog.record_table.find(g_recordName); + if (iter != prog.record_table.end()) { + auto &rec = iter->second; + auto isCommonJsField = panda::pandasm::Field(LANG_EXT); + isCommonJsField.name = "isCommonjs"; + isCommonJsField.type = panda::pandasm::Type("u8", 0); + isCommonJsField.metadata->SetValue( + panda::pandasm::ScalarValue::Create(static_cast(isCommonjs))); + rec.field_list.emplace_back(std::move(isCommonJsField)); + } } -static void AddModuleRecord(panda::pandasm::Program &prog, const std::string &moduleName, uint32_t moduleIdx) +static void SetModuleRecordIdx(panda::pandasm::Program &prog, uint32_t moduleIdx) { - auto iter = prog.record_table.find("_ESModuleRecord"); + auto iter = prog.record_table.find(g_recordName); if (iter != prog.record_table.end()) { auto &rec = iter->second; auto moduleIdxField = panda::pandasm::Field(LANG_EXT); - moduleIdxField.name = moduleName; + moduleIdxField.name = "moduleRecordIdx"; moduleIdxField.type = panda::pandasm::Type("u32", 0); moduleIdxField.metadata->SetValue(panda::pandasm::ScalarValue::Create( static_cast(moduleIdx))); @@ -857,23 +826,11 @@ int ParseJson(const std::string &data, Json::Value &rootValue) return RETURN_SUCCESS; } -static void ParseModuleMode(const Json::Value &rootValue, panda::pandasm::Program &prog) -{ - Logd("----------------parse module_mode-----------------"); - if (rootValue.isMember("module_mode") && rootValue["module_mode"].isBool()) { - if (rootValue["module_mode"].asBool()) { - GenerateESModuleRecord(prog); - } - } -} - -static void ParseCommonJsModuleMode(const Json::Value &rootValue, panda::pandasm::Program &prog) +static void SetCommonJsModuleMode(const Json::Value &rootValue, panda::pandasm::Program &prog) { Logd("------------parse commonjs_module_mode-------------"); if (rootValue.isMember("commonjs_module") && rootValue["commonjs_module"].isBool()) { - if (rootValue["commonjs_module"].asBool()) { - GenerateCommonJsRecord(prog, true); - } + SetCommonjsField(prog, rootValue["commonjs_module"].asBool()); } } @@ -942,8 +899,7 @@ static void ParseOptions(const Json::Value &rootValue, panda::pandasm::Program & { GenerateESCallTypeAnnotationRecord(prog); GenerateESTypeAnnotationRecord(prog); - ParseModuleMode(rootValue, prog); - ParseCommonJsModuleMode(rootValue, prog); + SetCommonJsModuleMode(rootValue, prog); ParseLogEnable(rootValue); ParseDebugMode(rootValue); ParseOptLevel(rootValue); @@ -958,9 +914,10 @@ static void ParseSingleFunc(const Json::Value &rootValue, panda::pandasm::Progra prog.function_table.emplace(function.name.c_str(), std::move(function)); } -static void ParseSingleRec(const Json::Value &rootValue, panda::pandasm::Program &prog) +static void ParseRec(const Json::Value &rootValue, panda::pandasm::Program &prog) { auto record = ParseRecord(rootValue["rb"]); + g_recordName = record.name; prog.record_table.emplace(record.name.c_str(), std::move(record)); } @@ -1102,8 +1059,7 @@ static void ParseSingleModule(const Json::Value &rootValue, panda::pandasm::Prog ParseIndirectExportEntries(moduleRecord["indirectExportEntries"], moduleLiteralArray); ParseStarExportEntries(moduleRecord["starExportEntries"], moduleLiteralArray); - auto moduleName = ParseString(moduleRecord["moduleName"].asString()); - AddModuleRecord(prog, moduleName, g_literalArrayCount); + SetModuleRecordIdx(prog, g_literalArrayCount); auto moduleLiteralarrayInstance = panda::pandasm::LiteralArray(moduleLiteralArray); prog.literalarray_table.emplace(std::to_string(g_literalArrayCount++), std::move(moduleLiteralarrayInstance)); @@ -1153,7 +1109,7 @@ static int ParseSmallPieceJson(const std::string &subJson, panda::pandasm::Progr } case static_cast(JsonType::RECORD): { if (rootValue.isMember("rb") && rootValue["rb"].isObject()) { - ParseSingleRec(rootValue, prog); + ParseRec(rootValue, prog); } break; } -- Gitee From 17a7b7e20519e4e2b272c59da4ad10077054b4fb Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Sat, 20 Aug 2022 20:04:11 +0800 Subject: [PATCH 06/23] Add serialize program to proto of ts2abc Signed-off-by: zhangrengao Change-Id: Ia88f4eba4b2c68de069e5df68bd784a790931a92 --- es2panda/aot/main.cpp | 5 ++++- es2panda/aot/options.cpp | 6 ++++-- ts2panda/src/cmdOptions.ts | 7 ++++++- ts2panda/src/ts2panda.ts | 3 ++- ts2panda/ts2abc/BUILD.gn | 6 +++++- ts2panda/ts2abc/main.cpp | 3 +-- ts2panda/ts2abc/ts2abc.cpp | 31 +++++++++++++++++++++++++++++-- ts2panda/ts2abc/ts2abc.h | 3 +-- ts2panda/ts2abc/ts2abc_options.h | 18 ++++++++++++++++++ 9 files changed, 70 insertions(+), 12 deletions(-) diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index 34406d15bc..84b03433ef 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -126,7 +126,10 @@ static int GenerateProgram(panda::pandasm::Program *prog, std::unique_ptrcompilerProtoOutput().size() > 0) { + panda::proto::ProtobufSnapshotGenerator::GenerateSnapshot(*prog, options->compilerProtoOutput()); + return 0; + } if (!panda::pandasm::AsmEmitter::Emit(output, *prog, statp, mapsp, true)) { return 1; diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 163704a49f..7cdd090b8e 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -71,9 +71,13 @@ bool Options::Parse(int argc, const char **argv) "evaluate expression in debugger mode"); panda::PandArg base64Input("base64Input", "", "base64 input of js content"); panda::PandArg base64Output("base64Output", false, "output panda file content as base64 to std out"); +<<<<<<< HEAD panda::PandArg sourceFile("source-file", "", "specify the file path info recorded in generated abc"); panda::PandArg outputProto("outputProto", "", "Compiler proto serialize binary output (.bin)"); +======= + panda::PandArg outputProto("outputProto", "", "compiler proto serialize binary output (.proto)"); +>>>>>>> Add serialize program to proto of ts2abc // tail arguments panda::PandArg inputFile("input", "", "input file"); @@ -176,8 +180,6 @@ bool Options::Parse(int argc, const char **argv) if (!outputProto.GetValue().empty()) { compilerProtoOutput_ = outputProto.GetValue(); - } else { - compilerProtoOutput_ = ""; } std::string extension = inputExtension.GetValue(); diff --git a/ts2panda/src/cmdOptions.ts b/ts2panda/src/cmdOptions.ts index 68440a46f5..d2d740ef84 100644 --- a/ts2panda/src/cmdOptions.ts +++ b/ts2panda/src/cmdOptions.ts @@ -50,7 +50,8 @@ const ts2pandaOptions = [ { name: 'function-sourcecode', type: Boolean, defaultValue: false, description: "Record functions' sourceCode to support the feature of [function].toString()" }, { name: 'expression-watch-toolchain', type: String, defaultValue: "es2panda", description: "Specify the tool chain used to transform the expression" }, { name: 'source-file', type: String, defaultValue: "", description: "specify the file path info recorded in generated abc" }, - { name: 'record-name', type: String, defaultValue: "", description: "specify the record name." } + { name: 'record-name', type: String, defaultValue: "", description: "specify the record name." }, + { name: 'output-proto', type: String, defaultValue: "", description: "Compiler proto serialize binary output (.proto)" } ] @@ -314,6 +315,10 @@ export class CmdOptions { static getSourceFile(): string { return this.options["source-file"]; } + + static getOutputproto(): string { + return this.options["output-proto"]; + } // @ts-ignore static parseUserCmd(args: string[]): ts.ParsedCommandLine | undefined { diff --git a/ts2panda/src/ts2panda.ts b/ts2panda/src/ts2panda.ts index ad08af2d99..349e15ec0c 100644 --- a/ts2panda/src/ts2panda.ts +++ b/ts2panda/src/ts2panda.ts @@ -198,7 +198,8 @@ export class Ts2Panda { "opt_level": CmdOptions.getOptLevel(), "opt_log_level": CmdOptions.getOptLogLevel(), "display_typeinfo": CmdOptions.getDisplayTypeinfo(), - "is_dts_file": isGlobalDeclare() + "is_dts_file": isGlobalDeclare(), + "output-proto": CmdOptions.getOutputproto() }; let jsonOpt = JSON.stringify(options, null, 2); jsonOpt = "$" + jsonOpt.replace(dollarSign, '#$') + "$"; diff --git a/ts2panda/ts2abc/BUILD.gn b/ts2panda/ts2abc/BUILD.gn index 7e723caf01..d299983578 100755 --- a/ts2panda/ts2abc/BUILD.gn +++ b/ts2panda/ts2abc/BUILD.gn @@ -40,6 +40,7 @@ config("ts2abc_config") { "$ark_root/libpandabase:arkbase_public_config", "$ark_root/runtime:arkruntime_public_config", "$ark_root/assembler:arkassembler_public_config", + "//arkcompiler/ets_frontend/merge_abc:panda_assembly_proto_public_config", ] if (enable_bytecode_optimizer) { @@ -91,7 +92,10 @@ if (!defined(ark_independent_build)) { "-Wno-unknown-warning-option", ] - deps = [ sdk_libc_secshared_dep ] + deps = [ + sdk_libc_secshared_dep, + "//arkcompiler/ets_frontend/merge_abc:panda_assembly_proto_static", + ] if (is_linux || is_mingw || is_mac) { deps += [ diff --git a/ts2panda/ts2abc/main.cpp b/ts2panda/ts2abc/main.cpp index 4a5b3ecd98..c284060058 100644 --- a/ts2panda/ts2abc/main.cpp +++ b/ts2panda/ts2abc/main.cpp @@ -92,8 +92,7 @@ int main(int argc, const char *argv[]) return panda::ts2abc::RETURN_FAILED; } - if (!panda::ts2abc::GenerateProgram(data, output, options.GetCompileByPipeArg(), - options.GetOptLevelArg(), optLogLevel)) { + if (!panda::ts2abc::GenerateProgram(data, output, options)) { std::cerr << "call GenerateProgram fail" << std::endl; return panda::ts2abc::RETURN_FAILED; } diff --git a/ts2panda/ts2abc/ts2abc.cpp b/ts2panda/ts2abc/ts2abc.cpp index fbd3e5f21f..4a236df478 100644 --- a/ts2panda/ts2abc/ts2abc.cpp +++ b/ts2panda/ts2abc/ts2abc.cpp @@ -28,6 +28,7 @@ #include "ts2abc_options.h" #include "type_adapter.h" #include "ts2abc.h" +#include "protobufSnapshotGenerator.h" #ifdef ENABLE_BYTECODE_OPT #include "optimize_bytecode.h" @@ -46,6 +47,7 @@ bool g_isDtsFile = false; std::string g_optLogLevel = "error"; uint32_t g_literalArrayCount = 0; using ts2abc_type_adapter::TypeAdapter; +std::string g_compilerOutputProto = ""; constexpr std::size_t BOUND_LEFT = 0; constexpr std::size_t BOUND_RIGHT = 0; @@ -884,6 +886,12 @@ static void ParseIsDtsFile(const Json::Value &rootValue) } } +static void ParseCompilerOutputProto(const Json::Value &rootValue) { + Logd("-----------------parse compiler output proto-----------------"); + if (rootValue.isMember("output-proto") && rootValue["output-proto"].isString()) { + g_compilerOutputProto = rootValue["output-proto"].asString(); + } +} static void ReplaceAllDistinct(std::string &str, const std::string &oldValue, const std::string &newValue) { for (std::string::size_type pos(0); pos != std::string::npos; pos += newValue.length()) { @@ -906,6 +914,7 @@ static void ParseOptions(const Json::Value &rootValue, panda::pandasm::Program & ParseDisplayTypeinfo(rootValue); ParseOptLogLevel(rootValue); ParseIsDtsFile(rootValue); + ParseCompilerOutputProto(rootValue); } static void ParseSingleFunc(const Json::Value &rootValue, panda::pandasm::Program &prog) @@ -1257,9 +1266,11 @@ static bool ReadFromPipe(panda::pandasm::Program &prog) return true; } -bool GenerateProgram([[maybe_unused]] const std::string &data, const std::string &output, bool isParsingFromPipe, - int optLevel, std::string &optLogLevel) +bool GenerateProgram([[maybe_unused]] const std::string &data, const std::string &output, panda::ts2abc::Options options) { + bool isParsingFromPipe = options.GetCompileByPipeArg(); + int optLevel = options.GetOptLevelArg(); + std::string optLogLevel = options.GetOptLogLevelArg(); panda::pandasm::Program prog = panda::pandasm::Program(); prog.lang = panda::pandasm::extensions::Language::ECMASCRIPT; @@ -1277,6 +1288,11 @@ bool GenerateProgram([[maybe_unused]] const std::string &data, const std::string Logd("parsing done, calling pandasm\n"); + std::string compilerOutputProto = g_compilerOutputProto; + if (options.GetCompilerOutputProto().size() > 0) { + compilerOutputProto = options.GetCompilerOutputProto(); + } + TypeAdapter ada(g_displayTypeinfo); ada.AdaptTypeForProgram(&prog); @@ -1302,7 +1318,14 @@ bool GenerateProgram([[maybe_unused]] const std::string &data, const std::string std::cerr << "Failed to emit binary data: " << panda::pandasm::AsmEmitter::GetLastError() << std::endl; return false; } + panda::bytecodeopt::OptimizeBytecode(&prog, mapsp, output.c_str(), true); + + if (compilerOutputProto.size() > 0) { + panda::proto::ProtobufSnapshotGenerator::GenerateSnapshot(prog, compilerOutputProto); + return true; + } + if (!panda::pandasm::AsmEmitter::Emit(output.c_str(), prog, statp, mapsp, emitDebugInfo)) { std::cerr << "Failed to emit binary data: " << panda::pandasm::AsmEmitter::GetLastError() << std::endl; return false; @@ -1310,6 +1333,10 @@ bool GenerateProgram([[maybe_unused]] const std::string &data, const std::string return true; } #endif + if (compilerOutputProto.size() > 0) { + panda::proto::ProtobufSnapshotGenerator::GenerateSnapshot(prog, compilerOutputProto); + return true; + } if (!panda::pandasm::AsmEmitter::Emit(output.c_str(), prog, nullptr)) { std::cerr << "Failed to emit binary data: " << panda::pandasm::AsmEmitter::GetLastError() << std::endl; diff --git a/ts2panda/ts2abc/ts2abc.h b/ts2panda/ts2abc/ts2abc.h index 019b5e8c7f..421205bb35 100644 --- a/ts2panda/ts2abc/ts2abc.h +++ b/ts2panda/ts2abc/ts2abc.h @@ -49,8 +49,7 @@ enum class OptLevel { }; bool HandleJsonFile(const std::string &input, std::string &data); -bool GenerateProgram(const std::string &data, const std::string &output, bool isParsingFromPipe, - int optLevel, std::string &optLogLevel); +bool GenerateProgram(const std::string &data, const std::string &output, panda::ts2abc::Options options); bool GetDebugLog(); void ParseLogEnable(const Json::Value &rootValue); bool GetDebugModeEnabled(); diff --git a/ts2panda/ts2abc/ts2abc_options.h b/ts2panda/ts2abc/ts2abc_options.h index 310c98e707..76f326fe25 100755 --- a/ts2panda/ts2abc/ts2abc_options.h +++ b/ts2panda/ts2abc/ts2abc_options.h @@ -39,6 +39,7 @@ namespace panda::ts2abc { parser->Add(&bc_version_arg_); parser->Add(&bc_min_version_arg_); parser->Add(&compile_by_pipe_arg_); + parser->Add(&compiler_output_proto_); parser->EnableTail(); parser->PushBackTail(&Tail_Arg1_arg_); parser->PushBackTail(&Tail_Arg2_arg_); @@ -149,6 +150,21 @@ namespace panda::ts2abc { return compile_by_pipe_arg_.WasSet(); } + std::string GetCompilerOutputProto() const + { + return compiler_output_proto_.GetValue(); + } + + void SetCompilerOutputProto(std::string value) + { + compiler_output_proto_.SetValue(value); + } + + bool WasSetCompilerOutputProto() const + { + return compiler_output_proto_.WasSet(); + } + std::string GetTailArg1() const { return Tail_Arg1_arg_.GetValue(); @@ -207,6 +223,8 @@ namespace panda::ts2abc { R"(Print ark bytecode minimum supported version)"}; panda::PandArg compile_by_pipe_arg_{ "compile-by-pipe", false, R"(Compile a json file that is passed by pipe)"}; + panda::PandArg compiler_output_proto_{ "output-proto", "", + R"(compiler proto serialize binary output (.proto))"}; panda::PandArg Tail_Arg1_arg_{ "ARG_1", "", R"(Path to input(json file) or path to output(ark bytecode)" " when 'compile-by-pipe' enabled)"}; -- Gitee From 2708b350cbdc9df12ac4352d4aba61e483ff7a4f Mon Sep 17 00:00:00 2001 From: gavin1012_hw Date: Sat, 20 Aug 2022 22:00:59 +0800 Subject: [PATCH 07/23] Enable merge_abc compilation in different platform Signed-off-by: gavin1012_hw Change-Id: I4428b7e3b4a8e90d5cbfbc38bc5deafc0e409332 --- merge_abc/BUILD.gn | 12 ++++++ merge_abc/src/mergeProgramProto.cpp | 62 +++++++++++++++++++++++++---- 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/merge_abc/BUILD.gn b/merge_abc/BUILD.gn index f4b349d855..5d79da65b7 100644 --- a/merge_abc/BUILD.gn +++ b/merge_abc/BUILD.gn @@ -182,6 +182,10 @@ ohos_executable("merge_abc") { libs = [ libcpp_static_lib ] } + defines = [ + "PANDA_TARGET_LINUX", + ] + # for statically linking pthread ldflags += [ "-Wl,--whole-archive", @@ -189,6 +193,14 @@ ohos_executable("merge_abc") { "-lpthread", "-Wl,--no-whole-archive", ] + } else if (is_mac) { + defines = [ + "PANDA_TARGET_MACOS", + ] + } else if (is_mingw) { + defines = [ + "PANDA_TARGET_WINDOWS", + ] } if (!is_mac) { diff --git a/merge_abc/src/mergeProgramProto.cpp b/merge_abc/src/mergeProgramProto.cpp index 6482b24138..0b48176309 100644 --- a/merge_abc/src/mergeProgramProto.cpp +++ b/merge_abc/src/mergeProgramProto.cpp @@ -21,7 +21,11 @@ #include "libpandafile/literal_data_accessor.h" #include -#include +#if defined(PANDA_TARGET_WINDOWS) +#include +#else +#include +#endif #include namespace panda::proto { @@ -53,17 +57,53 @@ int TraverseProtoBinPath(const std::string &protoBinPath, const std::string &pro { panda::pandasm::Program program; - const std::filesystem::path fsPath(protoBinPath); - if (!std::filesystem::exists(fsPath)) { +#if PANDA_TARGET_WINDOWS + int handle = 0; + struct _finddata_t fileInfo; + std::string path; + if ((handle = _findfirst(path.assign(protoBinPath).append("\\*").c_str(), &fileInfo)) == -1) { return 1; } - for (auto &itr : std::filesystem::directory_iterator(fsPath)) { - if (std::filesystem::is_directory(itr.status())) { - if (TraverseProtoBinPath(itr.path().string(), protoBinSuffix, mergeProgram, std::move(allocator)) != 0) { + do + { + if (fileInfo.attrib & _A_SUBDIR) { + if((!strncmp(fileInfo.name, ".", 1)) || (!strncmp(fileInfo.name, "..", 2))) { + continue; + } + if (TraverseProtoBinPath(path.assign(protoBinPath).append("\\").append(fileInfo.name), protoBinSuffix, + mergeProgram, std::move(allocator)) != 0) { + _findclose(handle); + return 1; + } + } else { + std::string fileName(fileInfo.name); + if (fileName.substr(fileName.find_last_of(".") + 1).compare(protoBinSuffix) == 0) { + proto::ProtobufSnapshotGenerator::GenerateProgram( + path.assign(protoBinPath).append("\\").append(fileName), program, std::move(allocator)); + mergeProgram->Merge(&program); + } + } + } while (_findnext(handle, &fileInfo) == 0); + _findclose(handle); +#else + DIR *protoBin = opendir(protoBinPath.c_str()); + if (protoBin == nullptr) { + return 1; + } + dirent *dir = nullptr; + std::string pathPrefix = protoBinPath + "/"; + while ((dir = readdir(protoBin)) != nullptr) { + if((!strncmp(dir->d_name, ".", 1)) || (!strncmp(dir->d_name, "..", 2))) { + continue; + } + if (dir->d_type == DT_DIR) { + std::string subDirName = pathPrefix + dir->d_name; + if (TraverseProtoBinPath(subDirName, protoBinSuffix, mergeProgram, std::move(allocator)) != 0) { + closedir(protoBin); return 1; } } else { - auto fileName = itr.path().string(); + std::string fileName = pathPrefix + dir->d_name; std::string suffixStr = fileName.substr(fileName.find_last_of(".") + 1); if (suffixStr.compare(protoBinSuffix) == 0) { proto::ProtobufSnapshotGenerator::GenerateProgram(fileName, program, std::move(allocator)); @@ -71,6 +111,8 @@ int TraverseProtoBinPath(const std::string &protoBinPath, const std::string &pro } } } + closedir(protoBin); +#endif return 0; } @@ -185,7 +227,11 @@ int Run(int argc, const char **argv) panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps *mapsp = nullptr; std::string outputPandaFile = options->outputPandaFile(); - outputPandaFile = std::filesystem::path(protoBinPath).append(outputPandaFile); +#ifdef PANDA_TARGET_WINDOWS + outputPandaFile = protoBinPath + "\\" + outputPandaFile; +#else + outputPandaFile = protoBinPath + "/" + outputPandaFile; +#endif if (!panda::pandasm::AsmEmitter::Emit(outputPandaFile, *(mergeProgram.GetResult()), statp, mapsp, true)) { return 1; } -- Gitee From cbf28eab8f9de1dfc0669862a32ae84f7164441f Mon Sep 17 00:00:00 2001 From: hufeng Date: Mon, 22 Aug 2022 21:06:56 +0800 Subject: [PATCH 08/23] Set function internalName Signed-off-by: hufeng Change-Id: I5a572f36a8d662e988c4eac155bf7bb2bb0e027b --- es2panda/binder/binder.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/es2panda/binder/binder.cpp b/es2panda/binder/binder.cpp index f3a024bea2..5bc997bc6b 100644 --- a/es2panda/binder/binder.cpp +++ b/es2panda/binder/binder.cpp @@ -200,13 +200,13 @@ void Binder::BuildFunction(FunctionScope *funcScope, util::StringView name) bool funcNameWithoutDot = (name.Find(".") == std::string::npos); bool funcNameWithoutBackslash = (name.Find("\\") == std::string::npos); if (name != ANONYMOUS_FUNC_NAME && funcNameWithoutDot && funcNameWithoutBackslash && !functionNames_.count(name)) { - auto internalName = program_->RecordName().Mutf8() + "." + name.Mutf8(); + auto internalName = std::string(program_->RecordName()) + "." + std::string(name); functionNames_.insert(name); funcScope->BindName(name, util::UString(internalName, Allocator()).View()); return; } std::stringstream ss; - ss << program_->RecordName().Mutf8() << "."; + ss << std::string(program_->RecordName()) << "."; uint32_t idx = functionNameIndex_++; ss << "#" << std::to_string(idx) << "#"; if (funcNameWithoutDot && funcNameWithoutBackslash) { -- Gitee From c9eb6355d5c214cc80b4d065db098c5bd79aee8e Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Tue, 23 Aug 2022 10:14:54 +0800 Subject: [PATCH 09/23] Remove conflict code Signed-off-by: zhangrengao Change-Id: Iba5e55240783b9fe96aeb89165de6af5865a8446 --- es2panda/aot/options.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 7cdd090b8e..c19852724e 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -71,13 +71,9 @@ bool Options::Parse(int argc, const char **argv) "evaluate expression in debugger mode"); panda::PandArg base64Input("base64Input", "", "base64 input of js content"); panda::PandArg base64Output("base64Output", false, "output panda file content as base64 to std out"); -<<<<<<< HEAD panda::PandArg sourceFile("source-file", "", "specify the file path info recorded in generated abc"); - panda::PandArg outputProto("outputProto", "", "Compiler proto serialize binary output (.bin)"); -======= panda::PandArg outputProto("outputProto", "", "compiler proto serialize binary output (.proto)"); ->>>>>>> Add serialize program to proto of ts2abc // tail arguments panda::PandArg inputFile("input", "", "input file"); -- Gitee From bcea4ae8fa10659120c7cea95caa7ab9a8c89060 Mon Sep 17 00:00:00 2001 From: gavin1012_hw Date: Tue, 23 Aug 2022 16:26:51 +0800 Subject: [PATCH 10/23] Passing allocator pointer && Rename cpp file Signed-off-by: gavin1012_hw Change-Id: Id93be7c27851f00a08deb42a032887fc36c257e2 --- es2panda/aot/main.cpp | 1 - merge_abc/BUILD.gn | 4 ++-- .../src/{mergeOptions.cpp => Options.cpp} | 2 +- merge_abc/src/{mergeOptions.h => Options.h} | 2 +- merge_abc/src/annotationProto.cpp | 23 +++++++++--------- merge_abc/src/annotationProto.h | 8 +++---- merge_abc/src/assemblyDebugProto.cpp | 2 +- merge_abc/src/assemblyDebugProto.h | 2 +- merge_abc/src/assemblyFieldProto.cpp | 8 +++---- merge_abc/src/assemblyFieldProto.h | 4 ++-- merge_abc/src/assemblyFileLocationProto.h | 2 +- merge_abc/src/assemblyFunctionProto.cpp | 16 ++++++------- merge_abc/src/assemblyFunctionProto.h | 5 ++-- merge_abc/src/assemblyInsProto.cpp | 2 +- merge_abc/src/assemblyInsProto.h | 2 +- merge_abc/src/assemblyLabelProto.cpp | 2 +- merge_abc/src/assemblyLabelProto.h | 2 +- merge_abc/src/assemblyLiteralsProto.h | 2 +- merge_abc/src/assemblyProgramProto.cpp | 10 ++++---- merge_abc/src/assemblyProgramProto.h | 4 ++-- merge_abc/src/assemblyRecordProto.cpp | 8 +++---- merge_abc/src/assemblyRecordProto.h | 4 ++-- merge_abc/src/assemblyTypeProto.cpp | 4 ++-- merge_abc/src/assemblyTypeProto.h | 4 ++-- merge_abc/src/ideHelpersProto.cpp | 2 +- merge_abc/src/ideHelpersProto.h | 2 +- ...mergeProgramProto.cpp => mergeProgram.cpp} | 19 +++++++-------- .../{mergeProgramProto.h => mergeProgram.h} | 0 merge_abc/src/metaProto.cpp | 24 +++++++++---------- merge_abc/src/metaProto.h | 12 +++++----- merge_abc/src/protobufSnapshotGenerator.cpp | 4 ++-- merge_abc/src/protobufSnapshotGenerator.h | 4 ++-- 32 files changed, 93 insertions(+), 97 deletions(-) rename merge_abc/src/{mergeOptions.cpp => Options.cpp} (98%) rename merge_abc/src/{mergeOptions.h => Options.h} (96%) rename merge_abc/src/{mergeProgramProto.cpp => mergeProgram.cpp} (93%) rename merge_abc/src/{mergeProgramProto.h => mergeProgram.h} (100%) diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index 84b03433ef..581c99141d 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -32,7 +32,6 @@ #include #include -#include namespace panda::es2panda::aot { diff --git a/merge_abc/BUILD.gn b/merge_abc/BUILD.gn index 5d79da65b7..71beb15aed 100644 --- a/merge_abc/BUILD.gn +++ b/merge_abc/BUILD.gn @@ -149,8 +149,8 @@ ohos_static_library("panda_assembly_proto_static") { ohos_executable("merge_abc") { use_exceptions = true sources = [ - "src/mergeOptions.cpp", - "src/mergeProgramProto.cpp", + "src/Options.cpp", + "src/mergeProgram.cpp", ] include_dirs = [ "./src" ] diff --git a/merge_abc/src/mergeOptions.cpp b/merge_abc/src/Options.cpp similarity index 98% rename from merge_abc/src/mergeOptions.cpp rename to merge_abc/src/Options.cpp index 0dca2fd898..46cbc9e30c 100644 --- a/merge_abc/src/mergeOptions.cpp +++ b/merge_abc/src/Options.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "mergeOptions.h" +#include "Options.h" #include diff --git a/merge_abc/src/mergeOptions.h b/merge_abc/src/Options.h similarity index 96% rename from merge_abc/src/mergeOptions.h rename to merge_abc/src/Options.h index 4e91135856..ddff2d0935 100644 --- a/merge_abc/src/mergeOptions.h +++ b/merge_abc/src/Options.h @@ -55,7 +55,7 @@ private: std::string errorMsg_; std::string protoBinSuffix_ {"protoBin"}; std::string protoBinPath_; - std::string outputPandaFile_ {"merge.abc"}; + std::string outputPandaFile_ {"modules.abc"}; }; } #endif diff --git a/merge_abc/src/annotationProto.cpp b/merge_abc/src/annotationProto.cpp index 13a96b39d8..8f8d713449 100644 --- a/merge_abc/src/annotationProto.cpp +++ b/merge_abc/src/annotationProto.cpp @@ -26,10 +26,10 @@ void AnnotationData::Serialize(const panda::pandasm::AnnotationData &anno, proto } void AnnotationData::Deserialize(const proto_panda::AnnotationData &protoAnno, panda::pandasm::AnnotationData &anno, - std::unique_ptr &&allocator) + panda::ArenaAllocator *allocator) { for (const auto &protoElement : protoAnno.elements()) { - panda::pandasm::AnnotationElement element = AnnotationElement::Deserialize(protoElement, std::move(allocator)); + panda::pandasm::AnnotationElement element = AnnotationElement::Deserialize(protoElement, allocator); anno.AddElement(std::move(element)); } } @@ -50,15 +50,15 @@ void AnnotationElement::Serialize(const panda::pandasm::AnnotationElement &eleme } panda::pandasm::AnnotationElement &AnnotationElement::Deserialize(const proto_panda::AnnotationElement &protoElement, - std::unique_ptr &&allocator) + panda::ArenaAllocator *allocator) { if (protoElement.is_array()) { - panda::pandasm::ArrayValue array = ArrayValue::Deserialize(protoElement.array(), std::move(allocator)); + panda::pandasm::ArrayValue array = ArrayValue::Deserialize(protoElement.array(), allocator); auto element = allocator->New(protoElement.name(), std::make_unique(array)); return *element; } - panda::pandasm::ScalarValue scalar = ScalarValue::Deserialize(protoElement.scalar(), std::move(allocator)); + panda::pandasm::ScalarValue scalar = ScalarValue::Deserialize(protoElement.scalar(), allocator); auto element = allocator->New(protoElement.name(), std::make_unique(scalar)); return *element; @@ -129,7 +129,7 @@ void ScalarValue::Serialize(const panda::pandasm::ScalarValue &scalar, proto_pan } panda::pandasm::ScalarValue ScalarValue::Deserialize(const proto_panda::ScalarValue &protoScalar, - std::unique_ptr &&allocator) + panda::ArenaAllocator *allocator) { proto_panda::ScalarValue_VariantValueType scalarType = protoScalar.type(); std::variant value; @@ -151,14 +151,13 @@ panda::pandasm::ScalarValue ScalarValue::Deserialize(const proto_panda::ScalarVa break; } case proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_PANDASM_TYPE: { - value = static_cast(Type::Deserialize(protoScalar.value_type(), - std::move(allocator))); + value = static_cast(Type::Deserialize(protoScalar.value_type(), allocator)); break; } case proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_ANNOTATION_DATA: { auto protoAnnotationData = protoScalar.value_anno(); auto value = allocator->New(protoAnnotationData.record_name()); - AnnotationData::Deserialize(protoAnnotationData, *value, std::move(allocator)); + AnnotationData::Deserialize(protoAnnotationData, *value, allocator); break; } default: @@ -254,15 +253,15 @@ void ArrayValue::Serialize(const panda::pandasm::ArrayValue &array, proto_panda: } panda::pandasm::ArrayValue &ArrayValue::Deserialize(const proto_panda::ArrayValue &protoArray, - std::unique_ptr &&allocator) + panda::ArenaAllocator *allocator) { std::vector values; for (const auto &protoValue : protoArray.values()) { - panda::pandasm::ScalarValue scalar = ScalarValue::Deserialize(protoValue, std::move(allocator)); + panda::pandasm::ScalarValue scalar = ScalarValue::Deserialize(protoValue, allocator); values.emplace_back(std::move(scalar)); } auto array = allocator->New( static_cast(protoArray.component_type()), values); return *array; } -} // panda::proto \ No newline at end of file +} // panda::proto diff --git a/merge_abc/src/annotationProto.h b/merge_abc/src/annotationProto.h index 3e2bc2270e..03a4268a68 100644 --- a/merge_abc/src/annotationProto.h +++ b/merge_abc/src/annotationProto.h @@ -26,7 +26,7 @@ class AnnotationData { public: static void Serialize(const panda::pandasm::AnnotationData &anno, proto_panda::AnnotationData &protoAnno); static void Deserialize(const proto_panda::AnnotationData &protoAnno, panda::pandasm::AnnotationData &anno, - std::unique_ptr &&allocator); + panda::ArenaAllocator *allocator); }; class AnnotationElement { @@ -34,14 +34,14 @@ public: static void Serialize(const panda::pandasm::AnnotationElement &element, proto_panda::AnnotationElement &protoElement); static panda::pandasm::AnnotationElement &Deserialize(const proto_panda::AnnotationElement &protoElement, - std::unique_ptr &&allocator); + panda::ArenaAllocator *allocator); }; class ScalarValue { public: static void Serialize(const panda::pandasm::ScalarValue &scalar, proto_panda::ScalarValue &protoScalar); static panda::pandasm::ScalarValue Deserialize(const proto_panda::ScalarValue &protoScalar, - std::unique_ptr &&allocator); + panda::ArenaAllocator *allocator); static panda::pandasm::ScalarValue CreateScalarValue(const panda::pandasm::Value::Type &type, std::variant &value); @@ -51,7 +51,7 @@ class ArrayValue { public: static void Serialize(const panda::pandasm::ArrayValue &array, proto_panda::ArrayValue &protoArray); static panda::pandasm::ArrayValue &Deserialize(const proto_panda::ArrayValue &protoArray, - std::unique_ptr &&allocator); + panda::ArenaAllocator *allocator); }; } // panda::proto #endif diff --git a/merge_abc/src/assemblyDebugProto.cpp b/merge_abc/src/assemblyDebugProto.cpp index 6f6d162aa7..c04da9bd09 100644 --- a/merge_abc/src/assemblyDebugProto.cpp +++ b/merge_abc/src/assemblyDebugProto.cpp @@ -55,4 +55,4 @@ void LocalVariable::Deserialize(const proto_panda::LocalVariable &protoDebug, debug.start = protoDebug.start(); debug.length = protoDebug.length(); } -} // panda::proto \ No newline at end of file +} // panda::proto diff --git a/merge_abc/src/assemblyDebugProto.h b/merge_abc/src/assemblyDebugProto.h index e0e2dbb205..566a82bfea 100644 --- a/merge_abc/src/assemblyDebugProto.h +++ b/merge_abc/src/assemblyDebugProto.h @@ -34,4 +34,4 @@ public: panda::pandasm::debuginfo::LocalVariable &debug); }; } // panda::proto -#endif \ No newline at end of file +#endif diff --git a/merge_abc/src/assemblyFieldProto.cpp b/merge_abc/src/assemblyFieldProto.cpp index 3b32eb2941..a99b9d37d3 100644 --- a/merge_abc/src/assemblyFieldProto.cpp +++ b/merge_abc/src/assemblyFieldProto.cpp @@ -31,15 +31,15 @@ void Field::Serialize(const panda::pandasm::Field &field, proto_panda::Field &pr } void Field::Deserialize(const proto_panda::Field &protoField, panda::pandasm::Field &field, - std::unique_ptr &&allocator) + panda::ArenaAllocator *allocator) { - field.type = Type::Deserialize(protoField.type(), std::move(allocator)); + field.type = Type::Deserialize(protoField.type(), allocator); field.name = protoField.name(); - FieldMetadata::Deserialize(protoField.metadata(), field.metadata, std::move(allocator)); + FieldMetadata::Deserialize(protoField.metadata(), field.metadata, allocator); field.line_of_def = protoField.line_of_def(); field.whole_line = protoField.whole_line(); field.bound_left = protoField.bound_left(); field.bound_right = protoField.bound_right(); field.is_defined = protoField.is_defined(); } -} // panda::proto \ No newline at end of file +} // panda::proto diff --git a/merge_abc/src/assemblyFieldProto.h b/merge_abc/src/assemblyFieldProto.h index 7f885b706f..9a9857a527 100644 --- a/merge_abc/src/assemblyFieldProto.h +++ b/merge_abc/src/assemblyFieldProto.h @@ -26,7 +26,7 @@ class Field { public: static void Serialize(const panda::pandasm::Field &field, proto_panda::Field &protoField); static void Deserialize(const proto_panda::Field &protoField, panda::pandasm::Field &field, - std::unique_ptr &&allocator); + panda::ArenaAllocator *allocator); }; } // panda::proto -#endif \ No newline at end of file +#endif diff --git a/merge_abc/src/assemblyFileLocationProto.h b/merge_abc/src/assemblyFileLocationProto.h index 52eb8af33f..4479034063 100644 --- a/merge_abc/src/assemblyFileLocationProto.h +++ b/merge_abc/src/assemblyFileLocationProto.h @@ -26,4 +26,4 @@ public: static void Deserialize(const proto_panda::FileLocation &protoLocation, panda::pandasm::FileLocation &location); }; } // panda::proto -#endif \ No newline at end of file +#endif diff --git a/merge_abc/src/assemblyFunctionProto.cpp b/merge_abc/src/assemblyFunctionProto.cpp index ad570b86bb..18a0b22f6e 100644 --- a/merge_abc/src/assemblyFunctionProto.cpp +++ b/merge_abc/src/assemblyFunctionProto.cpp @@ -45,9 +45,9 @@ void Parameter::Serialize(const panda::pandasm::Function::Parameter ¶m, prot } void Parameter::Deserialize(const proto_panda::Parameter &protoParam, panda::pandasm::Function::Parameter ¶m, - std::unique_ptr &&allocator) + panda::ArenaAllocator *allocator) { - ParamMetadata::Deserialize(protoParam.metadata(), param.metadata, std::move(allocator)); + ParamMetadata::Deserialize(protoParam.metadata(), param.metadata, allocator); } void Function::Serialize(const panda::pandasm::Function &function, proto_panda::Function &protoFunction) @@ -107,9 +107,9 @@ void Function::Serialize(const panda::pandasm::Function &function, proto_panda:: } void Function::Deserialize(const proto_panda::Function &protoFunction, panda::pandasm::Function &function, - std::unique_ptr &&allocator) + panda::ArenaAllocator *allocator) { - FunctionMetadata::Deserialize(protoFunction.metadata(), function.metadata, std::move(allocator)); + FunctionMetadata::Deserialize(protoFunction.metadata(), function.metadata, allocator); for (const auto &labelUnit : protoFunction.label_table()) { auto name = labelUnit.key(); auto protoLabel = labelUnit.value(); @@ -143,18 +143,18 @@ void Function::Deserialize(const proto_panda::Function &protoFunction, panda::pa function.regs_num = protoFunction.regs_num(); for (const auto &protoParam : protoFunction.params()) { - auto paramType = Type::Deserialize(protoParam.type(), std::move(allocator)); + auto paramType = Type::Deserialize(protoParam.type(), allocator); panda::pandasm::Function::Parameter param(paramType, panda::panda_file::SourceLang::ECMASCRIPT); - Parameter::Deserialize(protoParam, param, std::move(allocator)); + Parameter::Deserialize(protoParam, param, allocator); function.params.emplace_back(std::move(param)); } function.body_presence = protoFunction.body_presence(); - function.return_type = Type::Deserialize(protoFunction.return_type(), std::move(allocator)); + function.return_type = Type::Deserialize(protoFunction.return_type(), allocator); SourceLocation::Deserialize(protoFunction.body_location(), function.body_location); if (protoFunction.has_file_location()) { FileLocation::Deserialize(protoFunction.file_location(), function.file_location.value()); } } -} // panda::proto \ No newline at end of file +} // panda::proto diff --git a/merge_abc/src/assemblyFunctionProto.h b/merge_abc/src/assemblyFunctionProto.h index 48d0496565..d3f6d495f4 100644 --- a/merge_abc/src/assemblyFunctionProto.h +++ b/merge_abc/src/assemblyFunctionProto.h @@ -38,15 +38,14 @@ class Parameter { public: static void Serialize(const panda::pandasm::Function::Parameter ¶m, proto_panda::Parameter &protoParam); static void Deserialize(const proto_panda::Parameter &protoParam, panda::pandasm::Function::Parameter ¶m, - std::unique_ptr &&allocator_); + panda::ArenaAllocator *allocator_); }; class Function { public: static void Serialize(const panda::pandasm::Function &function, proto_panda::Function &protoFunction); static void Deserialize(const proto_panda::Function &protoFunction, panda::pandasm::Function &function, - std::unique_ptr &&allocator_); + panda::ArenaAllocator *allocator_); }; } // panda::proto #endif - diff --git a/merge_abc/src/assemblyInsProto.cpp b/merge_abc/src/assemblyInsProto.cpp index de982b4bb6..dbc74fa5bb 100644 --- a/merge_abc/src/assemblyInsProto.cpp +++ b/merge_abc/src/assemblyInsProto.cpp @@ -72,4 +72,4 @@ void Ins::Deserialize(const proto_panda::Ins &protoInsn, panda::pandasm::Ins &in const proto_panda::DebuginfoIns protoDebugInfoIns = protoInsn.ins_debug(); DebuginfoIns::Deserialize(protoDebugInfoIns, insn.ins_debug); } -} // panda::proto \ No newline at end of file +} // panda::proto diff --git a/merge_abc/src/assemblyInsProto.h b/merge_abc/src/assemblyInsProto.h index a4a5365639..4ec5cc9bd4 100644 --- a/merge_abc/src/assemblyInsProto.h +++ b/merge_abc/src/assemblyInsProto.h @@ -27,4 +27,4 @@ public: static void Deserialize(const proto_panda::Ins &protoInsn, panda::pandasm::Ins &insn); }; } // panda::proto -#endif \ No newline at end of file +#endif diff --git a/merge_abc/src/assemblyLabelProto.cpp b/merge_abc/src/assemblyLabelProto.cpp index 45cd2efe19..fc6f4f5133 100644 --- a/merge_abc/src/assemblyLabelProto.cpp +++ b/merge_abc/src/assemblyLabelProto.cpp @@ -34,4 +34,4 @@ void Label::Deserialize(const proto_panda::Label &protoLabel, panda::pandasm::La FileLocation::Deserialize(protoLocation, label.file_location.value()); } } -} // panda::proto \ No newline at end of file +} // panda::proto diff --git a/merge_abc/src/assemblyLabelProto.h b/merge_abc/src/assemblyLabelProto.h index 8a2a4a2466..98bac92032 100644 --- a/merge_abc/src/assemblyLabelProto.h +++ b/merge_abc/src/assemblyLabelProto.h @@ -27,4 +27,4 @@ public: static void Deserialize(const proto_panda::Label &protoLabel, panda::pandasm::Label &label); }; } // panda::proto -#endif \ No newline at end of file +#endif diff --git a/merge_abc/src/assemblyLiteralsProto.h b/merge_abc/src/assemblyLiteralsProto.h index 9d3ada71ea..14c58667d3 100644 --- a/merge_abc/src/assemblyLiteralsProto.h +++ b/merge_abc/src/assemblyLiteralsProto.h @@ -39,4 +39,4 @@ public: static void Deserialize(const proto_panda::Literal &protoLiteral, panda::pandasm::LiteralArray::Literal &literal); }; } // panda::proto -#endif \ No newline at end of file +#endif diff --git a/merge_abc/src/assemblyProgramProto.cpp b/merge_abc/src/assemblyProgramProto.cpp index 382e0d1599..b396defe9b 100644 --- a/merge_abc/src/assemblyProgramProto.cpp +++ b/merge_abc/src/assemblyProgramProto.cpp @@ -50,7 +50,7 @@ void Program::Serialize(const panda::pandasm::Program &program, proto_panda::Pro } void Program::Deserialize(const proto_panda::Program &protoProgram, panda::pandasm::Program &program, - std::unique_ptr &&allocator) + panda::ArenaAllocator *allocator) { program.lang = static_cast(protoProgram.lang()); @@ -59,7 +59,7 @@ void Program::Deserialize(const proto_panda::Program &protoProgram, panda::panda auto protoRecord = recordUnit.value(); auto record = panda::pandasm::Record(protoRecord.name(), static_cast(protoRecord.language())); - Record::Deserialize(protoRecord, record, std::move(allocator)); + Record::Deserialize(protoRecord, record, allocator); program.record_table.insert({name, std::move(record)}); } @@ -68,7 +68,7 @@ void Program::Deserialize(const proto_panda::Program &protoProgram, panda::panda auto protoFunction = functionUnit.value(); auto function = allocator->New(protoFunction.name(), static_cast(protoFunction.language())); - Function::Deserialize(protoFunction, *function, std::move(allocator)); + Function::Deserialize(protoFunction, *function, allocator); program.function_table.insert({name, std::move(*function)}); } @@ -85,8 +85,8 @@ void Program::Deserialize(const proto_panda::Program &protoProgram, panda::panda } for (const auto &protoArrayType : protoProgram.array_types()) { - auto arrayType = Type::Deserialize(protoArrayType, std::move(allocator)); + auto arrayType = Type::Deserialize(protoArrayType, allocator); program.array_types.insert(std::move(arrayType)); } } -} // panda::proto \ No newline at end of file +} // panda::proto diff --git a/merge_abc/src/assemblyProgramProto.h b/merge_abc/src/assemblyProgramProto.h index 5017257853..3f1d09d417 100644 --- a/merge_abc/src/assemblyProgramProto.h +++ b/merge_abc/src/assemblyProgramProto.h @@ -28,7 +28,7 @@ class Program { public: static void Serialize(const panda::pandasm::Program &program, proto_panda::Program &protoProgram); static void Deserialize(const proto_panda::Program &protoProgram, panda::pandasm::Program &program, - std::unique_ptr &&allocator); + panda::ArenaAllocator *allocator); }; } // panda::proto -#endif \ No newline at end of file +#endif diff --git a/merge_abc/src/assemblyRecordProto.cpp b/merge_abc/src/assemblyRecordProto.cpp index b3e31b118e..d43a87ec55 100644 --- a/merge_abc/src/assemblyRecordProto.cpp +++ b/merge_abc/src/assemblyRecordProto.cpp @@ -41,13 +41,13 @@ void Record::Serialize(const panda::pandasm::Record &record, proto_panda::Record } void Record::Deserialize(const proto_panda::Record &protoRecord, panda::pandasm::Record &record, - std::unique_ptr &&allocator) + panda::ArenaAllocator *allocator) { record.conflict = protoRecord.conflict(); - RecordMetadata::Deserialize(protoRecord.metadata(), record.metadata, std::move(allocator)); + RecordMetadata::Deserialize(protoRecord.metadata(), record.metadata, allocator); for (const auto &protoField : protoRecord.field_list()) { auto recordField = panda::pandasm::Field(panda::panda_file::SourceLang::ECMASCRIPT); - Field::Deserialize(protoField, recordField, std::move(allocator)); + Field::Deserialize(protoField, recordField, allocator); record.field_list.emplace_back(std::move(recordField)); } record.params_num = protoRecord.params_num(); @@ -58,4 +58,4 @@ void Record::Deserialize(const proto_panda::Record &protoRecord, panda::pandasm: FileLocation::Deserialize(protoLocation, record.file_location.value()); } } -} // panda::proto \ No newline at end of file +} // panda::proto diff --git a/merge_abc/src/assemblyRecordProto.h b/merge_abc/src/assemblyRecordProto.h index 683719d933..4d197b7d88 100644 --- a/merge_abc/src/assemblyRecordProto.h +++ b/merge_abc/src/assemblyRecordProto.h @@ -27,7 +27,7 @@ class Record { public: static void Serialize(const panda::pandasm::Record &record, proto_panda::Record &protoRecord); static void Deserialize(const proto_panda::Record &protoRecord, panda::pandasm::Record &record, - std::unique_ptr &&allocator); + panda::ArenaAllocator *allocator); }; } // panda::proto -#endif \ No newline at end of file +#endif diff --git a/merge_abc/src/assemblyTypeProto.cpp b/merge_abc/src/assemblyTypeProto.cpp index 27a275c52e..6a47920006 100644 --- a/merge_abc/src/assemblyTypeProto.cpp +++ b/merge_abc/src/assemblyTypeProto.cpp @@ -25,9 +25,9 @@ void Type::Serialize(const panda::pandasm::Type type, proto_panda::Type &protoTy } panda::pandasm::Type &Type::Deserialize(const proto_panda::Type &protoType, - std::unique_ptr &&allocator) + panda::ArenaAllocator *allocator) { auto type = allocator->New(protoType.component_name(), protoType.rank()); return *type; } -} // panda::proto \ No newline at end of file +} // panda::proto diff --git a/merge_abc/src/assemblyTypeProto.h b/merge_abc/src/assemblyTypeProto.h index 866c295838..864abe4990 100644 --- a/merge_abc/src/assemblyTypeProto.h +++ b/merge_abc/src/assemblyTypeProto.h @@ -25,7 +25,7 @@ class Type { public: static void Serialize(const panda::pandasm::Type type, proto_panda::Type &protoType); static panda::pandasm::Type &Deserialize(const proto_panda::Type &protoType, - std::unique_ptr &&allocator); + panda::ArenaAllocator *allocator); }; } // panda::proto -#endif \ No newline at end of file +#endif diff --git a/merge_abc/src/ideHelpersProto.cpp b/merge_abc/src/ideHelpersProto.cpp index 894ee7fd75..db595e8a0f 100644 --- a/merge_abc/src/ideHelpersProto.cpp +++ b/merge_abc/src/ideHelpersProto.cpp @@ -49,4 +49,4 @@ void SourcePosition::Deserialize(const proto_panda::SourcePosition &protoPositio position.line = protoPosition.line(); position.column = protoPosition.column(); } -} // panda::proto \ No newline at end of file +} // panda::proto diff --git a/merge_abc/src/ideHelpersProto.h b/merge_abc/src/ideHelpersProto.h index 1f8608a5b6..43d52d5c63 100644 --- a/merge_abc/src/ideHelpersProto.h +++ b/merge_abc/src/ideHelpersProto.h @@ -34,4 +34,4 @@ public: static void Deserialize(const proto_panda::SourcePosition &protoPosition, panda::pandasm::SourcePosition &position); }; } // panda::proto -#endif \ No newline at end of file +#endif diff --git a/merge_abc/src/mergeProgramProto.cpp b/merge_abc/src/mergeProgram.cpp similarity index 93% rename from merge_abc/src/mergeProgramProto.cpp rename to merge_abc/src/mergeProgram.cpp index 0b48176309..6777c3d6d5 100644 --- a/merge_abc/src/mergeProgramProto.cpp +++ b/merge_abc/src/mergeProgram.cpp @@ -13,10 +13,10 @@ * limitations under the License. */ -#include "mergeProgramProto.h" +#include "mergeProgram.h" #include "protobufSnapshotGenerator.h" #include "arena_allocator.h" -#include "mergeOptions.h" +#include "Options.h" #include "assembler/assembly-function.h" #include "libpandafile/literal_data_accessor.h" #include @@ -53,7 +53,7 @@ public: }; int TraverseProtoBinPath(const std::string &protoBinPath, const std::string &protoBinSuffix, MergeProgram *mergeProgram, - std::unique_ptr &&allocator) + panda::ArenaAllocator *allocator) { panda::pandasm::Program program; @@ -71,7 +71,7 @@ int TraverseProtoBinPath(const std::string &protoBinPath, const std::string &pro continue; } if (TraverseProtoBinPath(path.assign(protoBinPath).append("\\").append(fileInfo.name), protoBinSuffix, - mergeProgram, std::move(allocator)) != 0) { + mergeProgram, allocator) != 0) { _findclose(handle); return 1; } @@ -79,7 +79,7 @@ int TraverseProtoBinPath(const std::string &protoBinPath, const std::string &pro std::string fileName(fileInfo.name); if (fileName.substr(fileName.find_last_of(".") + 1).compare(protoBinSuffix) == 0) { proto::ProtobufSnapshotGenerator::GenerateProgram( - path.assign(protoBinPath).append("\\").append(fileName), program, std::move(allocator)); + path.assign(protoBinPath).append("\\").append(fileName), program, allocator); mergeProgram->Merge(&program); } } @@ -98,7 +98,7 @@ int TraverseProtoBinPath(const std::string &protoBinPath, const std::string &pro } if (dir->d_type == DT_DIR) { std::string subDirName = pathPrefix + dir->d_name; - if (TraverseProtoBinPath(subDirName, protoBinSuffix, mergeProgram, std::move(allocator)) != 0) { + if (TraverseProtoBinPath(subDirName, protoBinSuffix, mergeProgram, allocator) != 0) { closedir(protoBin); return 1; } @@ -106,7 +106,7 @@ int TraverseProtoBinPath(const std::string &protoBinPath, const std::string &pro std::string fileName = pathPrefix + dir->d_name; std::string suffixStr = fileName.substr(fileName.find_last_of(".") + 1); if (suffixStr.compare(protoBinSuffix) == 0) { - proto::ProtobufSnapshotGenerator::GenerateProgram(fileName, program, std::move(allocator)); + proto::ProtobufSnapshotGenerator::GenerateProgram(fileName, program, allocator); mergeProgram->Merge(&program); } } @@ -212,12 +212,11 @@ int Run(int argc, const char **argv) std::string protoBinPath = options->protoBinPath(); std::string protoBinSuffix = options->protoBinSuffix(); - std::unique_ptr allocator = std::make_unique( - panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true); + panda::ArenaAllocator allocator(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true); panda::pandasm::Program program; MergeProgram mergeProgram(&program); - if (panda::proto::TraverseProtoBinPath(protoBinPath, protoBinSuffix, &mergeProgram, std::move(allocator))) { + if (panda::proto::TraverseProtoBinPath(protoBinPath, protoBinSuffix, &mergeProgram, &allocator)) { return 1; } diff --git a/merge_abc/src/mergeProgramProto.h b/merge_abc/src/mergeProgram.h similarity index 100% rename from merge_abc/src/mergeProgramProto.h rename to merge_abc/src/mergeProgram.h diff --git a/merge_abc/src/metaProto.cpp b/merge_abc/src/metaProto.cpp index b4b724d8b7..82e47bd3a7 100644 --- a/merge_abc/src/metaProto.cpp +++ b/merge_abc/src/metaProto.cpp @@ -23,13 +23,13 @@ void RecordMetadata::Serialize(const panda::pandasm::RecordMetadata &meta, proto void RecordMetadata::Deserialize(const proto_panda::RecordMetadata &protoMeta, std::unique_ptr &meta, - std::unique_ptr &&allocator) + panda::ArenaAllocator *allocator) { auto protoItemMetadata = protoMeta.father(); ItemMetadata::Deserialize(protoItemMetadata, *meta); auto protoAnnoMetadata = protoItemMetadata.father(); - AnnotationMetadata::Deserialize(protoAnnoMetadata, *meta, std::move(allocator)); + AnnotationMetadata::Deserialize(protoAnnoMetadata, *meta, allocator); auto protoMetadata = protoAnnoMetadata.father(); Metadata::Deserialize(protoMetadata, *meta); @@ -44,13 +44,13 @@ void FunctionMetadata::Serialize(const panda::pandasm::FunctionMetadata &meta, void FunctionMetadata::Deserialize(const proto_panda::FunctionMetadata &protoMeta, std::unique_ptr &meta, - std::unique_ptr &&allocator) + panda::ArenaAllocator *allocator) { auto protoItemMetadata = protoMeta.father(); ItemMetadata::Deserialize(protoItemMetadata, *meta); auto protoAnnoMetadata = protoItemMetadata.father(); - AnnotationMetadata::Deserialize(protoAnnoMetadata, *meta, std::move(allocator)); + AnnotationMetadata::Deserialize(protoAnnoMetadata, *meta, allocator); auto protoMetadata = protoAnnoMetadata.father(); Metadata::Deserialize(protoMetadata, *meta); @@ -71,20 +71,20 @@ void FieldMetadata::Serialize(const panda::pandasm::FieldMetadata &meta, proto_p void FieldMetadata::Deserialize(const proto_panda::FieldMetadata &protoMeta, std::unique_ptr &meta, - std::unique_ptr &&allocator) + panda::ArenaAllocator *allocator) { auto protoItemMetadata = protoMeta.father(); ItemMetadata::Deserialize(protoItemMetadata, *meta); auto protoAnnoMetadata = protoItemMetadata.father(); - AnnotationMetadata::Deserialize(protoAnnoMetadata, *meta, std::move(allocator)); + AnnotationMetadata::Deserialize(protoAnnoMetadata, *meta, allocator); auto protoMetadata = protoAnnoMetadata.father(); Metadata::Deserialize(protoMetadata, *meta); - auto fieldType = Type::Deserialize(protoMeta.field_type(), std::move(allocator)); + auto fieldType = Type::Deserialize(protoMeta.field_type(), allocator); meta->SetFieldType(fieldType); ScalarValue scalarValue; if (protoMeta.has_value()) { - auto scalar = scalarValue.Deserialize(protoMeta.value(), std::move(allocator)); + auto scalar = scalarValue.Deserialize(protoMeta.value(), allocator); meta->SetValue(scalar); } } @@ -97,10 +97,10 @@ void ParamMetadata::Serialize(const panda::pandasm::ParamMetadata &meta, proto_p void ParamMetadata::Deserialize(const proto_panda::ParamMetadata &protoMeta, std::unique_ptr &meta, - std::unique_ptr &&allocator) + panda::ArenaAllocator *allocator) { auto protoAnnoMetadata = protoMeta.father(); - AnnotationMetadata::Deserialize(protoAnnoMetadata, *meta, std::move(allocator)); + AnnotationMetadata::Deserialize(protoAnnoMetadata, *meta, allocator); } void ItemMetadata::Serialize(const panda::pandasm::ItemMetadata &meta, proto_panda::ItemMetadata &protoMeta) @@ -128,12 +128,12 @@ void AnnotationMetadata::Serialize(const panda::pandasm::AnnotationMetadata &met void AnnotationMetadata::Deserialize(const proto_panda::AnnotationMetadata &protoMeta, panda::pandasm::AnnotationMetadata &meta, - std::unique_ptr &&allocator) + panda::ArenaAllocator *allocator) { std::vector annotations; for (const auto &protoAnnotation : protoMeta.annotations()) { auto annotation = allocator->New(protoAnnotation.record_name()); - AnnotationData::Deserialize(protoAnnotation, *annotation, std::move(allocator)); + AnnotationData::Deserialize(protoAnnotation, *annotation, allocator); annotations.emplace_back(std::move(*annotation)); } meta.AddAnnotations(annotations); diff --git a/merge_abc/src/metaProto.h b/merge_abc/src/metaProto.h index 995644f0aa..1761fa07a1 100644 --- a/merge_abc/src/metaProto.h +++ b/merge_abc/src/metaProto.h @@ -28,7 +28,7 @@ public: static void Serialize(const panda::pandasm::RecordMetadata &meta, proto_panda::RecordMetadata &protoMeta); static void Deserialize(const proto_panda::RecordMetadata &protoMeta, std::unique_ptr &meta, - std::unique_ptr &&allocator); + panda::ArenaAllocator *allocator); }; class FunctionMetadata { @@ -37,7 +37,7 @@ public: proto_panda::FunctionMetadata &protoMeta); static void Deserialize(const proto_panda::FunctionMetadata &protoMeta, std::unique_ptr &meta, - std::unique_ptr &&allocator); + panda::ArenaAllocator *allocator); }; class FieldMetadata { @@ -45,7 +45,7 @@ public: static void Serialize(const panda::pandasm::FieldMetadata &meta, proto_panda::FieldMetadata &protoMeta); static void Deserialize(const proto_panda::FieldMetadata &protoMeta, std::unique_ptr &meta, - std::unique_ptr &&allocator); + panda::ArenaAllocator *allocator); }; class ParamMetadata { @@ -53,7 +53,7 @@ public: static void Serialize(const panda::pandasm::ParamMetadata &meta, proto_panda::ParamMetadata &protoMeta); static void Deserialize(const proto_panda::ParamMetadata &protoMeta, std::unique_ptr &meta, - std::unique_ptr &&allocator); + panda::ArenaAllocator *allocator); }; class ItemMetadata { @@ -67,7 +67,7 @@ public: static void Serialize(const panda::pandasm::AnnotationMetadata &meta, proto_panda::AnnotationMetadata &protoMeta); static void Deserialize(const proto_panda::AnnotationMetadata &protoMeta, panda::pandasm::AnnotationMetadata &meta, - std::unique_ptr &&allocator); + panda::ArenaAllocator *allocator); }; class Metadata { @@ -76,4 +76,4 @@ public: static void Deserialize(const proto_panda::Metadata &protoMeta, panda::pandasm::Metadata &meta); }; } // panda::proto -#endif \ No newline at end of file +#endif diff --git a/merge_abc/src/protobufSnapshotGenerator.cpp b/merge_abc/src/protobufSnapshotGenerator.cpp index c9cfd31f20..23fbffa592 100644 --- a/merge_abc/src/protobufSnapshotGenerator.cpp +++ b/merge_abc/src/protobufSnapshotGenerator.cpp @@ -34,7 +34,7 @@ void ProtobufSnapshotGenerator::GenerateSnapshot(const panda::pandasm::Program & } void ProtobufSnapshotGenerator::GenerateProgram(const std::string &inputName, panda::pandasm::Program &prog, - std::unique_ptr &&allocator) + panda::ArenaAllocator *allocator) { std::fstream input(inputName, std::ios::in | std::ios::binary); if (!input) { @@ -47,6 +47,6 @@ void ProtobufSnapshotGenerator::GenerateProgram(const std::string &inputName, pa return; } Program program; - program.Deserialize(proto_program, prog, std::move(allocator)); + program.Deserialize(proto_program, prog, allocator); } } // panda::proto diff --git a/merge_abc/src/protobufSnapshotGenerator.h b/merge_abc/src/protobufSnapshotGenerator.h index 9cd7ddccca..a92f9b5254 100644 --- a/merge_abc/src/protobufSnapshotGenerator.h +++ b/merge_abc/src/protobufSnapshotGenerator.h @@ -23,7 +23,7 @@ class ProtobufSnapshotGenerator { public: static void GenerateSnapshot(const panda::pandasm::Program &prog, const std::string &outputName); static void GenerateProgram(const std::string &inputName, panda::pandasm::Program &prog, - std::unique_ptr &&allocator); + panda::ArenaAllocator *allocator); }; } // panda::proto -#endif \ No newline at end of file +#endif -- Gitee From 23e26e4b06eb7e50b08c62da3b8b46dc619ad943 Mon Sep 17 00:00:00 2001 From: gavin1012_hw Date: Tue, 23 Aug 2022 23:40:44 +0800 Subject: [PATCH 11/23] Support passing proto bin file name && proto bin files' path && @input.txt with paths for merge binary Signed-off-by: gavin1012_hw Change-Id: Iaaebf7cb743464ac1ca860b5734a6956dc828f0e --- merge_abc/BUILD.gn | 1 + merge_abc/src/Options.cpp | 27 ++-- merge_abc/src/Options.h | 20 ++- merge_abc/src/mergeProgram.cpp | 225 ++++++++++++++++++++++----------- 4 files changed, 182 insertions(+), 91 deletions(-) diff --git a/merge_abc/BUILD.gn b/merge_abc/BUILD.gn index 71beb15aed..8a094d6a89 100644 --- a/merge_abc/BUILD.gn +++ b/merge_abc/BUILD.gn @@ -40,6 +40,7 @@ protobuf_snapshot_generator_sources = [ config("panda_assembly_proto_public_config") { include_dirs = [ "$ark_root/assembler", + "$ark_root/libpandabase", "$ark_root/libpandabase/mem", "$ark_root", "src", diff --git a/merge_abc/src/Options.cpp b/merge_abc/src/Options.cpp index 46cbc9e30c..9df5f41a2f 100644 --- a/merge_abc/src/Options.cpp +++ b/merge_abc/src/Options.cpp @@ -29,22 +29,26 @@ Options::~Options() bool Options::Parse(int argc, const char **argv) { panda::PandArg opHelp("help", false, "Print this message and exit"); - panda::PandArg protoBinPath("protoBinPath", "", "path of proto bin files"); - panda::PandArg protoBinSuffix("protoBinSuffix", "", "suffix of proto bin file"); - panda::PandArg outputPandaFile("outputPandaFile", "", "name of merged panda file"); + panda::PandArg protoPathInput("input", "", + "Path of Proto bin file or directory. If input path starts with '@', " + "it considered as a text file with list of files or directories."); + panda::PandArg protoBinSuffix("suffix", "", "suffix of proto bin file"); + panda::PandArg outputFileName("output", "", "name of merged panda file"); + panda::PandArg outputFilePath("outputFilePath", "", "output path for merged panda file"); argparser_->Add(&opHelp); - argparser_->Add(&protoBinPath); + argparser_->Add(&protoPathInput); argparser_->Add(&protoBinSuffix); - argparser_->Add(&outputPandaFile); + argparser_->Add(&outputFileName); + argparser_->Add(&outputFilePath); - if (!argparser_->Parse(argc, argv) || opHelp.GetValue() || protoBinPath.GetValue().empty()) { + if (!argparser_->Parse(argc, argv) || opHelp.GetValue() || protoPathInput.GetValue().empty()) { std::stringstream ss; ss << argparser_->GetErrorString() << std::endl; ss << "Usage: " << "merge_abc" - << " [OPTIONS]" << std::endl; + << " [OPTIONS] --input" << std::endl; ss << std::endl; ss << "optional arguments:" << std::endl; ss << argparser_->GetHelpString() << std::endl; @@ -53,12 +57,15 @@ bool Options::Parse(int argc, const char **argv) { return false; } - protoBinPath_ = protoBinPath.GetValue(); + protoPathInput_ = protoPathInput.GetValue(); if (!protoBinSuffix.GetValue().empty()) { protoBinSuffix_ = protoBinSuffix.GetValue(); } - if (!outputPandaFile.GetValue().empty()) { - outputPandaFile_ = outputPandaFile.GetValue(); + if (!outputFileName.GetValue().empty()) { + outputFileName_ = outputFileName.GetValue(); + } + if (!outputFilePath.GetValue().empty()) { + outputFilePath_ = outputFilePath.GetValue(); } return true; diff --git a/merge_abc/src/Options.h b/merge_abc/src/Options.h index ddff2d0935..20b7db6fc8 100644 --- a/merge_abc/src/Options.h +++ b/merge_abc/src/Options.h @@ -30,9 +30,9 @@ public: bool Parse(int argc, const char **argv); - const std::string &protoBinPath() const + const std::string &protoPathInput() const { - return protoBinPath_; + return protoPathInput_; } const std::string &protoBinSuffix() const @@ -40,9 +40,14 @@ public: return protoBinSuffix_; } - const std::string &outputPandaFile() const + const std::string &outputFileName() const { - return outputPandaFile_; + return outputFileName_; + } + + const std::string &outputFilePath() const + { + return outputFilePath_; } const std::string &ErrorMsg() const @@ -53,9 +58,10 @@ public: private: panda::PandArgParser *argparser_; std::string errorMsg_; - std::string protoBinSuffix_ {"protoBin"}; - std::string protoBinPath_; - std::string outputPandaFile_ {"modules.abc"}; + std::string protoBinSuffix_ {"bin"}; + std::string protoPathInput_; + std::string outputFileName_ {"modules.abc"}; + std::string outputFilePath_; }; } #endif diff --git a/merge_abc/src/mergeProgram.cpp b/merge_abc/src/mergeProgram.cpp index 6777c3d6d5..d5c46af111 100644 --- a/merge_abc/src/mergeProgram.cpp +++ b/merge_abc/src/mergeProgram.cpp @@ -20,6 +20,8 @@ #include "assembler/assembly-function.h" #include "libpandafile/literal_data_accessor.h" #include +#include +#include "os/file.h" #if defined(PANDA_TARGET_WINDOWS) #include @@ -52,70 +54,6 @@ public: } }; -int TraverseProtoBinPath(const std::string &protoBinPath, const std::string &protoBinSuffix, MergeProgram *mergeProgram, - panda::ArenaAllocator *allocator) -{ - panda::pandasm::Program program; - -#if PANDA_TARGET_WINDOWS - int handle = 0; - struct _finddata_t fileInfo; - std::string path; - if ((handle = _findfirst(path.assign(protoBinPath).append("\\*").c_str(), &fileInfo)) == -1) { - return 1; - } - do - { - if (fileInfo.attrib & _A_SUBDIR) { - if((!strncmp(fileInfo.name, ".", 1)) || (!strncmp(fileInfo.name, "..", 2))) { - continue; - } - if (TraverseProtoBinPath(path.assign(protoBinPath).append("\\").append(fileInfo.name), protoBinSuffix, - mergeProgram, allocator) != 0) { - _findclose(handle); - return 1; - } - } else { - std::string fileName(fileInfo.name); - if (fileName.substr(fileName.find_last_of(".") + 1).compare(protoBinSuffix) == 0) { - proto::ProtobufSnapshotGenerator::GenerateProgram( - path.assign(protoBinPath).append("\\").append(fileName), program, allocator); - mergeProgram->Merge(&program); - } - } - } while (_findnext(handle, &fileInfo) == 0); - _findclose(handle); -#else - DIR *protoBin = opendir(protoBinPath.c_str()); - if (protoBin == nullptr) { - return 1; - } - dirent *dir = nullptr; - std::string pathPrefix = protoBinPath + "/"; - while ((dir = readdir(protoBin)) != nullptr) { - if((!strncmp(dir->d_name, ".", 1)) || (!strncmp(dir->d_name, "..", 2))) { - continue; - } - if (dir->d_type == DT_DIR) { - std::string subDirName = pathPrefix + dir->d_name; - if (TraverseProtoBinPath(subDirName, protoBinSuffix, mergeProgram, allocator) != 0) { - closedir(protoBin); - return 1; - } - } else { - std::string fileName = pathPrefix + dir->d_name; - std::string suffixStr = fileName.substr(fileName.find_last_of(".") + 1); - if (suffixStr.compare(protoBinSuffix) == 0) { - proto::ProtobufSnapshotGenerator::GenerateProgram(fileName, program, allocator); - mergeProgram->Merge(&program); - } - } - } - closedir(protoBin); -#endif - return 0; -} - void MergeProgram::Merge(panda::pandasm::Program *src) { CorrectLiteraArrayId(src); @@ -201,6 +139,136 @@ void MergeProgram::IncreaseInsLiteralArrayIdByBase(panda::pandasm::Ins &insn, si } } +bool GetProtoFiles(std::string &protoBinPath, std::string &protoBinSuffix, std::vector &directoryFiles) +{ +#if PANDA_TARGET_WINDOWS + int handle = 0; + struct _finddata_t fileInfo; + std::string path; + if ((handle = _findfirst(path.assign(protoBinPath).append("\\*").c_str(), &fileInfo)) == -1) { + return false; + } + do + { + if (fileInfo.attrib & _A_SUBDIR) { + if((!strncmp(fileInfo.name, ".", 1)) || (!strncmp(fileInfo.name, "..", 2))) { + continue; + } + if (!GetProtoFiles(path.assign(protoBinPath).append("\\").append(fileInfo.name), protoBinSuffix, + directoryFiles)) { + _findclose(handle); + return false; + } + } else { + std::string fileName(fileInfo.name); + if (fileName.substr(fileName.find_last_of(".") + 1).compare(protoBinSuffix) == 0) { + directoryFiles.emplace_back(path.assign(protoBinPath).append("\\").append(fileName)); + } + } + } while (_findnext(handle, &fileInfo) == 0); + _findclose(handle); +#elif PANDA_TARGET_UNIX + DIR *protoBin = opendir(protoBinPath.c_str()); + if (protoBin == nullptr) { + return false; + } + dirent *dir = nullptr; + std::string pathPrefix = protoBinPath + "/"; + while ((dir = readdir(protoBin)) != nullptr) { + if((!strncmp(dir->d_name, ".", 1)) || (!strncmp(dir->d_name, "..", 2))) { + continue; + } + if (dir->d_type == DT_DIR) { + std::string subDirName = pathPrefix + dir->d_name; + if (!GetProtoFiles(subDirName, protoBinSuffix, directoryFiles)) { + closedir(protoBin); + return false; + } + } else { + std::string fileName = pathPrefix + dir->d_name; + if (fileName.substr(fileName.find_last_of(".") + 1).compare(protoBinSuffix) == 0) { + directoryFiles.emplace_back(fileName); + } + } + } + closedir(protoBin); +#endif + return true; +} + +bool AppendProtoFiles(std::string filePath, std::string protoBinSuffix, std::vector &protoFiles) +{ + auto inputAbs = panda::os::file::File::GetAbsolutePath(filePath); + if (!inputAbs) { + std::cerr << "Failed to open: " << inputAbs.Value() << std::endl; + return false; + } + + auto fPath = inputAbs.Value(); + if (panda::os::file::File::IsRegularFile(fPath)) { + if (filePath.substr(filePath.find_last_of(".") + 1).compare(protoBinSuffix) == 0) { + protoFiles.emplace_back(fPath); + } + } else if (panda::os::file::File::IsDirectory(fPath)) { + std::vector directoryFiles; + if (!GetProtoFiles(fPath, protoBinSuffix, directoryFiles)) { + return false; + } + protoFiles.insert(protoFiles.end(), directoryFiles.begin(), directoryFiles.end()); + } else { + std::cerr << "Input must be either a regular file or directory" << std::endl; + return false; + } + + return true; +} + +bool CollectProtoFiles(std::string input, std::string protoBinSuffix, std::vector &protoFiles) +{ + constexpr const char DOGGY = '@'; + std::vector inputs; + bool isList = false; + + if (input[0] == DOGGY) { + input.erase(input.begin() + 0); + isList = true; + } + + auto inputAbs = panda::os::file::File::GetAbsolutePath(input); + if (!inputAbs) { + std::cerr << "Failed to open: " << inputAbs.Value() << std::endl; + return false; + } + if (isList) { + std::ifstream in(inputAbs.Value()); + std::string line; + constexpr const char CARRIAGE = '\r'; + while (getline(in, line)) + { + // erase front spaces + line.erase(line.begin(), + std::find_if(line.begin(), line.end(), [](unsigned char ch) { return std::isspace(ch) == 0; })); + // erase carrige return symbol (Windows workaround) + line.erase(std::find_if(line.rbegin(), line.rend(), [](unsigned char ch) { return ch != CARRIAGE; }).base(), + line.end()); + if (!line.empty()) { + inputs.push_back(line); + } + } + in.close(); + } else { + inputs.push_back(inputAbs.Value()); + } + + for (auto &filePath : inputs) { + if (!AppendProtoFiles(filePath, protoBinSuffix, protoFiles)) { + return false; + } + } + + return true; +} + int Run(int argc, const char **argv) { auto options = std::make_unique(); @@ -209,15 +277,29 @@ int Run(int argc, const char **argv) return 1; } - std::string protoBinPath = options->protoBinPath(); + std::string protoPathInput = options->protoPathInput(); std::string protoBinSuffix = options->protoBinSuffix(); + std::string outputFilePath = options->outputFilePath(); + + if (outputFilePath.empty()) { + outputFilePath = panda::os::file::File::GetExecutablePath().Value().append( + panda::os::file::File::GetPathDelim()); + } panda::ArenaAllocator allocator(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true); + std::vector protoFiles; + if (!CollectProtoFiles(protoPathInput, protoBinSuffix, protoFiles)) { + return 1; + } + panda::pandasm::Program program; MergeProgram mergeProgram(&program); - if (panda::proto::TraverseProtoBinPath(protoBinPath, protoBinSuffix, &mergeProgram, &allocator)) { - return 1; + + for (auto &protoFile : protoFiles) { + panda::pandasm::Program program; + proto::ProtobufSnapshotGenerator::GenerateProgram(protoFile, program, &allocator); + mergeProgram.Merge(&program); } std::map stat; @@ -225,13 +307,8 @@ int Run(int argc, const char **argv) panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps maps {}; panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps *mapsp = nullptr; - std::string outputPandaFile = options->outputPandaFile(); -#ifdef PANDA_TARGET_WINDOWS - outputPandaFile = protoBinPath + "\\" + outputPandaFile; -#else - outputPandaFile = protoBinPath + "/" + outputPandaFile; -#endif - if (!panda::pandasm::AsmEmitter::Emit(outputPandaFile, *(mergeProgram.GetResult()), statp, mapsp, true)) { + std::string outputFileName = outputFilePath.append(options->outputFileName()); + if (!panda::pandasm::AsmEmitter::Emit(outputFileName, *(mergeProgram.GetResult()), statp, mapsp, true)) { return 1; } -- Gitee From e06485d7dd35201a151ae5dc8567fa3cb048e786 Mon Sep 17 00:00:00 2001 From: hufeng Date: Wed, 24 Aug 2022 17:18:39 +0800 Subject: [PATCH 12/23] Adapt UT to merged abc Signed-off-by: hufeng Change-Id: Ic68d1f7fd1fe89e57577d403508390956c56bb31 --- ts2panda/tests/builtIns.test.ts | 2 +- ts2panda/tests/commonjs.test.ts | 6 +-- ts2panda/tests/esmodule.test.ts | 2 +- ts2panda/tests/expression/arguments.test.ts | 4 +- ts2panda/tests/expression/commalist.test.ts | 2 +- .../expression/functionExpression.test.ts | 38 +++++++++---------- ts2panda/tests/expression/thisKeyWord.test.ts | 2 +- ts2panda/tests/hoist.test.ts | 19 +++++----- ts2panda/tests/lexenv.test.ts | 31 ++++++++------- .../statements/functionDeclaration.test.ts | 20 +++++----- .../statements/variableDeclaration.test.ts | 8 ++-- ts2panda/tests/types/array.test.ts | 12 +++--- ts2panda/tests/types/class.test.ts | 16 ++++---- ts2panda/tests/types/function.test.ts | 10 ++--- ts2panda/tests/types/object.test.ts | 4 +- ts2panda/tests/types/primitives.test.ts | 14 +++---- ts2panda/tests/types/union.test.ts | 8 ++-- ts2panda/tests/utils/base.ts | 10 ++--- 18 files changed, 103 insertions(+), 105 deletions(-) diff --git a/ts2panda/tests/builtIns.test.ts b/ts2panda/tests/builtIns.test.ts index ace7fc1c21..590a3131b2 100644 --- a/ts2panda/tests/builtIns.test.ts +++ b/ts2panda/tests/builtIns.test.ts @@ -45,7 +45,7 @@ describe("FunctionToStringTest", function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compileAfter(`function foo() {return 123;}\nfunction bar() {return 321;}\n`, 'toStringTest.js'); CmdOptions.needRecordSourceCode = () => {return false}; - let pandaGen = snippetCompiler.getPandaGenByName('foo'); + let pandaGen = snippetCompiler.getPandaGenByName('UnitTest.foo'); let expected = "function foo() {return 123;}"; expect(pandaGen.getSourceCode() == expected).to.be.true; }) diff --git a/ts2panda/tests/commonjs.test.ts b/ts2panda/tests/commonjs.test.ts index f0148848a4..119cce756f 100644 --- a/ts2panda/tests/commonjs.test.ts +++ b/ts2panda/tests/commonjs.test.ts @@ -44,7 +44,7 @@ describe("CommonJsTest", function () { CmdOptions.isCommonJs = () => {return false}; let funcMainInsns = snippetCompiler.getGlobalInsns(); let expected = [ - new EcmaDefinefuncdyn('#1#', new Imm(5), new VReg()), + new EcmaDefinefuncdyn('UnitTest.#1#', new Imm(5), new VReg()), new StaDyn(new VReg()), new LdaDyn(new VReg()), new StaDyn(new VReg()), @@ -67,7 +67,7 @@ describe("CommonJsTest", function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compileCommonjs(`let a = require('a.js')`, 'cjs.js'); CmdOptions.isCommonJs = () => {return false}; - let execInsns = snippetCompiler.getPandaGenByName('#1#')!.getInsns(); + let execInsns = snippetCompiler.getPandaGenByName('UnitTest.#1#')!.getInsns(); let requirePara = new VReg(); let requireReg = new VReg(); let moduleRequest = new VReg(); @@ -88,7 +88,7 @@ describe("CommonJsTest", function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compileCommonjs(`let a = 1; exports.a = a;`, 'cjs.js'); CmdOptions.isCommonJs = () => {return false}; - let execInsns = snippetCompiler.getPandaGenByName('#1#')!.getInsns(); + let execInsns = snippetCompiler.getPandaGenByName('UnitTest.#1#')!.getInsns(); let exportsPara = new VReg(); let exportsReg = new VReg(); let tmpReg = new VReg(); diff --git a/ts2panda/tests/esmodule.test.ts b/ts2panda/tests/esmodule.test.ts index e28b9b6db4..f88272059a 100644 --- a/ts2panda/tests/esmodule.test.ts +++ b/ts2panda/tests/esmodule.test.ts @@ -45,7 +45,7 @@ describe("ExportDeclaration", function () { let classReg = new VReg(); let expected = [ new MovDyn(new VReg(), new VReg()), - new EcmaDefineclasswithbuffer("#1#C", new Imm(0), new Imm(0), new VReg(), new VReg()), + new EcmaDefineclasswithbuffer("UnitTest.#1#C", new Imm(0), new Imm(0), new VReg(), new VReg()), new StaDyn(classReg), new LdaDyn(classReg), new EcmaStmodulevar('C'), diff --git a/ts2panda/tests/expression/arguments.test.ts b/ts2panda/tests/expression/arguments.test.ts index 3dd2fbd706..350836037e 100644 --- a/ts2panda/tests/expression/arguments.test.ts +++ b/ts2panda/tests/expression/arguments.test.ts @@ -43,7 +43,7 @@ describe("arguments Keyword", function () { new EcmaLdobjbyindex(temp1, new Imm(0)), new EcmaReturnundefined() ]; - let functionPg = snippetCompiler.getPandaGenByName("foo"); + let functionPg = snippetCompiler.getPandaGenByName("UnitTest.foo"); let insns = functionPg!.getInsns(); expect(checkInstructions(insns, expected)).to.be.true; @@ -62,7 +62,7 @@ describe("arguments Keyword", function () { new EcmaLdobjbyindex(temp1, new Imm(0)), new EcmaReturnundefined() ]; - let functionPg = snippetCompiler.getPandaGenByName("foo"); + let functionPg = snippetCompiler.getPandaGenByName("UnitTest.foo"); let insns = functionPg!.getInsns(); expect(checkInstructions(insns, expected)).to.be.true; diff --git a/ts2panda/tests/expression/commalist.test.ts b/ts2panda/tests/expression/commalist.test.ts index 5163fded64..0681472412 100644 --- a/ts2panda/tests/expression/commalist.test.ts +++ b/ts2panda/tests/expression/commalist.test.ts @@ -54,7 +54,7 @@ describe("CommaListExpression", function () { let insns = snippetCompiler.getGlobalInsns(); let expected = [ new MovDyn(new VReg(), new VReg()), - new EcmaDefineclasswithbuffer("#1#Test", new Imm(0), new Imm(0), new VReg(), new VReg()), + new EcmaDefineclasswithbuffer("UnitTest.#1#Test", new Imm(0), new Imm(0), new VReg(), new VReg()), new StaDyn(new VReg()), new LdaDyn(new VReg()), new EcmaStclasstoglobalrecord("Test"), diff --git a/ts2panda/tests/expression/functionExpression.test.ts b/ts2panda/tests/expression/functionExpression.test.ts index e04bb8ea3e..f1b0624fd1 100644 --- a/ts2panda/tests/expression/functionExpression.test.ts +++ b/ts2panda/tests/expression/functionExpression.test.ts @@ -72,7 +72,7 @@ describe("compileFunctionExpression", function () { let checkCount = 0; pandaGens.forEach((pg) => { - if (pg.internalName == "test") { + if (pg.internalName == "UnitTest.test") { expect(checkInstructions(pg.getInsns(), expected_func), "check func insns").to.be.true; checkCount++; } @@ -90,15 +90,15 @@ describe("compileFunctionExpression", function () { let checkCount = 0; pandaGens.forEach((pg) => { - if (pg.internalName == "a") { + if (pg.internalName == "UnitTest.a") { checkCount++; } - if (pg.internalName == "func_main_0") { + if (pg.internalName == "UnitTest.func_main_0") { pg.getInsns().forEach((insns) => { if (insns instanceof EcmaDefinefuncdyn) { - expect(insns.operands[0]).to.equal('a'); + expect(insns.operands[0]).to.equal('UnitTest.a'); checkCount++; } }); @@ -118,15 +118,15 @@ describe("compileFunctionExpression", function () { let checkCount = 0; pandaGens.forEach((pg) => { - if (pg.internalName == "a") { + if (pg.internalName == "UnitTest.a") { checkCount++; } - if (pg.internalName == "func_main_0") { + if (pg.internalName == "UnitTest.func_main_0") { pg.getInsns().forEach((insns) => { if (insns instanceof EcmaDefinefuncdyn) { - expect(insns.operands[0]).to.equal('a'); + expect(insns.operands[0]).to.equal('UnitTest.a'); checkCount++; } }); @@ -146,15 +146,15 @@ describe("compileFunctionExpression", function () { let checkCount = 0; pandaGens.forEach((pg) => { - if (pg.internalName == "a") { + if (pg.internalName == "UnitTest.a") { checkCount++; } - if (pg.internalName == "func_main_0") { + if (pg.internalName == "UnitTest.func_main_0") { pg.getInsns().forEach((insns) => { if (insns instanceof EcmaDefinencfuncdyn) { - expect(insns.operands[0]).to.equal('a'); + expect(insns.operands[0]).to.equal('UnitTest.a'); checkCount++; } }); @@ -182,16 +182,16 @@ describe("compileFunctionExpression", function () { ]; pandaGens.forEach((pg) => { - if (pg.internalName == "p") { + if (pg.internalName == "UnitTest.p") { expect(checkInstructions(pg.getInsns(), expected_func), "check arrow func insns").to.be.true; checkCount++; } - if (pg.internalName == "func_main_0") { + if (pg.internalName == "UnitTest.func_main_0") { pg.getInsns().forEach((insns) => { if (insns instanceof EcmaDefinencfuncdyn) { - expect(insns.operands[0]).to.equal('p'); + expect(insns.operands[0]).to.equal('UnitTest.p'); checkCount++; } }); @@ -283,15 +283,15 @@ describe("compileFunctionExpression", function () { let checkCount = 0; pandaGens.forEach((pg) => { - if (pg.internalName == "a") { + if (pg.internalName == "UnitTest.a") { expect(checkInstructions(pg.getInsns(), expected_func), "check generator func insns").to.be.true; checkCount++; } - if (pg.internalName == "func_main_0") { + if (pg.internalName == "UnitTest.func_main_0") { pg.getInsns().forEach((insns) => { if (insns instanceof EcmaDefinegeneratorfunc) { - expect(insns.operands[0]).to.equal('a'); + expect(insns.operands[0]).to.equal('UnitTest.a'); checkCount++; } }); @@ -343,15 +343,15 @@ describe("compileFunctionExpression", function () { let checkCount = 0; pandaGens.forEach((pg) => { - if (pg.internalName == "a") { + if (pg.internalName == "UnitTest.a") { expect(checkInstructions(pg.getInsns(), expected_func), "check async func insns").to.be.true; checkCount++; } - if (pg.internalName == "func_main_0") { + if (pg.internalName == "UnitTest.func_main_0") { pg.getInsns().forEach((insns) => { if (insns instanceof EcmaDefinencfuncdyn) { - expect(insns.operands[0]).to.equal('a'); + expect(insns.operands[0]).to.equal('UnitTest.a'); checkCount++; } }); diff --git a/ts2panda/tests/expression/thisKeyWord.test.ts b/ts2panda/tests/expression/thisKeyWord.test.ts index 186c2d2b94..b55be1d511 100644 --- a/ts2panda/tests/expression/thisKeyWord.test.ts +++ b/ts2panda/tests/expression/thisKeyWord.test.ts @@ -50,7 +50,7 @@ describe("ThisKeyword", function () { it("this in function scope", function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compile("function a() {this}"); - let functionPg = snippetCompiler.getPandaGenByName("a"); + let functionPg = snippetCompiler.getPandaGenByName("UnitTest.a"); let functionScope = functionPg!.getScope(); let insns = compileMainSnippet("this;", pandaGen, functionScope); let expected = [ diff --git a/ts2panda/tests/hoist.test.ts b/ts2panda/tests/hoist.test.ts index ffd5a7fe4d..e048a0eca7 100644 --- a/ts2panda/tests/hoist.test.ts +++ b/ts2panda/tests/hoist.test.ts @@ -29,7 +29,6 @@ import { LdaDyn, LdaiDyn, LdaStr, - ResultType, StaDyn, VReg } from "../src/irnodes"; @@ -79,7 +78,7 @@ describe("HoistTest", function () { let insns = snippetCompiler.getGlobalInsns(); let expected = [ - new EcmaDefinefuncdyn("a", new Imm(0), new VReg()), + new EcmaDefinefuncdyn("UnitTest.a", new Imm(0), new VReg()), new EcmaStglobalvar("a"), new EcmaReturnundefined() ] @@ -93,7 +92,7 @@ describe("HoistTest", function () { let insns = snippetCompiler.getGlobalInsns(); let expected = [ - new EcmaDefinefuncdyn("#2#a", new Imm(0), new VReg()), + new EcmaDefinefuncdyn("UnitTest.#2#a", new Imm(0), new VReg()), new EcmaStglobalvar("a"), new EcmaReturnundefined() ] @@ -107,7 +106,7 @@ describe("HoistTest", function () { snippetCompiler.compile(`var a = 1; function a() {}`); let insns = snippetCompiler.getGlobalInsns(); let expected = [ - new EcmaDefinefuncdyn("a", new Imm(0), new VReg()), + new EcmaDefinefuncdyn("UnitTest.a", new Imm(0), new VReg()), new EcmaStglobalvar("a"), new LdaiDyn(new Imm(1)), new EcmaStglobalvar("a"), @@ -121,7 +120,7 @@ describe("HoistTest", function () { it('case 6', function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compile(`function a() {var a = 1;}`); - let funcPg = snippetCompiler.getPandaGenByName("a"); + let funcPg = snippetCompiler.getPandaGenByName("UnitTest.a"); let insns = funcPg!.getInsns(); let a = new VReg(); @@ -140,11 +139,11 @@ describe("HoistTest", function () { it('case 7', function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compile(`function a() {function b() {}};`); - let funcPg = snippetCompiler.getPandaGenByName("a"); + let funcPg = snippetCompiler.getPandaGenByName("UnitTest.a"); let insns = funcPg!.getInsns(); let a = new VReg(); let expected = [ - new EcmaDefinefuncdyn("b", new Imm(0), new VReg()), + new EcmaDefinefuncdyn("UnitTest.b", new Imm(0), new VReg()), new StaDyn(a), new EcmaReturnundefined() @@ -158,7 +157,7 @@ describe("HoistTest", function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compile(`a = 1; let a;`); - let funcPg = snippetCompiler.getPandaGenByName("func_main_0"); + let funcPg = snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let insns = funcPg!.getInsns(); let idReg = new VReg(); let expected = [ @@ -177,7 +176,7 @@ describe("HoistTest", function () { a = 1; let a; }`); - let funcPg = snippetCompiler.getPandaGenByName("b"); + let funcPg = snippetCompiler.getPandaGenByName("UnitTest.b"); let insns = funcPg!.getInsns(); let idReg = new VReg(); @@ -197,7 +196,7 @@ describe("HoistTest", function () { a = 1; let a; }`); - let funcPg = snippetCompiler.getPandaGenByName("func_main_0"); + let funcPg = snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let insns = funcPg!.getInsns(); let idReg = new VReg(); diff --git a/ts2panda/tests/lexenv.test.ts b/ts2panda/tests/lexenv.test.ts index a2180a6a15..ec6c337aae 100644 --- a/ts2panda/tests/lexenv.test.ts +++ b/ts2panda/tests/lexenv.test.ts @@ -39,7 +39,6 @@ import { LdaDyn, LdaiDyn, LdaStr, - ResultType, ReturnDyn, StaDyn, VReg @@ -116,7 +115,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { it("test CompilerDriver.scanFunctions-with-empty", function () { let source: string = ``; let sourceFile = creatAstFromSnippet(source); - let compilerDriver = new CompilerDriver('UnitTest'); + let compilerDriver = new CompilerDriver('UnitTest', 'UnitTest'); let globalScope = new GlobalScope(sourceFile); let recorder = new Recorder(sourceFile, globalScope, compilerDriver, false, false, true); recorder.record(); @@ -144,7 +143,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { var funcExpression = function() { } `; let sourceFile = creatAstFromSnippet(source); - let compilerDriver = new CompilerDriver('UnitTest'); + let compilerDriver = new CompilerDriver('UnitTest', 'UnitTest'); let globalScope = new GlobalScope(sourceFile); let recorder = new Recorder(sourceFile, globalScope, compilerDriver, false, false, true); recorder.record(); @@ -191,7 +190,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { let source: string = ` `; let sourceFile = creatAstFromSnippet(source); - let compilerDriver = new CompilerDriver('UnitTest'); + let compilerDriver = new CompilerDriver('UnitTest', 'UnitTest'); let globalScope = new GlobalScope(sourceFile); let recorder = new Recorder(sourceFile, globalScope, compilerDriver, false, false, true); @@ -215,7 +214,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { var funcExt = function() { } `; let sourceFile = creatAstFromSnippet(source); - let compilerDriver = new CompilerDriver('UnitTest'); + let compilerDriver = new CompilerDriver('UnitTest', 'UnitTest'); let globalScope = new GlobalScope(sourceFile); let recorder = new Recorder(sourceFile, globalScope, compilerDriver, false, false, true); @@ -269,7 +268,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { }))) `; let sourceFile = creatAstFromSnippet(source); - let compilerDriver = new CompilerDriver('UnitTest'); + let compilerDriver = new CompilerDriver('UnitTest', 'UnitTest'); let globalScope = new GlobalScope(sourceFile); let recorder = new Recorder(sourceFile, globalScope, compilerDriver, false, false, true); @@ -412,7 +411,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { let expected_main = [ new LdaDyn(new VReg()), new EcmaStglobalvar("outer"), - new EcmaDefinefuncdyn("func", new Imm(0), new VReg()), + new EcmaDefinefuncdyn("UnitTest.func", new Imm(0), new VReg()), new EcmaStglobalvar("func"), new LdaiDyn(new Imm(1)), new EcmaStglobalvar("outer"), @@ -425,9 +424,9 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { ]; pandaGens.forEach((pg) => { - if (pg.internalName == "func_main_0") { + if (pg.internalName == "UnitTest.func_main_0") { expect(checkInstructions(pg.getInsns(), expected_main)).to.be.true; - } else if (pg.internalName == "func") { + } else if (pg.internalName == "UnitTest.func") { expect(checkInstructions(pg.getInsns(), expected_func)).to.be.true; } }) @@ -447,7 +446,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { let pandaGens = compileAllSnippet(source, passes); let expected_main = [ ...insnsCreateLexEnv_main, - new EcmaDefinefuncdyn("func", new Imm(0), new VReg()), + new EcmaDefinefuncdyn("UnitTest.func", new Imm(0), new VReg()), new EcmaStglobalvar("func"), // global.func = func_func_1 new LdaiDyn(new Imm(1)), // value = 1 // ...insnsStoreLexVar_main, @@ -465,11 +464,11 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { pandaGens.forEach((pg) => { let scope = pg.getScope(); - if (pg.internalName == "func_main_0") { + if (pg.internalName == "UnitTest.func_main_0") { expect(checkInstructions(pg.getInsns(), expected_main), "check main insns").to.be.true; expect(scope.getNumLexEnv(), "main scope has 0 lexvar").to.be.equal(0); // expect(scope.hasLexEnv(), "main scope has lexenv").to.be.true; - } else if (pg.internalName == "func") { + } else if (pg.internalName == "UnitTest.func") { expect(checkInstructions(pg.getInsns(), expected_func), "check func insns").to.be.true; expect(scope.getNumLexEnv(), "func scope has 1 lexvar").to.be.equal(0); @@ -505,7 +504,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { new LdaDyn(new VReg()), new StaDyn(new VReg()), ...insnsStoreLexVar_outer_2, - new EcmaDefinefuncdyn("#1#", new Imm(0), new VReg()), + new EcmaDefinefuncdyn("UnitTest.#1#", new Imm(0), new VReg()), // returnStatement new StaDyn(new VReg()), new LdaDyn(new VReg()), @@ -536,13 +535,13 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { snippetCompiler.compile(source, passes); // check compile result! - let outerPg = snippetCompiler.getPandaGenByName("outer"); + let outerPg = snippetCompiler.getPandaGenByName("UnitTest.outer"); let outerScope = outerPg!.getScope(); let outerA = outerScope!.findLocal("a"); expect(outerA instanceof LocalVariable, "a in outer is local variable").to.be.true; // expect((outerScope).hasLexEnv(), "outer scope need to create lex env").to.be.true; expect((outerScope).getNumLexEnv(), "number of lexvar at outer scope").to.be.equal(2); - let anonymousPg = snippetCompiler.getPandaGenByName("#1#"); + let anonymousPg = snippetCompiler.getPandaGenByName("UnitTest.#1#"); let anonymousScope = anonymousPg!.getScope(); let anonymousA = anonymousScope!.findLocal("a"); let searchRlt = anonymousScope!.find("a"); @@ -551,7 +550,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { expect(anonymousA, "no a in anonymous function").to.be.undefined; // expect((anonymousScope).hasLexEnv(), "anonymous scope had lex env").to.be.true; expect((anonymousScope).getNumLexEnv()).to.be.equal(0); - let globalPg = snippetCompiler.getPandaGenByName("func_main_0"); + let globalPg = snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let globalScope = globalPg!.getScope(); let globalA = globalScope!.findLocal("a"); expect(globalA instanceof GlobalVariable, "globalA is GlobalVariable").to.be.true; diff --git a/ts2panda/tests/statements/functionDeclaration.test.ts b/ts2panda/tests/statements/functionDeclaration.test.ts index 3c9b990385..079b05e8e4 100644 --- a/ts2panda/tests/statements/functionDeclaration.test.ts +++ b/ts2panda/tests/statements/functionDeclaration.test.ts @@ -29,7 +29,6 @@ import { Label, LdaDyn, LdaiDyn, - ResultType, StaDyn, VReg } from "../../src/irnodes"; @@ -43,9 +42,10 @@ describe("FunctionDeclarationTest", function () { it('function definition in the global scope', function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compile("function foo() {}"); + let funcInternalName = "UnitTest.foo"; let funcName = "foo"; let expected = [ - new EcmaDefinefuncdyn(funcName, new Imm(0), new VReg()), + new EcmaDefinefuncdyn(funcInternalName, new Imm(0), new VReg()), new EcmaStglobalvar(funcName), new EcmaReturnundefined() ]; @@ -64,7 +64,7 @@ describe("FunctionDeclarationTest", function () { function foo() {} `); let expected = [ - new EcmaDefinefuncdyn("#2#foo", new Imm(0), new VReg()), + new EcmaDefinefuncdyn("UnitTest.#2#foo", new Imm(0), new VReg()), new EcmaStglobalvar("foo"), new EcmaReturnundefined() ]; @@ -81,12 +81,12 @@ describe("FunctionDeclarationTest", function () { snippetCompiler.compile(`function out() {function foo() {}}`); let funcReg = new VReg(); let expected = [ - new EcmaDefinefuncdyn("foo", new Imm(0), new VReg()), + new EcmaDefinefuncdyn("UnitTest.foo", new Imm(0), new VReg()), new StaDyn(funcReg), new EcmaReturnundefined() ]; - let functionPg = snippetCompiler.getPandaGenByName("out"); + let functionPg = snippetCompiler.getPandaGenByName("UnitTest.out"); let insns = functionPg!.getInsns(); let functionScope = functionPg!.getScope(); @@ -103,7 +103,7 @@ describe("FunctionDeclarationTest", function () { snippetCompiler.compile("let foo = function() {}"); let insns = snippetCompiler.getGlobalInsns(); let expected = [ - new EcmaDefinefuncdyn("foo", new Imm(0), new VReg()), + new EcmaDefinefuncdyn("UnitTest.foo", new Imm(0), new VReg()), new EcmaStlettoglobalrecord("foo"), new EcmaReturnundefined() ]; @@ -117,7 +117,7 @@ describe("FunctionDeclarationTest", function () { let endLabel = new Label(); let expected_main = [ - new EcmaDefinefuncdyn("test", new Imm(1), new VReg()), + new EcmaDefinefuncdyn("UnitTest.test", new Imm(1), new VReg()), new EcmaStglobalvar("test"), new EcmaReturnundefined() ]; @@ -133,10 +133,10 @@ describe("FunctionDeclarationTest", function () { ]; compilerunit.forEach(element => { - if (element.internalName == "func_main_0") { + if (element.internalName == "UnitTest.func_main_0") { let insns = element.getInsns(); expect(checkInstructions(insns, expected_main)).to.be.true; - } else if (element.internalName == "test") { + } else if (element.internalName == "UnitTest.test") { let insns = element.getInsns(); expect(checkInstructions(insns, expected_func)).to.be.true; let parameterLength = element.getParameterLength(); @@ -158,7 +158,7 @@ describe("FunctionDeclarationTest", function () { new EcmaReturnundefined(), ]; - let functionPg = snippetCompiler.getPandaGenByName("test"); + let functionPg = snippetCompiler.getPandaGenByName("UnitTest.test"); let insns = functionPg!.getInsns(); expect(checkInstructions(insns, expected_func)).to.be.true; diff --git a/ts2panda/tests/statements/variableDeclaration.test.ts b/ts2panda/tests/statements/variableDeclaration.test.ts index 1ce753c2d0..2e64168b4d 100644 --- a/ts2panda/tests/statements/variableDeclaration.test.ts +++ b/ts2panda/tests/statements/variableDeclaration.test.ts @@ -154,7 +154,7 @@ describe("VariableDeclarationTest", function () { it('var i in a function scope', function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compile("function a() {var i;}"); - let funcPg = snippetCompiler.getPandaGenByName("a"); + let funcPg = snippetCompiler.getPandaGenByName("UnitTest.a"); let functionScope = funcPg!.getScope(); let insns = funcPg!.getInsns(); let expected = [ @@ -172,7 +172,7 @@ describe("VariableDeclarationTest", function () { it('let i in a function scope', function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compile("function a() {let i;}"); - let funcPg = snippetCompiler.getPandaGenByName("a"); + let funcPg = snippetCompiler.getPandaGenByName("UnitTest.a"); let functionScope = funcPg!.getScope(); let insns = funcPg!.getInsns(); let expected = [ @@ -188,7 +188,7 @@ describe("VariableDeclarationTest", function () { it('const i in a function scope', function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compile("function a() {const i = 5;}"); - let funcPg = snippetCompiler.getPandaGenByName("a"); + let funcPg = snippetCompiler.getPandaGenByName("UnitTest.a"); let functionScope = funcPg!.getScope(); let insns = funcPg!.getInsns(); let expected = [ @@ -204,7 +204,7 @@ describe("VariableDeclarationTest", function () { it('let i in a local scope', function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compile("{let i;}"); - let funcPg = snippetCompiler.getPandaGenByName("func_main_0"); + let funcPg = snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let localScope = funcPg!.getScope(); let insns = funcPg!.getInsns(); diff --git a/ts2panda/tests/types/array.test.ts b/ts2panda/tests/types/array.test.ts index edaf90fdfa..9742c7faed 100644 --- a/ts2panda/tests/types/array.test.ts +++ b/ts2panda/tests/types/array.test.ts @@ -30,7 +30,7 @@ describe("array tests in array.test.ts", function() { it("test array with primitives", function() { let fileNames = 'tests/types/array/array_primitives.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -75,7 +75,7 @@ describe("array tests in array.test.ts", function() { it("test array with class", function() { let fileNames = 'tests/types/array/array_class.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -108,7 +108,7 @@ describe("array tests in array.test.ts", function() { it("test array with multi same primitive", function() { let fileNames = 'tests/types/array/array_multi_same_primi.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -159,7 +159,7 @@ describe("array tests in array.test.ts", function() { it("test array with multi same class", function() { let fileNames = 'tests/types/array/array_multi_same_class.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -193,7 +193,7 @@ describe("array tests in array.test.ts", function() { it("test array with union", function() { let fileNames = 'tests/types/array/array_union.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -222,7 +222,7 @@ describe("array tests in array.test.ts", function() { it("test array with object", function() { let fileNames = 'tests/types/array/array_object.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ diff --git a/ts2panda/tests/types/class.test.ts b/ts2panda/tests/types/class.test.ts index 6f076b68e6..7fa9db6c9b 100644 --- a/ts2panda/tests/types/class.test.ts +++ b/ts2panda/tests/types/class.test.ts @@ -30,7 +30,7 @@ describe("class tests in class.test.ts", function () { it("test class with no parameter in block", function () { let fileNames = 'tests/types/class/class_constr_no_para.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -66,7 +66,7 @@ describe("class tests in class.test.ts", function () { it("test class with parameter in block", function () { let fileNames = 'tests/types/class/class_constr_para.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -102,7 +102,7 @@ describe("class tests in class.test.ts", function () { it("test class fields type", function () { let fileNames = 'tests/types/class/class_fields.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -136,7 +136,7 @@ describe("class tests in class.test.ts", function () { it("test class methods type", function () { let fileNames = 'tests/types/class/class_methods.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -176,7 +176,7 @@ describe("class tests in class.test.ts", function () { it("test class static fields type", function () { let fileNames = 'tests/types/class/class_static_fields.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -210,7 +210,7 @@ describe("class tests in class.test.ts", function () { it("test class static methods type", function () { let fileNames = 'tests/types/class/class_static_methods.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -252,7 +252,7 @@ describe("class tests in class.test.ts", function () { it("test abstract class type", function () { let fileNames = 'tests/types/class/class_abstract.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -297,7 +297,7 @@ describe("class tests in class.test.ts", function () { it("test class implements type", function () { let fileNames = 'tests/types/class/class_implements.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ diff --git a/ts2panda/tests/types/function.test.ts b/ts2panda/tests/types/function.test.ts index 563e2b4c00..a9ebb11ad8 100644 --- a/ts2panda/tests/types/function.test.ts +++ b/ts2panda/tests/types/function.test.ts @@ -30,7 +30,7 @@ describe("function tests in function.test.ts", function () { it("test function with no parameter", function () { let fileNames = 'tests/types/function/function_no_para.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -60,7 +60,7 @@ describe("function tests in function.test.ts", function () { it("test function with muti parameter", function () { let fileNames = 'tests/types/function/function_multi_para.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -92,7 +92,7 @@ describe("function tests in function.test.ts", function () { it("test function with same type of paras and return", function () { let fileNames = 'tests/types/function/function_same_para_and_return.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -131,7 +131,7 @@ describe("function tests in function.test.ts", function () { it("test function with class as parameter", function () { let fileNames = 'tests/types/function/function_class_para.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -172,7 +172,7 @@ describe("function tests in function.test.ts", function () { it("test function with class as return", function () { let fileNames = 'tests/types/function/function_class_return.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ diff --git a/ts2panda/tests/types/object.test.ts b/ts2panda/tests/types/object.test.ts index eae94789e7..9d10d53062 100644 --- a/ts2panda/tests/types/object.test.ts +++ b/ts2panda/tests/types/object.test.ts @@ -30,7 +30,7 @@ describe("object tests in object.test.ts", function() { it("test object with primitives", function() { let fileNames = 'tests/types/object/object_primi.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -56,7 +56,7 @@ describe("object tests in object.test.ts", function() { it("test object with user defined type", function() { let fileNames = 'tests/types/object/object_class.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ diff --git a/ts2panda/tests/types/primitives.test.ts b/ts2panda/tests/types/primitives.test.ts index d05b7c1ba2..9fab6e6a77 100644 --- a/ts2panda/tests/types/primitives.test.ts +++ b/ts2panda/tests/types/primitives.test.ts @@ -30,7 +30,7 @@ describe("primitives tests in primitives.test.ts", function() { it("test primitives in block", function() { let fileNames = 'tests/types/primitives/primitives_in_block.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -60,7 +60,7 @@ describe("primitives tests in primitives.test.ts", function() { it("test number in function", function() { let fileNames = 'tests/types/primitives/primitives_in_function.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("numberFunc"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.numberFunc"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -100,7 +100,7 @@ describe("primitives tests in primitives.test.ts", function() { it("test primitives in for", function() { let fileNames = 'tests/types/primitives/primitives_in_for.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -131,7 +131,7 @@ describe("primitives tests in primitives.test.ts", function() { it("test primitives in if", function() { let fileNames = 'tests/types/primitives/primitives_in_if.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -161,7 +161,7 @@ describe("primitives tests in primitives.test.ts", function() { it("test primitives in class", function() { let fileNames = 'tests/types/primitives/primitives_in_class.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -198,7 +198,7 @@ describe("primitives tests in primitives.test.ts", function() { it("test primitives with only type annotations", function() { let fileNames = 'tests/types/primitives/primitives_only_type_annotation.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -226,7 +226,7 @@ describe("primitives tests in primitives.test.ts", function() { it("test primitives without type annotations", function() { let fileNames = 'tests/types/primitives/primitives_no_type_annotation.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ diff --git a/ts2panda/tests/types/union.test.ts b/ts2panda/tests/types/union.test.ts index a1dc513747..ec68027356 100644 --- a/ts2panda/tests/types/union.test.ts +++ b/ts2panda/tests/types/union.test.ts @@ -30,7 +30,7 @@ describe("union tests in union.test.ts", function () { it("test union with primitives", function () { let fileNames = 'tests/types/union/union_primitives.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -68,7 +68,7 @@ describe("union tests in union.test.ts", function () { it("test union with user defined type", function () { let fileNames = 'tests/types/union/union_userDefinedType.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -104,7 +104,7 @@ describe("union tests in union.test.ts", function () { it("test union with multi same primitives", function () { let fileNames = 'tests/types/union/union_multi_same_primi.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -130,7 +130,7 @@ describe("union tests in union.test.ts", function () { it("test union with multi same user defined type", function () { let fileNames = 'tests/types/union/union_multi_userDefinedType.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ diff --git a/ts2panda/tests/utils/base.ts b/ts2panda/tests/utils/base.ts index 2d9f7ed318..49c7c5b52d 100644 --- a/ts2panda/tests/utils/base.ts +++ b/ts2panda/tests/utils/base.ts @@ -146,7 +146,7 @@ export function compileAllSnippet(snippet: string, passes?: Pass[], literalBuffe jshelpers.bindSourceFile(sourceFile, {}); CmdOptions.isWatchEvaluateExpressionMode() ? setGlobalStrict(true) : setGlobalStrict(jshelpers.isEffectiveStrictModeSourceFile(sourceFile, compileOptions)); - let compilerDriver = new CompilerDriver('UnitTest'); + let compilerDriver = new CompilerDriver('UnitTest', 'UnitTest'); if (!passes) { passes = []; @@ -166,7 +166,7 @@ export function compileMainSnippet(snippet: string, pandaGen?: PandaGen, scope?: // only return main function if (compileFunc) { compileUnits.filter((pg) => { - return (pg.internalName == "func_main_0"); + return (pg.internalName == "UnitTest.func_main_0"); }) } @@ -191,7 +191,7 @@ export function compileAfterSnippet(snippet: string, name:string, isCommonJs: bo } jshelpers.bindSourceFile(sourceFile, {}); setGlobalStrict(jshelpers.isEffectiveStrictModeSourceFile(sourceFile, compileOptions)); - let compilerDriver = new CompilerDriver('UnitTest'); + let compilerDriver = new CompilerDriver('UnitTest', 'UnitTest'); compilerDriver.setCustomPasses([]); compilerDriver.compileUnitTest(sourceFile, []); compileUnits = compilerDriver.getCompilationUnits(); @@ -228,7 +228,7 @@ export class SnippetCompiler { } getGlobalInsns(): IRNode[] { - let root = this.getPandaGenByName("func_main_0"); + let root = this.getPandaGenByName("UnitTest.func_main_0"); if (root) { return root.getInsns(); } else { @@ -237,7 +237,7 @@ export class SnippetCompiler { } getGlobalScope(): Scope | undefined { - let globalPandaGen = this.getPandaGenByName("func_main_0"); + let globalPandaGen = this.getPandaGenByName("UnitTest.func_main_0"); return globalPandaGen ? globalPandaGen.getScope()!.getNearestVariableScope() : undefined; } -- Gitee From fabad66596ca77df657f7b1ac4a01e90127dbf76 Mon Sep 17 00:00:00 2001 From: gavin1012_hw Date: Thu, 25 Aug 2022 14:38:08 +0800 Subject: [PATCH 13/23] Split merge_abc binary with merge_program_function Signed-off-by: gavin1012_hw Change-Id: I122133ee517dd54eb171c0b06a9d7c30ba0167f1 --- merge_abc/BUILD.gn | 3 +- merge_abc/src/main.cpp | 98 ++++++++++++++++++++++++++++++++++ merge_abc/src/mergeProgram.cpp | 88 +++--------------------------- merge_abc/src/mergeProgram.h | 6 +++ 4 files changed, 113 insertions(+), 82 deletions(-) create mode 100644 merge_abc/src/main.cpp diff --git a/merge_abc/BUILD.gn b/merge_abc/BUILD.gn index 8a094d6a89..c31a339e79 100644 --- a/merge_abc/BUILD.gn +++ b/merge_abc/BUILD.gn @@ -33,6 +33,7 @@ protobuf_snapshot_generator_sources = [ "src/assemblyRecordProto.cpp", "src/assemblyTypeProto.cpp", "src/ideHelpersProto.cpp", + "src/mergeProgram.cpp", "src/metaProto.cpp", "src/protobufSnapshotGenerator.cpp", ] @@ -150,8 +151,8 @@ ohos_static_library("panda_assembly_proto_static") { ohos_executable("merge_abc") { use_exceptions = true sources = [ + "src/main.cpp", "src/Options.cpp", - "src/mergeProgram.cpp", ] include_dirs = [ "./src" ] diff --git a/merge_abc/src/main.cpp b/merge_abc/src/main.cpp new file mode 100644 index 0000000000..6badcea549 --- /dev/null +++ b/merge_abc/src/main.cpp @@ -0,0 +1,98 @@ +/** + * 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. + */ + +#include "mergeProgram.h" +#include "arena_allocator.h" +#include "Options.h" +#include "protobufSnapshotGenerator.h" +#include +#include + +namespace panda::proto { + +using mem::MemConfig; + +class ProtoMemManager { +public: + explicit ProtoMemManager() + { + constexpr auto COMPILER_SIZE = 512_MB; + + MemConfig::Initialize(0, 0, COMPILER_SIZE, 0); + PoolManager::Initialize(PoolType::MMAP); + } + + NO_COPY_SEMANTIC(ProtoMemManager); + NO_MOVE_SEMANTIC(ProtoMemManager); + + ~ProtoMemManager() + { + PoolManager::Finalize(); + MemConfig::Finalize(); + } +}; + +int Run(int argc, const char **argv) +{ + auto options = std::make_unique(); + if (!options->Parse(argc, argv)) { + std::cerr << options->ErrorMsg() << std::endl; + return 1; + } + + std::string protoPathInput = options->protoPathInput(); + std::string protoBinSuffix = options->protoBinSuffix(); + std::string outputFilePath = options->outputFilePath(); + + if (outputFilePath.empty()) { + outputFilePath = panda::os::file::File::GetExecutablePath().Value(); + } + + panda::ArenaAllocator allocator(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true); + + std::vector protoFiles; + if (!MergeProgram::CollectProtoFiles(protoPathInput, protoBinSuffix, protoFiles)) { + return 1; + } + + panda::pandasm::Program program; + MergeProgram mergeProgram(&program); + + for (auto &protoFile : protoFiles) { + panda::pandasm::Program program; + proto::ProtobufSnapshotGenerator::GenerateProgram(protoFile, program, &allocator); + mergeProgram.Merge(&program); + } + + std::map stat; + std::map *statp = nullptr; + panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps maps {}; + panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps *mapsp = nullptr; + + std::string outputFileName = outputFilePath.append(panda::os::file::File::GetPathDelim()). + append(options->outputFileName()); + if (!panda::pandasm::AsmEmitter::Emit(outputFileName, *(mergeProgram.GetResult()), statp, mapsp, true)) { + return 1; + } + + return 0; +} +} // namespace panda::proto + +int main(int argc, const char **argv) +{ + panda::proto::ProtoMemManager mm; + return panda::proto::Run(argc, argv); +} diff --git a/merge_abc/src/mergeProgram.cpp b/merge_abc/src/mergeProgram.cpp index d5c46af111..279e89e1ab 100644 --- a/merge_abc/src/mergeProgram.cpp +++ b/merge_abc/src/mergeProgram.cpp @@ -14,12 +14,9 @@ */ #include "mergeProgram.h" -#include "protobufSnapshotGenerator.h" -#include "arena_allocator.h" #include "Options.h" #include "assembler/assembly-function.h" #include "libpandafile/literal_data_accessor.h" -#include #include #include "os/file.h" @@ -28,32 +25,9 @@ #else #include #endif -#include namespace panda::proto { -using mem::MemConfig; - -class ProtoMemManager { -public: - explicit ProtoMemManager() - { - constexpr auto COMPILER_SIZE = 512_MB; - - MemConfig::Initialize(0, 0, COMPILER_SIZE, 0); - PoolManager::Initialize(PoolType::MMAP); - } - - NO_COPY_SEMANTIC(ProtoMemManager); - NO_MOVE_SEMANTIC(ProtoMemManager); - - ~ProtoMemManager() - { - PoolManager::Finalize(); - MemConfig::Finalize(); - } -}; - void MergeProgram::Merge(panda::pandasm::Program *src) { CorrectLiteraArrayId(src); @@ -139,7 +113,8 @@ void MergeProgram::IncreaseInsLiteralArrayIdByBase(panda::pandasm::Ins &insn, si } } -bool GetProtoFiles(std::string &protoBinPath, std::string &protoBinSuffix, std::vector &directoryFiles) +bool MergeProgram::GetProtoFiles(std::string &protoBinPath, std::string &protoBinSuffix, + std::vector &directoryFiles) { #if PANDA_TARGET_WINDOWS int handle = 0; @@ -196,7 +171,8 @@ bool GetProtoFiles(std::string &protoBinPath, std::string &protoBinSuffix, std:: return true; } -bool AppendProtoFiles(std::string filePath, std::string protoBinSuffix, std::vector &protoFiles) +bool MergeProgram::AppendProtoFiles(std::string filePath, std::string protoBinSuffix, + std::vector &protoFiles) { auto inputAbs = panda::os::file::File::GetAbsolutePath(filePath); if (!inputAbs) { @@ -223,7 +199,8 @@ bool AppendProtoFiles(std::string filePath, std::string protoBinSuffix, std::vec return true; } -bool CollectProtoFiles(std::string input, std::string protoBinSuffix, std::vector &protoFiles) +bool MergeProgram::CollectProtoFiles(std::string input, std::string protoBinSuffix, + std::vector &protoFiles) { constexpr const char DOGGY = '@'; std::vector inputs; @@ -269,55 +246,4 @@ bool CollectProtoFiles(std::string input, std::string protoBinSuffix, std::vecto return true; } -int Run(int argc, const char **argv) -{ - auto options = std::make_unique(); - if (!options->Parse(argc, argv)) { - std::cerr << options->ErrorMsg() << std::endl; - return 1; - } - - std::string protoPathInput = options->protoPathInput(); - std::string protoBinSuffix = options->protoBinSuffix(); - std::string outputFilePath = options->outputFilePath(); - - if (outputFilePath.empty()) { - outputFilePath = panda::os::file::File::GetExecutablePath().Value().append( - panda::os::file::File::GetPathDelim()); - } - - panda::ArenaAllocator allocator(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true); - - std::vector protoFiles; - if (!CollectProtoFiles(protoPathInput, protoBinSuffix, protoFiles)) { - return 1; - } - - panda::pandasm::Program program; - MergeProgram mergeProgram(&program); - - for (auto &protoFile : protoFiles) { - panda::pandasm::Program program; - proto::ProtobufSnapshotGenerator::GenerateProgram(protoFile, program, &allocator); - mergeProgram.Merge(&program); - } - - std::map stat; - std::map *statp = nullptr; - panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps maps {}; - panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps *mapsp = nullptr; - - std::string outputFileName = outputFilePath.append(options->outputFileName()); - if (!panda::pandasm::AsmEmitter::Emit(outputFileName, *(mergeProgram.GetResult()), statp, mapsp, true)) { - return 1; - } - - return 0; -} -} - -int main(int argc, const char **argv) -{ - panda::proto::ProtoMemManager mm; - return panda::proto::Run(argc, argv); -} +} // namespace panda::proto diff --git a/merge_abc/src/mergeProgram.h b/merge_abc/src/mergeProgram.h index 67a9e1e472..110f0f7120 100644 --- a/merge_abc/src/mergeProgram.h +++ b/merge_abc/src/mergeProgram.h @@ -35,6 +35,12 @@ public: constexpr static std::string_view TYPE_ANNOTATION_RECORD = "_ESTypeAnnotation"; + static bool GetProtoFiles(std::string &protoBinPath, std::string &protoBinSuffix, + std::vector &directoryFiles); + static bool AppendProtoFiles(std::string filePath, std::string protoBinSuffix, + std::vector &protoFiles); + static bool CollectProtoFiles(std::string input, std::string protoBinSuffix, std::vector &protoFiles); + private: void CorrectLiteraArrayId(panda::pandasm::Program *src); void IncreaseInsLiteralArrayIdByBase(panda::pandasm::Ins &insn, size_t base); -- Gitee From bc884c4c84a35216808d6d748178201651f7b034 Mon Sep 17 00:00:00 2001 From: gavin1012_hw Date: Thu, 25 Aug 2022 22:22:11 +0800 Subject: [PATCH 14/23] Add composite program for serializing && deserializing Signed-off-by: gavin1012_hw Change-Id: I7a8d599849c879ff8500001242f82d4cf4607332 --- es2panda/util/compositeHelpers.h | 38 +++++++++ merge_abc/BUILD.gn | 3 + merge_abc/protos/compositeProgram.proto | 29 +++++++ merge_abc/src/compositeProgramProto.cpp | 47 ++++++++++++ merge_abc/src/compositeProgramProto.h | 34 +++++++++ merge_abc/src/main.cpp | 17 ++--- merge_abc/src/mergeProgram.cpp | 85 --------------------- merge_abc/src/mergeProgram.h | 17 ----- merge_abc/src/protobufSnapshotGenerator.cpp | 40 +++++++++- merge_abc/src/protobufSnapshotGenerator.h | 5 ++ 10 files changed, 199 insertions(+), 116 deletions(-) create mode 100644 es2panda/util/compositeHelpers.h create mode 100644 merge_abc/protos/compositeProgram.proto create mode 100644 merge_abc/src/compositeProgramProto.cpp create mode 100644 merge_abc/src/compositeProgramProto.h diff --git a/es2panda/util/compositeHelpers.h b/es2panda/util/compositeHelpers.h new file mode 100644 index 0000000000..e11b0ff51b --- /dev/null +++ b/es2panda/util/compositeHelpers.h @@ -0,0 +1,38 @@ +/** + * 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_COMPOSITE_HELPERS_H +#define ES2PANDA_UTIL_COMPOSITE_HELPERS_H + +#include + +namespace panda::es2panda::util { + +struct HashProgram { + uint32_t hashCode; + panda::pandasm::Program* program; + + HashProgram(uint32_t hashCode, panda::pandasm::Program* program) : hashCode(hashCode), program(program) + { + } +}; + +struct CompositeProgramMap { + std::unordered_map compositeProgramInfo; +}; + +} //panda::es2panda::util + +#endif diff --git a/merge_abc/BUILD.gn b/merge_abc/BUILD.gn index c31a339e79..de41934673 100644 --- a/merge_abc/BUILD.gn +++ b/merge_abc/BUILD.gn @@ -32,6 +32,7 @@ protobuf_snapshot_generator_sources = [ "src/assemblyProgramProto.cpp", "src/assemblyRecordProto.cpp", "src/assemblyTypeProto.cpp", + "src/compositeProgramProto.cpp", "src/ideHelpersProto.cpp", "src/mergeProgram.cpp", "src/metaProto.cpp", @@ -49,6 +50,7 @@ config("panda_assembly_proto_public_config") { "//third_party/protobuf/src", "//third_party/protobuf/src/google", "//third_party/protobuf/src/google/protobuf", + "//arkcompiler/ets_frontend/es2panda/util", ] } @@ -74,6 +76,7 @@ proto_file_defines = [ "assemblyProgram", "assemblyRecord", "assemblyType", + "compositeProgram", "ideHelpers", "meta", ] diff --git a/merge_abc/protos/compositeProgram.proto b/merge_abc/protos/compositeProgram.proto new file mode 100644 index 0000000000..226c69dff8 --- /dev/null +++ b/merge_abc/protos/compositeProgram.proto @@ -0,0 +1,29 @@ +/** + * 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. + */ + +syntax = "proto3"; +package proto_panda; + +import "assemblyProgram.proto"; + +message HashNameProgram { + bytes fileName = 1; + uint32 hashCode = 2; + Program program = 3; +} + +message CompositeProgram { + repeated HashNameProgram hashNameProgram = 1; +} diff --git a/merge_abc/src/compositeProgramProto.cpp b/merge_abc/src/compositeProgramProto.cpp new file mode 100644 index 0000000000..35afb80b87 --- /dev/null +++ b/merge_abc/src/compositeProgramProto.cpp @@ -0,0 +1,47 @@ +/** + * 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. + */ + +#include "compositeProgramProto.h" + +namespace panda::proto { + +void CompositeProgram::Serialize(const panda::es2panda::util::CompositeProgramMap &compositeProgramMap, + proto_panda::CompositeProgram &protoCompositeProgram) +{ + for (const auto &[fileName, hashProgram] : compositeProgramMap.compositeProgramInfo) { + auto protoHashNameProgram = protoCompositeProgram.add_hashnameprogram(); + protoHashNameProgram->set_filename(fileName); + protoHashNameProgram->set_hashcode(hashProgram->hashCode); + auto *protoProgram = protoHashNameProgram->mutable_program(); + Program::Serialize(*(hashProgram->program), *protoProgram); + } +} + +void CompositeProgram::Deserialize(const proto_panda::CompositeProgram &protoCompositeProgram, + panda::es2panda::util::CompositeProgramMap &compositeProgramMap, + panda::ArenaAllocator *allocator) +{ + for (const auto &protoHashNameProgram : protoCompositeProgram.hashnameprogram()) { + auto fileName = protoHashNameProgram.filename(); + auto hashCode = protoHashNameProgram.hashcode(); + auto protoProgram = protoHashNameProgram.program(); + auto *program = allocator->New(); + Program::Deserialize(protoProgram, *program, allocator); + auto *hashProgram = allocator->New(hashCode, program); + compositeProgramMap.compositeProgramInfo.insert({fileName, hashProgram}); + } +} + +} // namespace panda::proto diff --git a/merge_abc/src/compositeProgramProto.h b/merge_abc/src/compositeProgramProto.h new file mode 100644 index 0000000000..8316285cf2 --- /dev/null +++ b/merge_abc/src/compositeProgramProto.h @@ -0,0 +1,34 @@ +/** + * 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 MERGE_ABC_BUILD_COMPOSITE_PROGRAM_H +#define MERGE_ABC_BUILD_COMPOSITE_PROGRAM_H + +#include "compositeHelpers.h" +#include "compositeProgram.pb.h" +#include "assemblyProgramProto.h" + +namespace panda::proto { +class CompositeProgram { +public: + static void Serialize(const panda::es2panda::util::CompositeProgramMap &compositeProgramMap, + proto_panda::CompositeProgram &protoCompositeProgram); + static void Deserialize(const proto_panda::CompositeProgram &protoCompositeProgram, + panda::es2panda::util::CompositeProgramMap &compositeProgramMap, + panda::ArenaAllocator *allocator); +}; +} // panda::proto + +#endif diff --git a/merge_abc/src/main.cpp b/merge_abc/src/main.cpp index 6badcea549..40a6bc307a 100644 --- a/merge_abc/src/main.cpp +++ b/merge_abc/src/main.cpp @@ -67,23 +67,18 @@ int Run(int argc, const char **argv) return 1; } - panda::pandasm::Program program; - MergeProgram mergeProgram(&program); + std::vector programs(protoFiles.size()); for (auto &protoFile : protoFiles) { - panda::pandasm::Program program; - proto::ProtobufSnapshotGenerator::GenerateProgram(protoFile, program, &allocator); - mergeProgram.Merge(&program); + auto *prog = allocator.New(); + proto::ProtobufSnapshotGenerator::GenerateProgram(protoFile, *prog, &allocator); + programs.emplace_back(prog); } - std::map stat; - std::map *statp = nullptr; - panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps maps {}; - panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps *mapsp = nullptr; - std::string outputFileName = outputFilePath.append(panda::os::file::File::GetPathDelim()). append(options->outputFileName()); - if (!panda::pandasm::AsmEmitter::Emit(outputFileName, *(mergeProgram.GetResult()), statp, mapsp, true)) { + + if (!panda::pandasm::AsmEmitter::EmitPrograms(outputFileName, programs, true)) { return 1; } diff --git a/merge_abc/src/mergeProgram.cpp b/merge_abc/src/mergeProgram.cpp index 279e89e1ab..f99d58d349 100644 --- a/merge_abc/src/mergeProgram.cpp +++ b/merge_abc/src/mergeProgram.cpp @@ -28,91 +28,6 @@ namespace panda::proto { -void MergeProgram::Merge(panda::pandasm::Program *src) { - CorrectLiteraArrayId(src); - - bool hasTypeAnnoRecord = false; - for (auto &iter : src->record_table) { - auto &name = iter.first; - bool isTypeAnnoRecord = name == std::string(TYPE_ANNOTATION_RECORD.data()); - if (hasTypeAnnoRecord && isTypeAnnoRecord) { - continue; - } - ASSERT(prog_->record_table.find(name) == prog_->record_table.end()); - prog_->record_table.insert(std::move(iter)); - hasTypeAnnoRecord = hasTypeAnnoRecord || isTypeAnnoRecord; - } - - for (auto &[name, func] : src->function_table) { - ASSERT(prog_->function_table.find(name) == prog_->function_table.end()); - prog_->function_table.emplace(name, std::move(func)); - } - - ASSERT(src->function_synonyms.empty()); - - const auto base = prog_->literalarray_table.size(); - size_t count = 0; - for (auto &[id, litArray] : src->literalarray_table) { - prog_->literalarray_table.emplace(std::to_string(base + count), std::move(litArray)); - count++; - } - - for (const auto &str : src->strings) { - prog_->strings.insert(str); - } - - for (const auto &type: src->array_types) { - prog_->array_types.insert(type); - } -} - -void MergeProgram::CorrectLiteraArrayId(panda::pandasm::Program *src) -{ - const auto base = prog_->literalarray_table.size(); - - for (auto &[name, litArray] : src->literalarray_table) { - for (auto &lit : litArray.literals_) { - if (lit.tag_ == panda_file::LiteralTag::TYPEINDEX) { - lit.value_ = std::get(lit.value_) + base; - } - } - } - - for (auto &[name, func] : src->function_table) { - for (auto &insn : func.ins) { - IncreaseInsLiteralArrayIdByBase(insn, base); - } - } - - for (auto &[name, record] : src->record_table) { - for (auto &field : record.field_list) { - if (field.type.GetId() != panda_file::Type::TypeId::U32) { - continue; - } - auto addedVal = static_cast(base) + field.metadata->GetValue().value().GetValue(); - field.metadata->SetValue(panda::pandasm::ScalarValue::Create(addedVal)); - } - } -} - -// TODO: let it be auto-generated after isa-refactoring -void MergeProgram::IncreaseInsLiteralArrayIdByBase(panda::pandasm::Ins &insn, size_t base) -{ - switch (insn.opcode) { - case panda::pandasm::Opcode::ECMA_CREATEARRAYWITHBUFFER: - case panda::pandasm::Opcode::ECMA_CREATEOBJECTWITHBUFFER: - case panda::pandasm::Opcode::ECMA_CREATEOBJECTHAVINGMETHOD: - case panda::pandasm::Opcode::ECMA_DEFINECLASSWITHBUFFER: - insn.imms[0] = std::get(insn.imms[0]) + static_cast(base); - return; - case panda::pandasm::Opcode::ECMA_NEWLEXENVWITHNAMEDYN: - insn.imms[1] = std::get(insn.imms[1]) + static_cast(base); - return; - default: - return; - } -} - bool MergeProgram::GetProtoFiles(std::string &protoBinPath, std::string &protoBinSuffix, std::vector &directoryFiles) { diff --git a/merge_abc/src/mergeProgram.h b/merge_abc/src/mergeProgram.h index 110f0f7120..06125ae93f 100644 --- a/merge_abc/src/mergeProgram.h +++ b/merge_abc/src/mergeProgram.h @@ -23,28 +23,11 @@ namespace panda::proto { class MergeProgram { public: - explicit MergeProgram(panda::pandasm::Program *program) : prog_(program) {} - ~MergeProgram() = default; - - const panda::pandasm::Program *GetResult() const - { - return prog_; - } - - void Merge(panda::pandasm::Program *src); - - constexpr static std::string_view TYPE_ANNOTATION_RECORD = "_ESTypeAnnotation"; - static bool GetProtoFiles(std::string &protoBinPath, std::string &protoBinSuffix, std::vector &directoryFiles); static bool AppendProtoFiles(std::string filePath, std::string protoBinSuffix, std::vector &protoFiles); static bool CollectProtoFiles(std::string input, std::string protoBinSuffix, std::vector &protoFiles); - -private: - void CorrectLiteraArrayId(panda::pandasm::Program *src); - void IncreaseInsLiteralArrayIdByBase(panda::pandasm::Ins &insn, size_t base); - panda::pandasm::Program *prog_; }; } // namespace panda::proto #endif // MERGE_ABC_MERGE_PROGRAM_H diff --git a/merge_abc/src/protobufSnapshotGenerator.cpp b/merge_abc/src/protobufSnapshotGenerator.cpp index 23fbffa592..9415ad3da0 100644 --- a/merge_abc/src/protobufSnapshotGenerator.cpp +++ b/merge_abc/src/protobufSnapshotGenerator.cpp @@ -22,7 +22,7 @@ void ProtobufSnapshotGenerator::GenerateSnapshot(const panda::pandasm::Program & { proto_panda::Program protoProgram; - panda::proto::Program::Serialize(program, protoProgram); + Program::Serialize(program, protoProgram); std::fstream output(outputName, std::ios::out | std::ios::trunc | std::ios::binary); if (!output) { @@ -46,7 +46,41 @@ void ProtobufSnapshotGenerator::GenerateProgram(const std::string &inputName, pa std::cerr << "Failed to parse " << inputName << std::endl; return; } - Program program; - program.Deserialize(proto_program, prog, allocator); + Program::Deserialize(proto_program, prog, allocator); } + +void ProtobufSnapshotGenerator::UpdateCacheFile(panda::es2panda::util::CompositeProgramMap compositeProgramMap, + const std::string &cacheFilePath) +{ + proto_panda::CompositeProgram protoCompositeProgram; + CompositeProgram::Serialize(compositeProgramMap, protoCompositeProgram); + std::fstream output(cacheFilePath, std::ios::out | std::ios::trunc | std::ios::binary); + if (!output) { + std::cout << "Fail to create cache file: " << cacheFilePath << std::endl; + return; + } + protoCompositeProgram.SerializeToOstream(&output); + output.close(); +} + +panda::es2panda::util::CompositeProgramMap *ProtobufSnapshotGenerator::GetCacheContext(const std::string &cacheFilePath, + panda::ArenaAllocator *allocator) +{ + std::fstream input(cacheFilePath, std::ios::in | std::ios::binary); + if (!input) { + std::cerr << "Failed to open cache file: " << cacheFilePath << std::endl; + return nullptr; + } + proto_panda::CompositeProgram protoCompositeProgram; + if (!protoCompositeProgram.ParseFromIstream(&input)) { + std::cerr << "Failed to parse cache file: " << cacheFilePath << std::endl; + return nullptr; + } + + auto compositeProgramMap = allocator->New(); + CompositeProgram::Deserialize(protoCompositeProgram, *compositeProgramMap, allocator); + + return compositeProgramMap; +} + } // panda::proto diff --git a/merge_abc/src/protobufSnapshotGenerator.h b/merge_abc/src/protobufSnapshotGenerator.h index a92f9b5254..ba50ea815d 100644 --- a/merge_abc/src/protobufSnapshotGenerator.h +++ b/merge_abc/src/protobufSnapshotGenerator.h @@ -17,6 +17,7 @@ #define MERGE_ABC_POROBUFSNAPSHOTGENERATOR_H #include "assemblyProgramProto.h" +#include "compositeProgramProto.h" namespace panda::proto { class ProtobufSnapshotGenerator { @@ -24,6 +25,10 @@ public: static void GenerateSnapshot(const panda::pandasm::Program &prog, const std::string &outputName); static void GenerateProgram(const std::string &inputName, panda::pandasm::Program &prog, panda::ArenaAllocator *allocator); + static panda::es2panda::util::CompositeProgramMap *GetCacheContext(const std::string &cacheFilePath, + panda::ArenaAllocator *allocator); + static void UpdateCacheFile(panda::es2panda::util::CompositeProgramMap compositeProgramMap, + const std::string &cacheFilePath); }; } // panda::proto #endif -- Gitee From cef3b96744f96580aa565f5a8dc87a00542a458e Mon Sep 17 00:00:00 2001 From: qiuyu Date: Fri, 26 Aug 2022 17:27:51 +0800 Subject: [PATCH 15/23] Bugfix for coredump after deserializing programs Bugfix for coredump after deserializing programs Signed-off-by: qiuyu Change-Id: I3c6485f605b728e36746bc96a45f4e1cd1300c19 --- merge_abc/src/main.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/merge_abc/src/main.cpp b/merge_abc/src/main.cpp index 40a6bc307a..3b651b5fe4 100644 --- a/merge_abc/src/main.cpp +++ b/merge_abc/src/main.cpp @@ -60,21 +60,24 @@ int Run(int argc, const char **argv) outputFilePath = panda::os::file::File::GetExecutablePath().Value(); } - panda::ArenaAllocator allocator(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true); - std::vector protoFiles; if (!MergeProgram::CollectProtoFiles(protoPathInput, protoBinSuffix, protoFiles)) { return 1; } - std::vector programs(protoFiles.size()); + panda::ArenaAllocator allocator(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true); - for (auto &protoFile : protoFiles) { + std::vector programs; + for(size_t i = 0; i < protoFiles.size(); i++) { auto *prog = allocator.New(); - proto::ProtobufSnapshotGenerator::GenerateProgram(protoFile, *prog, &allocator); programs.emplace_back(prog); } + size_t idx = 0; + for (auto &protoFile : protoFiles) { + proto::ProtobufSnapshotGenerator::GenerateProgram(protoFile, *(programs[idx++]), &allocator); + } + std::string outputFileName = outputFilePath.append(panda::os::file::File::GetPathDelim()). append(options->outputFileName()); -- Gitee From cccaa6d658c8a1b2214ea794617c08b2293f1569 Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Sun, 28 Aug 2022 10:09:05 +0800 Subject: [PATCH 16/23] camel-case of proto file Signed-off-by: zhangrengao Change-Id: Iae15bfc3fc1e9ec20cec9615e50fe1d0db555f65 --- merge_abc/protos/annotation.proto | 24 +++-- merge_abc/protos/assemblyDebug.proto | 14 +-- merge_abc/protos/assemblyField.proto | 12 +-- merge_abc/protos/assemblyFileLocation.proto | 12 +-- merge_abc/protos/assemblyFunction.proto | 44 ++++----- merge_abc/protos/assemblyIns.proto | 11 ++- merge_abc/protos/assemblyLabel.proto | 4 +- merge_abc/protos/assemblyLiterals.proto | 10 +- merge_abc/protos/assemblyProgram.proto | 12 +-- merge_abc/protos/assemblyRecord.proto | 14 +-- merge_abc/protos/assemblyType.proto | 6 +- merge_abc/protos/compositeProgram.proto | 2 +- merge_abc/protos/ideHelpers.proto | 2 +- merge_abc/protos/meta.proto | 6 +- merge_abc/src/annotationProto.cpp | 102 ++++++++++---------- merge_abc/src/annotationProto.h | 16 +-- merge_abc/src/assemblyDebugProto.cpp | 32 +++--- merge_abc/src/assemblyDebugProto.h | 8 +- merge_abc/src/assemblyFieldProto.cpp | 24 ++--- merge_abc/src/assemblyFieldProto.h | 4 +- merge_abc/src/assemblyFileLocationProto.cpp | 20 ++-- merge_abc/src/assemblyFileLocationProto.h | 4 +- merge_abc/src/assemblyFunctionProto.cpp | 82 ++++++++-------- merge_abc/src/assemblyFunctionProto.h | 12 +-- merge_abc/src/assemblyInsProto.cpp | 30 +++--- merge_abc/src/assemblyInsProto.h | 4 +- merge_abc/src/assemblyLabelProto.cpp | 10 +- merge_abc/src/assemblyLabelProto.h | 4 +- merge_abc/src/assemblyLiteralsProto.cpp | 78 +++++++-------- merge_abc/src/assemblyLiteralsProto.h | 12 +-- merge_abc/src/assemblyProgramProto.cpp | 20 ++-- merge_abc/src/assemblyProgramProto.h | 4 +- merge_abc/src/assemblyRecordProto.cpp | 26 ++--- merge_abc/src/assemblyRecordProto.h | 4 +- merge_abc/src/assemblyTypeProto.cpp | 10 +- merge_abc/src/assemblyTypeProto.h | 4 +- merge_abc/src/compositeProgramProto.cpp | 6 +- merge_abc/src/compositeProgramProto.h | 6 +- merge_abc/src/ideHelpersProto.cpp | 8 +- merge_abc/src/ideHelpersProto.h | 8 +- merge_abc/src/metaProto.cpp | 38 ++++---- merge_abc/src/metaProto.h | 28 +++--- merge_abc/src/protobufSnapshotGenerator.cpp | 10 +- 43 files changed, 396 insertions(+), 391 deletions(-) diff --git a/merge_abc/protos/annotation.proto b/merge_abc/protos/annotation.proto index 848e7e30ba..91e850d73d 100644 --- a/merge_abc/protos/annotation.proto +++ b/merge_abc/protos/annotation.proto @@ -14,7 +14,7 @@ */ syntax = "proto3"; -package proto_panda; +package protoPanda; import "assemblyType.proto"; @@ -33,32 +33,36 @@ message ScalarValue { } Value father = 1; oneof value { - uint64 value_u64 = 2; - float value_f = 3; - double value_d = 4; - bytes value_str = 5; - Type value_type = 6; - AnnotationData value_anno = 7; + uint64 valueU64 = 2; + float valueFloat = 3; + double valueDouble = 4; + bytes valueStr = 5; + Type valueType = 6; + AnnotationData valueAnno = 7; } VariantValueType type = 8; } message ArrayValue { Value father = 1; - uint32 component_type = 2; + uint32 componentType = 2; repeated ScalarValue values = 3; } message AnnotationElement { + enum ValueType { + SCALAR = 0; + ARRAY = 1; + } bytes name = 1; oneof value { ScalarValue scalar = 2; ArrayValue array = 3; } - bool is_array = 4; + ValueType valueType = 4; } message AnnotationData { - bytes record_name = 1; + bytes recordName = 1; repeated AnnotationElement elements = 2; } diff --git a/merge_abc/protos/assemblyDebug.proto b/merge_abc/protos/assemblyDebug.proto index 3d56843809..16321f5e19 100644 --- a/merge_abc/protos/assemblyDebug.proto +++ b/merge_abc/protos/assemblyDebug.proto @@ -14,20 +14,20 @@ */ syntax = "proto3"; -package proto_panda; +package protoPanda; message DebuginfoIns { - uint64 line_number = 1; - uint32 column_number = 2; - bytes whole_line = 3; - uint64 bound_left = 4; - uint64 bound_right = 5; + uint64 lineNumber = 1; + uint32 columnNumber = 2; + bytes wholeLine = 3; + uint64 boundLeft = 4; + uint64 boundRight = 5; } message LocalVariable { bytes name = 1; bytes signature = 2; - bytes signature_type = 3; + bytes signatureType = 3; int32 reg = 4; uint32 start = 5; uint32 length = 6; diff --git a/merge_abc/protos/assemblyField.proto b/merge_abc/protos/assemblyField.proto index e3cf2daa81..70c8d6bbb2 100644 --- a/merge_abc/protos/assemblyField.proto +++ b/merge_abc/protos/assemblyField.proto @@ -14,7 +14,7 @@ */ syntax = "proto3"; -package proto_panda; +package protoPanda; import "assemblyType.proto"; import "meta.proto"; @@ -23,9 +23,9 @@ message Field { Type type = 1; bytes name = 2; FieldMetadata metadata = 3; - uint64 line_of_def = 4; - bytes whole_line = 5; - uint64 bound_left = 6; - uint64 bound_right = 7; - bool is_defined = 8; + uint64 lineOfDef = 4; + bytes wholeLine = 5; + uint64 boundLeft = 6; + uint64 boundRight = 7; + bool isDefined = 8; } diff --git a/merge_abc/protos/assemblyFileLocation.proto b/merge_abc/protos/assemblyFileLocation.proto index 500239f743..864a9a9609 100644 --- a/merge_abc/protos/assemblyFileLocation.proto +++ b/merge_abc/protos/assemblyFileLocation.proto @@ -14,12 +14,12 @@ */ syntax = "proto3"; -package proto_panda; +package protoPanda; message FileLocation { - bytes whole_line = 1; - uint64 bound_left = 2; - uint64 bound_right = 3; - uint64 line_number = 4; - bool is_defined = 5; + bytes wholeLine = 1; + uint64 boundLeft = 2; + uint64 boundRight = 3; + uint64 lineNumber = 4; + bool isDefined = 5; } diff --git a/merge_abc/protos/assemblyFunction.proto b/merge_abc/protos/assemblyFunction.proto index 8e2ab5bc9b..8fb3c05943 100644 --- a/merge_abc/protos/assemblyFunction.proto +++ b/merge_abc/protos/assemblyFunction.proto @@ -14,7 +14,7 @@ */ syntax = "proto3"; -package proto_panda; +package protoPanda; import "assemblyIns.proto"; import "assemblyLabel.proto"; @@ -25,12 +25,12 @@ import "ideHelpers.proto"; import "meta.proto"; message CatchBlock { - bytes whole_line = 1; - bytes exception_record = 2; - bytes try_begin_label = 3; - bytes try_end_label = 4; - bytes catch_begin_label = 5; - bytes catch_end_label = 6; + bytes wholeLine = 1; + bytes exceptionRecord = 2; + bytes tryBeginLabel = 3; + bytes tryEndLabel = 4; + bytes catchBeginLabel = 5; + bytes catchEndLabel = 6; } message TryCatchInfo { @@ -40,11 +40,11 @@ message TryCatchInfo { } message TryCatchMap { bytes key = 1; - repeated CatchBlock catch_blocks = 2; + repeated CatchBlock catchBlocks = 2; } - repeated TryCatchLabel try_catch_labels = 1; - repeated TryCatchMap try_catch_map = 2; - repeated bytes try_catch_order = 3; + repeated TryCatchLabel tryCatchLabels = 1; + repeated TryCatchMap tryCatchMap = 2; + repeated bytes tryCatchOrder = 3; } message Parameter { @@ -61,18 +61,18 @@ message Function { bytes name = 1; uint32 language = 2; FunctionMetadata metadata = 3; - repeated LabelTable label_table = 4; + repeated LabelTable labelTable = 4; repeated Ins ins = 5; - repeated LocalVariable local_variable_debug = 6; - bytes source_file = 7; - bytes source_code = 8; - repeated CatchBlock catch_blocks = 9; - int64 value_of_first_param = 10; - uint64 regs_num = 11; + repeated LocalVariable localVariableDebug = 6; + bytes sourceFile = 7; + bytes sourceCode = 8; + repeated CatchBlock catchBlocks = 9; + int64 valueOfFirstParam = 10; + uint64 regsNum = 11; repeated Parameter params = 12; - bool body_presence = 13; - Type return_type = 14; - SourceLocation body_location = 15; - optional FileLocation file_location = 16; + bool bodyPresence = 13; + Type returnType = 14; + SourceLocation bodyLocation = 15; + optional FileLocation fileLocation = 16; } diff --git a/merge_abc/protos/assemblyIns.proto b/merge_abc/protos/assemblyIns.proto index 2dc81a675c..c5b90a1de3 100644 --- a/merge_abc/protos/assemblyIns.proto +++ b/merge_abc/protos/assemblyIns.proto @@ -14,15 +14,15 @@ */ syntax = "proto3"; -package proto_panda; +package protoPanda; import "assemblyDebug.proto"; message Ins { message IType { oneof type { - int64 value_int = 1; - double value_double = 2; + int64 valueInt = 1; + double valueDouble = 2; } } @@ -31,6 +31,7 @@ message Ins { repeated bytes ids = 3; repeated IType imms = 4; bytes label = 5; - bool set_label = 6; - DebuginfoIns ins_debug = 7; + // duplicate name + bool setLabelVal = 6; + DebuginfoIns insDebug = 7; } diff --git a/merge_abc/protos/assemblyLabel.proto b/merge_abc/protos/assemblyLabel.proto index 1ada1f4287..03e1d21262 100644 --- a/merge_abc/protos/assemblyLabel.proto +++ b/merge_abc/protos/assemblyLabel.proto @@ -14,11 +14,11 @@ */ syntax = "proto3"; -package proto_panda; +package protoPanda; import "assemblyFileLocation.proto"; message Label { bytes name = 1; - optional FileLocation file_location = 2; + optional FileLocation fileLocation = 2; } diff --git a/merge_abc/protos/assemblyLiterals.proto b/merge_abc/protos/assemblyLiterals.proto index cfcc582c85..e98480ff99 100644 --- a/merge_abc/protos/assemblyLiterals.proto +++ b/merge_abc/protos/assemblyLiterals.proto @@ -14,7 +14,7 @@ */ syntax = "proto3"; -package proto_panda; +package protoPanda; message VariantValue { enum VariantValueType { @@ -29,10 +29,10 @@ message VariantValue { } oneof value { - uint64 value_int = 1; - float value_f = 2; - double value_d = 3; - bytes value_str = 4; + uint64 valueInt = 1; + float valueFloat = 2; + double valueDouble = 3; + bytes valueStr = 4; } VariantValueType type = 5; } diff --git a/merge_abc/protos/assemblyProgram.proto b/merge_abc/protos/assemblyProgram.proto index fb30ab1bbc..58c93fbf97 100644 --- a/merge_abc/protos/assemblyProgram.proto +++ b/merge_abc/protos/assemblyProgram.proto @@ -14,7 +14,7 @@ */ syntax = "proto3"; -package proto_panda; +package protoPanda; import "assemblyFunction.proto"; import "assemblyRecord.proto"; @@ -39,10 +39,10 @@ message Program { LiteralArray value = 2; } uint32 lang = 1; - repeated RecordTable record_table = 2; - repeated FunctionTable function_table = 3; - repeated FunctionSynnoyms function_synonyms = 4; - repeated LiteralArrayTable literalarray_table = 5; + repeated RecordTable recordTable = 2; + repeated FunctionTable functionTable = 3; + repeated FunctionSynnoyms functionSynonyms = 4; + repeated LiteralArrayTable literalArrayTable = 5; repeated bytes strings = 6; - repeated Type array_types = 7; + repeated Type arrayTypes = 7; } diff --git a/merge_abc/protos/assemblyRecord.proto b/merge_abc/protos/assemblyRecord.proto index dd341edee1..9996414e59 100644 --- a/merge_abc/protos/assemblyRecord.proto +++ b/merge_abc/protos/assemblyRecord.proto @@ -14,7 +14,7 @@ */ syntax = "proto3"; -package proto_panda; +package protoPanda; import "assemblyField.proto"; import "assemblyFileLocation.proto"; @@ -26,10 +26,10 @@ message Record { bool conflict = 2; uint32 language = 3; RecordMetadata metadata = 4; - repeated Field field_list = 5; - uint64 params_num = 6; - bool body_presence = 7; - SourceLocation body_location = 8; - bytes source_file = 9; - optional FileLocation file_location = 10; + repeated Field fieldList = 5; + uint64 paramsNum = 6; + bool bodyPresence = 7; + SourceLocation bodyLocation = 8; + bytes sourceFile = 9; + optional FileLocation fileLocation = 10; } diff --git a/merge_abc/protos/assemblyType.proto b/merge_abc/protos/assemblyType.proto index b0a29eace2..ea6cb36425 100644 --- a/merge_abc/protos/assemblyType.proto +++ b/merge_abc/protos/assemblyType.proto @@ -14,11 +14,11 @@ */ syntax = "proto3"; -package proto_panda; +package protoPanda; message Type { - bytes component_name = 1; + bytes componentName = 1; uint64 rank = 2; bytes name = 3; - uint32 type_id = 4; + uint32 typeId = 4; } diff --git a/merge_abc/protos/compositeProgram.proto b/merge_abc/protos/compositeProgram.proto index 226c69dff8..35baef97bb 100644 --- a/merge_abc/protos/compositeProgram.proto +++ b/merge_abc/protos/compositeProgram.proto @@ -14,7 +14,7 @@ */ syntax = "proto3"; -package proto_panda; +package protoPanda; import "assemblyProgram.proto"; diff --git a/merge_abc/protos/ideHelpers.proto b/merge_abc/protos/ideHelpers.proto index 6fb77d8bfd..e344b9b282 100644 --- a/merge_abc/protos/ideHelpers.proto +++ b/merge_abc/protos/ideHelpers.proto @@ -14,7 +14,7 @@ */ syntax = "proto3"; -package proto_panda; +package protoPanda; message SourcePosition { uint64 line = 1; diff --git a/merge_abc/protos/meta.proto b/merge_abc/protos/meta.proto index a4ffc18095..05b4e7e3ce 100644 --- a/merge_abc/protos/meta.proto +++ b/merge_abc/protos/meta.proto @@ -14,7 +14,7 @@ */ syntax = "proto3"; -package proto_panda; +package protoPanda; import "annotation.proto"; import "assemblyType.proto"; @@ -35,7 +35,7 @@ message AnnotationMetadata { message ItemMetadata { AnnotationMetadata father = 1; - uint32 access_flags = 2; + uint32 accessFlags = 2; } message RecordMetadata { @@ -44,7 +44,7 @@ message RecordMetadata { message FieldMetadata { ItemMetadata father = 1; - Type field_type = 2; + Type fieldType = 2; optional ScalarValue value = 3; } diff --git a/merge_abc/src/annotationProto.cpp b/merge_abc/src/annotationProto.cpp index 8f8d713449..37b7d86995 100644 --- a/merge_abc/src/annotationProto.cpp +++ b/merge_abc/src/annotationProto.cpp @@ -16,16 +16,16 @@ #include "annotationProto.h" namespace panda::proto { -void AnnotationData::Serialize(const panda::pandasm::AnnotationData &anno, proto_panda::AnnotationData &protoAnno) +void AnnotationData::Serialize(const panda::pandasm::AnnotationData &anno, protoPanda::AnnotationData &protoAnno) { - protoAnno.set_record_name(anno.GetName()); + protoAnno.set_recordname(anno.GetName()); for (const auto &element : anno.GetElements()) { auto *protoElement = protoAnno.add_elements(); AnnotationElement::Serialize(element, *protoElement); } } -void AnnotationData::Deserialize(const proto_panda::AnnotationData &protoAnno, panda::pandasm::AnnotationData &anno, +void AnnotationData::Deserialize(const protoPanda::AnnotationData &protoAnno, panda::pandasm::AnnotationData &anno, panda::ArenaAllocator *allocator) { for (const auto &protoElement : protoAnno.elements()) { @@ -35,24 +35,24 @@ void AnnotationData::Deserialize(const proto_panda::AnnotationData &protoAnno, p } void AnnotationElement::Serialize(const panda::pandasm::AnnotationElement &element, - proto_panda::AnnotationElement &protoElement) + protoPanda::AnnotationElement &protoElement) { protoElement.set_name(element.GetName()); - bool is_array = element.GetValue()->IsArray(); - protoElement.set_is_array(is_array); - if (is_array) { + if (element.GetValue()->IsArray()) { + protoElement.set_valuetype(protoPanda::AnnotationElement_ValueType::AnnotationElement_ValueType_ARRAY); auto *protoArray = protoElement.mutable_array(); ArrayValue::Serialize(*(element.GetValue()->GetAsArray()), *protoArray); } else { + protoElement.set_valuetype(protoPanda::AnnotationElement_ValueType::AnnotationElement_ValueType_SCALAR); auto *protoScalar = protoElement.mutable_scalar(); ScalarValue::Serialize(*(element.GetValue()->GetAsScalar()), *protoScalar); } } -panda::pandasm::AnnotationElement &AnnotationElement::Deserialize(const proto_panda::AnnotationElement &protoElement, +panda::pandasm::AnnotationElement &AnnotationElement::Deserialize(const protoPanda::AnnotationElement &protoElement, panda::ArenaAllocator *allocator) { - if (protoElement.is_array()) { + if (protoElement.valuetype() == protoPanda::AnnotationElement_ValueType::AnnotationElement_ValueType_ARRAY) { panda::pandasm::ArrayValue array = ArrayValue::Deserialize(protoElement.array(), allocator); auto element = allocator->New(protoElement.name(), std::make_unique(array)); @@ -64,61 +64,61 @@ panda::pandasm::AnnotationElement &AnnotationElement::Deserialize(const proto_pa return *element; } -void ScalarValue::Serialize(const panda::pandasm::ScalarValue &scalar, proto_panda::ScalarValue &protoScalar) +void ScalarValue::Serialize(const panda::pandasm::ScalarValue &scalar, protoPanda::ScalarValue &protoScalar) { - const auto &value_type = scalar.GetType(); - protoScalar.mutable_father()->set_type(static_cast(value_type)); - auto type = proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_UINT64; - switch (value_type) { + const auto &valueType = scalar.GetType(); + protoScalar.mutable_father()->set_type(static_cast(valueType)); + auto type = protoPanda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_UINT64; + switch (valueType) { case panda::pandasm::Value::Type::U1: case panda::pandasm::Value::Type::U8: - protoScalar.set_value_u64(static_cast(scalar.GetValue())); + protoScalar.set_valueu64(static_cast(scalar.GetValue())); break; case panda::pandasm::Value::Type::U16: - protoScalar.set_value_u64(static_cast(scalar.GetValue())); + protoScalar.set_valueu64(static_cast(scalar.GetValue())); break; case panda::pandasm::Value::Type::STRING_NULLPTR: case panda::pandasm::Value::Type::U32: - protoScalar.set_value_u64(static_cast(scalar.GetValue())); + protoScalar.set_valueu64(static_cast(scalar.GetValue())); break; case panda::pandasm::Value::Type::U64: - protoScalar.set_value_u64(scalar.GetValue()); + protoScalar.set_valueu64(scalar.GetValue()); break; case panda::pandasm::Value::Type::I8: - protoScalar.set_value_u64(static_cast(scalar.GetValue())); + protoScalar.set_valueu64(static_cast(scalar.GetValue())); break; case panda::pandasm::Value::Type::I16: - protoScalar.set_value_u64(static_cast(scalar.GetValue())); + protoScalar.set_valueu64(static_cast(scalar.GetValue())); break; case panda::pandasm::Value::Type::I32: - protoScalar.set_value_u64(static_cast(scalar.GetValue())); + protoScalar.set_valueu64(static_cast(scalar.GetValue())); break; case panda::pandasm::Value::Type::I64: - protoScalar.set_value_u64(static_cast(scalar.GetValue())); + protoScalar.set_valueu64(static_cast(scalar.GetValue())); break; case panda::pandasm::Value::Type::F32: - type = proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_FLOAT; - protoScalar.set_value_f(scalar.GetValue()); + type = protoPanda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_FLOAT; + protoScalar.set_valuefloat(scalar.GetValue()); break; case panda::pandasm::Value::Type::F64: - type = proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_DOUBLE; - protoScalar.set_value_d(scalar.GetValue()); + type = protoPanda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_DOUBLE; + protoScalar.set_valuedouble(scalar.GetValue()); break; case panda::pandasm::Value::Type::STRING: case panda::pandasm::Value::Type::METHOD: case panda::pandasm::Value::Type::ENUM: - type = proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_STRING; - protoScalar.set_value_str(scalar.GetValue()); + type = protoPanda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_STRING; + protoScalar.set_valuestr(scalar.GetValue()); break; case panda::pandasm::Value::Type::RECORD: { - type = proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_PANDASM_TYPE; - auto *protoType = protoScalar.mutable_value_type(); + type = protoPanda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_PANDASM_TYPE; + auto *protoType = protoScalar.mutable_valuetype(); Type::Serialize(scalar.GetValue(), *protoType); break; } case panda::pandasm::Value::Type::ANNOTATION: { - type = proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_ANNOTATION_DATA; - auto *protoAnno = protoScalar.mutable_value_anno(); + type = protoPanda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_ANNOTATION_DATA; + auto *protoAnno = protoScalar.mutable_valueanno(); AnnotationData::Serialize(scalar.GetValue(), *protoAnno); break; } @@ -128,35 +128,35 @@ void ScalarValue::Serialize(const panda::pandasm::ScalarValue &scalar, proto_pan protoScalar.set_type(type); } -panda::pandasm::ScalarValue ScalarValue::Deserialize(const proto_panda::ScalarValue &protoScalar, +panda::pandasm::ScalarValue ScalarValue::Deserialize(const protoPanda::ScalarValue &protoScalar, panda::ArenaAllocator *allocator) { - proto_panda::ScalarValue_VariantValueType scalarType = protoScalar.type(); + protoPanda::ScalarValue_VariantValueType scalarType = protoScalar.type(); std::variant value; switch (scalarType) { - case proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_UINT64: { - value = static_cast(protoScalar.value_u64()); + case protoPanda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_UINT64: { + value = static_cast(protoScalar.valueu64()); break; } - case proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_FLOAT: { - value = static_cast(protoScalar.value_f()); + case protoPanda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_FLOAT: { + value = static_cast(protoScalar.valuefloat()); break; } - case proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_DOUBLE: { - value = static_cast(protoScalar.value_d()); + case protoPanda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_DOUBLE: { + value = static_cast(protoScalar.valuedouble()); break; } - case proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_STRING: { - value = static_cast(protoScalar.value_str()); + case protoPanda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_STRING: { + value = static_cast(protoScalar.valuestr()); break; } - case proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_PANDASM_TYPE: { - value = static_cast(Type::Deserialize(protoScalar.value_type(), allocator)); + case protoPanda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_PANDASM_TYPE: { + value = static_cast(Type::Deserialize(protoScalar.valuetype(), allocator)); break; } - case proto_panda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_ANNOTATION_DATA: { - auto protoAnnotationData = protoScalar.value_anno(); - auto value = allocator->New(protoAnnotationData.record_name()); + case protoPanda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_ANNOTATION_DATA: { + auto protoAnnotationData = protoScalar.valueanno(); + auto value = allocator->New(protoAnnotationData.recordname()); AnnotationData::Deserialize(protoAnnotationData, *value, allocator); break; } @@ -242,17 +242,17 @@ panda::pandasm::ScalarValue ScalarValue::CreateScalarValue(const panda::pandasm: } } -void ArrayValue::Serialize(const panda::pandasm::ArrayValue &array, proto_panda::ArrayValue &protoArray) +void ArrayValue::Serialize(const panda::pandasm::ArrayValue &array, protoPanda::ArrayValue &protoArray) { protoArray.mutable_father()->set_type(static_cast(array.GetType())); - protoArray.set_component_type(static_cast(array.GetComponentType())); + protoArray.set_componenttype(static_cast(array.GetComponentType())); for (const auto &val : array.GetValues()) { auto *protoScalar = protoArray.add_values(); ScalarValue::Serialize(val, *protoScalar); } } -panda::pandasm::ArrayValue &ArrayValue::Deserialize(const proto_panda::ArrayValue &protoArray, +panda::pandasm::ArrayValue &ArrayValue::Deserialize(const protoPanda::ArrayValue &protoArray, panda::ArenaAllocator *allocator) { std::vector values; @@ -261,7 +261,7 @@ panda::pandasm::ArrayValue &ArrayValue::Deserialize(const proto_panda::ArrayValu values.emplace_back(std::move(scalar)); } auto array = allocator->New( - static_cast(protoArray.component_type()), values); + static_cast(protoArray.componenttype()), values); return *array; } } // panda::proto diff --git a/merge_abc/src/annotationProto.h b/merge_abc/src/annotationProto.h index 03a4268a68..51bff7ac1e 100644 --- a/merge_abc/src/annotationProto.h +++ b/merge_abc/src/annotationProto.h @@ -24,23 +24,23 @@ namespace panda::proto { class AnnotationData { public: - static void Serialize(const panda::pandasm::AnnotationData &anno, proto_panda::AnnotationData &protoAnno); - static void Deserialize(const proto_panda::AnnotationData &protoAnno, panda::pandasm::AnnotationData &anno, + static void Serialize(const panda::pandasm::AnnotationData &anno, protoPanda::AnnotationData &protoAnno); + static void Deserialize(const protoPanda::AnnotationData &protoAnno, panda::pandasm::AnnotationData &anno, panda::ArenaAllocator *allocator); }; class AnnotationElement { public: static void Serialize(const panda::pandasm::AnnotationElement &element, - proto_panda::AnnotationElement &protoElement); - static panda::pandasm::AnnotationElement &Deserialize(const proto_panda::AnnotationElement &protoElement, + protoPanda::AnnotationElement &protoElement); + static panda::pandasm::AnnotationElement &Deserialize(const protoPanda::AnnotationElement &protoElement, panda::ArenaAllocator *allocator); }; class ScalarValue { public: - static void Serialize(const panda::pandasm::ScalarValue &scalar, proto_panda::ScalarValue &protoScalar); - static panda::pandasm::ScalarValue Deserialize(const proto_panda::ScalarValue &protoScalar, + static void Serialize(const panda::pandasm::ScalarValue &scalar, protoPanda::ScalarValue &protoScalar); + static panda::pandasm::ScalarValue Deserialize(const protoPanda::ScalarValue &protoScalar, panda::ArenaAllocator *allocator); static panda::pandasm::ScalarValue CreateScalarValue(const panda::pandasm::Value::Type &type, std::variant @@ -49,8 +49,8 @@ public: class ArrayValue { public: - static void Serialize(const panda::pandasm::ArrayValue &array, proto_panda::ArrayValue &protoArray); - static panda::pandasm::ArrayValue &Deserialize(const proto_panda::ArrayValue &protoArray, + static void Serialize(const panda::pandasm::ArrayValue &array, protoPanda::ArrayValue &protoArray); + static panda::pandasm::ArrayValue &Deserialize(const protoPanda::ArrayValue &protoArray, panda::ArenaAllocator *allocator); }; } // panda::proto diff --git a/merge_abc/src/assemblyDebugProto.cpp b/merge_abc/src/assemblyDebugProto.cpp index c04da9bd09..443d4a2d80 100644 --- a/merge_abc/src/assemblyDebugProto.cpp +++ b/merge_abc/src/assemblyDebugProto.cpp @@ -16,41 +16,41 @@ #include "assemblyDebugProto.h" namespace panda::proto { -void DebuginfoIns::Serialize(const panda::pandasm::debuginfo::Ins &debug, proto_panda::DebuginfoIns &protoDebug) +void DebuginfoIns::Serialize(const panda::pandasm::debuginfo::Ins &debug, protoPanda::DebuginfoIns &protoDebug) { - protoDebug.set_line_number(debug.line_number); - protoDebug.set_column_number(debug.column_number); - protoDebug.set_whole_line(debug.whole_line); - protoDebug.set_bound_left(debug.bound_left); - protoDebug.set_bound_right(debug.bound_right); + protoDebug.set_linenumber(debug.line_number); + protoDebug.set_columnnumber(debug.column_number); + protoDebug.set_wholeline(debug.whole_line); + protoDebug.set_boundleft(debug.bound_left); + protoDebug.set_boundright(debug.bound_right); } -void DebuginfoIns::Deserialize(const proto_panda::DebuginfoIns &protoDebug, panda::pandasm::debuginfo::Ins &debug) +void DebuginfoIns::Deserialize(const protoPanda::DebuginfoIns &protoDebug, panda::pandasm::debuginfo::Ins &debug) { - debug.line_number = protoDebug.line_number(); - debug.column_number = protoDebug.column_number(); - debug.whole_line = protoDebug.whole_line(); - debug.bound_left = protoDebug.bound_left(); - debug.bound_right = protoDebug.bound_right(); + debug.line_number = protoDebug.linenumber(); + debug.column_number = protoDebug.columnnumber(); + debug.whole_line = protoDebug.wholeline(); + debug.bound_left = protoDebug.boundleft(); + debug.bound_right = protoDebug.boundright(); } void LocalVariable::Serialize(const panda::pandasm::debuginfo::LocalVariable &debug, - proto_panda::LocalVariable &protoDebug) + protoPanda::LocalVariable &protoDebug) { protoDebug.set_name(debug.name); protoDebug.set_signature(debug.signature); - protoDebug.set_signature_type(debug.signature_type); + protoDebug.set_signaturetype(debug.signature_type); protoDebug.set_reg(debug.reg); protoDebug.set_start(debug.start); protoDebug.set_length(debug.length); } -void LocalVariable::Deserialize(const proto_panda::LocalVariable &protoDebug, +void LocalVariable::Deserialize(const protoPanda::LocalVariable &protoDebug, panda::pandasm::debuginfo::LocalVariable &debug) { debug.name = protoDebug.name(); debug.signature = protoDebug.signature(); - debug.signature_type = protoDebug.signature_type(); + debug.signature_type = protoDebug.signaturetype(); debug.reg = protoDebug.reg(); debug.start = protoDebug.start(); debug.length = protoDebug.length(); diff --git a/merge_abc/src/assemblyDebugProto.h b/merge_abc/src/assemblyDebugProto.h index 566a82bfea..94508d125e 100644 --- a/merge_abc/src/assemblyDebugProto.h +++ b/merge_abc/src/assemblyDebugProto.h @@ -22,15 +22,15 @@ namespace panda::proto { class DebuginfoIns { public: - static void Serialize(const panda::pandasm::debuginfo::Ins &debug, proto_panda::DebuginfoIns &protoDebug); - static void Deserialize(const proto_panda::DebuginfoIns &protoDebug, panda::pandasm::debuginfo::Ins &debug); + static void Serialize(const panda::pandasm::debuginfo::Ins &debug, protoPanda::DebuginfoIns &protoDebug); + static void Deserialize(const protoPanda::DebuginfoIns &protoDebug, panda::pandasm::debuginfo::Ins &debug); }; class LocalVariable { public: static void Serialize(const panda::pandasm::debuginfo::LocalVariable &debug, - proto_panda::LocalVariable &protoDebug); - static void Deserialize(const proto_panda::LocalVariable &protoDebug, + protoPanda::LocalVariable &protoDebug); + static void Deserialize(const protoPanda::LocalVariable &protoDebug, panda::pandasm::debuginfo::LocalVariable &debug); }; } // panda::proto diff --git a/merge_abc/src/assemblyFieldProto.cpp b/merge_abc/src/assemblyFieldProto.cpp index a99b9d37d3..e92b8a1f99 100644 --- a/merge_abc/src/assemblyFieldProto.cpp +++ b/merge_abc/src/assemblyFieldProto.cpp @@ -16,30 +16,30 @@ #include "assemblyFieldProto.h" namespace panda::proto { -void Field::Serialize(const panda::pandasm::Field &field, proto_panda::Field &protoField) +void Field::Serialize(const panda::pandasm::Field &field, protoPanda::Field &protoField) { auto *protoType = protoField.mutable_type(); Type::Serialize(field.type, *protoType); protoField.set_name(field.name); auto *protoFieldmeta = protoField.mutable_metadata(); FieldMetadata::Serialize(*field.metadata, *protoFieldmeta); - protoField.set_line_of_def(field.line_of_def); - protoField.set_whole_line(field.whole_line); - protoField.set_bound_left(field.bound_left); - protoField.set_bound_right(field.bound_right); - protoField.set_is_defined(field.is_defined); + protoField.set_lineofdef(field.line_of_def); + protoField.set_wholeline(field.whole_line); + protoField.set_boundleft(field.bound_left); + protoField.set_boundright(field.bound_right); + protoField.set_isdefined(field.is_defined); } -void Field::Deserialize(const proto_panda::Field &protoField, panda::pandasm::Field &field, +void Field::Deserialize(const protoPanda::Field &protoField, panda::pandasm::Field &field, panda::ArenaAllocator *allocator) { field.type = Type::Deserialize(protoField.type(), allocator); field.name = protoField.name(); FieldMetadata::Deserialize(protoField.metadata(), field.metadata, allocator); - field.line_of_def = protoField.line_of_def(); - field.whole_line = protoField.whole_line(); - field.bound_left = protoField.bound_left(); - field.bound_right = protoField.bound_right(); - field.is_defined = protoField.is_defined(); + field.line_of_def = protoField.lineofdef(); + field.whole_line = protoField.wholeline(); + field.bound_left = protoField.boundleft(); + field.bound_right = protoField.boundright(); + field.is_defined = protoField.isdefined(); } } // panda::proto diff --git a/merge_abc/src/assemblyFieldProto.h b/merge_abc/src/assemblyFieldProto.h index 9a9857a527..7dbb8d763e 100644 --- a/merge_abc/src/assemblyFieldProto.h +++ b/merge_abc/src/assemblyFieldProto.h @@ -24,8 +24,8 @@ namespace panda::proto { class Field { public: - static void Serialize(const panda::pandasm::Field &field, proto_panda::Field &protoField); - static void Deserialize(const proto_panda::Field &protoField, panda::pandasm::Field &field, + static void Serialize(const panda::pandasm::Field &field, protoPanda::Field &protoField); + static void Deserialize(const protoPanda::Field &protoField, panda::pandasm::Field &field, panda::ArenaAllocator *allocator); }; } // panda::proto diff --git a/merge_abc/src/assemblyFileLocationProto.cpp b/merge_abc/src/assemblyFileLocationProto.cpp index d0d0da38ed..9f4a0f23bd 100644 --- a/merge_abc/src/assemblyFileLocationProto.cpp +++ b/merge_abc/src/assemblyFileLocationProto.cpp @@ -16,19 +16,19 @@ #include "assemblyFileLocationProto.h" namespace panda::proto { -void FileLocation::Serialize(const panda::pandasm::FileLocation &location, proto_panda::FileLocation &protoLocation) +void FileLocation::Serialize(const panda::pandasm::FileLocation &location, protoPanda::FileLocation &protoLocation) { - protoLocation.set_whole_line(location.whole_line); - protoLocation.set_bound_left(location.bound_left); - protoLocation.set_bound_right(location.bound_right); - protoLocation.set_is_defined(location.is_defined); + protoLocation.set_wholeline(location.whole_line); + protoLocation.set_boundleft(location.bound_left); + protoLocation.set_boundright(location.bound_right); + protoLocation.set_isdefined(location.is_defined); } -void FileLocation::Deserialize(const proto_panda::FileLocation &protoLocation, panda::pandasm::FileLocation &location) +void FileLocation::Deserialize(const protoPanda::FileLocation &protoLocation, panda::pandasm::FileLocation &location) { - location.whole_line = protoLocation.whole_line(); - location.bound_left = protoLocation.bound_left(); - location.bound_right = protoLocation.bound_right(); - location.is_defined = protoLocation.is_defined(); + location.whole_line = protoLocation.wholeline(); + location.bound_left = protoLocation.boundleft(); + location.bound_right = protoLocation.boundright(); + location.is_defined = protoLocation.isdefined(); } } // panda::proto diff --git a/merge_abc/src/assemblyFileLocationProto.h b/merge_abc/src/assemblyFileLocationProto.h index 4479034063..5245a24aa0 100644 --- a/merge_abc/src/assemblyFileLocationProto.h +++ b/merge_abc/src/assemblyFileLocationProto.h @@ -22,8 +22,8 @@ namespace panda::proto { class FileLocation { public: - static void Serialize(const panda::pandasm::FileLocation &location, proto_panda::FileLocation &protoLocation); - static void Deserialize(const proto_panda::FileLocation &protoLocation, panda::pandasm::FileLocation &location); + static void Serialize(const panda::pandasm::FileLocation &location, protoPanda::FileLocation &protoLocation); + static void Deserialize(const protoPanda::FileLocation &protoLocation, panda::pandasm::FileLocation &location); }; } // panda::proto #endif diff --git a/merge_abc/src/assemblyFunctionProto.cpp b/merge_abc/src/assemblyFunctionProto.cpp index 18a0b22f6e..0301e52e1f 100644 --- a/merge_abc/src/assemblyFunctionProto.cpp +++ b/merge_abc/src/assemblyFunctionProto.cpp @@ -16,27 +16,27 @@ #include "assemblyFunctionProto.h" namespace panda::proto { -void CatchBlock::Serialize(const panda::pandasm::Function::CatchBlock &block, proto_panda::CatchBlock &protoBlock) +void CatchBlock::Serialize(const panda::pandasm::Function::CatchBlock &block, protoPanda::CatchBlock &protoBlock) { - protoBlock.set_whole_line(block.whole_line); - protoBlock.set_exception_record(block.exception_record); - protoBlock.set_try_begin_label(block.try_begin_label); - protoBlock.set_try_end_label(block.try_end_label); - protoBlock.set_catch_begin_label(block.catch_begin_label); - protoBlock.set_catch_end_label(block.catch_end_label); + protoBlock.set_wholeline(block.whole_line); + protoBlock.set_exceptionrecord(block.exception_record); + protoBlock.set_trybeginlabel(block.try_begin_label); + protoBlock.set_tryendlabel(block.try_end_label); + protoBlock.set_catchbeginlabel(block.catch_begin_label); + protoBlock.set_catchendlabel(block.catch_end_label); } -void CatchBlock::Deserialize(const proto_panda::CatchBlock &protoBlock, panda::pandasm::Function::CatchBlock &block) +void CatchBlock::Deserialize(const protoPanda::CatchBlock &protoBlock, panda::pandasm::Function::CatchBlock &block) { - block.whole_line = protoBlock.whole_line(); - block.exception_record = protoBlock.exception_record(); - block.try_begin_label = protoBlock.try_begin_label(); - block.try_end_label = protoBlock.try_end_label(); - block.catch_begin_label = protoBlock.catch_begin_label(); - block.catch_end_label = protoBlock.catch_end_label(); + block.whole_line = protoBlock.wholeline(); + block.exception_record = protoBlock.exceptionrecord(); + block.try_begin_label = protoBlock.trybeginlabel(); + block.try_end_label = protoBlock.tryendlabel(); + block.catch_begin_label = protoBlock.catchbeginlabel(); + block.catch_end_label = protoBlock.catchendlabel(); } -void Parameter::Serialize(const panda::pandasm::Function::Parameter ¶m, proto_panda::Parameter &protoParam) +void Parameter::Serialize(const panda::pandasm::Function::Parameter ¶m, protoPanda::Parameter &protoParam) { auto *type = protoParam.mutable_type(); Type::Serialize(param.type, *type); @@ -44,13 +44,13 @@ void Parameter::Serialize(const panda::pandasm::Function::Parameter ¶m, prot ParamMetadata::Serialize(*(param.metadata), *metadata); } -void Parameter::Deserialize(const proto_panda::Parameter &protoParam, panda::pandasm::Function::Parameter ¶m, +void Parameter::Deserialize(const protoPanda::Parameter &protoParam, panda::pandasm::Function::Parameter ¶m, panda::ArenaAllocator *allocator) { ParamMetadata::Deserialize(protoParam.metadata(), param.metadata, allocator); } -void Function::Serialize(const panda::pandasm::Function &function, proto_panda::Function &protoFunction) +void Function::Serialize(const panda::pandasm::Function &function, protoPanda::Function &protoFunction) { protoFunction.set_name(function.name); protoFunction.set_language(static_cast(function.language)); @@ -59,7 +59,7 @@ void Function::Serialize(const panda::pandasm::Function &function, proto_panda:: FunctionMetadata::Serialize(*function.metadata, *protoFuncMeta); for (const auto &[name, label] : function.label_table) { - auto *labelMap = protoFunction.add_label_table(); + auto *labelMap = protoFunction.add_labeltable(); labelMap->set_key(name); auto *protoLabel = labelMap->mutable_value(); Label::Serialize(label, *protoLabel); @@ -71,46 +71,46 @@ void Function::Serialize(const panda::pandasm::Function &function, proto_panda:: } for (const auto &debug : function.local_variable_debug) { - auto *protoDebug = protoFunction.add_local_variable_debug(); + auto *protoDebug = protoFunction.add_localvariabledebug(); LocalVariable::Serialize(debug, *protoDebug); } - protoFunction.set_source_file(function.source_file); - protoFunction.set_source_code(function.source_code); + protoFunction.set_sourcefile(function.source_file); + protoFunction.set_sourcecode(function.source_code); for (const auto &block : function.catch_blocks) { - auto *protoBlock = protoFunction.add_catch_blocks(); + auto *protoBlock = protoFunction.add_catchblocks(); CatchBlock::Serialize(block, *protoBlock); } - protoFunction.set_value_of_first_param(function.value_of_first_param); - protoFunction.set_regs_num(function.regs_num); + protoFunction.set_valueoffirstparam(function.value_of_first_param); + protoFunction.set_regsnum(function.regs_num); for (const auto ¶m : function.params) { auto *protoParam = protoFunction.add_params(); Parameter::Serialize(param, *protoParam); } - protoFunction.set_body_presence(function.body_presence); + protoFunction.set_bodypresence(function.body_presence); - auto *protoReturnType = protoFunction.mutable_return_type(); + auto *protoReturnType = protoFunction.mutable_returntype(); Type::Serialize(function.return_type, *protoReturnType); - auto *protoBodyLocation = protoFunction.mutable_body_location(); + auto *protoBodyLocation = protoFunction.mutable_bodylocation(); SourceLocation::Serialize(function.body_location, *protoBodyLocation); const auto &fileLocation = function.file_location; if (fileLocation.has_value()) { - auto *protoFileLocation = protoFunction.mutable_file_location(); + auto *protoFileLocation = protoFunction.mutable_filelocation(); FileLocation::Serialize(fileLocation.value(), *protoFileLocation); } } -void Function::Deserialize(const proto_panda::Function &protoFunction, panda::pandasm::Function &function, +void Function::Deserialize(const protoPanda::Function &protoFunction, panda::pandasm::Function &function, panda::ArenaAllocator *allocator) { FunctionMetadata::Deserialize(protoFunction.metadata(), function.metadata, allocator); - for (const auto &labelUnit : protoFunction.label_table()) { + for (const auto &labelUnit : protoFunction.labeltable()) { auto name = labelUnit.key(); auto protoLabel = labelUnit.value(); panda::pandasm::Label label(name); @@ -124,23 +124,23 @@ void Function::Deserialize(const proto_panda::Function &protoFunction, panda::pa function.ins.emplace_back(std::move(ins)); } - for (const auto &protoLocalVariable : protoFunction.local_variable_debug()) { + for (const auto &protoLocalVariable : protoFunction.localvariabledebug()) { panda::pandasm::debuginfo::LocalVariable localVariable; LocalVariable::Deserialize(protoLocalVariable, localVariable); function.local_variable_debug.emplace_back(std::move(localVariable)); } - function.source_file = protoFunction.source_file(); - function.source_file = protoFunction.source_code(); + function.source_file = protoFunction.sourcefile(); + function.source_code = protoFunction.sourcecode(); - for (const auto &protoCatchBlock : protoFunction.catch_blocks()) { + for (const auto &protoCatchBlock : protoFunction.catchblocks()) { auto catchBlock = allocator->New(); CatchBlock::Deserialize(protoCatchBlock, *catchBlock); function.catch_blocks.emplace_back(std::move(*catchBlock)); } - function.value_of_first_param = protoFunction.value_of_first_param(); - function.regs_num = protoFunction.regs_num(); + function.value_of_first_param = protoFunction.valueoffirstparam(); + function.regs_num = protoFunction.regsnum(); for (const auto &protoParam : protoFunction.params()) { auto paramType = Type::Deserialize(protoParam.type(), allocator); @@ -149,12 +149,12 @@ void Function::Deserialize(const proto_panda::Function &protoFunction, panda::pa function.params.emplace_back(std::move(param)); } - function.body_presence = protoFunction.body_presence(); - function.return_type = Type::Deserialize(protoFunction.return_type(), allocator); - SourceLocation::Deserialize(protoFunction.body_location(), function.body_location); + function.body_presence = protoFunction.bodypresence(); + function.return_type = Type::Deserialize(protoFunction.returntype(), allocator); + SourceLocation::Deserialize(protoFunction.bodylocation(), function.body_location); - if (protoFunction.has_file_location()) { - FileLocation::Deserialize(protoFunction.file_location(), function.file_location.value()); + if (protoFunction.has_filelocation()) { + FileLocation::Deserialize(protoFunction.filelocation(), function.file_location.value()); } } } // panda::proto diff --git a/merge_abc/src/assemblyFunctionProto.h b/merge_abc/src/assemblyFunctionProto.h index d3f6d495f4..6db904b90a 100644 --- a/merge_abc/src/assemblyFunctionProto.h +++ b/merge_abc/src/assemblyFunctionProto.h @@ -30,21 +30,21 @@ namespace panda::proto { class CatchBlock { public: - static void Serialize(const panda::pandasm::Function::CatchBlock &block, proto_panda::CatchBlock &protoBlock); - static void Deserialize(const proto_panda::CatchBlock &protoBlock, panda::pandasm::Function::CatchBlock &block); + static void Serialize(const panda::pandasm::Function::CatchBlock &block, protoPanda::CatchBlock &protoBlock); + static void Deserialize(const protoPanda::CatchBlock &protoBlock, panda::pandasm::Function::CatchBlock &block); }; class Parameter { public: - static void Serialize(const panda::pandasm::Function::Parameter ¶m, proto_panda::Parameter &protoParam); - static void Deserialize(const proto_panda::Parameter &protoParam, panda::pandasm::Function::Parameter ¶m, + static void Serialize(const panda::pandasm::Function::Parameter ¶m, protoPanda::Parameter &protoParam); + static void Deserialize(const protoPanda::Parameter &protoParam, panda::pandasm::Function::Parameter ¶m, panda::ArenaAllocator *allocator_); }; class Function { public: - static void Serialize(const panda::pandasm::Function &function, proto_panda::Function &protoFunction); - static void Deserialize(const proto_panda::Function &protoFunction, panda::pandasm::Function &function, + static void Serialize(const panda::pandasm::Function &function, protoPanda::Function &protoFunction); + static void Deserialize(const protoPanda::Function &protoFunction, panda::pandasm::Function &function, panda::ArenaAllocator *allocator_); }; } // panda::proto diff --git a/merge_abc/src/assemblyInsProto.cpp b/merge_abc/src/assemblyInsProto.cpp index dbc74fa5bb..c4ab16ae4d 100644 --- a/merge_abc/src/assemblyInsProto.cpp +++ b/merge_abc/src/assemblyInsProto.cpp @@ -16,7 +16,7 @@ #include "assemblyInsProto.h" namespace panda::proto { -void Ins::Serialize(const panda::pandasm::Ins &insn, proto_panda::Ins &protoInsn) +void Ins::Serialize(const panda::pandasm::Ins &insn, protoPanda::Ins &protoInsn) { protoInsn.set_opcode(static_cast(insn.opcode)); for (const auto ® : insn.regs) { @@ -27,24 +27,24 @@ void Ins::Serialize(const panda::pandasm::Ins &insn, proto_panda::Ins &protoInsn } for (const auto &imm : insn.imms) { auto *protoImm = protoInsn.add_imms(); - switch (static_cast(imm.index() + 1)) { // 1: enum TypeCase start from 1 - case proto_panda::Ins_IType::kValueInt: - protoImm->set_value_int(std::get(imm)); + switch (static_cast(imm.index() + 1)) { // 1: enum TypeCase start from 1 + case protoPanda::Ins_IType::kValueInt: + protoImm->set_valueint(std::get(imm)); break; - case proto_panda::Ins_IType::kValueDouble: - protoImm->set_value_double(std::get(imm)); + case protoPanda::Ins_IType::kValueDouble: + protoImm->set_valuedouble(std::get(imm)); break; default: UNREACHABLE(); } } protoInsn.set_label(insn.label); - protoInsn.set_set_label(insn.set_label); - auto *protoDebug = protoInsn.mutable_ins_debug(); + protoInsn.set_setlabelval(insn.set_label); + auto *protoDebug = protoInsn.mutable_insdebug(); DebuginfoIns::Serialize(insn.ins_debug, *protoDebug); } -void Ins::Deserialize(const proto_panda::Ins &protoInsn, panda::pandasm::Ins &insn) +void Ins::Deserialize(const protoPanda::Ins &protoInsn, panda::pandasm::Ins &insn) { insn.opcode = static_cast(protoInsn.opcode()); for (const auto &protoReg : protoInsn.regs()) { @@ -55,12 +55,12 @@ void Ins::Deserialize(const proto_panda::Ins &protoInsn, panda::pandasm::Ins &in } for (const auto &protoImm : protoInsn.imms()) { switch (protoImm.type_case()) { - case proto_panda::Ins_IType::kValueInt: { - insn.imms.push_back(protoImm.value_int()); + case protoPanda::Ins_IType::kValueInt: { + insn.imms.push_back(protoImm.valueint()); break; } - case proto_panda::Ins_IType::kValueDouble: { - insn.imms.push_back(protoImm.value_double()); + case protoPanda::Ins_IType::kValueDouble: { + insn.imms.push_back(protoImm.valuedouble()); break; } default: @@ -68,8 +68,8 @@ void Ins::Deserialize(const proto_panda::Ins &protoInsn, panda::pandasm::Ins &in } } insn.label = protoInsn.label(); - insn.set_label = protoInsn.set_label(); - const proto_panda::DebuginfoIns protoDebugInfoIns = protoInsn.ins_debug(); + insn.set_label = protoInsn.setlabelval(); + const protoPanda::DebuginfoIns protoDebugInfoIns = protoInsn.insdebug(); DebuginfoIns::Deserialize(protoDebugInfoIns, insn.ins_debug); } } // panda::proto diff --git a/merge_abc/src/assemblyInsProto.h b/merge_abc/src/assemblyInsProto.h index 4ec5cc9bd4..0a3a9c3da3 100644 --- a/merge_abc/src/assemblyInsProto.h +++ b/merge_abc/src/assemblyInsProto.h @@ -23,8 +23,8 @@ namespace panda::proto { class Ins { public: - static void Serialize(const panda::pandasm::Ins &insn, proto_panda::Ins &protoInsn); - static void Deserialize(const proto_panda::Ins &protoInsn, panda::pandasm::Ins &insn); + static void Serialize(const panda::pandasm::Ins &insn, protoPanda::Ins &protoInsn); + static void Deserialize(const protoPanda::Ins &protoInsn, panda::pandasm::Ins &insn); }; } // panda::proto #endif diff --git a/merge_abc/src/assemblyLabelProto.cpp b/merge_abc/src/assemblyLabelProto.cpp index fc6f4f5133..f355a80490 100644 --- a/merge_abc/src/assemblyLabelProto.cpp +++ b/merge_abc/src/assemblyLabelProto.cpp @@ -16,21 +16,21 @@ #include "assemblyLabelProto.h" namespace panda::proto { -void Label::Serialize(const panda::pandasm::Label &label, proto_panda::Label &protoLabel) +void Label::Serialize(const panda::pandasm::Label &label, protoPanda::Label &protoLabel) { protoLabel.set_name(label.name); const auto &fileLocation = label.file_location; if (fileLocation.has_value()) { - auto *protoLocation = protoLabel.mutable_file_location(); + auto *protoLocation = protoLabel.mutable_filelocation(); FileLocation::Serialize(fileLocation.value(), *protoLocation); } } -void Label::Deserialize(const proto_panda::Label &protoLabel, panda::pandasm::Label &label) +void Label::Deserialize(const protoPanda::Label &protoLabel, panda::pandasm::Label &label) { label.name = protoLabel.name(); - if (protoLabel.has_file_location()) { - proto_panda::FileLocation protoLocation = protoLabel.file_location(); + if (protoLabel.has_filelocation()) { + protoPanda::FileLocation protoLocation = protoLabel.filelocation(); FileLocation::Deserialize(protoLocation, label.file_location.value()); } } diff --git a/merge_abc/src/assemblyLabelProto.h b/merge_abc/src/assemblyLabelProto.h index 98bac92032..908fcaff12 100644 --- a/merge_abc/src/assemblyLabelProto.h +++ b/merge_abc/src/assemblyLabelProto.h @@ -23,8 +23,8 @@ namespace panda::proto { class Label { public: - static void Serialize(const panda::pandasm::Label &label, proto_panda::Label &protoLabel); - static void Deserialize(const proto_panda::Label &protoLabel, panda::pandasm::Label &label); + static void Serialize(const panda::pandasm::Label &label, protoPanda::Label &protoLabel); + static void Deserialize(const protoPanda::Label &protoLabel, panda::pandasm::Label &label); }; } // panda::proto #endif diff --git a/merge_abc/src/assemblyLiteralsProto.cpp b/merge_abc/src/assemblyLiteralsProto.cpp index 95dabfe5e2..889357b94d 100644 --- a/merge_abc/src/assemblyLiteralsProto.cpp +++ b/merge_abc/src/assemblyLiteralsProto.cpp @@ -16,41 +16,41 @@ #include "assemblyLiteralsProto.h" namespace panda::proto { -void VariantValue::Serialize(const LiteralValueType &value, proto_panda::VariantValue &protoValue) +void VariantValue::Serialize(const LiteralValueType &value, protoPanda::VariantValue &protoValue) { - const auto type = static_cast(value.index()); + const auto type = static_cast(value.index()); protoValue.set_type(type); switch (type) { - case proto_panda::VariantValue_VariantValueType_BOOL: { - protoValue.set_value_int(static_cast(std::get(value))); + case protoPanda::VariantValue_VariantValueType_BOOL: { + protoValue.set_valueint(static_cast(std::get(value))); return; } - case proto_panda::VariantValue_VariantValueType_U8: { - protoValue.set_value_int(static_cast(std::get(value))); + case protoPanda::VariantValue_VariantValueType_U8: { + protoValue.set_valueint(static_cast(std::get(value))); return; } - case proto_panda::VariantValue_VariantValueType_U16: { - protoValue.set_value_int(static_cast(std::get(value))); + case protoPanda::VariantValue_VariantValueType_U16: { + protoValue.set_valueint(static_cast(std::get(value))); return; } - case proto_panda::VariantValue_VariantValueType_U32: { - protoValue.set_value_int(static_cast(std::get(value))); + case protoPanda::VariantValue_VariantValueType_U32: { + protoValue.set_valueint(static_cast(std::get(value))); return; } - case proto_panda::VariantValue_VariantValueType_U64: { - protoValue.set_value_int(std::get(value)); + case protoPanda::VariantValue_VariantValueType_U64: { + protoValue.set_valueint(std::get(value)); return; } - case proto_panda::VariantValue_VariantValueType_F32: { - protoValue.set_value_f(std::get(value)); + case protoPanda::VariantValue_VariantValueType_F32: { + protoValue.set_valuefloat(std::get(value)); return; } - case proto_panda::VariantValue_VariantValueType_F64: { - protoValue.set_value_d(std::get(value)); + case protoPanda::VariantValue_VariantValueType_F64: { + protoValue.set_valuedouble(std::get(value)); return; } - case proto_panda::VariantValue_VariantValueType_STRING: { - protoValue.set_value_str(std::get(value)); + case protoPanda::VariantValue_VariantValueType_STRING: { + protoValue.set_valuestr(std::get(value)); return; } default: @@ -58,40 +58,40 @@ void VariantValue::Serialize(const LiteralValueType &value, proto_panda::Variant } } -void VariantValue::Deserialize(const proto_panda::VariantValue &protoValue, LiteralValueType &value) +void VariantValue::Deserialize(const protoPanda::VariantValue &protoValue, LiteralValueType &value) { auto type = protoValue.type(); switch (type) { - case proto_panda::VariantValue_VariantValueType_BOOL: { - value = static_cast(protoValue.value_int()); + case protoPanda::VariantValue_VariantValueType_BOOL: { + value = static_cast(protoValue.valueint()); return; } - case proto_panda::VariantValue_VariantValueType_U8: { - value = static_cast(protoValue.value_int()); + case protoPanda::VariantValue_VariantValueType_U8: { + value = static_cast(protoValue.valueint()); return; } - case proto_panda::VariantValue_VariantValueType_U16: { - value = static_cast(protoValue.value_int()); + case protoPanda::VariantValue_VariantValueType_U16: { + value = static_cast(protoValue.valueint()); return; } - case proto_panda::VariantValue_VariantValueType_U32: { - value = static_cast(protoValue.value_int()); + case protoPanda::VariantValue_VariantValueType_U32: { + value = static_cast(protoValue.valueint()); return; } - case proto_panda::VariantValue_VariantValueType_U64: { - value = static_cast(protoValue.value_int()); + case protoPanda::VariantValue_VariantValueType_U64: { + value = static_cast(protoValue.valueint()); return; } - case proto_panda::VariantValue_VariantValueType_F32: { - value = protoValue.value_f(); + case protoPanda::VariantValue_VariantValueType_F32: { + value = protoValue.valuefloat(); return; } - case proto_panda::VariantValue_VariantValueType_F64: { - value = protoValue.value_d(); + case protoPanda::VariantValue_VariantValueType_F64: { + value = protoValue.valuedouble(); return; } - case proto_panda::VariantValue_VariantValueType_STRING: { - value = protoValue.value_str(); + case protoPanda::VariantValue_VariantValueType_STRING: { + value = protoValue.valuestr(); return; } default: @@ -99,7 +99,7 @@ void VariantValue::Deserialize(const proto_panda::VariantValue &protoValue, Lite } } -void LiteralArray::Serialize(const panda::pandasm::LiteralArray &array, proto_panda::LiteralArray &protoArray) +void LiteralArray::Serialize(const panda::pandasm::LiteralArray &array, protoPanda::LiteralArray &protoArray) { for (const auto &literal : array.literals_) { auto *protoLiteral = protoArray.add_literals(); @@ -107,7 +107,7 @@ void LiteralArray::Serialize(const panda::pandasm::LiteralArray &array, proto_pa } } -void LiteralArray::Deserialize(const proto_panda::LiteralArray &protoArray, panda::pandasm::LiteralArray &array) +void LiteralArray::Deserialize(const protoPanda::LiteralArray &protoArray, panda::pandasm::LiteralArray &array) { for (const auto &protoLiteral : protoArray.literals()) { panda::pandasm::LiteralArray::Literal literal; @@ -116,14 +116,14 @@ void LiteralArray::Deserialize(const proto_panda::LiteralArray &protoArray, pand } } -void Literal::Serialize(const panda::pandasm::LiteralArray::Literal &literal, proto_panda::Literal &protoLiteral) +void Literal::Serialize(const panda::pandasm::LiteralArray::Literal &literal, protoPanda::Literal &protoLiteral) { protoLiteral.set_tag(static_cast(literal.tag_)); auto *value = protoLiteral.mutable_value(); VariantValue::Serialize(literal.value_, *value); } -void Literal::Deserialize(const proto_panda::Literal &protoLiteral, panda::pandasm::LiteralArray::Literal &literal) +void Literal::Deserialize(const protoPanda::Literal &protoLiteral, panda::pandasm::LiteralArray::Literal &literal) { literal.tag_ = static_cast(protoLiteral.tag()); VariantValue::Deserialize(protoLiteral.value(), literal.value_); diff --git a/merge_abc/src/assemblyLiteralsProto.h b/merge_abc/src/assemblyLiteralsProto.h index 14c58667d3..b5b21e7559 100644 --- a/merge_abc/src/assemblyLiteralsProto.h +++ b/merge_abc/src/assemblyLiteralsProto.h @@ -23,20 +23,20 @@ namespace panda::proto { class VariantValue { public: using LiteralValueType = std::variant; - static void Serialize(const LiteralValueType &value, proto_panda::VariantValue &protoValue); - static void Deserialize(const proto_panda::VariantValue &protoValue, LiteralValueType &value); + static void Serialize(const LiteralValueType &value, protoPanda::VariantValue &protoValue); + static void Deserialize(const protoPanda::VariantValue &protoValue, LiteralValueType &value); }; class LiteralArray { public: - static void Serialize(const panda::pandasm::LiteralArray &array, proto_panda::LiteralArray &protoArray); - static void Deserialize(const proto_panda::LiteralArray &protoArray, panda::pandasm::LiteralArray &array); + static void Serialize(const panda::pandasm::LiteralArray &array, protoPanda::LiteralArray &protoArray); + static void Deserialize(const protoPanda::LiteralArray &protoArray, panda::pandasm::LiteralArray &array); }; class Literal { public: - static void Serialize(const panda::pandasm::LiteralArray::Literal &literal, proto_panda::Literal &protoLiteral); - static void Deserialize(const proto_panda::Literal &protoLiteral, panda::pandasm::LiteralArray::Literal &literal); + static void Serialize(const panda::pandasm::LiteralArray::Literal &literal, protoPanda::Literal &protoLiteral); + static void Deserialize(const protoPanda::Literal &protoLiteral, panda::pandasm::LiteralArray::Literal &literal); }; } // panda::proto #endif diff --git a/merge_abc/src/assemblyProgramProto.cpp b/merge_abc/src/assemblyProgramProto.cpp index b396defe9b..e8658511ea 100644 --- a/merge_abc/src/assemblyProgramProto.cpp +++ b/merge_abc/src/assemblyProgramProto.cpp @@ -16,26 +16,26 @@ #include "assemblyProgramProto.h" namespace panda::proto { -void Program::Serialize(const panda::pandasm::Program &program, proto_panda::Program &protoProgram) +void Program::Serialize(const panda::pandasm::Program &program, protoPanda::Program &protoProgram) { protoProgram.set_lang(static_cast(program.lang)); for (const auto &[name, record] : program.record_table) { - auto *recordMap = protoProgram.add_record_table(); + auto *recordMap = protoProgram.add_recordtable(); recordMap->set_key(name); auto *protoRecord = recordMap->mutable_value(); Record::Serialize(record, *protoRecord); } for (const auto &[name, func] : program.function_table) { - auto *functionMap = protoProgram.add_function_table(); + auto *functionMap = protoProgram.add_functiontable(); functionMap->set_key(name); auto *protoFunc = functionMap->mutable_value(); Function::Serialize(func, *protoFunc); } for (const auto &[name, array] : program.literalarray_table) { - auto *literalarrayMap = protoProgram.add_literalarray_table(); + auto *literalarrayMap = protoProgram.add_literalarraytable(); literalarrayMap->set_key(name); auto *protoArray = literalarrayMap->mutable_value(); LiteralArray::Serialize(array, *protoArray); @@ -44,17 +44,17 @@ void Program::Serialize(const panda::pandasm::Program &program, proto_panda::Pro protoProgram.add_strings(str); } for (const auto &type : program.array_types) { - auto *protoType = protoProgram.add_array_types(); + auto *protoType = protoProgram.add_arraytypes(); Type::Serialize(type, *protoType); } } -void Program::Deserialize(const proto_panda::Program &protoProgram, panda::pandasm::Program &program, +void Program::Deserialize(const protoPanda::Program &protoProgram, panda::pandasm::Program &program, panda::ArenaAllocator *allocator) { program.lang = static_cast(protoProgram.lang()); - for (const auto &recordUnit : protoProgram.record_table()) { + for (const auto &recordUnit : protoProgram.recordtable()) { auto name = recordUnit.key(); auto protoRecord = recordUnit.value(); auto record = panda::pandasm::Record(protoRecord.name(), @@ -63,7 +63,7 @@ void Program::Deserialize(const proto_panda::Program &protoProgram, panda::panda program.record_table.insert({name, std::move(record)}); } - for (const auto &functionUnit : protoProgram.function_table()) { + for (const auto &functionUnit : protoProgram.functiontable()) { auto name = functionUnit.key(); auto protoFunction = functionUnit.value(); auto function = allocator->New(protoFunction.name(), @@ -72,7 +72,7 @@ void Program::Deserialize(const proto_panda::Program &protoProgram, panda::panda program.function_table.insert({name, std::move(*function)}); } - for (const auto &literalUnit : protoProgram.literalarray_table()) { + for (const auto &literalUnit : protoProgram.literalarraytable()) { auto name = literalUnit.key(); auto protoLiteralArray = literalUnit.value(); panda::pandasm::LiteralArray literalArray; @@ -84,7 +84,7 @@ void Program::Deserialize(const proto_panda::Program &protoProgram, panda::panda program.strings.insert(protoString); } - for (const auto &protoArrayType : protoProgram.array_types()) { + for (const auto &protoArrayType : protoProgram.arraytypes()) { auto arrayType = Type::Deserialize(protoArrayType, allocator); program.array_types.insert(std::move(arrayType)); } diff --git a/merge_abc/src/assemblyProgramProto.h b/merge_abc/src/assemblyProgramProto.h index 3f1d09d417..6942530ea4 100644 --- a/merge_abc/src/assemblyProgramProto.h +++ b/merge_abc/src/assemblyProgramProto.h @@ -26,8 +26,8 @@ namespace panda::proto { class Program { public: - static void Serialize(const panda::pandasm::Program &program, proto_panda::Program &protoProgram); - static void Deserialize(const proto_panda::Program &protoProgram, panda::pandasm::Program &program, + static void Serialize(const panda::pandasm::Program &program, protoPanda::Program &protoProgram); + static void Deserialize(const protoPanda::Program &protoProgram, panda::pandasm::Program &program, panda::ArenaAllocator *allocator); }; } // panda::proto diff --git a/merge_abc/src/assemblyRecordProto.cpp b/merge_abc/src/assemblyRecordProto.cpp index d43a87ec55..15e34a327f 100644 --- a/merge_abc/src/assemblyRecordProto.cpp +++ b/merge_abc/src/assemblyRecordProto.cpp @@ -16,7 +16,7 @@ #include "assemblyRecordProto.h" namespace panda::proto { -void Record::Serialize(const panda::pandasm::Record &record, proto_panda::Record &protoRecord) +void Record::Serialize(const panda::pandasm::Record &record, protoPanda::Record &protoRecord) { protoRecord.set_name(record.name); protoRecord.set_conflict(record.conflict); @@ -25,36 +25,36 @@ void Record::Serialize(const panda::pandasm::Record &record, proto_panda::Record RecordMetadata::Serialize(*record.metadata, *proto_record_meta); for (const auto &field : record.field_list) { - auto *proto_field = protoRecord.add_field_list(); + auto *proto_field = protoRecord.add_fieldlist(); Field::Serialize(field, *proto_field); } - protoRecord.set_params_num(record.params_num); - protoRecord.set_body_presence(record.body_presence); - protoRecord.set_source_file(record.source_file); + protoRecord.set_paramsnum(record.params_num); + protoRecord.set_bodypresence(record.body_presence); + protoRecord.set_sourcefile(record.source_file); const auto &location = record.file_location; if (location.has_value()) { - auto *proto_location = protoRecord.mutable_file_location(); + auto *proto_location = protoRecord.mutable_filelocation(); FileLocation::Serialize(location.value(), *proto_location); } } -void Record::Deserialize(const proto_panda::Record &protoRecord, panda::pandasm::Record &record, +void Record::Deserialize(const protoPanda::Record &protoRecord, panda::pandasm::Record &record, panda::ArenaAllocator *allocator) { record.conflict = protoRecord.conflict(); RecordMetadata::Deserialize(protoRecord.metadata(), record.metadata, allocator); - for (const auto &protoField : protoRecord.field_list()) { + for (const auto &protoField : protoRecord.fieldlist()) { auto recordField = panda::pandasm::Field(panda::panda_file::SourceLang::ECMASCRIPT); Field::Deserialize(protoField, recordField, allocator); record.field_list.emplace_back(std::move(recordField)); } - record.params_num = protoRecord.params_num(); - record.body_presence = protoRecord.body_presence(); - record.source_file = protoRecord.source_file(); - if (protoRecord.has_file_location()) { - const auto &protoLocation = protoRecord.file_location(); + record.params_num = protoRecord.paramsnum(); + record.body_presence = protoRecord.bodypresence(); + record.source_file = protoRecord.sourcefile(); + if (protoRecord.has_filelocation()) { + const auto &protoLocation = protoRecord.filelocation(); FileLocation::Deserialize(protoLocation, record.file_location.value()); } } diff --git a/merge_abc/src/assemblyRecordProto.h b/merge_abc/src/assemblyRecordProto.h index 4d197b7d88..19535c1252 100644 --- a/merge_abc/src/assemblyRecordProto.h +++ b/merge_abc/src/assemblyRecordProto.h @@ -25,8 +25,8 @@ namespace panda::proto { class Record { public: - static void Serialize(const panda::pandasm::Record &record, proto_panda::Record &protoRecord); - static void Deserialize(const proto_panda::Record &protoRecord, panda::pandasm::Record &record, + static void Serialize(const panda::pandasm::Record &record, protoPanda::Record &protoRecord); + static void Deserialize(const protoPanda::Record &protoRecord, panda::pandasm::Record &record, panda::ArenaAllocator *allocator); }; } // panda::proto diff --git a/merge_abc/src/assemblyTypeProto.cpp b/merge_abc/src/assemblyTypeProto.cpp index 6a47920006..eded41401c 100644 --- a/merge_abc/src/assemblyTypeProto.cpp +++ b/merge_abc/src/assemblyTypeProto.cpp @@ -16,18 +16,18 @@ #include "assemblyTypeProto.h" namespace panda::proto { -void Type::Serialize(const panda::pandasm::Type type, proto_panda::Type &protoType) +void Type::Serialize(const panda::pandasm::Type type, protoPanda::Type &protoType) { - protoType.set_component_name(type.GetComponentName()); + protoType.set_componentname(type.GetComponentName()); protoType.set_rank(type.GetRank()); protoType.set_name(type.GetName()); - protoType.set_type_id(static_cast(type.GetId())); + protoType.set_typeid_(static_cast(type.GetId())); } -panda::pandasm::Type &Type::Deserialize(const proto_panda::Type &protoType, +panda::pandasm::Type &Type::Deserialize(const protoPanda::Type &protoType, panda::ArenaAllocator *allocator) { - auto type = allocator->New(protoType.component_name(), protoType.rank()); + auto type = allocator->New(protoType.componentname(), protoType.rank()); return *type; } } // panda::proto diff --git a/merge_abc/src/assemblyTypeProto.h b/merge_abc/src/assemblyTypeProto.h index 864abe4990..661cc731c2 100644 --- a/merge_abc/src/assemblyTypeProto.h +++ b/merge_abc/src/assemblyTypeProto.h @@ -23,8 +23,8 @@ namespace panda::proto { class Type { public: - static void Serialize(const panda::pandasm::Type type, proto_panda::Type &protoType); - static panda::pandasm::Type &Deserialize(const proto_panda::Type &protoType, + static void Serialize(const panda::pandasm::Type type, protoPanda::Type &protoType); + static panda::pandasm::Type &Deserialize(const protoPanda::Type &protoType, panda::ArenaAllocator *allocator); }; } // panda::proto diff --git a/merge_abc/src/compositeProgramProto.cpp b/merge_abc/src/compositeProgramProto.cpp index 35afb80b87..47c9b09ff9 100644 --- a/merge_abc/src/compositeProgramProto.cpp +++ b/merge_abc/src/compositeProgramProto.cpp @@ -17,8 +17,8 @@ namespace panda::proto { -void CompositeProgram::Serialize(const panda::es2panda::util::CompositeProgramMap &compositeProgramMap, - proto_panda::CompositeProgram &protoCompositeProgram) +void CompositeProgram::Serialize(const panda::es2panda::util::CompositeProgram &compositeProgram, + protoPanda::CompositeProgram &protoCompositeProgram) { for (const auto &[fileName, hashProgram] : compositeProgramMap.compositeProgramInfo) { auto protoHashNameProgram = protoCompositeProgram.add_hashnameprogram(); @@ -29,7 +29,7 @@ void CompositeProgram::Serialize(const panda::es2panda::util::CompositeProgramMa } } -void CompositeProgram::Deserialize(const proto_panda::CompositeProgram &protoCompositeProgram, +void CompositeProgram::Deserialize(const protoPanda::CompositeProgram &protoCompositeProgram, panda::es2panda::util::CompositeProgramMap &compositeProgramMap, panda::ArenaAllocator *allocator) { diff --git a/merge_abc/src/compositeProgramProto.h b/merge_abc/src/compositeProgramProto.h index 8316285cf2..b1526f31e6 100644 --- a/merge_abc/src/compositeProgramProto.h +++ b/merge_abc/src/compositeProgramProto.h @@ -23,9 +23,9 @@ namespace panda::proto { class CompositeProgram { public: - static void Serialize(const panda::es2panda::util::CompositeProgramMap &compositeProgramMap, - proto_panda::CompositeProgram &protoCompositeProgram); - static void Deserialize(const proto_panda::CompositeProgram &protoCompositeProgram, + static void Serialize(const panda::es2panda::util::CompositeProgram &compositeProgram, + protoPanda::CompositeProgram &protoCompositeProgram); + static void Deserialize(const protoPanda::CompositeProgram &protoCompositeProgram, panda::es2panda::util::CompositeProgramMap &compositeProgramMap, panda::ArenaAllocator *allocator); }; diff --git a/merge_abc/src/ideHelpersProto.cpp b/merge_abc/src/ideHelpersProto.cpp index db595e8a0f..d4d5d7dbb1 100644 --- a/merge_abc/src/ideHelpersProto.cpp +++ b/merge_abc/src/ideHelpersProto.cpp @@ -17,7 +17,7 @@ namespace panda::proto { void SourceLocation::Serialize(const panda::pandasm::SourceLocation &location, - proto_panda::SourceLocation &protoLocation) + protoPanda::SourceLocation &protoLocation) { auto *protoBegin = protoLocation.mutable_begin(); SourcePosition::Serialize(location.begin, *protoBegin); @@ -25,7 +25,7 @@ void SourceLocation::Serialize(const panda::pandasm::SourceLocation &location, SourcePosition::Serialize(location.end, *protoEnd); } -void SourceLocation::Deserialize(const proto_panda::SourceLocation &protoLocation, +void SourceLocation::Deserialize(const protoPanda::SourceLocation &protoLocation, panda::pandasm::SourceLocation &location) { if (protoLocation.has_begin()) { @@ -37,13 +37,13 @@ void SourceLocation::Deserialize(const proto_panda::SourceLocation &protoLocatio } void SourcePosition::Serialize(const panda::pandasm::SourcePosition &position, - proto_panda::SourcePosition &protoPosition) + protoPanda::SourcePosition &protoPosition) { protoPosition.set_line(position.line); protoPosition.set_column(position.column); } -void SourcePosition::Deserialize(const proto_panda::SourcePosition &protoPosition, +void SourcePosition::Deserialize(const protoPanda::SourcePosition &protoPosition, panda::pandasm::SourcePosition &position) { position.line = protoPosition.line(); diff --git a/merge_abc/src/ideHelpersProto.h b/merge_abc/src/ideHelpersProto.h index 43d52d5c63..a6596b3c8f 100644 --- a/merge_abc/src/ideHelpersProto.h +++ b/merge_abc/src/ideHelpersProto.h @@ -23,15 +23,15 @@ namespace panda::proto { class SourceLocation { public: static void Serialize(const panda::pandasm::SourceLocation &location, - proto_panda::SourceLocation &protoLocation); - static void Deserialize(const proto_panda::SourceLocation &protoLocation, panda::pandasm::SourceLocation &location); + protoPanda::SourceLocation &protoLocation); + static void Deserialize(const protoPanda::SourceLocation &protoLocation, panda::pandasm::SourceLocation &location); }; class SourcePosition { public: static void Serialize(const panda::pandasm::SourcePosition &position, - proto_panda::SourcePosition &protoPosition); - static void Deserialize(const proto_panda::SourcePosition &protoPosition, panda::pandasm::SourcePosition &position); + protoPanda::SourcePosition &protoPosition); + static void Deserialize(const protoPanda::SourcePosition &protoPosition, panda::pandasm::SourcePosition &position); }; } // panda::proto #endif diff --git a/merge_abc/src/metaProto.cpp b/merge_abc/src/metaProto.cpp index 82e47bd3a7..75fb586355 100644 --- a/merge_abc/src/metaProto.cpp +++ b/merge_abc/src/metaProto.cpp @@ -15,13 +15,13 @@ #include "metaProto.h" namespace panda::proto { -void RecordMetadata::Serialize(const panda::pandasm::RecordMetadata &meta, proto_panda::RecordMetadata &protoMeta) +void RecordMetadata::Serialize(const panda::pandasm::RecordMetadata &meta, protoPanda::RecordMetadata &protoMeta) { auto *protoItemmetadata = protoMeta.mutable_father(); ItemMetadata::Serialize(static_cast(meta), *protoItemmetadata); } -void RecordMetadata::Deserialize(const proto_panda::RecordMetadata &protoMeta, +void RecordMetadata::Deserialize(const protoPanda::RecordMetadata &protoMeta, std::unique_ptr &meta, panda::ArenaAllocator *allocator) { @@ -36,13 +36,13 @@ void RecordMetadata::Deserialize(const proto_panda::RecordMetadata &protoMeta, } void FunctionMetadata::Serialize(const panda::pandasm::FunctionMetadata &meta, - proto_panda::FunctionMetadata &protoMeta) + protoPanda::FunctionMetadata &protoMeta) { auto *protoItemmetadata = protoMeta.mutable_father(); ItemMetadata::Serialize(static_cast(meta), *protoItemmetadata); } -void FunctionMetadata::Deserialize(const proto_panda::FunctionMetadata &protoMeta, +void FunctionMetadata::Deserialize(const protoPanda::FunctionMetadata &protoMeta, std::unique_ptr &meta, panda::ArenaAllocator *allocator) { @@ -56,11 +56,11 @@ void FunctionMetadata::Deserialize(const proto_panda::FunctionMetadata &protoMet Metadata::Deserialize(protoMetadata, *meta); } -void FieldMetadata::Serialize(const panda::pandasm::FieldMetadata &meta, proto_panda::FieldMetadata &protoMeta) +void FieldMetadata::Serialize(const panda::pandasm::FieldMetadata &meta, protoPanda::FieldMetadata &protoMeta) { auto *protoItemmetadata = protoMeta.mutable_father(); ItemMetadata::Serialize(meta, *protoItemmetadata); - auto *protoType = protoMeta.mutable_field_type(); + auto *protoType = protoMeta.mutable_fieldtype(); Type::Serialize(meta.GetFieldType(), *protoType); const auto val = meta.GetValue(); if (val.has_value()) { @@ -69,7 +69,7 @@ void FieldMetadata::Serialize(const panda::pandasm::FieldMetadata &meta, proto_p } } -void FieldMetadata::Deserialize(const proto_panda::FieldMetadata &protoMeta, +void FieldMetadata::Deserialize(const protoPanda::FieldMetadata &protoMeta, std::unique_ptr &meta, panda::ArenaAllocator *allocator) { @@ -80,7 +80,7 @@ void FieldMetadata::Deserialize(const proto_panda::FieldMetadata &protoMeta, auto protoMetadata = protoAnnoMetadata.father(); Metadata::Deserialize(protoMetadata, *meta); - auto fieldType = Type::Deserialize(protoMeta.field_type(), allocator); + auto fieldType = Type::Deserialize(protoMeta.fieldtype(), allocator); meta->SetFieldType(fieldType); ScalarValue scalarValue; if (protoMeta.has_value()) { @@ -89,13 +89,13 @@ void FieldMetadata::Deserialize(const proto_panda::FieldMetadata &protoMeta, } } -void ParamMetadata::Serialize(const panda::pandasm::ParamMetadata &meta, proto_panda::ParamMetadata &protoMeta) +void ParamMetadata::Serialize(const panda::pandasm::ParamMetadata &meta, protoPanda::ParamMetadata &protoMeta) { auto *protoAnnometadata = protoMeta.mutable_father(); AnnotationMetadata::Serialize(static_cast(meta), *protoAnnometadata); } -void ParamMetadata::Deserialize(const proto_panda::ParamMetadata &protoMeta, +void ParamMetadata::Deserialize(const protoPanda::ParamMetadata &protoMeta, std::unique_ptr &meta, panda::ArenaAllocator *allocator) { @@ -103,20 +103,20 @@ void ParamMetadata::Deserialize(const proto_panda::ParamMetadata &protoMeta, AnnotationMetadata::Deserialize(protoAnnoMetadata, *meta, allocator); } -void ItemMetadata::Serialize(const panda::pandasm::ItemMetadata &meta, proto_panda::ItemMetadata &protoMeta) +void ItemMetadata::Serialize(const panda::pandasm::ItemMetadata &meta, protoPanda::ItemMetadata &protoMeta) { auto *protoAnnometadata = protoMeta.mutable_father(); AnnotationMetadata::Serialize(static_cast(meta), *protoAnnometadata); - protoMeta.set_access_flags(meta.GetAccessFlags()); + protoMeta.set_accessflags(meta.GetAccessFlags()); } -void ItemMetadata::Deserialize(const proto_panda::ItemMetadata &protoMeta, panda::pandasm::ItemMetadata &meta) +void ItemMetadata::Deserialize(const protoPanda::ItemMetadata &protoMeta, panda::pandasm::ItemMetadata &meta) { - meta.SetAccessFlags(protoMeta.access_flags()); + meta.SetAccessFlags(protoMeta.accessflags()); } void AnnotationMetadata::Serialize(const panda::pandasm::AnnotationMetadata &meta, - proto_panda::AnnotationMetadata &protoMeta) + protoPanda::AnnotationMetadata &protoMeta) { auto *protoMetadata = protoMeta.mutable_father(); Metadata::Serialize(static_cast(meta), *protoMetadata); @@ -126,20 +126,20 @@ void AnnotationMetadata::Serialize(const panda::pandasm::AnnotationMetadata &met } } -void AnnotationMetadata::Deserialize(const proto_panda::AnnotationMetadata &protoMeta, +void AnnotationMetadata::Deserialize(const protoPanda::AnnotationMetadata &protoMeta, panda::pandasm::AnnotationMetadata &meta, panda::ArenaAllocator *allocator) { std::vector annotations; for (const auto &protoAnnotation : protoMeta.annotations()) { - auto annotation = allocator->New(protoAnnotation.record_name()); + auto annotation = allocator->New(protoAnnotation.recordname()); AnnotationData::Deserialize(protoAnnotation, *annotation, allocator); annotations.emplace_back(std::move(*annotation)); } meta.AddAnnotations(annotations); } -void Metadata::Serialize(const panda::pandasm::Metadata &meta, proto_panda::Metadata &protoMeta) +void Metadata::Serialize(const panda::pandasm::Metadata &meta, protoPanda::Metadata &protoMeta) { for (const auto &attr : meta.GetBoolAttributes()) { protoMeta.add_set_attributes(attr); @@ -153,7 +153,7 @@ void Metadata::Serialize(const panda::pandasm::Metadata &meta, proto_panda::Meta } } -void Metadata::Deserialize(const proto_panda::Metadata &protoMeta, panda::pandasm::Metadata &meta) +void Metadata::Deserialize(const protoPanda::Metadata &protoMeta, panda::pandasm::Metadata &meta) { for (const auto &attr : protoMeta.set_attributes()) { meta.SetAttribute(attr); diff --git a/merge_abc/src/metaProto.h b/merge_abc/src/metaProto.h index 1761fa07a1..c3baeacd09 100644 --- a/merge_abc/src/metaProto.h +++ b/merge_abc/src/metaProto.h @@ -25,8 +25,8 @@ namespace panda::proto { class RecordMetadata { public: - static void Serialize(const panda::pandasm::RecordMetadata &meta, proto_panda::RecordMetadata &protoMeta); - static void Deserialize(const proto_panda::RecordMetadata &protoMeta, + static void Serialize(const panda::pandasm::RecordMetadata &meta, protoPanda::RecordMetadata &protoMeta); + static void Deserialize(const protoPanda::RecordMetadata &protoMeta, std::unique_ptr &meta, panda::ArenaAllocator *allocator); }; @@ -34,46 +34,46 @@ public: class FunctionMetadata { public: static void Serialize(const panda::pandasm::FunctionMetadata &meta, - proto_panda::FunctionMetadata &protoMeta); - static void Deserialize(const proto_panda::FunctionMetadata &protoMeta, + protoPanda::FunctionMetadata &protoMeta); + static void Deserialize(const protoPanda::FunctionMetadata &protoMeta, std::unique_ptr &meta, panda::ArenaAllocator *allocator); }; class FieldMetadata { public: - static void Serialize(const panda::pandasm::FieldMetadata &meta, proto_panda::FieldMetadata &protoMeta); - static void Deserialize(const proto_panda::FieldMetadata &protoMeta, + static void Serialize(const panda::pandasm::FieldMetadata &meta, protoPanda::FieldMetadata &protoMeta); + static void Deserialize(const protoPanda::FieldMetadata &protoMeta, std::unique_ptr &meta, panda::ArenaAllocator *allocator); }; class ParamMetadata { public: - static void Serialize(const panda::pandasm::ParamMetadata &meta, proto_panda::ParamMetadata &protoMeta); - static void Deserialize(const proto_panda::ParamMetadata &protoMeta, + static void Serialize(const panda::pandasm::ParamMetadata &meta, protoPanda::ParamMetadata &protoMeta); + static void Deserialize(const protoPanda::ParamMetadata &protoMeta, std::unique_ptr &meta, panda::ArenaAllocator *allocator); }; class ItemMetadata { public: - static void Serialize(const panda::pandasm::ItemMetadata &meta, proto_panda::ItemMetadata &protoMeta); - static void Deserialize(const proto_panda::ItemMetadata &protoMeta, panda::pandasm::ItemMetadata &meta); + static void Serialize(const panda::pandasm::ItemMetadata &meta, protoPanda::ItemMetadata &protoMeta); + static void Deserialize(const protoPanda::ItemMetadata &protoMeta, panda::pandasm::ItemMetadata &meta); }; class AnnotationMetadata { public: static void Serialize(const panda::pandasm::AnnotationMetadata &meta, - proto_panda::AnnotationMetadata &protoMeta); - static void Deserialize(const proto_panda::AnnotationMetadata &protoMeta, panda::pandasm::AnnotationMetadata &meta, + protoPanda::AnnotationMetadata &protoMeta); + static void Deserialize(const protoPanda::AnnotationMetadata &protoMeta, panda::pandasm::AnnotationMetadata &meta, panda::ArenaAllocator *allocator); }; class Metadata { public: - static void Serialize(const panda::pandasm::Metadata &meta, proto_panda::Metadata &protoMeta); - static void Deserialize(const proto_panda::Metadata &protoMeta, panda::pandasm::Metadata &meta); + static void Serialize(const panda::pandasm::Metadata &meta, protoPanda::Metadata &protoMeta); + static void Deserialize(const protoPanda::Metadata &protoMeta, panda::pandasm::Metadata &meta); }; } // panda::proto #endif diff --git a/merge_abc/src/protobufSnapshotGenerator.cpp b/merge_abc/src/protobufSnapshotGenerator.cpp index 9415ad3da0..f50988ff86 100644 --- a/merge_abc/src/protobufSnapshotGenerator.cpp +++ b/merge_abc/src/protobufSnapshotGenerator.cpp @@ -20,7 +20,7 @@ namespace panda::proto { void ProtobufSnapshotGenerator::GenerateSnapshot(const panda::pandasm::Program &program, const std::string &outputName) { - proto_panda::Program protoProgram; + protoPanda::Program protoProgram; Program::Serialize(program, protoProgram); @@ -41,7 +41,7 @@ void ProtobufSnapshotGenerator::GenerateProgram(const std::string &inputName, pa std::cerr << "Failed to open " << inputName << std::endl; return; } - proto_panda::Program proto_program; + protoPanda::Program proto_program; if (!proto_program.ParseFromIstream(&input)) { std::cerr << "Failed to parse " << inputName << std::endl; return; @@ -52,8 +52,8 @@ void ProtobufSnapshotGenerator::GenerateProgram(const std::string &inputName, pa void ProtobufSnapshotGenerator::UpdateCacheFile(panda::es2panda::util::CompositeProgramMap compositeProgramMap, const std::string &cacheFilePath) { - proto_panda::CompositeProgram protoCompositeProgram; - CompositeProgram::Serialize(compositeProgramMap, protoCompositeProgram); + protoPanda::CompositeProgram protoCompositeProgram; + CompositeProgram::Serialize(compositeProgram, protoCompositeProgram); std::fstream output(cacheFilePath, std::ios::out | std::ios::trunc | std::ios::binary); if (!output) { std::cout << "Fail to create cache file: " << cacheFilePath << std::endl; @@ -71,7 +71,7 @@ panda::es2panda::util::CompositeProgramMap *ProtobufSnapshotGenerator::GetCacheC std::cerr << "Failed to open cache file: " << cacheFilePath << std::endl; return nullptr; } - proto_panda::CompositeProgram protoCompositeProgram; + protoPanda::CompositeProgram protoCompositeProgram; if (!protoCompositeProgram.ParseFromIstream(&input)) { std::cerr << "Failed to parse cache file: " << cacheFilePath << std::endl; return nullptr; -- Gitee From 5600c30d53eb30b816899165f266448847c8ad4e Mon Sep 17 00:00:00 2001 From: hufeng Date: Sun, 28 Aug 2022 14:47:55 +0800 Subject: [PATCH 17/23] Change TYPEINDEX to LITERALBUFFERINDEX Signed-off-by: hufeng Change-Id: Ied63e2681f899cf6aa1a6b8c98c5316f96a0ea3d --- es2panda/compiler/core/emitter/emitter.cpp | 5 ++++ es2panda/ir/expressions/literal.h | 2 +- ts2panda/src/base/literal.ts | 2 +- ts2panda/src/base/typeSystem.ts | 30 +++++++++++----------- ts2panda/ts2abc/ts2abc.cpp | 4 +-- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index e03ee13bbf..7349cd73f9 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -123,6 +123,11 @@ void FunctionEmitter::GenBufferLiterals(const LiteralBuffer *buff) valueLit.value_ = literal->GetMethod().Mutf8(); break; } + case ir::LiteralTag::LITERALBUFFERINDEX: { + valueLit.tag_ = panda::panda_file::LiteralTag::LITERALBUFFERINDEX; + valueLit.value_ = literal->GetInt(); + break; + } // TODO: support ir::LiteralTag::ASYNC_GENERATOR_METHOD case ir::LiteralTag::NULL_VALUE: { valueLit.tag_ = panda::panda_file::LiteralTag::NULLVALUE; diff --git a/es2panda/ir/expressions/literal.h b/es2panda/ir/expressions/literal.h index 86c3256f5b..57c76603b3 100644 --- a/es2panda/ir/expressions/literal.h +++ b/es2panda/ir/expressions/literal.h @@ -43,7 +43,7 @@ enum class LiteralTag { METHODAFFILIATE, // 0x0a - 0x15 for ARRAY_Type ASYNC_GENERATOR_METHOD = 22, - TYPEINDEX = 23, + LITERALBUFFERINDEX = 23, NULL_VALUE = 255, }; diff --git a/ts2panda/src/base/literal.ts b/ts2panda/src/base/literal.ts index 79c1c0169a..50d7c9d52c 100644 --- a/ts2panda/src/base/literal.ts +++ b/ts2panda/src/base/literal.ts @@ -24,7 +24,7 @@ export enum LiteralTag { METHODAFFILIATE = 9, // 0x0a - 0x15 for ARRAY_Type ASYNCGENERATOR = 22, - TYPEINDEX = 23, + LITERALBUFFERINDEX = 23, NULLVALUE = 255 } diff --git a/ts2panda/src/base/typeSystem.ts b/ts2panda/src/base/typeSystem.ts index a4fa806c5b..0167dfe2dd 100644 --- a/ts2panda/src/base/typeSystem.ts +++ b/ts2panda/src/base/typeSystem.ts @@ -407,7 +407,7 @@ export class ClassType extends BaseType { classTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.extendsHeritage)); classTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.implementsHeritages.length)); this.implementsHeritages.forEach(heritage => { - classTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, heritage)); + classTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, heritage)); }); // record unstatic fields and methods @@ -428,7 +428,7 @@ export class ClassType extends BaseType { classTypeLiterals.push(new Literal(LiteralTag.INTEGER, transferredTarget.size)); transferredTarget.forEach((typeInfo, name) => { classTypeLiterals.push(new Literal(LiteralTag.STRING, name)); - classTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, typeInfo[0])); // typeIndex + classTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, typeInfo[0])); // typeIndex classTypeLiterals.push(new Literal(LiteralTag.INTEGER, typeInfo[1])); // accessFlag classTypeLiterals.push(new Literal(LiteralTag.INTEGER, typeInfo[2])); // readonly }); @@ -440,7 +440,7 @@ export class ClassType extends BaseType { classTypeLiterals.push(new Literal(LiteralTag.INTEGER, transferredTarget.size)); transferredTarget.forEach((typeInfo, name) => { classTypeLiterals.push(new Literal(LiteralTag.STRING, name)); - classTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, typeInfo)); + classTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, typeInfo)); }); } } @@ -462,7 +462,7 @@ export class ClassInstType extends BaseType { let classInstLiterals: Array = new Array(); classInstLiterals.push(new Literal(LiteralTag.INTEGER, L2Type.CLASSINST)); - classInstLiterals.push(new Literal(LiteralTag.TYPEINDEX, this.shiftedReferredClassIndex)); + classInstLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, this.shiftedReferredClassIndex)); classInstBuf.addLiterals(...classInstLiterals); return classInstBuf; @@ -570,17 +570,17 @@ export class FunctionType extends BaseType { funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.parameters[0])); funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.parameters.length - 1)); for (let i = 1; i < this.parameters.length; i++) { - funcTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, this.parameters[i])); + funcTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, this.parameters[i])); } } else { funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, 0)); // marker for not having 'this' param funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.parameters.length)); for (let i = 0; i < this.parameters.length; i++) { - funcTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, this.parameters[i])); + funcTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, this.parameters[i])); } } - funcTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, this.returnType)); + funcTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, this.returnType)); funcTypeBuf.addLiterals(...funcTypeLiterals); return funcTypeBuf; } @@ -657,7 +657,7 @@ export class UnionType extends BaseType { UnionTypeLiterals.push(new Literal(LiteralTag.INTEGER, L2Type.UNION)); UnionTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.unionedTypeArray.length)); for (let type of this.unionedTypeArray) { - UnionTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, type)); + UnionTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, type)); } UnionTypeBuf.addLiterals(...UnionTypeLiterals); return UnionTypeBuf; @@ -702,7 +702,7 @@ export class ArrayType extends BaseType { let arrayBuf = new LiteralBuffer(); let arrayLiterals: Array = new Array(); arrayLiterals.push(new Literal(LiteralTag.INTEGER, L2Type.ARRAY)); - arrayLiterals.push(new Literal(LiteralTag.TYPEINDEX, this.referedTypeIndex)); + arrayLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, this.referedTypeIndex)); arrayBuf.addLiterals(...arrayLiterals); return arrayBuf; } @@ -737,7 +737,7 @@ export class ObjectType extends BaseType { objLiterals.push(new Literal(LiteralTag.INTEGER, this.properties.size)); this.properties.forEach((typeIndex, name) => { objLiterals.push(new Literal(LiteralTag.STRING, name)); - objLiterals.push(new Literal(LiteralTag.TYPEINDEX, typeIndex)); + objLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, typeIndex)); }); objTypeBuf.addLiterals(...objLiterals); return objTypeBuf; @@ -847,7 +847,7 @@ export class InterfaceType extends BaseType { interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.heritages.length)); this.heritages.forEach(heritage => { - interfaceTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, heritage)); + interfaceTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, heritage)); }); // record fields and methods @@ -864,7 +864,7 @@ export class InterfaceType extends BaseType { interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, transferredTarget.size)); transferredTarget.forEach((typeInfo, name) => { interfaceTypeLiterals.push(new Literal(LiteralTag.STRING, name)); - interfaceTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, typeInfo[0])); // typeIndex + interfaceTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, typeInfo[0])); // typeIndex interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, typeInfo[1])); // accessFlag interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, typeInfo[2])); // readonly }); @@ -875,7 +875,7 @@ export class InterfaceType extends BaseType { interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, transferredTarget.length)); transferredTarget.forEach(method => { - interfaceTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, method)); + interfaceTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, method)); }); } } @@ -904,10 +904,10 @@ export class BuiltinContainerType extends BaseType { let UnionTypeBuf = new LiteralBuffer(); let UnionTypeLiterals: Array = new Array(); UnionTypeLiterals.push(new Literal(LiteralTag.INTEGER, L2Type.BUILTINCONTAINER)); - UnionTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, this.builtinTypeIndex)); + UnionTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, this.builtinTypeIndex)); UnionTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.containerArray.length)); for (let type of this.containerArray) { - UnionTypeLiterals.push(new Literal(LiteralTag.TYPEINDEX, type)); + UnionTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, type)); } UnionTypeBuf.addLiterals(...UnionTypeLiterals); return UnionTypeBuf; diff --git a/ts2panda/ts2abc/ts2abc.cpp b/ts2panda/ts2abc/ts2abc.cpp index 4a236df478..f47ac2a8fb 100644 --- a/ts2panda/ts2abc/ts2abc.cpp +++ b/ts2panda/ts2abc/ts2abc.cpp @@ -265,8 +265,8 @@ static void ParseLiteral(const Json::Value &literal, std::vector(literal["v"].asUInt()); break; } - case static_cast(panda::panda_file::LiteralTag::TYPEINDEX): { - valueLiteral.tag_ = panda::panda_file::LiteralTag::TYPEINDEX; + case static_cast(panda::panda_file::LiteralTag::LITERALBUFFERINDEX): { + valueLiteral.tag_ = panda::panda_file::LiteralTag::LITERALBUFFERINDEX; valueLiteral.value_ = static_cast(literal["v"].asInt()); break; } -- Gitee From 999689a1632c84400217f31fb9bb1ceaef7a1f86 Mon Sep 17 00:00:00 2001 From: chenqy930 Date: Sun, 28 Aug 2022 15:52:28 +0800 Subject: [PATCH 18/23] Support compile multi files Signed-off-by: chenqy930 Change-Id: Icd437776c65631298a15965fac82433501046a3d --- es2panda/BUILD.gn | 1 + es2panda/aot/main.cpp | 66 ++++-- es2panda/aot/options.cpp | 214 +++++++++++++----- es2panda/aot/options.h | 35 ++- es2panda/compiler/core/compileQueue.cpp | 97 ++++++-- es2panda/compiler/core/compileQueue.h | 78 ++++++- es2panda/compiler/core/compilerImpl.cpp | 15 +- es2panda/compiler/core/compilerImpl.h | 9 +- es2panda/compiler/core/emitter/emitter.cpp | 4 + es2panda/es2panda.cpp | 113 ++++++++- es2panda/es2panda.h | 32 ++- es2panda/util/moduleHelpers.cpp | 72 ++++++ es2panda/util/moduleHelpers.h | 36 +++ .../{compositeHelpers.h => programCache.h} | 12 +- merge_abc/protos/compositeProgram.proto | 5 +- merge_abc/src/compositeProgramProto.cpp | 35 +-- merge_abc/src/compositeProgramProto.h | 11 +- merge_abc/src/mergeProgram.cpp | 10 +- merge_abc/src/mergeProgram.h | 6 +- merge_abc/src/protobufSnapshotGenerator.cpp | 15 +- merge_abc/src/protobufSnapshotGenerator.h | 9 +- 21 files changed, 688 insertions(+), 187 deletions(-) create mode 100644 es2panda/util/moduleHelpers.cpp create mode 100644 es2panda/util/moduleHelpers.h rename es2panda/util/{compositeHelpers.h => programCache.h} (71%) diff --git a/es2panda/BUILD.gn b/es2panda/BUILD.gn index a67ebbd94c..d39a5f7f13 100644 --- a/es2panda/BUILD.gn +++ b/es2panda/BUILD.gn @@ -239,6 +239,7 @@ es2panda_src = [ "util/bitset.cpp", "util/dumper.cpp", "util/helpers.cpp", + "util/moduleHelpers.cpp", "util/ustring.cpp", ] diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index 581c99141d..ce5c3aea30 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include #include @@ -89,12 +91,35 @@ static void DumpPandaFileSizeStatistic(std::map &stat) std::cout << "total: " << totalSize << std::endl; } -static int GenerateProgram(panda::pandasm::Program *prog, std::unique_ptr &options) +static int GenerateProgram(std::vector &progs, std::unique_ptr &options) { const std::string output = options->CompilerOutput(); + + if (progs.size() == 0) { + std::cerr << "Failed to generate program " << std::endl; + return 1; + } + + // std::cout << "progs.sizezzzzzzz()" << progs.size() << std::endl; + // int index = 0; + // for (auto *prog: progs) { + // std::cout << "prog " << index++ << std::endl; + // es2panda::Compiler::DumpAsm(prog); + // } + + if (progs.size() > 1) { + if (!panda::pandasm::AsmEmitter::EmitPrograms(output, progs, true)) { + std::cerr << "Failed to emit merged program " << std::endl; + return 1; + } + return 0; + } + + auto *prog = progs[0]; 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 {}; @@ -125,15 +150,15 @@ static int GenerateProgram(panda::pandasm::Program *prog, std::unique_ptrcompilerProtoOutput().size() > 0) { panda::proto::ProtobufSnapshotGenerator::GenerateSnapshot(*prog, options->compilerProtoOutput()); return 0; } - if (!panda::pandasm::AsmEmitter::Emit(output, *prog, statp, mapsp, true)) { - return 1; - } - if (compilerOptions.dumpLiteralBuffer) { panda::es2panda::util::Dumper::DumpLiterals(prog->literalarray_table); } @@ -154,28 +179,29 @@ int Run(int argc, const char **argv) return 1; } - es2panda::Compiler compiler(options->Extension(), options->ThreadCount()); - es2panda::SourceFile input(options->SourceFile(), options->ParserInput(), - options->RecordName(), options->ScriptKind()); + std::vector programs; + std::unordered_map programsInfo; + panda::ArenaAllocator allocator(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true); - auto *program = compiler.Compile(input, options->CompilerOptions()); + std::unordered_map *cachePrograms = nullptr; + bool isCacheHasDebugInfo = false; + if (!options->CacheFile().empty()) { + cachePrograms = proto::ProtobufSnapshotGenerator::GetCacheContext(options->CacheFile(), isCacheHasDebugInfo, &allocator); + } - if (!program) { - const auto &err = compiler.GetError(); + Compiler::CompileFiles(options->CompilerOptions(), cachePrograms, programs, programsInfo, &allocator, isCacheHasDebugInfo); - if (err.Message().empty() && options->ParseOnly()) { - return 0; - } + if (!options->NpmModuleEntryList().empty()) { + es2panda::util::ModuleHelpers::CompileNpmModuleEntryList(options->NpmModuleEntryList(), cachePrograms, + programs, programsInfo, &allocator); + } - std::cerr << err.TypeString() << ": " << err.Message(); - std::cerr << " [" << options->SourceFile() << ":" << err.Line() << ":" << err.Col() << "]" << std::endl; + GenerateProgram(programs, options); - return err.ErrorCode(); + if (!options->CacheFile().empty()) { + proto::ProtobufSnapshotGenerator::UpdateCacheFile(programsInfo, options->CompilerOptions().isDebug, options->CacheFile()); } - GenerateProgram(program, options); - delete program; - return 0; } diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index c19852724e..b9d41e888f 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -20,10 +20,20 @@ #include #include +#include "mergeProgram.h" +#include +#include "os/file.h" + +#if defined(PANDA_TARGET_WINDOWS) +#include +#else +#include +#endif + namespace panda::es2panda::aot { template -T BaseName(T const &path, T const &delims = "/") +T BaseName(T const &path, T const &delims = std::string(panda::os::file::File::GetPathDelim())) { return path.substr(path.find_last_of(delims) + 1); } @@ -35,8 +45,73 @@ T RemoveExtension(T const &filename) return P > 0 && P != T::npos ? filename.substr(0, P) : filename; } -// Options +static std::vector GetStringItems(std::string &input, const std::string &delimiter) +{ + std::vector items; + size_t pos = 0; + std::string token; + while ((pos = input.find(delimiter)) != std::string::npos) { + token = input.substr(0, pos); + if (!token.empty()) { + items.push_back(token); + } + input.erase(0, pos + delimiter.length()); + } + if (!input.empty()) { + items.push_back(input); + } + return items; +} + +bool Options::CollectInputFilesFromFileList(const std::string &input) +{ + std::ifstream ifs; + std::string line; + ifs.open(input.c_str()); + if (!ifs.is_open()) { + std::cerr << "Failed to open source list: " << input << std::endl; + return false; + } + + while (std::getline(ifs, line)) { + const std::string seperator = ";"; + std::vector itemList = GetStringItems(line, seperator); + if (itemList.size() != 3) { + std::cerr << "Failed to parse input file" << std::endl; + return false; + } + std::string fileName = itemList[0]; + std::string recordName = itemList[1]; + parser::ScriptKind scriptKind; + if (itemList[2] == "script") { + scriptKind = parser::ScriptKind::SCRIPT; + } else if (itemList[2] == "commonjs") { + scriptKind = parser::ScriptKind::COMMONJS; + } else { + scriptKind = parser::ScriptKind::MODULE; + } + + es2panda::SourceFile src(fileName, recordName, scriptKind); + sourceFiles_.push_back(src); + } + return true; +} + +bool Options::CollectInputFilesFromFileDirectory(const std::string &input, const std::string &extension) +{ + std::vector files; + if (!proto::MergeProgram::GetProtoFiles(input, extension, files)) { + return false; + } + for (auto &f : files) { + es2panda::SourceFile src(f, BaseName(f), scriptKind_); + sourceFiles_.push_back(src); + } + + return true; +} +// Options Options::Options() : argparser_(new panda::PandArgParser()) {} Options::~Options() @@ -62,7 +137,8 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg opDebugInfo("debug-info", false, "Compile with debug info"); panda::PandArg opDumpDebugInfo("dump-debug-info", false, "Dump debug info"); panda::PandArg opOptLevel("opt-level", 0, "Compiler optimization level (options: 0 | 1 | 2)"); - panda::PandArg opThreadCount("thread", 0, "Number of worker theads"); + panda::PandArg opFunctionThreadCount("function-threads", 0, "Number of worker threads to compile function"); + panda::PandArg opFileThreadCount("file-threads", 0, "Number of worker threads to compile file"); 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)"); @@ -74,6 +150,8 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg sourceFile("source-file", "", "specify the file path info recorded in generated abc"); panda::PandArg outputProto("outputProto", "", "compiler proto serialize binary output (.proto)"); + panda::PandArg opCacheFile("cache-file", "", "cache file for incremental compile"); + panda::PandArg opNpmModuleEntryList("npm-module-entry-list", "", "entry list file for module compile"); // tail arguments panda::PandArg inputFile("input", "", "input file"); @@ -92,7 +170,8 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&base64Output); argparser_->Add(&opOptLevel); - argparser_->Add(&opThreadCount); + argparser_->Add(&opFunctionThreadCount); + argparser_->Add(&opFileThreadCount); argparser_->Add(&opSizeStat); argparser_->Add(&opDumpLiteralBuffer); @@ -101,13 +180,14 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&sourceFile); argparser_->Add(&recordName); argparser_->Add(&outputProto); + argparser_->Add(&opCacheFile); + argparser_->Add(&opNpmModuleEntryList); argparser_->PushBackTail(&inputFile); argparser_->EnableTail(); argparser_->EnableRemainder(); - if (!argparser_->Parse(argc, argv) || opHelp.GetValue() || (inputFile.GetValue().empty() - && base64Input.GetValue().empty())) { + if (!argparser_->Parse(argc, argv) || opHelp.GetValue() || (inputFile.GetValue().empty() && base64Input.GetValue().empty())) { std::stringstream ss; ss << argparser_->GetErrorString() << std::endl; @@ -136,50 +216,20 @@ bool Options::Parse(int argc, const char **argv) return false; } - if (!inputIsEmpty) { - // in common mode: passed argument is js file path - sourceFile_ = inputFile.GetValue(); - std::ifstream inputStream(sourceFile_.c_str()); - - if (inputStream.fail()) { - errorMsg_ = "Failed to open file: "; - errorMsg_.append(sourceFile_); - return false; - } - - std::stringstream ss; - ss << inputStream.rdbuf(); - parserInput_ = ss.str(); - - sourceFile_ = BaseName(sourceFile_); - } else { - // input content is base64 string - parserInput_ = ExtractContentFromBase64Input(base64Input.GetValue()); - if (parserInput_.empty()) { - errorMsg_ = "The input string is not a valid base64 data"; - return false; - } - } - - if (base64Output.GetValue()) { - compilerOutput_ = ""; - } else if (!outputIsEmpty) { - compilerOutput_ = outputFile.GetValue(); - } else if (outputIsEmpty && !inputIsEmpty) { - compilerOutput_ = RemoveExtension(sourceFile_).append(".abc"); - } - - recordName_ = recordName.GetValue(); - if (recordName_.empty()) { - recordName_ = compilerOutput_.empty() ? "Base64Output" : RemoveExtension(BaseName(compilerOutput_)); + if (opModule.GetValue() && opCommonjs.GetValue()) { + errorMsg_ = "[--module] and [--commonjs] can not be used simultaneously"; + return false; } - if (!outputProto.GetValue().empty()) { - compilerProtoOutput_ = outputProto.GetValue(); + if (opModule.GetValue()) { + scriptKind_ = es2panda::parser::ScriptKind::MODULE; + } else if (opCommonjs.GetValue()) { + scriptKind_ = es2panda::parser::ScriptKind::COMMONJS; + } else { + scriptKind_ = es2panda::parser::ScriptKind::SCRIPT; } std::string extension = inputExtension.GetValue(); - if (!extension.empty()) { if (extension == "js") { extension_ = es2panda::ScriptExtension::JS; @@ -193,24 +243,69 @@ bool Options::Parse(int argc, const char **argv) } } - optLevel_ = opOptLevel.GetValue(); - threadCount_ = opThreadCount.GetValue(); + bool isInputFileList = false; + if (!inputIsEmpty) { + std::string rawInput = inputFile.GetValue(); + isInputFileList = rawInput[0] == '@'; + std::string input = isInputFileList ? rawInput.substr(1) : rawInput; + sourceFile_ = input; + } - if (opParseOnly.GetValue()) { - options_ |= OptionFlags::PARSE_ONLY; + if (base64Output.GetValue()) { + compilerOutput_ = ""; + } else if (!outputIsEmpty) { + compilerOutput_ = outputFile.GetValue(); + } else if (outputIsEmpty && !inputIsEmpty) { + compilerOutput_ = RemoveExtension(BaseName(sourceFile_)).append(".abc"); } - if (opModule.GetValue() && opCommonjs.GetValue()) { - errorMsg_ = "[--module] and [--commonjs] can not be used simultaneously"; - return false; + if (!inputIsEmpty) { + // common mode + auto inputAbs = panda::os::file::File::GetAbsolutePath(sourceFile_); + if (!inputAbs) { + std::cerr << "Failed to find: " << sourceFile_ << std::endl; + return false; + } + + auto fpath = inputAbs.Value(); + if (isInputFileList) { + CollectInputFilesFromFileList(fpath); + } else if (panda::os::file::File::IsDirectory(fpath)) { + CollectInputFilesFromFileDirectory(fpath, extension); + } else { + recordName_ = recordName.GetValue(); + if (recordName_.empty()) { + recordName_ = RemoveExtension(BaseName(compilerOutput_)); + } + + es2panda::SourceFile src(sourceFile_, recordName_, scriptKind_); + sourceFiles_.push_back(src); + } + } else if (!base64InputIsEmpty) { + // input content is base64 string + base64Input_ = ExtractContentFromBase64Input(base64Input.GetValue()); + if (base64Input_.empty()) { + errorMsg_ = "The input string is not a valid base64 data"; + return false; + } + + es2panda::SourceFile src("", "Base64Output", es2panda::parser::ScriptKind::SCRIPT); + src.source = base64Input_; + sourceFiles_.push_back(src); } - if (opModule.GetValue()) { - scriptKind_ = es2panda::parser::ScriptKind::MODULE; + if (!outputProto.GetValue().empty()) { + compilerProtoOutput_ = outputProto.GetValue(); } - if (opCommonjs.GetValue()) { - scriptKind_ = es2panda::parser::ScriptKind::COMMONJS; + optLevel_ = opOptLevel.GetValue(); + functionThreadCount_ = opFunctionThreadCount.GetValue(); + fileThreadCount_ = opFileThreadCount.GetValue(); + npmModuleEntryList_ = opNpmModuleEntryList.GetValue(); + cacheFile_ = opCacheFile.GetValue(); + + if (opParseOnly.GetValue()) { + options_ |= OptionFlags::PARSE_ONLY; } if (opSizeStat.GetValue()) { @@ -225,7 +320,12 @@ bool Options::Parse(int argc, const char **argv) compilerOptions_.enableTypeCheck = opEnableTypeCheck.GetValue(); compilerOptions_.dumpLiteralBuffer = opDumpLiteralBuffer.GetValue(); compilerOptions_.isDebuggerEvaluateExpressionMode = debuggerEvaluateExpression.GetValue(); - compilerOptions_.sourceFile = sourceFile.GetValue(); + + compilerOptions_.extension = extension_; + compilerOptions_.functionThreadCount = functionThreadCount_; + compilerOptions_.fileThreadCount = fileThreadCount_; + compilerOptions_.debugSourceFile = sourceFile.GetValue(); + compilerOptions_.sourceFiles = sourceFiles_; return true; } diff --git a/es2panda/aot/options.h b/es2panda/aot/options.h index 4cbef85454..a5eef1d533 100644 --- a/es2panda/aot/options.h +++ b/es2panda/aot/options.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -71,14 +72,14 @@ public: return compilerOptions_; } - es2panda::parser::ScriptKind ScriptKind() const + es2panda::CompilerOptions &CompilerOptions() { - return scriptKind_; + return compilerOptions_; } - const std::string &ParserInput() const + es2panda::parser::ScriptKind ScriptKind() const { - return parserInput_; + return scriptKind_; } const std::string &CompilerOutput() const @@ -106,11 +107,6 @@ public: return optLevel_; } - int ThreadCount() const - { - return threadCount_; - } - bool ParseOnly() const { return (options_ & OptionFlags::PARSE_ONLY) != 0; @@ -128,13 +124,26 @@ public: return compilerProtoOutput_; } + const std::string &CacheFile() const + { + return cacheFile_; + } + + const std::string &NpmModuleEntryList() const + { + return npmModuleEntryList_; + } + + bool CollectInputFilesFromFileList(const std::string &input); + bool CollectInputFilesFromFileDirectory(const std::string &input, const std::string &extension); + private: es2panda::ScriptExtension extension_ {es2panda::ScriptExtension::JS}; es2panda::CompilerOptions compilerOptions_ {}; es2panda::parser::ScriptKind scriptKind_ {es2panda::parser::ScriptKind::SCRIPT}; OptionFlags options_ {OptionFlags::DEFAULT}; panda::PandArgParser *argparser_; - std::string parserInput_; + std::string base64Input_; std::string compilerOutput_; std::string result_; std::string sourceFile_; @@ -142,7 +151,11 @@ private: std::string errorMsg_; std::string compilerProtoOutput_; int optLevel_ {0}; - int threadCount_ {0}; + int functionThreadCount_ {0}; + int fileThreadCount_ {0}; + std::string cacheFile_; + std::string npmModuleEntryList_; + std::vector sourceFiles_; }; } // namespace panda::es2panda::aot diff --git a/es2panda/compiler/core/compileQueue.cpp b/es2panda/compiler/core/compileQueue.cpp index 67dbd851a2..de7e931a16 100644 --- a/es2panda/compiler/core/compileQueue.cpp +++ b/es2panda/compiler/core/compileQueue.cpp @@ -22,8 +22,30 @@ #include #include +#include +#ifdef ENABLE_BYTECODE_OPT +#include +#include +#else +#include +#include +#include +#endif +#include +#include +#include +#include + +#include +#include +#include + +#include + namespace panda::es2panda::compiler { +std::mutex CompileFileJob::global_m_; + void CompileJob::DependsOn(CompileJob *job) { job->dependant_ = this; @@ -75,6 +97,20 @@ void CompileModuleRecordJob::Run() } } +void CompileFileJob::Run() +{ + es2panda::Compiler compiler(options_->extension, options_->functionThreadCount); + + auto *prog = compiler.CompileFile(*options_, src_); + + { + std::unique_lock lock(global_m_); + auto *cache = allocator_->New(src_->hash, prog); + progsInfo_.insert({src_->fileName, cache}); + progs_.push_back(prog); + } +} + CompileQueue::CompileQueue(size_t threadCount) { threads_.reserve(threadCount); @@ -98,29 +134,6 @@ CompileQueue::~CompileQueue() } } -void CompileQueue::Schedule(CompilerContext *context) -{ - ASSERT(jobsCount_ == 0); - std::unique_lock lock(m_); - const auto &functions = context->Binder()->Functions(); - - for (auto *function : functions) { - auto *funcJob = new CompileFunctionJob(context); - funcJob->SetFunctionScope(function); - jobs_.push_back(funcJob); - jobsCount_++; - } - - if (context->Binder()->Program()->Kind() == parser::ScriptKind::MODULE) { - auto *moduleRecordJob = new CompileModuleRecordJob(context); - jobs_.push_back(moduleRecordJob); - jobsCount_++; - } - - lock.unlock(); - jobsAvailable_.notify_all(); -} - void CompileQueue::Worker(CompileQueue *queue) { while (true) { @@ -181,4 +194,42 @@ void CompileQueue::Wait() } } +void CompileFuncQueue::Schedule() +{ + ASSERT(jobsCount_ == 0); + std::unique_lock lock(m_); + const auto &functions = context_->Binder()->Functions(); + + for (auto *function : functions) { + auto *funcJob = new CompileFunctionJob(context_); + funcJob->SetFunctionScope(function); + jobs_.push_back(funcJob); + jobsCount_++; + } + + if (context_->Binder()->Program()->Kind() == parser::ScriptKind::MODULE) { + auto *moduleRecordJob = new CompileModuleRecordJob(context_); + jobs_.push_back(moduleRecordJob); + jobsCount_++; + } + + lock.unlock(); + jobsAvailable_.notify_all(); +} + +void CompileFileQueue::Schedule() +{ + ASSERT(jobsCount_ == 0); + std::unique_lock lock(m_); + + for (auto &input: options_->sourceFiles) { + auto *fileJob = new CompileFileJob(&input, options_, progs_, progsInfo_, allocator_); + jobs_.push_back(fileJob); + jobsCount_++; + } + + lock.unlock(); + jobsAvailable_.notify_all(); +} + } // namespace panda::es2panda::compiler diff --git a/es2panda/compiler/core/compileQueue.h b/es2panda/compiler/core/compileQueue.h index f53b8b4c6b..a78b257ebe 100644 --- a/es2panda/compiler/core/compileQueue.h +++ b/es2panda/compiler/core/compileQueue.h @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include @@ -33,7 +33,7 @@ class CompilerContext; class CompileJob { public: - explicit CompileJob(CompilerContext *context) : context_(context) {}; + explicit CompileJob() {}; NO_COPY_SEMANTIC(CompileJob); NO_MOVE_SEMANTIC(CompileJob); virtual ~CompileJob() = default; @@ -43,7 +43,6 @@ public: void Signal(); protected: - [[maybe_unused]] CompilerContext *context_ {}; std::mutex m_; std::condition_variable cond_; CompileJob *dependant_ {}; @@ -52,7 +51,7 @@ protected: class CompileFunctionJob : public CompileJob { public: - explicit CompileFunctionJob(CompilerContext *context) : CompileJob(context) {}; + explicit CompileFunctionJob(CompilerContext *context) : context_(context) {}; NO_COPY_SEMANTIC(CompileFunctionJob); NO_MOVE_SEMANTIC(CompileFunctionJob); ~CompileFunctionJob() = default; @@ -68,18 +67,45 @@ public: } void Run() override; + private: + CompilerContext *context_ {}; binder::FunctionScope *scope_ {}; }; class CompileModuleRecordJob : public CompileJob { public: - explicit CompileModuleRecordJob(CompilerContext *context) : CompileJob(context) {}; + explicit CompileModuleRecordJob(CompilerContext *context) : context_(context) {}; NO_COPY_SEMANTIC(CompileModuleRecordJob); NO_MOVE_SEMANTIC(CompileModuleRecordJob); ~CompileModuleRecordJob() = default; void Run() override; + +private: + CompilerContext *context_ {}; +}; + +class CompileFileJob : public CompileJob { +public: + explicit CompileFileJob(es2panda::SourceFile *src, es2panda::CompilerOptions *options, + std::vector &progs, + std::unordered_map &progsInfo, + panda::ArenaAllocator *allocator) : + src_(src), options_(options), progs_(progs), progsInfo_(progsInfo), allocator_(allocator) {}; + NO_COPY_SEMANTIC(CompileFileJob); + NO_MOVE_SEMANTIC(CompileFileJob); + ~CompileFileJob() = default; + + void Run() override; + +private: + static std::mutex global_m_; + es2panda::SourceFile *src_; + es2panda::CompilerOptions *options_; + std::vector &progs_; + std::unordered_map &progsInfo_; + panda::ArenaAllocator *allocator_; }; class CompileQueue { @@ -87,13 +113,13 @@ public: explicit CompileQueue(size_t threadCount); NO_COPY_SEMANTIC(CompileQueue); NO_MOVE_SEMANTIC(CompileQueue); - ~CompileQueue(); + virtual ~CompileQueue(); - void Schedule(CompilerContext *context); + virtual void Schedule() = 0; void Consume(); void Wait(); -private: +protected: static void Worker(CompileQueue *queue); std::vector threads_; @@ -107,6 +133,42 @@ private: bool terminate_ {false}; }; +class CompileFuncQueue : public CompileQueue { +public: + explicit CompileFuncQueue(size_t threadCount, CompilerContext *context): + CompileQueue(threadCount), context_(context) {} + + NO_COPY_SEMANTIC(CompileFuncQueue); + NO_MOVE_SEMANTIC(CompileFuncQueue); + ~CompileFuncQueue() = default; + + void Schedule() override; + +private: + CompilerContext *context_; +}; + +class CompileFileQueue : public CompileQueue { +public: + explicit CompileFileQueue(size_t threadCount, es2panda::CompilerOptions *options, + std::vector &progs, + std::unordered_map &progsInfo, + panda::ArenaAllocator *allocator): + CompileQueue(threadCount), options_(options), progs_(progs), progsInfo_(progsInfo), allocator_(allocator) {} + + NO_COPY_SEMANTIC(CompileFileQueue); + NO_MOVE_SEMANTIC(CompileFileQueue); + ~CompileFileQueue() = default; + + void Schedule() override; + +private: + es2panda::CompilerOptions *options_; + std::vector &progs_; + std::unordered_map &progsInfo_; + panda::ArenaAllocator *allocator_; +}; + } // namespace panda::es2panda::compiler #endif diff --git a/es2panda/compiler/core/compilerImpl.cpp b/es2panda/compiler/core/compilerImpl.cpp index a1a79e65af..3f06a33e3e 100644 --- a/es2panda/compiler/core/compilerImpl.cpp +++ b/es2panda/compiler/core/compilerImpl.cpp @@ -27,17 +27,17 @@ namespace panda::es2panda::compiler { -CompilerImpl::CompilerImpl(size_t threadCount) : queue_(new CompileQueue(threadCount)) {} - CompilerImpl::~CompilerImpl() { - delete queue_; + if (queue_ != nullptr) { + delete queue_; + queue_ = nullptr; + } } -panda::pandasm::Program *CompilerImpl::Compile(parser::Program *program, const es2panda::CompilerOptions &options) +panda::pandasm::Program *CompilerImpl::Compile(parser::Program *program, const es2panda::CompilerOptions &options, const std::string &debugSourceFile) { - CompilerContext context(program->Binder(), options.isDebug, options.isDebuggerEvaluateExpressionMode, - options.sourceFile); + CompilerContext context(program->Binder(), options.isDebug, options.isDebuggerEvaluateExpressionMode, debugSourceFile); if (program->Extension() == ScriptExtension::TS && options.enableTypeCheck) { ArenaAllocator localAllocator(SpaceType::SPACE_TYPE_COMPILER, nullptr, true); @@ -49,7 +49,8 @@ panda::pandasm::Program *CompilerImpl::Compile(parser::Program *program, const e return nullptr; } - queue_->Schedule(&context); + queue_ = new CompileFuncQueue(threadCount_, &context); + queue_->Schedule(); /* Main thread can also be used instead of idling */ queue_->Consume(); diff --git a/es2panda/compiler/core/compilerImpl.h b/es2panda/compiler/core/compilerImpl.h index 19c6061347..2c7a3dbeb0 100644 --- a/es2panda/compiler/core/compilerImpl.h +++ b/es2panda/compiler/core/compilerImpl.h @@ -32,20 +32,21 @@ class Program; } // namespace panda::es2panda::parser namespace panda::es2panda::compiler { -class CompileQueue; +class CompileFuncQueue; class CompilerImpl { public: - explicit CompilerImpl(size_t threadCount); + explicit CompilerImpl(size_t threadCount): threadCount_(threadCount) {} ~CompilerImpl(); NO_COPY_SEMANTIC(CompilerImpl); NO_MOVE_SEMANTIC(CompilerImpl); - panda::pandasm::Program *Compile(parser::Program *program, const es2panda::CompilerOptions &options); + panda::pandasm::Program *Compile(parser::Program *program, const es2panda::CompilerOptions &options, const std::string &debugSourceFile); static void DumpAsm(const panda::pandasm::Program *prog); private: - CompileQueue *queue_; + size_t threadCount_ {0}; + CompileFuncQueue *queue_ {nullptr}; }; } // namespace panda::es2panda::compiler diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index 7349cd73f9..f55a8df720 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -416,6 +416,10 @@ void Emitter::DumpAsm(const panda::pandasm::Program *prog) } } + for (auto &[name, rec] : prog->record_table) { + ss << ".record " << name << '('; + } + ss << std::endl; } diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index b423c8dd47..90ec74fe75 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -21,6 +21,8 @@ #include #include +#include + #include #include @@ -57,7 +59,8 @@ panda::pandasm::Program *Compiler::Compile(const SourceFile &input, const Compil std::cout << ast.Dump() << std::endl; } - auto *prog = compiler_->Compile(&ast, options); + std::string debugSourceFile = options.debugSourceFile.empty() ? fname : options.debugSourceFile; + auto *prog = compiler_->Compile(&ast, options, debugSourceFile); return prog; } catch (const class Error &e) { @@ -70,4 +73,112 @@ void Compiler::DumpAsm(const panda::pandasm::Program *prog) { compiler::CompilerImpl::DumpAsm(prog); } + +static bool ReadFileToBuffer(const std::string &file, std::stringstream &ss) { + std::ifstream inputStream(file); + if (inputStream.fail()) { + std::cerr << "Failed to read file to buffer: " << file << std::endl; + return false; + } + ss << inputStream.rdbuf(); + return true; +} + +void Compiler::SelectCompileFile(CompilerOptions &options, + std::unordered_map *cacheProgs, + std::vector &progs, + std::unordered_map &progsInfo, + panda::ArenaAllocator *allocator, bool isCacheHasDebugInfo) +{ + if (cacheProgs == nullptr) { + return; + } + + if (isCacheHasDebugInfo != options.isDebug) { + return; + } + + auto fullList = options.sourceFiles; + std::vector inputList; + + for (auto &input: fullList) { + if (input.fileName.empty()) { + // base64 source + inputList.push_back(input); + continue; + } + + std::stringstream ss; + if (!ReadFileToBuffer(input.fileName, ss)) { + continue; + } + + uint32_t hash = GetHash32String(reinterpret_cast(ss.str().c_str())); + + // std::cout << "this function: "<< input.fileName << " hash " << hash << std::endl; + + auto it = cacheProgs->find(input.fileName); + if (it != cacheProgs->end() && hash == it->second->hashCode) { + progs.push_back(it->second->program); + auto *cache = allocator->New(it->second->hashCode, it->second->program); + progsInfo.insert({input.fileName, cache}); + // std::cout << "find same function: "<< input.fileName << std::endl; + } else { + input.hash = hash; + inputList.push_back(input); + } + } + options.sourceFiles = inputList; +} + +void Compiler::CompileFiles(CompilerOptions &options, + std::unordered_map *cacheProgs, + std::vector &progs, + std::unordered_map &progsInfo, + panda::ArenaAllocator *allocator, bool isCacheHasDebugInfo) +{ + SelectCompileFile(options, cacheProgs, progs, progsInfo, allocator, isCacheHasDebugInfo); + + auto queue = new compiler::CompileFileQueue(options.fileThreadCount, &options, progs, progsInfo, allocator); + + queue->Schedule(); + queue->Consume(); + queue->Wait(); + + delete queue; +} + +panda::pandasm::Program *Compiler::CompileFile(CompilerOptions &options, SourceFile *src) +{ + std::string buffer; + if (src->source.empty()) { + std::stringstream ss; + if (!ReadFileToBuffer(src->fileName, ss)) { + return nullptr; + } + buffer = ss.str(); + src->source = buffer; + + if (src->hash == 0) { + src->hash = GetHash32String(reinterpret_cast(buffer.c_str())); + } + } + + auto *program = Compile(*src, options); + + if (!program) { + const auto &err = GetError(); + + if (err.Message().empty() && options.parseOnly) { + return nullptr; + } + + std::cerr << err.TypeString() << ": " << err.Message(); + std::cerr << " [" << src->fileName << ":" << err.Line() << ":" << err.Col() << "]" << std::endl; + return nullptr; + } + + return program; +} + } // namespace panda::es2panda diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index 18127c3109..5b4e0e0298 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -17,8 +17,10 @@ #define ES2PANDA_PUBLIC_H #include - #include +#include +#include +#include namespace panda::pandasm { struct Program; @@ -41,15 +43,16 @@ enum class ScriptExtension { }; struct SourceFile { - SourceFile(std::string_view fn, std::string_view s, std::string_view rn, parser::ScriptKind sk) - : fileName(fn), source(s), recordName(rn), scriptKind(sk) + SourceFile(std::string fn, std::string rn, parser::ScriptKind sk) + : fileName(fn), recordName(rn), scriptKind(sk) { } - std::string_view fileName {}; + std::string fileName {}; + std::string recordName {}; std::string_view source {}; - std::string_view recordName {}; parser::ScriptKind scriptKind {}; + uint32_t hash {0}; }; struct CompilerOptions { @@ -61,7 +64,11 @@ struct CompilerOptions { bool enableTypeCheck {false}; bool dumpLiteralBuffer {false}; bool isDebuggerEvaluateExpressionMode {false}; - std::string sourceFile {}; + ScriptExtension extension {}; + int fileThreadCount {0}; + int functionThreadCount {0}; + std::string debugSourceFile {}; + std::vector sourceFiles; }; enum class ErrorType { @@ -143,6 +150,19 @@ public: NO_MOVE_SEMANTIC(Compiler); panda::pandasm::Program *Compile(const SourceFile &input, const CompilerOptions &options); + panda::pandasm::Program *CompileFile(CompilerOptions &options, SourceFile *src); + + static void CompileFiles(CompilerOptions &options, + std::unordered_map *cacheProgs, + std::vector &progs, + std::unordered_map &progsInfo, + panda::ArenaAllocator *allocator, bool isCacheHasDebugInfo); + + static void SelectCompileFile(CompilerOptions &options, + std::unordered_map *cacheProgs, + std::vector &progs, + std::unordered_map &progsInfo, + panda::ArenaAllocator *allocator, bool isCacheHasDebugInfo); inline panda::pandasm::Program *Compile(const SourceFile &input) { diff --git a/es2panda/util/moduleHelpers.cpp b/es2panda/util/moduleHelpers.cpp new file mode 100644 index 0000000000..77f538117b --- /dev/null +++ b/es2panda/util/moduleHelpers.cpp @@ -0,0 +1,72 @@ +/** + * 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 "moduleHelpers.h" + +#include + +namespace panda::es2panda::util { + +void ModuleHelpers::CompileNpmModuleEntryList(const std::string &entriesInfo, + std::unordered_map *cacheProgs, + std::vector &progs, + std::unordered_map &progsInfo, + panda::ArenaAllocator *allocator) +{ + std::stringstream ss; + std::ifstream inputStream(entriesInfo); + if (inputStream.fail()) { + std::cerr << "Failed to read file to buffer: " << entriesInfo << std::endl; + return; + } + ss << inputStream.rdbuf(); + + uint32_t hash = GetHash32String(reinterpret_cast(ss.str().c_str())); + + if (cacheProgs != nullptr) { + auto it = cacheProgs->find(entriesInfo); + if (it != cacheProgs->end() && hash == it->second->hashCode) { + progs.push_back(it->second->program); + auto *cache = allocator->New(it->second->hashCode, it->second->program); + progsInfo.insert({entriesInfo, cache}); + return; + } + } + + auto *prog = allocator->New(); + std::string line; + while (getline(ss, line)) { + std::size_t pos = line.find(":"); + std::string recordName = line.substr(0, pos); + std::string field = line.substr(pos + 1); + + auto langExt = panda::pandasm::extensions::Language::ECMASCRIPT; + auto entryNameField = panda::pandasm::Field(langExt); + entryNameField.name = field; + entryNameField.type = panda::pandasm::Type("u8", 0); + entryNameField.metadata->SetValue(panda::pandasm::ScalarValue::Create( + static_cast(0))); + + panda::pandasm::Record *entryRecord = new panda::pandasm::Record(recordName, langExt); + entryRecord->field_list.emplace_back(std::move(entryNameField)); + prog->record_table.emplace(recordName, std::move(*entryRecord)); + } + + progs.push_back(prog); + auto *cache = allocator->New(hash, prog); + progsInfo.insert({entriesInfo, cache}); +} + +} // namespace panda::es2panda::util \ No newline at end of file diff --git a/es2panda/util/moduleHelpers.h b/es2panda/util/moduleHelpers.h new file mode 100644 index 0000000000..38f783a066 --- /dev/null +++ b/es2panda/util/moduleHelpers.h @@ -0,0 +1,36 @@ +/** + * 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_MODULE_HELPERS_H +#define ES2PANDA_UTIL_MODULE_HELPERS_H + +#include +#include +#include + +namespace panda::es2panda::util { + +class ModuleHelpers { +public: + static void CompileNpmModuleEntryList(const std::string &entriesInfo, + std::unordered_map *cacheProgs, + std::vector &progs, + std::unordered_map &progsInfo, + panda::ArenaAllocator *allocator); +}; + +} //panda::es2panda::util + +#endif \ No newline at end of file diff --git a/es2panda/util/compositeHelpers.h b/es2panda/util/programCache.h similarity index 71% rename from es2panda/util/compositeHelpers.h rename to es2panda/util/programCache.h index e11b0ff51b..581bb4cfc1 100644 --- a/es2panda/util/compositeHelpers.h +++ b/es2panda/util/programCache.h @@ -13,26 +13,22 @@ * limitations under the License. */ -#ifndef ES2PANDA_UTIL_COMPOSITE_HELPERS_H -#define ES2PANDA_UTIL_COMPOSITE_HELPERS_H +#ifndef ES2PANDA_UTIL_PROGRAM_CACHE_H +#define ES2PANDA_UTIL_PROGRAM_CACHE_H #include namespace panda::es2panda::util { -struct HashProgram { +struct ProgramCache { uint32_t hashCode; panda::pandasm::Program* program; - HashProgram(uint32_t hashCode, panda::pandasm::Program* program) : hashCode(hashCode), program(program) + ProgramCache(uint32_t hashCode, panda::pandasm::Program* program) : hashCode(hashCode), program(program) { } }; -struct CompositeProgramMap { - std::unordered_map compositeProgramInfo; -}; - } //panda::es2panda::util #endif diff --git a/merge_abc/protos/compositeProgram.proto b/merge_abc/protos/compositeProgram.proto index 35baef97bb..0177aba504 100644 --- a/merge_abc/protos/compositeProgram.proto +++ b/merge_abc/protos/compositeProgram.proto @@ -18,12 +18,13 @@ package protoPanda; import "assemblyProgram.proto"; -message HashNameProgram { +message ProgramCache { bytes fileName = 1; uint32 hashCode = 2; Program program = 3; } message CompositeProgram { - repeated HashNameProgram hashNameProgram = 1; + repeated ProgramCache ProgramCache = 1; + bool isDebug = 2; } diff --git a/merge_abc/src/compositeProgramProto.cpp b/merge_abc/src/compositeProgramProto.cpp index 47c9b09ff9..5dde8b8ec9 100644 --- a/merge_abc/src/compositeProgramProto.cpp +++ b/merge_abc/src/compositeProgramProto.cpp @@ -17,31 +17,34 @@ namespace panda::proto { -void CompositeProgram::Serialize(const panda::es2panda::util::CompositeProgram &compositeProgram, - protoPanda::CompositeProgram &protoCompositeProgram) +void CompositeProgram::Serialize( + const std::unordered_map &compositeProgramMap, bool isDebug, + protoPanda::CompositeProgram &protoCompositeProgram) { - for (const auto &[fileName, hashProgram] : compositeProgramMap.compositeProgramInfo) { - auto protoHashNameProgram = protoCompositeProgram.add_hashnameprogram(); - protoHashNameProgram->set_filename(fileName); - protoHashNameProgram->set_hashcode(hashProgram->hashCode); - auto *protoProgram = protoHashNameProgram->mutable_program(); - Program::Serialize(*(hashProgram->program), *protoProgram); + for (const auto &[fileName, programCache] : compositeProgramMap) { + auto protoProgramcache = protoCompositeProgram.add_programcache(); + protoProgramcache->set_filename(fileName); + protoProgramcache->set_hashcode(programCache->hashCode); + auto *protoProgram = protoProgramcache->mutable_program(); + Program::Serialize(*(programCache->program), *protoProgram); } + protoCompositeProgram.set_isdebug(isDebug); } void CompositeProgram::Deserialize(const protoPanda::CompositeProgram &protoCompositeProgram, - panda::es2panda::util::CompositeProgramMap &compositeProgramMap, - panda::ArenaAllocator *allocator) + std::unordered_map &compositeProgramMap, + bool &isDebug, panda::ArenaAllocator *allocator) { - for (const auto &protoHashNameProgram : protoCompositeProgram.hashnameprogram()) { - auto fileName = protoHashNameProgram.filename(); - auto hashCode = protoHashNameProgram.hashcode(); - auto protoProgram = protoHashNameProgram.program(); + for (const auto &protoProgramcache : protoCompositeProgram.programcache()) { + auto fileName = protoProgramcache.filename(); + auto hashCode = protoProgramcache.hashcode(); + auto protoProgram = protoProgramcache.program(); auto *program = allocator->New(); Program::Deserialize(protoProgram, *program, allocator); - auto *hashProgram = allocator->New(hashCode, program); - compositeProgramMap.compositeProgramInfo.insert({fileName, hashProgram}); + auto *programCache = allocator->New(hashCode, program); + compositeProgramMap.insert({fileName, programCache}); } + isDebug = protoCompositeProgram.isdebug(); } } // namespace panda::proto diff --git a/merge_abc/src/compositeProgramProto.h b/merge_abc/src/compositeProgramProto.h index b1526f31e6..868180ef46 100644 --- a/merge_abc/src/compositeProgramProto.h +++ b/merge_abc/src/compositeProgramProto.h @@ -16,18 +16,19 @@ #ifndef MERGE_ABC_BUILD_COMPOSITE_PROGRAM_H #define MERGE_ABC_BUILD_COMPOSITE_PROGRAM_H -#include "compositeHelpers.h" +#include "programCache.h" #include "compositeProgram.pb.h" #include "assemblyProgramProto.h" namespace panda::proto { class CompositeProgram { public: - static void Serialize(const panda::es2panda::util::CompositeProgram &compositeProgram, - protoPanda::CompositeProgram &protoCompositeProgram); + static void Serialize( + const std::unordered_map &compositeProgramMap, bool isDebug, + protoPanda::CompositeProgram &protoCompositeProgram); static void Deserialize(const protoPanda::CompositeProgram &protoCompositeProgram, - panda::es2panda::util::CompositeProgramMap &compositeProgramMap, - panda::ArenaAllocator *allocator); + std::unordered_map &compositeProgramMap, + bool &isDebug, panda::ArenaAllocator *allocator); }; } // panda::proto diff --git a/merge_abc/src/mergeProgram.cpp b/merge_abc/src/mergeProgram.cpp index f99d58d349..d3f9281d2c 100644 --- a/merge_abc/src/mergeProgram.cpp +++ b/merge_abc/src/mergeProgram.cpp @@ -28,7 +28,7 @@ namespace panda::proto { -bool MergeProgram::GetProtoFiles(std::string &protoBinPath, std::string &protoBinSuffix, +bool MergeProgram::GetProtoFiles(const std::string &protoBinPath, const std::string &protoBinSuffix, std::vector &directoryFiles) { #if PANDA_TARGET_WINDOWS @@ -86,12 +86,12 @@ bool MergeProgram::GetProtoFiles(std::string &protoBinPath, std::string &protoBi return true; } -bool MergeProgram::AppendProtoFiles(std::string filePath, std::string protoBinSuffix, +bool MergeProgram::AppendProtoFiles(const std::string &filePath, const std::string &protoBinSuffix, std::vector &protoFiles) { auto inputAbs = panda::os::file::File::GetAbsolutePath(filePath); if (!inputAbs) { - std::cerr << "Failed to open: " << inputAbs.Value() << std::endl; + std::cerr << "Failed to open: " << filePath << std::endl; return false; } @@ -114,7 +114,7 @@ bool MergeProgram::AppendProtoFiles(std::string filePath, std::string protoBinSu return true; } -bool MergeProgram::CollectProtoFiles(std::string input, std::string protoBinSuffix, +bool MergeProgram::CollectProtoFiles(std::string &input, const std::string &protoBinSuffix, std::vector &protoFiles) { constexpr const char DOGGY = '@'; @@ -128,7 +128,7 @@ bool MergeProgram::CollectProtoFiles(std::string input, std::string protoBinSuff auto inputAbs = panda::os::file::File::GetAbsolutePath(input); if (!inputAbs) { - std::cerr << "Failed to open: " << inputAbs.Value() << std::endl; + std::cerr << "Failed to open: " << input << std::endl; return false; } if (isList) { diff --git a/merge_abc/src/mergeProgram.h b/merge_abc/src/mergeProgram.h index 06125ae93f..54f850dfd0 100644 --- a/merge_abc/src/mergeProgram.h +++ b/merge_abc/src/mergeProgram.h @@ -23,11 +23,11 @@ namespace panda::proto { class MergeProgram { public: - static bool GetProtoFiles(std::string &protoBinPath, std::string &protoBinSuffix, + static bool GetProtoFiles(const std::string &protoBinPath, const std::string &protoBinSuffix, std::vector &directoryFiles); - static bool AppendProtoFiles(std::string filePath, std::string protoBinSuffix, + static bool AppendProtoFiles(const std::string &filePath, const std::string &protoBinSuffix, std::vector &protoFiles); - static bool CollectProtoFiles(std::string input, std::string protoBinSuffix, std::vector &protoFiles); + static bool CollectProtoFiles(std::string &input, const std::string &protoBinSuffix, std::vector &protoFiles); }; } // namespace panda::proto #endif // MERGE_ABC_MERGE_PROGRAM_H diff --git a/merge_abc/src/protobufSnapshotGenerator.cpp b/merge_abc/src/protobufSnapshotGenerator.cpp index f50988ff86..ec558b44fd 100644 --- a/merge_abc/src/protobufSnapshotGenerator.cpp +++ b/merge_abc/src/protobufSnapshotGenerator.cpp @@ -49,11 +49,12 @@ void ProtobufSnapshotGenerator::GenerateProgram(const std::string &inputName, pa Program::Deserialize(proto_program, prog, allocator); } -void ProtobufSnapshotGenerator::UpdateCacheFile(panda::es2panda::util::CompositeProgramMap compositeProgramMap, - const std::string &cacheFilePath) +void ProtobufSnapshotGenerator::UpdateCacheFile( + const std::unordered_map &compositeProgramMap, + bool &isDebug, const std::string &cacheFilePath) { protoPanda::CompositeProgram protoCompositeProgram; - CompositeProgram::Serialize(compositeProgram, protoCompositeProgram); + CompositeProgram::Serialize(compositeProgramMap, isDebug, protoCompositeProgram); std::fstream output(cacheFilePath, std::ios::out | std::ios::trunc | std::ios::binary); if (!output) { std::cout << "Fail to create cache file: " << cacheFilePath << std::endl; @@ -63,8 +64,8 @@ void ProtobufSnapshotGenerator::UpdateCacheFile(panda::es2panda::util::Composite output.close(); } -panda::es2panda::util::CompositeProgramMap *ProtobufSnapshotGenerator::GetCacheContext(const std::string &cacheFilePath, - panda::ArenaAllocator *allocator) +std::unordered_map *ProtobufSnapshotGenerator::GetCacheContext( + const std::string &cacheFilePath, bool &isDebug, panda::ArenaAllocator *allocator) { std::fstream input(cacheFilePath, std::ios::in | std::ios::binary); if (!input) { @@ -77,8 +78,8 @@ panda::es2panda::util::CompositeProgramMap *ProtobufSnapshotGenerator::GetCacheC return nullptr; } - auto compositeProgramMap = allocator->New(); - CompositeProgram::Deserialize(protoCompositeProgram, *compositeProgramMap, allocator); + auto compositeProgramMap = allocator->New>(); + CompositeProgram::Deserialize(protoCompositeProgram, *compositeProgramMap, isDebug, allocator); return compositeProgramMap; } diff --git a/merge_abc/src/protobufSnapshotGenerator.h b/merge_abc/src/protobufSnapshotGenerator.h index ba50ea815d..a735ba4535 100644 --- a/merge_abc/src/protobufSnapshotGenerator.h +++ b/merge_abc/src/protobufSnapshotGenerator.h @@ -25,10 +25,11 @@ public: static void GenerateSnapshot(const panda::pandasm::Program &prog, const std::string &outputName); static void GenerateProgram(const std::string &inputName, panda::pandasm::Program &prog, panda::ArenaAllocator *allocator); - static panda::es2panda::util::CompositeProgramMap *GetCacheContext(const std::string &cacheFilePath, - panda::ArenaAllocator *allocator); - static void UpdateCacheFile(panda::es2panda::util::CompositeProgramMap compositeProgramMap, - const std::string &cacheFilePath); + static std::unordered_map *GetCacheContext( + const std::string &cacheFilePath, bool &isDebug, panda::ArenaAllocator *allocator); + static void UpdateCacheFile( + const std::unordered_map &compositeProgram, + bool &isDebug, const std::string &cacheFilePath); }; } // panda::proto #endif -- Gitee From 5e07a58565af1f446233b00c49078550962fd045 Mon Sep 17 00:00:00 2001 From: gavin1012_hw Date: Mon, 29 Aug 2022 11:40:18 +0800 Subject: [PATCH 19/23] Modify reference && Fix cerr info Signed-off-by: gavin1012_hw Change-Id: I2515c1c93b9c310a2d5c5989644b8e01399ef527 --- merge_abc/src/annotationProto.cpp | 15 ++++++----- merge_abc/src/assemblyFunctionProto.cpp | 13 ++++++--- merge_abc/src/assemblyInsProto.cpp | 5 +++- merge_abc/src/assemblyLiteralsProto.cpp | 1 + merge_abc/src/assemblyProgramProto.cpp | 20 ++++++++------ merge_abc/src/assemblyRecordProto.cpp | 1 + merge_abc/src/assemblyTypeProto.cpp | 2 +- merge_abc/src/compositeProgramProto.cpp | 7 ++--- merge_abc/src/main.cpp | 1 + merge_abc/src/mergeProgram.cpp | 1 + merge_abc/src/metaProto.cpp | 29 +++++++++++---------- merge_abc/src/protobufSnapshotGenerator.cpp | 8 +++--- 12 files changed, 61 insertions(+), 42 deletions(-) diff --git a/merge_abc/src/annotationProto.cpp b/merge_abc/src/annotationProto.cpp index 37b7d86995..85d13681f2 100644 --- a/merge_abc/src/annotationProto.cpp +++ b/merge_abc/src/annotationProto.cpp @@ -29,7 +29,7 @@ void AnnotationData::Deserialize(const protoPanda::AnnotationData &protoAnno, pa panda::ArenaAllocator *allocator) { for (const auto &protoElement : protoAnno.elements()) { - panda::pandasm::AnnotationElement element = AnnotationElement::Deserialize(protoElement, allocator); + panda::pandasm::AnnotationElement &element = AnnotationElement::Deserialize(protoElement, allocator); anno.AddElement(std::move(element)); } } @@ -53,13 +53,13 @@ panda::pandasm::AnnotationElement &AnnotationElement::Deserialize(const protoPan panda::ArenaAllocator *allocator) { if (protoElement.valuetype() == protoPanda::AnnotationElement_ValueType::AnnotationElement_ValueType_ARRAY) { - panda::pandasm::ArrayValue array = ArrayValue::Deserialize(protoElement.array(), allocator); - auto element = allocator->New(protoElement.name(), + panda::pandasm::ArrayValue &array = ArrayValue::Deserialize(protoElement.array(), allocator); + auto *element = allocator->New(protoElement.name(), std::make_unique(array)); return *element; } panda::pandasm::ScalarValue scalar = ScalarValue::Deserialize(protoElement.scalar(), allocator); - auto element = allocator->New(protoElement.name(), + auto *element = allocator->New(protoElement.name(), std::make_unique(scalar)); return *element; } @@ -155,8 +155,8 @@ panda::pandasm::ScalarValue ScalarValue::Deserialize(const protoPanda::ScalarVal break; } case protoPanda::ScalarValue_VariantValueType::ScalarValue_VariantValueType_ANNOTATION_DATA: { - auto protoAnnotationData = protoScalar.valueanno(); - auto value = allocator->New(protoAnnotationData.recordname()); + auto &protoAnnotationData = protoScalar.valueanno(); + auto *value = allocator->New(protoAnnotationData.recordname()); AnnotationData::Deserialize(protoAnnotationData, *value, allocator); break; } @@ -256,11 +256,12 @@ panda::pandasm::ArrayValue &ArrayValue::Deserialize(const protoPanda::ArrayValue panda::ArenaAllocator *allocator) { std::vector values; + values.reserve(protoArray.values_size()); for (const auto &protoValue : protoArray.values()) { panda::pandasm::ScalarValue scalar = ScalarValue::Deserialize(protoValue, allocator); values.emplace_back(std::move(scalar)); } - auto array = allocator->New( + auto *array = allocator->New( static_cast(protoArray.componenttype()), values); return *array; } diff --git a/merge_abc/src/assemblyFunctionProto.cpp b/merge_abc/src/assemblyFunctionProto.cpp index 0301e52e1f..5b3e638703 100644 --- a/merge_abc/src/assemblyFunctionProto.cpp +++ b/merge_abc/src/assemblyFunctionProto.cpp @@ -110,20 +110,23 @@ void Function::Deserialize(const protoPanda::Function &protoFunction, panda::pan panda::ArenaAllocator *allocator) { FunctionMetadata::Deserialize(protoFunction.metadata(), function.metadata, allocator); + function.label_table.reserve(protoFunction.labeltable_size()); for (const auto &labelUnit : protoFunction.labeltable()) { - auto name = labelUnit.key(); - auto protoLabel = labelUnit.value(); + auto &name = labelUnit.key(); + auto &protoLabel = labelUnit.value(); panda::pandasm::Label label(name); Label::Deserialize(protoLabel, label); function.label_table.insert({name, label}); } + function.ins.reserve(protoFunction.ins_size()); for (const auto &protoIns : protoFunction.ins()) { panda::pandasm::Ins ins; Ins::Deserialize(protoIns, ins); function.ins.emplace_back(std::move(ins)); } + function.local_variable_debug.reserve(protoFunction.localvariabledebug_size()); for (const auto &protoLocalVariable : protoFunction.localvariabledebug()) { panda::pandasm::debuginfo::LocalVariable localVariable; LocalVariable::Deserialize(protoLocalVariable, localVariable); @@ -133,8 +136,9 @@ void Function::Deserialize(const protoPanda::Function &protoFunction, panda::pan function.source_file = protoFunction.sourcefile(); function.source_code = protoFunction.sourcecode(); + function.catch_blocks.reserve(protoFunction.catchblocks_size()); for (const auto &protoCatchBlock : protoFunction.catchblocks()) { - auto catchBlock = allocator->New(); + auto *catchBlock = allocator->New(); CatchBlock::Deserialize(protoCatchBlock, *catchBlock); function.catch_blocks.emplace_back(std::move(*catchBlock)); } @@ -142,8 +146,9 @@ void Function::Deserialize(const protoPanda::Function &protoFunction, panda::pan function.value_of_first_param = protoFunction.valueoffirstparam(); function.regs_num = protoFunction.regsnum(); + function.params.reserve(protoFunction.params_size()); for (const auto &protoParam : protoFunction.params()) { - auto paramType = Type::Deserialize(protoParam.type(), allocator); + auto ¶mType = Type::Deserialize(protoParam.type(), allocator); panda::pandasm::Function::Parameter param(paramType, panda::panda_file::SourceLang::ECMASCRIPT); Parameter::Deserialize(protoParam, param, allocator); function.params.emplace_back(std::move(param)); diff --git a/merge_abc/src/assemblyInsProto.cpp b/merge_abc/src/assemblyInsProto.cpp index c4ab16ae4d..c1016ef04a 100644 --- a/merge_abc/src/assemblyInsProto.cpp +++ b/merge_abc/src/assemblyInsProto.cpp @@ -47,12 +47,15 @@ void Ins::Serialize(const panda::pandasm::Ins &insn, protoPanda::Ins &protoInsn) void Ins::Deserialize(const protoPanda::Ins &protoInsn, panda::pandasm::Ins &insn) { insn.opcode = static_cast(protoInsn.opcode()); + insn.regs.reserve(protoInsn.regs_size()); for (const auto &protoReg : protoInsn.regs()) { insn.regs.push_back(static_cast(protoReg)); } + insn.ids.reserve(protoInsn.ids_size()); for (const auto &protoId : protoInsn.ids()) { insn.ids.push_back(protoId); } + insn.imms.reserve(protoInsn.imms_size()); for (const auto &protoImm : protoInsn.imms()) { switch (protoImm.type_case()) { case protoPanda::Ins_IType::kValueInt: { @@ -69,7 +72,7 @@ void Ins::Deserialize(const protoPanda::Ins &protoInsn, panda::pandasm::Ins &ins } insn.label = protoInsn.label(); insn.set_label = protoInsn.setlabelval(); - const protoPanda::DebuginfoIns protoDebugInfoIns = protoInsn.insdebug(); + const protoPanda::DebuginfoIns &protoDebugInfoIns = protoInsn.insdebug(); DebuginfoIns::Deserialize(protoDebugInfoIns, insn.ins_debug); } } // panda::proto diff --git a/merge_abc/src/assemblyLiteralsProto.cpp b/merge_abc/src/assemblyLiteralsProto.cpp index 889357b94d..1e4542d919 100644 --- a/merge_abc/src/assemblyLiteralsProto.cpp +++ b/merge_abc/src/assemblyLiteralsProto.cpp @@ -109,6 +109,7 @@ void LiteralArray::Serialize(const panda::pandasm::LiteralArray &array, protoPan void LiteralArray::Deserialize(const protoPanda::LiteralArray &protoArray, panda::pandasm::LiteralArray &array) { + array.literals_.reserve(protoArray.literals_size()); for (const auto &protoLiteral : protoArray.literals()) { panda::pandasm::LiteralArray::Literal literal; Literal::Deserialize(protoLiteral, literal); diff --git a/merge_abc/src/assemblyProgramProto.cpp b/merge_abc/src/assemblyProgramProto.cpp index e8658511ea..8e8f4ad080 100644 --- a/merge_abc/src/assemblyProgramProto.cpp +++ b/merge_abc/src/assemblyProgramProto.cpp @@ -54,38 +54,42 @@ void Program::Deserialize(const protoPanda::Program &protoProgram, panda::pandas { program.lang = static_cast(protoProgram.lang()); + program.record_table.reserve(protoProgram.recordtable_size()); for (const auto &recordUnit : protoProgram.recordtable()) { - auto name = recordUnit.key(); - auto protoRecord = recordUnit.value(); + auto &name = recordUnit.key(); + auto &protoRecord = recordUnit.value(); auto record = panda::pandasm::Record(protoRecord.name(), static_cast(protoRecord.language())); Record::Deserialize(protoRecord, record, allocator); program.record_table.insert({name, std::move(record)}); } + program.function_table.reserve(protoProgram.functiontable_size()); for (const auto &functionUnit : protoProgram.functiontable()) { - auto name = functionUnit.key(); - auto protoFunction = functionUnit.value(); - auto function = allocator->New(protoFunction.name(), + auto &name = functionUnit.key(); + auto &protoFunction = functionUnit.value(); + auto *function = allocator->New(protoFunction.name(), static_cast(protoFunction.language())); Function::Deserialize(protoFunction, *function, allocator); program.function_table.insert({name, std::move(*function)}); } for (const auto &literalUnit : protoProgram.literalarraytable()) { - auto name = literalUnit.key(); - auto protoLiteralArray = literalUnit.value(); + auto &name = literalUnit.key(); + auto &protoLiteralArray = literalUnit.value(); panda::pandasm::LiteralArray literalArray; LiteralArray::Deserialize(protoLiteralArray, literalArray); program.literalarray_table.insert({name, std::move(literalArray)}); } + program.strings.reserve(protoProgram.strings_size()); for (const auto &protoString : protoProgram.strings()) { program.strings.insert(protoString); } + program.array_types.reserve(protoProgram.arraytypes_size()); for (const auto &protoArrayType : protoProgram.arraytypes()) { - auto arrayType = Type::Deserialize(protoArrayType, allocator); + auto &arrayType = Type::Deserialize(protoArrayType, allocator); program.array_types.insert(std::move(arrayType)); } } diff --git a/merge_abc/src/assemblyRecordProto.cpp b/merge_abc/src/assemblyRecordProto.cpp index 15e34a327f..0ba26f7339 100644 --- a/merge_abc/src/assemblyRecordProto.cpp +++ b/merge_abc/src/assemblyRecordProto.cpp @@ -45,6 +45,7 @@ void Record::Deserialize(const protoPanda::Record &protoRecord, panda::pandasm:: { record.conflict = protoRecord.conflict(); RecordMetadata::Deserialize(protoRecord.metadata(), record.metadata, allocator); + record.field_list.reserve(protoRecord.fieldlist_size()); for (const auto &protoField : protoRecord.fieldlist()) { auto recordField = panda::pandasm::Field(panda::panda_file::SourceLang::ECMASCRIPT); Field::Deserialize(protoField, recordField, allocator); diff --git a/merge_abc/src/assemblyTypeProto.cpp b/merge_abc/src/assemblyTypeProto.cpp index eded41401c..eea55eb4b4 100644 --- a/merge_abc/src/assemblyTypeProto.cpp +++ b/merge_abc/src/assemblyTypeProto.cpp @@ -27,7 +27,7 @@ void Type::Serialize(const panda::pandasm::Type type, protoPanda::Type &protoTyp panda::pandasm::Type &Type::Deserialize(const protoPanda::Type &protoType, panda::ArenaAllocator *allocator) { - auto type = allocator->New(protoType.componentname(), protoType.rank()); + auto *type = allocator->New(protoType.componentname(), protoType.rank()); return *type; } } // panda::proto diff --git a/merge_abc/src/compositeProgramProto.cpp b/merge_abc/src/compositeProgramProto.cpp index 5dde8b8ec9..485927e41f 100644 --- a/merge_abc/src/compositeProgramProto.cpp +++ b/merge_abc/src/compositeProgramProto.cpp @@ -22,7 +22,7 @@ void CompositeProgram::Serialize( protoPanda::CompositeProgram &protoCompositeProgram) { for (const auto &[fileName, programCache] : compositeProgramMap) { - auto protoProgramcache = protoCompositeProgram.add_programcache(); + auto *protoProgramcache = protoCompositeProgram.add_programcache(); protoProgramcache->set_filename(fileName); protoProgramcache->set_hashcode(programCache->hashCode); auto *protoProgram = protoProgramcache->mutable_program(); @@ -35,10 +35,11 @@ void CompositeProgram::Deserialize(const protoPanda::CompositeProgram &protoComp std::unordered_map &compositeProgramMap, bool &isDebug, panda::ArenaAllocator *allocator) { + compositeProgramMap.reserve(protoCompositeProgram.programcache_size()); for (const auto &protoProgramcache : protoCompositeProgram.programcache()) { - auto fileName = protoProgramcache.filename(); + auto &fileName = protoProgramcache.filename(); auto hashCode = protoProgramcache.hashcode(); - auto protoProgram = protoProgramcache.program(); + auto &protoProgram = protoProgramcache.program(); auto *program = allocator->New(); Program::Deserialize(protoProgram, *program, allocator); auto *programCache = allocator->New(hashCode, program); diff --git a/merge_abc/src/main.cpp b/merge_abc/src/main.cpp index 3b651b5fe4..0fe19879b6 100644 --- a/merge_abc/src/main.cpp +++ b/merge_abc/src/main.cpp @@ -68,6 +68,7 @@ int Run(int argc, const char **argv) panda::ArenaAllocator allocator(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true); std::vector programs; + programs.reserve(protoFiles.size()); for(size_t i = 0; i < protoFiles.size(); i++) { auto *prog = allocator.New(); programs.emplace_back(prog); diff --git a/merge_abc/src/mergeProgram.cpp b/merge_abc/src/mergeProgram.cpp index d3f9281d2c..2de584b517 100644 --- a/merge_abc/src/mergeProgram.cpp +++ b/merge_abc/src/mergeProgram.cpp @@ -152,6 +152,7 @@ bool MergeProgram::CollectProtoFiles(std::string &input, const std::string &prot inputs.push_back(inputAbs.Value()); } + protoFiles.reserve(inputs.size()); for (auto &filePath : inputs) { if (!AppendProtoFiles(filePath, protoBinSuffix, protoFiles)) { return false; diff --git a/merge_abc/src/metaProto.cpp b/merge_abc/src/metaProto.cpp index 75fb586355..fd70b26406 100644 --- a/merge_abc/src/metaProto.cpp +++ b/merge_abc/src/metaProto.cpp @@ -25,13 +25,13 @@ void RecordMetadata::Deserialize(const protoPanda::RecordMetadata &protoMeta, std::unique_ptr &meta, panda::ArenaAllocator *allocator) { - auto protoItemMetadata = protoMeta.father(); + auto &protoItemMetadata = protoMeta.father(); ItemMetadata::Deserialize(protoItemMetadata, *meta); - auto protoAnnoMetadata = protoItemMetadata.father(); + auto &protoAnnoMetadata = protoItemMetadata.father(); AnnotationMetadata::Deserialize(protoAnnoMetadata, *meta, allocator); - auto protoMetadata = protoAnnoMetadata.father(); + auto &protoMetadata = protoAnnoMetadata.father(); Metadata::Deserialize(protoMetadata, *meta); } @@ -46,13 +46,13 @@ void FunctionMetadata::Deserialize(const protoPanda::FunctionMetadata &protoMeta std::unique_ptr &meta, panda::ArenaAllocator *allocator) { - auto protoItemMetadata = protoMeta.father(); + auto &protoItemMetadata = protoMeta.father(); ItemMetadata::Deserialize(protoItemMetadata, *meta); - auto protoAnnoMetadata = protoItemMetadata.father(); + auto &protoAnnoMetadata = protoItemMetadata.father(); AnnotationMetadata::Deserialize(protoAnnoMetadata, *meta, allocator); - auto protoMetadata = protoAnnoMetadata.father(); + auto &protoMetadata = protoAnnoMetadata.father(); Metadata::Deserialize(protoMetadata, *meta); } @@ -73,14 +73,14 @@ void FieldMetadata::Deserialize(const protoPanda::FieldMetadata &protoMeta, std::unique_ptr &meta, panda::ArenaAllocator *allocator) { - auto protoItemMetadata = protoMeta.father(); + auto &protoItemMetadata = protoMeta.father(); ItemMetadata::Deserialize(protoItemMetadata, *meta); - auto protoAnnoMetadata = protoItemMetadata.father(); + auto &protoAnnoMetadata = protoItemMetadata.father(); AnnotationMetadata::Deserialize(protoAnnoMetadata, *meta, allocator); - auto protoMetadata = protoAnnoMetadata.father(); + auto &protoMetadata = protoAnnoMetadata.father(); Metadata::Deserialize(protoMetadata, *meta); - auto fieldType = Type::Deserialize(protoMeta.fieldtype(), allocator); + auto &fieldType = Type::Deserialize(protoMeta.fieldtype(), allocator); meta->SetFieldType(fieldType); ScalarValue scalarValue; if (protoMeta.has_value()) { @@ -99,7 +99,7 @@ void ParamMetadata::Deserialize(const protoPanda::ParamMetadata &protoMeta, std::unique_ptr &meta, panda::ArenaAllocator *allocator) { - auto protoAnnoMetadata = protoMeta.father(); + auto &protoAnnoMetadata = protoMeta.father(); AnnotationMetadata::Deserialize(protoAnnoMetadata, *meta, allocator); } @@ -131,8 +131,9 @@ void AnnotationMetadata::Deserialize(const protoPanda::AnnotationMetadata &proto panda::ArenaAllocator *allocator) { std::vector annotations; + annotations.reserve(protoMeta.annotations_size()); for (const auto &protoAnnotation : protoMeta.annotations()) { - auto annotation = allocator->New(protoAnnotation.recordname()); + auto *annotation = allocator->New(protoAnnotation.recordname()); AnnotationData::Deserialize(protoAnnotation, *annotation, allocator); annotations.emplace_back(std::move(*annotation)); } @@ -159,9 +160,9 @@ void Metadata::Deserialize(const protoPanda::Metadata &protoMeta, panda::pandasm meta.SetAttribute(attr); } for (const auto &protoKeyVal: protoMeta.attributes()) { - auto key = protoKeyVal.key(); + auto &key = protoKeyVal.key(); for (const auto &attr : protoKeyVal.value()) { - meta.SetAttributeValue(protoKeyVal.key(), attr); + meta.SetAttributeValue(key, attr); } } } diff --git a/merge_abc/src/protobufSnapshotGenerator.cpp b/merge_abc/src/protobufSnapshotGenerator.cpp index ec558b44fd..e7b5952ef6 100644 --- a/merge_abc/src/protobufSnapshotGenerator.cpp +++ b/merge_abc/src/protobufSnapshotGenerator.cpp @@ -26,7 +26,7 @@ void ProtobufSnapshotGenerator::GenerateSnapshot(const panda::pandasm::Program & std::fstream output(outputName, std::ios::out | std::ios::trunc | std::ios::binary); if (!output) { - std::cout << ": Fail to create file" << std::endl; + std::cerr << "Failed to create: " << outputName << std::endl; return; } protoProgram.SerializeToOstream(&output); @@ -38,12 +38,12 @@ void ProtobufSnapshotGenerator::GenerateProgram(const std::string &inputName, pa { std::fstream input(inputName, std::ios::in | std::ios::binary); if (!input) { - std::cerr << "Failed to open " << inputName << std::endl; + std::cerr << "Failed to open: " << inputName << std::endl; return; } protoPanda::Program proto_program; if (!proto_program.ParseFromIstream(&input)) { - std::cerr << "Failed to parse " << inputName << std::endl; + std::cerr << "Failed to parse: " << inputName << std::endl; return; } Program::Deserialize(proto_program, prog, allocator); @@ -57,7 +57,7 @@ void ProtobufSnapshotGenerator::UpdateCacheFile( CompositeProgram::Serialize(compositeProgramMap, isDebug, protoCompositeProgram); std::fstream output(cacheFilePath, std::ios::out | std::ios::trunc | std::ios::binary); if (!output) { - std::cout << "Fail to create cache file: " << cacheFilePath << std::endl; + std::cerr << "Failed to create cache file: " << cacheFilePath << std::endl; return; } protoCompositeProgram.SerializeToOstream(&output); -- Gitee From 1f771c0dd5e7122522387ef8c3d75bc171e232f3 Mon Sep 17 00:00:00 2001 From: hufeng Date: Mon, 29 Aug 2022 09:33:33 +0800 Subject: [PATCH 20/23] Revert "Adapt UT to merged abc" This reverts commit e06485d7dd35201a151ae5dc8567fa3cb048e786. Signed-off-by: hufeng Change-Id: I5d2e5d1efd67cb5f9fb0659c6a71efd857c570a1 --- ts2panda/tests/builtIns.test.ts | 2 +- ts2panda/tests/commonjs.test.ts | 6 +-- ts2panda/tests/esmodule.test.ts | 2 +- ts2panda/tests/expression/arguments.test.ts | 4 +- ts2panda/tests/expression/commalist.test.ts | 2 +- .../expression/functionExpression.test.ts | 38 +++++++++---------- ts2panda/tests/expression/thisKeyWord.test.ts | 2 +- ts2panda/tests/hoist.test.ts | 19 +++++----- ts2panda/tests/lexenv.test.ts | 31 +++++++-------- .../statements/functionDeclaration.test.ts | 20 +++++----- .../statements/variableDeclaration.test.ts | 8 ++-- ts2panda/tests/types/array.test.ts | 12 +++--- ts2panda/tests/types/class.test.ts | 16 ++++---- ts2panda/tests/types/function.test.ts | 10 ++--- ts2panda/tests/types/object.test.ts | 4 +- ts2panda/tests/types/primitives.test.ts | 14 +++---- ts2panda/tests/types/union.test.ts | 8 ++-- ts2panda/tests/utils/base.ts | 10 ++--- 18 files changed, 105 insertions(+), 103 deletions(-) diff --git a/ts2panda/tests/builtIns.test.ts b/ts2panda/tests/builtIns.test.ts index 590a3131b2..ace7fc1c21 100644 --- a/ts2panda/tests/builtIns.test.ts +++ b/ts2panda/tests/builtIns.test.ts @@ -45,7 +45,7 @@ describe("FunctionToStringTest", function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compileAfter(`function foo() {return 123;}\nfunction bar() {return 321;}\n`, 'toStringTest.js'); CmdOptions.needRecordSourceCode = () => {return false}; - let pandaGen = snippetCompiler.getPandaGenByName('UnitTest.foo'); + let pandaGen = snippetCompiler.getPandaGenByName('foo'); let expected = "function foo() {return 123;}"; expect(pandaGen.getSourceCode() == expected).to.be.true; }) diff --git a/ts2panda/tests/commonjs.test.ts b/ts2panda/tests/commonjs.test.ts index 119cce756f..f0148848a4 100644 --- a/ts2panda/tests/commonjs.test.ts +++ b/ts2panda/tests/commonjs.test.ts @@ -44,7 +44,7 @@ describe("CommonJsTest", function () { CmdOptions.isCommonJs = () => {return false}; let funcMainInsns = snippetCompiler.getGlobalInsns(); let expected = [ - new EcmaDefinefuncdyn('UnitTest.#1#', new Imm(5), new VReg()), + new EcmaDefinefuncdyn('#1#', new Imm(5), new VReg()), new StaDyn(new VReg()), new LdaDyn(new VReg()), new StaDyn(new VReg()), @@ -67,7 +67,7 @@ describe("CommonJsTest", function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compileCommonjs(`let a = require('a.js')`, 'cjs.js'); CmdOptions.isCommonJs = () => {return false}; - let execInsns = snippetCompiler.getPandaGenByName('UnitTest.#1#')!.getInsns(); + let execInsns = snippetCompiler.getPandaGenByName('#1#')!.getInsns(); let requirePara = new VReg(); let requireReg = new VReg(); let moduleRequest = new VReg(); @@ -88,7 +88,7 @@ describe("CommonJsTest", function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compileCommonjs(`let a = 1; exports.a = a;`, 'cjs.js'); CmdOptions.isCommonJs = () => {return false}; - let execInsns = snippetCompiler.getPandaGenByName('UnitTest.#1#')!.getInsns(); + let execInsns = snippetCompiler.getPandaGenByName('#1#')!.getInsns(); let exportsPara = new VReg(); let exportsReg = new VReg(); let tmpReg = new VReg(); diff --git a/ts2panda/tests/esmodule.test.ts b/ts2panda/tests/esmodule.test.ts index f88272059a..e28b9b6db4 100644 --- a/ts2panda/tests/esmodule.test.ts +++ b/ts2panda/tests/esmodule.test.ts @@ -45,7 +45,7 @@ describe("ExportDeclaration", function () { let classReg = new VReg(); let expected = [ new MovDyn(new VReg(), new VReg()), - new EcmaDefineclasswithbuffer("UnitTest.#1#C", new Imm(0), new Imm(0), new VReg(), new VReg()), + new EcmaDefineclasswithbuffer("#1#C", new Imm(0), new Imm(0), new VReg(), new VReg()), new StaDyn(classReg), new LdaDyn(classReg), new EcmaStmodulevar('C'), diff --git a/ts2panda/tests/expression/arguments.test.ts b/ts2panda/tests/expression/arguments.test.ts index 350836037e..3dd2fbd706 100644 --- a/ts2panda/tests/expression/arguments.test.ts +++ b/ts2panda/tests/expression/arguments.test.ts @@ -43,7 +43,7 @@ describe("arguments Keyword", function () { new EcmaLdobjbyindex(temp1, new Imm(0)), new EcmaReturnundefined() ]; - let functionPg = snippetCompiler.getPandaGenByName("UnitTest.foo"); + let functionPg = snippetCompiler.getPandaGenByName("foo"); let insns = functionPg!.getInsns(); expect(checkInstructions(insns, expected)).to.be.true; @@ -62,7 +62,7 @@ describe("arguments Keyword", function () { new EcmaLdobjbyindex(temp1, new Imm(0)), new EcmaReturnundefined() ]; - let functionPg = snippetCompiler.getPandaGenByName("UnitTest.foo"); + let functionPg = snippetCompiler.getPandaGenByName("foo"); let insns = functionPg!.getInsns(); expect(checkInstructions(insns, expected)).to.be.true; diff --git a/ts2panda/tests/expression/commalist.test.ts b/ts2panda/tests/expression/commalist.test.ts index 0681472412..5163fded64 100644 --- a/ts2panda/tests/expression/commalist.test.ts +++ b/ts2panda/tests/expression/commalist.test.ts @@ -54,7 +54,7 @@ describe("CommaListExpression", function () { let insns = snippetCompiler.getGlobalInsns(); let expected = [ new MovDyn(new VReg(), new VReg()), - new EcmaDefineclasswithbuffer("UnitTest.#1#Test", new Imm(0), new Imm(0), new VReg(), new VReg()), + new EcmaDefineclasswithbuffer("#1#Test", new Imm(0), new Imm(0), new VReg(), new VReg()), new StaDyn(new VReg()), new LdaDyn(new VReg()), new EcmaStclasstoglobalrecord("Test"), diff --git a/ts2panda/tests/expression/functionExpression.test.ts b/ts2panda/tests/expression/functionExpression.test.ts index f1b0624fd1..e04bb8ea3e 100644 --- a/ts2panda/tests/expression/functionExpression.test.ts +++ b/ts2panda/tests/expression/functionExpression.test.ts @@ -72,7 +72,7 @@ describe("compileFunctionExpression", function () { let checkCount = 0; pandaGens.forEach((pg) => { - if (pg.internalName == "UnitTest.test") { + if (pg.internalName == "test") { expect(checkInstructions(pg.getInsns(), expected_func), "check func insns").to.be.true; checkCount++; } @@ -90,15 +90,15 @@ describe("compileFunctionExpression", function () { let checkCount = 0; pandaGens.forEach((pg) => { - if (pg.internalName == "UnitTest.a") { + if (pg.internalName == "a") { checkCount++; } - if (pg.internalName == "UnitTest.func_main_0") { + if (pg.internalName == "func_main_0") { pg.getInsns().forEach((insns) => { if (insns instanceof EcmaDefinefuncdyn) { - expect(insns.operands[0]).to.equal('UnitTest.a'); + expect(insns.operands[0]).to.equal('a'); checkCount++; } }); @@ -118,15 +118,15 @@ describe("compileFunctionExpression", function () { let checkCount = 0; pandaGens.forEach((pg) => { - if (pg.internalName == "UnitTest.a") { + if (pg.internalName == "a") { checkCount++; } - if (pg.internalName == "UnitTest.func_main_0") { + if (pg.internalName == "func_main_0") { pg.getInsns().forEach((insns) => { if (insns instanceof EcmaDefinefuncdyn) { - expect(insns.operands[0]).to.equal('UnitTest.a'); + expect(insns.operands[0]).to.equal('a'); checkCount++; } }); @@ -146,15 +146,15 @@ describe("compileFunctionExpression", function () { let checkCount = 0; pandaGens.forEach((pg) => { - if (pg.internalName == "UnitTest.a") { + if (pg.internalName == "a") { checkCount++; } - if (pg.internalName == "UnitTest.func_main_0") { + if (pg.internalName == "func_main_0") { pg.getInsns().forEach((insns) => { if (insns instanceof EcmaDefinencfuncdyn) { - expect(insns.operands[0]).to.equal('UnitTest.a'); + expect(insns.operands[0]).to.equal('a'); checkCount++; } }); @@ -182,16 +182,16 @@ describe("compileFunctionExpression", function () { ]; pandaGens.forEach((pg) => { - if (pg.internalName == "UnitTest.p") { + if (pg.internalName == "p") { expect(checkInstructions(pg.getInsns(), expected_func), "check arrow func insns").to.be.true; checkCount++; } - if (pg.internalName == "UnitTest.func_main_0") { + if (pg.internalName == "func_main_0") { pg.getInsns().forEach((insns) => { if (insns instanceof EcmaDefinencfuncdyn) { - expect(insns.operands[0]).to.equal('UnitTest.p'); + expect(insns.operands[0]).to.equal('p'); checkCount++; } }); @@ -283,15 +283,15 @@ describe("compileFunctionExpression", function () { let checkCount = 0; pandaGens.forEach((pg) => { - if (pg.internalName == "UnitTest.a") { + if (pg.internalName == "a") { expect(checkInstructions(pg.getInsns(), expected_func), "check generator func insns").to.be.true; checkCount++; } - if (pg.internalName == "UnitTest.func_main_0") { + if (pg.internalName == "func_main_0") { pg.getInsns().forEach((insns) => { if (insns instanceof EcmaDefinegeneratorfunc) { - expect(insns.operands[0]).to.equal('UnitTest.a'); + expect(insns.operands[0]).to.equal('a'); checkCount++; } }); @@ -343,15 +343,15 @@ describe("compileFunctionExpression", function () { let checkCount = 0; pandaGens.forEach((pg) => { - if (pg.internalName == "UnitTest.a") { + if (pg.internalName == "a") { expect(checkInstructions(pg.getInsns(), expected_func), "check async func insns").to.be.true; checkCount++; } - if (pg.internalName == "UnitTest.func_main_0") { + if (pg.internalName == "func_main_0") { pg.getInsns().forEach((insns) => { if (insns instanceof EcmaDefinencfuncdyn) { - expect(insns.operands[0]).to.equal('UnitTest.a'); + expect(insns.operands[0]).to.equal('a'); checkCount++; } }); diff --git a/ts2panda/tests/expression/thisKeyWord.test.ts b/ts2panda/tests/expression/thisKeyWord.test.ts index b55be1d511..186c2d2b94 100644 --- a/ts2panda/tests/expression/thisKeyWord.test.ts +++ b/ts2panda/tests/expression/thisKeyWord.test.ts @@ -50,7 +50,7 @@ describe("ThisKeyword", function () { it("this in function scope", function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compile("function a() {this}"); - let functionPg = snippetCompiler.getPandaGenByName("UnitTest.a"); + let functionPg = snippetCompiler.getPandaGenByName("a"); let functionScope = functionPg!.getScope(); let insns = compileMainSnippet("this;", pandaGen, functionScope); let expected = [ diff --git a/ts2panda/tests/hoist.test.ts b/ts2panda/tests/hoist.test.ts index e048a0eca7..ffd5a7fe4d 100644 --- a/ts2panda/tests/hoist.test.ts +++ b/ts2panda/tests/hoist.test.ts @@ -29,6 +29,7 @@ import { LdaDyn, LdaiDyn, LdaStr, + ResultType, StaDyn, VReg } from "../src/irnodes"; @@ -78,7 +79,7 @@ describe("HoistTest", function () { let insns = snippetCompiler.getGlobalInsns(); let expected = [ - new EcmaDefinefuncdyn("UnitTest.a", new Imm(0), new VReg()), + new EcmaDefinefuncdyn("a", new Imm(0), new VReg()), new EcmaStglobalvar("a"), new EcmaReturnundefined() ] @@ -92,7 +93,7 @@ describe("HoistTest", function () { let insns = snippetCompiler.getGlobalInsns(); let expected = [ - new EcmaDefinefuncdyn("UnitTest.#2#a", new Imm(0), new VReg()), + new EcmaDefinefuncdyn("#2#a", new Imm(0), new VReg()), new EcmaStglobalvar("a"), new EcmaReturnundefined() ] @@ -106,7 +107,7 @@ describe("HoistTest", function () { snippetCompiler.compile(`var a = 1; function a() {}`); let insns = snippetCompiler.getGlobalInsns(); let expected = [ - new EcmaDefinefuncdyn("UnitTest.a", new Imm(0), new VReg()), + new EcmaDefinefuncdyn("a", new Imm(0), new VReg()), new EcmaStglobalvar("a"), new LdaiDyn(new Imm(1)), new EcmaStglobalvar("a"), @@ -120,7 +121,7 @@ describe("HoistTest", function () { it('case 6', function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compile(`function a() {var a = 1;}`); - let funcPg = snippetCompiler.getPandaGenByName("UnitTest.a"); + let funcPg = snippetCompiler.getPandaGenByName("a"); let insns = funcPg!.getInsns(); let a = new VReg(); @@ -139,11 +140,11 @@ describe("HoistTest", function () { it('case 7', function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compile(`function a() {function b() {}};`); - let funcPg = snippetCompiler.getPandaGenByName("UnitTest.a"); + let funcPg = snippetCompiler.getPandaGenByName("a"); let insns = funcPg!.getInsns(); let a = new VReg(); let expected = [ - new EcmaDefinefuncdyn("UnitTest.b", new Imm(0), new VReg()), + new EcmaDefinefuncdyn("b", new Imm(0), new VReg()), new StaDyn(a), new EcmaReturnundefined() @@ -157,7 +158,7 @@ describe("HoistTest", function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compile(`a = 1; let a;`); - let funcPg = snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let funcPg = snippetCompiler.getPandaGenByName("func_main_0"); let insns = funcPg!.getInsns(); let idReg = new VReg(); let expected = [ @@ -176,7 +177,7 @@ describe("HoistTest", function () { a = 1; let a; }`); - let funcPg = snippetCompiler.getPandaGenByName("UnitTest.b"); + let funcPg = snippetCompiler.getPandaGenByName("b"); let insns = funcPg!.getInsns(); let idReg = new VReg(); @@ -196,7 +197,7 @@ describe("HoistTest", function () { a = 1; let a; }`); - let funcPg = snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let funcPg = snippetCompiler.getPandaGenByName("func_main_0"); let insns = funcPg!.getInsns(); let idReg = new VReg(); diff --git a/ts2panda/tests/lexenv.test.ts b/ts2panda/tests/lexenv.test.ts index ec6c337aae..a2180a6a15 100644 --- a/ts2panda/tests/lexenv.test.ts +++ b/ts2panda/tests/lexenv.test.ts @@ -39,6 +39,7 @@ import { LdaDyn, LdaiDyn, LdaStr, + ResultType, ReturnDyn, StaDyn, VReg @@ -115,7 +116,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { it("test CompilerDriver.scanFunctions-with-empty", function () { let source: string = ``; let sourceFile = creatAstFromSnippet(source); - let compilerDriver = new CompilerDriver('UnitTest', 'UnitTest'); + let compilerDriver = new CompilerDriver('UnitTest'); let globalScope = new GlobalScope(sourceFile); let recorder = new Recorder(sourceFile, globalScope, compilerDriver, false, false, true); recorder.record(); @@ -143,7 +144,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { var funcExpression = function() { } `; let sourceFile = creatAstFromSnippet(source); - let compilerDriver = new CompilerDriver('UnitTest', 'UnitTest'); + let compilerDriver = new CompilerDriver('UnitTest'); let globalScope = new GlobalScope(sourceFile); let recorder = new Recorder(sourceFile, globalScope, compilerDriver, false, false, true); recorder.record(); @@ -190,7 +191,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { let source: string = ` `; let sourceFile = creatAstFromSnippet(source); - let compilerDriver = new CompilerDriver('UnitTest', 'UnitTest'); + let compilerDriver = new CompilerDriver('UnitTest'); let globalScope = new GlobalScope(sourceFile); let recorder = new Recorder(sourceFile, globalScope, compilerDriver, false, false, true); @@ -214,7 +215,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { var funcExt = function() { } `; let sourceFile = creatAstFromSnippet(source); - let compilerDriver = new CompilerDriver('UnitTest', 'UnitTest'); + let compilerDriver = new CompilerDriver('UnitTest'); let globalScope = new GlobalScope(sourceFile); let recorder = new Recorder(sourceFile, globalScope, compilerDriver, false, false, true); @@ -268,7 +269,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { }))) `; let sourceFile = creatAstFromSnippet(source); - let compilerDriver = new CompilerDriver('UnitTest', 'UnitTest'); + let compilerDriver = new CompilerDriver('UnitTest'); let globalScope = new GlobalScope(sourceFile); let recorder = new Recorder(sourceFile, globalScope, compilerDriver, false, false, true); @@ -411,7 +412,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { let expected_main = [ new LdaDyn(new VReg()), new EcmaStglobalvar("outer"), - new EcmaDefinefuncdyn("UnitTest.func", new Imm(0), new VReg()), + new EcmaDefinefuncdyn("func", new Imm(0), new VReg()), new EcmaStglobalvar("func"), new LdaiDyn(new Imm(1)), new EcmaStglobalvar("outer"), @@ -424,9 +425,9 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { ]; pandaGens.forEach((pg) => { - if (pg.internalName == "UnitTest.func_main_0") { + if (pg.internalName == "func_main_0") { expect(checkInstructions(pg.getInsns(), expected_main)).to.be.true; - } else if (pg.internalName == "UnitTest.func") { + } else if (pg.internalName == "func") { expect(checkInstructions(pg.getInsns(), expected_func)).to.be.true; } }) @@ -446,7 +447,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { let pandaGens = compileAllSnippet(source, passes); let expected_main = [ ...insnsCreateLexEnv_main, - new EcmaDefinefuncdyn("UnitTest.func", new Imm(0), new VReg()), + new EcmaDefinefuncdyn("func", new Imm(0), new VReg()), new EcmaStglobalvar("func"), // global.func = func_func_1 new LdaiDyn(new Imm(1)), // value = 1 // ...insnsStoreLexVar_main, @@ -464,11 +465,11 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { pandaGens.forEach((pg) => { let scope = pg.getScope(); - if (pg.internalName == "UnitTest.func_main_0") { + if (pg.internalName == "func_main_0") { expect(checkInstructions(pg.getInsns(), expected_main), "check main insns").to.be.true; expect(scope.getNumLexEnv(), "main scope has 0 lexvar").to.be.equal(0); // expect(scope.hasLexEnv(), "main scope has lexenv").to.be.true; - } else if (pg.internalName == "UnitTest.func") { + } else if (pg.internalName == "func") { expect(checkInstructions(pg.getInsns(), expected_func), "check func insns").to.be.true; expect(scope.getNumLexEnv(), "func scope has 1 lexvar").to.be.equal(0); @@ -504,7 +505,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { new LdaDyn(new VReg()), new StaDyn(new VReg()), ...insnsStoreLexVar_outer_2, - new EcmaDefinefuncdyn("UnitTest.#1#", new Imm(0), new VReg()), + new EcmaDefinefuncdyn("#1#", new Imm(0), new VReg()), // returnStatement new StaDyn(new VReg()), new LdaDyn(new VReg()), @@ -535,13 +536,13 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { snippetCompiler.compile(source, passes); // check compile result! - let outerPg = snippetCompiler.getPandaGenByName("UnitTest.outer"); + let outerPg = snippetCompiler.getPandaGenByName("outer"); let outerScope = outerPg!.getScope(); let outerA = outerScope!.findLocal("a"); expect(outerA instanceof LocalVariable, "a in outer is local variable").to.be.true; // expect((outerScope).hasLexEnv(), "outer scope need to create lex env").to.be.true; expect((outerScope).getNumLexEnv(), "number of lexvar at outer scope").to.be.equal(2); - let anonymousPg = snippetCompiler.getPandaGenByName("UnitTest.#1#"); + let anonymousPg = snippetCompiler.getPandaGenByName("#1#"); let anonymousScope = anonymousPg!.getScope(); let anonymousA = anonymousScope!.findLocal("a"); let searchRlt = anonymousScope!.find("a"); @@ -550,7 +551,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { expect(anonymousA, "no a in anonymous function").to.be.undefined; // expect((anonymousScope).hasLexEnv(), "anonymous scope had lex env").to.be.true; expect((anonymousScope).getNumLexEnv()).to.be.equal(0); - let globalPg = snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let globalPg = snippetCompiler.getPandaGenByName("func_main_0"); let globalScope = globalPg!.getScope(); let globalA = globalScope!.findLocal("a"); expect(globalA instanceof GlobalVariable, "globalA is GlobalVariable").to.be.true; diff --git a/ts2panda/tests/statements/functionDeclaration.test.ts b/ts2panda/tests/statements/functionDeclaration.test.ts index 079b05e8e4..3c9b990385 100644 --- a/ts2panda/tests/statements/functionDeclaration.test.ts +++ b/ts2panda/tests/statements/functionDeclaration.test.ts @@ -29,6 +29,7 @@ import { Label, LdaDyn, LdaiDyn, + ResultType, StaDyn, VReg } from "../../src/irnodes"; @@ -42,10 +43,9 @@ describe("FunctionDeclarationTest", function () { it('function definition in the global scope', function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compile("function foo() {}"); - let funcInternalName = "UnitTest.foo"; let funcName = "foo"; let expected = [ - new EcmaDefinefuncdyn(funcInternalName, new Imm(0), new VReg()), + new EcmaDefinefuncdyn(funcName, new Imm(0), new VReg()), new EcmaStglobalvar(funcName), new EcmaReturnundefined() ]; @@ -64,7 +64,7 @@ describe("FunctionDeclarationTest", function () { function foo() {} `); let expected = [ - new EcmaDefinefuncdyn("UnitTest.#2#foo", new Imm(0), new VReg()), + new EcmaDefinefuncdyn("#2#foo", new Imm(0), new VReg()), new EcmaStglobalvar("foo"), new EcmaReturnundefined() ]; @@ -81,12 +81,12 @@ describe("FunctionDeclarationTest", function () { snippetCompiler.compile(`function out() {function foo() {}}`); let funcReg = new VReg(); let expected = [ - new EcmaDefinefuncdyn("UnitTest.foo", new Imm(0), new VReg()), + new EcmaDefinefuncdyn("foo", new Imm(0), new VReg()), new StaDyn(funcReg), new EcmaReturnundefined() ]; - let functionPg = snippetCompiler.getPandaGenByName("UnitTest.out"); + let functionPg = snippetCompiler.getPandaGenByName("out"); let insns = functionPg!.getInsns(); let functionScope = functionPg!.getScope(); @@ -103,7 +103,7 @@ describe("FunctionDeclarationTest", function () { snippetCompiler.compile("let foo = function() {}"); let insns = snippetCompiler.getGlobalInsns(); let expected = [ - new EcmaDefinefuncdyn("UnitTest.foo", new Imm(0), new VReg()), + new EcmaDefinefuncdyn("foo", new Imm(0), new VReg()), new EcmaStlettoglobalrecord("foo"), new EcmaReturnundefined() ]; @@ -117,7 +117,7 @@ describe("FunctionDeclarationTest", function () { let endLabel = new Label(); let expected_main = [ - new EcmaDefinefuncdyn("UnitTest.test", new Imm(1), new VReg()), + new EcmaDefinefuncdyn("test", new Imm(1), new VReg()), new EcmaStglobalvar("test"), new EcmaReturnundefined() ]; @@ -133,10 +133,10 @@ describe("FunctionDeclarationTest", function () { ]; compilerunit.forEach(element => { - if (element.internalName == "UnitTest.func_main_0") { + if (element.internalName == "func_main_0") { let insns = element.getInsns(); expect(checkInstructions(insns, expected_main)).to.be.true; - } else if (element.internalName == "UnitTest.test") { + } else if (element.internalName == "test") { let insns = element.getInsns(); expect(checkInstructions(insns, expected_func)).to.be.true; let parameterLength = element.getParameterLength(); @@ -158,7 +158,7 @@ describe("FunctionDeclarationTest", function () { new EcmaReturnundefined(), ]; - let functionPg = snippetCompiler.getPandaGenByName("UnitTest.test"); + let functionPg = snippetCompiler.getPandaGenByName("test"); let insns = functionPg!.getInsns(); expect(checkInstructions(insns, expected_func)).to.be.true; diff --git a/ts2panda/tests/statements/variableDeclaration.test.ts b/ts2panda/tests/statements/variableDeclaration.test.ts index 2e64168b4d..1ce753c2d0 100644 --- a/ts2panda/tests/statements/variableDeclaration.test.ts +++ b/ts2panda/tests/statements/variableDeclaration.test.ts @@ -154,7 +154,7 @@ describe("VariableDeclarationTest", function () { it('var i in a function scope', function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compile("function a() {var i;}"); - let funcPg = snippetCompiler.getPandaGenByName("UnitTest.a"); + let funcPg = snippetCompiler.getPandaGenByName("a"); let functionScope = funcPg!.getScope(); let insns = funcPg!.getInsns(); let expected = [ @@ -172,7 +172,7 @@ describe("VariableDeclarationTest", function () { it('let i in a function scope', function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compile("function a() {let i;}"); - let funcPg = snippetCompiler.getPandaGenByName("UnitTest.a"); + let funcPg = snippetCompiler.getPandaGenByName("a"); let functionScope = funcPg!.getScope(); let insns = funcPg!.getInsns(); let expected = [ @@ -188,7 +188,7 @@ describe("VariableDeclarationTest", function () { it('const i in a function scope', function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compile("function a() {const i = 5;}"); - let funcPg = snippetCompiler.getPandaGenByName("UnitTest.a"); + let funcPg = snippetCompiler.getPandaGenByName("a"); let functionScope = funcPg!.getScope(); let insns = funcPg!.getInsns(); let expected = [ @@ -204,7 +204,7 @@ describe("VariableDeclarationTest", function () { it('let i in a local scope', function () { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compile("{let i;}"); - let funcPg = snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let funcPg = snippetCompiler.getPandaGenByName("func_main_0"); let localScope = funcPg!.getScope(); let insns = funcPg!.getInsns(); diff --git a/ts2panda/tests/types/array.test.ts b/ts2panda/tests/types/array.test.ts index 9742c7faed..edaf90fdfa 100644 --- a/ts2panda/tests/types/array.test.ts +++ b/ts2panda/tests/types/array.test.ts @@ -30,7 +30,7 @@ describe("array tests in array.test.ts", function() { it("test array with primitives", function() { let fileNames = 'tests/types/array/array_primitives.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -75,7 +75,7 @@ describe("array tests in array.test.ts", function() { it("test array with class", function() { let fileNames = 'tests/types/array/array_class.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -108,7 +108,7 @@ describe("array tests in array.test.ts", function() { it("test array with multi same primitive", function() { let fileNames = 'tests/types/array/array_multi_same_primi.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -159,7 +159,7 @@ describe("array tests in array.test.ts", function() { it("test array with multi same class", function() { let fileNames = 'tests/types/array/array_multi_same_class.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -193,7 +193,7 @@ describe("array tests in array.test.ts", function() { it("test array with union", function() { let fileNames = 'tests/types/array/array_union.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -222,7 +222,7 @@ describe("array tests in array.test.ts", function() { it("test array with object", function() { let fileNames = 'tests/types/array/array_object.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ diff --git a/ts2panda/tests/types/class.test.ts b/ts2panda/tests/types/class.test.ts index 7fa9db6c9b..6f076b68e6 100644 --- a/ts2panda/tests/types/class.test.ts +++ b/ts2panda/tests/types/class.test.ts @@ -30,7 +30,7 @@ describe("class tests in class.test.ts", function () { it("test class with no parameter in block", function () { let fileNames = 'tests/types/class/class_constr_no_para.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -66,7 +66,7 @@ describe("class tests in class.test.ts", function () { it("test class with parameter in block", function () { let fileNames = 'tests/types/class/class_constr_para.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -102,7 +102,7 @@ describe("class tests in class.test.ts", function () { it("test class fields type", function () { let fileNames = 'tests/types/class/class_fields.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -136,7 +136,7 @@ describe("class tests in class.test.ts", function () { it("test class methods type", function () { let fileNames = 'tests/types/class/class_methods.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -176,7 +176,7 @@ describe("class tests in class.test.ts", function () { it("test class static fields type", function () { let fileNames = 'tests/types/class/class_static_fields.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -210,7 +210,7 @@ describe("class tests in class.test.ts", function () { it("test class static methods type", function () { let fileNames = 'tests/types/class/class_static_methods.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -252,7 +252,7 @@ describe("class tests in class.test.ts", function () { it("test abstract class type", function () { let fileNames = 'tests/types/class/class_abstract.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -297,7 +297,7 @@ describe("class tests in class.test.ts", function () { it("test class implements type", function () { let fileNames = 'tests/types/class/class_implements.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ diff --git a/ts2panda/tests/types/function.test.ts b/ts2panda/tests/types/function.test.ts index a9ebb11ad8..563e2b4c00 100644 --- a/ts2panda/tests/types/function.test.ts +++ b/ts2panda/tests/types/function.test.ts @@ -30,7 +30,7 @@ describe("function tests in function.test.ts", function () { it("test function with no parameter", function () { let fileNames = 'tests/types/function/function_no_para.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -60,7 +60,7 @@ describe("function tests in function.test.ts", function () { it("test function with muti parameter", function () { let fileNames = 'tests/types/function/function_multi_para.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -92,7 +92,7 @@ describe("function tests in function.test.ts", function () { it("test function with same type of paras and return", function () { let fileNames = 'tests/types/function/function_same_para_and_return.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -131,7 +131,7 @@ describe("function tests in function.test.ts", function () { it("test function with class as parameter", function () { let fileNames = 'tests/types/function/function_class_para.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -172,7 +172,7 @@ describe("function tests in function.test.ts", function () { it("test function with class as return", function () { let fileNames = 'tests/types/function/function_class_return.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ diff --git a/ts2panda/tests/types/object.test.ts b/ts2panda/tests/types/object.test.ts index 9d10d53062..eae94789e7 100644 --- a/ts2panda/tests/types/object.test.ts +++ b/ts2panda/tests/types/object.test.ts @@ -30,7 +30,7 @@ describe("object tests in object.test.ts", function() { it("test object with primitives", function() { let fileNames = 'tests/types/object/object_primi.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -56,7 +56,7 @@ describe("object tests in object.test.ts", function() { it("test object with user defined type", function() { let fileNames = 'tests/types/object/object_class.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ diff --git a/ts2panda/tests/types/primitives.test.ts b/ts2panda/tests/types/primitives.test.ts index 9fab6e6a77..d05b7c1ba2 100644 --- a/ts2panda/tests/types/primitives.test.ts +++ b/ts2panda/tests/types/primitives.test.ts @@ -30,7 +30,7 @@ describe("primitives tests in primitives.test.ts", function() { it("test primitives in block", function() { let fileNames = 'tests/types/primitives/primitives_in_block.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -60,7 +60,7 @@ describe("primitives tests in primitives.test.ts", function() { it("test number in function", function() { let fileNames = 'tests/types/primitives/primitives_in_function.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.numberFunc"); + let functionPg = result.snippetCompiler.getPandaGenByName("numberFunc"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -100,7 +100,7 @@ describe("primitives tests in primitives.test.ts", function() { it("test primitives in for", function() { let fileNames = 'tests/types/primitives/primitives_in_for.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -131,7 +131,7 @@ describe("primitives tests in primitives.test.ts", function() { it("test primitives in if", function() { let fileNames = 'tests/types/primitives/primitives_in_if.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -161,7 +161,7 @@ describe("primitives tests in primitives.test.ts", function() { it("test primitives in class", function() { let fileNames = 'tests/types/primitives/primitives_in_class.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -198,7 +198,7 @@ describe("primitives tests in primitives.test.ts", function() { it("test primitives with only type annotations", function() { let fileNames = 'tests/types/primitives/primitives_only_type_annotation.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -226,7 +226,7 @@ describe("primitives tests in primitives.test.ts", function() { it("test primitives without type annotations", function() { let fileNames = 'tests/types/primitives/primitives_no_type_annotation.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ diff --git a/ts2panda/tests/types/union.test.ts b/ts2panda/tests/types/union.test.ts index ec68027356..a1dc513747 100644 --- a/ts2panda/tests/types/union.test.ts +++ b/ts2panda/tests/types/union.test.ts @@ -30,7 +30,7 @@ describe("union tests in union.test.ts", function () { it("test union with primitives", function () { let fileNames = 'tests/types/union/union_primitives.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -68,7 +68,7 @@ describe("union tests in union.test.ts", function () { it("test union with user defined type", function () { let fileNames = 'tests/types/union/union_userDefinedType.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -104,7 +104,7 @@ describe("union tests in union.test.ts", function () { it("test union with multi same primitives", function () { let fileNames = 'tests/types/union/union_multi_same_primi.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ @@ -130,7 +130,7 @@ describe("union tests in union.test.ts", function () { it("test union with multi same user defined type", function () { let fileNames = 'tests/types/union/union_multi_userDefinedType.ts'; let result = compileTsWithType(fileNames); - let functionPg = result.snippetCompiler.getPandaGenByName("UnitTest.func_main_0"); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ diff --git a/ts2panda/tests/utils/base.ts b/ts2panda/tests/utils/base.ts index 49c7c5b52d..2d9f7ed318 100644 --- a/ts2panda/tests/utils/base.ts +++ b/ts2panda/tests/utils/base.ts @@ -146,7 +146,7 @@ export function compileAllSnippet(snippet: string, passes?: Pass[], literalBuffe jshelpers.bindSourceFile(sourceFile, {}); CmdOptions.isWatchEvaluateExpressionMode() ? setGlobalStrict(true) : setGlobalStrict(jshelpers.isEffectiveStrictModeSourceFile(sourceFile, compileOptions)); - let compilerDriver = new CompilerDriver('UnitTest', 'UnitTest'); + let compilerDriver = new CompilerDriver('UnitTest'); if (!passes) { passes = []; @@ -166,7 +166,7 @@ export function compileMainSnippet(snippet: string, pandaGen?: PandaGen, scope?: // only return main function if (compileFunc) { compileUnits.filter((pg) => { - return (pg.internalName == "UnitTest.func_main_0"); + return (pg.internalName == "func_main_0"); }) } @@ -191,7 +191,7 @@ export function compileAfterSnippet(snippet: string, name:string, isCommonJs: bo } jshelpers.bindSourceFile(sourceFile, {}); setGlobalStrict(jshelpers.isEffectiveStrictModeSourceFile(sourceFile, compileOptions)); - let compilerDriver = new CompilerDriver('UnitTest', 'UnitTest'); + let compilerDriver = new CompilerDriver('UnitTest'); compilerDriver.setCustomPasses([]); compilerDriver.compileUnitTest(sourceFile, []); compileUnits = compilerDriver.getCompilationUnits(); @@ -228,7 +228,7 @@ export class SnippetCompiler { } getGlobalInsns(): IRNode[] { - let root = this.getPandaGenByName("UnitTest.func_main_0"); + let root = this.getPandaGenByName("func_main_0"); if (root) { return root.getInsns(); } else { @@ -237,7 +237,7 @@ export class SnippetCompiler { } getGlobalScope(): Scope | undefined { - let globalPandaGen = this.getPandaGenByName("UnitTest.func_main_0"); + let globalPandaGen = this.getPandaGenByName("func_main_0"); return globalPandaGen ? globalPandaGen.getScope()!.getNearestVariableScope() : undefined; } -- Gitee From 88833cf94c94410f31ce44a04286fd13ccf77709 Mon Sep 17 00:00:00 2001 From: hufeng Date: Mon, 29 Aug 2022 12:05:36 +0800 Subject: [PATCH 21/23] Revert ts2abc's adaption Signed-off-by: hufeng Change-Id: I6a41c5806a85179a9f55506f22267d5821b9e5e2 --- ts2panda/src/base/typeSystem.ts | 30 +++++++++++++++--------------- ts2panda/src/cmdOptions.ts | 13 ------------- ts2panda/src/compilerDriver.ts | 15 ++++++--------- ts2panda/src/index.ts | 31 +++++++++---------------------- ts2panda/src/pandasm.ts | 16 +++++++++++++++- ts2panda/src/ts2panda.ts | 21 +++------------------ 6 files changed, 48 insertions(+), 78 deletions(-) diff --git a/ts2panda/src/base/typeSystem.ts b/ts2panda/src/base/typeSystem.ts index 0167dfe2dd..3920efbff3 100644 --- a/ts2panda/src/base/typeSystem.ts +++ b/ts2panda/src/base/typeSystem.ts @@ -407,7 +407,7 @@ export class ClassType extends BaseType { classTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.extendsHeritage)); classTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.implementsHeritages.length)); this.implementsHeritages.forEach(heritage => { - classTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, heritage)); + classTypeLiterals.push(new Literal(LiteralTag.INTEGER, heritage)); }); // record unstatic fields and methods @@ -428,7 +428,7 @@ export class ClassType extends BaseType { classTypeLiterals.push(new Literal(LiteralTag.INTEGER, transferredTarget.size)); transferredTarget.forEach((typeInfo, name) => { classTypeLiterals.push(new Literal(LiteralTag.STRING, name)); - classTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, typeInfo[0])); // typeIndex + classTypeLiterals.push(new Literal(LiteralTag.INTEGER, typeInfo[0])); // typeIndex classTypeLiterals.push(new Literal(LiteralTag.INTEGER, typeInfo[1])); // accessFlag classTypeLiterals.push(new Literal(LiteralTag.INTEGER, typeInfo[2])); // readonly }); @@ -440,7 +440,7 @@ export class ClassType extends BaseType { classTypeLiterals.push(new Literal(LiteralTag.INTEGER, transferredTarget.size)); transferredTarget.forEach((typeInfo, name) => { classTypeLiterals.push(new Literal(LiteralTag.STRING, name)); - classTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, typeInfo)); + classTypeLiterals.push(new Literal(LiteralTag.INTEGER, typeInfo)); }); } } @@ -462,7 +462,7 @@ export class ClassInstType extends BaseType { let classInstLiterals: Array = new Array(); classInstLiterals.push(new Literal(LiteralTag.INTEGER, L2Type.CLASSINST)); - classInstLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, this.shiftedReferredClassIndex)); + classInstLiterals.push(new Literal(LiteralTag.INTEGER, this.shiftedReferredClassIndex)); classInstBuf.addLiterals(...classInstLiterals); return classInstBuf; @@ -570,17 +570,17 @@ export class FunctionType extends BaseType { funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.parameters[0])); funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.parameters.length - 1)); for (let i = 1; i < this.parameters.length; i++) { - funcTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, this.parameters[i])); + funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.parameters[i])); } } else { funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, 0)); // marker for not having 'this' param funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.parameters.length)); for (let i = 0; i < this.parameters.length; i++) { - funcTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, this.parameters[i])); + funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.parameters[i])); } } - funcTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, this.returnType)); + funcTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.returnType)); funcTypeBuf.addLiterals(...funcTypeLiterals); return funcTypeBuf; } @@ -657,7 +657,7 @@ export class UnionType extends BaseType { UnionTypeLiterals.push(new Literal(LiteralTag.INTEGER, L2Type.UNION)); UnionTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.unionedTypeArray.length)); for (let type of this.unionedTypeArray) { - UnionTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, type)); + UnionTypeLiterals.push(new Literal(LiteralTag.INTEGER, type)); } UnionTypeBuf.addLiterals(...UnionTypeLiterals); return UnionTypeBuf; @@ -702,7 +702,7 @@ export class ArrayType extends BaseType { let arrayBuf = new LiteralBuffer(); let arrayLiterals: Array = new Array(); arrayLiterals.push(new Literal(LiteralTag.INTEGER, L2Type.ARRAY)); - arrayLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, this.referedTypeIndex)); + arrayLiterals.push(new Literal(LiteralTag.INTEGER, this.referedTypeIndex)); arrayBuf.addLiterals(...arrayLiterals); return arrayBuf; } @@ -737,7 +737,7 @@ export class ObjectType extends BaseType { objLiterals.push(new Literal(LiteralTag.INTEGER, this.properties.size)); this.properties.forEach((typeIndex, name) => { objLiterals.push(new Literal(LiteralTag.STRING, name)); - objLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, typeIndex)); + objLiterals.push(new Literal(LiteralTag.INTEGER, typeIndex)); }); objTypeBuf.addLiterals(...objLiterals); return objTypeBuf; @@ -847,7 +847,7 @@ export class InterfaceType extends BaseType { interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.heritages.length)); this.heritages.forEach(heritage => { - interfaceTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, heritage)); + interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, heritage)); }); // record fields and methods @@ -864,7 +864,7 @@ export class InterfaceType extends BaseType { interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, transferredTarget.size)); transferredTarget.forEach((typeInfo, name) => { interfaceTypeLiterals.push(new Literal(LiteralTag.STRING, name)); - interfaceTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, typeInfo[0])); // typeIndex + interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, typeInfo[0])); // typeIndex interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, typeInfo[1])); // accessFlag interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, typeInfo[2])); // readonly }); @@ -875,7 +875,7 @@ export class InterfaceType extends BaseType { interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, transferredTarget.length)); transferredTarget.forEach(method => { - interfaceTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, method)); + interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, method)); }); } } @@ -904,10 +904,10 @@ export class BuiltinContainerType extends BaseType { let UnionTypeBuf = new LiteralBuffer(); let UnionTypeLiterals: Array = new Array(); UnionTypeLiterals.push(new Literal(LiteralTag.INTEGER, L2Type.BUILTINCONTAINER)); - UnionTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, this.builtinTypeIndex)); + UnionTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.builtinTypeIndex)); UnionTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.containerArray.length)); for (let type of this.containerArray) { - UnionTypeLiterals.push(new Literal(LiteralTag.LITERALBUFFERINDEX, type)); + UnionTypeLiterals.push(new Literal(LiteralTag.INTEGER, type)); } UnionTypeBuf.addLiterals(...UnionTypeLiterals); return UnionTypeBuf; diff --git a/ts2panda/src/cmdOptions.ts b/ts2panda/src/cmdOptions.ts index d2d740ef84..87064a12c1 100644 --- a/ts2panda/src/cmdOptions.ts +++ b/ts2panda/src/cmdOptions.ts @@ -50,8 +50,6 @@ const ts2pandaOptions = [ { name: 'function-sourcecode', type: Boolean, defaultValue: false, description: "Record functions' sourceCode to support the feature of [function].toString()" }, { name: 'expression-watch-toolchain', type: String, defaultValue: "es2panda", description: "Specify the tool chain used to transform the expression" }, { name: 'source-file', type: String, defaultValue: "", description: "specify the file path info recorded in generated abc" }, - { name: 'record-name', type: String, defaultValue: "", description: "specify the record name." }, - { name: 'output-proto', type: String, defaultValue: "", description: "Compiler proto serialize binary output (.proto)" } ] @@ -210,13 +208,6 @@ export class CmdOptions { return outputFile; } - static getRecordName(): string { - if (!this.options) { - return ""; - } - return this.options["record-name"]; - } - static getTimeOut(): Number { if (!this.options) { return 0; @@ -315,10 +306,6 @@ export class CmdOptions { static getSourceFile(): string { return this.options["source-file"]; } - - static getOutputproto(): string { - return this.options["output-proto"]; - } // @ts-ignore static parseUserCmd(args: string[]): ts.ParsedCommandLine | undefined { diff --git a/ts2panda/src/compilerDriver.ts b/ts2panda/src/compilerDriver.ts index ac3c7a8110..66747fbe58 100644 --- a/ts2panda/src/compilerDriver.ts +++ b/ts2panda/src/compilerDriver.ts @@ -61,7 +61,6 @@ export class PendingCompilationUnit { export class CompilerDriver { static isTsFile: boolean = false; private fileName: string; - private recordName: string; private passes: Pass[] = []; private compilationUnits: PandaGen[]; pendingCompilationUnits: PendingCompilationUnit[]; @@ -71,9 +70,8 @@ export class CompilerDriver { private needDumpHeader: boolean = true; private ts2abcProcess: any = undefined; - constructor(fileName: string, recordName: string) { + constructor(fileName: string) { this.fileName = fileName; - this.recordName = recordName; // register passes here this.passes = [ new CacheExpander(), @@ -177,7 +175,6 @@ export class CompilerDriver { listenErrorEvent(ts2abcProc); try { - Ts2Panda.dumpRecord(ts2abcProc, this.recordName); Ts2Panda.dumpCmdOptions(ts2abcProc); for (let i = 0; i < this.pendingCompilationUnits.length; i++) { @@ -363,13 +360,13 @@ export class CompilerDriver { if (name == '') { if ((ts.isFunctionDeclaration(node) && hasExportKeywordModifier(node) && hasDefaultKeywordModifier(node)) || ts.isExportAssignment(findOuterNodeOfParenthesis(node))) { - return `${this.recordName}.default`; + return 'default'; } - return `${this.recordName}.#${this.getFuncId(funcNode)}#`; + return `#${this.getFuncId(funcNode)}#`; } if (name == "func_main_0") { - return `${this.recordName}.#${this.getFuncId(funcNode)}#${name}`; + return `#${this.getFuncId(funcNode)}#${name}`; } let funcNameMap = recorder.getFuncNameMap(); @@ -386,7 +383,7 @@ export class CompilerDriver { name = `#${this.getFuncId(funcNode)}#` } } - return `${this.recordName}.${name}`; + return name; } getInternalNameForCtor(node: ts.ClassLikeDeclaration, ctor: ts.ConstructorDeclaration) { @@ -395,7 +392,7 @@ export class CompilerDriver { if (name.lastIndexOf(".") != -1) { name = `#${this.getFuncId(ctor)}#` } - return `${this.recordName}.${name}`; + return name; } writeBinaryFile(pandaGen: PandaGen) { diff --git a/ts2panda/src/index.ts b/ts2panda/src/index.ts index 8cae20dcff..944570172b 100644 --- a/ts2panda/src/index.ts +++ b/ts2panda/src/index.ts @@ -45,7 +45,7 @@ function checkIsGlobalDeclaration(sourceFile: ts.SourceFile) { function generateDTs(node: ts.SourceFile, options: ts.CompilerOptions) { let outputBinName = getOutputBinName(node); - let compilerDriver = new CompilerDriver(outputBinName, getRecordName(node)); + let compilerDriver = new CompilerDriver(outputBinName); setGlobalStrict(jshelpers.isEffectiveStrictModeSourceFile(node, options)); compilerDriver.compile(node); compilerDriver.showStatistics(); @@ -81,7 +81,7 @@ function main(fileNames: string[], options: ts.CompilerOptions) { (ctx: ts.TransformationContext) => { return (node: ts.SourceFile) => { let outputBinName = getOutputBinName(node); - let compilerDriver = new CompilerDriver(outputBinName, getRecordName(node)); + let compilerDriver = new CompilerDriver(outputBinName); compilerDriver.compileForSyntaxCheck(node); return node; } @@ -109,7 +109,7 @@ function main(fileNames: string[], options: ts.CompilerOptions) { node = transformCommonjsModule(node); } let outputBinName = getOutputBinName(node); - let compilerDriver = new CompilerDriver(outputBinName, getRecordName(node)); + let compilerDriver = new CompilerDriver(outputBinName); setGlobalStrict(jshelpers.isEffectiveStrictModeSourceFile(node, options)); compilerDriver.compile(node); compilerDriver.showStatistics(); @@ -148,17 +148,6 @@ function getOutputBinName(node: ts.SourceFile) { return outputBinName; } -function getRecordName(node: ts.SourceFile): string { - let recordName = CmdOptions.getRecordName(); - - if (recordName == "") { - let outputBinName = getOutputBinName(node); - recordName = path.basename(outputBinName, path.extname(outputBinName)); - } - - return recordName; -} - function getDtsFiles(libDir: string): string[] { let dtsFiles:string[] = []; function finDtsFile(dir){ @@ -181,7 +170,6 @@ function getDtsFiles(libDir: string): string[] { const stopWatchingStr = "####"; const watchAbcFileDefaultTimeOut = 10; const watchFileName = "watch_expressions"; -const watchOutputFileName = "Base64Output"; // this path is only available in sdk const es2abcBinaryPath = path["join"](__dirname, "..", "bin", path.sep); const es2abcBinaryName = /^win/.test(require('os').platform()) ? "es2abc.exe" : "es2abc"; @@ -285,7 +273,7 @@ function compileWatchExpression(jsFileName: string, errorMsgFileName: string, op return (node: ts.SourceFile) => { if (path.basename(node.fileName) == fileName) { node = sourceFile; } let outputBinName = getOutputBinName(node); - let compilerDriver = new CompilerDriver(outputBinName, watchOutputFileName); + let compilerDriver = new CompilerDriver(outputBinName); compilerDriver.compileForSyntaxCheck(node); return node; } @@ -310,7 +298,7 @@ function compileWatchExpression(jsFileName: string, errorMsgFileName: string, op node = ts.factory.updateSourceFile(node, newStatements); } let outputBinName = getOutputBinName(node); - let compilerDriver = new CompilerDriver(outputBinName, watchOutputFileName); + let compilerDriver = new CompilerDriver(outputBinName); setGlobalStrict(jshelpers.isEffectiveStrictModeSourceFile(node, options)); compilerDriver.compile(node); return node; @@ -326,11 +314,10 @@ function launchWatchEvaluateDeamon(parsed: ts.ParsedCommandLine | undefined) { console.log("startWatchingSuccess supportTimeout"); return; } - let deamonJSFilePrefix = CmdOptions.getEvaluateDeamonPath() + path.sep + watchFileName; - let deamonABCFilePrefix = CmdOptions.getEvaluateDeamonPath() + path.sep + watchOutputFileName; - let jsFileName = deamonJSFilePrefix + ".js"; - let abcFileName = deamonABCFilePrefix + ".abc"; - let errorMsgFileName = deamonJSFilePrefix + ".err"; + let deamonFilePrefix = CmdOptions.getEvaluateDeamonPath() + path.sep + watchFileName; + let jsFileName = deamonFilePrefix + ".js"; + let abcFileName = deamonFilePrefix + ".abc"; + let errorMsgFileName = deamonFilePrefix + ".err"; if (fs.existsSync(jsFileName)) { console.log("watchFileServer has been initialized supportTimeout"); diff --git a/ts2panda/src/pandasm.ts b/ts2panda/src/pandasm.ts index 549c9a6a3d..da58e906a6 100644 --- a/ts2panda/src/pandasm.ts +++ b/ts2panda/src/pandasm.ts @@ -109,10 +109,24 @@ export class Function { export class Record { public name: string; + public whole_line: string; + public bound_left: number; + public bound_right: number; + public line_number: number; public metadata: Metadata; - constructor(name: string) { + constructor( + name: string, + whole_line: string, + bound_left: number, + bound_right: number, + line_number: number + ) { this.name = name; + this.whole_line = whole_line; + this.bound_left = bound_left; + this.bound_right = bound_right; + this.line_number = line_number; this.metadata = new Metadata(); } } diff --git a/ts2panda/src/ts2panda.ts b/ts2panda/src/ts2panda.ts index 349e15ec0c..384f5fb0dc 100644 --- a/ts2panda/src/ts2panda.ts +++ b/ts2panda/src/ts2panda.ts @@ -36,8 +36,7 @@ import { ModuleRecord, NamespaceImportEntry, RegularImportEntry, - Signature, - Record + Signature } from "./pandasm"; import { generateCatchTables } from "./statement/tryStatement"; import { @@ -198,8 +197,7 @@ export class Ts2Panda { "opt_level": CmdOptions.getOptLevel(), "opt_log_level": CmdOptions.getOptLogLevel(), "display_typeinfo": CmdOptions.getDisplayTypeinfo(), - "is_dts_file": isGlobalDeclare(), - "output-proto": CmdOptions.getOutputproto() + "is_dts_file": isGlobalDeclare() }; let jsonOpt = JSON.stringify(options, null, 2); jsonOpt = "$" + jsonOpt.replace(dollarSign, '#$') + "$"; @@ -209,19 +207,6 @@ export class Ts2Panda { ts2abc.stdio[3].write(jsonOpt + '\n'); } - static dumpRecord(ts2abc: any, recordName: string): void { - let record = { - "t": JsonType.record, - "rb": new Record(recordName) - } - let jsonRecord = escapeUnicode(JSON.stringify(record, null, 2)); - jsonRecord = "$" + jsonRecord.replace(dollarSign, '#$') + "$"; - if (CmdOptions.isEnableDebugLog()) { - Ts2Panda.jsonString += jsonRecord; - } - ts2abc.stdio[3].write(jsonRecord + '\n'); - } - // @ts-ignore static dumpPandaGen(pg: PandaGen, ts2abc: any, recordType?: boolean): void { let funcName = pg.internalName; @@ -245,7 +230,7 @@ export class Ts2Panda { } }); - if (funcName.indexOf("func_main_0") !== -1) { + if (funcName == "func_main_0") { let exportedTypes = PandaGen.getExportedTypes(); let declareddTypes = PandaGen.getDeclaredTypes(); if (exportedTypes.size != 0) { -- Gitee From ca4dcf8f5f5307bc881639fbbec727f890537341 Mon Sep 17 00:00:00 2001 From: gavin1012_hw Date: Thu, 25 Aug 2022 22:58:25 +0800 Subject: [PATCH 22/23] Add 262 support for testing serializing and deserializing panda file via protobuf Signed-off-by: gavin1012_hw Change-Id: I28943ee01fd180bca6da1fe6d462d24d9ad6e864 --- test262/config.py | 2 ++ test262/run_sunspider.py | 44 +++++++++++++++++++++++++++++++++++----- test262/run_test262.py | 14 +++++++++++++ 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/test262/config.py b/test262/config.py index cdaf4bbe71..7c326f67de 100755 --- a/test262/config.py +++ b/test262/config.py @@ -91,6 +91,7 @@ ARK_FRONTEND_BINARY_LIST = [ DEFAULT_ARK_FRONTEND = ARK_FRONTEND_LIST[0] DEFAULT_ARK_FRONTEND_BINARY = ARK_FRONTEND_BINARY_LIST[0] +DEFAULT_MERGE_ABC_BINARY = os.path.join(ARK_DIR, "merge_abc") ARK_ARCH_LIST = [ "x64", @@ -101,3 +102,4 @@ ARK_ARCH_LIST = [ DEFAULT_ARK_ARCH = ARK_ARCH_LIST[0] DEFAULT_OPT_LEVEL = 2 DEFAULT_ES2ABC_THREAD_COUNT = 0 +DEFAULT_MERGE_ABC_MODE = 0 diff --git a/test262/run_sunspider.py b/test262/run_sunspider.py index bc8b09b780..520f202d4a 100755 --- a/test262/run_sunspider.py +++ b/test262/run_sunspider.py @@ -79,6 +79,14 @@ def parse_args(): default=DEFAULT_ES2ABC_THREAD_COUNT, required=False, help="the thread count for es2abc") + parser.add_argument('--merge-abc-binary', + default=DEFAULT_MERGE_ABC_BINARY, + required=False, + help="frontend merge abc binary tool") + parser.add_argument('--merge-abc-mode', + default=DEFAULT_MERGE_ABC_MODE, + required=False, + help="run test for merge abc mode") arguments = parser.parse_args() return arguments @@ -175,6 +183,8 @@ class ArkProgram(): self.arch_root = "" self.opt_level = DEFAULT_OPT_LEVEL self.es2abc_thread_count = DEFAULT_ES2ABC_THREAD_COUNT + self.merge_abc_binary = DEFAULT_MERGE_ABC_BINARY + self.merge_abc_mode = DEFAULT_MERGE_ABC_MODE def proce_parameters(self): if self.args.ark_tool: @@ -201,6 +211,12 @@ class ArkProgram(): if self.args.es2abc_thread_count: self.es2abc_thread_count = self.args.es2abc_thread_count + if self.args.merge_abc_binary: + self.merge_abc_binary = self.args.merge_abc_binary + + if self.args.merge_abc_mode: + self.merge_abc_mode = self.args.merge_abc_mode + self.module_list = self.args.module_list.splitlines() self.js_file = self.args.js_file @@ -211,10 +227,12 @@ class ArkProgram(): def gen_dependency_abc(self, dependency): cmd_args = [] - output_file = os.path.splitext(os.path.join(BASE_OUT_DIR, os.path.split(dependency)[1]))[0] + output_file = os.path.splitext(os.path.join(BASE_OUT_DIR, + os.path.split(dependency)[1]))[0] output_abc = f"{output_file}.abc" frontend_tool = self.ark_frontend_binary - cmd_args = [frontend_tool, dependency, '--output', output_abc, '--module'] + cmd_args = [frontend_tool, dependency, '--output', output_abc, + '--module'] proc = subprocess.Popen(cmd_args) proc.wait() @@ -222,15 +240,21 @@ class ArkProgram(): js_file = self.js_file file_name_pre = os.path.splitext(js_file)[0] file_name = os.path.basename(js_file) + file_dir = os.path.split(js_file)[0] out_file = f"{file_name_pre}.abc" + proto_bin_file = f"{file_name_pre}.bin" + proto_abc_file = ".".join([os.path.splitext(file_name)[0], "abc"]) self.abc_file = out_file mod_opt_index = 0 cmd_args = [] frontend_tool = self.ark_frontend_binary + merge_abc_binary = self.args.merge_abc_binary + merge_abc_mode = self.merge_abc_mode # pre-generate the dependencies' abc when ark_frontend is [es2panda] if file_name in self.module_list and self.ark_frontend == ARK_FRONTEND_LIST[1]: - dependencies = collect_module_dependencies(js_file, os.path.join(TEST_ES2021_DIR, "language/module-code"), []) + dependencies = collect_module_dependencies(js_file, + os.path.join(TEST_ES2021_DIR, "language/module-code"), []) for dependency in list(set(dependencies)): self.gen_dependency_abc(dependency) @@ -243,8 +267,13 @@ class ArkProgram(): self.module = True elif self.ark_frontend == ARK_FRONTEND_LIST[1]: mod_opt_index = 1 - cmd_args = [frontend_tool, '--opt-level=' + str(self.opt_level), - '--thread=' + str(self.es2abc_thread_count), '--output', out_file, js_file] + if merge_abc_mode != "0": + cmd_args = [frontend_tool, '--outputProto', + proto_bin_file, js_file] + else: + cmd_args = [frontend_tool, '--opt-level=' + str(self.opt_level), + '--thread=' + str(self.es2abc_thread_count), + '--output', out_file, js_file] if file_name in self.module_list: cmd_args.insert(mod_opt_index, "--module") self.module = True @@ -263,6 +292,11 @@ class ArkProgram(): self.abc_file += f':{abc_file}' retcode = exec_command(cmd_args) self.abc_cmd = cmd_args + if self.ark_frontend == ARK_FRONTEND_LIST[1] and merge_abc_mode != "0": + cmd_args = [merge_abc_binary, '--input', proto_bin_file, + '--suffix', "bin", '--outputFilePath', + file_dir, '--output', proto_abc_file] + retcode = exec_command(cmd_args) return retcode def compile_aot(self): diff --git a/test262/run_test262.py b/test262/run_test262.py index 5fdf49e23a..570c593d72 100755 --- a/test262/run_test262.py +++ b/test262/run_test262.py @@ -98,6 +98,10 @@ def parse_args(): parser.add_argument('--es2abc-thread-count', default=DEFAULT_ES2ABC_THREAD_COUNT, help="the thread count for es2abc") + parser.add_argument('--merge-abc-binary', + help="frontend merge abc binary tool") + parser.add_argument('--merge-abc-mode', + help="run test for merge abc mode") return parser.parse_args() @@ -483,6 +487,8 @@ def get_host_args(args, host_type): module_list = '' opt_level = DEFAULT_OPT_LEVEL es2abc_thread_count = DEFAULT_ES2ABC_THREAD_COUNT + merge_abc_binary = DEFAULT_MERGE_ABC_BINARY + merge_abc_mode = DEFAULT_MERGE_ABC_MODE with open(MODULE_FILES_LIST) as fopen: module_list = fopen.read() @@ -510,6 +516,12 @@ def get_host_args(args, host_type): if args.es2abc_thread_count: es2abc_thread_count = args.es2abc_thread_count + if args.merge_abc_binary: + merge_abc_binary = args.merge_abc_binary + + if args.merge_abc_mode: + merge_abc_mode = args.merge_abc_mode + if host_type == DEFAULT_HOST_TYPE: host_args = f"-B test262/run_sunspider.py " host_args += f"--ark-tool={ark_tool} " @@ -522,6 +534,8 @@ def get_host_args(args, host_type): host_args += f"--module-list={module_list} " host_args += f"--opt-level={opt_level} " host_args += f"--es2abc-thread-count={es2abc_thread_count} " + host_args += f"--merge-abc-binary={merge_abc_binary} " + host_args += f"--merge-abc-mode={merge_abc_mode} " if args.ark_arch != ark_arch: host_args += f"--ark-arch={args.ark_arch} " -- Gitee From 78d1fa1204d7ff5d3f83d48e3c4db210b71408d2 Mon Sep 17 00:00:00 2001 From: chenqy930 Date: Sun, 28 Aug 2022 15:52:28 +0800 Subject: [PATCH 23/23] Support compile multi files Signed-off-by: chenqy930 Change-Id: Icd437776c65631298a15965fac82433501046a3d --- es2panda/aot/main.cpp | 116 ++++++++------------ es2panda/aot/options.cpp | 29 ++--- es2panda/aot/options.h | 3 +- es2panda/compiler/core/compileQueue.cpp | 15 +++ es2panda/compiler/core/compileQueue.h | 6 +- es2panda/compiler/core/compilerImpl.cpp | 8 +- es2panda/compiler/core/compilerImpl.h | 2 +- es2panda/compiler/core/emitter/emitter.cpp | 2 +- es2panda/es2panda.cpp | 19 +--- es2panda/es2panda.h | 15 ++- es2panda/util/helpers.cpp | 33 ++++++ es2panda/util/helpers.h | 11 ++ merge_abc/BUILD.gn | 2 +- merge_abc/src/annotationProto.h | 4 +- merge_abc/src/assemblyDebugProto.h | 2 +- merge_abc/src/assemblyFieldProto.h | 4 +- merge_abc/src/assemblyFileLocationProto.h | 2 +- merge_abc/src/assemblyFunctionProto.h | 12 +- merge_abc/src/assemblyInsProto.h | 2 +- merge_abc/src/assemblyLabelProto.h | 2 +- merge_abc/src/assemblyLiteralsProto.h | 2 +- merge_abc/src/assemblyProgramProto.h | 6 +- merge_abc/src/assemblyRecordProto.h | 4 +- merge_abc/src/assemblyTypeProto.h | 4 +- merge_abc/src/compositeProgramProto.cpp | 3 +- merge_abc/src/compositeProgramProto.h | 6 +- merge_abc/src/main.cpp | 7 +- merge_abc/src/mergeProgram.cpp | 7 +- merge_abc/src/mergeProgram.h | 2 +- merge_abc/src/metaProto.h | 4 +- merge_abc/src/{Options.cpp => options.cpp} | 2 +- merge_abc/src/{Options.h => options.h} | 2 +- merge_abc/src/protobufSnapshotGenerator.cpp | 14 ++- merge_abc/src/protobufSnapshotGenerator.h | 2 +- 34 files changed, 196 insertions(+), 158 deletions(-) rename merge_abc/src/{Options.cpp => options.cpp} (99%) rename merge_abc/src/{Options.h => options.h} (100%) diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index ce5c3aea30..07a978abe0 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -13,19 +13,13 @@ * limitations under the License. */ -#include -#ifdef ENABLE_BYTECODE_OPT -#include -#include -#else -#include #include #include -#endif #include #include #include #include +#include #include #include #include @@ -33,8 +27,6 @@ #include #include -#include - namespace panda::es2panda::aot { using mem::MemConfig; @@ -91,80 +83,60 @@ static void DumpPandaFileSizeStatistic(std::map &stat) std::cout << "total: " << totalSize << std::endl; } -static int GenerateProgram(std::vector &progs, std::unique_ptr &options) +static int GenerateProgram(std::vector &progs, + std::unique_ptr &options) { - const std::string output = options->CompilerOutput(); - if (progs.size() == 0) { std::cerr << "Failed to generate program " << std::endl; return 1; } - // std::cout << "progs.sizezzzzzzz()" << progs.size() << std::endl; - // int index = 0; - // for (auto *prog: progs) { - // std::cout << "prog " << index++ << std::endl; - // es2panda::Compiler::DumpAsm(prog); - // } + int optLevel = options->OptLevel(); + bool dumpSize = options->SizeStat(); + const std::string output = options->CompilerOutput(); + const es2panda::CompilerOptions compilerOptions = options->CompilerOptions(); + + if (compilerOptions.dumpAsm || compilerOptions.dumpLiteralBuffer) { + for (auto *prog : progs) { + if (compilerOptions.dumpAsm) { + es2panda::Compiler::DumpAsm(prog); + } + + if (compilerOptions.dumpLiteralBuffer) { + panda::es2panda::util::Dumper::DumpLiterals(prog->literalarray_table); + } + } + } if (progs.size() > 1) { if (!panda::pandasm::AsmEmitter::EmitPrograms(output, progs, true)) { std::cerr << "Failed to emit merged program " << std::endl; return 1; } - return 0; - } - - auto *prog = progs[0]; - 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 {}; - panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps *mapsp = optLevel != 0 ? &maps : nullptr; + } else { + auto *prog = progs[0]; + std::map stat; + std::map *statp = optLevel != 0 ? &stat : nullptr; + panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps maps {}; + panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps *mapsp = optLevel != 0 ? &maps : nullptr; + + if (output.empty()) { + GenerateBase64Output(prog, mapsp); + return 0; + } -#ifdef PANDA_WITH_BYTECODE_OPTIMIZER - if (optLevel != 0) { - const uint32_t COMPONENT_MASK = panda::Logger::Component::ASSEMBLER | - panda::Logger::Component::BYTECODE_OPTIMIZER | - panda::Logger::Component::COMPILER; - panda::Logger::InitializeStdLogging(panda::Logger::Level::ERROR, COMPONENT_MASK); + if (options->compilerProtoOutput().size() > 0) { + panda::proto::ProtobufSnapshotGenerator::GenerateSnapshot(*prog, options->compilerProtoOutput()); + return 0; + } if (!panda::pandasm::AsmEmitter::Emit(output, *prog, statp, mapsp, true)) { return 1; } - panda::bytecodeopt::options.SetOptLevel(optLevel); - panda::bytecodeopt::OptimizeBytecode(prog, mapsp, output, true, true); - } -#endif - - if (compilerOptions.dumpAsm) { - es2panda::Compiler::DumpAsm(prog); - } - - if (output.empty()) { - GenerateBase64Output(prog, mapsp); - return 0; - } - - if (!panda::pandasm::AsmEmitter::Emit(output, *prog, statp, mapsp, true)) { - return 1; - } - - if (options->compilerProtoOutput().size() > 0) { - panda::proto::ProtobufSnapshotGenerator::GenerateSnapshot(*prog, options->compilerProtoOutput()); - return 0; - } - - if (compilerOptions.dumpLiteralBuffer) { - panda::es2panda::util::Dumper::DumpLiterals(prog->literalarray_table); - } - - if (dumpSize && optLevel != 0) { - DumpPandaFileSizeStatistic(stat); + if (dumpSize && optLevel != 0) { + DumpPandaFileSizeStatistic(stat); + } } return 0; @@ -184,22 +156,26 @@ int Run(int argc, const char **argv) panda::ArenaAllocator allocator(panda::SpaceType::SPACE_TYPE_COMPILER, nullptr, true); std::unordered_map *cachePrograms = nullptr; - bool isCacheHasDebugInfo = false; + if (!options->CacheFile().empty()) { - cachePrograms = proto::ProtobufSnapshotGenerator::GetCacheContext(options->CacheFile(), isCacheHasDebugInfo, &allocator); + cachePrograms = proto::ProtobufSnapshotGenerator::GetCacheContext(options->CacheFile(), + options->CompilerOptions().isDebug, &allocator); } - Compiler::CompileFiles(options->CompilerOptions(), cachePrograms, programs, programsInfo, &allocator, isCacheHasDebugInfo); + Compiler::CompileFiles(options->CompilerOptions(), cachePrograms, programs, programsInfo, &allocator); if (!options->NpmModuleEntryList().empty()) { es2panda::util::ModuleHelpers::CompileNpmModuleEntryList(options->NpmModuleEntryList(), cachePrograms, programs, programsInfo, &allocator); } - GenerateProgram(programs, options); + if (GenerateProgram(programs, options) != 0) { + return 1; + } if (!options->CacheFile().empty()) { - proto::ProtobufSnapshotGenerator::UpdateCacheFile(programsInfo, options->CompilerOptions().isDebug, options->CacheFile()); + proto::ProtobufSnapshotGenerator::UpdateCacheFile(programsInfo, options->CompilerOptions().isDebug, + options->CacheFile()); } return 0; diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index b9d41e888f..f09eddb2c9 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -16,20 +16,18 @@ #include "options.h" #include - -#include -#include - #include "mergeProgram.h" -#include #include "os/file.h" - #if defined(PANDA_TARGET_WINDOWS) #include #else #include #endif +#include +#include +#include + namespace panda::es2panda::aot { template @@ -187,7 +185,8 @@ bool Options::Parse(int argc, const char **argv) argparser_->EnableTail(); argparser_->EnableRemainder(); - if (!argparser_->Parse(argc, argv) || opHelp.GetValue() || (inputFile.GetValue().empty() && base64Input.GetValue().empty())) { + if (!argparser_->Parse(argc, argv) || opHelp.GetValue() || (inputFile.GetValue().empty() + && base64Input.GetValue().empty())) { std::stringstream ss; ss << argparser_->GetErrorString() << std::endl; @@ -259,6 +258,11 @@ bool Options::Parse(int argc, const char **argv) compilerOutput_ = RemoveExtension(BaseName(sourceFile_)).append(".abc"); } + recordName_ = recordName.GetValue(); + if (recordName_.empty()) { + recordName_ = compilerOutput_.empty() ? "Base64Output" : RemoveExtension(BaseName(compilerOutput_)); + } + if (!inputIsEmpty) { // common mode auto inputAbs = panda::os::file::File::GetAbsolutePath(sourceFile_); @@ -273,11 +277,6 @@ bool Options::Parse(int argc, const char **argv) } else if (panda::os::file::File::IsDirectory(fpath)) { CollectInputFilesFromFileDirectory(fpath, extension); } else { - recordName_ = recordName.GetValue(); - if (recordName_.empty()) { - recordName_ = RemoveExtension(BaseName(compilerOutput_)); - } - es2panda::SourceFile src(sourceFile_, recordName_, scriptKind_); sourceFiles_.push_back(src); } @@ -289,7 +288,7 @@ bool Options::Parse(int argc, const char **argv) return false; } - es2panda::SourceFile src("", "Base64Output", es2panda::parser::ScriptKind::SCRIPT); + es2panda::SourceFile src("", recordName_, es2panda::parser::ScriptKind::SCRIPT); src.source = base64Input_; sourceFiles_.push_back(src); } @@ -324,7 +323,9 @@ bool Options::Parse(int argc, const char **argv) compilerOptions_.extension = extension_; compilerOptions_.functionThreadCount = functionThreadCount_; compilerOptions_.fileThreadCount = fileThreadCount_; - compilerOptions_.debugSourceFile = sourceFile.GetValue(); + compilerOptions_.output = compilerOutput_; + compilerOptions_.debugInfoSourceFile = sourceFile.GetValue(); + compilerOptions_.optLevel = opOptLevel.GetValue(); compilerOptions_.sourceFiles = sourceFiles_; return true; diff --git a/es2panda/aot/options.h b/es2panda/aot/options.h index a5eef1d533..8d35256edc 100644 --- a/es2panda/aot/options.h +++ b/es2panda/aot/options.h @@ -16,10 +16,9 @@ #ifndef ES2PANDA_AOT_OPTIONS_H #define ES2PANDA_AOT_OPTIONS_H -#include #include +#include #include -#include #include #include diff --git a/es2panda/compiler/core/compileQueue.cpp b/es2panda/compiler/core/compileQueue.cpp index de7e931a16..00ea3f6c48 100644 --- a/es2panda/compiler/core/compileQueue.cpp +++ b/es2panda/compiler/core/compileQueue.cpp @@ -21,6 +21,17 @@ #include #include #include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include #include #ifdef ENABLE_BYTECODE_OPT @@ -103,6 +114,10 @@ void CompileFileJob::Run() auto *prog = compiler.CompileFile(*options_, src_); + if (options_->optLevel != 0) { + util::Helpers::OptimizeProgram(prog, options_); + } + { std::unique_lock lock(global_m_); auto *cache = allocator_->New(src_->hash, prog); diff --git a/es2panda/compiler/core/compileQueue.h b/es2panda/compiler/core/compileQueue.h index a78b257ebe..e7b109f61c 100644 --- a/es2panda/compiler/core/compileQueue.h +++ b/es2panda/compiler/core/compileQueue.h @@ -16,9 +16,9 @@ #ifndef ES2PANDA_COMPILER_CORE_COMPILEQUEUE_H #define ES2PANDA_COMPILER_CORE_COMPILEQUEUE_H +#include #include #include -#include #include #include @@ -150,8 +150,8 @@ private: class CompileFileQueue : public CompileQueue { public: - explicit CompileFileQueue(size_t threadCount, es2panda::CompilerOptions *options, - std::vector &progs, + explicit CompileFileQueue(size_t threadCount, es2panda::CompilerOptions *options, + std::vector &progs, std::unordered_map &progsInfo, panda::ArenaAllocator *allocator): CompileQueue(threadCount), options_(options), progs_(progs), progsInfo_(progsInfo), allocator_(allocator) {} diff --git a/es2panda/compiler/core/compilerImpl.cpp b/es2panda/compiler/core/compilerImpl.cpp index 3f06a33e3e..3a4dd3ac29 100644 --- a/es2panda/compiler/core/compilerImpl.cpp +++ b/es2panda/compiler/core/compilerImpl.cpp @@ -18,9 +18,9 @@ #include #include #include -#include #include #include +#include #include #include @@ -35,9 +35,11 @@ CompilerImpl::~CompilerImpl() } } -panda::pandasm::Program *CompilerImpl::Compile(parser::Program *program, const es2panda::CompilerOptions &options, const std::string &debugSourceFile) +panda::pandasm::Program *CompilerImpl::Compile(parser::Program *program, const es2panda::CompilerOptions &options, + const std::string &debugInfoSourceFile) { - CompilerContext context(program->Binder(), options.isDebug, options.isDebuggerEvaluateExpressionMode, debugSourceFile); + CompilerContext context(program->Binder(), options.isDebug, options.isDebuggerEvaluateExpressionMode, + debugInfoSourceFile); if (program->Extension() == ScriptExtension::TS && options.enableTypeCheck) { ArenaAllocator localAllocator(SpaceType::SPACE_TYPE_COMPILER, nullptr, true); diff --git a/es2panda/compiler/core/compilerImpl.h b/es2panda/compiler/core/compilerImpl.h index 2c7a3dbeb0..123bd2d680 100644 --- a/es2panda/compiler/core/compilerImpl.h +++ b/es2panda/compiler/core/compilerImpl.h @@ -41,7 +41,7 @@ public: NO_COPY_SEMANTIC(CompilerImpl); NO_MOVE_SEMANTIC(CompilerImpl); - panda::pandasm::Program *Compile(parser::Program *program, const es2panda::CompilerOptions &options, const std::string &debugSourceFile); + panda::pandasm::Program *Compile(parser::Program *program, const es2panda::CompilerOptions &options, const std::string &debugInfoSourceFile); static void DumpAsm(const panda::pandasm::Program *prog); private: diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index f55a8df720..b7426b090c 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -16,7 +16,6 @@ #include "emitter.h" #include -#include #include #include #include @@ -30,6 +29,7 @@ #include #include #include +#include #include #include diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index 90ec74fe75..51ce8a4ea7 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -59,8 +59,8 @@ panda::pandasm::Program *Compiler::Compile(const SourceFile &input, const Compil std::cout << ast.Dump() << std::endl; } - std::string debugSourceFile = options.debugSourceFile.empty() ? fname : options.debugSourceFile; - auto *prog = compiler_->Compile(&ast, options, debugSourceFile); + std::string debugInfoSourceFile = options.debugInfoSourceFile.empty() ? fname : options.debugInfoSourceFile; + auto *prog = compiler_->Compile(&ast, options, debugInfoSourceFile); return prog; } catch (const class Error &e) { @@ -88,16 +88,12 @@ void Compiler::SelectCompileFile(CompilerOptions &options, std::unordered_map *cacheProgs, std::vector &progs, std::unordered_map &progsInfo, - panda::ArenaAllocator *allocator, bool isCacheHasDebugInfo) + panda::ArenaAllocator *allocator) { if (cacheProgs == nullptr) { return; } - if (isCacheHasDebugInfo != options.isDebug) { - return; - } - auto fullList = options.sourceFiles; std::vector inputList; @@ -115,14 +111,11 @@ void Compiler::SelectCompileFile(CompilerOptions &options, uint32_t hash = GetHash32String(reinterpret_cast(ss.str().c_str())); - // std::cout << "this function: "<< input.fileName << " hash " << hash << std::endl; - auto it = cacheProgs->find(input.fileName); if (it != cacheProgs->end() && hash == it->second->hashCode) { progs.push_back(it->second->program); auto *cache = allocator->New(it->second->hashCode, it->second->program); progsInfo.insert({input.fileName, cache}); - // std::cout << "find same function: "<< input.fileName << std::endl; } else { input.hash = hash; inputList.push_back(input); @@ -135,9 +128,9 @@ void Compiler::CompileFiles(CompilerOptions &options, std::unordered_map *cacheProgs, std::vector &progs, std::unordered_map &progsInfo, - panda::ArenaAllocator *allocator, bool isCacheHasDebugInfo) + panda::ArenaAllocator *allocator) { - SelectCompileFile(options, cacheProgs, progs, progsInfo, allocator, isCacheHasDebugInfo); + SelectCompileFile(options, cacheProgs, progs, progsInfo, allocator); auto queue = new compiler::CompileFileQueue(options.fileThreadCount, &options, progs, progsInfo, allocator); @@ -161,7 +154,7 @@ panda::pandasm::Program *Compiler::CompileFile(CompilerOptions &options, SourceF if (src->hash == 0) { src->hash = GetHash32String(reinterpret_cast(buffer.c_str())); - } + } } auto *program = Compile(*src, options); diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index 5b4e0e0298..2da521fd64 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -17,10 +17,11 @@ #define ES2PANDA_PUBLIC_H #include +#include +#include + #include #include -#include -#include namespace panda::pandasm { struct Program; @@ -67,7 +68,9 @@ struct CompilerOptions { ScriptExtension extension {}; int fileThreadCount {0}; int functionThreadCount {0}; - std::string debugSourceFile {}; + int optLevel {0}; + std::string output {}; + std::string debugInfoSourceFile {}; std::vector sourceFiles; }; @@ -154,15 +157,15 @@ public: static void CompileFiles(CompilerOptions &options, std::unordered_map *cacheProgs, - std::vector &progs, + std::vector &progs, std::unordered_map &progsInfo, - panda::ArenaAllocator *allocator, bool isCacheHasDebugInfo); + panda::ArenaAllocator *allocator); static void SelectCompileFile(CompilerOptions &options, std::unordered_map *cacheProgs, std::vector &progs, std::unordered_map &progsInfo, - panda::ArenaAllocator *allocator, bool isCacheHasDebugInfo); + panda::ArenaAllocator *allocator); inline panda::pandasm::Program *Compile(const SourceFile &input) { diff --git a/es2panda/util/helpers.cpp b/es2panda/util/helpers.cpp index f04ee77ddd..10c598c476 100644 --- a/es2panda/util/helpers.cpp +++ b/es2panda/util/helpers.cpp @@ -15,6 +15,7 @@ #include "helpers.h" +#include #include #include #include @@ -33,6 +34,15 @@ #include #include +#ifdef ENABLE_BYTECODE_OPT +#include +#include +#else +#include +#include +#include +#endif + namespace panda::es2panda::util { // Helpers @@ -403,4 +413,27 @@ std::tuple Helpers::ParamName(ArenaAllocator *allocator, return {Helpers::ToStringView(allocator, index), true}; } +bool Helpers::OptimizeProgram(panda::pandasm::Program * prog, es2panda::CompilerOptions *options) +{ + std::map stat; + std::map *statp = &stat; + panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps maps{}; + panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps *mapsp = &maps; + +#ifdef PANDA_WITH_BYTECODE_OPTIMIZER + const uint32_t COMPONENT_MASK = panda::Logger::Component::ASSEMBLER | + panda::Logger::Component::BYTECODE_OPTIMIZER | + panda::Logger::Component::COMPILER; + panda::Logger::InitializeStdLogging(panda::Logger::Level::ERROR, COMPONENT_MASK); + + if (!panda::pandasm::AsmEmitter::Emit(options->output, *prog, statp, mapsp, true)) { + return false; + } + + panda::bytecodeopt::options.SetOptLevel(options->optLevel); + panda::bytecodeopt::OptimizeBytecode(prog, mapsp, options->output, true, true); +#endif + return true; +} + } // namespace panda::es2panda::util diff --git a/es2panda/util/helpers.h b/es2panda/util/helpers.h index a5dab4112a..f1ec92a334 100644 --- a/es2panda/util/helpers.h +++ b/es2panda/util/helpers.h @@ -31,6 +31,15 @@ class Identifier; class AstNode; } // namespace panda::es2panda::ir +namespace panda::es2panda { +struct CompilerOptions; +} // namespace panda::es2panda + +namespace panda::pandasm { +struct Program; +} // namespace panda::pandasm + + namespace panda::es2panda::util { class Helpers { @@ -65,6 +74,8 @@ public: static std::tuple ParamName(ArenaAllocator *allocator, const ir::AstNode *param, uint32_t index); + static bool OptimizeProgram(panda::pandasm::Program * prog, es2panda::CompilerOptions *options); + static const uint32_t INVALID_INDEX = 4294967295L; static const uint32_t MAX_INT32 = 2147483647; }; diff --git a/merge_abc/BUILD.gn b/merge_abc/BUILD.gn index de41934673..8631215db7 100644 --- a/merge_abc/BUILD.gn +++ b/merge_abc/BUILD.gn @@ -155,7 +155,7 @@ ohos_executable("merge_abc") { use_exceptions = true sources = [ "src/main.cpp", - "src/Options.cpp", + "src/options.cpp", ] include_dirs = [ "./src" ] diff --git a/merge_abc/src/annotationProto.h b/merge_abc/src/annotationProto.h index 51bff7ac1e..e34d7bdba6 100644 --- a/merge_abc/src/annotationProto.h +++ b/merge_abc/src/annotationProto.h @@ -16,10 +16,10 @@ #ifndef MERGE_ABC_ANNOTATION_H #define MERGE_ABC_ANNOTATION_H -#include "assembly-program.h" -#include "assemblyTypeProto.h" #include "annotation.pb.h" #include "arena_allocator.h" +#include "assembly-program.h" +#include "assemblyTypeProto.h" namespace panda::proto { class AnnotationData { diff --git a/merge_abc/src/assemblyDebugProto.h b/merge_abc/src/assemblyDebugProto.h index 94508d125e..47e3e3766d 100644 --- a/merge_abc/src/assemblyDebugProto.h +++ b/merge_abc/src/assemblyDebugProto.h @@ -16,8 +16,8 @@ #ifndef MERGE_ABC_ASSEMBLY_DEBUG_H #define MERGE_ABC_ASSEMBLY_DEBUG_H -#include "assembly-program.h" #include "assemblyDebug.pb.h" +#include "assembly-program.h" namespace panda::proto { class DebuginfoIns { diff --git a/merge_abc/src/assemblyFieldProto.h b/merge_abc/src/assemblyFieldProto.h index 7dbb8d763e..81ccab6e55 100644 --- a/merge_abc/src/assemblyFieldProto.h +++ b/merge_abc/src/assemblyFieldProto.h @@ -16,10 +16,10 @@ #ifndef MERGE_ABC_ASSEMBLY_FIELD_H #define MERGE_ABC_ASSEMBLY_FIELD_H -#include "assembly-program.h" #include "assemblyField.pb.h" -#include "metaProto.h" #include "assemblyTypeProto.h" +#include "assembly-program.h" +#include "metaProto.h" namespace panda::proto { class Field { diff --git a/merge_abc/src/assemblyFileLocationProto.h b/merge_abc/src/assemblyFileLocationProto.h index 5245a24aa0..83afe39022 100644 --- a/merge_abc/src/assemblyFileLocationProto.h +++ b/merge_abc/src/assemblyFileLocationProto.h @@ -16,8 +16,8 @@ #ifndef MERGE_ABC_ASSEMBLY_FILE_LOCATION_H #define MERGE_ABC_ASSEMBLY_FILE_LOCATION_H -#include "assembly-program.h" #include "assemblyFileLocation.pb.h" +#include "assembly-program.h" namespace panda::proto { class FileLocation { diff --git a/merge_abc/src/assemblyFunctionProto.h b/merge_abc/src/assemblyFunctionProto.h index 6db904b90a..6346cadc52 100644 --- a/merge_abc/src/assemblyFunctionProto.h +++ b/merge_abc/src/assemblyFunctionProto.h @@ -16,16 +16,16 @@ #ifndef MERGE_ABC_ASSEMBLY_FUNCTION_H #define MERGE_ABC_ASSEMBLY_FUNCTION_H -#include "assembly-program.h" +#include "arena_allocator.h" +#include "assemblyDebugProto.h" +#include "assemblyFileLocationProto.h" +#include "assemblyFunction.pb.h" +#include "assemblyInsProto.h" #include "assemblyLabelProto.h" #include "assemblyTypeProto.h" -#include "assemblyInsProto.h" -#include "assemblyDebugProto.h" +#include "assembly-program.h" #include "ideHelpersProto.h" -#include "assemblyFileLocationProto.h" #include "metaProto.h" -#include "assemblyFunction.pb.h" -#include "arena_allocator.h" namespace panda::proto { class CatchBlock { diff --git a/merge_abc/src/assemblyInsProto.h b/merge_abc/src/assemblyInsProto.h index 0a3a9c3da3..05053d5dec 100644 --- a/merge_abc/src/assemblyInsProto.h +++ b/merge_abc/src/assemblyInsProto.h @@ -16,9 +16,9 @@ #ifndef MERGE_ABC_ASSEMBLY_INS_H #define MERGE_ABC_ASSEMBLY_INS_H -#include "assembly-program.h" #include "assemblyDebugProto.h" #include "assemblyIns.pb.h" +#include "assembly-program.h" namespace panda::proto { class Ins { diff --git a/merge_abc/src/assemblyLabelProto.h b/merge_abc/src/assemblyLabelProto.h index 908fcaff12..e2c44756ac 100644 --- a/merge_abc/src/assemblyLabelProto.h +++ b/merge_abc/src/assemblyLabelProto.h @@ -16,9 +16,9 @@ #ifndef MERGE_ABC_ASSEMBLY_LABEL_H #define MERGE_ABC_ASSEMBLY_LABEL_H -#include "assembly-program.h" #include "assemblyFileLocationProto.h" #include "assemblyLabel.pb.h" +#include "assembly-program.h" namespace panda::proto { class Label { diff --git a/merge_abc/src/assemblyLiteralsProto.h b/merge_abc/src/assemblyLiteralsProto.h index b5b21e7559..172a0c3a69 100644 --- a/merge_abc/src/assemblyLiteralsProto.h +++ b/merge_abc/src/assemblyLiteralsProto.h @@ -16,8 +16,8 @@ #ifndef MERGE_ABC_ASSEMBLY_LITERALS_H #define MERGE_ABC_ASSEMBLY_LITERALS_H -#include "assembly-program.h" #include "assemblyLiterals.pb.h" +#include "assembly-program.h" namespace panda::proto { class VariantValue { diff --git a/merge_abc/src/assemblyProgramProto.h b/merge_abc/src/assemblyProgramProto.h index 6942530ea4..6b5d3e4c13 100644 --- a/merge_abc/src/assemblyProgramProto.h +++ b/merge_abc/src/assemblyProgramProto.h @@ -16,12 +16,12 @@ #ifndef MERGE_ABC_ASSEMBLY_PROGRAM_H #define MERGE_ABC_ASSEMBLY_PROGRAM_H -#include "assembly-program.h" -#include "assemblyRecordProto.h" +#include "arena_allocator.h" #include "assemblyFunctionProto.h" #include "assemblyLiteralsProto.h" #include "assemblyProgram.pb.h" -#include "arena_allocator.h" +#include "assemblyRecordProto.h" +#include "assembly-program.h" namespace panda::proto { class Program { diff --git a/merge_abc/src/assemblyRecordProto.h b/merge_abc/src/assemblyRecordProto.h index 19535c1252..8a73e058c3 100644 --- a/merge_abc/src/assemblyRecordProto.h +++ b/merge_abc/src/assemblyRecordProto.h @@ -16,11 +16,11 @@ #ifndef MERGE_ABC_ASSEMBLY_RECORD_H #define MERGE_ABC_ASSEMBLY_RECORD_H -#include "assembly-program.h" -#include "metaProto.h" #include "assemblyFieldProto.h" #include "assemblyFunctionProto.h" #include "assemblyRecord.pb.h" +#include "assembly-program.h" +#include "metaProto.h" namespace panda::proto { class Record { diff --git a/merge_abc/src/assemblyTypeProto.h b/merge_abc/src/assemblyTypeProto.h index 661cc731c2..636ceea5d4 100644 --- a/merge_abc/src/assemblyTypeProto.h +++ b/merge_abc/src/assemblyTypeProto.h @@ -16,9 +16,9 @@ #ifndef MERGE_ABC_ASSEMBLY_TYPE_H #define MERGE_ABC_ASSEMBLY_TYPE_H -#include "assembly-program.h" -#include "assemblyType.pb.h" #include "arena_allocator.h" +#include "assemblyType.pb.h" +#include "assembly-program.h" namespace panda::proto { class Type { diff --git a/merge_abc/src/compositeProgramProto.cpp b/merge_abc/src/compositeProgramProto.cpp index 485927e41f..0a94e94a3a 100644 --- a/merge_abc/src/compositeProgramProto.cpp +++ b/merge_abc/src/compositeProgramProto.cpp @@ -33,7 +33,7 @@ void CompositeProgram::Serialize( void CompositeProgram::Deserialize(const protoPanda::CompositeProgram &protoCompositeProgram, std::unordered_map &compositeProgramMap, - bool &isDebug, panda::ArenaAllocator *allocator) + panda::ArenaAllocator *allocator) { compositeProgramMap.reserve(protoCompositeProgram.programcache_size()); for (const auto &protoProgramcache : protoCompositeProgram.programcache()) { @@ -45,7 +45,6 @@ void CompositeProgram::Deserialize(const protoPanda::CompositeProgram &protoComp auto *programCache = allocator->New(hashCode, program); compositeProgramMap.insert({fileName, programCache}); } - isDebug = protoCompositeProgram.isdebug(); } } // namespace panda::proto diff --git a/merge_abc/src/compositeProgramProto.h b/merge_abc/src/compositeProgramProto.h index 868180ef46..d9e381c7e8 100644 --- a/merge_abc/src/compositeProgramProto.h +++ b/merge_abc/src/compositeProgramProto.h @@ -16,9 +16,9 @@ #ifndef MERGE_ABC_BUILD_COMPOSITE_PROGRAM_H #define MERGE_ABC_BUILD_COMPOSITE_PROGRAM_H -#include "programCache.h" -#include "compositeProgram.pb.h" #include "assemblyProgramProto.h" +#include "compositeProgram.pb.h" +#include "programCache.h" namespace panda::proto { class CompositeProgram { @@ -28,7 +28,7 @@ public: protoPanda::CompositeProgram &protoCompositeProgram); static void Deserialize(const protoPanda::CompositeProgram &protoCompositeProgram, std::unordered_map &compositeProgramMap, - bool &isDebug, panda::ArenaAllocator *allocator); + panda::ArenaAllocator *allocator); }; } // panda::proto diff --git a/merge_abc/src/main.cpp b/merge_abc/src/main.cpp index 0fe19879b6..4c1df2f7a7 100644 --- a/merge_abc/src/main.cpp +++ b/merge_abc/src/main.cpp @@ -13,12 +13,13 @@ * limitations under the License. */ -#include "mergeProgram.h" #include "arena_allocator.h" -#include "Options.h" +#include "mergeProgram.h" +#include "options.h" #include "protobufSnapshotGenerator.h" -#include + #include +#include namespace panda::proto { diff --git a/merge_abc/src/mergeProgram.cpp b/merge_abc/src/mergeProgram.cpp index 2de584b517..3f51e1fd3e 100644 --- a/merge_abc/src/mergeProgram.cpp +++ b/merge_abc/src/mergeProgram.cpp @@ -13,12 +13,11 @@ * limitations under the License. */ -#include "mergeProgram.h" -#include "Options.h" #include "assembler/assembly-function.h" #include "libpandafile/literal_data_accessor.h" -#include +#include "mergeProgram.h" #include "os/file.h" +#include "options.h" #if defined(PANDA_TARGET_WINDOWS) #include @@ -26,6 +25,8 @@ #include #endif +#include + namespace panda::proto { bool MergeProgram::GetProtoFiles(const std::string &protoBinPath, const std::string &protoBinSuffix, diff --git a/merge_abc/src/mergeProgram.h b/merge_abc/src/mergeProgram.h index 54f850dfd0..b874395ffb 100644 --- a/merge_abc/src/mergeProgram.h +++ b/merge_abc/src/mergeProgram.h @@ -16,9 +16,9 @@ #ifndef MERGE_ABC_MERGE_PROGRAM_H #define MERGE_ABC_MERGE_PROGRAM_H +#include "assembly-function.h" #include "assembly-ins.h" #include "assembly-program.h" -#include "assembler/assembly-function.h" namespace panda::proto { class MergeProgram { diff --git a/merge_abc/src/metaProto.h b/merge_abc/src/metaProto.h index c3baeacd09..93d5d1743d 100644 --- a/merge_abc/src/metaProto.h +++ b/merge_abc/src/metaProto.h @@ -16,11 +16,11 @@ #ifndef MERGE_ABC_META_H #define MERGE_ABC_META_H -#include "assembly-program.h" #include "annotationProto.h" +#include "arena_allocator.h" +#include "assembly-program.h" #include "assemblyTypeProto.h" #include "meta.pb.h" -#include "arena_allocator.h" namespace panda::proto { class RecordMetadata { diff --git a/merge_abc/src/Options.cpp b/merge_abc/src/options.cpp similarity index 99% rename from merge_abc/src/Options.cpp rename to merge_abc/src/options.cpp index 9df5f41a2f..de8c4af675 100644 --- a/merge_abc/src/Options.cpp +++ b/merge_abc/src/options.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "Options.h" +#include "options.h" #include diff --git a/merge_abc/src/Options.h b/merge_abc/src/options.h similarity index 100% rename from merge_abc/src/Options.h rename to merge_abc/src/options.h index 20b7db6fc8..1ff88357d5 100644 --- a/merge_abc/src/Options.h +++ b/merge_abc/src/options.h @@ -16,8 +16,8 @@ #ifndef MERGE_ABC_MERGE_OPTIONS_H #define MERGE_ABC_MERGE_OPTIONS_H -#include #include +#include #include namespace panda::proto { diff --git a/merge_abc/src/protobufSnapshotGenerator.cpp b/merge_abc/src/protobufSnapshotGenerator.cpp index e7b5952ef6..12016abcab 100644 --- a/merge_abc/src/protobufSnapshotGenerator.cpp +++ b/merge_abc/src/protobufSnapshotGenerator.cpp @@ -13,9 +13,9 @@ * limitations under the License. */ -#include "protobufSnapshotGenerator.h" -#include "assembly-program.h" #include "assemblyProgramProto.h" +#include "assembly-program.h" +#include "protobufSnapshotGenerator.h" namespace panda::proto { void ProtobufSnapshotGenerator::GenerateSnapshot(const panda::pandasm::Program &program, const std::string &outputName) @@ -65,11 +65,11 @@ void ProtobufSnapshotGenerator::UpdateCacheFile( } std::unordered_map *ProtobufSnapshotGenerator::GetCacheContext( - const std::string &cacheFilePath, bool &isDebug, panda::ArenaAllocator *allocator) + const std::string &cacheFilePath, bool isDebug, panda::ArenaAllocator *allocator) { std::fstream input(cacheFilePath, std::ios::in | std::ios::binary); if (!input) { - std::cerr << "Failed to open cache file: " << cacheFilePath << std::endl; + std::cerr << "Cache file: " << cacheFilePath << " doesn't exist" << std::endl; return nullptr; } protoPanda::CompositeProgram protoCompositeProgram; @@ -78,8 +78,12 @@ std::unordered_map *ProtobufS return nullptr; } + if (protoCompositeProgram.isdebug() != isDebug) { + return nullptr; + } + auto compositeProgramMap = allocator->New>(); - CompositeProgram::Deserialize(protoCompositeProgram, *compositeProgramMap, isDebug, allocator); + CompositeProgram::Deserialize(protoCompositeProgram, *compositeProgramMap, allocator); return compositeProgramMap; } diff --git a/merge_abc/src/protobufSnapshotGenerator.h b/merge_abc/src/protobufSnapshotGenerator.h index a735ba4535..20bb7118e9 100644 --- a/merge_abc/src/protobufSnapshotGenerator.h +++ b/merge_abc/src/protobufSnapshotGenerator.h @@ -26,7 +26,7 @@ public: static void GenerateProgram(const std::string &inputName, panda::pandasm::Program &prog, panda::ArenaAllocator *allocator); static std::unordered_map *GetCacheContext( - const std::string &cacheFilePath, bool &isDebug, panda::ArenaAllocator *allocator); + const std::string &cacheFilePath, bool isDebug, panda::ArenaAllocator *allocator); static void UpdateCacheFile( const std::unordered_map &compositeProgram, bool &isDebug, const std::string &cacheFilePath); -- Gitee