1 | # $Id: various.sed 96407 2022-08-22 17: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).
|
---|
6 | #
|
---|
7 |
|
---|
8 | #
|
---|
9 | # Copyright (C) 2006-2022 Oracle and/or its affiliates.
|
---|
10 | #
|
---|
11 | # This file is part of VirtualBox base platform packages, as
|
---|
12 | # available from https://www.virtualbox.org.
|
---|
13 | #
|
---|
14 | # This program is free software; you can redistribute it and/or
|
---|
15 | # modify it under the terms of the GNU General Public License
|
---|
16 | # as published by the Free Software Foundation, in version 3 of the
|
---|
17 | # License.
|
---|
18 | #
|
---|
19 | # This program is distributed in the hope that it will be useful, but
|
---|
20 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
22 | # General Public License for more details.
|
---|
23 | #
|
---|
24 | # You should have received a copy of the GNU General Public License
|
---|
25 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
26 | #
|
---|
27 | # The contents of this file may alternatively be used under the terms
|
---|
28 | # of the Common Development and Distribution License Version 1.0
|
---|
29 | # (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
30 | # in the VirtualBox distribution, in which case the provisions of the
|
---|
31 | # CDDL are applicable instead of those of the GPL.
|
---|
32 | #
|
---|
33 | # You may elect to license modified versions of this file under the
|
---|
34 | # terms and conditions of either the GPL or the CDDL or both.
|
---|
35 | #
|
---|
36 | # SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
37 | #
|
---|
38 |
|
---|
39 | # Pass thru the file header and copyright.
|
---|
40 | 1,/^\#ifndef/{
|
---|
41 | /^\#ifndef/b next
|
---|
42 | s/^[/ ]//
|
---|
43 | s/^\*\//;/
|
---|
44 | s/\*/;/g
|
---|
45 | 4s/^.*$/; Automatically generated by various.sed. DO NOT EDIT!/
|
---|
46 | b end
|
---|
47 | }
|
---|
48 | :next
|
---|
49 |
|
---|
50 | # Check for markers (typically in comments).
|
---|
51 | /ASM-INC/basm-inc
|
---|
52 | /ASM-NOINC/basm-noinc
|
---|
53 |
|
---|
54 | # Newline escapes.
|
---|
55 | :check-newline-escape
|
---|
56 | /\\$/!bno-more-newline-escapes
|
---|
57 | N
|
---|
58 | b check-newline-escape
|
---|
59 | :no-more-newline-escapes
|
---|
60 |
|
---|
61 | # Strip comments and trailing space.
|
---|
62 | s/[[:space:]][[:space:]]*\/\*.*$//g
|
---|
63 | s/[[:space:]][[:space:]]*\/\/.*$//g
|
---|
64 | s/[[:space:]][[:space:]]*$//g
|
---|
65 |
|
---|
66 | # Try identify the statement.
|
---|
67 | /#[[:space:]]*define[[:space:]]/bdefine
|
---|
68 | /#[[:space:]]*ifdef[[:space:]]/bifdef
|
---|
69 | /#[[:space:]]*ifndef[[:space:]]/bifndef
|
---|
70 | /#[[:space:]]*if[[:space:]]/bif
|
---|
71 | /#[[:space:]]*elif[[:space:]]/belif
|
---|
72 | /#[[:space:]]*else$/belse
|
---|
73 | /#[[:space:]]*endif$/bendif
|
---|
74 |
|
---|
75 | # Not recognized, drop it.
|
---|
76 | :asm-noinc
|
---|
77 | d
|
---|
78 | b end
|
---|
79 |
|
---|
80 | #
|
---|
81 | # Defines needs some extra massaging to work in yasm.
|
---|
82 | # Things like trailing type indicators ('U', 'ULL' ++) does not go down well.
|
---|
83 | #
|
---|
84 | :define
|
---|
85 | /\$/d
|
---|
86 | s/#\([[:space:]]*\)define/\1%define/
|
---|
87 |
|
---|
88 | s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)U$/\1/
|
---|
89 | s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)U\([[:space:]]*\))$/\1\2)/
|
---|
90 | s/\([[:space:]][0-9][0-9]*\)U[[:space:]]*$/\1/
|
---|
91 | s/\([[:space:]][0-9][0-9]*\)U\([[:space:]]*\))$/\1\2)/
|
---|
92 |
|
---|
93 | s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)UL$/\1/
|
---|
94 | s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)UL\([[:space:]]*\))$/\1\2)/
|
---|
95 | s/\([[:space:]][0-9][0-9]*\)UL[[:space:]]*$/\1/
|
---|
96 | s/\([[:space:]][0-9][0-9]*\)UL\([[:space:]]*\))$/\1\2)/
|
---|
97 |
|
---|
98 | s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)ULL$/\1/
|
---|
99 | s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)ULL\([[:space:]]*\))$/\1\2)/
|
---|
100 | s/\([[:space:]][0-9][0-9]*\)ULL[[:space:]]*$/\1/
|
---|
101 | s/\([[:space:]][0-9][0-9]*\)ULL\([[:space:]]*\))$/\1\2)/
|
---|
102 |
|
---|
103 | s/UINT64_C([[:space:]]*\(0[xX][0-9a-fA-F][0-9a-fA-F]*\)[[:space:]]*)/\1/
|
---|
104 | s/UINT64_C([[:space:]]*\([0-9][0-9]*\)[[:space:]]*)/\1/
|
---|
105 | s/UINT32_C([[:space:]]*\(0[xX][0-9a-fA-F][0-9a-fA-F]*\)[[:space:]]*)/\1/
|
---|
106 | s/UINT32_C([[:space:]]*\([0-9][0-9]*\)[[:space:]]*)/\1/
|
---|
107 | s/UINT16_C([[:space:]]*\(0[xX][0-9a-fA-F][0-9a-fA-F]*\)[[:space:]]*)/\1/
|
---|
108 | s/UINT16_C([[:space:]]*\([0-9][0-9]*\)[[:space:]]*)/\1/
|
---|
109 | s/UINT8_C([[:space:]]*\(0[xX][0-9a-fA-F][0-9a-fA-F]*\)[[:space:]]*)/\1/
|
---|
110 | s/UINT8_C([[:space:]]*\([0-9][0-9]*\)[[:space:]]*)/\1/
|
---|
111 |
|
---|
112 | b end
|
---|
113 |
|
---|
114 | #
|
---|
115 | # Conditional statements, 1:1.
|
---|
116 | #
|
---|
117 | :ifdef
|
---|
118 | s/#\([[:space:]]*\)ifdef/\1%ifdef/
|
---|
119 | b end
|
---|
120 |
|
---|
121 | :ifndef
|
---|
122 | s/#\([[:space:]]*\)ifndef/\1%ifndef/
|
---|
123 | b end
|
---|
124 |
|
---|
125 | :if
|
---|
126 | s/#\([[:space:]]*\)if/\1%if/
|
---|
127 | b end
|
---|
128 |
|
---|
129 | :elif
|
---|
130 | s/#\([[:space:]]*\)elif/\1%elif/
|
---|
131 | b end
|
---|
132 |
|
---|
133 | :else
|
---|
134 | s/#\([[:space:]]*\)else.*$/\1%else/
|
---|
135 | b end
|
---|
136 |
|
---|
137 | :endif
|
---|
138 | s/#\([[:space:]]*\)endif.*$/\1%endif/
|
---|
139 | b end
|
---|
140 |
|
---|
141 | #
|
---|
142 | # Assembly statement... may need adjusting when used.
|
---|
143 | #
|
---|
144 | :asm-inc
|
---|
145 | b end
|
---|
146 |
|
---|
147 | :end
|
---|
148 |
|
---|