diff options
author | dotnet-bot <dotnet-bot@microsoft.com> | 2015-01-30 14:14:42 -0800 |
---|---|---|
committer | dotnet-bot <dotnet-bot@microsoft.com> | 2015-01-30 14:14:42 -0800 |
commit | ef1e2ab328087c61a6878c1e84f4fc5d710aebce (patch) | |
tree | dee1bbb89e9d722e16b0d1485e3cdd1b6c8e2cfa /src/vm/h2inc.ps1 | |
download | coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.tar.gz coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.tar.bz2 coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.zip |
Initial commit to populate CoreCLR repo
[tfs-changeset: 1407945]
Diffstat (limited to 'src/vm/h2inc.ps1')
-rw-r--r-- | src/vm/h2inc.ps1 | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/vm/h2inc.ps1 b/src/vm/h2inc.ps1 new file mode 100644 index 0000000000..40dbe1d72c --- /dev/null +++ b/src/vm/h2inc.ps1 @@ -0,0 +1,65 @@ +# ==++== +# +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. +# +# ==--== + +# C to MASM include file translator +# This is replacement for the deprecated h2inc tool that used to be part of VS. + +Function ProcessFile($filePath) { + + Write-Output "// 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 + Write-Output "$name EQU $value" + } else { + Write-Output "$name TEXTEQU <$value>" + } + } + } + + Write-Output $_ + } + + Write-Output "// File end: $filePath" +} + +ProcessFile $args[0] |