huangyu c658ccf319 Update runtime_core code
Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/I5G96F
Test: Test262 suit, ark unittest, rk3568 XTS, ark previewer demo

Signed-off-by: huangyu <huangyu76@huawei.com>
Change-Id: I3f63d129a07deaa27a390f556dcaa5651c098185
2022-07-17 10:20:32 +08:00

151 lines
4.2 KiB
C++

/**
* Copyright (c) 2021-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 PANDA_IR_INTERFACE_H
#define PANDA_IR_INTERFACE_H
#include <string>
#include "assembler/assembly-emitter.h"
#include "libpandafile/method_data_accessor-inl.h"
#include "compiler/optimizer/ir/constants.h"
namespace panda::bytecodeopt {
class BytecodeOptIrInterface {
public:
explicit BytecodeOptIrInterface(const pandasm::AsmEmitter::PandaFileToPandaAsmMaps *maps,
pandasm::Program *prog = nullptr)
: prog_(prog), maps_(maps)
{
}
virtual ~BytecodeOptIrInterface() = default;
virtual std::string GetMethodIdByOffset(uint32_t offset) const
{
auto it = maps_->methods.find(offset);
ASSERT(it != maps_->methods.cend());
return std::string(it->second);
}
virtual std::string GetStringIdByOffset(uint32_t offset) const
{
auto it = maps_->strings.find(offset);
ASSERT(it != maps_->strings.cend());
return std::string(it->second);
}
std::optional<std::string> GetLiteralArrayIdByOffset(uint32_t offset) const
{
ASSERT(prog_ != nullptr);
if (prog_ == nullptr) {
return std::nullopt;
}
auto id = std::to_string(offset);
auto it = prog_->literalarray_table.find(id);
ASSERT(it != prog_->literalarray_table.end());
return it != prog_->literalarray_table.end() ? std::optional<std::string>(id) : std::nullopt;
}
virtual std::string GetTypeIdByOffset(uint32_t offset) const
{
auto it = maps_->classes.find(offset);
ASSERT(it != maps_->classes.cend());
return std::string(it->second);
}
virtual std::string GetFieldIdByOffset(uint32_t offset) const
{
auto it = maps_->fields.find(offset);
ASSERT(it != maps_->fields.cend());
return std::string(it->second);
}
std::unordered_map<size_t, pandasm::Ins *> *GetPcInsMap()
{
return &pc_ins_map_;
}
size_t GetLineNumberByPc(size_t pc) const
{
if (pc == compiler::INVALID_PC || pc_ins_map_.size() == 0) {
return 0;
}
auto iter = pc_ins_map_.find(pc);
if (iter == pc_ins_map_.end()) {
return 0;
}
return iter->second->ins_debug.line_number;
}
uint32_t GetColumnNumberByPc(size_t pc) const
{
if (pc == compiler::INVALID_PC || pc_ins_map_.size() == 0) {
return compiler::INVALID_COLUMN_NUM;
}
auto iter = pc_ins_map_.find(pc);
if (iter == pc_ins_map_.end()) {
return compiler::INVALID_COLUMN_NUM;
}
return iter->second->ins_debug.column_number;
}
void ClearPcInsMap()
{
pc_ins_map_.clear();
}
void StoreLiteralArray(std::string id, pandasm::LiteralArray &&literalarray)
{
ASSERT(prog_ != nullptr);
if (prog_ == nullptr) {
return;
}
prog_->literalarray_table.emplace(id, std::move(literalarray));
}
size_t GetLiteralArrayTableSize() const
{
ASSERT(prog_ != nullptr);
if (prog_ == nullptr) {
return 0;
}
return prog_->literalarray_table.size();
}
bool IsMapsSet() const
{
return maps_ != nullptr;
}
panda_file::SourceLang GetSourceLang()
{
return prog_ != nullptr ? prog_->lang : panda_file::SourceLang::PANDA_ASSEMBLY;
}
private:
pandasm::Program *prog_ {nullptr};
const pandasm::AsmEmitter::PandaFileToPandaAsmMaps *maps_ {nullptr};
std::unordered_map<size_t, pandasm::Ins *> pc_ins_map_;
};
} // namespace panda::bytecodeopt
#endif // PANDA_IR_INTERFACE_H