Enable sub version controlling

Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/IACORD

Signed-off-by: huyunhui1 <huyunhui1@huawei.com>
Change-Id: Ia6590fc54469f85c1459079a75411d64d91d0273
This commit is contained in:
huyunhui1 2024-07-12 22:48:09 +08:00
parent d70aa5bb6c
commit 821fd125c1
9 changed files with 45 additions and 19 deletions

View File

@ -50,9 +50,10 @@ bool Abc2ProgramCompiler::IsVersionLessEqual(
}
bool Abc2ProgramCompiler::CheckFileVersionIsSupported(std::array<uint8_t, panda_file::File::VERSION_SIZE> min_version,
uint8_t target_api_version) const
uint8_t target_api_version,
std::string target_api_sub_version) const
{
auto target_version = panda_file::GetVersionByApi(target_api_version);
auto target_version = panda_file::GetVersionByApi(target_api_version, target_api_sub_version);
if (!target_version.has_value()) {
return false;
}

View File

@ -28,7 +28,7 @@ public:
~Abc2ProgramCompiler();
bool OpenAbcFile(const std::string &file_path);
bool CheckFileVersionIsSupported(std::array<uint8_t, panda_file::File::VERSION_SIZE> min_version,
uint8_t target_api_version) const;
uint8_t target_api_version, std::string target_api_sub_version) const;
const panda_file::File &GetAbcFile() const;
const panda_file::DebugInfoExtractor &GetDebugInfoExtractor() const;
pandasm::Program *CompileAbcFile();

View File

@ -1424,7 +1424,7 @@ static void MakeConcurrentModuleRequestsAnnotation(Program *prog)
}
bool AsmEmitter::EmitPrograms(const std::string &filename, const std::vector<Program *> &progs, bool emit_debug_info,
uint8_t api)
uint8_t api, std::string subApi)
{
ASSERT(!progs.empty());
for (auto *prog : progs) {
@ -1435,6 +1435,7 @@ bool AsmEmitter::EmitPrograms(const std::string &filename, const std::vector<Pro
}
ItemContainer::SetApi(api);
ItemContainer::SetSubApi(subApi);
auto items = ItemContainer {};
auto primitive_types = CreatePrimitiveTypes(&items);
auto entities = AsmEmitter::AsmEntityCollections {};
@ -1509,9 +1510,10 @@ bool AsmEmitter::Emit(ItemContainer *items, const Program &program, PandaFileToP
bool AsmEmitter::Emit(Writer *writer, const Program &program, std::map<std::string, size_t> *stat,
PandaFileToPandaAsmMaps *maps, bool debug_info,
panda::panda_file::pgo::ProfileOptimizer *profile_opt, uint8_t api)
panda::panda_file::pgo::ProfileOptimizer *profile_opt, uint8_t api, std::string subApi)
{
ItemContainer::SetApi(api);
ItemContainer::SetSubApi(subApi);
auto items = ItemContainer {};
if (!Emit(&items, program, maps, debug_info, profile_opt)) {
return false;
@ -1526,20 +1528,21 @@ bool AsmEmitter::Emit(Writer *writer, const Program &program, std::map<std::stri
bool AsmEmitter::Emit(const std::string &filename, const Program &program, std::map<std::string, size_t> *stat,
PandaFileToPandaAsmMaps *maps, bool debug_info,
panda::panda_file::pgo::ProfileOptimizer *profile_opt, uint8_t api)
panda::panda_file::pgo::ProfileOptimizer *profile_opt, uint8_t api, std::string subApi)
{
auto writer = FileWriter(filename);
if (!writer) {
SetLastError("Unable to open" + filename + " for writing");
return false;
}
return Emit(&writer, program, stat, maps, debug_info, profile_opt, api);
return Emit(&writer, program, stat, maps, debug_info, profile_opt, api, subApi);
}
std::unique_ptr<const panda_file::File> AsmEmitter::Emit(const Program &program, PandaFileToPandaAsmMaps *maps,
uint8_t api)
uint8_t api, std::string subApi)
{
ItemContainer::SetApi(api);
ItemContainer::SetSubApi(subApi);
auto items = ItemContainer {};
if (!Emit(&items, program, maps)) {
return nullptr;

View File

@ -55,18 +55,20 @@ public:
static bool Emit(panda_file::Writer *writer, const Program &program, std::map<std::string, size_t> *stat = nullptr,
PandaFileToPandaAsmMaps *maps = nullptr, bool debug_info = true,
panda::panda_file::pgo::ProfileOptimizer *profile_opt = nullptr,
uint8_t api = 0);
uint8_t api = 0, std::string subApi = panda_file::DEFAULT_SUB_API_VERSION);
static bool Emit(const std::string &filename, const Program &program, std::map<std::string, size_t> *stat = nullptr,
PandaFileToPandaAsmMaps *maps = nullptr, bool debug_info = true,
panda::panda_file::pgo::ProfileOptimizer *profile_opt = nullptr,
uint8_t api = 0);
uint8_t api = 0, std::string subApi = panda_file::DEFAULT_SUB_API_VERSION);
static bool EmitPrograms(const std::string &filename, const std::vector<Program *> &progs, bool emit_debug_info,
uint8_t api = 0);
uint8_t api = 0, std::string subApi = panda_file::DEFAULT_SUB_API_VERSION);
static std::unique_ptr<const panda_file::File> Emit(const Program &program,
PandaFileToPandaAsmMaps *maps = nullptr, uint8_t api = 0);
PandaFileToPandaAsmMaps *maps = nullptr,
uint8_t api = 0,
std::string subApi = panda_file::DEFAULT_SUB_API_VERSION);
static std::string GetLastError()
{

View File

@ -166,6 +166,7 @@ static T *GetOrInsert(C &map, I &items, const P &pos, const E &key, bool is_fore
/*static*/
uint8_t ItemContainer::apiVersion = 0;
std::string ItemContainer::subApiVersion = DEFAULT_SUB_API_VERSION;
ItemContainer::ItemContainer()
{
@ -606,7 +607,7 @@ bool ItemContainer::WriteHeader(Writer *writer, ssize_t *checksum_offset)
}
writer->CountChecksum(true);
const auto bc_version = GetVersionByApi(ItemContainer::GetApi());
const auto bc_version = GetVersionByApi(ItemContainer::GetApi(), ItemContainer::GetSubApi());
std::vector<uint8_t> versionVec(std::begin(bc_version.value()), std::end(bc_version.value()));
if (!writer->WriteBytes(versionVec)) {

View File

@ -214,12 +214,23 @@ public:
ItemContainer::apiVersion = api;
}
static void SetSubApi(std::string subApi)
{
ItemContainer::subApiVersion = subApi;
}
static std::string GetSubApi()
{
return ItemContainer::subApiVersion;
}
static uint8_t GetApi()
{
return ItemContainer::apiVersion;
}
static uint8_t apiVersion;
static std::string subApiVersion;
private:
template <class T>
@ -242,7 +253,7 @@ private:
{
ASSERT(type_ != IndexType::NONE);
const auto bc_version = GetVersionByApi(ItemContainer::GetApi());
const auto bc_version = GetVersionByApi(ItemContainer::GetApi(), ItemContainer::GetSubApi());
if (bc_version.value().front() >= API_12 && (type == IndexType::FIELD || type == IndexType::PROTO)) {
SetNeedsEmit(false);
}

View File

@ -502,7 +502,7 @@ ProtoItem::ProtoItem(TypeItem *ret_type, const std::vector<MethodParamItem> &par
AddType(p.GetType(), &n);
}
const auto bc_version = GetVersionByApi(ItemContainer::GetApi());
const auto bc_version = GetVersionByApi(ItemContainer::GetApi(), ItemContainer::GetSubApi());
if (bc_version.value().front() >= API_12) {
// no need to emit protoItem
SetNeedsEmit(false);
@ -575,7 +575,7 @@ bool BaseMethodItem::Write(Writer *writer)
return false;
}
const auto bc_version = GetVersionByApi(ItemContainer::GetApi());
const auto bc_version = GetVersionByApi(ItemContainer::GetApi(), ItemContainer::GetSubApi());
if (bc_version.value().front() >= API_12) {
// reserve [proto_idx] field, write invalid index
if (!writer->Write<uint16_t>(INVALID_INDEX_16)) {

View File

@ -105,8 +105,6 @@ static constexpr uint32_t FLAG_MASK = 0xFF;
constexpr uint16_t INVALID_INDEX_16 = std::numeric_limits<uint16_t>::max();
constexpr uint32_t MAX_INDEX_16 = std::numeric_limits<uint16_t>::max() - 1;
constexpr uint8_t API_12 = 12;
constexpr uint32_t PGO_STRING_DEFAULT_COUNT = 5;
constexpr uint32_t PGO_CLASS_DEFAULT_COUNT = 3;
constexpr uint32_t PGO_CODE_DEFAULT_COUNT = 1;

View File

@ -23,8 +23,14 @@
#include <set>
#include "file.h"
#include "utils/const_value.h"
namespace panda::panda_file {
constexpr uint8_t API_12 = 12;
const std::string SUB_API_VERSION_1 = "beta1";
const std::string SUB_API_VERSION_2 = "beta2";
const std::string DEFAULT_SUB_API_VERSION = SUB_API_VERSION_1;
constexpr std::array<uint8_t, File::VERSION_SIZE> version {<%= Panda::version.split('.').join(', ') %>};
constexpr std::array<uint8_t, File::VERSION_SIZE> minVersion {<%= Panda::min_version.split('.').join(', ') %>};
const std::set<std::array<uint8_t, File::VERSION_SIZE>> incompatibleVersion {
@ -70,8 +76,12 @@ inline void PrintSupportedApi() {
}
}
inline std::optional<const std::array<uint8_t, File::VERSION_SIZE>> GetVersionByApi(uint8_t api)
inline std::optional<const std::array<uint8_t, File::VERSION_SIZE>> GetVersionByApi(uint8_t api, std::string subApi)
{
if (api == API_12 && (subApi == SUB_API_VERSION_1 || subApi == SUB_API_VERSION_2)) {
return std::array<uint8_t, File::VERSION_SIZE> {12, 0, 2, 0};
}
const auto iter = api_version_map.find(api);
if (iter == api_version_map.end()) {
// if there is no corresponding api version, the default branch is current version.