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 |
| 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 Brukman | ef7dd46 | 2004-10-08 01:11:15 +0000 | [diff] [blame] | 20 | # llvmdo [-dirs "DIRNAMES..."] PROGRAM ARGS... |
Reid Spencer | 33709e5 | 2004-09-20 08:00:09 +0000 | [diff] [blame] | 21 | # |
| 22 | # The -dirs argument allows you to specify the set of directories that are |
Reid Spencer | 9610fc9 | 2004-09-20 08:04:13 +0000 | [diff] [blame] | 23 | # 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 Spencer | 8141e37 | 2004-09-20 07:21:19 +0000 | [diff] [blame] | 28 | |
| 29 | if test $# -lt 1 ; then |
| 30 | echo "Usage: llvmdo [-dirs "DIRNAMES..."] PROGRAM ARGS..."; |
| 31 | exit 1; |
| 32 | fi |
| 33 | |
| 34 | if test "$1" = "-dirs" ; then |
| 35 | LLVMDO_DIRS="$2"; |
| 36 | shift ; shift |
| 37 | elif test -z "$LLVMDO_DIRS" ; then |
Reid Spencer | 33709e5 | 2004-09-20 08:00:09 +0000 | [diff] [blame] | 38 | LLVMDO_DIRS="include lib tools utils runtime autoconf docs test examples projects" |
Reid Spencer | 8141e37 | 2004-09-20 07:21:19 +0000 | [diff] [blame] | 39 | fi |
Reid Spencer | a60ff2e | 2004-07-26 22:52:44 +0000 | [diff] [blame] | 40 | PROGRAM=`which $1` |
Reid Spencer | 8141e37 | 2004-09-20 07:21:19 +0000 | [diff] [blame] | 41 | if test ! -x "$PROGRAM" ; then |
Reid Spencer | a60ff2e | 2004-07-26 22:52:44 +0000 | [diff] [blame] | 42 | echo "Can't execute $1" |
| 43 | exit 1 |
| 44 | fi |
| 45 | shift; |
Reid Spencer | 09a053a | 2006-03-14 06:08:05 +0000 | [diff] [blame] | 46 | TOPDIR=`pwd | sed -e 's#\(.*/llvm[0-9]*\).*#\1#'` |
Reid Spencer | a60ff2e | 2004-07-26 22:52:44 +0000 | [diff] [blame] | 47 | if test -d "$TOPDIR" ; then |
| 48 | cd $TOPDIR |
Reid Spencer | 054defa | 2004-10-07 16:03:21 +0000 | [diff] [blame] | 49 | case `uname -s` in |
| 50 | SunOS) find_prog=gfind ;; |
| 51 | *) find_prog=find ;; |
| 52 | esac |
| 53 | $find_prog $LLVMDO_DIRS -type f \ |
Reid Spencer | 8141e37 | 2004-09-20 07:21:19 +0000 | [diff] [blame] | 54 | \( \ |
| 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 Spencer | 8141e37 | 2004-09-20 07:21:19 +0000 | [diff] [blame] | 61 | -path 'docs/img/*' -o \ |
| 62 | -path '*/.libs/*' \ |
| 63 | \) -prune -o \( \ |
Reid Spencer | 33709e5 | 2004-09-20 08:00:09 +0000 | [diff] [blame] | 64 | \( \ |
| 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 Spencer | 8141e37 | 2004-09-20 07:21:19 +0000 | [diff] [blame] | 94 | \! -name '.*' \ |
Reid Spencer | a60ff2e | 2004-07-26 22:52:44 +0000 | [diff] [blame] | 95 | \! -name '*~' \ |
| 96 | \! -name '#*' \ |
Chris Lattner | 485a350 | 2006-01-19 22:01:51 +0000 | [diff] [blame] | 97 | \! -name 'Lexer.cpp' \ |
Reid Spencer | a60ff2e | 2004-07-26 22:52:44 +0000 | [diff] [blame] | 98 | \! -name 'llvmAsmParser.cpp' \ |
| 99 | \! -name 'llvmAsmParser.h' \ |
Chris Lattner | 485a350 | 2006-01-19 22:01:51 +0000 | [diff] [blame] | 100 | \! -name 'FileLexer.cpp' \ |
Reid Spencer | a60ff2e | 2004-07-26 22:52:44 +0000 | [diff] [blame] | 101 | \! -name 'FileParser.cpp' \ |
| 102 | \! -name 'FileParser.h' \ |
Reid Spencer | 8141e37 | 2004-09-20 07:21:19 +0000 | [diff] [blame] | 103 | \! -name 'StackerParser.h' \ |
| 104 | \! -name 'StackerParser.cpp' \ |
Chris Lattner | 485a350 | 2006-01-19 22:01:51 +0000 | [diff] [blame] | 105 | \! -name 'ConfigLexer.cpp' \ |
Chris Lattner | 2f97623 | 2006-04-17 00:46:09 +0000 | [diff] [blame] | 106 | \! -name 'PPCPerfectShuffle.h' \ |
Reid Spencer | 761e41b | 2004-10-08 17:59:29 +0000 | [diff] [blame] | 107 | -exec $PROGRAM "$@" {} \; \ |
Reid Spencer | 8141e37 | 2004-09-20 07:21:19 +0000 | [diff] [blame] | 108 | \) |
Reid Spencer | a60ff2e | 2004-07-26 22:52:44 +0000 | [diff] [blame] | 109 | else |
| 110 | echo "Can't find LLVM top directory in $TOPDIR" |
| 111 | fi |
Reid Spencer | 8141e37 | 2004-09-20 07:21:19 +0000 | [diff] [blame] | 112 | |