]> git.ipfire.org Git - thirdparty/gcc.git/blame - ylwrap
tree-optimization/114736 - SLP DFS walk issue
[thirdparty/gcc.git] / ylwrap
CommitLineData
6599da04
JM
1#! /bin/sh
2# ylwrap - wrapper for lex/yacc invocations.
dfb2c39a 3
d7134c0e 4scriptversion=2013-01-12.17; # UTC
dfb2c39a 5
d7134c0e 6# Copyright (C) 1996-2014 Free Software Foundation, Inc.
dfb2c39a 7#
6599da04
JM
8# Written by Tom Tromey <tromey@cygnus.com>.
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2, or (at your option)
13# any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
0539cb2c 21# along with this program. If not, see <http://www.gnu.org/licenses/>.
6599da04 22
dfb2c39a
DJ
23# As a special exception to the GNU General Public License, if you
24# distribute this file as part of a program that contains a
25# configuration script generated by Autoconf, you may include it under
26# the same distribution terms that you use for the rest of that program.
6599da04 27
dfb2c39a
DJ
28# This file is maintained in Automake, please report
29# bugs to <bug-automake@gnu.org> or send patches to
30# <automake-patches@gnu.org>.
31
d7134c0e
JBG
32get_dirname ()
33{
34 case $1 in
35 */*|*\\*) printf '%s\n' "$1" | sed -e 's|\([\\/]\)[^\\/]*$|\1|';;
36 # Otherwise, we want the empty string (not ".").
37 esac
38}
39
40# guard FILE
41# ----------
42# The CPP macro used to guard inclusion of FILE.
43guard ()
44{
45 printf '%s\n' "$1" \
46 | sed \
47 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \
48 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g' \
49 -e 's/__*/_/g'
50}
51
52# quote_for_sed [STRING]
53# ----------------------
54# Return STRING (or stdin) quoted to be used as a sed pattern.
55quote_for_sed ()
56{
57 case $# in
58 0) cat;;
59 1) printf '%s\n' "$1";;
60 esac \
61 | sed -e 's|[][\\.*]|\\&|g'
62}
63
dfb2c39a
DJ
64case "$1" in
65 '')
d7134c0e 66 echo "$0: No files given. Try '$0 --help' for more information." 1>&2
dfb2c39a
DJ
67 exit 1
68 ;;
69 --basedir)
70 basedir=$2
71 shift 2
72 ;;
73 -h|--h*)
74 cat <<\EOF
75Usage: ylwrap [--help|--version] INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]...
76
77Wrapper for lex/yacc invocations, renaming files as desired.
78
79 INPUT is the input file
80 OUTPUT is one file PROG generates
81 DESIRED is the file we actually want instead of OUTPUT
82 PROGRAM is program to run
83 ARGS are passed to PROG
84
85Any number of OUTPUT,DESIRED pairs may be used.
86
87Report bugs to <bug-automake@gnu.org>.
88EOF
89 exit $?
90 ;;
91 -v|--v*)
92 echo "ylwrap $scriptversion"
93 exit $?
94 ;;
6599da04
JM
95esac
96
dfb2c39a 97
6599da04 98# The input.
d7134c0e 99input=$1
6599da04 100shift
d7134c0e
JBG
101# We'll later need for a correct munging of "#line" directives.
102input_sub_rx=`get_dirname "$input" | quote_for_sed`
103case $input in
dfb2c39a 104 [\\/]* | ?:[\\/]*)
6599da04
JM
105 # Absolute path; do nothing.
106 ;;
dfb2c39a
DJ
107 *)
108 # Relative path. Make it absolute.
d7134c0e 109 input=`pwd`/$input
6599da04
JM
110 ;;
111esac
d7134c0e
JBG
112input_rx=`get_dirname "$input" | quote_for_sed`
113
114# The parser itself, the first file, is the destination of the .y.c
115# rule in the Makefile.
116parser=$1
117
118# A sed program to s/FROM/TO/g for all the FROM/TO so that, for
119# instance, we rename #include "y.tab.h" into #include "parse.h"
120# during the conversion from y.tab.c to parse.c.
121sed_fix_filenames=
122
123# Also rename header guards, as Bison 2.7 for instance uses its header
124# guard in its implementation file.
125sed_fix_header_guards=
6599da04 126
d7134c0e
JBG
127while test $# -ne 0; do
128 if test x"$1" = x"--"; then
dfb2c39a
DJ
129 shift
130 break
131 fi
d7134c0e 132 from=$1
dfb2c39a 133 shift
d7134c0e
JBG
134 to=$1
135 shift
136 sed_fix_filenames="${sed_fix_filenames}s|"`quote_for_sed "$from"`"|$to|g;"
137 sed_fix_header_guards="${sed_fix_header_guards}s|"`guard "$from"`"|"`guard "$to"`"|g;"
6599da04
JM
138done
139
dfb2c39a 140# The program to run.
d7134c0e 141prog=$1
dfb2c39a
DJ
142shift
143# Make any relative path in $prog absolute.
d7134c0e 144case $prog in
dfb2c39a 145 [\\/]* | ?:[\\/]*) ;;
d7134c0e 146 *[\\/]*) prog=`pwd`/$prog ;;
dfb2c39a
DJ
147esac
148
6599da04 149dirname=ylwrap$$
d7134c0e
JBG
150do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit $ret'
151trap "ret=129; $do_exit" 1
152trap "ret=130; $do_exit" 2
153trap "ret=141; $do_exit" 13
154trap "ret=143; $do_exit" 15
6599da04
JM
155mkdir $dirname || exit 1
156
157cd $dirname
dfb2c39a
DJ
158
159case $# in
0539cb2c
RW
160 0) "$prog" "$input" ;;
161 *) "$prog" "$@" "$input" ;;
9f2f70f4 162esac
dfb2c39a
DJ
163ret=$?
164
165if test $ret -eq 0; then
d7134c0e
JBG
166 for from in *
167 do
168 to=`printf '%s\n' "$from" | sed "$sed_fix_filenames"`
dfb2c39a
DJ
169 if test -f "$from"; then
170 # If $2 is an absolute path name, then just use that,
d7134c0e
JBG
171 # otherwise prepend '../'.
172 case $to in
173 [\\/]* | ?:[\\/]*) target=$to;;
174 *) target=../$to;;
dfb2c39a
DJ
175 esac
176
d7134c0e
JBG
177 # Do not overwrite unchanged header files to avoid useless
178 # recompilations. Always update the parser itself: it is the
179 # destination of the .y.c rule in the Makefile. Divert the
180 # output of all other files to a temporary file so we can
181 # compare them to existing versions.
182 if test $from != $parser; then
183 realtarget=$target
184 target=tmp-`printf '%s\n' "$target" | sed 's|.*[\\/]||g'`
6599da04 185 fi
d7134c0e
JBG
186
187 # Munge "#line" or "#" directives. Don't let the resulting
188 # debug information point at an absolute srcdir. Use the real
189 # output file name, not yy.lex.c for instance. Adjust the
190 # include guards too.
191 sed -e "/^#/!b" \
192 -e "s|$input_rx|$input_sub_rx|" \
193 -e "$sed_fix_filenames" \
194 -e "$sed_fix_header_guards" \
195 "$from" >"$target" || ret=$?
196
197 # Check whether files must be updated.
198 if test "$from" != "$parser"; then
199 if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
200 echo "$to is unchanged"
201 rm -f "$target"
202 else
203 echo "updating $to"
dfb2c39a
DJ
204 mv -f "$target" "$realtarget"
205 fi
206 fi
207 else
d7134c0e
JBG
208 # A missing file is only an error for the parser. This is a
209 # blatant hack to let us support using "yacc -d". If -d is not
210 # specified, don't fail when the header file is "missing".
211 if test "$from" = "$parser"; then
dfb2c39a
DJ
212 ret=1
213 fi
214 fi
dfb2c39a 215 done
6599da04
JM
216fi
217
218# Remove the directory.
219cd ..
220rm -rf $dirname
221
dfb2c39a
DJ
222exit $ret
223
224# Local Variables:
225# mode: shell-script
226# sh-indentation: 2
227# eval: (add-hook 'write-file-hooks 'time-stamp)
228# time-stamp-start: "scriptversion="
229# time-stamp-format: "%:y-%02m-%02d.%02H"
0539cb2c
RW
230# time-stamp-time-zone: "UTC"
231# time-stamp-end: "; # UTC"
dfb2c39a 232# End: