diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index 4e68a9be01e8c9..c4af68ba7dc610 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -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 diff --git a/src/coreclr/vm/h2inc.pl b/src/coreclr/vm/h2inc.pl deleted file mode 100644 index 6d2e0c3e03dcf1..00000000000000 --- a/src/coreclr/vm/h2inc.pl +++ /dev/null @@ -1,61 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the MIT license. - -# C to MASM include file translator -# This is replacement for the deprecated h2inc tool that used to be part of VS. - -use File::Basename; - -sub ProcessFile($) { - my ($input_file) = @_; - - local *INPUT_FILE; - if (!open(INPUT_FILE, $input_file)) - { - print "#error: File can not be opened: $input_file\n"; - return; - } - - print ("// File start: $input_file\n"); - - while() { - # Skip all pragmas - if (m/^\s*#\s*pragma/) { - next; - } - - # Expand includes. - if (m/\s*#\s*include\s*\"(.+)\"/) { - ProcessFile(dirname($input_file) . "/" . $1); - next; - } - - # Augment #defines with their MASM equivalent - if (m/^\s*#\s*define\s+(\S+)\s+(.*)/) { - my $name = $1; - my $value = $2; - - # Note that we do not handle multiline constants - - # Strip comments from value - $value =~ s/\/\/.*//; - $value =~ s/\/\*.*\*\///g; - - # Strip whitespaces from value - $value =~ s/\s+$//; - - # ignore #defines with arguments - if (!($name =~ m/\(/)) { - my $number = 0; - $number |= ($value =~ s/\b0x(\w+)\b/0\1h/g); # Convert hex constants - $number |= ($value =~ s/(-?\b\d+\b)/\1t/g); # Convert dec constants - print $number ? "$name EQU $value\n" : "$name TEXTEQU <$value>\n"; - } - } - print; - } - - print ("// File end: $input_file\n"); -} - -ProcessFile($ARGV[0]); diff --git a/src/coreclr/vm/h2inc.ps1 b/src/coreclr/vm/h2inc.ps1 deleted file mode 100644 index f2c2c07f26582b..00000000000000 --- a/src/coreclr/vm/h2inc.ps1 +++ /dev/null @@ -1,69 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the MIT license. - -# C to MASM include file translator -# This is replacement for the deprecated h2inc tool that used to be part of VS. - -# -# The use of [console]::WriteLine (instead of Write-Output) is intentional. -# PowerShell 2.0 (installed by default on Windows 7) wraps lines written with -# Write-Output at whatever column width is being used by the current terminal, -# even when output is being redirected to a file. We can't have this behavior -# because it will cause the generated file to be malformed. -# - -Function ProcessFile($filePath) { - - [console]::WriteLine("// File start: $filePath") - - Get-Content $filePath | ForEach-Object { - - if ($_ -match "^\s*#\spragma") { - # Ignore pragmas - return - } - - if ($_ -match "^\s*#\s*include\s*`"(.*)`"") - { - # Expand includes. - ProcessFile(Join-Path (Split-Path -Parent $filePath) $Matches[1]) - return - } - - if ($_ -match "^\s*#define\s+(\S+)\s*(.*)") - { - # Augment #defines with their MASM equivalent - $name = $Matches[1] - $value = $Matches[2] - - # Note that we do not handle multiline constants - - # Strip comments from value - $value = $value -replace "//.*", "" - $value = $value -replace "/\*.*\*/", "" - - # Strip whitespaces from value - $value = $value -replace "\s+$", "" - - # ignore #defines with arguments - if ($name -notmatch "\(") { - $HEX_NUMBER_PATTERN = "\b0x(\w+)\b" - $DECIMAL_NUMBER_PATTERN = "(-?\b\d+\b)" - - if ($value -match $HEX_NUMBER_PATTERN -or $value -match $DECIMAL_NUMBER_PATTERN) { - $value = $value -replace $HEX_NUMBER_PATTERN, "0`$1h" # Convert hex constants - $value = $value -replace $DECIMAL_NUMBER_PATTERN, "`$1t" # Convert dec constants - [console]::WriteLine("$name EQU $value") - } else { - [console]::WriteLine("$name TEXTEQU <$value>") - } - } - } - - [console]::WriteLine("$_") - } - - [console]::WriteLine("// File end: $filePath") -} - -ProcessFile $args[0] diff --git a/src/coreclr/vm/wks/CMakeLists.txt b/src/coreclr/vm/wks/CMakeLists.txt index cb7ba8ca2cc997..b0113575c1e05e 100644 --- a/src/coreclr/vm/wks/CMakeLists.txt +++ b/src/coreclr/vm/wks/CMakeLists.txt @@ -26,7 +26,6 @@ add_dependencies(cee_wks_obj eventing_headers) add_dependencies(cee_wks_mergeable_obj eventing_headers) if (CLR_CMAKE_TARGET_WIN32) - if(NOT CLR_CMAKE_HOST_ARCH_ARM AND NOT CLR_CMAKE_HOST_ARCH_ARM64) if (CLR_CMAKE_HOST_ARCH_I386) @@ -34,33 +33,16 @@ 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() - - # 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" - ) + h2inc("${VM_DIR}/${ARCH_SOURCES_DIR}/asmconstants.h" "${CMAKE_CURRENT_BINARY_DIR}/AsmConstants.tmp") + preprocess_file("${CMAKE_CURRENT_BINARY_DIR}/AsmConstants.tmp" "${CMAKE_CURRENT_BINARY_DIR}/AsmConstants.inc") - set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/AsmConstants.inc PROPERTIES GENERATED TRUE) - - add_custom_target( - asmconstants_inc - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/AsmConstants.inc - ) + add_custom_target(asmconstants_inc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/AsmConstants.inc) add_dependencies(cee_wks_core asmconstants_inc) add_dependencies(cee_wks_obj asmconstants_inc) add_dependencies(cee_wks_mergeable_obj asmconstants_inc) endif(NOT CLR_CMAKE_HOST_ARCH_ARM AND NOT CLR_CMAKE_HOST_ARCH_ARM64) - endif (CLR_CMAKE_TARGET_WIN32) add_custom_target(precompiled_asm DEPENDS ${VM_WKS_ARCH_ASM_OBJECTS})