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