• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
14add_library(asm_defines defines.cpp)
15
16add_dependencies(asm_defines
17    type_gen_arkfile
18    isa_gen_arkfile
19    arkfile_gen
20    events_gen
21    logger_gen
22    intrinsics_gen_arkruntime
23    entrypoints_gen
24    runtime_language_context
25    shorty_values_gen_arkruntime
26    plugins_defines_h
27    plugins_asm_defines_def
28)
29
30set(GEN_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/../include")
31
32set(ASM_DIR ${CMAKE_CURRENT_BINARY_DIR})
33set(ASM_FILE libasm_defines.S)
34set(OUTPUT_FILE asm_defines.h)
35set(OUTPUT_DIR ${GEN_INCLUDE_DIR})
36file(MAKE_DIRECTORY ${OUTPUT_DIR})
37
38set_target_properties(asm_defines
39    PROPERTIES
40    ARCHIVE_OUTPUT_DIRECTORY ${ASM_DIR}
41    SUFFIX .S
42)
43
44target_include_directories(asm_defines
45    PUBLIC ${PANDA_ROOT}/runtime
46    PUBLIC ${PANDA_ROOT}
47    PUBLIC ${CMAKE_BINARY_DIR}/runtime/include
48    PUBLIC ${PANDA_BINARY_ROOT}/panda_gen_options
49    PUBLIC ${PANDA_BINARY_ROOT}/verification/gen/include
50    PUBLIC ${PANDA_ROOT}/libpandabase
51    PUBLIC ${PANDA_ROOT}/libpandafile
52    PUBLIC "$<TARGET_PROPERTY:c_secshared,INCLUDE_DIRECTORIES>"
53    PUBLIC ${PANDA_BINARY_ROOT}/libpandafile/include
54    PUBLIC ${PANDA_BINARY_ROOT}/libpandabase/generated
55)
56
57# We have to disable LTO, because it generates llvm IR instead of assembly for '-S' option.
58# Without this restriction, we can just use generator expressions and inherit compile flags from arkruntime (that looks
59# best way to do that):
60# target_compile_options(asm_defines
61#     PUBLIC "$<TARGET_PROPERTY:arkruntime,COMPILE_OPTIONS>"
62# )
63# But it seems that we can't remove options from the generator expressions.
64# (-fno-lto doesn't work because compilation fails with inappropriate regalloc)
65string(REPLACE "-mllvm -regalloc=${PANDA_LLVM_REGALLOC}" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
66string(REPLACE "-flto=thin" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
67target_compile_options(asm_defines PUBLIC "-Wno-attributes")
68target_compile_options(asm_defines PUBLIC "-Wno-invalid-offsetof")
69target_compile_options(asm_defines PUBLIC "-S")
70
71if (PANDA_TARGET_WINDOWS)
72    target_compile_options(asm_defines PUBLIC "-Wno-inconsistent-dllimport")
73endif()
74
75add_custom_command(OUTPUT ${OUTPUT_DIR}/${OUTPUT_FILE}
76    COMMAND ruby ${CMAKE_CURRENT_SOURCE_DIR}/defines_generator.rb "${ASM_DIR}/${ASM_FILE}" ${OUTPUT_DIR}/${OUTPUT_FILE}
77    DEPENDS asm_defines ${ASM_DIR}/${ASM_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/defines_generator.rb
78)
79
80add_custom_target(asm_defines_generator
81    DEPENDS ${OUTPUT_DIR}/${OUTPUT_FILE}
82)
83