Skip to content

Commit

Permalink
CMake: rework compiler component ASM defines
Browse files Browse the repository at this point in the history
Rework handling of defines for compiler so that it can handle
GNU assembler and NASM

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>
  • Loading branch information
dnakamura committed Nov 12, 2018
1 parent f3e25d9 commit ab2b85b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
48 changes: 47 additions & 1 deletion cmake/modules/OmrCompilerSupport.cmake
Expand Up @@ -245,6 +245,34 @@ function(omr_inject_object_modification_targets result compiler_name)
set(${result} ${arg} PARENT_SCOPE)
endfunction(omr_inject_object_modification_targets)

# make_gnu_asm_defines(output_var <define> ...)
# Make output_var a string which will define each <define>
# as an assembler define (rather than a c pre-processor define)
function(make_gnu_asm_defines output)

foreach(arg IN LISTS ARGN)
set(clean_arg)
string(REGEX REPLACE "^-D" "" clean_arg "${arg}")
# if clean_arg already is of form FOO=BAR, append it as is
# otherwise we change it to FOO=1
if(clean_arg MATCHES "=")
set(arg_str "${arg_str},--defsym,${clean_arg}")
else()
set(arg_str "${arg_str},--defsym,${clean_arg}=1")
endif()
endforeach()

if(OMR_ENV_DATA64)
set(arg_str ",--64${arg_str}")
endif()

# if we actually generated any string
# ie we were passed in any <define> values
if(arg_str)
set(${output} "-Wa${arg_str}" PARENT_SCOPE)
endif()
endfunction(make_gnu_asm_defines)

# Setup the current scope for compiling the Testarossa compiler technology. Used in
# conjunction with make_compiler_target -- Only can infect add_directory scope.
macro(set_tr_compile_options)
Expand All @@ -254,7 +282,25 @@ macro(set_tr_compile_options)
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} PARENT_SCOPE)
# message("[set_tr_compile_options] Set CMAKE_CXX_FLAGS to ${CMAKE_CXX_FLAGS}")
# message("[set_tr_compile_options] Set CMAKE_C_FLAGS to ${CMAKE_C_FLAGS}")
set(CMAKE_ASM_FLAGS ${TR_ASM_FLAGS} PARENT_SCOPE)

set(TR_ASM_FLAGS "")
foreach(def IN LISTS TR_COMPILE_DEFINITIONS)
# Prepend leading '-D' only if required
if(def MATCHES "^-D")
set(TR_ASM_FLAGS "${TR_ASM_FLAGS} ${def}")
else()
set(TR_ASM_FLAGS "${TR_ASM_FLAGS} -D${def}")
endif()
endforeach()

# We need special handling on x86 because we could be gnu or NASM assembler
if(OMR_ARCH_X86)
make_gnu_asm_defines(gnu_defines ${TR_COMPILE_DEFINITIONS})
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${gnu_defines}" PARENT_SCOPE)
set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} ${TR_ASM_FLAGS}" PARENT_SCOPE)
else()
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${TR_ASM_FLAGS}" PARENT_SCOPE)
endif()
endmacro(set_tr_compile_options)

# Create an OMR Compiler component
Expand Down
4 changes: 0 additions & 4 deletions cmake/modules/platform/arch/x86.cmake
Expand Up @@ -44,10 +44,6 @@ if(OMR_ENV_DATA64)

set(TR_HOST_SUBARCH amd64)
set(TR_HOST_BITS 64)
#TODO the asm flags only work for GNU right now.
if(CMAKE_ASM_COMPILER_ID STREQUAL "GNU")
set(TR_ASM_FLAGS "-Wa,--64,--defsym,TR_HOST_X86=1,--defsym,TR_HOST_64BIT=1,--defsym,BITVECTOR_64BIT=1,--defsym,LINUX=1,--defsym,TR_TARGET_X86=1,--defsym,TR_TARGET_64BIT=1")
endif()
else()
list(APPEND TR_COMPILE_DEFINITIONS -DTR_HOST_32BIT -DTR_TARGET_32BIT)

Expand Down

0 comments on commit ab2b85b

Please sign in to comment.