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(assembler CXX)
16b1994897Sopenharmony_ci
17b1994897Sopenharmony_cipanda_add_executable(ark_asm pandasm.cpp)
18b1994897Sopenharmony_ci
19b1994897Sopenharmony_ciset(PANDASM_BIN_TESTS ${CMAKE_CURRENT_BINARY_DIR}/tests)
20b1994897Sopenharmony_cifile(MAKE_DIRECTORY "${PANDASM_BIN_TESTS}")
21b1994897Sopenharmony_ci
22b1994897Sopenharmony_cipanda_isa_gen(
23b1994897Sopenharmony_ci    TEMPLATES
24b1994897Sopenharmony_ci        "isa.h.erb"
25b1994897Sopenharmony_ci        "function_collect_string.cpp.erb"
26b1994897Sopenharmony_ci        "ins_emit.h.erb"
27b1994897Sopenharmony_ci        "ins_to_string.cpp.erb"
28b1994897Sopenharmony_ci        "ins_create_api.h.erb"
29b1994897Sopenharmony_ci        "opcode_parsing.h.erb"
30b1994897Sopenharmony_ci        "operand_types_print.h.erb"
31b1994897Sopenharmony_ci    REQUIRES
32b1994897Sopenharmony_ci        "${CMAKE_CURRENT_SOURCE_DIR}/asm_isapi.rb"
33b1994897Sopenharmony_ci        "${PANDA_ROOT}/libpandafile/pandafile_isapi.rb"
34b1994897Sopenharmony_ci)
35b1994897Sopenharmony_ci
36b1994897Sopenharmony_ciset(SOURCES
37b1994897Sopenharmony_ci    lexer.cpp
38b1994897Sopenharmony_ci    annotation.cpp
39b1994897Sopenharmony_ci    assembly-emitter.cpp
40b1994897Sopenharmony_ci    assembly-parser.cpp
41b1994897Sopenharmony_ci    assembly-program.cpp
42b1994897Sopenharmony_ci    assembly-type.cpp
43b1994897Sopenharmony_ci    assembly-ins.cpp
44b1994897Sopenharmony_ci    context.cpp
45b1994897Sopenharmony_ci    meta.cpp
46b1994897Sopenharmony_ci    ins_to_string.cpp
47b1994897Sopenharmony_ci    extensions/extensions.cpp
48b1994897Sopenharmony_ci)
49b1994897Sopenharmony_ci
50b1994897Sopenharmony_ciset(META_GEN_H ${CMAKE_CURRENT_BINARY_DIR}/meta_gen.h)
51b1994897Sopenharmony_cipanda_gen_file(
52b1994897Sopenharmony_ci    DATAFILE ${CMAKE_CURRENT_SOURCE_DIR}/metadata.yaml
53b1994897Sopenharmony_ci    TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/templates/meta_gen.cpp.erb
54b1994897Sopenharmony_ci    OUTPUTFILE ${META_GEN_H}
55b1994897Sopenharmony_ci    REQUIRES ${CMAKE_CURRENT_SOURCE_DIR}/asm_metadata.rb
56b1994897Sopenharmony_ci)
57b1994897Sopenharmony_ciadd_custom_target(meta_gen_h DEPENDS ${META_GEN_H})
58b1994897Sopenharmony_ci
59b1994897Sopenharmony_ciadd_library(arkassembler ${PANDA_DEFAULT_LIB_TYPE} ${SOURCES})
60b1994897Sopenharmony_ciadd_dependencies(arkassembler
61b1994897Sopenharmony_ci    isa_gen_assembler
62b1994897Sopenharmony_ci    arkfile
63b1994897Sopenharmony_ci    meta_gen_h
64b1994897Sopenharmony_ci)
65b1994897Sopenharmony_ci
66b1994897Sopenharmony_citarget_include_directories(arkassembler PUBLIC
67b1994897Sopenharmony_ci    ${CMAKE_CURRENT_BINARY_DIR}
68b1994897Sopenharmony_ci    ${CMAKE_CURRENT_SOURCE_DIR}
69b1994897Sopenharmony_ci    ${CMAKE_BINARY_DIR}/libpandabase
70b1994897Sopenharmony_ci    ${PANDA_ROOT}
71b1994897Sopenharmony_ci)
72b1994897Sopenharmony_ci
73b1994897Sopenharmony_cipanda_add_to_clang_tidy(arkassembler)
74b1994897Sopenharmony_cipanda_add_to_clang_tidy(TARGET ark_asm CHECKS
75b1994897Sopenharmony_ci    "-cert-dcl21-cpp"
76b1994897Sopenharmony_ci    "-cppcoreguidelines-macro-usage"
77b1994897Sopenharmony_ci    "-google-runtime-references"
78b1994897Sopenharmony_ci    "-misc-non-private-member-variables-in-classes"
79b1994897Sopenharmony_ci)
80b1994897Sopenharmony_ci
81b1994897Sopenharmony_citarget_link_libraries(arkassembler arkfile)
82b1994897Sopenharmony_citarget_link_libraries(ark_asm arkassembler arkbase)
83b1994897Sopenharmony_ciif(PANDA_WITH_BYTECODE_OPTIMIZER)
84b1994897Sopenharmony_ci    target_link_libraries(ark_asm arkbytecodeopt)
85b1994897Sopenharmony_ciendif()
86b1994897Sopenharmony_ci
87b1994897Sopenharmony_ciinclude_directories(${PANDA_ROOT}/libpandabase/)
88b1994897Sopenharmony_ciinclude_directories(${CMAKE_BINARY_DIR}/libpandafile/include/)
89b1994897Sopenharmony_ci
90b1994897Sopenharmony_cipanda_add_gtest(
91b1994897Sopenharmony_ci    NAME assembler_tests
92b1994897Sopenharmony_ci    SOURCES
93b1994897Sopenharmony_ci        tests/lexer_test.cpp
94b1994897Sopenharmony_ci        tests/parser_test.cpp
95b1994897Sopenharmony_ci        tests/emitter_test.cpp
96b1994897Sopenharmony_ci        tests/mangling_tests.cpp
97b1994897Sopenharmony_ci    LIBRARIES
98b1994897Sopenharmony_ci        arkbase arkassembler
99b1994897Sopenharmony_ci    SANITIZERS
100b1994897Sopenharmony_ci        ${PANDA_SANITIZERS_LIST}
101b1994897Sopenharmony_ci)
102b1994897Sopenharmony_ciif(TARGET assembler_tests)
103b1994897Sopenharmony_ci    target_compile_options(assembler_tests PUBLIC "-Wno-ignored-attributes")
104b1994897Sopenharmony_ciendif()
105b1994897Sopenharmony_ci
106b1994897Sopenharmony_cipanda_add_sanitizers(TARGET arkassembler SANITIZERS ${PANDA_SANITIZERS_LIST})
107b1994897Sopenharmony_cipanda_add_sanitizers(TARGET ark_asm SANITIZERS ${PANDA_SANITIZERS_LIST})
108b1994897Sopenharmony_ci
109b1994897Sopenharmony_ci# TODO: remove after all components will use ark_asm instead of pandasm
110b1994897Sopenharmony_ciadd_custom_target(pandasm ALL
111b1994897Sopenharmony_ci                  COMMAND cd $<TARGET_FILE_DIR:ark_asm> && ${CMAKE_COMMAND} -E create_symlink $<TARGET_FILE_NAME:ark_asm> pandasm)
112b1994897Sopenharmony_ci
113b1994897Sopenharmony_ciadd_dependencies(pandasm ark_asm)
114b1994897Sopenharmony_ci
115b1994897Sopenharmony_ciadd_check_style(".")
116b1994897Sopenharmony_ci
117b1994897Sopenharmony_ciif (TARGET host_tools_depends)
118b1994897Sopenharmony_ci    add_dependencies(host_tools_depends arkassembler)
119b1994897Sopenharmony_ciendif()
120b1994897Sopenharmony_ci
121b1994897Sopenharmony_ciif (DEFINED PANDA_ROOT_BINARY_DIR)
122b1994897Sopenharmony_ci    # Special case for host tool build.
123b1994897Sopenharmony_ci    target_include_directories(arkassembler PUBLIC ${PANDA_ROOT_BINARY_DIR}/assembler)
124b1994897Sopenharmony_ciendif()
125b1994897Sopenharmony_ci
126b1994897Sopenharmony_ciif (PANDA_ENABLE_AFL)
127b1994897Sopenharmony_ci    include("${PANDA_ROOT}/fuzzing/Fuzzing.cmake")
128b1994897Sopenharmony_ci    panda_substitute_libs(TARGET arkassembler LIBS arkbase c_secshared arkfile)
129b1994897Sopenharmony_ciendif()
130