VirtualBox

source: vbox/trunk/include/VBox/various.sed@ 106165

Last change on this file since 106165 was 106033, checked in by vboxsync, 2 months ago

VBox/various.sed: Ignore the \r in \r\n when on unixy hosts. Fixes building the recompiler on linux from a windows svn checkout. bugref:10653 bugref:10370

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 KB
Line 
1# $Id: various.sed 106033 2024-09-12 13:26:05Z vboxsync $
2## @file
3# Converts some C header elements into nasm/yasm syntax.
4#
5# This is used by 'incs' in /Maintenance.kmk (/Makefile.kmk) as well as the VMM
6# for IEM headers.
7#
8
9#
10# Copyright (C) 2006-2024 Oracle and/or its affiliates.
11#
12# This file is part of VirtualBox base platform packages, as
13# available from https://www.virtualbox.org.
14#
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#
28# The contents of this file may alternatively be used under the terms
29# of the Common Development and Distribution License Version 1.0
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
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#
37# SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
38#
39
40# Convert \r\n -> \n if running a windows checkout with unix tools (IEM).
41s/[\r]$//
42
43# Pass thru the file header and copyright.
441,/^\#ifndef/{
45/^\#ifndef/b next
46s/^[/ ]//
47s/^\*\//;/
48s/\*/;/g
494s/^.*$/; Automatically generated by various.sed. DO NOT EDIT!/
50b end
51}
52:next
53
54# Check for block markers (typically in comments).
55/ASM-NOINC-START/,/ASM-NOINC-END/ {
56 d
57}
58
59# Newline escapes.
60:check-newline-escape
61/\\$/!bno-more-newline-escapes
62N
63s/[\r]$//
64b check-newline-escape
65:no-more-newline-escapes
66
67# Check for line markers (typically in comments).
68/ASM-INC/basm-inc
69/ASM-NOINC/basm-noinc
70
71# Save the original line in the hold space for error reporting.
72h
73
74# Strip comments.
75/\/\*/!b strip_cpp_style_comment
76:load_another_c_style_comment_line
77/\*\//b strip_c_style_comment
78N
79s/[\r]$//
80b load_another_c_style_comment_line
81:strip_c_style_comment
82s/\/\*.*\*\// /g
83
84:strip_cpp_style_comment
85s,//.*$, ,g
86
87# Strip trailing spaces
88s/[[:space:]][[:space:]]*$//g
89
90# Try identify the statement.
91/#[[:space:]]*define[[:space:]]/bdefine
92/#[[:space:]]*ifdef[[:space:]]/bifdef
93/#[[:space:]]*ifndef[[:space:]]/bifndef
94/#[[:space:]]*if[[:space:]]/bif
95/#[[:space:]]*elif[[:space:]]/belif
96/#[[:space:]]*else$/belse
97/#[[:space:]]*endif$/bendif
98
99# Not recognized, drop it.
100:asm-noinc
101d
102b end
103
104#
105# Defines needs some extra massaging to work in yasm.
106# Things like trailing type indicators ('U', 'ULL' ++) does not go down well.
107#
108:define
109/\$/d
110s/#\([[:space:]]*\)define/\1%define/
111
112s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)U$/\1/
113s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)U\([[:space:]]*\))$/\1\2)/
114s/\([[:space:]][0-9][0-9]*\)U[[:space:]]*$/\1/
115s/\([[:space:]][0-9][0-9]*\)U\([[:space:]]*\))$/\1\2)/
116
117s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)UL$/\1/
118s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)UL\([[:space:]]*\))$/\1\2)/
119s/\([[:space:]][0-9][0-9]*\)UL[[:space:]]*$/\1/
120s/\([[:space:]][0-9][0-9]*\)UL\([[:space:]]*\))$/\1\2)/
121
122s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)ULL$/\1/
123s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)ULL\([[:space:]]*\))$/\1\2)/
124s/\([[:space:]][0-9][0-9]*\)ULL[[:space:]]*$/\1/
125s/\([[:space:]][0-9][0-9]*\)ULL\([[:space:]]*\))$/\1\2)/
126
127s/UINT64_C([[:space:]]*\(0[xX][0-9a-fA-F][0-9a-fA-F]*\)[[:space:]]*)/\1/
128s/UINT64_C([[:space:]]*\([0-9][0-9]*\)[[:space:]]*)/\1/
129s/UINT32_C([[:space:]]*\(0[xX][0-9a-fA-F][0-9a-fA-F]*\)[[:space:]]*)/\1/
130s/UINT32_C([[:space:]]*\([0-9][0-9]*\)[[:space:]]*)/\1/
131s/UINT16_C([[:space:]]*\(0[xX][0-9a-fA-F][0-9a-fA-F]*\)[[:space:]]*)/\1/
132s/UINT16_C([[:space:]]*\([0-9][0-9]*\)[[:space:]]*)/\1/
133s/UINT8_C([[:space:]]*\(0[xX][0-9a-fA-F][0-9a-fA-F]*\)[[:space:]]*)/\1/
134s/UINT8_C([[:space:]]*\([0-9][0-9]*\)[[:space:]]*)/\1/
135
136b end
137
138#
139# Conditional statements, 1:1.
140#
141:ifdef
142s/#\([[:space:]]*\)ifdef/\1%ifdef/
143b end
144
145
146:ifndef
147s/#\([[:space:]]*\)ifndef/\1%ifndef/
148b end
149
150
151:if
152s/#\([[:space:]]*\)if/\1%if/
153
154# Replace 'defined(DOXYGEN_RUNNING)' with '0' to simplify subsequent matching to '[0]' when we mean 'defined[(]DOXYGEN_RUNNING[)]'.
155s/defined[(]DOXYGEN_RUNNING[)]/0/
156
157# Simplify stuff that was turned into '0' in the previous step (or in the input file).
158s/||[[:space:]]*0[[:space:]]*$//g
159s/||[[:space:]]*0\([[:space:]|&]\)/\1/g
160s/\([[:space:]|&]\)0[[:space:]]*||/\1/g
161s/[[:space:]][[:space:]]*$//
162
163# Convert #if [!]defined(xxxx) into %if[n]def xxxx
164s/%if[[:space:]][[:space:]]*defined[(]\([^)][^)]*\)[)]$/%ifdef \1/
165s/%if[[:space:]][[:space:]]*[!][[:space:]]*defined[(]\([^)][^)]*\)[)]$/%ifndef \1/
166
167# Convert '#if ... && 0' and '#if 0 && ...' to %if 0
168s/%if[[:space:]].*&&[[:space:]]*00*$/%if 0/
169s/%if[[:space:]][[:space:]]*00*[[:space:]]*&&$/%if 0/
170
171# Convert '#if ... || 1' and '#if 1 || ...' to '%if 1'
172s/%if[[:space:]].*||[[:space:]]*1[0-9]*$/%if 1/
173s/%if[[:space:]][[:space:]]*1[0-9]*[[:space:]]*||$/%if 1/
174
175/defined/b defined_error
176b end
177
178
179:elif
180s/#\([[:space:]]*\)elif/\1%elif/
181
182# Replace 'defined(DOXYGEN_RUNNING)' with '0' to simplify subsequent matching to '[0]' when we mean 'defined[(]DOXYGEN_RUNNING[)]'.
183s/defined[(]DOXYGEN_RUNNING[)]/0/
184
185# Simplify stuff that was turned into '0' in the previous step (or in the input file).
186s/||[[:space:]]*0[[:space:]]*$//g
187s/||[[:space:]]*0\([[:space:]|&]\)/\1/g
188s/\([[:space:]|&]\)0[[:space:]]*||/\1/g
189s/[[:space:]][[:space:]]*$//
190
191# Convert #if [!]defined(xxxx) into %if[n]def xxxx
192s/%elif[[:space:]][[:space:]]*defined[(]\([^)][^)]*\)[)]$/%elifdef \1/
193s/%elif[[:space:]][[:space:]]*[!][[:space:]]*defined[(]\([^)][^)]*\)[)]$/%elifndef \1/
194
195# Convert '#elif ... && 0' and '#elif 0 && ...' to '%elif 0'
196s/%elif[[:space:]].*&&[[:space:]]*00*$/%elif 0/
197s/%elif[[:space:]][[:space:]]*00*[[:space:]]*&&$/%elif 0/
198
199# Convert '#elif ... || 1' and '#elif 1 || ...' to '%elif 1'
200s/%elif[[:space:]].*||[[:space:]]*1[0-9]*$/%elif 1/
201s/%elif[[:space:]][[:space:]]*1[0-9]*[[:space:]]*||$/%elif 1/
202
203/defined/b defined_error
204b end
205
206
207:else
208s/#\([[:space:]]*\)else.*$/\1%else/
209b end
210
211
212:endif
213s/#\([[:space:]]*\)endif.*$/\1%endif/
214b end
215
216
217:defined_error
218x
219s/^/error: yasm & nasm does not grok 'defined': /
220p
221x
222s/^/info: state: /
223q1
224
225
226#
227# Assembly statement inside a C-style comment.
228#
229:asm-inc
230/\/\*[[:space:]]*ASM-INC:.*\*\//b asm-inc-c-style-oneliner
231/\/\/[[:space:]]*ASM-INC:/b asm-inc-cpp-style-oneliner
232/\/\*[[:space:]]*ASM-INC/b asm-inc-c-style-block
233s/^/error: unknown ASM-INC form: /
234q1
235
236# /* ASM-INC: %include "whatever.mac" */
237:asm-inc-c-style-oneliner
238s/[[:space:]]*\/\*[[:space:]][[:space:]]*ASM-INC:[[:space:]]*\(.*\)[[:space:]]*\*\//\1/
239b end
240
241# // ASM-INC: %include "whatever.mac"
242:asm-inc-cpp-style-oneliner
243s/[[:space:]]*\/\/[[:space:]][[:space:]]*ASM-INC:[[:space:]]*\(.*\)[[:space:]]*$/\1/
244b end
245
246# /* ASM-INC
247# %include "whatever.mac"
248# */
249:asm-inc-c-style-block
250s/.*$//
251:asm-inc-c-style-block-next
252h
253N
254s/[\r]$//
255/\*\//!b asm-inc-c-style-block-next
256x
257b end
258
259
260:end
261
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette