[69181] | 1 | # $Id: various.sed 104378 2024-04-19 14:43:14Z vboxsync $
|
---|
| 2 | ## @file
|
---|
| 3 | # Converts some C header elements into nasm/yasm syntax.
|
---|
| 4 | #
|
---|
[104378] | 5 | # This is used by 'incs' in /Maintenance.kmk (/Makefile.kmk) as well as the VMM
|
---|
| 6 | # for IEM headers.
|
---|
[69181] | 7 | #
|
---|
[20742] | 8 |
|
---|
[69181] | 9 | #
|
---|
[104378] | 10 | # Copyright (C) 2006-2024 Oracle and/or its affiliates.
|
---|
[69181] | 11 | #
|
---|
[96407] | 12 | # This file is part of VirtualBox base platform packages, as
|
---|
| 13 | # available from https://www.virtualbox.org.
|
---|
[69181] | 14 | #
|
---|
[96407] | 15 | # This program is free software; you can redistribute it and/or
|
---|
| 16 | # modify it under the terms of the GNU General Public License
|
---|
| 17 | # as published by the Free Software Foundation, in version 3 of the
|
---|
| 18 | # License.
|
---|
| 19 | #
|
---|
| 20 | # This program is distributed in the hope that it will be useful, but
|
---|
| 21 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 22 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 23 | # General Public License for more details.
|
---|
| 24 | #
|
---|
| 25 | # You should have received a copy of the GNU General Public License
|
---|
| 26 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 27 | #
|
---|
[69181] | 28 | # The contents of this file may alternatively be used under the terms
|
---|
| 29 | # of the Common Development and Distribution License Version 1.0
|
---|
[96407] | 30 | # (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
| 31 | # in the VirtualBox distribution, in which case the provisions of the
|
---|
[69181] | 32 | # CDDL are applicable instead of those of the GPL.
|
---|
| 33 | #
|
---|
| 34 | # You may elect to license modified versions of this file under the
|
---|
| 35 | # terms and conditions of either the GPL or the CDDL or both.
|
---|
| 36 | #
|
---|
[96407] | 37 | # SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
| 38 | #
|
---|
[69181] | 39 |
|
---|
[69202] | 40 | # Pass thru the file header and copyright.
|
---|
| 41 | 1,/^\#ifndef/{
|
---|
| 42 | /^\#ifndef/b next
|
---|
| 43 | s/^[/ ]//
|
---|
| 44 | s/^\*\//;/
|
---|
| 45 | s/\*/;/g
|
---|
| 46 | 4s/^.*$/; Automatically generated by various.sed. DO NOT EDIT!/
|
---|
| 47 | b end
|
---|
| 48 | }
|
---|
| 49 | :next
|
---|
[69181] | 50 |
|
---|
[104378] | 51 | # Check for block markers (typically in comments).
|
---|
| 52 | /ASM-NOINC-START/,/ASM-NOINC-END/ {
|
---|
| 53 | d
|
---|
| 54 | }
|
---|
[20742] | 55 |
|
---|
[47442] | 56 | # Newline escapes.
|
---|
| 57 | :check-newline-escape
|
---|
| 58 | /\\$/!bno-more-newline-escapes
|
---|
| 59 | N
|
---|
| 60 | b check-newline-escape
|
---|
| 61 | :no-more-newline-escapes
|
---|
| 62 |
|
---|
[104378] | 63 | # Check for line markers (typically in comments).
|
---|
| 64 | /ASM-INC/basm-inc
|
---|
| 65 | /ASM-NOINC/basm-noinc
|
---|
| 66 |
|
---|
| 67 | # Save the original line in the hold space for error reporting.
|
---|
| 68 | h
|
---|
| 69 |
|
---|
| 70 | # Strip comments.
|
---|
| 71 | /\/\*/!b strip_cpp_style_comment
|
---|
| 72 | :load_another_c_style_comment_line
|
---|
| 73 | /\*\//b strip_c_style_comment
|
---|
| 74 | N
|
---|
| 75 | b load_another_c_style_comment_line
|
---|
| 76 | :strip_c_style_comment
|
---|
| 77 | s/\/\*.*\*\// /g
|
---|
| 78 |
|
---|
| 79 | :strip_cpp_style_comment
|
---|
| 80 | s,//.*$, ,g
|
---|
| 81 |
|
---|
| 82 | # Strip trailing spaces
|
---|
[20742] | 83 | s/[[:space:]][[:space:]]*$//g
|
---|
| 84 |
|
---|
| 85 | # Try identify the statement.
|
---|
| 86 | /#[[:space:]]*define[[:space:]]/bdefine
|
---|
| 87 | /#[[:space:]]*ifdef[[:space:]]/bifdef
|
---|
| 88 | /#[[:space:]]*ifndef[[:space:]]/bifndef
|
---|
| 89 | /#[[:space:]]*if[[:space:]]/bif
|
---|
| 90 | /#[[:space:]]*elif[[:space:]]/belif
|
---|
| 91 | /#[[:space:]]*else$/belse
|
---|
| 92 | /#[[:space:]]*endif$/bendif
|
---|
| 93 |
|
---|
| 94 | # Not recognized, drop it.
|
---|
| 95 | :asm-noinc
|
---|
| 96 | d
|
---|
| 97 | b end
|
---|
| 98 |
|
---|
| 99 | #
|
---|
| 100 | # Defines needs some extra massaging to work in yasm.
|
---|
| 101 | # Things like trailing type indicators ('U', 'ULL' ++) does not go down well.
|
---|
| 102 | #
|
---|
| 103 | :define
|
---|
[20542] | 104 | /\$/d
|
---|
[20742] | 105 | s/#\([[:space:]]*\)define/\1%define/
|
---|
[20542] | 106 |
|
---|
[20742] | 107 | s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)U$/\1/
|
---|
| 108 | s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)U\([[:space:]]*\))$/\1\2)/
|
---|
| 109 | s/\([[:space:]][0-9][0-9]*\)U[[:space:]]*$/\1/
|
---|
| 110 | s/\([[:space:]][0-9][0-9]*\)U\([[:space:]]*\))$/\1\2)/
|
---|
| 111 |
|
---|
| 112 | s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)UL$/\1/
|
---|
| 113 | s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)UL\([[:space:]]*\))$/\1\2)/
|
---|
| 114 | s/\([[:space:]][0-9][0-9]*\)UL[[:space:]]*$/\1/
|
---|
| 115 | s/\([[:space:]][0-9][0-9]*\)UL\([[:space:]]*\))$/\1\2)/
|
---|
| 116 |
|
---|
| 117 | s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)ULL$/\1/
|
---|
| 118 | s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)ULL\([[:space:]]*\))$/\1\2)/
|
---|
| 119 | s/\([[:space:]][0-9][0-9]*\)ULL[[:space:]]*$/\1/
|
---|
| 120 | s/\([[:space:]][0-9][0-9]*\)ULL\([[:space:]]*\))$/\1\2)/
|
---|
| 121 |
|
---|
[30969] | 122 | s/UINT64_C([[:space:]]*\(0[xX][0-9a-fA-F][0-9a-fA-F]*\)[[:space:]]*)/\1/
|
---|
| 123 | s/UINT64_C([[:space:]]*\([0-9][0-9]*\)[[:space:]]*)/\1/
|
---|
[30736] | 124 | s/UINT32_C([[:space:]]*\(0[xX][0-9a-fA-F][0-9a-fA-F]*\)[[:space:]]*)/\1/
|
---|
| 125 | s/UINT32_C([[:space:]]*\([0-9][0-9]*\)[[:space:]]*)/\1/
|
---|
[30772] | 126 | s/UINT16_C([[:space:]]*\(0[xX][0-9a-fA-F][0-9a-fA-F]*\)[[:space:]]*)/\1/
|
---|
| 127 | s/UINT16_C([[:space:]]*\([0-9][0-9]*\)[[:space:]]*)/\1/
|
---|
| 128 | s/UINT8_C([[:space:]]*\(0[xX][0-9a-fA-F][0-9a-fA-F]*\)[[:space:]]*)/\1/
|
---|
| 129 | s/UINT8_C([[:space:]]*\([0-9][0-9]*\)[[:space:]]*)/\1/
|
---|
[30736] | 130 |
|
---|
[20742] | 131 | b end
|
---|
| 132 |
|
---|
| 133 | #
|
---|
| 134 | # Conditional statements, 1:1.
|
---|
| 135 | #
|
---|
| 136 | :ifdef
|
---|
| 137 | s/#\([[:space:]]*\)ifdef/\1%ifdef/
|
---|
| 138 | b end
|
---|
| 139 |
|
---|
[104378] | 140 |
|
---|
[20742] | 141 | :ifndef
|
---|
| 142 | s/#\([[:space:]]*\)ifndef/\1%ifndef/
|
---|
| 143 | b end
|
---|
| 144 |
|
---|
[104378] | 145 |
|
---|
[20742] | 146 | :if
|
---|
| 147 | s/#\([[:space:]]*\)if/\1%if/
|
---|
[104378] | 148 |
|
---|
| 149 | # Replace 'defined(DOXYGEN_RUNNING)' with '0' to simplify subsequent matching to '[0]' when we mean 'defined[(]DOXYGEN_RUNNING[)]'.
|
---|
| 150 | s/defined[(]DOXYGEN_RUNNING[)]/0/
|
---|
| 151 |
|
---|
| 152 | # Simplify stuff that was turned into '0' in the previous step (or in the input file).
|
---|
| 153 | s/||[[:space:]]*0[[:space:]]*$//g
|
---|
| 154 | s/||[[:space:]]*0\([[:space:]|&]\)/\1/g
|
---|
| 155 | s/\([[:space:]|&]\)0[[:space:]]*||/\1/g
|
---|
| 156 | s/[[:space:]][[:space:]]*$//
|
---|
| 157 |
|
---|
| 158 | # Convert #if [!]defined(xxxx) into %if[n]def xxxx
|
---|
| 159 | s/%if[[:space:]][[:space:]]*defined[(]\([^)][^)]*\)[)]$/%ifdef \1/
|
---|
| 160 | s/%if[[:space:]][[:space:]]*[!][[:space:]]*defined[(]\([^)][^)]*\)[)]$/%ifndef \1/
|
---|
| 161 |
|
---|
| 162 | # Convert '#if ... && 0' and '#if 0 && ...' to %if 0
|
---|
| 163 | s/%if[[:space:]].*&&[[:space:]]*00*$/%if 0/
|
---|
| 164 | s/%if[[:space:]][[:space:]]*00*[[:space:]]*&&$/%if 0/
|
---|
| 165 |
|
---|
| 166 | # Convert '#if ... || 1' and '#if 1 || ...' to '%if 1'
|
---|
| 167 | s/%if[[:space:]].*||[[:space:]]*1[0-9]*$/%if 1/
|
---|
| 168 | s/%if[[:space:]][[:space:]]*1[0-9]*[[:space:]]*||$/%if 1/
|
---|
| 169 |
|
---|
| 170 | /defined/b defined_error
|
---|
[20742] | 171 | b end
|
---|
| 172 |
|
---|
[104378] | 173 |
|
---|
[20742] | 174 | :elif
|
---|
| 175 | s/#\([[:space:]]*\)elif/\1%elif/
|
---|
[104378] | 176 |
|
---|
| 177 | # Replace 'defined(DOXYGEN_RUNNING)' with '0' to simplify subsequent matching to '[0]' when we mean 'defined[(]DOXYGEN_RUNNING[)]'.
|
---|
| 178 | s/defined[(]DOXYGEN_RUNNING[)]/0/
|
---|
| 179 |
|
---|
| 180 | # Simplify stuff that was turned into '0' in the previous step (or in the input file).
|
---|
| 181 | s/||[[:space:]]*0[[:space:]]*$//g
|
---|
| 182 | s/||[[:space:]]*0\([[:space:]|&]\)/\1/g
|
---|
| 183 | s/\([[:space:]|&]\)0[[:space:]]*||/\1/g
|
---|
| 184 | s/[[:space:]][[:space:]]*$//
|
---|
| 185 |
|
---|
| 186 | # Convert #if [!]defined(xxxx) into %if[n]def xxxx
|
---|
| 187 | s/%elif[[:space:]][[:space:]]*defined[(]\([^)][^)]*\)[)]$/%elifdef \1/
|
---|
| 188 | s/%elif[[:space:]][[:space:]]*[!][[:space:]]*defined[(]\([^)][^)]*\)[)]$/%elifndef \1/
|
---|
| 189 |
|
---|
| 190 | # Convert '#elif ... && 0' and '#elif 0 && ...' to '%elif 0'
|
---|
| 191 | s/%elif[[:space:]].*&&[[:space:]]*00*$/%elif 0/
|
---|
| 192 | s/%elif[[:space:]][[:space:]]*00*[[:space:]]*&&$/%elif 0/
|
---|
| 193 |
|
---|
| 194 | # Convert '#elif ... || 1' and '#elif 1 || ...' to '%elif 1'
|
---|
| 195 | s/%elif[[:space:]].*||[[:space:]]*1[0-9]*$/%elif 1/
|
---|
| 196 | s/%elif[[:space:]][[:space:]]*1[0-9]*[[:space:]]*||$/%elif 1/
|
---|
| 197 |
|
---|
| 198 | /defined/b defined_error
|
---|
[20742] | 199 | b end
|
---|
| 200 |
|
---|
[104378] | 201 |
|
---|
[20742] | 202 | :else
|
---|
| 203 | s/#\([[:space:]]*\)else.*$/\1%else/
|
---|
| 204 | b end
|
---|
| 205 |
|
---|
[104378] | 206 |
|
---|
[20742] | 207 | :endif
|
---|
| 208 | s/#\([[:space:]]*\)endif.*$/\1%endif/
|
---|
| 209 | b end
|
---|
| 210 |
|
---|
[104378] | 211 |
|
---|
| 212 | :defined_error
|
---|
| 213 | x
|
---|
| 214 | s/^/error: yasm & nasm does not grok 'defined': /
|
---|
| 215 | p
|
---|
| 216 | x
|
---|
| 217 | s/^/info: state: /
|
---|
| 218 | q1
|
---|
| 219 |
|
---|
| 220 |
|
---|
[20742] | 221 | #
|
---|
[104378] | 222 | # Assembly statement inside a C-style comment.
|
---|
[20742] | 223 | #
|
---|
| 224 | :asm-inc
|
---|
[104378] | 225 | /\/\*[[:space:]]*ASM-INC:.*\*\//b asm-inc-c-style-oneliner
|
---|
| 226 | /\/\/[[:space:]]*ASM-INC:/b asm-inc-cpp-style-oneliner
|
---|
| 227 | /\/\*[[:space:]]*ASM-INC/b asm-inc-c-style-block
|
---|
| 228 | s/^/error: unknown ASM-INC form: /
|
---|
| 229 | q1
|
---|
| 230 |
|
---|
| 231 | # /* ASM-INC: %include "whatever.mac" */
|
---|
| 232 | :asm-inc-c-style-oneliner
|
---|
| 233 | s/[[:space:]]*\/\*[[:space:]][[:space:]]*ASM-INC:[[:space:]]*\(.*\)[[:space:]]*\*\//\1/
|
---|
[20742] | 234 | b end
|
---|
| 235 |
|
---|
[104378] | 236 | # // ASM-INC: %include "whatever.mac"
|
---|
| 237 | :asm-inc-cpp-style-oneliner
|
---|
| 238 | s/[[:space:]]*\/\/[[:space:]][[:space:]]*ASM-INC:[[:space:]]*\(.*\)[[:space:]]*$/\1/
|
---|
| 239 | b end
|
---|
| 240 |
|
---|
| 241 | # /* ASM-INC
|
---|
| 242 | # %include "whatever.mac"
|
---|
| 243 | # */
|
---|
| 244 | :asm-inc-c-style-block
|
---|
| 245 | s/.*$//
|
---|
| 246 | :asm-inc-c-style-block-next
|
---|
| 247 | h
|
---|
| 248 | N
|
---|
| 249 | /\*\//!b asm-inc-c-style-block-next
|
---|
| 250 | x
|
---|
| 251 | b end
|
---|
| 252 |
|
---|
| 253 |
|
---|
[20742] | 254 | :end
|
---|
| 255 |
|
---|