VirtualBox

source: kBuild/trunk/src/kash/mknodes.sh

Last change on this file was 3458, checked in by bird, 4 years ago

kash: Use reference counting of parser output in threaded-mode.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 5.6 KB
Line 
1#! /bin/sh
2# $NetBSD: mknodes.sh,v 1.1 2004/01/16 23:24:38 dsl Exp $
3
4# Copyright (c) 2003 The NetBSD Foundation, Inc.
5# All rights reserved.
6#
7# This code is derived from software contributed to The NetBSD Foundation
8# by David Laight.
9#
10# Redistribution and use in source and binary forms, with or without
11# modification, are permitted provided that the following conditions
12# are met:
13# 1. Redistributions of source code must retain the above copyright
14# notice, this list of conditions and the following disclaimer.
15# 2. Redistributions in binary form must reproduce the above copyright
16# notice, this list of conditions and the following disclaimer in the
17# documentation and/or other materials provided with the distribution.
18# 3. Neither the name of The NetBSD Foundation nor the names of its
19# contributors may be used to endorse or promote products derived
20# from this software without specific prior written permission.
21#
22# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32# POSSIBILITY OF SUCH DAMAGE.
33
34nodetypes=$1
35nodes_pat=$2
36objdir="$3"
37
38exec <$nodetypes
39exec >$objdir/nodes.h.tmp
40
41echo "/*"
42echo " * This file was generated by mknodes.sh"
43echo " */"
44echo
45
46tagno=0
47while IFS=; read -r line; do
48 line="${line%%#*}"
49 IFS=' '
50 set -- $line
51 IFS=
52 [ -z "$2" ] && continue
53 case "$line" in
54 [" "]* )
55 IFS=' '
56 [ $field = 0 ] && struct_list="$struct_list $struct"
57 eval field_${struct}_$field=\"\$*\"
58 eval numfld_$struct=\$field
59 field=$(($field + 1))
60 ;;
61 * )
62 define=$1
63 struct=$2
64 echo "#define $define $tagno"
65 tagno=$(($tagno + 1))
66 eval define_$struct=\"\$define_$struct \$define\"
67 struct_define="$struct_define $struct"
68 field=0
69 ;;
70 esac
71done
72
73echo
74
75## @todo inconsistent indentation here.
76IFS=' '
77for struct in $struct_list; do
78 echo
79 echo
80 echo "struct $struct {"
81 echo "#ifdef KASH_SEPARATE_PARSER_ALLOCATOR"
82 echo " struct pstack_block *pblock;"
83 echo "#endif"
84 field=0
85 while
86 eval line=\"\$field_${struct}_$field\"
87 field=$(($field + 1))
88 [ -n "$line" ]
89 do
90 IFS=' '
91 set -- $line
92 name=$1
93 case $2 in
94 nodeptr ) type="union node *";;
95 nodelist ) type="struct nodelist *";;
96 string ) type="char *";;
97 int ) type="int ";;
98 * ) name=; shift 2; type="$*";;
99 esac
100 echo " $type$name;"
101 done
102 echo "};"
103done
104
105echo
106echo
107echo "union node {"
108echo "#ifdef KASH_SEPARATE_PARSER_ALLOCATOR"
109echo "# ifdef __GNUC__"
110echo " __extension__"
111echo "# endif"
112echo " struct {"
113echo " struct pstack_block *pblock;"
114echo " int type;"
115echo " };"
116echo "#else"
117echo " int type;"
118echo "#endif"
119for struct in $struct_list; do
120 echo " struct $struct $struct;"
121done
122echo "};"
123echo
124echo
125echo "struct nodelist {"
126echo " struct nodelist *next;"
127echo " union node *n;"
128echo "};"
129echo
130echo
131echo "union node *copyfunc(struct shinstance *, union node *);"
132echo "void freefunc(struct shinstance *, union node *);"
133
134exec <$nodes_pat
135exec >$objdir/nodes.c.tmp
136mv -f $objdir/nodes.h.tmp $objdir/nodes.h || exit 1
137
138echo "/*"
139echo " * This file was generated by mknodes.sh"
140echo " */"
141echo
142
143while IFS=; read -r line; do
144 IFS=' '
145 set -- $line
146 IFS=
147 case "$1" in
148 '%SIZES' )
149 echo "static const short nodesize[$tagno] = {"
150 IFS=' '
151 for struct in $struct_define; do
152 echo " SHELL_ALIGN(sizeof (struct $struct)),"
153 done
154 echo "};"
155 ;;
156 '%CALCSIZE' )
157 echo " if (n == NULL)"
158 echo " return;"
159 echo " funcblocksize += nodesize[n->type];"
160 echo " switch (n->type) {"
161 IFS=' '
162 for struct in $struct_list; do
163 eval defines=\"\$define_$struct\"
164 for define in $defines; do
165 echo " case $define:"
166 done
167 eval field=\$numfld_$struct
168 while
169 [ $field != 0 ]
170 do
171 eval line=\"\$field_${struct}_$field\"
172 field=$(($field - 1))
173 IFS=' '
174 set -- $line
175 name=$1
176 cl=")"
177 case $2 in
178 nodeptr ) fn=calcsize;;
179 nodelist ) fn=sizenodelist;;
180 string ) fn="funcstringsize += strlen"
181 cl=") + 1";;
182 * ) continue;;
183 esac
184 echo " ${fn}(n->$struct.$name${cl};"
185 done
186 echo " break;"
187 done
188 echo " };"
189 ;;
190 '%COPY' )
191 echo " if (n == NULL)"
192 echo " return NULL;"
193 echo " new = funcblock;"
194 echo " funcblock = (char *) funcblock + nodesize[n->type];"
195 echo " switch (n->type) {"
196 IFS=' '
197 for struct in $struct_list; do
198 eval defines=\"\$define_$struct\"
199 for define in $defines; do
200 echo " case $define:"
201 done
202 eval field=\$numfld_$struct
203 while
204 [ $field != 0 ]
205 do
206 eval line=\"\$field_${struct}_$field\"
207 field=$(($field - 1))
208 IFS=' '
209 set -- $line
210 name=$1
211 case $2 in
212 nodeptr ) fn="copynode(";;
213 nodelist ) fn="copynodelist(";;
214 string ) fn="nodesavestr(";;
215 int ) fn=;;
216 temp ) echo "unexpected 'temp' node type" >&2; exit 2;;
217 * ) continue;;
218 esac
219 f="$struct.$name"
220 echo " new->$f = ${fn}n->$f${fn:+)};"
221 done
222 echo " break;"
223 done
224 echo " };"
225 echo " new->type = n->type;"
226 ;;
227 * ) echo "$line";;
228 esac
229done
230
231exec >/dev/null
232mv -f $objdir/nodes.c.tmp $objdir/nodes.c || exit 1
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