1b1994897Sopenharmony_ci# Copyright (c) 2021-2022 Huawei Device Co., Ltd. 2b1994897Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 3b1994897Sopenharmony_ci# you may not use this file except in compliance with the License. 4b1994897Sopenharmony_ci# You may obtain a copy of the License at 5b1994897Sopenharmony_ci# 6b1994897Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 7b1994897Sopenharmony_ci# 8b1994897Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software 9b1994897Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 10b1994897Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11b1994897Sopenharmony_ci# See the License for the specific language governing permissions and 12b1994897Sopenharmony_ci# limitations under the License. 13b1994897Sopenharmony_ci 14b1994897Sopenharmony_cicmake_minimum_required(VERSION 3.3.2 FATAL_ERROR) 15b1994897Sopenharmony_ciproject(arkdisassembler CXX) 16b1994897Sopenharmony_ci 17b1994897Sopenharmony_cipanda_add_executable(ark_disasm disasm.cpp) 18b1994897Sopenharmony_ci 19b1994897Sopenharmony_ciset(GENERATOR ${PANDA_ROOT}/libpandafile/types.rb) 20b1994897Sopenharmony_ciset(TEMPLATE ${CMAKE_CURRENT_LIST_DIR}/templates/type_to_pandasm_type.cpp.erb) 21b1994897Sopenharmony_ciset(DATAFILE ${PANDA_ROOT}/libpandafile/types.yaml) 22b1994897Sopenharmony_ciset(DEPENDENCIES ${GENERATOR} ${TEMPLATE} ${DATAFILE}) 23b1994897Sopenharmony_ciset(OUTFILE "${CMAKE_CURRENT_BINARY_DIR}/type_to_pandasm_type.cpp") 24b1994897Sopenharmony_ciadd_custom_command(OUTPUT "${OUTFILE}" 25b1994897Sopenharmony_ci COMMENT "Generating type_to_pandasm_type.cpp" 26b1994897Sopenharmony_ci COMMAND ${PANDA_ROOT}/isa/gen.rb -d ${DATAFILE} -t ${TEMPLATE} -o "${OUTFILE}" -r ${GENERATOR} 27b1994897Sopenharmony_ci DEPENDS ${DEPENDENCIES}) 28b1994897Sopenharmony_ciadd_custom_target(type_to_pandasm_type_gen_${PROJECT_NAME} ALL DEPENDS "${OUTFILE}") 29b1994897Sopenharmony_ci 30b1994897Sopenharmony_cipanda_isa_gen( 31b1994897Sopenharmony_ci TEMPLATES 32b1994897Sopenharmony_ci "opcode_translator.cpp.erb" 33b1994897Sopenharmony_ci "bc_ins_to_pandasm_ins.cpp.erb" 34b1994897Sopenharmony_ci "get_ins_info.cpp.erb" 35b1994897Sopenharmony_ci REQUIRES 36b1994897Sopenharmony_ci "${PANDA_ROOT}/assembler/asm_isapi.rb" 37b1994897Sopenharmony_ci "${PANDA_ROOT}/libpandafile/pandafile_isapi.rb" 38b1994897Sopenharmony_ci) 39b1994897Sopenharmony_ci 40b1994897Sopenharmony_ciadd_library(arkdisassembler ${PANDA_DEFAULT_LIB_TYPE} 41b1994897Sopenharmony_ci disassembler.cpp 42b1994897Sopenharmony_ci opcode_translator.cpp 43b1994897Sopenharmony_ci bc_ins_to_pandasm_ins.cpp 44b1994897Sopenharmony_ci get_ins_info.cpp 45b1994897Sopenharmony_ci type_to_pandasm_type.cpp 46b1994897Sopenharmony_ci) 47b1994897Sopenharmony_ci 48b1994897Sopenharmony_citarget_include_directories(arkdisassembler 49b1994897Sopenharmony_ci PUBLIC ${CMAKE_CURRENT_BINARY_DIR} 50b1994897Sopenharmony_ci PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} 51b1994897Sopenharmony_ci PUBLIC ${CMAKE_SOURCE_DIR}/libpandabase 52b1994897Sopenharmony_ci PUBLIC ${CMAKE_BINARY_DIR}/libpandabase 53b1994897Sopenharmony_ci PUBLIC ${CMAKE_BINARY_DIR}/libpandafile/include 54b1994897Sopenharmony_ci) 55b1994897Sopenharmony_ci 56b1994897Sopenharmony_citarget_link_libraries(arkdisassembler arkfile arkbase arkassembler) 57b1994897Sopenharmony_ci 58b1994897Sopenharmony_citarget_link_libraries(ark_disasm arkdisassembler arkbase arkfile arkassembler) 59b1994897Sopenharmony_ci 60b1994897Sopenharmony_cipanda_add_to_clang_tidy(arkdisassembler) 61b1994897Sopenharmony_cipanda_add_to_clang_tidy(TARGET ark_disasm CHECKS 62b1994897Sopenharmony_ci "-cert-dcl21-cpp" 63b1994897Sopenharmony_ci "-cppcoreguidelines-macro-usage" 64b1994897Sopenharmony_ci "-google-runtime-references" 65b1994897Sopenharmony_ci "-misc-non-private-member-variables-in-classes" 66b1994897Sopenharmony_ci) 67b1994897Sopenharmony_ci 68b1994897Sopenharmony_cipanda_add_sanitizers(TARGET arkdisassembler SANITIZERS ${PANDA_SANITIZERS_LIST}) 69b1994897Sopenharmony_cipanda_add_sanitizers(TARGET ark_disasm SANITIZERS ${PANDA_SANITIZERS_LIST}) 70b1994897Sopenharmony_ci 71b1994897Sopenharmony_ciadd_check_style(".") 72b1994897Sopenharmony_ci 73b1994897Sopenharmony_ciif(NOT PANDA_WITH_TESTS) 74b1994897Sopenharmony_ci return() 75b1994897Sopenharmony_ciendif() 76b1994897Sopenharmony_ci 77b1994897Sopenharmony_ci# disasm_bin directory 78b1994897Sopenharmony_ciset(DISASM_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin) 79b1994897Sopenharmony_cifile(MAKE_DIRECTORY "${DISASM_BIN_DIR}") 80b1994897Sopenharmony_ci 81b1994897Sopenharmony_ci# disasm_tests directory 82b1994897Sopenharmony_ciset(DISASM_TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests/sources) 83b1994897Sopenharmony_ci 84b1994897Sopenharmony_ciset(FUNCTIONS_TEST_SRC ${CMAKE_CURRENT_BINARY_DIR}/functions_test.cpp) 85b1994897Sopenharmony_ciset(INSTRUCTIONS_TEST_SRC ${CMAKE_CURRENT_BINARY_DIR}/instructions_test.cpp) 86b1994897Sopenharmony_ciset(LABELS_TEST_SRC ${CMAKE_CURRENT_BINARY_DIR}/labels_test.cpp) 87b1994897Sopenharmony_ciset(LITERALS_TEST_SRC ${CMAKE_CURRENT_BINARY_DIR}/literals_test.cpp) 88b1994897Sopenharmony_ciset(METADATA_TEST_SRC ${CMAKE_CURRENT_BINARY_DIR}/metadata_test.cpp) 89b1994897Sopenharmony_ciset(RECORDS_TEST_SRC ${CMAKE_CURRENT_BINARY_DIR}/records_test.cpp) 90b1994897Sopenharmony_ci 91b1994897Sopenharmony_ciconfigure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/functions_test.cpp.in ${FUNCTIONS_TEST_SRC} @ONLY) 92b1994897Sopenharmony_ciconfigure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/instructions_test.cpp.in ${INSTRUCTIONS_TEST_SRC} @ONLY) 93b1994897Sopenharmony_ciconfigure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/labels_test.cpp.in ${LABELS_TEST_SRC} @ONLY) 94b1994897Sopenharmony_ciconfigure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/literals_test.cpp.in ${LITERALS_TEST_SRC} @ONLY) 95b1994897Sopenharmony_ciconfigure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/metadata_test.cpp.in ${METADATA_TEST_SRC} @ONLY) 96b1994897Sopenharmony_ciconfigure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/records_test.cpp.in ${RECORDS_TEST_SRC} @ONLY) 97b1994897Sopenharmony_ci 98b1994897Sopenharmony_ci 99b1994897Sopenharmony_cipanda_add_gtest( 100b1994897Sopenharmony_ci NAME disasm_tests 101b1994897Sopenharmony_ci SOURCES 102b1994897Sopenharmony_ci ${FUNCTIONS_TEST_SRC} 103b1994897Sopenharmony_ci ${INSTRUCTIONS_TEST_SRC} 104b1994897Sopenharmony_ci ${LABELS_TEST_SRC} 105b1994897Sopenharmony_ci ${LITERALS_TEST_SRC} 106b1994897Sopenharmony_ci ${METADATA_TEST_SRC} 107b1994897Sopenharmony_ci ${RECORDS_TEST_SRC} 108b1994897Sopenharmony_ci LIBRARIES 109b1994897Sopenharmony_ci arkbase arkassembler arkdisassembler arkfile 110b1994897Sopenharmony_ci SANITIZERS 111b1994897Sopenharmony_ci ${PANDA_SANITIZERS_LIST} 112b1994897Sopenharmony_ci) 113b1994897Sopenharmony_ci 114b1994897Sopenharmony_ci############################## 115b1994897Sopenharmony_ci 116b1994897Sopenharmony_ciif(CMAKE_CROSSCOMPILING) 117b1994897Sopenharmony_ci ExternalProject_Get_Property(panda_host_tools binary_dir) 118b1994897Sopenharmony_ci set(assembler_target panda_host_tools) 119b1994897Sopenharmony_ci set(assembler_bin "${binary_dir}/assembler/ark_asm") 120b1994897Sopenharmony_cielse() 121b1994897Sopenharmony_ci set(assembler_target ark_asm) 122b1994897Sopenharmony_ci set(assembler_bin $<TARGET_FILE:${assembler_target}>) 123b1994897Sopenharmony_ciendif() 124b1994897Sopenharmony_ci 125b1994897Sopenharmony_cifunction(compile_pre_build) 126b1994897Sopenharmony_ci set(options) 127b1994897Sopenharmony_ci set(singleValueArgs TARGET FILE_SRC FILE_DST) 128b1994897Sopenharmony_ci set(multiValueArgs) 129b1994897Sopenharmony_ci 130b1994897Sopenharmony_ci cmake_parse_arguments(CPB "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN}) 131b1994897Sopenharmony_ci 132b1994897Sopenharmony_ci if (NOT DEFINED CPB_TARGET) 133b1994897Sopenharmony_ci message(FATAL_ERROR "TARGET argument is missing") 134b1994897Sopenharmony_ci endif() 135b1994897Sopenharmony_ci 136b1994897Sopenharmony_ci if (NOT DEFINED CPB_FILE_SRC) 137b1994897Sopenharmony_ci message(FATAL_ERROR "FILE_SRC argument is missing") 138b1994897Sopenharmony_ci endif() 139b1994897Sopenharmony_ci 140b1994897Sopenharmony_ci if (NOT DEFINED CPB_FILE_DST) 141b1994897Sopenharmony_ci message(FATAL_ERROR "FILE_DST argument is missing") 142b1994897Sopenharmony_ci endif() 143b1994897Sopenharmony_ci 144b1994897Sopenharmony_ci add_custom_command(OUTPUT "${CPB_FILE_DST}" 145b1994897Sopenharmony_ci COMMENT "Compiling ${CPB_FILE_SRC} ( ${CPB_TARGET} ) in c_p_b function" 146b1994897Sopenharmony_ci COMMAND ${assembler_bin} "${CPB_FILE_SRC}" "${CPB_FILE_DST}" 147b1994897Sopenharmony_ci DEPENDS ${assembler_target} "${CPB_FILE_SRC}") 148b1994897Sopenharmony_ci 149b1994897Sopenharmony_ci add_custom_target(${CPB_TARGET} 150b1994897Sopenharmony_ci COMMENT "reached ${CPB_TARGET}" 151b1994897Sopenharmony_ci DEPENDS "${CPB_FILE_DST}") 152b1994897Sopenharmony_ciendfunction() 153b1994897Sopenharmony_ci 154b1994897Sopenharmony_ci# label_tests files 155b1994897Sopenharmony_cicompile_pre_build(TARGET disasm_binaries-labels1 156b1994897Sopenharmony_ci FILE_SRC ${DISASM_TESTS_DIR}/labels1.pa 157b1994897Sopenharmony_ci FILE_DST ${DISASM_BIN_DIR}/labels1.bc) 158b1994897Sopenharmony_cicompile_pre_build(TARGET disasm_binaries-labels2 159b1994897Sopenharmony_ci FILE_SRC ${DISASM_TESTS_DIR}/labels2.pa 160b1994897Sopenharmony_ci FILE_DST ${DISASM_BIN_DIR}/labels2.bc) 161b1994897Sopenharmony_cicompile_pre_build(TARGET disasm_binaries-exceptions 162b1994897Sopenharmony_ci FILE_SRC ${DISASM_TESTS_DIR}/exceptions.pa 163b1994897Sopenharmony_ci FILE_DST ${DISASM_BIN_DIR}/exceptions.bc) 164b1994897Sopenharmony_ci 165b1994897Sopenharmony_ciadd_dependencies(disasm_tests disasm_binaries-labels1) 166b1994897Sopenharmony_ciadd_dependencies(disasm_tests disasm_binaries-labels2) 167b1994897Sopenharmony_ciadd_dependencies(disasm_tests disasm_binaries-exceptions) 168b1994897Sopenharmony_ci 169b1994897Sopenharmony_ci# record_tests files 170b1994897Sopenharmony_cicompile_pre_build(TARGET disasm_binaries-record_with_fields 171b1994897Sopenharmony_ci FILE_SRC ${DISASM_TESTS_DIR}/record_with_fields.pa 172b1994897Sopenharmony_ci FILE_DST ${DISASM_BIN_DIR}/record_with_fields.bc) 173b1994897Sopenharmony_cicompile_pre_build(TARGET disasm_binaries-record_in_record 174b1994897Sopenharmony_ci FILE_SRC ${DISASM_TESTS_DIR}/record_in_record.pa 175b1994897Sopenharmony_ci FILE_DST ${DISASM_BIN_DIR}/record_in_record.bc) 176b1994897Sopenharmony_cicompile_pre_build(TARGET disasm_binaries-empty_record 177b1994897Sopenharmony_ci FILE_SRC ${DISASM_TESTS_DIR}/empty_record.pa 178b1994897Sopenharmony_ci FILE_DST ${DISASM_BIN_DIR}/empty_record.bc) 179b1994897Sopenharmony_ci 180b1994897Sopenharmony_ciadd_dependencies(disasm_tests disasm_binaries-record_with_fields) 181b1994897Sopenharmony_ciadd_dependencies(disasm_tests disasm_binaries-record_in_record) 182b1994897Sopenharmony_ciadd_dependencies(disasm_tests disasm_binaries-empty_record) 183b1994897Sopenharmony_ci 184b1994897Sopenharmony_ci# functions_tests files 185b1994897Sopenharmony_cicompile_pre_build(TARGET disasm_binaries-empty_function 186b1994897Sopenharmony_ci FILE_SRC ${DISASM_TESTS_DIR}/empty_function.pa 187b1994897Sopenharmony_ci FILE_DST ${DISASM_BIN_DIR}/empty_function.bc) 188b1994897Sopenharmony_cicompile_pre_build(TARGET disasm_binaries-overloading 189b1994897Sopenharmony_ci FILE_SRC ${DISASM_TESTS_DIR}/overloading.pa 190b1994897Sopenharmony_ci FILE_DST ${DISASM_BIN_DIR}/overloading.bc) 191b1994897Sopenharmony_ci 192b1994897Sopenharmony_ciadd_dependencies(disasm_tests disasm_binaries-empty_function) 193b1994897Sopenharmony_ciadd_dependencies(disasm_tests disasm_binaries-overloading) 194b1994897Sopenharmony_ci 195b1994897Sopenharmony_ci# instruction_tests files 196b1994897Sopenharmony_cicompile_pre_build(TARGET disasm_binaries-instructions 197b1994897Sopenharmony_ci FILE_SRC ${DISASM_TESTS_DIR}/instructions.pa 198b1994897Sopenharmony_ci FILE_DST ${DISASM_BIN_DIR}/instructions.bc) 199b1994897Sopenharmony_cicompile_pre_build(TARGET disasm_binaries-returns 200b1994897Sopenharmony_ci FILE_SRC ${DISASM_TESTS_DIR}/returns.pa 201b1994897Sopenharmony_ci FILE_DST ${DISASM_BIN_DIR}/returns.bc) 202b1994897Sopenharmony_cicompile_pre_build(TARGET disasm_binaries-calls 203b1994897Sopenharmony_ci FILE_SRC ${DISASM_TESTS_DIR}/calls.pa 204b1994897Sopenharmony_ci FILE_DST ${DISASM_BIN_DIR}/calls.bc) 205b1994897Sopenharmony_cicompile_pre_build(TARGET disasm_binaries-newarrs 206b1994897Sopenharmony_ci FILE_SRC ${DISASM_TESTS_DIR}/newarrs.pa 207b1994897Sopenharmony_ci FILE_DST ${DISASM_BIN_DIR}/newarrs.bc) 208b1994897Sopenharmony_ci 209b1994897Sopenharmony_ciadd_dependencies(disasm_tests disasm_binaries-instructions) 210b1994897Sopenharmony_ciadd_dependencies(disasm_tests disasm_binaries-returns) 211b1994897Sopenharmony_ciadd_dependencies(disasm_tests disasm_binaries-calls) 212b1994897Sopenharmony_ciadd_dependencies(disasm_tests disasm_binaries-newarrs) 213b1994897Sopenharmony_ci 214b1994897Sopenharmony_ci# metadata_tests files 215b1994897Sopenharmony_cicompile_pre_build(TARGET disasm_binaries-meta 216b1994897Sopenharmony_ci FILE_SRC ${DISASM_TESTS_DIR}/meta.pa 217b1994897Sopenharmony_ci FILE_DST ${DISASM_BIN_DIR}/meta.bc) 218b1994897Sopenharmony_ci 219b1994897Sopenharmony_ciadd_dependencies(disasm_tests disasm_binaries-meta) 220b1994897Sopenharmony_ci 221b1994897Sopenharmony_ci# literals_tests files 222b1994897Sopenharmony_cicompile_pre_build(TARGET disasm_binaries-literals 223b1994897Sopenharmony_ci FILE_SRC ${DISASM_TESTS_DIR}/literals.pa 224b1994897Sopenharmony_ci FILE_DST ${DISASM_BIN_DIR}/literals.bc) 225b1994897Sopenharmony_cicompile_pre_build(TARGET disasm_binaries-literals_same 226b1994897Sopenharmony_ci FILE_SRC ${DISASM_TESTS_DIR}/literals_same.pa 227b1994897Sopenharmony_ci FILE_DST ${DISASM_BIN_DIR}/literals_same.bc) 228b1994897Sopenharmony_ci 229b1994897Sopenharmony_ciadd_dependencies(disasm_tests disasm_binaries-literals) 230b1994897Sopenharmony_ciadd_dependencies(disasm_tests disasm_binaries-literals_same) 231b1994897Sopenharmony_ci 232b1994897Sopenharmony_ciadd_dependencies(arkdisassembler isa_gen_${PROJECT_NAME} type_to_pandasm_type_gen_${PROJECT_NAME}) 233b1994897Sopenharmony_ci 234b1994897Sopenharmony_ci############################## 235