blob: 54c21293d1943b90ab3780babaafd7007565c2ef [file] [log] [blame]
Reid Spencera60ff2e2004-07-26 22:52:44 +00001#!/bin/sh
Reid Spencer33709e52004-09-20 08:00:09 +00002##===- 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
14# the other find related tools (countloc.sh,llvmgrep,getsrcs.sh) are all based
15# on the implementation. This script defines "what is a source file" in LLVM and
16# so should be maintained if new directories, new file extensions, etc. are
17# used in LLVM as it progresses.
18#
19# Usage:
Misha Brukmanef7dd462004-10-08 01:11:15 +000020# llvmdo [-dirs "DIRNAMES..."] PROGRAM ARGS...
Reid Spencer33709e52004-09-20 08:00:09 +000021#
22# The -dirs argument allows you to specify the set of directories that are
Reid Spencer9610fc92004-09-20 08:04:13 +000023# searched. By default, everything is searched. Note that you must use quotes
24# around the list of directory names. After that you simply specify whatever
25# program you want to run against each file and the arguments to give it. The
26# PROGRAM will be given the file name as its last argument.
27##===----------------------------------------------------------------------===##
Reid Spencer8141e372004-09-20 07:21:19 +000028
29if test $# -lt 1 ; then
Reid Spencer956dae82006-08-13 18:28:27 +000030 echo "Usage: llvmdo [-dirs "DIRNAMES..."] [-code-only] PROGRAM ARGS..."
Reid Spencer1e75b7b2006-08-11 21:53:27 +000031 exit 1
Reid Spencer8141e372004-09-20 07:21:19 +000032fi
33
34if test "$1" = "-dirs" ; then
35 LLVMDO_DIRS="$2";
36 shift ; shift
37elif test -z "$LLVMDO_DIRS" ; then
Reid Spencer33709e52004-09-20 08:00:09 +000038 LLVMDO_DIRS="include lib tools utils runtime autoconf docs test examples projects"
Reid Spencer8141e372004-09-20 07:21:19 +000039fi
Reid Spencer956dae82006-08-13 18:28:27 +000040
41if test "$1" = "-code-only" ; then
42 CODE_ONLY="set"
43 shift
44else
45 CODE_ONLY=""
46fi
47
Reid Spencer1e75b7b2006-08-11 21:53:27 +000048if test "$1" = "" ; then
49 echo "Missing program name to run"
50 exit 1
51fi
52
Reid Spencera60ff2e2004-07-26 22:52:44 +000053PROGRAM=`which $1`
Reid Spencer8141e372004-09-20 07:21:19 +000054if test ! -x "$PROGRAM" ; then
Reid Spencera60ff2e2004-07-26 22:52:44 +000055 echo "Can't execute $1"
56 exit 1
57fi
58shift;
Reid Spencer1e75b7b2006-08-11 21:53:27 +000059
60TOPDIR=`llvm-config --src-root`
61
Reid Spencera60ff2e2004-07-26 22:52:44 +000062if test -d "$TOPDIR" ; then
63 cd $TOPDIR
Reid Spencer054defa2004-10-07 16:03:21 +000064 case `uname -s` in
65 SunOS) find_prog=gfind ;;
66 *) find_prog=find ;;
67 esac
Reid Spencer956dae82006-08-13 18:28:27 +000068 paths_to_ignore="\
69 -path */CVS -o \
70 -path */CVS/* -o \
71 -path docs/doxygen/* -o \
72 -path docs/CommandGuide/html/* -o \
73 -path docs/CommandGuide/man/* -o \
74 -path docs/CommandGuide/ps/* -o \
75 -path docs/CommandGuide/man/* -o \
76 -path docs/HistoricalNotes/* -o \
77 -path docs/img/* -o \
78 -path */.libs/* -o \
79 -path lib/Support/bzip2/* -o \
80 -path projects/llvm-test/* \
81 "
82 files_to_match="\
83 -name *.ac \
84 -o -name *.b \
85 -o -name *.c \
86 -o -name *.cc \
87 -o -name *.cfg \
88 -o -name *.cpp \
89 -o -name *.css \
90 -o -name *.def \
91 -o -name *.el \
92 -o -name *.exp \
93 -o -name *.gnuplot' \
94 -o -name *.h \
95 -o -name *.in \
96 -o -name *.inc \
97 -o -name *.l \
98 -o -name *.ll \
99 -o -name *.llx \
100 -o -name *.lst \
101 -o -name *.m4 \
102 -o -name *.pl \
103 -o -name *.py \
104 -o -name *.sh \
105 -o -name *.schema \
106 -o -name *.st \
107 -o -name *.tcl \
108 -o -name *.td \
109 -o -name *.tr \
110 -o -name *.y \
111 -o -name Make* \
112 -o -name llvmdo \
113 -o -name llvmgrep \
114 -o -name check-each-file \
115 -o -name codgen-diff \
116 -o -name cvsupdate \
117 -o -name llvm-native-gcc \
118 -o -name llvm-native-gxx \
119 -o -name makellvm \
120 -o -path include/llvm/ADT/ilist \
121 -o -path test/\*.ll \
122 -o -path test/Scripts/not \
123 -o -path runtime/\*.ll \
124 "
125 if test -z "$CODE_ONLY" ; then
126 files_to_match="$files_to_match \
127 -o -name *.footer \
128 -o -name *.header \
129 -o -name *.html \
130 -o -name *.intro \
131 -o -name *.pod \
132 -o -name *.txt \
133 -o -name *.TXT \
134 -o -name *.vim \
135 -o -name vimrc \
136 -o -name README \
137 -o -name COPYING.LIB \
138 -o -name LICENSE* "
139 fi
140 files_to_ignore="\
141 -name \.* \
142 -o -name *~ \
143 -o -name #* \
144 -o -name *.cvs \
145 -o -name configure \
146 -o -name slow.ll \
147 -o -name *libtool* \
148 -o -name ltdl* \
149 -o -name ltdl.m4 \
150 -o -name ltmain.m4 \
151 -o -name ltmain.sh \
152 -o -name aclocal.m4 \
153 -o -name acinclude.m4 \
154 -o -name *VerifierIsReallySlow.llx \
155 -o -name *LoopSimplifyCrash.ll \
156 -o -name *AST-Remove.ll \
157 -o -name llvmAsmParser.cpp \
158 -o -name llvmAsmParser.h \
159 -o -name Lexer.cpp \
160 -o -name FileLexer.cpp \
161 -o -name FileParser.cpp \
162 -o -name FileParser.h \
163 -o -name StackerParser.h \
164 -o -name StackerParser.cpp \
165 -o -name ConfigLexer.cpp \
166 -o -name PPCPerfectShuffle.h \
167 "
168
169 # Turn off file name generation (globbing) so that substitution of the
170 # variables doesn't cause the shell to create lists of file names
171 set -f
Reid Spencer054defa2004-10-07 16:03:21 +0000172 $find_prog $LLVMDO_DIRS -type f \
Reid Spencer956dae82006-08-13 18:28:27 +0000173 \( $paths_to_ignore \) -prune \
174 -o \( \( $files_to_match \) \! \( $files_to_ignore \) \
175 -exec $PROGRAM "$@" {} \; \)
Reid Spencera60ff2e2004-07-26 22:52:44 +0000176else
177 echo "Can't find LLVM top directory in $TOPDIR"
178fi