blob: 9b1179b44e32e4ceba8a5888f1fcb213af882cb5 [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
30 echo "Usage: llvmdo [-dirs "DIRNAMES..."] PROGRAM ARGS...";
31 exit 1;
32fi
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 Spencera60ff2e2004-07-26 22:52:44 +000040PROGRAM=`which $1`
Reid Spencer8141e372004-09-20 07:21:19 +000041if test ! -x "$PROGRAM" ; then
Reid Spencera60ff2e2004-07-26 22:52:44 +000042 echo "Can't execute $1"
43 exit 1
44fi
45shift;
Reid Spencer09a053a2006-03-14 06:08:05 +000046TOPDIR=`pwd | sed -e 's#\(.*/llvm[0-9]*\).*#\1#'`
Reid Spencera60ff2e2004-07-26 22:52:44 +000047if test -d "$TOPDIR" ; then
48 cd $TOPDIR
Reid Spencer054defa2004-10-07 16:03:21 +000049 case `uname -s` in
50 SunOS) find_prog=gfind ;;
51 *) find_prog=find ;;
52 esac
53 $find_prog $LLVMDO_DIRS -type f \
Reid Spencer8141e372004-09-20 07:21:19 +000054 \( \
55 -path 'docs/doxygen/*' -o \
56 -path 'docs/CommandGuide/html/*' -o \
57 -path 'docs/CommandGuide/man/*' -o \
58 -path 'docs/CommandGuide/ps/*' -o \
59 -path 'docs/CommandGuide/man/*' -o \
60 -path 'docs/HistoricalNotes/*' -o \
Reid Spencer8141e372004-09-20 07:21:19 +000061 -path 'docs/img/*' -o \
62 -path '*/.libs/*' \
63 \) -prune -o \( \
Reid Spencer33709e52004-09-20 08:00:09 +000064 \( \
65 -name '*.cpp' -o \
66 -name '*.h' -o \
67 -name '*.def' -o \
68 -name '*.c' -o \
69 -name '*.l' -o \
70 -name '*.y' -o \
71 -name '*.td' -o \
72 -name '*.py' -o \
73 -name '*.pl' -o \
74 -name '*.sh' -o \
75 -name '*.lst' -o \
76 -name '*.pod' -o \
77 -name '*.html' -o \
78 -name '*.css' -o \
79 -name '*.cfg' -o \
80 -name '*.cc' -o \
81 -name '*.txt' -o \
82 -name '*.TXT' -o \
83 -name '*.el' -o \
84 -name '*.m4' -o \
85 -name '*.in' -o \
86 -name '*.ac' -o \
87 -name '*.tr' -o \
88 -name '*.vim' -o \
89 -name '*.gnuplot' -o \
90 -name 'Make*' -o \
91 -path 'test/*.ll' -o \
92 -path 'runtime/*.ll' \
93 \) \
Reid Spencer8141e372004-09-20 07:21:19 +000094 \! -name '.*' \
Reid Spencera60ff2e2004-07-26 22:52:44 +000095 \! -name '*~' \
96 \! -name '#*' \
Chris Lattner485a3502006-01-19 22:01:51 +000097 \! -name 'Lexer.cpp' \
Reid Spencera60ff2e2004-07-26 22:52:44 +000098 \! -name 'llvmAsmParser.cpp' \
99 \! -name 'llvmAsmParser.h' \
Chris Lattner485a3502006-01-19 22:01:51 +0000100 \! -name 'FileLexer.cpp' \
Reid Spencera60ff2e2004-07-26 22:52:44 +0000101 \! -name 'FileParser.cpp' \
102 \! -name 'FileParser.h' \
Reid Spencer8141e372004-09-20 07:21:19 +0000103 \! -name 'StackerParser.h' \
104 \! -name 'StackerParser.cpp' \
Chris Lattner485a3502006-01-19 22:01:51 +0000105 \! -name 'ConfigLexer.cpp' \
Chris Lattner2f976232006-04-17 00:46:09 +0000106 \! -name 'PPCPerfectShuffle.h' \
Reid Spencer761e41b2004-10-08 17:59:29 +0000107 -exec $PROGRAM "$@" {} \; \
Reid Spencer8141e372004-09-20 07:21:19 +0000108 \)
Reid Spencera60ff2e2004-07-26 22:52:44 +0000109else
110 echo "Can't find LLVM top directory in $TOPDIR"
111fi
Reid Spencer8141e372004-09-20 07:21:19 +0000112