annotate llvm/utils/llvmdo @ 220:42394fc6a535

Added tag llvm12 for changeset 0572611fdcc8
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 15 Jun 2021 19:13:43 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 #!/bin/sh
anatofuz
parents:
diff changeset
2 ##===- utils/llvmdo - Counts Lines Of Code -------------------*- Script -*-===##
anatofuz
parents:
diff changeset
3 #
anatofuz
parents:
diff changeset
4 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
5 # See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
6 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
7 #
anatofuz
parents:
diff changeset
8 ##===----------------------------------------------------------------------===##
anatofuz
parents:
diff changeset
9 #
anatofuz
parents:
diff changeset
10 # This script is a general purpose "apply" function for the source files in LLVM
anatofuz
parents:
diff changeset
11 # It uses "find" to locate all the source files and then applies the user's
anatofuz
parents:
diff changeset
12 # command to them. As such, this command is often not used by itself much but
anatofuz
parents:
diff changeset
13 # the other find related tools (countloc.sh,llvmgrep,getsrcs.sh,userloc.sh) are
anatofuz
parents:
diff changeset
14 # all based on this script. This script defines "what is a source file" in
anatofuz
parents:
diff changeset
15 # LLVM and so should be maintained if new directories, new file extensions,
anatofuz
parents:
diff changeset
16 # etc. are used in LLVM as it progresses.
anatofuz
parents:
diff changeset
17 #
anatofuz
parents:
diff changeset
18 # Usage:
anatofuz
parents:
diff changeset
19 # llvmdo [-topdir DIR] [-dirs "DIRNAMES..."] [-code-only] PROGRAM ARGS...
anatofuz
parents:
diff changeset
20 #
anatofuz
parents:
diff changeset
21 # The -topdir option allows you to specify the llvm source root directly. If it
anatofuz
parents:
diff changeset
22 # is not specified then it will be obtained with llvm-config which must be built
anatofuz
parents:
diff changeset
23 # and in your path.
anatofuz
parents:
diff changeset
24 #
anatofuz
parents:
diff changeset
25 # The -dirs argument allows you to specify the set of directories that are
anatofuz
parents:
diff changeset
26 # searched. The default list of directories searched is:
anatofuz
parents:
diff changeset
27 # include lib tools utils runtime autoconf docs test examples projects
anatofuz
parents:
diff changeset
28 # Note that you must use quotes around the list of directory names.
anatofuz
parents:
diff changeset
29 #
anatofuz
parents:
diff changeset
30 # The -code-only option specifies that only those files that are considered
anatofuz
parents:
diff changeset
31 # "code" should be visited. HTML documentation is considered code, but things
anatofuz
parents:
diff changeset
32 # like README files, etc. are not.
anatofuz
parents:
diff changeset
33 #
anatofuz
parents:
diff changeset
34 # Finally, you simply specify whatever program you want to run against each
anatofuz
parents:
diff changeset
35 # file and the arguments to give it. The PROGRAM will be given the file name
anatofuz
parents:
diff changeset
36 # as its last argument.
anatofuz
parents:
diff changeset
37 ##===----------------------------------------------------------------------===##
anatofuz
parents:
diff changeset
38
anatofuz
parents:
diff changeset
39 if test $# -lt 1 ; then
anatofuz
parents:
diff changeset
40 echo "Usage: llvmdo [-topdir DIR] [-dirs "DIRNAMES..."] [-code-only] PROGRAM ARGS..."
anatofuz
parents:
diff changeset
41 exit 1
anatofuz
parents:
diff changeset
42 fi
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 if test "$1" = "-topdir" ; then
anatofuz
parents:
diff changeset
45 TOPDIR="$2"
anatofuz
parents:
diff changeset
46 shift; shift;
anatofuz
parents:
diff changeset
47 else
anatofuz
parents:
diff changeset
48 TOPDIR=`llvm-config --src-root`
anatofuz
parents:
diff changeset
49 fi
anatofuz
parents:
diff changeset
50
anatofuz
parents:
diff changeset
51 if test "$1" = "-dirs" ; then
anatofuz
parents:
diff changeset
52 LLVMDO_DIRS="$2"
anatofuz
parents:
diff changeset
53 shift ; shift
anatofuz
parents:
diff changeset
54 elif test -z "$LLVMDO_DIRS" ; then
anatofuz
parents:
diff changeset
55 LLVMDO_DIRS="include lib tools utils runtime autoconf docs test examples projects cmake"
anatofuz
parents:
diff changeset
56 fi
anatofuz
parents:
diff changeset
57
anatofuz
parents:
diff changeset
58 if test "$1" = "-code-only" ; then
anatofuz
parents:
diff changeset
59 CODE_ONLY="set"
anatofuz
parents:
diff changeset
60 shift
anatofuz
parents:
diff changeset
61 else
anatofuz
parents:
diff changeset
62 CODE_ONLY=""
anatofuz
parents:
diff changeset
63 fi
anatofuz
parents:
diff changeset
64
anatofuz
parents:
diff changeset
65 if test "$1" = "" ; then
anatofuz
parents:
diff changeset
66 echo "Missing program name to run"
anatofuz
parents:
diff changeset
67 exit 1
anatofuz
parents:
diff changeset
68 fi
anatofuz
parents:
diff changeset
69
anatofuz
parents:
diff changeset
70 PROGRAM=`which $1`
anatofuz
parents:
diff changeset
71 if test ! -x "$PROGRAM" ; then
anatofuz
parents:
diff changeset
72 echo "Can't execute $1"
anatofuz
parents:
diff changeset
73 exit 1
anatofuz
parents:
diff changeset
74 fi
anatofuz
parents:
diff changeset
75 shift;
anatofuz
parents:
diff changeset
76
anatofuz
parents:
diff changeset
77 paths_to_ignore="\
anatofuz
parents:
diff changeset
78 -path */.svn/ -o \
anatofuz
parents:
diff changeset
79 -path */.svn/* -o \
anatofuz
parents:
diff changeset
80 -path docs/doxygen/* -o \
anatofuz
parents:
diff changeset
81 -path docs/CommandGuide/html/* -o \
anatofuz
parents:
diff changeset
82 -path docs/CommandGuide/man/* -o \
anatofuz
parents:
diff changeset
83 -path docs/CommandGuide/ps/* -o \
anatofuz
parents:
diff changeset
84 -path docs/CommandGuide/man/* -o \
anatofuz
parents:
diff changeset
85 -path docs/HistoricalNotes/* -o \
anatofuz
parents:
diff changeset
86 -path docs/img/* -o \
anatofuz
parents:
diff changeset
87 -path */.libs/* -o \
anatofuz
parents:
diff changeset
88 -path lib/Support/bzip2/* -o \
anatofuz
parents:
diff changeset
89 -path projects/llvm-test/* \
anatofuz
parents:
diff changeset
90 "
anatofuz
parents:
diff changeset
91 files_to_match="\
anatofuz
parents:
diff changeset
92 -name *.ac \
anatofuz
parents:
diff changeset
93 -o -name *.b \
anatofuz
parents:
diff changeset
94 -o -name *.c \
anatofuz
parents:
diff changeset
95 -o -name *.cc \
anatofuz
parents:
diff changeset
96 -o -name *.cfg \
anatofuz
parents:
diff changeset
97 -o -name *.cpp \
anatofuz
parents:
diff changeset
98 -o -name *.css \
anatofuz
parents:
diff changeset
99 -o -name *.def \
anatofuz
parents:
diff changeset
100 -o -name *.el \
anatofuz
parents:
diff changeset
101 -o -name *.exp \
anatofuz
parents:
diff changeset
102 -o -name *.footer \
anatofuz
parents:
diff changeset
103 -o -name *.gnuplot' \
anatofuz
parents:
diff changeset
104 -o -name *.h \
anatofuz
parents:
diff changeset
105 -o -name *.header \
anatofuz
parents:
diff changeset
106 -o -name *.html \
anatofuz
parents:
diff changeset
107 -o -name *.in \
anatofuz
parents:
diff changeset
108 -o -name *.inc \
anatofuz
parents:
diff changeset
109 -o -name *.intro \
anatofuz
parents:
diff changeset
110 -o -name *.l \
anatofuz
parents:
diff changeset
111 -o -name *.ll \
anatofuz
parents:
diff changeset
112 -o -name *.lst \
anatofuz
parents:
diff changeset
113 -o -name *.m4 \
anatofuz
parents:
diff changeset
114 -o -name *.pod \
anatofuz
parents:
diff changeset
115 -o -name *.pl \
anatofuz
parents:
diff changeset
116 -o -name *.py \
anatofuz
parents:
diff changeset
117 -o -name *.sh \
anatofuz
parents:
diff changeset
118 -o -name *.schema \
anatofuz
parents:
diff changeset
119 -o -name *.st \
anatofuz
parents:
diff changeset
120 -o -name *.tcl \
anatofuz
parents:
diff changeset
121 -o -name *.td \
anatofuz
parents:
diff changeset
122 -o -name *.tr \
anatofuz
parents:
diff changeset
123 -o -name *.y \
anatofuz
parents:
diff changeset
124 -o -name Make* \
anatofuz
parents:
diff changeset
125 -o -name *.cmake \
anatofuz
parents:
diff changeset
126 -o -name llvmdo \
anatofuz
parents:
diff changeset
127 -o -name llvmgrep \
anatofuz
parents:
diff changeset
128 -o -name check-each-file \
anatofuz
parents:
diff changeset
129 -o -name codgen-diff \
anatofuz
parents:
diff changeset
130 -o -name llvm-native-gcc \
anatofuz
parents:
diff changeset
131 -o -name llvm-native-gxx \
anatofuz
parents:
diff changeset
132 -o -name makellvm \
anatofuz
parents:
diff changeset
133 -o -path include/llvm/ADT/ilist \
anatofuz
parents:
diff changeset
134 -o -path test/\*.ll \
anatofuz
parents:
diff changeset
135 -o -path test/Scripts/not \
anatofuz
parents:
diff changeset
136 -o -path runtime/\*.ll \
anatofuz
parents:
diff changeset
137 "
anatofuz
parents:
diff changeset
138 if test -z "$CODE_ONLY" ; then
anatofuz
parents:
diff changeset
139 files_to_match="$files_to_match \
anatofuz
parents:
diff changeset
140 -o -name *.txt \
anatofuz
parents:
diff changeset
141 -o -name *.TXT \
anatofuz
parents:
diff changeset
142 -o -name *.vim \
anatofuz
parents:
diff changeset
143 -o -name vimrc \
anatofuz
parents:
diff changeset
144 -o -name README \
anatofuz
parents:
diff changeset
145 -o -name COPYING.LIB \
anatofuz
parents:
diff changeset
146 -o -name LICENSE* "
anatofuz
parents:
diff changeset
147 fi
anatofuz
parents:
diff changeset
148 files_to_ignore="\
anatofuz
parents:
diff changeset
149 -name \.* \
anatofuz
parents:
diff changeset
150 -o -name *~ \
anatofuz
parents:
diff changeset
151 -o -name #* \
anatofuz
parents:
diff changeset
152 -o -name configure \
anatofuz
parents:
diff changeset
153 -o -name slow.ll \
anatofuz
parents:
diff changeset
154 -o -name *libtool* \
anatofuz
parents:
diff changeset
155 -o -name ltdl* \
anatofuz
parents:
diff changeset
156 -o -name ltdl.m4 \
anatofuz
parents:
diff changeset
157 -o -name ltmain.m4 \
anatofuz
parents:
diff changeset
158 -o -name ltmain.sh \
anatofuz
parents:
diff changeset
159 -o -name aclocal.m4 \
anatofuz
parents:
diff changeset
160 -o -name acinclude.m4 \
anatofuz
parents:
diff changeset
161 -o -name *LoopSimplifyCrash.ll \
anatofuz
parents:
diff changeset
162 -o -name *AST-Remove.ll \
anatofuz
parents:
diff changeset
163 -o -name PPCPerfectShuffle.h \
anatofuz
parents:
diff changeset
164 "
anatofuz
parents:
diff changeset
165
anatofuz
parents:
diff changeset
166 if test -d "$TOPDIR" ; then
anatofuz
parents:
diff changeset
167 cd $TOPDIR
anatofuz
parents:
diff changeset
168 # Have to use the right "find" on a per-platform basis. Most platforms have
anatofuz
parents:
diff changeset
169 # Gnu find as "find", but Solaris does not.
anatofuz
parents:
diff changeset
170 case `uname -s` in
anatofuz
parents:
diff changeset
171 SunOS) find_prog=gfind ;;
anatofuz
parents:
diff changeset
172 *) find_prog=find ;;
anatofuz
parents:
diff changeset
173 esac
anatofuz
parents:
diff changeset
174 # Turn off file name generation (globbing) so that substitution of the
anatofuz
parents:
diff changeset
175 # variables doesn't cause the shell to create lists of file names
anatofuz
parents:
diff changeset
176 set -f
anatofuz
parents:
diff changeset
177 $find_prog $LLVMDO_DIRS -type f \
anatofuz
parents:
diff changeset
178 \( $paths_to_ignore \) -prune \
anatofuz
parents:
diff changeset
179 -o \( \( $files_to_match \) \! \( $files_to_ignore \) \
anatofuz
parents:
diff changeset
180 -exec $PROGRAM "$@" {} \; \)
anatofuz
parents:
diff changeset
181 else
anatofuz
parents:
diff changeset
182 echo "Can't find LLVM top directory in $TOPDIR"
anatofuz
parents:
diff changeset
183 fi