blob: b8fcf88ac026fe3c4164105883398fa3185d1367 [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 Spencer1e75b7b2006-08-11 21:53:27 +000030 echo "Usage: llvmdo [-dirs "DIRNAMES..."] PROGRAM ARGS..."
31 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 Spencer1e75b7b2006-08-11 21:53:27 +000040if test "$1" = "" ; then
41 echo "Missing program name to run"
42 exit 1
43fi
44
Reid Spencera60ff2e2004-07-26 22:52:44 +000045PROGRAM=`which $1`
Reid Spencer8141e372004-09-20 07:21:19 +000046if test ! -x "$PROGRAM" ; then
Reid Spencera60ff2e2004-07-26 22:52:44 +000047 echo "Can't execute $1"
48 exit 1
49fi
50shift;
Reid Spencer1e75b7b2006-08-11 21:53:27 +000051
52TOPDIR=`llvm-config --src-root`
53
Reid Spencera60ff2e2004-07-26 22:52:44 +000054if test -d "$TOPDIR" ; then
55 cd $TOPDIR
Reid Spencer054defa2004-10-07 16:03:21 +000056 case `uname -s` in
57 SunOS) find_prog=gfind ;;
58 *) find_prog=find ;;
59 esac
60 $find_prog $LLVMDO_DIRS -type f \
Reid Spencer8141e372004-09-20 07:21:19 +000061 \( \
62 -path 'docs/doxygen/*' -o \
63 -path 'docs/CommandGuide/html/*' -o \
64 -path 'docs/CommandGuide/man/*' -o \
65 -path 'docs/CommandGuide/ps/*' -o \
66 -path 'docs/CommandGuide/man/*' -o \
67 -path 'docs/HistoricalNotes/*' -o \
Reid Spencer8141e372004-09-20 07:21:19 +000068 -path 'docs/img/*' -o \
69 -path '*/.libs/*' \
70 \) -prune -o \( \
Reid Spencer33709e52004-09-20 08:00:09 +000071 \( \
Reid Spencer2914a692006-08-11 23:51:05 +000072 -name '*.ac' -o \
73 -name '*.b' -o \
Reid Spencer33709e52004-09-20 08:00:09 +000074 -name '*.c' -o \
Reid Spencer33709e52004-09-20 08:00:09 +000075 -name '*.cc' -o \
Reid Spencer2914a692006-08-11 23:51:05 +000076 -name '*.cfg' -o \
77 -name '*.cpp' -o \
78 -name '*.css' -o \
79 -name '*.def' -o \
80 -name '*.el' -o \
81 -name '*.exp' -o \
82 -name '*.footer' -o \
83 -name '*.gnuplot' -o \
84 -name '*.h' -o \
85 -name '*.header' -o \
86 -name '*.html' -o \
87 -name '*.in' -o \
88 -name '*.inc' -o \
89 -name '*.intro' -o \
90 -name '*.l' -o \
91 -name '*.ll' -o \
92 -name '*.llx' -o \
93 -name '*.lst' -o \
94 -name '*.m4' -o \
95 -name '*.pl' -o \
96 -name '*.pod' -o \
97 -name '*.py' -o \
98 -name '*.sh' -o \
99 -name '*.schema' -o \
100 -name '*.tcl' -o \
101 -name '*.td' -o \
102 -name '*.tr' -o \
Reid Spencer33709e52004-09-20 08:00:09 +0000103 -name '*.txt' -o \
104 -name '*.TXT' -o \
Reid Spencer33709e52004-09-20 08:00:09 +0000105 -name '*.tr' -o \
106 -name '*.vim' -o \
Reid Spencer2914a692006-08-11 23:51:05 +0000107 -name '*.y' -o \
Reid Spencer33709e52004-09-20 08:00:09 +0000108 -name 'Make*' -o \
109 -path 'test/*.ll' -o \
110 -path 'runtime/*.ll' \
111 \) \
Reid Spencer8141e372004-09-20 07:21:19 +0000112 \! -name '.*' \
Reid Spencera60ff2e2004-07-26 22:52:44 +0000113 \! -name '*~' \
114 \! -name '#*' \
Reid Spencer2914a692006-08-11 23:51:05 +0000115 \! -name '*.cvs' \
116 \! -name 'configure' \
117 \! -name 'slow.ll' \
118 \! -name '*libtool*' \
119 \! -name 'ltdl*' \
120 \! -name 'ltdl.m4' \
121 \! -name 'ltmain.m4' \
122 \! -name 'ltmain.sh' \
123 \! -name 'aclocal.m4' \
124 \! -name 'acinclude.m4' \
125 \! -name '*VerifierIsReallySlow.llx' \
126 \! -name '*LoopSimplifyCrash.ll' \
127 \! -name '*AST-Remove.ll' \
Reid Spencera60ff2e2004-07-26 22:52:44 +0000128 \! -name 'llvmAsmParser.cpp' \
129 \! -name 'llvmAsmParser.h' \
Reid Spencer44771852006-08-11 23:58:58 +0000130 \! -name 'Lexer.cpp' \
Chris Lattner485a3502006-01-19 22:01:51 +0000131 \! -name 'FileLexer.cpp' \
Reid Spencera60ff2e2004-07-26 22:52:44 +0000132 \! -name 'FileParser.cpp' \
133 \! -name 'FileParser.h' \
Reid Spencer8141e372004-09-20 07:21:19 +0000134 \! -name 'StackerParser.h' \
135 \! -name 'StackerParser.cpp' \
Chris Lattner485a3502006-01-19 22:01:51 +0000136 \! -name 'ConfigLexer.cpp' \
Chris Lattner2f976232006-04-17 00:46:09 +0000137 \! -name 'PPCPerfectShuffle.h' \
Reid Spencer761e41b2004-10-08 17:59:29 +0000138 -exec $PROGRAM "$@" {} \; \
Reid Spencer8141e372004-09-20 07:21:19 +0000139 \)
Reid Spencera60ff2e2004-07-26 22:52:44 +0000140else
141 echo "Can't find LLVM top directory in $TOPDIR"
142fi