1# Copyright (c) 2021-2022 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14cmake_minimum_required(VERSION 3.3.2 FATAL_ERROR) 15project(assembler CXX) 16 17panda_add_executable(ark_asm pandasm.cpp) 18 19set(PANDASM_BIN_TESTS ${CMAKE_CURRENT_BINARY_DIR}/tests) 20file(MAKE_DIRECTORY "${PANDASM_BIN_TESTS}") 21 22panda_isa_gen( 23 TEMPLATES 24 "isa.h.erb" 25 "ins_emit.h.erb" 26 "ins_to_string.cpp.erb" 27 "ins_create_api.h.erb" 28 "opcode_parsing.h.erb" 29 "operand_types_print.h.erb" 30 REQUIRES 31 "${CMAKE_CURRENT_SOURCE_DIR}/asm_isapi.rb" 32 "${PANDA_ROOT}/libpandafile/pandafile_isapi.rb" 33) 34 35set(SOURCES 36 lexer.cpp 37 annotation.cpp 38 assembly-emitter.cpp 39 assembly-parser.cpp 40 assembly-program.cpp 41 assembly-type.cpp 42 assembly-ins.cpp 43 context.cpp 44 meta.cpp 45 ins_to_string.cpp 46 extensions/extensions.cpp 47) 48 49set(META_GEN_H ${CMAKE_CURRENT_BINARY_DIR}/meta_gen.h) 50panda_gen_file( 51 DATAFILE ${CMAKE_CURRENT_SOURCE_DIR}/metadata.yaml 52 TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/templates/meta_gen.cpp.erb 53 OUTPUTFILE ${META_GEN_H} 54 REQUIRES ${CMAKE_CURRENT_SOURCE_DIR}/asm_metadata.rb 55) 56add_custom_target(meta_gen_h DEPENDS ${META_GEN_H}) 57 58add_library(arkassembler ${PANDA_DEFAULT_LIB_TYPE} ${SOURCES}) 59add_dependencies(arkassembler 60 isa_gen_assembler 61 arkfile 62 meta_gen_h 63) 64 65target_include_directories(arkassembler PUBLIC 66 ${CMAKE_CURRENT_BINARY_DIR} 67 ${CMAKE_CURRENT_SOURCE_DIR} 68 ${CMAKE_BINARY_DIR}/libpandabase 69 ${PANDA_ROOT} 70) 71 72panda_add_to_clang_tidy(arkassembler) 73panda_add_to_clang_tidy(TARGET ark_asm CHECKS 74 "-cert-dcl21-cpp" 75 "-cppcoreguidelines-macro-usage" 76 "-google-runtime-references" 77 "-misc-non-private-member-variables-in-classes" 78) 79 80target_link_libraries(arkassembler arkfile) 81target_link_libraries(ark_asm arkassembler arkbase) 82if(PANDA_WITH_BYTECODE_OPTIMIZER) 83 target_link_libraries(ark_asm arkbytecodeopt) 84endif() 85 86include_directories(${PANDA_ROOT}/libpandabase/) 87include_directories(${CMAKE_BINARY_DIR}/libpandafile/include/) 88 89panda_add_gtest( 90 NAME assembler_tests 91 SOURCES 92 tests/lexer_test.cpp 93 tests/parser_test.cpp 94 tests/emitter_test.cpp 95 tests/mangling_tests.cpp 96 LIBRARIES 97 arkbase arkassembler 98 SANITIZERS 99 ${PANDA_SANITIZERS_LIST} 100) 101if(TARGET assembler_tests) 102 target_compile_options(assembler_tests PUBLIC "-Wno-ignored-attributes") 103endif() 104 105panda_add_sanitizers(TARGET arkassembler SANITIZERS ${PANDA_SANITIZERS_LIST}) 106panda_add_sanitizers(TARGET ark_asm SANITIZERS ${PANDA_SANITIZERS_LIST}) 107 108# TODO: remove after all components will use ark_asm instead of pandasm 109add_custom_target(pandasm ALL 110 COMMAND cd $<TARGET_FILE_DIR:ark_asm> && ${CMAKE_COMMAND} -E create_symlink $<TARGET_FILE_NAME:ark_asm> pandasm) 111 112add_dependencies(pandasm ark_asm) 113 114add_check_style(".") 115 116if (TARGET host_tools_depends) 117 add_dependencies(host_tools_depends arkassembler) 118endif() 119 120if (DEFINED PANDA_ROOT_BINARY_DIR) 121 # Special case for host tool build. 122 target_include_directories(arkassembler PUBLIC ${PANDA_ROOT_BINARY_DIR}/assembler) 123endif() 124 125if (PANDA_ENABLE_AFL) 126 include("${PANDA_ROOT}/fuzzing/Fuzzing.cmake") 127 panda_substitute_libs(TARGET arkassembler LIBS arkbase c_secshared arkfile) 128endif() 129