Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions eng/native/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,71 @@ function(clr_unknown_arch)
endif()
endfunction()

# C to MASM include file translator
# This is replacement for the deprecated h2inc tool that used to be part of VS.
function(h2inc filename output)
file(STRINGS ${filename} lines)
get_filename_component(path "${filename}" DIRECTORY)
file(RELATIVE_PATH relative_filename "${CLR_REPO_ROOT_DIR}" "${filename}")

file(APPEND "${output}" "// File start: ${relative_filename}\n")

# Use of NEWLINE_CONSUME is needed for lines with trailing backslash
file(STRINGS ${filename} contents NEWLINE_CONSUME)
string(REGEX REPLACE "\\\\\n" "\\\\\\\\ \n" contents "${contents}")
string(REGEX REPLACE "\n" ";" lines "${contents}")

foreach(line IN LISTS lines)
string(REGEX REPLACE "\\\\\\\\ " "\\\\" line "${line}")

if(line MATCHES "^ *# pragma")
# Ignore pragmas
continue()
endif()

if(line MATCHES "^ *# *include *\"(.*)\"")
# Expand includes.
h2inc("${path}/${CMAKE_MATCH_1}" "${output}")
continue()
endif()

if(line MATCHES "^ *#define +([0-9A-Za-z_()]+) *(.*)")
# Augment #defines with their MASM equivalent
set(name "${CMAKE_MATCH_1}")
set(value "${CMAKE_MATCH_2}")

# Note that we do not handle multiline constants

# Strip comments from value
string(REGEX REPLACE "//.*" "" value "${value}")
string(REGEX REPLACE "/\\*.*\\*/" "" value "${value}")

# Strip whitespaces from value
string(REPLACE " +$" "" value "${value}")

# ignore #defines with arguments
if(NOT "${name}" MATCHES "\\(")
set(HEX_NUMBER_PATTERN "0x([0-9A-Fa-f]+)")
set(DECIMAL_NUMBER_PATTERN "(-?[0-9]+)")

if("${value}" MATCHES "${HEX_NUMBER_PATTERN}")
string(REGEX REPLACE "${HEX_NUMBER_PATTERN}" "0\\1h" value "${value}") # Convert hex constants
file(APPEND "${output}" "${name} EQU ${value}\n")
elseif("${value}" MATCHES "${DECIMAL_NUMBER_PATTERN}" AND (NOT "${value}" MATCHES "[G-Zg-z]+" OR "${value}" MATCHES "\\("))
string(REGEX REPLACE "${DECIMAL_NUMBER_PATTERN}" "\\1t" value "${value}") # Convert dec constants
file(APPEND "${output}" "${name} EQU ${value}\n")
else()
file(APPEND "${output}" "${name} TEXTEQU <${value}>\n")
endif()
endif()
endif()

file(APPEND "${output}" "${line}\n")
endforeach()

file(APPEND "${output}" "// File end: ${relative_filename}\n")
endfunction()

# Build a list of compiler definitions by putting -D in front of each define.
function(get_compile_definitions DefinitionName)
# Get the current list of definitions
Expand Down
61 changes: 0 additions & 61 deletions src/coreclr/vm/h2inc.pl

This file was deleted.

69 changes: 0 additions & 69 deletions src/coreclr/vm/h2inc.ps1

This file was deleted.

7 changes: 2 additions & 5 deletions src/coreclr/vm/wks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,14 @@ if (CLR_CMAKE_TARGET_WIN32)
endif (CLR_CMAKE_HOST_ARCH_I386)

# Convert AsmConstants.h into AsmConstants.inc
find_program(POWERSHELL powershell)
if (POWERSHELL STREQUAL "POWERSHELL-NOTFOUND")
message(FATAL_ERROR "POWERSHELL not found")
endif()
h2inc("${VM_DIR}/${ARCH_SOURCES_DIR}/asmconstants.h" "${CMAKE_CURRENT_BINARY_DIR}/AsmConstants.tmp")

# Get the current list of definitions
get_compile_definitions(DEFINITIONS)

add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/AsmConstants.inc"
DEPENDS ${VM_DIR}/${ARCH_SOURCES_DIR}/asmconstants.h
COMMAND ${POWERSHELL} -NoProfile -ExecutionPolicy Bypass -NonInteractive \"& \"\"${VM_DIR}/h2inc.ps1\"\"\" \"\"\"${VM_DIR}/${ARCH_SOURCES_DIR}/asmconstants.h\"\"\" >"${CMAKE_CURRENT_BINARY_DIR}/AsmConstants.tmp"
COMMAND ${CMAKE_CXX_COMPILER} ${DEFINITIONS} /EP "${CMAKE_CURRENT_BINARY_DIR}/AsmConstants.tmp" >"${CMAKE_CURRENT_BINARY_DIR}/AsmConstants.inc"
)

Expand Down