blob: 40dbe1d72c37c57a9c088747fbd4fe213a53b5ee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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]
|