Skip to content

Commit

Permalink
Merge pull request #3128 from dnakamura/m4_asm
Browse files Browse the repository at this point in the history
CMake: Add j9vm_gen_asm function
  • Loading branch information
pshipton authored Oct 3, 2018
2 parents 9ee0c57 + 2af3f22 commit 47c4910
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 35 deletions.
2 changes: 1 addition & 1 deletion runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ include(OmrTracegen)

include(cmake/build_tags.cmake)
include(cmake/compiler_config.cmake)
include(cmake/J9vmGenAsm.cmake)

###
### Various configuration
Expand Down Expand Up @@ -129,7 +130,6 @@ add_custom_target(j9vm_m4gen
"${CMAKE_CURRENT_BINARY_DIR}/j9vm/generated.h"
)


###
### Helper interface libraries
###
Expand Down
54 changes: 54 additions & 0 deletions runtime/cmake/J9vmGenAsm.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
################################################################################
# Copyright (c) 2018, 2018 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
# distribution and is available at https://www.eclipse.org/legal/epl-2.0/
# or the Apache License, Version 2.0 which accompanies this distribution and
# is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# This Source Code may also be made available under the following
# Secondary Licenses when the conditions for such availability set
# forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
# General Public License, version 2 with the GNU Classpath
# Exception [1] and GNU General Public License, version 2 with the
# OpenJDK Assembly Exception [2].
#
# [1] https://www.gnu.org/software/classpath/license.html
# [2] http://openjdk.java.net/legal/assembly-exception.html
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
################################################################################

# Include once
if(COMMAND j9vm_gen_asm)
return()
endif()

# Helper function for generating assembly from m4
# usage: j9vm_gen_asm(some_file.m4 ....)
# converts 'some_file.m4' into 'some_file.s'.
# Note: path is interpreted relative to CMAKE_CURRENT_SOURCE_DIR
# .s file is put in CMAKE_CURRENT_BINARY_DIR
# Directory names from the input are ignored. IE. foo/bar.m4 > bar.s
function(j9vm_gen_asm)
set(m4_defines "")
if(OMR_HOST_OS STREQUAL "linux")
set(m4_defines "-DLINUX")
elseif(OMR_HOST_OS STREQUAL "osx")
set(m4_defines "-DOSX")
endif()
#TODO need to add other platforms here

foreach(m4_file IN LISTS ARGN)
get_filename_component(base_name "${m4_file}" NAME_WE)

add_custom_command(
OUTPUT ${base_name}.s
DEPENDS ${m4_file} run_constgen
COMMAND m4 -I "${j9vm_SOURCE_DIR}/oti" ${m4_defines} ${CMAKE_CURRENT_SOURCE_DIR}/${m4_file} > ${base_name}.s
)
endforeach()


endfunction(j9vm_gen_asm)
12 changes: 2 additions & 10 deletions runtime/codert_vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,14 @@ target_include_directories(j9codert_vm
)

if(OMR_ARCH_X86)
add_custom_command(
OUTPUT xnathelp.s
DEPENDS xnathelp.m4 run_constgen
COMMAND m4 -I${CMAKE_CURRENT_SOURCE_DIR}/../oti ${CMAKE_CURRENT_SOURCE_DIR}/xnathelp.m4 > xnathelp.s
)
j9vm_gen_asm(xnathelp.m4)

# conditionalize this in the future
target_sources(j9codert_vm PRIVATE
xnathelp.s
)
elseif(OMR_ARCH_POWER)
add_custom_command(
OUTPUT pnathelp.s
DEPENDS pnathelp.m4 run_constgen
COMMAND m4 -I${CMAKE_CURRENT_SOURCE_DIR}/../oti ${CMAKE_CURRENT_SOURCE_DIR}/pnathelp.m4 > pnathelp.s
)
j9vm_gen_asm(pnathelp.m4)

# conditionalize this in the future
target_sources(j9codert_vm PRIVATE
Expand Down
6 changes: 1 addition & 5 deletions runtime/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ add_tracegen(vmutil.tdf j9vmutil)
add_tracegen(module.tdf)
add_tracegen(srphashtable.tdf)

j9vm_gen_asm(fpusup.m4)

add_custom_command(
OUTPUT fpusup.s
DEPENDS fpusup.m4 run_constgen
COMMAND m4 -I${CMAKE_CURRENT_SOURCE_DIR}/../oti ${CMAKE_CURRENT_SOURCE_DIR}/fpusup.m4 > fpusup.s
)
add_library(j9util STATIC
alignedmemcpy.c
annhelp.c
Expand Down
35 changes: 16 additions & 19 deletions runtime/vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,33 +125,30 @@ add_library(j9vm SHARED
${CMAKE_CURRENT_BINARY_DIR}/ut_j9vm.c
)

#hacks for M4 stuff
#TODO we should be detecting m4 properly
#also we probably need to fix up the path dir separators for windows

if(OMR_ARCH_X86)
add_custom_command( OUTPUT xcinterp.s
DEPENDS xcinterp.m4 run_constgen
COMMAND m4 -I ${CMAKE_CURRENT_SOURCE_DIR}/../oti ${CMAKE_CURRENT_SOURCE_DIR}/xcinterp.m4 > xcinterp.s
)
add_custom_command(OUTPUT stackswap.s
DEPENDS xa64/stackswap.m4 run_constgen
COMMAND m4 -I ${CMAKE_CURRENT_SOURCE_DIR}/../oti ${CMAKE_CURRENT_SOURCE_DIR}/xa64/stackswap.m4 > stackswap.s
)
add_custom_command(OUTPUT unsafeHelper.s
DEPENDS xa64/unsafeHelper.m4 run_constgen
COMMAND m4 -I ${CMAKE_CURRENT_SOURCE_DIR}/../oti ${CMAKE_CURRENT_SOURCE_DIR}/xa64/unsafeHelper.m4 > unsafeHelper.s
)
j9vm_gen_asm(xcinterp.m4)

if(OMR_ENV_DATA64)
j9vm_gen_asm(
xa64/stackswap.m4
xa64/unsafeHelper.m4
)
else()
message(SEND_ERROR "x86-32 is not currently supported")
endif()
target_sources(j9vm
PRIVATE
unsafeHelper.s
xcinterp.s
stackswap.s
)
elseif(OMR_ARCH_POWER) #TODO check linux and 64bit
add_custom_command( OUTPUT pcinterp.s
DEPENDS pcinterp.m4 run_constgen
COMMAND m4 -I ${CMAKE_CURRENT_SOURCE_DIR}/../oti ${CMAKE_CURRENT_SOURCE_DIR}/pcinterp.m4 > pcinterp.s
)
j9vm_gen_asm(pcinterp.m4)

if(NOT (OMR_ENV_DATA64 AND OMR_ENV_LITTLE_ENDIAN))
message(SEND_ERROR "Only PPC64 LE is currently supported")
endif()
target_sources(j9vm
PRIVATE
xl64/unsafeHelper.s
Expand Down

0 comments on commit 47c4910

Please sign in to comment.