VirtualBox

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

Last change on this file was 104378, checked in by vboxsync, 4 weeks ago

VMM/IEM: Automtically convert IEMInternal.h & IEMN8veRecompiler.h into nasm/yasm include files so IEMAllN8veHlpA.asm can make use of some of the constants define in them for the prolog code. bugref:10653 bugref:10370

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
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#
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# Pass thru the file header and copyright.
411,/^\#ifndef/{
42/^\#ifndef/b next
43s/^[/ ]//
44s/^\*\//;/
45s/\*/;/g
464s/^.*$/; Automatically generated by various.sed. DO NOT EDIT!/
47b end
48}
49:next
50
51# Check for block markers (typically in comments).
52/ASM-NOINC-START/,/ASM-NOINC-END/ {
53 d
54}
55
56# Newline escapes.
57:check-newline-escape
58/\\$/!bno-more-newline-escapes
59N
60b check-newline-escape
61:no-more-newline-escapes
62
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.
68h
69
70# Strip comments.
71/\/\*/!b strip_cpp_style_comment
72:load_another_c_style_comment_line
73/\*\//b strip_c_style_comment
74N
75b load_another_c_style_comment_line
76:strip_c_style_comment
77s/\/\*.*\*\// /g
78
79:strip_cpp_style_comment
80s,//.*$, ,g
81
82# Strip trailing spaces
83s/[[: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
96d
97b 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
104/\$/d
105s/#\([[:space:]]*\)define/\1%define/
106
107s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)U$/\1/
108s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)U\([[:space:]]*\))$/\1\2)/
109s/\([[:space:]][0-9][0-9]*\)U[[:space:]]*$/\1/
110s/\([[:space:]][0-9][0-9]*\)U\([[:space:]]*\))$/\1\2)/
111
112s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)UL$/\1/
113s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)UL\([[:space:]]*\))$/\1\2)/
114s/\([[:space:]][0-9][0-9]*\)UL[[:space:]]*$/\1/
115s/\([[:space:]][0-9][0-9]*\)UL\([[:space:]]*\))$/\1\2)/
116
117s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)ULL$/\1/
118s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)ULL\([[:space:]]*\))$/\1\2)/
119s/\([[:space:]][0-9][0-9]*\)ULL[[:space:]]*$/\1/
120s/\([[:space:]][0-9][0-9]*\)ULL\([[:space:]]*\))$/\1\2)/
121
122s/UINT64_C([[:space:]]*\(0[xX][0-9a-fA-F][0-9a-fA-F]*\)[[:space:]]*)/\1/
123s/UINT64_C([[:space:]]*\([0-9][0-9]*\)[[:space:]]*)/\1/
124s/UINT32_C([[:space:]]*\(0[xX][0-9a-fA-F][0-9a-fA-F]*\)[[:space:]]*)/\1/
125s/UINT32_C([[:space:]]*\([0-9][0-9]*\)[[:space:]]*)/\1/
126s/UINT16_C([[:space:]]*\(0[xX][0-9a-fA-F][0-9a-fA-F]*\)[[:space:]]*)/\1/
127s/UINT16_C([[:space:]]*\([0-9][0-9]*\)[[:space:]]*)/\1/
128s/UINT8_C([[:space:]]*\(0[xX][0-9a-fA-F][0-9a-fA-F]*\)[[:space:]]*)/\1/
129s/UINT8_C([[:space:]]*\([0-9][0-9]*\)[[:space:]]*)/\1/
130
131b end
132
133#
134# Conditional statements, 1:1.
135#
136:ifdef
137s/#\([[:space:]]*\)ifdef/\1%ifdef/
138b end
139
140
141:ifndef
142s/#\([[:space:]]*\)ifndef/\1%ifndef/
143b end
144
145
146:if
147s/#\([[:space:]]*\)if/\1%if/
148
149# Replace 'defined(DOXYGEN_RUNNING)' with '0' to simplify subsequent matching to '[0]' when we mean 'defined[(]DOXYGEN_RUNNING[)]'.
150s/defined[(]DOXYGEN_RUNNING[)]/0/
151
152# Simplify stuff that was turned into '0' in the previous step (or in the input file).
153s/||[[:space:]]*0[[:space:]]*$//g
154s/||[[:space:]]*0\([[:space:]|&]\)/\1/g
155s/\([[:space:]|&]\)0[[:space:]]*||/\1/g
156s/[[:space:]][[:space:]]*$//
157
158# Convert #if [!]defined(xxxx) into %if[n]def xxxx
159s/%if[[:space:]][[:space:]]*defined[(]\([^)][^)]*\)[)]$/%ifdef \1/
160s/%if[[:space:]][[:space:]]*[!][[:space:]]*defined[(]\([^)][^)]*\)[)]$/%ifndef \1/
161
162# Convert '#if ... && 0' and '#if 0 && ...' to %if 0
163s/%if[[:space:]].*&&[[:space:]]*00*$/%if 0/
164s/%if[[:space:]][[:space:]]*00*[[:space:]]*&&$/%if 0/
165
166# Convert '#if ... || 1' and '#if 1 || ...' to '%if 1'
167s/%if[[:space:]].*||[[:space:]]*1[0-9]*$/%if 1/
168s/%if[[:space:]][[:space:]]*1[0-9]*[[:space:]]*||$/%if 1/
169
170/defined/b defined_error
171b end
172
173
174:elif
175s/#\([[:space:]]*\)elif/\1%elif/
176
177# Replace 'defined(DOXYGEN_RUNNING)' with '0' to simplify subsequent matching to '[0]' when we mean 'defined[(]DOXYGEN_RUNNING[)]'.
178s/defined[(]DOXYGEN_RUNNING[)]/0/
179
180# Simplify stuff that was turned into '0' in the previous step (or in the input file).
181s/||[[:space:]]*0[[:space:]]*$//g
182s/||[[:space:]]*0\([[:space:]|&]\)/\1/g
183s/\([[:space:]|&]\)0[[:space:]]*||/\1/g
184s/[[:space:]][[:space:]]*$//
185
186# Convert #if [!]defined(xxxx) into %if[n]def xxxx
187s/%elif[[:space:]][[:space:]]*defined[(]\([^)][^)]*\)[)]$/%elifdef \1/
188s/%elif[[:space:]][[:space:]]*[!][[:space:]]*defined[(]\([^)][^)]*\)[)]$/%elifndef \1/
189
190# Convert '#elif ... && 0' and '#elif 0 && ...' to '%elif 0'
191s/%elif[[:space:]].*&&[[:space:]]*00*$/%elif 0/
192s/%elif[[:space:]][[:space:]]*00*[[:space:]]*&&$/%elif 0/
193
194# Convert '#elif ... || 1' and '#elif 1 || ...' to '%elif 1'
195s/%elif[[:space:]].*||[[:space:]]*1[0-9]*$/%elif 1/
196s/%elif[[:space:]][[:space:]]*1[0-9]*[[:space:]]*||$/%elif 1/
197
198/defined/b defined_error
199b end
200
201
202:else
203s/#\([[:space:]]*\)else.*$/\1%else/
204b end
205
206
207:endif
208s/#\([[:space:]]*\)endif.*$/\1%endif/
209b end
210
211
212:defined_error
213x
214s/^/error: yasm & nasm does not grok 'defined': /
215p
216x
217s/^/info: state: /
218q1
219
220
221#
222# Assembly statement inside a C-style comment.
223#
224:asm-inc
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
228s/^/error: unknown ASM-INC form: /
229q1
230
231# /* ASM-INC: %include "whatever.mac" */
232:asm-inc-c-style-oneliner
233s/[[:space:]]*\/\*[[:space:]][[:space:]]*ASM-INC:[[:space:]]*\(.*\)[[:space:]]*\*\//\1/
234b end
235
236# // ASM-INC: %include "whatever.mac"
237:asm-inc-cpp-style-oneliner
238s/[[:space:]]*\/\/[[:space:]][[:space:]]*ASM-INC:[[:space:]]*\(.*\)[[:space:]]*$/\1/
239b end
240
241# /* ASM-INC
242# %include "whatever.mac"
243# */
244:asm-inc-c-style-block
245s/.*$//
246:asm-inc-c-style-block-next
247h
248N
249/\*\//!b asm-inc-c-style-block-next
250x
251b end
252
253
254:end
255
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use