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