Adapt the lib of defect scan to isa refactoring

Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/I5WL4G
Test: unittest

Signed-off-by: wangyantian <wangyantian@huawei.com>
Change-Id: Iea270e021d7b972809359111245b0679b0a62e68
This commit is contained in:
wangyantian 2022-10-14 17:02:54 +08:00
parent 1ab0393668
commit cea05e2223
14 changed files with 458 additions and 522 deletions

View File

@ -309,7 +309,7 @@ if (!ark_standalone_build) {
}
}
group("ark_defectscanaux_unittest") {
group("ark_host_linux_defectscanaux_unittest") {
testonly = true
deps = []
if (host_os == "linux") {

View File

@ -12,7 +12,10 @@
import("//arkcompiler/runtime_core/ark_config.gni")
config("defectscanaux_public_config") {
include_dirs = [ "$ark_root/libark_defect_scan_aux/include" ]
include_dirs = [
"$target_gen_dir/generated",
"$ark_root/libark_defect_scan_aux/include",
]
configs = [
"$ark_root:ark_config",
@ -23,7 +26,7 @@ config("defectscanaux_public_config") {
]
}
config("defectscan_test_config") {
config("defectscanaux_test_config") {
visibility = [ ":*" ]
configs = [ ":defectscanaux_public_config" ]
@ -38,11 +41,27 @@ libarkdefectscanaux_sources = [
"$ark_root/libark_defect_scan_aux/module_record.cpp",
]
ark_gen("defectscanaux_opcode") {
data = "$ark_root/compiler/optimizer/ir/instructions.yaml"
template_files = [ "opcode_map_table.h.erb" ]
sources = "templates"
destination = "$target_gen_dir/generated"
requires = [ "$ark_root/compiler/optimizer/templates/instructions.rb" ]
}
ark_isa_gen("defectscanaux_intrinsic") {
template_files = [ "intrinsic_map_table.h.erb" ]
sources = "templates"
destination = "$target_gen_dir/generated"
}
ohos_shared_library("libark_defect_scan_aux") {
sources = libarkdefectscanaux_sources
configs = [ ":defectscanaux_public_config" ]
deps = [
":defectscanaux_intrinsic_intrinsic_map_table_h",
":defectscanaux_opcode_opcode_map_table_h",
"$ark_root/compiler:libarkcompiler_frontend_static",
"$ark_root/libpandabase:libarkbase_frontend_static",
"$ark_root/libpandafile:libarkfile_frontend_static",
@ -60,6 +79,8 @@ ohos_static_library("libark_defect_scan_aux_static_test") {
configs = [ ":defectscanaux_public_config" ]
deps = [
":defectscanaux_intrinsic_intrinsic_map_table_h",
":defectscanaux_opcode_opcode_map_table_h",
"$ark_root/compiler:libarkcompiler_frontend_static",
"$ark_root/libpandabase:libarkbase_frontend_static",
"$ark_root/libpandafile:libarkfile_frontend_static",

View File

@ -109,7 +109,9 @@ const Function *AbcFile::GetExportFunctionByExportName(std::string_view export_f
std::string inter_func_name = GetInternalNameByExportName(export_func_name);
for (auto export_func : export_func_list_) {
if (export_func->GetFunctionName() == inter_func_name) {
const std::string &ex_func_name = export_func->GetFunctionName();
std::string_view no_hashtag_name = GetNameWithoutHashtag(ex_func_name);
if (no_hashtag_name == inter_func_name) {
return export_func;
}
}
@ -215,35 +217,41 @@ std::string AbcFile::GetStringByInst(const Inst &inst) const
{
auto type = inst.GetType();
switch (type) {
case InstType::Intrinsic_DefineFuncDyn:
case InstType::Intrinsic_DefineNcFuncDyn:
case InstType::Intrinsic_DefineGeneratorFunc:
case InstType::Intrinsic_DefineAsyncFunc:
case InstType::Intrinsic_DefineMethod:
case InstType::Intrinsic_DefineClassWithBuffer:
case InstType::Intrinsic_DefineAsyncGeneratorFunc: {
uint32_t m_id = inst.GetImms()[0];
return GetStringByMethodId(EntityId(m_id));
case InstType::DEFINEFUNC_IMM8_ID16_IMM8:
case InstType::DEFINEFUNC_IMM16_ID16_IMM8:
case InstType::DEFINEMETHOD_IMM8_ID16_IMM8:
case InstType::DEFINEMETHOD_IMM16_ID16_IMM8:
case InstType::DEFINECLASSWITHBUFFER_IMM8_ID16_ID16_IMM16_V8:
case InstType::DEFINECLASSWITHBUFFER_IMM16_ID16_ID16_IMM16_V8: {
uint32_t method_id = inst.GetImms()[1];
return GetStringByMethodId(EntityId(method_id));
}
case InstType::Intrinsic_LdObjByName:
case InstType::Intrinsic_GetModuleNamespace:
case InstType::Intrinsic_StModuleVar:
case InstType::Intrinsic_TryLdGlobalByName:
case InstType::Intrinsic_TryStGlobalByName:
case InstType::Intrinsic_LdGlobalVar:
case InstType::Intrinsic_StGlobalVar:
case InstType::Intrinsic_StObjByName:
case InstType::Intrinsic_StOwnByName:
case InstType::Intrinsic_LdSuperByName:
case InstType::Intrinsic_StSuperByName:
case InstType::Intrinsic_LdModuleVar:
case InstType::Intrinsic_CreateRegexpWithLiteral:
case InstType::Intrinsic_StConstToGlobalRecord:
case InstType::Intrinsic_StLetToGlobalRecord:
case InstType::Intrinsic_StClassToGlobalRecord:
case InstType::Intrinsic_StOwnByNameWithNameSet: {
auto str_id = EntityId(inst.GetImms()[0]);
return GetStringByStringId(str_id);
case InstType::TRYLDGLOBALBYNAME_IMM8_ID16:
case InstType::TRYSTGLOBALBYNAME_IMM8_ID16:
case InstType::TRYLDGLOBALBYNAME_IMM16_ID16:
case InstType::TRYSTGLOBALBYNAME_IMM16_ID16:
case InstType::STCONSTTOGLOBALRECORD_IMM16_ID16:
case InstType::STTOGLOBALRECORD_IMM16_ID16:
case InstType::LDGLOBALVAR_IMM16_ID16:
case InstType::STGLOBALVAR_IMM16_ID16:
case InstType::LDOBJBYNAME_IMM8_ID16:
case InstType::LDOBJBYNAME_IMM16_ID16:
case InstType::STOBJBYNAME_IMM8_ID16_V8:
case InstType::STOBJBYNAME_IMM16_ID16_V8:
case InstType::LDSUPERBYNAME_IMM8_ID16:
case InstType::LDSUPERBYNAME_IMM16_ID16:
case InstType::STSUPERBYNAME_IMM8_ID16_V8:
case InstType::STSUPERBYNAME_IMM16_ID16_V8:
case InstType::LDTHISBYNAME_IMM8_ID16:
case InstType::LDTHISBYNAME_IMM16_ID16:
case InstType::STTHISBYNAME_IMM8_ID16:
case InstType::STTHISBYNAME_IMM16_ID16:
case InstType::STOWNBYNAME_IMM8_ID16_V8:
case InstType::STOWNBYNAME_IMM16_ID16_V8:
case InstType::STOWNBYNAMEWITHNAMESET_IMM8_ID16_V8:
case InstType::STOWNBYNAMEWITHNAMESET_IMM16_ID16_V8: {
uint32_t string_id = inst.GetImms()[1];
return GetStringByStringId(EntityId(string_id));
}
default:
return EMPTY_STR;
@ -254,41 +262,35 @@ std::string AbcFile::GetStringByInst(const Inst &inst) const
std::optional<FuncInstPair> AbcFile::GetStLexInstByLdLexInst(FuncInstPair func_inst_pair) const
{
const Function *func = func_inst_pair.first;
Inst &ld_lex_inst = func_inst_pair.second;
if (func == nullptr) {
const Inst &ld_lex_inst = func_inst_pair.second;
if (func == nullptr || !ld_lex_inst.IsInstLdLexVar()) {
return std::nullopt;
}
auto type = ld_lex_inst.GetType();
if (type == InstType::Intrinsic_LdLexVarDyn_Imm4 || type == InstType::Intrinsic_LdLexVarDyn_Imm8 ||
type == InstType::Intrinsic_LdLexVarDyn_Imm16) {
auto ld_imms = ld_lex_inst.GetImms();
uint32_t ld_level = ld_imms[0];
uint32_t ld_slot_id = ld_imms[1];
const Function *cur_func = func;
for (uint32_t i = 0; i < ld_level; ++i) {
cur_func = cur_func->GetParentFunction();
if (cur_func == nullptr) {
return std::nullopt;
auto ld_imms = ld_lex_inst.GetImms();
uint32_t ld_level = ld_imms[0];
uint32_t ld_slot_id = ld_imms[1];
const Function *cur_func = func;
for (uint32_t i = 0; i < ld_level; ++i) {
cur_func = cur_func->GetParentFunction();
if (cur_func == nullptr) {
return std::nullopt;
}
}
auto &graph = cur_func->GetGraph();
Inst st_lex_inst = ld_lex_inst;
graph.VisitAllInstructions([ld_slot_id, &st_lex_inst](const Inst &inst) {
if (inst.IsInstStLexVar()) {
auto st_imms = inst.GetImms();
uint32_t st_level = st_imms[0];
uint32_t st_slot_id = st_imms[1];
if (st_level == 0 && st_slot_id == ld_slot_id) {
st_lex_inst = inst;
}
}
auto &graph = cur_func->GetGraph();
Inst st_lex_inst = ld_lex_inst;
graph.VisitAllInstructions([ld_slot_id, &st_lex_inst](const Inst &inst) {
auto type = inst.GetType();
if (type == InstType::Intrinsic_StLexVarDyn_Imm4 || type == InstType::Intrinsic_StLexVarDyn_Imm8 ||
type == InstType::Intrinsic_StLexVarDyn_Imm16) {
auto st_imms = inst.GetImms();
uint32_t st_level = st_imms[0];
uint32_t st_slot_id = st_imms[1];
if (st_level == 0 && st_slot_id == ld_slot_id) {
st_lex_inst = inst;
}
}
});
if (st_lex_inst != ld_lex_inst) {
return FuncInstPair(cur_func, st_lex_inst);
}
});
if (st_lex_inst != ld_lex_inst) {
return FuncInstPair(cur_func, st_lex_inst);
}
return std::nullopt;
@ -297,30 +299,28 @@ std::optional<FuncInstPair> AbcFile::GetStLexInstByLdLexInst(FuncInstPair func_i
std::optional<FuncInstPair> AbcFile::GetStGlobalInstByLdGlobalInst(FuncInstPair func_inst_pair) const
{
const Function *func = func_inst_pair.first;
Inst &ld_global_inst = func_inst_pair.second;
if (func == nullptr) {
const Inst &ld_global_inst = func_inst_pair.second;
if (func == nullptr || !ld_global_inst.IsInstLdGlobal()) {
return std::nullopt;
}
auto type = ld_global_inst.GetType();
if (type == InstType::Intrinsic_TryLdGlobalByName || type == InstType::Intrinsic_LdGlobalVar) {
uint32_t ld_str_id = ld_global_inst.GetImms()[0];
// TODO(wangyantian): only consider that func_main_0 has StGlobal inst for now, what about other cases?
const Function *func_main = def_func_list_[0].get();
auto &graph = func_main->GetGraph();
Inst st_global_inst = ld_global_inst;
graph.VisitAllInstructions([ld_str_id, &st_global_inst](const Inst &inst) {
if (inst.IsStGlobalInst()) {
uint32_t st_str_id = inst.GetImms()[0];
if (st_str_id == ld_str_id) {
st_global_inst = inst;
}
uint32_t ld_str_id = ld_global_inst.GetImms()[0];
// TODO(wangyantian): only consider that func_main_0 has StGlobal inst for now, what about other cases?
const Function *func_main = def_func_list_[0].get();
auto &graph = func_main->GetGraph();
Inst st_global_inst = ld_global_inst;
graph.VisitAllInstructions([ld_str_id, &st_global_inst](const Inst &inst) {
if (inst.IsInstStGlobal()) {
uint32_t st_str_id = inst.GetImms()[0];
if (st_str_id == ld_str_id) {
st_global_inst = inst;
}
});
if (st_global_inst != ld_global_inst) {
return FuncInstPair(func_main, st_global_inst);
}
});
if (st_global_inst != ld_global_inst) {
return FuncInstPair(func_main, st_global_inst);
}
return std::nullopt;
}
@ -334,7 +334,7 @@ void AbcFile::ExtractDebugInfo()
void AbcFile::ExtractModuleInfo()
{
int module_idx = -1;
int module_offset = -1;
for (uint32_t id : panda_file_->GetClasses()) {
EntityId class_id(id);
if (panda_file_->IsExternal(class_id)) {
@ -347,26 +347,22 @@ void AbcFile::ExtractModuleInfo()
EntityId field_name_id = field_accessor.GetNameId();
StringData sd = panda_file_->GetStringData(field_name_id);
if (std::strcmp(utf::Mutf8AsCString(sd.data), filename_.data())) {
module_idx = field_accessor.GetValue<int32_t>().value();
module_offset = field_accessor.GetValue<int32_t>().value();
return;
}
});
break;
}
}
if (module_idx == -1) {
if (module_offset == -1) {
return;
}
EntityId literal_arrays_id = panda_file_->GetLiteralArraysId();
panda_file::LiteralDataAccessor lda(*panda_file_, literal_arrays_id);
EntityId module_id = lda.GetLiteralArrayId(static_cast<size_t>(module_idx));
std::unique_ptr<ModuleRecord> module_record = std::make_unique<ModuleRecord>(filename_);
if (module_record == nullptr) {
LOG(FATAL, DEFECT_SCAN_AUX) << "Can not create ModuleRecord instance for '" << filename_ << "'";
}
ExtractModuleRecord(module_id, module_record);
ExtractModuleRecord(EntityId(module_offset), module_record);
module_record_ = std::move(module_record);
}
@ -380,6 +376,8 @@ void AbcFile::ExtractModuleRecord(EntityId module_id, std::unique_ptr<ModuleReco
}
module_record->SetRequestModules(request_modules);
size_t regular_import_num = 0;
size_t local_export_num = 0;
mda.EnumerateModuleRecord([&](const ModuleTag &tag, uint32_t export_name_offset, uint32_t module_request_idx,
uint32_t import_name_offset, uint32_t local_name_offset) {
size_t request_num = request_modules.size();
@ -390,6 +388,7 @@ void AbcFile::ExtractModuleRecord(EntityId module_id, std::unique_ptr<ModuleReco
}
switch (tag) {
case ModuleTag::REGULAR_IMPORT: {
++regular_import_num;
std::string local_name = GetStringByStringId(EntityId(local_name_offset));
std::string import_name = GetStringByStringId(EntityId(import_name_offset));
module_record->AddImportEntry({module_request, import_name, local_name});
@ -405,6 +404,7 @@ void AbcFile::ExtractModuleRecord(EntityId module_id, std::unique_ptr<ModuleReco
break;
}
case ModuleTag::LOCAL_EXPORT: {
++local_export_num;
std::string local_name = GetStringByStringId(EntityId(local_name_offset));
std::string export_name = GetStringByStringId(EntityId(export_name_offset));
module_record->AddExportEntry({export_name, EMPTY_STR, EMPTY_STR, local_name});
@ -432,6 +432,8 @@ void AbcFile::ExtractModuleRecord(EntityId module_id, std::unique_ptr<ModuleReco
}
}
});
module_record->SetRegularImportNum(regular_import_num);
module_record->SetLocalExportNum(local_export_num);
}
void AbcFile::InitializeAllDefinedFunction()
@ -444,7 +446,7 @@ void AbcFile::InitializeAllDefinedFunction()
panda_file::ClassDataAccessor cda {*panda_file_, class_id};
cda.EnumerateMethods([&](panda_file::MethodDataAccessor &mda) {
if (!mda.IsExternal() && !mda.IsAbstract() && !mda.IsNative()) {
if (!mda.IsExternal()) {
std::string func_name = GetStringByStringId(mda.GetNameId());
EntityId m_id = mda.GetMethodId();
panda_file::CodeDataAccessor cda {*panda_file_, mda.GetCodeId().value()};
@ -491,28 +493,30 @@ void AbcFile::ExtractClassAndFunctionInfo(Function *func)
graph.VisitAllInstructions([&](const Inst &inst) {
auto type = inst.GetType();
switch (type) {
case InstType::Intrinsic_DefineFuncDyn:
case InstType::Intrinsic_DefineNcFuncDyn:
case InstType::Intrinsic_DefineGeneratorFunc:
case InstType::Intrinsic_DefineAsyncFunc: {
Function *def_func = ResolveDefineFuncInstCommon(func, inst);
BuildFunctionDefineChain(func, def_func);
break;
}
case InstType::Intrinsic_DefineClassWithBuffer: {
case InstType::DEFINECLASSWITHBUFFER_IMM8_ID16_ID16_IMM16_V8:
case InstType::DEFINECLASSWITHBUFFER_IMM16_ID16_ID16_IMM16_V8: {
auto def_class = ResolveDefineClassWithBufferInst(func, inst);
AddDefinedClass(std::move(def_class));
break;
}
case InstType::Intrinsic_DefineMethod: {
case InstType::DEFINEFUNC_IMM8_ID16_IMM8:
case InstType::DEFINEFUNC_IMM16_ID16_IMM8: {
Function *def_func = ResolveDefineFuncInstCommon(func, inst);
BuildFunctionDefineChain(func, def_func);
break;
}
case InstType::DEFINEMETHOD_IMM8_ID16_IMM8:
case InstType::DEFINEMETHOD_IMM16_ID16_IMM8: {
auto member_func = ResolveDefineFuncInstCommon(func, inst);
BuildFunctionDefineChain(func, member_func);
// resolve the class where it's defined
Inst def_method_input0 = inst.GetInputInsts()[1];
Inst def_method_input0 = inst.GetInputInsts()[0];
Inst ld_obj_input0 = def_method_input0.GetInputInsts()[0];
if (def_method_input0.GetType() == InstType::Intrinsic_LdObjByName &&
if ((def_method_input0.GetType() == InstType::LDOBJBYNAME_IMM8_ID16 ||
def_method_input0.GetType() == InstType::LDOBJBYNAME_IMM16_ID16) &&
GetStringByInst(def_method_input0) == PROTOTYPE &&
ld_obj_input0.GetType() == InstType::Intrinsic_DefineClassWithBuffer) {
(ld_obj_input0.GetType() == InstType::DEFINECLASSWITHBUFFER_IMM8_ID16_ID16_IMM16_V8 ||
ld_obj_input0.GetType() == InstType::DEFINECLASSWITHBUFFER_IMM16_ID16_ID16_IMM16_V8)) {
auto clazz = GetClassByNameImpl(GetStringByInst(ld_obj_input0));
if (clazz != nullptr) {
BuildClassAndMemberFuncRelation(clazz, member_func);
@ -530,13 +534,14 @@ void AbcFile::ExtractClassInheritInfo(const Function *func) const
{
auto &graph = func->GetGraph();
graph.VisitAllInstructions([&](const Inst &inst) {
if (inst.GetType() != InstType::Intrinsic_DefineClassWithBuffer) {
if (inst.GetType() != InstType::DEFINECLASSWITHBUFFER_IMM8_ID16_ID16_IMM16_V8 &&
inst.GetType() != InstType::DEFINECLASSWITHBUFFER_IMM16_ID16_ID16_IMM16_V8) {
return;
}
Class *cur_class = GetClassByNameImpl(GetStringByInst(inst));
ASSERT(cur_class != nullptr);
Inst def_class_input1 = inst.GetInputInsts()[1];
Inst def_class_input1 = inst.GetInputInsts()[0];
auto [ret_ptr, ret_sym, ret_type] = ResolveInstCommon(func, def_class_input1);
if (ret_ptr != nullptr && ret_type == ResolveType::CLASS_OBJECT) {
auto par_class = reinterpret_cast<const Class *>(ret_ptr);
@ -577,47 +582,97 @@ void AbcFile::ExtractFunctionCalleeInfo(Function *func)
graph.VisitAllInstructions([&](const Inst &inst) {
std::unique_ptr<CalleeInfo> callee_info {nullptr};
switch (inst.GetType()) {
case InstType::Intrinsic_CallArg0Dyn: {
case InstType::CALLARG0_IMM8: {
callee_info = ResolveCallInstCommon(func, inst);
callee_info->SetCalleeArgCount(0);
break;
}
case InstType::Intrinsic_CallArg1Dyn: {
callee_info = ResolveCallInstCommon(func, inst);
case InstType::CALLARG1_IMM8_V8: {
callee_info = ResolveCallInstCommon(func, inst, 1);
callee_info->SetCalleeArgCount(1);
break;
}
case InstType::Intrinsic_CallArgs2Dyn: {
callee_info = ResolveCallInstCommon(func, inst);
case InstType::CALLARGS2_IMM8_V8_V8: {
constexpr int ARG_COUNT = 2;
callee_info = ResolveCallInstCommon(func, inst, ARG_COUNT);
callee_info->SetCalleeArgCount(ARG_COUNT);
break;
}
case InstType::Intrinsic_CallArgs3Dyn: {
callee_info = ResolveCallInstCommon(func, inst);
case InstType::CALLARGS3_IMM8_V8_V8_V8: {
constexpr int ARG_COUNT = 3;
callee_info = ResolveCallInstCommon(func, inst, ARG_COUNT);
callee_info->SetCalleeArgCount(ARG_COUNT);
break;
}
case InstType::Intrinsic_CallSpreadDyn: {
callee_info = ResolveCallInstCommon(func, inst);
case InstType::CALLRANGE_IMM8_IMM8_V8: {
uint32_t arg_count = inst.GetImms()[1];
callee_info = ResolveCallInstCommon(func, inst, arg_count);
callee_info->SetCalleeArgCount(arg_count);
break;
}
case InstType::Intrinsic_CallIRangeDyn: {
callee_info = ResolveCallInstCommon(func, inst);
// 1 stands for the func obj
callee_info->SetCalleeArgCount(inst.GetInputInsts().size() - 1);
case InstType::WIDE_CALLRANGE_PREF_IMM16_V8: {
uint32_t arg_count = inst.GetImms()[0];
callee_info = ResolveCallInstCommon(func, inst, arg_count);
callee_info->SetCalleeArgCount(arg_count);
break;
}
case InstType::Intrinsic_CallIThisRangeDyn: {
callee_info = ResolveCallInstCommon(func, inst);
// 2 stands for func obj and this pointer
callee_info->SetCalleeArgCount(inst.GetInputInsts().size() - 2);
case InstType::SUPERCALLSPREAD_IMM8_V8: {
callee_info = ResolveCallInstCommon(func, inst, 1);
break;
}
case InstType::Intrinsic_SuperCall:
case InstType::Intrinsic_SuperCallSpread: {
case InstType::APPLY_IMM8_V8_V8: {
constexpr uint32_t FUNC_OBJ_INDEX = 2;
callee_info = ResolveCallInstCommon(func, inst, FUNC_OBJ_INDEX);
break;
}
case InstType::CALLTHIS0_IMM8_V8: {
callee_info = ResolveCallInstCommon(func, inst, 1);
callee_info->SetCalleeArgCount(0);
break;
}
case InstType::CALLTHIS1_IMM8_V8_V8: {
constexpr int ARG_COUNT = 1;
// 1 represents the this pointer
callee_info = ResolveCallInstCommon(func, inst, ARG_COUNT + 1);
callee_info->SetCalleeArgCount(ARG_COUNT);
break;
}
case InstType::CALLTHIS2_IMM8_V8_V8_V8: {
constexpr int ARG_COUNT = 2;
callee_info = ResolveCallInstCommon(func, inst, ARG_COUNT + 1);
callee_info->SetCalleeArgCount(ARG_COUNT);
break;
}
case InstType::CALLTHIS3_IMM8_V8_V8_V8_V8: {
constexpr int ARG_COUNT = 3;
callee_info = ResolveCallInstCommon(func, inst, ARG_COUNT + 1);
callee_info->SetCalleeArgCount(ARG_COUNT);
break;
}
case InstType::CALLTHISRANGE_IMM8_IMM8_V8: {
uint32_t arg_count = inst.GetImms()[1];
callee_info = ResolveCallInstCommon(func, inst, arg_count + 1);
callee_info->SetCalleeArgCount(arg_count);
break;
}
case InstType::WIDE_CALLTHISRANGE_PREF_IMM16_V8: {
uint32_t arg_count = inst.GetImms()[0];
callee_info = ResolveCallInstCommon(func, inst, arg_count + 1);
callee_info->SetCalleeArgCount(arg_count);
break;
}
case InstType::SUPERCALLTHISRANGE_IMM8_IMM8_V8:
case InstType::SUPERCALLARROWRANGE_IMM8_IMM8_V8: {
uint32_t arg_count = inst.GetImms()[1];
callee_info = ResolveSuperCallInst(func, inst);
callee_info->SetCalleeArgCount(arg_count);
break;
}
case InstType::WIDE_SUPERCALLTHISRANGE_PREF_IMM16_V8:
case InstType::WIDE_SUPERCALLARROWRANGE_PREF_IMM16_V8: {
uint32_t arg_count = inst.GetImms()[0];
callee_info = ResolveSuperCallInst(func, inst);
callee_info->SetCalleeArgCount(arg_count);
break;
}
default:
@ -657,22 +712,21 @@ void AbcFile::ExtractClassAndFunctionExportList()
auto &graph = func_main->GetGraph();
graph.VisitAllInstructions([&](const Inst &inst) {
auto type = inst.GetType();
if (type == InstType::Intrinsic_StModuleVar) {
if (type == InstType::STMODULEVAR_IMM8 || type == InstType::WIDE_STMODULEVAR_PREF_IMM16) {
Inst st_module_input0 = inst.GetInputInsts()[0];
switch (st_module_input0.GetType()) {
case InstType::Intrinsic_DefineFuncDyn:
case InstType::Intrinsic_DefineNcFuncDyn:
case InstType::Intrinsic_DefineGeneratorFunc:
case InstType::Intrinsic_DefineAsyncFunc: {
auto export_func = ResolveDefineFuncInstCommon(func_main, inst);
case InstType::DEFINEFUNC_IMM8_ID16_IMM8:
case InstType::DEFINEFUNC_IMM16_ID16_IMM8: {
auto export_func = ResolveDefineFuncInstCommon(func_main, st_module_input0);
ASSERT(export_func != nullptr);
export_func_list_.push_back(export_func);
break;
}
case InstType::Intrinsic_DefineClassWithBuffer: {
Class *clazz = GetClassByNameImpl(GetStringByInst(st_module_input0));
ASSERT(clazz != nullptr);
export_class_list_.push_back(clazz);
case InstType::DEFINECLASSWITHBUFFER_IMM8_ID16_ID16_IMM16_V8:
case InstType::DEFINECLASSWITHBUFFER_IMM16_ID16_ID16_IMM16_V8: {
Class *export_clazz = GetClassByNameImpl(GetStringByInst(st_module_input0));
ASSERT(export_clazz != nullptr);
export_class_list_.push_back(export_clazz);
break;
}
default:
@ -698,54 +752,83 @@ ResolveResult AbcFile::ResolveInstCommon(const Function *func, Inst inst) const
{
auto type = inst.GetType();
switch (type) {
case InstType::Intrinsic_DefineFuncDyn:
case InstType::Intrinsic_DefineNcFuncDyn:
case InstType::Intrinsic_DefineGeneratorFunc:
case InstType::Intrinsic_DefineAsyncFunc: {
case InstType::DEFINEFUNC_IMM8_ID16_IMM8:
case InstType::DEFINEFUNC_IMM16_ID16_IMM8: {
std::string func_name = GetStringByInst(inst);
const Function *func = GetFunctionByName(func_name);
ASSERT(func != nullptr);
return std::make_tuple(func, EMPTY_STR, ResolveType::FUNCTION_OBJECT);
}
case InstType::Intrinsic_DefineClassWithBuffer: {
case InstType::DEFINECLASSWITHBUFFER_IMM8_ID16_ID16_IMM16_V8:
case InstType::DEFINECLASSWITHBUFFER_IMM16_ID16_ID16_IMM16_V8: {
std::string class_name = GetStringByInst(inst);
const Class *clazz = GetClassByName(class_name);
ASSERT(clazz != nullptr);
return std::make_tuple(clazz, EMPTY_STR, ResolveType::CLASS_OBJECT);
}
case InstType::Intrinsic_NewObjSpreadDyn:
case InstType::Intrinsic_NewObjDynRange: {
case InstType::NEWOBJAPPLY_IMM8_V8:
case InstType::NEWOBJAPPLY_IMM16_V8:
case InstType::NEWOBJRANGE_IMM8_IMM8_V8:
case InstType::NEWOBJRANGE_IMM16_IMM8_V8:
case InstType::WIDE_NEWOBJRANGE_PREF_IMM16_V8: {
Inst newobj_input0 = inst.GetInputInsts()[0];
auto resolve_res = ResolveInstCommon(func, newobj_input0);
return HandleNewObjInstResolveResultCommon(resolve_res);
}
case InstType::Intrinsic_LdObjByName: {
case InstType::LDOBJBYNAME_IMM8_ID16:
case InstType::LDOBJBYNAME_IMM16_ID16: {
Inst ld_obj_input0 = inst.GetInputInsts()[0];
auto resolve_res = ResolveInstCommon(func, ld_obj_input0);
return HandleLdObjByNameInstResolveResult(inst, resolve_res);
}
case InstType::Intrinsic_LdLexVarDyn_Imm4:
case InstType::Intrinsic_LdLexVarDyn_Imm8:
case InstType::Intrinsic_LdLexVarDyn_Imm16: {
case InstType::LDLEXVAR_IMM4_IMM4:
case InstType::LDLEXVAR_IMM8_IMM8:
case InstType::WIDE_LDLEXVAR_PREF_IMM16_IMM16: {
auto p = GetStLexInstByLdLexInst({func, inst});
if (p == std::nullopt) {
return std::make_tuple(nullptr, EMPTY_STR, ResolveType::UNRESOLVED_OTHER);
}
return ResolveInstCommon(p.value().first, p.value().second);
}
case InstType::Intrinsic_StLexVarDyn_Imm4:
case InstType::Intrinsic_StLexVarDyn_Imm8:
case InstType::Intrinsic_StLexVarDyn_Imm16: {
case InstType::STLEXVAR_IMM4_IMM4:
case InstType::STLEXVAR_IMM8_IMM8:
case InstType::WIDE_STLEXVAR_PREF_IMM16_IMM16: {
Inst stlex_input0 = inst.GetInputInsts()[0];
return ResolveInstCommon(func, stlex_input0);
}
case InstType::Intrinsic_LdModuleVar:
case InstType::Intrinsic_GetModuleNamespace: {
std::string str = GetStringByInst(inst);
case InstType::LDLOCALMODULEVAR_IMM8:
case InstType::WIDE_LDLOCALMODULEVAR_PREF_IMM16: {
size_t index = inst.GetImms()[0];
const std::string &export_name = module_record_->GetExportNameByIndex(index);
const Function *func = GetExportFunctionByExportName(export_name);
if (func != nullptr) {
return std::make_tuple(func, EMPTY_STR, ResolveType::FUNCTION_OBJECT);
}
const Class *clazz = GetExportClassByExportName(export_name);
if (clazz != nullptr) {
return std::make_tuple(clazz, EMPTY_STR, ResolveType::CLASS_OBJECT);
}
return std::make_tuple(nullptr, EMPTY_STR, ResolveType::UNRESOLVED_OTHER);
}
case InstType::LDEXTERNALMODULEVAR_IMM8:
case InstType::WIDE_LDEXTERNALMODULEVAR_PREF_IMM16: {
size_t index = inst.GetImms()[0];
const std::string &inter_name = module_record_->GetImportInternalNameByIndex(index);
return std::make_tuple(nullptr, inter_name, ResolveType::UNRESOLVED_MODULE);
}
case InstType::GETMODULENAMESPACE_IMM8:
case InstType::WIDE_GETMODULENAMESPACE_PREF_IMM16: {
size_t index = inst.GetImms()[0];
const std::string &str = module_record_->GetImportNamespaceNameByIndex(index);
return std::make_tuple(nullptr, str, ResolveType::UNRESOLVED_MODULE);
}
case InstType::Intrinsic_LdGlobalVar:
case InstType::Intrinsic_TryLdGlobalByName: {
case InstType::LDGLOBAL: {
// TODO(wangyantian): load a specific global variable, namely 'globalThis'
return std::make_tuple(nullptr, EMPTY_STR, ResolveType::UNRESOLVED_OTHER);
}
case InstType::LDGLOBALVAR_IMM16_ID16:
case InstType::TRYLDGLOBALBYNAME_IMM8_ID16:
case InstType::TRYLDGLOBALBYNAME_IMM16_ID16: {
std::string str = GetStringByInst(inst);
auto p = GetStGlobalInstByLdGlobalInst({func, inst});
if (p == std::nullopt) {
@ -757,16 +840,15 @@ ResolveResult AbcFile::ResolveInstCommon(const Function *func, Inst inst) const
}
return std::make_tuple(nullptr, str, ResolveType::UNRESOLVED_GLOBAL_VAR);
}
case InstType::Intrinsic_TryStGlobalByName:
case InstType::Intrinsic_StGlobalVar:
case InstType::Intrinsic_StGlobalLet:
case InstType::Intrinsic_StConstToGlobalRecord:
case InstType::Intrinsic_StLetToGlobalRecord:
case InstType::Intrinsic_StClassToGlobalRecord: {
case InstType::TRYSTGLOBALBYNAME_IMM8_ID16:
case InstType::TRYSTGLOBALBYNAME_IMM16_ID16:
case InstType::STGLOBALVAR_IMM16_ID16:
case InstType::STCONSTTOGLOBALRECORD_IMM16_ID16:
case InstType::STTOGLOBALRECORD_IMM16_ID16: {
Inst stglobal_input0 = inst.GetInputInsts()[0];
return ResolveInstCommon(func, stglobal_input0);
}
case InstType::Phi: {
case InstType::OPCODE_PHI: {
// TODO(wangyantian): only the first path is considered for now, what about other paths?
Inst phi_input0 = inst.GetInputInsts()[0];
return ResolveInstCommon(func, phi_input0);
@ -840,7 +922,7 @@ Function *AbcFile::ResolveDefineFuncInstCommon(const Function *func, const Inst
std::unique_ptr<Class> AbcFile::ResolveDefineClassWithBufferInst(Function *func, const Inst &define_class_inst) const
{
auto imms = define_class_inst.GetImms();
auto m_id = EntityId(imms[0]);
auto m_id = EntityId(imms[1]);
std::string class_name = GetStringByMethodId(m_id);
std::unique_ptr<Class> def_class = std::make_unique<Class>(class_name, this, func);
if (def_class == nullptr) {
@ -853,11 +935,10 @@ std::unique_ptr<Class> AbcFile::ResolveDefineClassWithBufferInst(Function *func,
std::string ctor_name = GetStringByInst(define_class_inst);
HandleMemberFunctionFromClassBuf(ctor_name, func, def_class.get());
// handle member function defined in the class
uint32_t literal_array_idx = imms[1];
auto literal_array_id = EntityId(imms[2]);
panda_file::LiteralDataAccessor lit_array_accessor(*panda_file_, panda_file_->GetLiteralArraysId());
lit_array_accessor.EnumerateLiteralVals(
literal_array_idx, [&](const panda_file::LiteralDataAccessor::LiteralValue &value, const LiteralTag &tag) {
literal_array_id, [&](const panda_file::LiteralDataAccessor::LiteralValue &value, const LiteralTag &tag) {
if (tag == LiteralTag::METHOD || tag == LiteralTag::GENERATORMETHOD ||
tag == LiteralTag::ASYNCGENERATORMETHOD) {
auto method_id = EntityId(std::get<uint32_t>(value));
@ -869,14 +950,15 @@ std::unique_ptr<Class> AbcFile::ResolveDefineClassWithBufferInst(Function *func,
return def_class;
}
std::unique_ptr<CalleeInfo> AbcFile::ResolveCallInstCommon(Function *func, const Inst &call_inst) const
std::unique_ptr<CalleeInfo> AbcFile::ResolveCallInstCommon(Function *func, const Inst &call_inst,
uint32_t func_obj_idx) const
{
std::unique_ptr<CalleeInfo> callee_info = std::make_unique<CalleeInfo>(call_inst, func);
if (callee_info == nullptr) {
LOG(FATAL, DEFECT_SCAN_AUX) << "Can not allocate memory when processing '" << filename_ << "'";
}
Inst call_input0 = call_inst.GetInputInsts()[0];
Inst call_input0 = call_inst.GetInputInsts()[func_obj_idx];
auto [ret_ptr, ret_sym, ret_type] = ResolveInstCommon(func, call_input0);
if (ret_ptr != nullptr && ret_type == ResolveType::FUNCTION_OBJECT) {
auto callee = reinterpret_cast<const Function *>(ret_ptr);

View File

@ -87,7 +87,7 @@ std::vector<Inst> Function::GetReturnInstList() const
std::vector<Inst> ret_inst_list;
graph_.VisitAllInstructions([&](const Inst &inst) {
InstType type = inst.GetType();
if (type == InstType::Intrinsic_ReturnDyn) {
if (type == InstType::RETURN) {
ret_inst_list.push_back(inst);
}
});

View File

@ -19,10 +19,11 @@ namespace panda::defect_scan_aux {
using Opcode = compiler::Opcode;
using IntrinsicId = compiler::RuntimeInterface::IntrinsicId;
static std::unordered_map<Opcode, InstType> OPCODE_INSTTYPE_MAP_TABLE = {OPCODE_INSTTYPE_MAP(BUILD_OPCODE_MAP)};
static std::unordered_map<Opcode, InstType> OPCODE_INSTTYPE_MAP_TABLE = {
OPCODE_INSTTYPE_MAP_TABLE(BUILD_OPCODE_MAP_TABLE)};
static std::unordered_map<IntrinsicId, InstType> INTRINSIC_INSTTYPE_MAP_TABLE = {
INTRINSIC_INSTTYPE_MAP(BUILD_INTRINSIC_MAP)};
INTRINSIC_INSTTYPE_MAP_TABLE(BUILD_INTRINSIC_MAP_TABLE)};
bool Inst::operator==(const Inst &inst) const
{
@ -39,11 +40,29 @@ InstType Inst::GetType() const
return type_;
}
bool Inst::IsStGlobalInst() const
bool Inst::IsInstStLexVar() const
{
return type_ == InstType::Intrinsic_TryStGlobalByName || type_ == InstType::Intrinsic_StGlobalVar ||
type_ == InstType::Intrinsic_StGlobalLet || type_ == InstType::Intrinsic_StConstToGlobalRecord ||
type_ == InstType::Intrinsic_StLetToGlobalRecord || type_ == InstType::Intrinsic_StClassToGlobalRecord;
return type_ == InstType::STLEXVAR_IMM4_IMM4 || type_ == InstType::STLEXVAR_IMM8_IMM8 ||
type_ == InstType::WIDE_STLEXVAR_PREF_IMM16_IMM16;
}
bool Inst::IsInstLdLexVar() const
{
return type_ == InstType::LDLEXVAR_IMM4_IMM4 || type_ == InstType::LDLEXVAR_IMM8_IMM8 ||
type_ == InstType::WIDE_LDLEXVAR_PREF_IMM16_IMM16;
}
bool Inst::IsInstStGlobal() const
{
return type_ == InstType::TRYSTGLOBALBYNAME_IMM8_ID16 || type_ == InstType::TRYSTGLOBALBYNAME_IMM16_ID16 ||
type_ == InstType::STGLOBALVAR_IMM16_ID16 || type_ == InstType::STCONSTTOGLOBALRECORD_IMM16_ID16 ||
type_ == InstType::STTOGLOBALRECORD_IMM16_ID16;
}
bool Inst::IsInstLdGlobal() const
{
return type_ == InstType::LDGLOBALVAR_IMM16_ID16 || type_ == InstType::TRYLDGLOBALBYNAME_IMM8_ID16 ||
type_ == InstType::TRYLDGLOBALBYNAME_IMM16_ID16;
}
uint16_t Inst::GetArgIndex() const

View File

@ -109,7 +109,8 @@ private:
ResolveResult HandleNewObjInstResolveResultCommon(const ResolveResult &resolve_res) const;
Function *ResolveDefineFuncInstCommon(const Function *func, const Inst &def_func_inst) const;
std::unique_ptr<Class> ResolveDefineClassWithBufferInst(Function *func, const Inst &define_class_inst) const;
std::unique_ptr<CalleeInfo> ResolveCallInstCommon(Function *func, const Inst &call_inst) const;
std::unique_ptr<CalleeInfo> ResolveCallInstCommon(Function *func, const Inst &call_inst,
uint32_t func_obj_idx = 0) const;
std::unique_ptr<CalleeInfo> ResolveSuperCallInst(Function *func, const Inst &call_inst) const;
void HandleMemberFunctionFromClassBuf(const std::string &func_name, Function *def_func, Class *def_class) const;
void AddDefinedClass(std::unique_ptr<Class> &&def_class);

View File

@ -38,7 +38,10 @@ public:
bool operator==(const Inst &inst) const;
bool operator!=(const Inst &inst) const;
InstType GetType() const;
bool IsStGlobalInst() const;
bool IsInstStLexVar() const;
bool IsInstLdLexVar() const;
bool IsInstStGlobal() const;
bool IsInstLdGlobal() const;
uint16_t GetArgIndex() const;
uint32_t GetPc() const;
BasicBlock GetBasicBlock() const;

View File

@ -17,328 +17,20 @@
#define LIBARK_DEFECT_SCAN_AUX_INCLUDE_INST_TYPE_H
#include "compiler/optimizer/ir/inst.h"
#include "intrinsic_map_table.h"
#include "opcode_map_table.h"
namespace panda::defect_scan_aux {
#define OPCODE_INSTTYPE_MAP(V) \
V(Neg, Neg) \
V(Abs, Abs) \
V(Sqrt, Sqrt) \
V(Not, Not) \
V(Add, Add) \
V(Sub, Sub) \
V(Mul, Mul) \
V(Div, Div) \
V(Mod, Mod) \
V(Min, Min) \
V(Max, Max) \
V(Shl, Shl) \
V(Shr, Shr) \
V(AShr, AShr) \
V(And, And) \
V(Or, Or) \
V(Xor, Xor) \
V(Compare, Compare) \
V(Cmp, Cmp) \
V(CompareAnyType, CompareAnyType) \
V(CastAnyTypeValue, CastAnyTypeValue) \
V(CastValueToAnyType, CastValueToAnyType) \
V(Cast, Cast) \
V(Constant, Constant) \
V(Parameter, Parameter) \
V(NullPtr, NullPtr) \
V(NewArray, NewArray) \
V(NewObject, NewObject) \
V(InitObject, InitObject) \
V(LoadArray, LoadArray) \
V(LoadCompressedStringChar, LoadCompressedStringChar) \
V(StoreArray, StoreArray) \
V(LoadObject, LoadObject) \
V(Load, Load) \
V(LoadI, LoadI) \
V(Store, Store) \
V(StoreI, StoreI) \
V(UnresolvedLoadObject, UnresolvedLoadObject) \
V(StoreObject, StoreObject) \
V(UnresolvedStoreObject, UnresolvedStoreObject) \
V(LoadStatic, LoadStatic) \
V(UnresolvedLoadStatic, UnresolvedLoadStatic) \
V(StoreStatic, StoreStatic) \
V(UnresolvedStoreStatic, UnresolvedStoreStatic) \
V(LenArray, LenArray) \
V(LoadString, LoadString) \
V(LoadConstArray, LoadConstArray) \
V(FillConstArray, FillConstArray) \
V(LoadType, LoadType) \
V(UnresolvedLoadType, UnresolvedLoadType) \
V(CheckCast, CheckCast) \
V(IsInstance, IsInstance) \
V(InitClass, InitClass) \
V(LoadClass, LoadClass) \
V(LoadAndInitClass, LoadAndInitClass) \
V(UnresolvedLoadAndInitClass, UnresolvedLoadAndInitClass) \
V(GetInstanceClass, GetInstanceClass) \
V(ClassImmediate, ClassImmediate) \
V(NullCheck, NullCheck) \
V(BoundsCheck, BoundsCheck) \
V(RefTypeCheck, RefTypeCheck) \
V(ZeroCheck, ZeroCheck) \
V(NegativeCheck, NegativeCheck) \
V(AnyTypeCheck, AnyTypeCheck) \
V(Deoptimize, Deoptimize) \
V(DeoptimizeIf, DeoptimizeIf) \
V(DeoptimizeCompare, DeoptimizeCompare) \
V(DeoptimizeCompareImm, DeoptimizeCompareImm) \
V(IsMustDeoptimize, IsMustDeoptimize) \
V(ReturnVoid, ReturnVoid) \
V(Return, Return) \
V(ReturnInlined, ReturnInlined) \
V(Throw, Throw) \
V(IndirectJump, IndirectJump) \
V(CallStatic, CallStatic) \
V(UnresolvedCallStatic, UnresolvedCallStatic) \
V(CallVirtual, CallVirtual) \
V(UnresolvedCallVirtual, UnresolvedCallVirtual) \
V(CallDynamic, CallDynamic) \
V(CallIndirect, CallIndirect) \
V(Call, Call) \
V(MultiArray, MultiArray) \
V(Monitor, Monitor) \
V(Intrinsic, Intrinsic) \
V(Builtin, Builtin) \
V(AddI, AddI) \
V(SubI, SubI) \
V(MulI, MulI) \
V(DivI, DivI) \
V(ModI, ModI) \
V(ShlI, ShlI) \
V(ShrI, ShrI) \
V(AShrI, AShrI) \
V(AndI, AndI) \
V(OrI, OrI) \
V(XorI, XorI) \
V(MAdd, MAdd) \
V(MSub, MSub) \
V(MNeg, MNeg) \
V(OrNot, OrNot) \
V(AndNot, AndNot) \
V(XorNot, XorNot) \
V(AndSR, AndSR) \
V(OrSR, OrSR) \
V(XorSR, XorSR) \
V(AndNotSR, AndNotSR) \
V(OrNotSR, OrNotSR) \
V(XorNotSR, XorNotSR) \
V(AddSR, AddSR) \
V(SubSR, SubSR) \
V(NegSR, NegSR) \
V(BoundsCheckI, BoundsCheckI) \
V(LoadArrayI, LoadArrayI) \
V(LoadCompressedStringCharI, LoadCompressedStringCharI) \
V(StoreArrayI, StoreArrayI) \
V(LoadArrayPair, LoadArrayPair) \
V(LoadArrayPairI, LoadArrayPairI) \
V(LoadPairPart, LoadPairPart) \
V(StoreArrayPair, StoreArrayPair) \
V(StoreArrayPairI, StoreArrayPairI) \
V(ReturnI, ReturnI) \
V(Phi, Phi) \
V(SpillFill, SpillFill) \
V(SaveState, SaveState) \
V(SafePoint, SafePoint) \
V(SaveStateDeoptimize, SaveStateDeoptimize) \
V(SaveStateOsr, SaveStateOsr) \
V(Select, Select) \
V(SelectImm, SelectImm) \
V(AddOverflow, AddOverflow) \
V(SubOverflow, SubOverflow) \
V(AddOverflowCheck, AddOverflowCheck) \
V(SubOverflowCheck, SubOverflowCheck) \
V(If, If) \
V(IfImm, IfImm) \
V(NOP, NOP) \
V(Try, Try) \
V(CatchPhi, CatchPhi) \
V(LiveIn, LiveIn) \
V(LiveOut, LiveOut)
#define INTRINSIC_INSTTYPE_MAP(V) \
V(ECMA_LDNAN_PREF_NONE, Intrinsic_LdNan) \
V(ECMA_LDINFINITY_PREF_NONE, Intrinsic_LdInfinity) \
V(ECMA_LDGLOBALTHIS_PREF_NONE, Intrinsic_LdGlobalThis) \
V(ECMA_LDUNDEFINED_PREF_NONE, Intrinsic_LdUndefined) \
V(ECMA_LDNULL_PREF_NONE, Intrinsic_LdNull) \
V(ECMA_LDSYMBOL_PREF_NONE, Intrinsic_LdSymbol) \
V(ECMA_LDGLOBAL_PREF_NONE, Intrinsic_LdGlobal) \
V(ECMA_LDTRUE_PREF_NONE, Intrinsic_LdTrue) \
V(ECMA_LDFALSE_PREF_NONE, Intrinsic_LdFalse) \
V(ECMA_THROWDYN_PREF_NONE, Intrinsic_ThrowDyn) \
V(ECMA_RETHROWDYN_PREF_NONE, Intrinsic_RethrowDyn) \
V(ECMA_TYPEOFDYN_PREF_NONE, Intrinsic_TypeofDyn) \
V(ECMA_LDLEXENVDYN_PREF_NONE, Intrinsic_LdLexEnvDyn) \
V(ECMA_POPLEXENVDYN_PREF_NONE, Intrinsic_PopLexEnvDyn) \
V(ECMA_GETUNMAPPEDARGS_PREF_NONE, Intrinsic_GetUnmappedArgs) \
V(ECMA_GETPROPITERATOR_PREF_NONE, Intrinsic_GetPropIterator) \
V(ECMA_ASYNCFUNCTIONENTER_PREF_NONE, Intrinsic_AsyncFunctionEnter) \
V(ECMA_LDHOLE_PREF_NONE, Intrinsic_LdHole) \
V(ECMA_RETURNUNDEFINED_PREF_NONE, Intrinsic_ReturnUndefined) \
V(ECMA_CREATEEMPTYOBJECT_PREF_NONE, Intrinsic_CreateEmptyObject) \
V(ECMA_CREATEEMPTYARRAY_PREF_NONE, Intrinsic_CreateEmptyArray) \
V(ECMA_GETITERATOR_PREF_V8_V8, Intrinsic_GetIterator_V8) \
V(ECMA_GETITERATOR_PREF_NONE, Intrinsic_GetIterator_None) \
V(ECMA_GETASYNCITERATOR_PREF_NONE, Intrinsic_GetAsyncIterator) \
V(ECMA_THROWTHROWNOTEXISTS_PREF_NONE, Intrinsic_ThrowThrowNotExists) \
V(ECMA_THROWPATTERNNONCOERCIBLE_PREF_NONE, Intrinsic_ThrowPatternNonCoercible) \
V(ECMA_LDHOMEOBJECT_PREF_NONE, Intrinsic_LdHomeObject) \
V(ECMA_THROWDELETESUPERPROPERTY_PREF_NONE, Intrinsic_ThrowDeleteSuperProperty) \
V(ECMA_DEBUGGER_PREF_NONE, Intrinsic_Debugger) \
V(ECMA_ADD2DYN_PREF_V8, Intrinsic_Add2Dyn) \
V(ECMA_SUB2DYN_PREF_V8, Intrinsic_Sub2Dyn) \
V(ECMA_MUL2DYN_PREF_V8, Intrinsic_Mul2Dyn) \
V(ECMA_DIV2DYN_PREF_V8, Intrinsic_Div2Dyn) \
V(ECMA_MOD2DYN_PREF_V8, Intrinsic_Mod2Dyn) \
V(ECMA_EQDYN_PREF_V8, Intrinsic_EqDyn) \
V(ECMA_NOTEQDYN_PREF_V8, Intrinsic_NotEqDyn) \
V(ECMA_LESSDYN_PREF_V8, Intrinsic_LessDyn) \
V(ECMA_LESSEQDYN_PREF_V8, Intrinsic_LessEqDyn) \
V(ECMA_GREATERDYN_PREF_V8, Intrinsic_GreaterDyn) \
V(ECMA_GREATEREQDYN_PREF_V8, Intrinsic_GreaterEqDyn) \
V(ECMA_SHL2DYN_PREF_V8, Intrinsic_Shl2Dyn) \
V(ECMA_SHR2DYN_PREF_V8, Intrinsic_Shr2Dyn) \
V(ECMA_ASHR2DYN_PREF_V8, Intrinsic_AShr2Dyn) \
V(ECMA_AND2DYN_PREF_V8, Intrinsic_And2Dyn) \
V(ECMA_OR2DYN_PREF_V8, Intrinsic_Or2Dyn) \
V(ECMA_XOR2DYN_PREF_V8, Intrinsic_Xor2Dyn) \
V(ECMA_TONUMBER_PREF_V8, Intrinsic_ToNumber) \
V(ECMA_TONUMERIC_PREF_V8, Intrinsic_ToNumeric) \
V(ECMA_NEGDYN_PREF_V8, Intrinsic_NegDyn) \
V(ECMA_NOTDYN_PREF_V8, Intrinsic_NotDyn) \
V(ECMA_INCDYN_PREF_V8, Intrinsic_IncDyn) \
V(ECMA_DECDYN_PREF_V8, Intrinsic_DecDyn) \
V(ECMA_EXPDYN_PREF_V8, Intrinsic_ExpDyn) \
V(ECMA_ISINDYN_PREF_V8, Intrinsic_IsInDyn) \
V(ECMA_INSTANCEOFDYN_PREF_V8, Intrinsic_InstanceofDyn) \
V(ECMA_STRICTNOTEQDYN_PREF_V8, Intrinsic_StrictNotEqDyn) \
V(ECMA_STRICTEQDYN_PREF_V8, Intrinsic_StrictEqDyn) \
V(ECMA_RESUMEGENERATOR_PREF_V8, Intrinsic_ResumeGenerator) \
V(ECMA_GETRESUMEMODE_PREF_V8, Intrinsic_GetResumeMode) \
V(ECMA_CREATEGENERATOROBJ_PREF_V8, Intrinsic_CreateGeneratorObj) \
V(ECMA_SETGENERATORSTATE_PREF_V8_IMM8, Intrinsic_SetGeneratorState) \
V(ECMA_CREATEASYNCGENERATOROBJ_PREF_V8, Intrinsic_CreateAsyncGeneratorObj) \
V(ECMA_THROWCONSTASSIGNMENT_PREF_V8, Intrinsic_ThrowConstAssignment) \
V(ECMA_GETMETHOD_PREF_ID32_V8, Intrinsic_GetMethod) \
V(ECMA_GETTEMPLATEOBJECT_PREF_V8, Intrinsic_GetTemplateObject) \
V(ECMA_GETNEXTPROPNAME_PREF_V8, Intrinsic_GetNextPropName) \
V(ECMA_CALLARG0DYN_PREF_V8, Intrinsic_CallArg0Dyn) \
V(ECMA_THROWIFNOTOBJECT_PREF_V8, Intrinsic_ThrowIfNotObject) \
V(ECMA_CLOSEITERATOR_PREF_V8, Intrinsic_CloseIterator) \
V(ECMA_COPYMODULE_PREF_V8, Intrinsic_CopyModule) \
V(ECMA_SUPERCALLSPREAD_PREF_V8, Intrinsic_SuperCallSpread) \
V(ECMA_DELOBJPROP_PREF_V8_V8, Intrinsic_DelObjProp) \
V(ECMA_NEWOBJSPREADDYN_PREF_V8_V8, Intrinsic_NewObjSpreadDyn) \
V(ECMA_CREATEITERRESULTOBJ_PREF_V8_V8, Intrinsic_CreateIterResultObj) \
V(ECMA_SUSPENDGENERATOR_PREF_V8_V8, Intrinsic_SuspendGenerator) \
V(ECMA_SUSPENDASYNCGENERATOR_PREF_V8, Intrinsic_SuspendAsyncGenerator) \
V(ECMA_ASYNCFUNCTIONAWAITUNCAUGHT_PREF_V8_V8, Intrinsic_AsyncFunctionAwaitUncaught) \
V(ECMA_THROWUNDEFINEDIFHOLE_PREF_V8_V8, Intrinsic_ThrowUndefinedIfHole) \
V(ECMA_CALLARG1DYN_PREF_V8_V8, Intrinsic_CallArg1Dyn) \
V(ECMA_COPYDATAPROPERTIES_PREF_V8_V8, Intrinsic_CopyDataProperties) \
V(ECMA_STARRAYSPREAD_PREF_V8_V8, Intrinsic_StArraySpread) \
V(ECMA_SETOBJECTWITHPROTO_PREF_V8_V8, Intrinsic_SetObjectWithProto) \
V(ECMA_LDOBJBYVALUE_PREF_V8_V8, Intrinsic_LdObjByValue) \
V(ECMA_STOBJBYVALUE_PREF_V8_V8, Intrinsic_StObjByValue) \
V(ECMA_STOWNBYVALUE_PREF_V8_V8, Intrinsic_StOwnByValue) \
V(ECMA_LDSUPERBYVALUE_PREF_V8_V8, Intrinsic_LdSuperByValue) \
V(ECMA_STSUPERBYVALUE_PREF_V8_V8, Intrinsic_StSuperByValue) \
V(ECMA_LDOBJBYINDEX_PREF_IMM8_V8, Intrinsic_LdObjByIndex_Imm8) \
V(ECMA_LDOBJBYINDEX_PREF_IMM16_V8, Intrinsic_LdObjByIndex_Imm16) \
V(ECMA_LDOBJBYINDEX_PREF_V8_IMM32, Intrinsic_LdObjByIndex_Imm32) \
V(ECMA_STOBJBYINDEX_PREF_IMM8_V8, Intrinsic_StObjByIndex_Imm8) \
V(ECMA_STOBJBYINDEX_PREF_IMM16_V8, Intrinsic_StObjByIndex_Imm16) \
V(ECMA_STOBJBYINDEX_PREF_V8_IMM32, Intrinsic_StObjByIndex_Imm32) \
V(ECMA_STOWNBYINDEX_PREF_IMM8_V8, Intrinsic_StOwnByIndex_Imm8) \
V(ECMA_STOWNBYINDEX_PREF_IMM16_V8, Intrinsic_StOwnByIndex_Imm16) \
V(ECMA_STOWNBYINDEX_PREF_V8_IMM32, Intrinsic_StOwnByIndex_Imm32) \
V(ECMA_CALLSPREADDYN_PREF_V8_V8_V8, Intrinsic_CallSpreadDyn) \
V(ECMA_ASYNCFUNCTIONRESOLVE_PREF_V8_V8_V8, Intrinsic_AsyncFunctionResolve) \
V(ECMA_ASYNCFUNCTIONREJECT_PREF_V8_V8_V8, Intrinsic_AsyncFunctionReject) \
V(ECMA_ASYNCGENERATORRESOLVE_PREF_V8, Intrinsic_AsyncGeneratorResolve) \
V(ECMA_ASYNCGENERATORREJECT_PREF_V8, Intrinsic_AsyncGeneratorReject) \
V(ECMA_CALLARGS2DYN_PREF_V8_V8_V8, Intrinsic_CallArgs2Dyn) \
V(ECMA_CALLARGS3DYN_PREF_V8_V8_V8_V8, Intrinsic_CallArgs3Dyn) \
V(ECMA_DEFINEGETTERSETTERBYVALUE_PREF_V8_V8_V8_V8, Intrinsic_DefineGetterSetterByValue) \
V(ECMA_NEWOBJDYNRANGE_PREF_IMM16_V8, Intrinsic_NewObjDynRange) \
V(ECMA_CALLIRANGEDYN_PREF_IMM16_V8, Intrinsic_CallIRangeDyn) \
V(ECMA_CALLITHISRANGEDYN_PREF_IMM16_V8, Intrinsic_CallIThisRangeDyn) \
V(ECMA_SUPERCALL_PREF_IMM16_V8, Intrinsic_SuperCall) \
V(ECMA_CREATEOBJECTWITHEXCLUDEDKEYS_PREF_IMM16_V8_V8, Intrinsic_CreateObjectWithExcludedKeys) \
V(ECMA_DEFINEFUNCDYN_PREF_ID16_IMM16_V8, Intrinsic_DefineFuncDyn) \
V(ECMA_DEFINENCFUNCDYN_PREF_ID16_IMM16_V8, Intrinsic_DefineNcFuncDyn) \
V(ECMA_DEFINEGENERATORFUNC_PREF_ID16_IMM16_V8, Intrinsic_DefineGeneratorFunc) \
V(ECMA_DEFINEASYNCFUNC_PREF_ID16_IMM16_V8, Intrinsic_DefineAsyncFunc) \
V(ECMA_DEFINEASYNCGENERATORFUNC_PREF_ID16_V8, Intrinsic_DefineAsyncGeneratorFunc) \
V(ECMA_DEFINEMETHOD_PREF_ID16_IMM16_V8, Intrinsic_DefineMethod) \
V(ECMA_NEWLEXENVDYN_PREF_IMM16, Intrinsic_NewLexEnvDyn) \
V(ECMA_COPYLEXENVDYN_PREF_NONE, Intrinsic_CopyLexEnvDyn) \
V(ECMA_COPYRESTARGS_PREF_IMM16, Intrinsic_CopyRestArgs) \
V(ECMA_CREATEARRAYWITHBUFFER_PREF_IMM16, Intrinsic_CreateArrayWithBuffer) \
V(ECMA_CREATEOBJECTHAVINGMETHOD_PREF_IMM16, Intrinsic_CreateObjectHavingMethod) \
V(ECMA_THROWIFSUPERNOTCORRECTCALL_PREF_IMM16, Intrinsic_ThrowIfSuperNotCorrectCall) \
V(ECMA_CREATEOBJECTWITHBUFFER_PREF_IMM16, Intrinsic_CreateObjectWithBuffer) \
V(ECMA_LDLEXVARDYN_PREF_IMM4_IMM4, Intrinsic_LdLexVarDyn_Imm4) \
V(ECMA_LDLEXVARDYN_PREF_IMM8_IMM8, Intrinsic_LdLexVarDyn_Imm8) \
V(ECMA_LDLEXVARDYN_PREF_IMM16_IMM16, Intrinsic_LdLexVarDyn_Imm16) \
V(ECMA_STLEXVARDYN_PREF_IMM4_IMM4_V8, Intrinsic_StLexVarDyn_Imm4) \
V(ECMA_STLEXVARDYN_PREF_IMM8_IMM8_V8, Intrinsic_StLexVarDyn_Imm8) \
V(ECMA_STLEXVARDYN_PREF_IMM16_IMM16_V8, Intrinsic_StLexVarDyn_Imm16) \
V(ECMA_DEFINECLASSWITHBUFFER_PREF_ID16_IMM16_IMM16_V8_V8, Intrinsic_DefineClassWithBuffer) \
V(ECMA_IMPORTMODULE_PREF_ID32, Intrinsic_ImportModule) \
V(ECMA_STMODULEVAR_PREF_ID32, Intrinsic_StModuleVar) \
V(ECMA_TRYLDGLOBALBYNAME_PREF_ID32, Intrinsic_TryLdGlobalByName) \
V(ECMA_TRYSTGLOBALBYNAME_PREF_ID32, Intrinsic_TryStGlobalByName) \
V(ECMA_LDGLOBALVAR_PREF_ID32, Intrinsic_LdGlobalVar) \
V(ECMA_STGLOBALVAR_PREF_ID32, Intrinsic_StGlobalVar) \
V(ECMA_STGLOBALLET_PREF_ID32, Intrinsic_StGlobalLet) \
V(ECMA_LDOBJBYNAME_PREF_ID32_V8, Intrinsic_LdObjByName) \
V(ECMA_STOBJBYNAME_PREF_ID32_V8, Intrinsic_StObjByName) \
V(ECMA_STOWNBYNAME_PREF_ID32_V8, Intrinsic_StOwnByName) \
V(ECMA_LDSUPERBYNAME_PREF_ID32_V8, Intrinsic_LdSuperByName) \
V(ECMA_STSUPERBYNAME_PREF_ID32_V8, Intrinsic_StSuperByName) \
V(ECMA_LDMODVARBYNAME_PREF_ID32_V8, Intrinsic_LdModVarByName) \
V(ECMA_TOBOOLEAN_PREF_NONE, Intrinsic_ToBoolean) \
V(ECMA_NEGATE_PREF_NONE, Intrinsic_Negate) \
V(ECMA_ISTRUE_PREF_NONE, Intrinsic_IsTrue) \
V(ECMA_ISFALSE_PREF_NONE, Intrinsic_IsFalse) \
V(ECMA_ISUNDEFINED_PREF_NONE, Intrinsic_IsUndefined) \
V(ECMA_ISCOERCIBLE_PREF_NONE, Intrinsic_IsCoercible) \
V(ECMA_JFALSE_PREF_IMM8, Intrinsic_JFalse_Imm8) \
V(ECMA_JFALSE_PREF_IMM16, Intrinsic_JFalse_Imm16) \
V(ECMA_JFALSE_PREF_IMM32, Intrinsic_JFalse_Imm32) \
V(ECMA_JTRUE_PREF_IMM8, Intrinsic_JTrue_Imm8) \
V(ECMA_JTRUE_PREF_IMM16, Intrinsic_JTrue_Imm16) \
V(ECMA_JTRUE_PREF_IMM32, Intrinsic_JTrue_Imm32) \
V(ECMA_RETURN_DYN_PREF_NONE, Intrinsic_ReturnDyn) \
V(ECMA_ITERNEXT_PREF_V8, Intrinsic_IterNext) \
V(ECMA_GETMODULENAMESPACE_PREF_ID32, Intrinsic_GetModuleNamespace) \
V(ECMA_LDMODULEVAR_PREF_ID32_IMM8, Intrinsic_LdModuleVar) \
V(ECMA_STCONSTTOGLOBALRECORD_PREF_ID32, Intrinsic_StConstToGlobalRecord) \
V(ECMA_STLETTOGLOBALRECORD_PREF_ID32, Intrinsic_StLetToGlobalRecord) \
V(ECMA_GETITERATORNEXT_PREF_V8_V8, Intrinsic_GetIteratorNext) \
V(ECMA_CREATEREGEXPWITHLITERAL_PREF_ID32_IMM8, Intrinsic_CreateRegexpWithLiteral) \
V(ECMA_STCLASSTOGLOBALRECORD_PREF_ID32, Intrinsic_StClassToGlobalRecord) \
V(ECMA_STOWNBYVALUEWITHNAMESET_PREF_V8_V8, Intrinsic_StOwnByValueWithNameSet) \
V(ECMA_LDFUNCTION_PREF_NONE, Intrinsic_LdFunction) \
V(ECMA_NEWLEXENVWITHNAMEDYN_PREF_IMM16_IMM16, Intrinsic_NewLexEnvWithNameDyn) \
V(ECMA_LDBIGINT_PREF_ID32, Intrinsic_LdBigInt) \
V(ECMA_STOWNBYNAMEWITHNAMESET_PREF_ID32_V8, Intrinsic_StOwnByNameWithNameSet)
#define INSTTYPE_ENUM(x, y) y,
#define BUILD_OPCODE_MAP(x, y) {Opcode::x, InstType::y},
#define BUILD_INTRINSIC_MAP(x, y) {IntrinsicId::x, InstType::y},
#define BUILD_OPCODE_MAP_TABLE(x, y) {Opcode::x, InstType::y},
#define BUILD_INTRINSIC_MAP_TABLE(x, y) {IntrinsicId::x, InstType::y},
using Opcode = compiler::Opcode;
using IntrinsicId = compiler::RuntimeInterface::IntrinsicId;
enum class InstType {
OPCODE_INSTTYPE_MAP(INSTTYPE_ENUM) INTRINSIC_INSTTYPE_MAP(INSTTYPE_ENUM) COUNT,
OPCODE_INSTTYPE_MAP_TABLE(INSTTYPE_ENUM)
INTRINSIC_INSTTYPE_MAP_TABLE(INSTTYPE_ENUM)
COUNT,
INVALID_TYPE,
};
} // namespace panda::defect_scan_aux

View File

@ -42,6 +42,13 @@ public:
void SetRequestModules(std::vector<std::string> &request_modules);
void AddImportEntry(const ImportEntry &import_entry);
void AddExportEntry(const ExportEntry &export_entry);
void SetRegularImportNum(size_t regular_import_num);
void SetLocalExportNum(size_t local_export_num);
size_t GetRegularImportNum() const;
size_t GetLocalExportNum() const;
const std::string &GetImportInternalNameByIndex(size_t index) const;
const std::string &GetImportNamespaceNameByIndex(size_t index) const;
const std::string &GetExportNameByIndex(size_t index) const;
std::string GetInternalNameByExportName(std::string_view export_name) const;
std::string GetImportNameByExportName(std::string_view export_name) const;
std::string GetModuleNameByExportName(std::string_view export_name) const;
@ -50,6 +57,8 @@ public:
private:
std::string module_filename_;
size_t regular_import_num_ {0};
size_t local_export_num_ {0};
std::vector<std::string> request_modules_;
std::vector<ImportEntry> import_entries_;
std::vector<ExportEntry> export_entries_;

View File

@ -14,6 +14,8 @@
*/
#include "module_record.h"
#include <algorithm>
#include "libpandabase/macros.h"
namespace panda::defect_scan_aux {
void ModuleRecord::SetModuleFilename(std::string_view module_filename)
@ -36,6 +38,48 @@ void ModuleRecord::AddExportEntry(const ExportEntry &export_entry)
export_entries_.push_back(export_entry);
}
void ModuleRecord::SetRegularImportNum(size_t regular_import_num)
{
regular_import_num_ = regular_import_num;
}
void ModuleRecord::SetLocalExportNum(size_t local_export_num)
{
local_export_num_ = local_export_num;
}
size_t ModuleRecord::GetRegularImportNum() const
{
return regular_import_num_;
}
size_t ModuleRecord::GetLocalExportNum() const
{
return local_export_num_;
}
const std::string &ModuleRecord::GetImportInternalNameByIndex(size_t index) const
{
ASSERT(index < regular_import_num_);
return import_entries_[index].local_name_;
}
const std::string &ModuleRecord::GetImportNamespaceNameByIndex(size_t index) const
{
ASSERT(index < request_modules_.size());
const std::string &module_name = request_modules_[index];
auto iter = std::find_if(import_entries_.begin() + regular_import_num_, import_entries_.end(),
[&](const ImportEntry &entry) { return entry.module_request_ == module_name; });
ASSERT(iter != import_entries_.end());
return iter->local_name_;
}
const std::string &ModuleRecord::GetExportNameByIndex(size_t index) const
{
ASSERT(index < local_export_num_);
return export_entries_[index].export_name_;
}
std::string ModuleRecord::GetInternalNameByExportName(std::string_view export_name) const
{
for (auto &export_entry : export_entries_) {

View File

@ -0,0 +1,23 @@
/*
* 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.
*/
// Autogenerated file -- DO NOT EDIT!
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define INTRINSIC_INSTTYPE_MAP_TABLE(V) \
% Panda.instructions.select{|x| x.namespace == "ecmascript"}.each do |inst|
V( <%= inst.opcode.upcase.ljust(60) %>, <%= inst.opcode.upcase.ljust(60) %> ) \
% end

View File

@ -0,0 +1,23 @@
/*
* 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.
*/
// Autogenerated file -- DO NOT EDIT!
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define OPCODE_INSTTYPE_MAP_TABLE(V) \
% IR::instructions.each do |inst|
V( <%= inst.opcode.ljust(30) %>, OPCODE_<%= inst.opcode.upcase.ljust(30) %> ) \
% end

View File

@ -24,7 +24,7 @@ action("generate_abc_file") {
"--build-dir",
rebase_path("$ts2abc_build_path"),
"--dst-dir",
rebase_path("$root_out_dir/arkcompiler/ets_frontend"),
rebase_path("$root_out_dir/arkcompiler/runtime_core"),
]
deps = [ "$ts2abc_root:ark_ts2abc_build" ]
@ -34,7 +34,7 @@ action("generate_abc_file") {
ohos_executable("defect_scan_aux_unittest") {
sources = [ "defect_scan_aux_test.cpp" ]
configs = [ "$ark_root/libark_defect_scan_aux:defectscan_test_config" ]
configs = [ "$ark_root/libark_defect_scan_aux:defectscanaux_test_config" ]
deps = [
"$ark_root/libark_defect_scan_aux:libark_defect_scan_aux_static_test",

View File

@ -486,18 +486,30 @@ int main()
auto type = inst.GetType();
inst_cnt_table.insert_or_assign(type, inst_cnt_table[type] + 1);
});
TestHelper::ExpectEqual(inst_cnt_table[InstType::Intrinsic_NewObjDynRange], 2);
uint32_t ldlex_cnt = inst_cnt_table[InstType::Intrinsic_LdLexVarDyn_Imm4] +
inst_cnt_table[InstType::Intrinsic_LdLexVarDyn_Imm8] +
inst_cnt_table[InstType::Intrinsic_LdLexVarDyn_Imm16];
uint32_t newobj_cnt = inst_cnt_table[InstType::NEWOBJRANGE_IMM8_IMM8_V8] +
inst_cnt_table[InstType::NEWOBJRANGE_IMM16_IMM8_V8] +
inst_cnt_table[InstType::WIDE_NEWOBJRANGE_PREF_IMM16_V8];
TestHelper::ExpectEqual(newobj_cnt, 2);
uint32_t ldlex_cnt = inst_cnt_table[InstType::LDLEXVAR_IMM4_IMM4] +
inst_cnt_table[InstType::LDLEXVAR_IMM8_IMM8] +
inst_cnt_table[InstType::WIDE_LDLEXVAR_PREF_IMM16_IMM16];
TestHelper::ExpectEqual(ldlex_cnt, 7);
TestHelper::ExpectEqual(inst_cnt_table[InstType::Intrinsic_LdObjByName], 4);
TestHelper::ExpectEqual(inst_cnt_table[InstType::Intrinsic_CallIThisRangeDyn], 4);
TestHelper::ExpectEqual(inst_cnt_table[InstType::Intrinsic_DefineFuncDyn], 1);
TestHelper::ExpectEqual(inst_cnt_table[InstType::Intrinsic_CallArg0Dyn], 1);
TestHelper::ExpectEqual(inst_cnt_table[InstType::Intrinsic_CallArg1Dyn], 1);
TestHelper::ExpectEqual(inst_cnt_table[InstType::Intrinsic_LdModuleVar], 1);
TestHelper::ExpectEqual(inst_cnt_table[InstType::Parameter], 2);
TestHelper::ExpectEqual(
inst_cnt_table[InstType::LDOBJBYNAME_IMM8_ID16] + inst_cnt_table[InstType::LDOBJBYNAME_IMM16_ID16], 4);
TestHelper::ExpectEqual(inst_cnt_table[InstType::CALLTHIS1_IMM8_V8_V8], 3);
TestHelper::ExpectEqual(inst_cnt_table[InstType::CALLTHIS2_IMM8_V8_V8_V8], 1);
TestHelper::ExpectEqual(inst_cnt_table[InstType::DEFINEFUNC_IMM8_ID16_IMM8] +
inst_cnt_table[InstType::DEFINEFUNC_IMM16_ID16_IMM8],
1);
TestHelper::ExpectEqual(inst_cnt_table[InstType::CALLARG0_IMM8], 1);
TestHelper::ExpectEqual(inst_cnt_table[InstType::CALLARG1_IMM8_V8], 1);
TestHelper::ExpectEqual(inst_cnt_table[InstType::LDEXTERNALMODULEVAR_IMM8] +
inst_cnt_table[InstType::WIDE_LDEXTERNALMODULEVAR_PREF_IMM16],
1);
TestHelper::ExpectEqual(inst_cnt_table[InstType::GETMODULENAMESPACE_IMM8] +
inst_cnt_table[InstType::WIDE_GETMODULENAMESPACE_PREF_IMM16],
0);
TestHelper::ExpectEqual(inst_cnt_table[InstType::OPCODE_PARAMETER], 2);
// check api of basic block
auto bb0 = graph.GetStartBasicBlock();
@ -530,42 +542,49 @@ int main()
auto call_inst0 = ci0->GetCallInst();
auto call_inst0_ins = call_inst0.GetInputInsts();
TestHelper::ExpectEqual(call_inst0_ins.size(), 4);
TestHelper::ExpectEqual(call_inst0_ins[0].GetType(), InstType::Intrinsic_LdObjByName);
TestHelper::ExpectEqual(call_inst0_ins[0].GetUserInsts().size(), 1);
TestHelper::ExpectEqual(call_inst0_ins[0].GetUserInsts()[0], call_inst0);
TestHelper::ExpectEqual(call_inst0_ins[2].GetType(), InstType::Intrinsic_CallArg0Dyn);
TestHelper::ExpectEqual(call_inst0_ins[2].GetUserInsts().size(), 1);
TestHelper::ExpectEqual(call_inst0_ins[2].GetUserInsts()[0], call_inst0);
TestHelper::ExpectEqual(call_inst0_ins[3].GetType(), InstType::Parameter);
TestHelper::ExpectEqual(call_inst0_ins[3].GetArgIndex(), 1);
auto param1_usrs = call_inst0_ins[3].GetUserInsts();
auto call_inst0_in1_type = call_inst0_ins[1].GetType();
TestHelper::ExpectEqual(call_inst0_in1_type, InstType::CALLARG0_IMM8);
TestHelper::ExpectEqual(call_inst0_ins[1].GetUserInsts().size(), 1);
TestHelper::ExpectEqual(call_inst0_ins[1].GetUserInsts()[0], call_inst0);
auto call_inst0_in2_type = call_inst0_ins[2].GetType();
TestHelper::ExpectEqual(call_inst0_in2_type, InstType::OPCODE_PARAMETER);
TestHelper::ExpectEqual(call_inst0_ins[2].GetArgIndex(), 1);
auto param1_usrs = call_inst0_ins[2].GetUserInsts();
TestHelper::ExpectTrue(std::find(param1_usrs.begin(), param1_usrs.end(), call_inst0) != param1_usrs.end());
auto call_inst0_in3_type = call_inst0_ins[3].GetType();
TestHelper::ExpectTrue(call_inst0_in3_type == InstType::LDOBJBYNAME_IMM8_ID16 ||
call_inst0_in3_type == InstType::LDOBJBYNAME_IMM16_ID16);
TestHelper::ExpectEqual(call_inst0_ins[3].GetUserInsts().size(), 1);
TestHelper::ExpectEqual(call_inst0_ins[3].GetUserInsts()[0], call_inst0);
auto ci1 = f0->GetCalleeInfoByIndex(ci_cnt - 2);
auto call_inst1 = ci1->GetCallInst();
auto call_inst1_ins = call_inst1.GetInputInsts();
TestHelper::ExpectEqual(call_inst1_ins.size(), 2);
TestHelper::ExpectEqual(call_inst1_ins[0].GetType(), InstType::Intrinsic_LdModuleVar);
TestHelper::ExpectEqual(call_inst1_ins[0].GetUserInsts().size(), 2);
TestHelper::ExpectTrue((call_inst1_ins[0].GetUserInsts()[0] == call_inst1) ||
(call_inst1_ins[0].GetUserInsts()[1] == call_inst1));
auto phi_inst = call_inst1_ins[1];
TestHelper::ExpectEqual(phi_inst.GetType(), InstType::Phi);
auto call_inst1_in0_type = call_inst1_ins[1].GetType();
TestHelper::ExpectTrue(call_inst1_in0_type == InstType::LDEXTERNALMODULEVAR_IMM8 ||
call_inst1_in0_type == InstType::WIDE_LDEXTERNALMODULEVAR_PREF_IMM16);
TestHelper::ExpectEqual(call_inst1_ins[1].GetUserInsts().size(), 2);
TestHelper::ExpectTrue((call_inst1_ins[1].GetUserInsts()[0] == call_inst1) ||
(call_inst1_ins[1].GetUserInsts()[1] == call_inst1));
auto phi_inst = call_inst1_ins[0];
TestHelper::ExpectEqual(phi_inst.GetType(), InstType::OPCODE_PHI);
auto phi_inst_ins = phi_inst.GetInputInsts();
TestHelper::ExpectEqual(phi_inst_ins.size(), 2);
auto phi_inst_in0 = phi_inst_ins[0];
auto phi_inst_in1 = phi_inst_ins[1];
if (phi_inst_in0.GetType() != InstType::Parameter) {
if (phi_inst_in0.GetType() != InstType::OPCODE_PARAMETER) {
std::swap(phi_inst_in0, phi_inst_in1);
}
TestHelper::ExpectEqual(phi_inst_in0.GetType(), InstType::Parameter);
TestHelper::ExpectEqual(phi_inst_in0.GetType(), InstType::OPCODE_PARAMETER);
TestHelper::ExpectEqual(phi_inst_in0.GetArgIndex(), 0);
auto param0_usrs = phi_inst_in0.GetUserInsts();
TestHelper::ExpectTrue(std::find(param0_usrs.begin(), param0_usrs.end(), phi_inst) != param0_usrs.end());
TestHelper::ExpectEqual(phi_inst_in1.GetType(), InstType::Intrinsic_Add2Dyn);
TestHelper::ExpectEqual(phi_inst_in1.GetType(), InstType::ADD2_IMM8_V8);
auto add2_inst_ins = phi_inst_in1.GetInputInsts();
TestHelper::ExpectEqual(add2_inst_ins.size(), 2);
TestHelper::ExpectEqual(add2_inst_ins[0].GetType(), InstType::Parameter);
TestHelper::ExpectEqual(add2_inst_ins[1].GetType(), InstType::Parameter);
TestHelper::ExpectEqual(add2_inst_ins[0].GetType(), InstType::OPCODE_PARAMETER);
TestHelper::ExpectEqual(add2_inst_ins[1].GetType(), InstType::OPCODE_PARAMETER);
std::cout << " --- Pass ---" << std::endl;
}
std::cout << "===== [libark_defect_scan_aux] Unittest Pass =====" << std::endl;