From abbef52188cb52fc75b3d6ea57dbda3bd17b7b23 Mon Sep 17 00:00:00 2001 From: Maxim Bolshov Date: Thu, 28 Aug 2025 16:04:55 +0300 Subject: [PATCH 1/3] stdlib declaration files bootstrap decls Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICWWVO?from=project-issue Change-Id: I92fc331aa4bb41b3a46af02cc0bd7ba8f78b3d69 Signed-off-by: Daniel Kofanov --- static_core/plugins/ets/CMakeLists.txt | 7 ++++++- static_core/plugins/ets/stdlib/std/core/Null.ets | 2 +- .../ets/stdlib/{arktsconfig.json => stdconfig.json} | 10 +++------- .../tests-u-runner/runner/plugins/ets/runner_ets.py | 10 ---------- 4 files changed, 10 insertions(+), 19 deletions(-) rename static_core/plugins/ets/stdlib/{arktsconfig.json => stdconfig.json} (70%) diff --git a/static_core/plugins/ets/CMakeLists.txt b/static_core/plugins/ets/CMakeLists.txt index efa6693cec..107e29e618 100644 --- a/static_core/plugins/ets/CMakeLists.txt +++ b/static_core/plugins/ets/CMakeLists.txt @@ -53,9 +53,14 @@ function(compile_ets_code ETS_SRC OUTPUT_ABC TARGET) file(MAKE_DIRECTORY ${OUTPUT_DIR}) if ("${ETS_SRC}" STREQUAL "GEN_STD_LIB") + set(STDLIB ${CMAKE_CURRENT_LIST_DIR}/stdlib/) + set(DECLS_DST_DIR "${OUTPUT_DIR}/etsstdlib") + file(MAKE_DIRECTORY ${DECLS_DST_DIR}) list(APPEND ES2PANDA_ARGUMENTS "--gen-stdlib=true") + list(APPEND ES2PANDA_ARGUMENTS "--generate-decl:enabled,path=${DECLS_DST_DIR}") + list(APPEND ES2PANDA_ARGUMENTS "--arktsconfig=${STDLIB}/stdconfig.json") + set(STAMP "${OUTPUT_ABC}.stamp") - set(STDLIB ${CMAKE_CURRENT_LIST_DIR}/stdlib/) file(WRITE ${STAMP} "") add_custom_target(${TARGET}.stamp BYPRODUCTS ${STAMP} diff --git a/static_core/plugins/ets/stdlib/std/core/Null.ets b/static_core/plugins/ets/stdlib/std/core/Null.ets index a4a3fde28e..986a6f565c 100644 --- a/static_core/plugins/ets/stdlib/std/core/Null.ets +++ b/static_core/plugins/ets/stdlib/std/core/Null.ets @@ -15,7 +15,7 @@ package std.core; -final class Null { +export final class Null { private constructor() { }; public override toString(): String { return "null"; } diff --git a/static_core/plugins/ets/stdlib/arktsconfig.json b/static_core/plugins/ets/stdlib/stdconfig.json similarity index 70% rename from static_core/plugins/ets/stdlib/arktsconfig.json rename to static_core/plugins/ets/stdlib/stdconfig.json index f426767b3c..5a73e47ed8 100644 --- a/static_core/plugins/ets/stdlib/arktsconfig.json +++ b/static_core/plugins/ets/stdlib/stdconfig.json @@ -8,10 +8,6 @@ "escompat": [ "ets/stdlib/escompat" ] - }, - "outDir": "../cache" - }, - "include": [ - "./**/*.ets" - ] -} \ No newline at end of file + } + } +} diff --git a/static_core/tests/tests-u-runner/runner/plugins/ets/runner_ets.py b/static_core/tests/tests-u-runner/runner/plugins/ets/runner_ets.py index 45a8e68b46..4611d5aa98 100644 --- a/static_core/tests/tests-u-runner/runner/plugins/ets/runner_ets.py +++ b/static_core/tests/tests-u-runner/runner/plugins/ets/runner_ets.py @@ -131,7 +131,6 @@ class RunnerETS(RunnerFileBased): def _check_binary_artifacts(self) -> None: stdlib_path_obj = Path(self.stdlib_path) - stdlib_src_path_obj = Path(self._get_std_from_arktsconfig()) if not stdlib_path_obj.is_file(): Log.exception_and_raise( @@ -139,15 +138,6 @@ class RunnerETS(RunnerFileBased): f"Standard library at {self.stdlib_path} was not found", FileNotFoundError) - if not stdlib_src_path_obj.is_dir(): - path_as_string = str(stdlib_src_path_obj) - - Log.exception_and_raise( - _LOGGER, - f"Source code of standard library at {path_as_string} was not found, " - "please set the correct eTS stdlib root!", - FileNotFoundError) - # We use Log.exception_and_raise which throws exception. no need in return # pylint: disable=inconsistent-return-statements def _get_std_from_arktsconfig(self) -> Any: -- Gitee From 358796df6e4a267ec214d9789217923b156e7db0 Mon Sep 17 00:00:00 2001 From: lirismankarina Date: Fri, 22 Aug 2025 19:56:27 +0300 Subject: [PATCH 2/3] [core] Parsing from single .abc via offset Issue: [es2panda] Parsing from single .abc via offset https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICUN2Y Reason: Need to make parsing from abc file faster Description: update of abc file and parsing from es2panda Tests: ninja all tests Signed-off-by: lirismankarina --- bundle.json | 7 --- .../inspect_api/files/files_test.cpp | 4 +- static_core/assembler/assembly-emitter.cpp | 5 +- static_core/docs/file_format.md | 4 +- static_core/isa/ChangeLog.md | 4 ++ static_core/isa/isa.yaml | 4 +- static_core/libarkfile/file-inl.h | 48 +++++++++++++++++++ static_core/libarkfile/file.h | 10 ++++ .../libarkfile/file_item_container.cpp | 36 ++++++++++++-- static_core/libarkfile/file_item_container.h | 7 +++ .../tests/file_item_container_test.cpp | 10 +++- static_core/scripts/sdk/headers.txt | 1 - .../scripts/sdk/linux_arm64_host_tools.txt | 1 - static_core/scripts/sdk/linux_host_tools.txt | 1 - static_core/scripts/sdk/ohos_arm32.txt | 1 - static_core/scripts/sdk/ohos_arm64.txt | 1 - .../test/test_file_expected_list_arm64.txt | 1 - .../test/test_file_expected_list_linux.txt | 1 - ...t_file_expected_list_linux_withoutLLVM.txt | 1 - .../test_file_expected_list_ohos_arm32.txt | 1 - .../test_file_expected_list_ohos_arm64.txt | 2 - ...e_expected_list_ohos_arm64_withoutLLVM.txt | 2 - 22 files changed, 119 insertions(+), 33 deletions(-) diff --git a/bundle.json b/bundle.json index 7861996391..7f3380a2d8 100644 --- a/bundle.json +++ b/bundle.json @@ -199,13 +199,6 @@ "header_base": "//arkcompiler/runtime_core/static_core/assembler" } }, - { - "name": "//arkcompiler/runtime_core/static_core/abc2program:libarktsabc2program_package", - "header": { - "header_files": [], - "header_base": "//arkcompiler/runtime_core/static_core/abc2program" - } - }, { "name": "//arkcompiler/runtime_core/static_core/bytecode_optimizer:libarktsbytecodeopt_package", "header": { diff --git a/libabckit/tests/ut/metadata_core/inspect_api/files/files_test.cpp b/libabckit/tests/ut/metadata_core/inspect_api/files/files_test.cpp index 7229aadd3a..c3949b56c9 100644 --- a/libabckit/tests/ut/metadata_core/inspect_api/files/files_test.cpp +++ b/libabckit/tests/ut/metadata_core/inspect_api/files/files_test.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -38,7 +38,7 @@ TEST_F(LibAbcKitInspectApiFilesTest, StaticFileGetVersion) helpers::AssertOpenAbc(ABCKIT_ABC_DIR "ut/metadata_core/inspect_api/files/file_static.abc", &file); AbckitFileVersion version = g_implI->fileGetVersion(file); - std::array expectedVersion = {0, 0, 0, 5}; + std::array expectedVersion = {0, 0, 0, 6}; const auto versionsEquality = std::memcmp(expectedVersion.data(), version, sizeof(uint8_t) * ABCKIT_VERSION_SIZE); ASSERT_EQ(versionsEquality, 0); diff --git a/static_core/assembler/assembly-emitter.cpp b/static_core/assembler/assembly-emitter.cpp index 25f31136ee..888b1d3e59 100644 --- a/static_core/assembler/assembly-emitter.cpp +++ b/static_core/assembler/assembly-emitter.cpp @@ -1165,8 +1165,9 @@ bool AsmEmitter::HandleRecord(ItemContainer *items, const Program &program, AsmE Type recordType = Type::FromName(name); auto *record = items->GetOrCreateClassItem(recordType.GetDescriptor(rec.conflict)); entities.classItems.insert({name, record}); - - record->SetAccessFlags(rec.metadata->GetAccessFlags()); + if (rec.metadata != nullptr) { + record->SetAccessFlags(rec.metadata->GetAccessFlags()); + } record->SetSourceLang(rec.language); if (!rec.sourceFile.empty()) { diff --git a/static_core/docs/file_format.md b/static_core/docs/file_format.md index bed01003d7..1a2a8d8232 100644 --- a/static_core/docs/file_format.md +++ b/static_core/docs/file_format.md @@ -260,12 +260,14 @@ Format: | ---- | ------ | ----------- | | `magic` | `uint8_t[8]` | Magic string. Must be 'P' 'A' 'N' 'D' 'A' '\\0' '\\0' '\\0' | | `checksum` | `uint8_t[4]` | adler32 checksum of the file except magic and checksum fields. | -| `version` | `uint8_t[4]` | Version of the format. Current version is 0002. | +| `version` | `uint8_t[4]` | Version of the format. Current version is 0006. | | `file_size` | `uint32_t` | Size of the file in bytes. | | `foreign_off` | `uint32_t` | Offset to a foreign region. The region must contain elements of types only [ForeignField](#foreignfield), [ForeignMethod](#foreignmethod), or [ForeignClass](#foreignclass). Using `foreign_off` points to the first entity is not necessary. Runtime must use `foreign_off` and `foreign_size` to determine the type of offset. | | `foreign_size` | `uint32_t` | Size of the foreign region in bytes. | | `num_classes` | `uint32_t` | Number of classes defined in the file. This is also the number of elements in the [ClassIndex](#classindex) structure. | | `class_idx_off` | `uint32_t` | Offset to the class index structure. The offset must point to a structure in [ClassIndex](#classindex) format. | +| `num_export_table` | `uint32_t` | Number of exported classes defined in the file. The number can also be zero since the field is optional. | +| `export_table_off` | `uint32_t` | Offset to the exported class index structure. The offset must point to a structure in [ClassIndex](#classindex) | | `num_lnps` | `uint32_t` | Number of line number programs in the file. This is also the number of elements in the [LineNumberProgramIndex](#linenumberprogramindex) structure. | | `lnp_idx_off` | `uint32_t` | Offset to the line number program index structure. The offset must point to a structure in [LineNumberProgramIndex](#linenumberprogramindex) format. | | `num_literalarrays` | `uint32_t` | Number of literalArrays defined in the file. This is also the number of elements in the [LiteralArrayIndex](#literalarrayindex) structure. | diff --git a/static_core/isa/ChangeLog.md b/static_core/isa/ChangeLog.md index 0588e721da..84d9a6ee32 100644 --- a/static_core/isa/ChangeLog.md +++ b/static_core/isa/ChangeLog.md @@ -1,6 +1,10 @@ File format and ISA ChangeLog ============================= +* 0.0.0.6 + + Added export table for faster reading from abc + + Changed header - 2 new items for supporting table + * 0.0.0.5 + Removed calli.dyn and return.dyn opcodes diff --git a/static_core/isa/isa.yaml b/static_core/isa/isa.yaml index 5c5368dc4c..923c277d40 100644 --- a/static_core/isa/isa.yaml +++ b/static_core/isa/isa.yaml @@ -104,8 +104,8 @@ chapters: value. Regular static instructions can also be used when the VM executes a code inside a dynamically-typed language context. # File format and ISA versioning -min_version: 0.0.0.5 -version: 0.0.0.5 +min_version: 0.0.0.6 +version: 0.0.0.6 properties: - tag: type_id diff --git a/static_core/libarkfile/file-inl.h b/static_core/libarkfile/file-inl.h index 1319b39c8b..cb73c79488 100644 --- a/static_core/libarkfile/file-inl.h +++ b/static_core/libarkfile/file-inl.h @@ -35,6 +35,54 @@ inline File::StringData File::GetStringData(EntityId id) const return strData; } +// CC-OFFNXT(G.FUD.06) switch-case +inline std::string StringDataToString(File::StringData sd) +{ + std::string str = std::string(utf::Mutf8AsCString(sd.data)); + size_t symPos = 0; + while (symPos = str.find_first_of("\a\b\f\n\r\t\v\'\?\\", symPos), symPos != std::string::npos) { + std::string sym; + switch (str[symPos]) { + case '\a': + sym = R"(\a)"; + break; + case '\b': + sym = R"(\b)"; + break; + case '\f': + sym = R"(\f)"; + break; + case '\n': + sym = R"(\n)"; + break; + case '\r': + sym = R"(\r)"; + break; + case '\t': + sym = R"(\t)"; + break; + case '\v': + sym = R"(\v)"; + break; + case '\'': + sym = R"(\')"; + break; + case '\?': + sym = R"(\?)"; + break; + case '\\': + sym = R"(\\)"; + break; + default: + UNREACHABLE(); + } + str = str.replace(symPos, 1, sym); + ASSERT(sym.size() == 2U); + symPos += 2U; + } + return str; +} + } // namespace ark::panda_file #endif diff --git a/static_core/libarkfile/file.h b/static_core/libarkfile/file.h index 0232acaf93..a2467f5b4b 100644 --- a/static_core/libarkfile/file.h +++ b/static_core/libarkfile/file.h @@ -65,6 +65,8 @@ public: uint32_t quickenedFlag; uint32_t numClasses; uint32_t classIdxOff; + uint32_t numExportTable; + uint32_t exportTableOff; uint32_t numLnps; uint32_t lnpIdxOff; uint32_t numLiteralarrays; @@ -194,6 +196,14 @@ public: return Span(reinterpret_cast(classIdxData.data()), header->numClasses); } + Span GetExported() const + { + const Header *header = GetHeader(); + Span file(GetBase(), header->fileSize); + Span exportedIdxData = file.SubSpan(header->exportTableOff, header->numExportTable * sizeof(uint32_t)); + return Span(reinterpret_cast(exportedIdxData.data()), header->numExportTable); + } + Span GetLiteralArrays() const { const Header *header = GetHeader(); diff --git a/static_core/libarkfile/file_item_container.cpp b/static_core/libarkfile/file_item_container.cpp index a6e9ba844c..dc97ce994b 100644 --- a/static_core/libarkfile/file_item_container.cpp +++ b/static_core/libarkfile/file_item_container.cpp @@ -515,12 +515,25 @@ uint32_t ItemContainer::DeleteForeignItems() return 0; } +void ItemContainer::FillExportMap() +{ + for (auto it : classMap_) { + if (!it.second->IsForeign() && it.first.rfind("ETSGLOBAL") != std::string::npos) { + exportMap_.insert({it.first, it.second}); + } + } +} + uint32_t ItemContainer::ComputeLayout() { + FillExportMap(); + uint32_t numClasses = classMap_.size(); uint32_t numLiteralarrays = literalarrayMap_.size(); + uint32_t numExportClasses = exportMap_.size(); uint32_t classIdxOffset = sizeof(File::Header); - uint32_t curOffset = classIdxOffset + (numClasses + numLiteralarrays) * ID_SIZE; + uint32_t exportIdxOffset = classIdxOffset + numClasses * ID_SIZE; // immediately after class table + uint32_t curOffset = exportIdxOffset + (numExportClasses + numLiteralarrays) * ID_SIZE; UpdateOrderIndexes(); UpdateLiteralIndexes(); @@ -669,6 +682,15 @@ bool ItemContainer::WriteHeaderIndexInfo(Writer *writer) return false; } + if (!writer->Write(exportMap_.size())) { + return false; + } + + uint32_t exportMapOffset = sizeof(File::Header) + classMap_.size() * ID_SIZE; + if (!writer->Write(exportMapOffset)) { + return false; + } + if (!writer->Write(lineNumberProgramIndexItem_.GetNumItems())) { return false; } @@ -681,7 +703,7 @@ bool ItemContainer::WriteHeaderIndexInfo(Writer *writer) return false; } - uint32_t literalarrayIdxOffset = sizeof(File::Header) + classMap_.size() * ID_SIZE; + uint32_t literalarrayIdxOffset = sizeof(File::Header) + (classMap_.size() + exportMap_.size()) * ID_SIZE; if (!writer->Write(literalarrayIdxOffset)) { return false; } @@ -751,15 +773,20 @@ bool ItemContainer::Write(Writer *writer, bool deduplicateItems, bool computeLay ASSERT(checksumOffset != -1); // Write class idx - for (auto &entry : classMap_) { if (!writer->Write(entry.second->GetOffset())) { return false; } } - // Write literalArray idx + // Write export class idx + for (auto &entry : exportMap_) { + if (!writer->Write(entry.second->GetOffset())) { + return false; + } + } + // Write literalArray idx for (auto &entry : literalarrayMap_) { if (!writer->Write(entry.second->GetOffset())) { return false; @@ -813,6 +840,7 @@ std::map ItemContainer::GetStat() stat["header_item"] = sizeof(File::Header); stat["class_idx_item"] = classMap_.size() * ID_SIZE; + stat["export_table_idx_item"] = exportMap_.size() * ID_SIZE; stat["line_number_program_idx_item"] = lineNumberProgramIndexItem_.GetNumItems() * ID_SIZE; stat["literalarray_idx"] = literalarrayMap_.size() * ID_SIZE; diff --git a/static_core/libarkfile/file_item_container.h b/static_core/libarkfile/file_item_container.h index 6e70e513ec..406beff277 100644 --- a/static_core/libarkfile/file_item_container.h +++ b/static_core/libarkfile/file_item_container.h @@ -114,6 +114,7 @@ public: return ret; } + PANDA_PUBLIC_API void FillExportMap(); PANDA_PUBLIC_API uint32_t ComputeLayout(); PANDA_PUBLIC_API void MarkLiteralarrayMap(); PANDA_PUBLIC_API void DeleteReferenceFromAnno(AnnotationItem *annoItem); @@ -142,6 +143,11 @@ public: return &classMap_; } + std::map *GetExportMap() + { + return &exportMap_; + } + std::unordered_map *GetIntValueMap() { return &intValueMap_; @@ -558,6 +564,7 @@ private: std::map literalarrayMap_; std::map classMap_; + std::map exportMap_; std::unordered_map intValueMap_; std::unordered_map longValueMap_; diff --git a/static_core/libarkfile/tests/file_item_container_test.cpp b/static_core/libarkfile/tests/file_item_container_test.cpp index 43737631b3..e9826bd7b5 100644 --- a/static_core/libarkfile/tests/file_item_container_test.cpp +++ b/static_core/libarkfile/tests/file_item_container_test.cpp @@ -153,7 +153,7 @@ TEST(ItemContainer, TestFileFormatVersionValid) // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) std::fill(reinterpret_cast(&header), reinterpret_cast(&header) + sizeof(header), 0); header.magic = File::MAGIC; - header.version = {0, 0, 0, 5}; + header.version = {0, 0, 0, 6}; header.fileSize = sizeof(File::Header); auto pChecksumData = reinterpret_cast(&header.version); auto checksum = adler32(1, pChecksumData, sizeof(header) - offsetof(File::Header, version)); @@ -244,12 +244,15 @@ TEST(ItemContainer, TestClasses) ASSERT_NE(pandaFile, nullptr); - EXPECT_THAT(pandaFile->GetHeader()->version, ::testing::ElementsAre(0, 0, 0, 5)); + EXPECT_THAT(pandaFile->GetHeader()->version, ::testing::ElementsAre(0, 0, 0, 6)); EXPECT_EQ(pandaFile->GetHeader()->fileSize, memWriter.GetData().size()); EXPECT_EQ(pandaFile->GetHeader()->foreignOff, 0U); EXPECT_EQ(pandaFile->GetHeader()->foreignSize, 0U); EXPECT_EQ(pandaFile->GetHeader()->numClasses, 3U); EXPECT_EQ(pandaFile->GetHeader()->classIdxOff, sizeof(File::Header)); + EXPECT_EQ(pandaFile->GetHeader()->numExportTable, 0U); + EXPECT_EQ(pandaFile->GetHeader()->exportTableOff, + sizeof(File::Header) + (pandaFile->GetHeader()->numClasses * File::EntityId::GetSize())); // NOLINTBEGIN(cppcoreguidelines-pro-bounds-pointer-arithmetic) const auto *classIndex = @@ -997,6 +1000,9 @@ TEST(ItemContainer, GettersTest) auto it = classMap->find("Bar"); ASSERT_TRUE(it != classMap->end()); + std::map *exportMap = container.GetExportMap(); + ASSERT_TRUE(exportMap != nullptr && exportMap->size() == 0); + std::unordered_map *stringMap = container.GetStringMap(); ASSERT_TRUE(stringMap != nullptr && stringMap->size() == 4); auto sit0 = stringMap->find("field"); diff --git a/static_core/scripts/sdk/headers.txt b/static_core/scripts/sdk/headers.txt index b8dce7a5a6..a13cc1f882 100644 --- a/static_core/scripts/sdk/headers.txt +++ b/static_core/scripts/sdk/headers.txt @@ -1,4 +1,3 @@ -abc2program compiler/aot compiler/code_info compiler/compiler_options.h diff --git a/static_core/scripts/sdk/linux_arm64_host_tools.txt b/static_core/scripts/sdk/linux_arm64_host_tools.txt index 7a2aba92ac..c4bd8d2911 100644 --- a/static_core/scripts/sdk/linux_arm64_host_tools.txt +++ b/static_core/scripts/sdk/linux_arm64_host_tools.txt @@ -6,7 +6,6 @@ bin/aspt_converter bin/dependency_analyzer bin/es2panda bin/verifier -lib/libabc2program.so lib/libarkaotmanager.so lib/libarkassembler.so lib/libarkbase.so diff --git a/static_core/scripts/sdk/linux_host_tools.txt b/static_core/scripts/sdk/linux_host_tools.txt index 153d47a9d6..23cee76499 100644 --- a/static_core/scripts/sdk/linux_host_tools.txt +++ b/static_core/scripts/sdk/linux_host_tools.txt @@ -6,7 +6,6 @@ bin/aspt_converter bin/dependency_analyzer bin/es2panda bin/verifier -lib/libabc2program.so lib/libarkaotmanager.so lib/libarkassembler.so lib/libarkbase.so diff --git a/static_core/scripts/sdk/ohos_arm32.txt b/static_core/scripts/sdk/ohos_arm32.txt index fcf793fa43..227a66ce43 100644 --- a/static_core/scripts/sdk/ohos_arm32.txt +++ b/static_core/scripts/sdk/ohos_arm32.txt @@ -1,7 +1,6 @@ bin/ark bin/aspt_converter bin/dependency_analyzer -lib/libabc2program.so lib/libarkaotmanager.so lib/libarkassembler.so lib/libarkbase.so diff --git a/static_core/scripts/sdk/ohos_arm64.txt b/static_core/scripts/sdk/ohos_arm64.txt index 634b8ca605..c8d5b09568 100644 --- a/static_core/scripts/sdk/ohos_arm64.txt +++ b/static_core/scripts/sdk/ohos_arm64.txt @@ -2,7 +2,6 @@ bin/ark bin/ark_aot bin/aspt_converter bin/dependency_analyzer -lib/libabc2program.so lib/libarkaotmanager.so lib/libarkassembler.so lib/libarkbase.so diff --git a/static_core/scripts/sdk/test/test_file_expected_list_arm64.txt b/static_core/scripts/sdk/test/test_file_expected_list_arm64.txt index 8021d7976d..d3907571e0 100644 --- a/static_core/scripts/sdk/test/test_file_expected_list_arm64.txt +++ b/static_core/scripts/sdk/test/test_file_expected_list_arm64.txt @@ -9,7 +9,6 @@ build-sdk/sdk/linux_arm64_host_tools/bin/dependency_analyzer build-sdk/sdk/linux_arm64_host_tools/bin/es2panda build-sdk/sdk/linux_arm64_host_tools/bin/verifier build-sdk/sdk/linux_arm64_host_tools/lib -build-sdk/sdk/linux_arm64_host_tools/lib/libabc2program.so build-sdk/sdk/linux_arm64_host_tools/lib/libarkaotmanager.so build-sdk/sdk/linux_arm64_host_tools/lib/libarkassembler.so build-sdk/sdk/linux_arm64_host_tools/lib/libarkbase.so diff --git a/static_core/scripts/sdk/test/test_file_expected_list_linux.txt b/static_core/scripts/sdk/test/test_file_expected_list_linux.txt index f53d7656da..1de8dfd9f6 100644 --- a/static_core/scripts/sdk/test/test_file_expected_list_linux.txt +++ b/static_core/scripts/sdk/test/test_file_expected_list_linux.txt @@ -10,7 +10,6 @@ build-sdk/sdk/linux_host_tools/bin/es2panda build-sdk/sdk/linux_host_tools/bin/verifier build-sdk/sdk/linux_host_tools/lib build-sdk/sdk/linux_host_tools/lib/libLLVM-15.so -build-sdk/sdk/linux_host_tools/lib/libabc2program.so build-sdk/sdk/linux_host_tools/lib/libarkaotmanager.so build-sdk/sdk/linux_host_tools/lib/libarkassembler.so build-sdk/sdk/linux_host_tools/lib/libarkbase.so diff --git a/static_core/scripts/sdk/test/test_file_expected_list_linux_withoutLLVM.txt b/static_core/scripts/sdk/test/test_file_expected_list_linux_withoutLLVM.txt index 9da7d58cc1..b79f1eb5af 100644 --- a/static_core/scripts/sdk/test/test_file_expected_list_linux_withoutLLVM.txt +++ b/static_core/scripts/sdk/test/test_file_expected_list_linux_withoutLLVM.txt @@ -10,7 +10,6 @@ build-sdk/sdk/linux_host_tools/bin/es2panda build-sdk/sdk/linux_host_tools/bin/verifier build-sdk/sdk/linux_host_tools/lib build-sdk/sdk/linux_host_tools/lib/libani_helpers.so -build-sdk/sdk/linux_host_tools/lib/libabc2program.so build-sdk/sdk/linux_host_tools/lib/libarkaotmanager.so build-sdk/sdk/linux_host_tools/lib/libarkassembler.so build-sdk/sdk/linux_host_tools/lib/libarkbase.so diff --git a/static_core/scripts/sdk/test/test_file_expected_list_ohos_arm32.txt b/static_core/scripts/sdk/test/test_file_expected_list_ohos_arm32.txt index 12c5185080..db9c5a27de 100644 --- a/static_core/scripts/sdk/test/test_file_expected_list_ohos_arm32.txt +++ b/static_core/scripts/sdk/test/test_file_expected_list_ohos_arm32.txt @@ -4,7 +4,6 @@ build-sdk/sdk/ohos_arm32/bin/ark build-sdk/sdk/ohos_arm32/bin/aspt_converter build-sdk/sdk/ohos_arm32/bin/dependency_analyzer build-sdk/sdk/ohos_arm32/lib -build-sdk/sdk/ohos_arm32/lib/libabc2program.so build-sdk/sdk/ohos_arm32/lib/libarkaotmanager.so build-sdk/sdk/ohos_arm32/lib/libarkassembler.so build-sdk/sdk/ohos_arm32/lib/libarkbase.so diff --git a/static_core/scripts/sdk/test/test_file_expected_list_ohos_arm64.txt b/static_core/scripts/sdk/test/test_file_expected_list_ohos_arm64.txt index 95a8d31716..abf4f2264b 100644 --- a/static_core/scripts/sdk/test/test_file_expected_list_ohos_arm64.txt +++ b/static_core/scripts/sdk/test/test_file_expected_list_ohos_arm64.txt @@ -5,7 +5,6 @@ build-sdk/sdk/ohos_arm64/bin/ark_aot build-sdk/sdk/ohos_arm64/bin/aspt_converter build-sdk/sdk/ohos_arm64/bin/dependency_analyzer build-sdk/sdk/ohos_arm64/include -build-sdk/sdk/ohos_arm64/include/abc2program build-sdk/sdk/ohos_arm64/include/compiler build-sdk/sdk/ohos_arm64/include/libpandabase build-sdk/sdk/ohos_arm64/include/libarkfile @@ -18,7 +17,6 @@ build-sdk/sdk/ohos_arm64/include/tools build-sdk/sdk/ohos_arm64/include/verification build-sdk/sdk/ohos_arm64/lib build-sdk/sdk/ohos_arm64/lib/libLLVM-15.so -build-sdk/sdk/ohos_arm64/lib/libabc2program.so build-sdk/sdk/ohos_arm64/lib/libarkaotmanager.so build-sdk/sdk/ohos_arm64/lib/libarkassembler.so build-sdk/sdk/ohos_arm64/lib/libarkbase.so diff --git a/static_core/scripts/sdk/test/test_file_expected_list_ohos_arm64_withoutLLVM.txt b/static_core/scripts/sdk/test/test_file_expected_list_ohos_arm64_withoutLLVM.txt index 927c13cccf..0167d91aae 100644 --- a/static_core/scripts/sdk/test/test_file_expected_list_ohos_arm64_withoutLLVM.txt +++ b/static_core/scripts/sdk/test/test_file_expected_list_ohos_arm64_withoutLLVM.txt @@ -5,7 +5,6 @@ build-sdk/sdk/ohos_arm64/bin/ark_aot build-sdk/sdk/ohos_arm64/bin/aspt_converter build-sdk/sdk/ohos_arm64/bin/dependency_analyzer build-sdk/sdk/ohos_arm64/include -build-sdk/sdk/ohos_arm64/include/abc2program build-sdk/sdk/ohos_arm64/include/compiler build-sdk/sdk/ohos_arm64/include/libpandabase build-sdk/sdk/ohos_arm64/include/libarkfile @@ -17,7 +16,6 @@ build-sdk/sdk/ohos_arm64/include/third_party build-sdk/sdk/ohos_arm64/include/tools build-sdk/sdk/ohos_arm64/include/verification build-sdk/sdk/ohos_arm64/lib -build-sdk/sdk/ohos_arm64/lib/libabc2program.so build-sdk/sdk/ohos_arm64/lib/libani_helpers.so build-sdk/sdk/ohos_arm64/lib/libarkaotmanager.so build-sdk/sdk/ohos_arm64/lib/libarkassembler.so -- Gitee From 80508fe4ee9455c535e9d160eba86a3578471a3c Mon Sep 17 00:00:00 2001 From: lirismankarina Date: Mon, 1 Sep 2025 21:15:17 +0300 Subject: [PATCH 3/3] [core] Parsing from .d.ets that were taken from etsstdlib.abc Signed-off-by: lirismankarina --- static_core/plugins/ets/BUILD.gn | 1 + .../ets/runtime/intrinsics/escompat_Array.cpp | 4 +- .../plugins/ets/stdlib/arktsconfig.json | 51 +++++++++++++++++++ .../plugins/ets/stdlib/etsstdlib.d.ets | 0 .../CMakeLists.txt | 40 +++++++++++++++ .../arktsconfig.in.json | 10 ++++ .../declarations_from_etsstdlib_abc/test.ets | 6 +++ .../ets_test_suite/strings/CMakeLists.txt | 1 + .../ets/tests/runtime/tooling/CMakeLists.txt | 4 +- .../ets/tests/scripts/sunspider_compile.sh | 2 +- 10 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 static_core/plugins/ets/stdlib/arktsconfig.json create mode 100644 static_core/plugins/ets/stdlib/etsstdlib.d.ets create mode 100644 static_core/plugins/ets/tests/common/declarations_from_etsstdlib_abc/CMakeLists.txt create mode 100644 static_core/plugins/ets/tests/common/declarations_from_etsstdlib_abc/arktsconfig.in.json create mode 100644 static_core/plugins/ets/tests/common/declarations_from_etsstdlib_abc/test.ets diff --git a/static_core/plugins/ets/BUILD.gn b/static_core/plugins/ets/BUILD.gn index 94da8b8370..4d2462eead 100644 --- a/static_core/plugins/ets/BUILD.gn +++ b/static_core/plugins/ets/BUILD.gn @@ -314,6 +314,7 @@ if (with_stdlib) { "--extension=ets", "--opt-level=2", "--gen-stdlib=true", + "--emit-declaration=true", "--output=" + rebase_path(outputs[0], root_build_dir), ] } diff --git a/static_core/plugins/ets/runtime/intrinsics/escompat_Array.cpp b/static_core/plugins/ets/runtime/intrinsics/escompat_Array.cpp index c61d5c6dbf..2ac9064631 100644 --- a/static_core/plugins/ets/runtime/intrinsics/escompat_Array.cpp +++ b/static_core/plugins/ets/runtime/intrinsics/escompat_Array.cpp @@ -550,10 +550,10 @@ static void RefReverse(void *arrAddr, int32_t length, mem::GCBarrierSet *barrier } swap(aPtr, bPtr); }; - auto putSafepoint = [&usePreBarrier, barrierSet, arr](size_t dstStart, size_t dstEndMirror, size_t length) { + auto putSafepoint = [&usePreBarrier, barrierSet, arr](size_t dstStart, size_t dstEndMirror, size_t len) { if (barrierSet->GetPostType() != ark::mem::BarrierType::POST_WRB_NONE) { constexpr uint32_t OFFSET = ark::coretypes::Array::GetDataOffset(); - const uint32_t size = length * sizeof(ObjectPointerType); + const uint32_t size = len * sizeof(ObjectPointerType); barrierSet->PostBarrier(arr, OFFSET + dstStart * sizeof(ObjectPointerType), size); barrierSet->PostBarrier(arr, OFFSET + dstEndMirror * sizeof(ObjectPointerType) - size, size); } diff --git a/static_core/plugins/ets/stdlib/arktsconfig.json b/static_core/plugins/ets/stdlib/arktsconfig.json new file mode 100644 index 0000000000..9ab32e43eb --- /dev/null +++ b/static_core/plugins/ets/stdlib/arktsconfig.json @@ -0,0 +1,51 @@ +{ + "!NOTE!": "Generated from /home/karinalirisman/openharmony/ets_frontend/ets2panda/CMakeLists.txt", + + "compilerOptions": { + "cacheDir": "/home/karinalirisman/openharmony/build", + "baseUrl": "/home/karinalirisman/openharmony/runtime_core/static_core", + "paths": { + "@ohos.buffer": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/api/@ohos.buffer.ets"], + "@ohos.util.ArrayList": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/api/@ohos.util.ArrayList.ets"], + "@ohos.util.Deque": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/api/@ohos.util.Deque.ets"], + "@ohos.util.HashMap": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/api/@ohos.util.HashMap.ets"], + "@ohos.util.HashSet": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/api/@ohos.util.HashSet.ets"], + "@ohos.util.LightWeightMap": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/api/@ohos.util.LightWeightMap.ets"], + "@ohos.util.LightWeightSet": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/api/@ohos.util.LightWeightSet.ets"], + "@ohos.util.LinkedList": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/api/@ohos.util.LinkedList.ets"], + "@ohos.util.List": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/api/@ohos.util.List.ets"], + "@ohos.util.PlainArray": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/api/@ohos.util.PlainArray.ets"], + "@ohos.util.Queue": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/api/@ohos.util.Queue.ets"], + "@ohos.util.Stack": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/api/@ohos.util.Stack.ets"], + "@ohos.util.stream": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/api/@ohos.util.stream.ets"], + "@ohos.util": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/api/@ohos.util.ets"], + "@ohos.util.TreeMap": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/api/@ohos.util.TreeMap.ets"], + "@ohos.util.TreeSet": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/api/@ohos.util.TreeSet.ets"], + "@ohos.uri": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/api/@ohos.uri.ets"], + "@ohos.url": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/api/@ohos.url.ets"], + "@ohos.xml": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/api/@ohos.xml.ets"], + "@ohos.base": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/api/@ohos.base.ets"], + "@arkts.math.Decimal": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/arkts/@arkts.math.Decimal.ets"], + "@arkts.collections": ["/home/karinalirisman/openharmony/runtime_core/static_core/plugins/ets/sdk/arkts/@arkts.collections.ets"], + "import_tests": ["/home/karinalirisman/openharmony/ets_frontend/ets2panda/test/parser/ets/import_tests"] + }, + "dependencies": { + "std/core": { "path": "/home/karinalirisman/openharmony/build/etsstdlib.abc" }, + "std/math": { "path": "/home/karinalirisman/openharmony/build/etsstdlib.abc" }, + "std/math/consts": { "path": "/home/karinalirisman/openharmony/build/etsstdlib.abc" }, + "std/containers": { "path": "/home/karinalirisman/openharmony/build/etsstdlib.abc" }, + "std/interop/js":{ "path": "/home/karinalirisman/openharmony/build/etsstdlib.abc" }, + "std/time": { "path": "/home/karinalirisman/openharmony/build/etsstdlib.abc" }, + "std/debug": { "path": "/home/karinalirisman/openharmony/build/etsstdlib.abc" }, + "std/debug/concurrency": { "path": "/home/karinalirisman/openharmony/build/etsstdlib.abc" }, + "std/testing": { "path": "/home/karinalirisman/openharmony/build/etsstdlib.abc" }, + "std/concurrency": { "path": "/home/karinalirisman/openharmony/build/etsstdlib.abc" }, + "std/annotations": { "path": "/home/karinalirisman/openharmony/build/etsstdlib.abc" }, + "std/interop": { "path": "/home/karinalirisman/openharmony/build/etsstdlib.abc" }, + "escompat": { "path": "/home/karinalirisman/openharmony/build/etsstdlib.abc" }, + "dynamic_import_tests": {"language": "js", "ohmUrl": "dynamic_import_tests"}, + "dynamic_import_tests/modules/instanceof": {"language": "js", "path": "/home/karinalirisman/openharmony/ets_frontend/ets2panda/test/parser/ets/dynamic_import_tests/modules/instanceof.ets", "ohmUrl": "/home/karinalirisman/openharmony/ets_frontend/ets2panda/test/parser/ets/dynamic_import_tests/modules/instanceof.ets"}, + "dynamic_import_tests/modules/module": {"language": "js", "path": "/home/karinalirisman/openharmony/ets_frontend/ets2panda/test/parser/ets/dynamic_import_tests/modules/module.ets", "ohmUrl": "/home/karinalirisman/openharmony/ets_frontend/ets2panda/test/parser/ets/dynamic_import_tests/modules/module.ets"} + } + } +} diff --git a/static_core/plugins/ets/stdlib/etsstdlib.d.ets b/static_core/plugins/ets/stdlib/etsstdlib.d.ets new file mode 100644 index 0000000000..e69de29bb2 diff --git a/static_core/plugins/ets/tests/common/declarations_from_etsstdlib_abc/CMakeLists.txt b/static_core/plugins/ets/tests/common/declarations_from_etsstdlib_abc/CMakeLists.txt new file mode 100644 index 0000000000..a2a8a3c7f9 --- /dev/null +++ b/static_core/plugins/ets/tests/common/declarations_from_etsstdlib_abc/CMakeLists.txt @@ -0,0 +1,40 @@ +# Copyright (c) 2024-2025 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. + +if (PANDA_TARGET_ARM32) + return() +endif() +MESSAGE("---CHECKING DECLARATIONS---") +set(ETSSTDLIB_SOURCE_ETS " ") +set(ETSSTDLIB_SOURCE_ABC ${CMAKE_CURRENT_BINARY_DIR}/etsstdlib.abc) +set(ETSSTDLIB_SOURCE_DETS ${CMAKE_CURRENT_SOURCE_DIR}/declGen) +set(ETSSTDLIB_SOURCE_ABC_TARGET compile_etsstdlib) + +#compile stdlib with declarations and dump d.ets files during declGenPhase +compile_ets_code(${ETSSTDLIB_SOURCE_ETS} ${ETSSTDLIB_SOURCE_ABC} ${ETSSTDLIB_SOURCE_ABC_TARGET} + COMPILER_EXTRA_OPTIONS "--emit-declaration --opt-level=0 --gen-stdlib=true --extension=ets --generate-decl:enabled --generate-decl:path=${ETSSTDLIB_SOURCE_DETS}") + +#configure arktsconfig.json - need to add etsstdlib.abc in dependencies +set(ETS_CONFIG ${CMAKE_CURRENT_BINARY_DIR}/arktsconfig.json) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/arktsconfig.in.json ${ETS_CONFIG}) + +set(TEST_SOURCE_ETS ${CMAKE_CURRENT_SOURCE_DIR}/test.ets) +set(TEST_SOURCE_ABC ${CMAKE_CURRENT_BINARY_DIR}/test.abc) +set(TEST_SOURCE_ABC_TARGET compile_test_file) + +#compile test.ets with @etsstdlib imported as etsstdlib.abc file +#currently the compilation will fail, but the declarations from etsstdlib.abc can be reached +compile_ets_code(${TEST_SOURCE_ETS} ${TEST_SOURCE_ABC} ${TEST_SOURCE_ABC_TARGET} + COMPILER_EXTRA_OPTIONS "--arktsconfig ${ETS_CONFIG}") + +#check that d.ets files from declGenPhase and from etsstdlib.abc have the same content \ No newline at end of file diff --git a/static_core/plugins/ets/tests/common/declarations_from_etsstdlib_abc/arktsconfig.in.json b/static_core/plugins/ets/tests/common/declarations_from_etsstdlib_abc/arktsconfig.in.json new file mode 100644 index 0000000000..e5c3968bd5 --- /dev/null +++ b/static_core/plugins/ets/tests/common/declarations_from_etsstdlib_abc/arktsconfig.in.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "cacheDir": "${CMAKE_CURRENT_SOURCE_DIR}/fromAbc", + "rootDir": "${CMAKE_CURRENT_SOURCE_DIR}" + }, + "dependencies": { + "@etsstdlib": {"path": "{ETSSTDLIB_SOURCE_ABC}" } + } +} + diff --git a/static_core/plugins/ets/tests/common/declarations_from_etsstdlib_abc/test.ets b/static_core/plugins/ets/tests/common/declarations_from_etsstdlib_abc/test.ets new file mode 100644 index 0000000000..866b496a86 --- /dev/null +++ b/static_core/plugins/ets/tests/common/declarations_from_etsstdlib_abc/test.ets @@ -0,0 +1,6 @@ + +import {sin} from "@etsstdlib" + +function main(): void { + console.log(sin(1)) +} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets_test_suite/strings/CMakeLists.txt b/static_core/plugins/ets/tests/ets_test_suite/strings/CMakeLists.txt index 19954d4039..ba4cad1c6b 100644 --- a/static_core/plugins/ets/tests/ets_test_suite/strings/CMakeLists.txt +++ b/static_core/plugins/ets/tests/ets_test_suite/strings/CMakeLists.txt @@ -68,6 +68,7 @@ add_custom_target(ets_test_suite_strings_concat_stdlib COMMAND ${es2panda_bin} --opt-level=2 --gen-stdlib=true + --emit-declaration=true --ets-strings-concat=true --extension=ets --output ${strings_tests_out_dir}/etsstdlib.abc diff --git a/static_core/plugins/ets/tests/runtime/tooling/CMakeLists.txt b/static_core/plugins/ets/tests/runtime/tooling/CMakeLists.txt index 544b5616be..bb2ab77f34 100644 --- a/static_core/plugins/ets/tests/runtime/tooling/CMakeLists.txt +++ b/static_core/plugins/ets/tests/runtime/tooling/CMakeLists.txt @@ -36,13 +36,13 @@ panda_ets_add_gtest( ) add_custom_target(es2panda_ets_stdlib_debug_info - COMMAND ${es2panda_bin} --opt-level=0 --debug-info --gen-stdlib=true + COMMAND ${es2panda_bin} --opt-level=0 --debug-info --gen-stdlib=true --emit-declaration=true --extension=ets --output ${CMAKE_CURRENT_BINARY_DIR}/etsstdlib.abc DEPENDS ${es2panda_target} ) add_custom_target(es2panda_convert_ets_debug_info - COMMAND ${es2panda_bin} --opt-level=0 --debug-info --gen-stdlib=false --extension=ets + COMMAND ${es2panda_bin} --opt-level=0 --debug-info --gen-stdlib=false --extension=ets --output ${CMAKE_CURRENT_BINARY_DIR}/BitopsBitwiseAnd.abc ${CMAKE_CURRENT_SOURCE_DIR}/BitopsBitwiseAnd.ets DEPENDS es2panda_ets_stdlib_debug_info ) diff --git a/static_core/plugins/ets/tests/scripts/sunspider_compile.sh b/static_core/plugins/ets/tests/scripts/sunspider_compile.sh index de4b7d4eaa..ecee7d67f0 100755 --- a/static_core/plugins/ets/tests/scripts/sunspider_compile.sh +++ b/static_core/plugins/ets/tests/scripts/sunspider_compile.sh @@ -28,7 +28,7 @@ script_path=$(cd "$script_path" && pwd) tests_path=$(cd "$script_path/../Sunspider" && pwd) cd "$build" -"${build}/bin/es2panda" --extension=ets --output=etsstdlib.abc --gen-stdlib=true +"${build}/bin/es2panda" --extension=ets --output=etsstdlib.abc --gen-stdlib=true --emit-declaration=true for f in $tests_path/*.ets; do name=$(basename "$f" .ets) echo "$name" -- Gitee