aboutsummaryrefslogtreecommitdiffstats
path: root/utils/llvmdo
blob: 9b1179b44e32e4ceba8a5888f1fcb213af882cb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/sh
##===- utils/llvmdo - Counts Lines Of Code -------------------*- Script -*-===##
# 
#                     The LLVM Compiler Infrastructure
#
# This file was developed by Reid Spencer and is distributed under the 
# University of Illinois Open Source License. See LICENSE.TXT for details.
# 
##===----------------------------------------------------------------------===##
#
# This script is a general purpose "apply" function for the source files in LLVM
# It uses "find" to locate all the source files and then applies the user's 
# command to them. As such, this command is often not used by itself much but
# the other find related tools (countloc.sh,llvmgrep,getsrcs.sh) are all based 
# on the implementation. This script defines "what is a source file" in LLVM and
# so should be maintained if new directories, new file extensions, etc. are 
# used in LLVM as it progresses.
#
# Usage:
#  llvmdo [-dirs "DIRNAMES..."] PROGRAM ARGS...
#
# The -dirs argument allows you to specify the set of directories that are 
# searched. By default, everything is searched. Note that you must use quotes
# around the list of directory names. After that you simply specify whatever
# program you want to run against each file and the arguments to give it. The
# PROGRAM will be given the file name as its last argument.
##===----------------------------------------------------------------------===##

if test $# -lt 1 ; then
  echo "Usage: llvmdo [-dirs "DIRNAMES..."] PROGRAM ARGS...";
  exit 1;
fi

if test "$1" = "-dirs" ; then
  LLVMDO_DIRS="$2";
  shift ; shift
elif test -z "$LLVMDO_DIRS" ; then
  LLVMDO_DIRS="include lib tools utils runtime autoconf docs test examples projects"
fi
PROGRAM=`which $1`
if test ! -x "$PROGRAM" ; then
  echo "Can't execute $1"
  exit 1
fi
shift;
TOPDIR=`pwd | sed -e 's#\(.*/llvm[0-9]*\).*#\1#'`
if test -d "$TOPDIR" ; then
  cd $TOPDIR
  case `uname -s` in
    SunOS) find_prog=gfind ;;
    *) find_prog=find ;;
  esac
  $find_prog $LLVMDO_DIRS -type f \
    \( \
      -path 'docs/doxygen/*' -o \
      -path 'docs/CommandGuide/html/*' -o \
      -path 'docs/CommandGuide/man/*' -o \
      -path 'docs/CommandGuide/ps/*' -o \
      -path 'docs/CommandGuide/man/*' -o \
      -path 'docs/HistoricalNotes/*' -o \
      -path 'docs/img/*' -o \
      -path '*/.libs/*' \
    \) -prune  -o \( \
      \( \
         -name '*.cpp' -o \
         -name '*.h' -o \
         -name '*.def' -o \
         -name '*.c' -o \
         -name '*.l' -o \
         -name '*.y' -o \
         -name '*.td' -o \
         -name '*.py' -o \
         -name '*.pl' -o \
         -name '*.sh' -o \
         -name '*.lst' -o \
         -name '*.pod' -o \
         -name '*.html' -o \
         -name '*.css' -o \
         -name '*.cfg' -o \
         -name '*.cc' -o \
         -name '*.txt' -o \
         -name '*.TXT' -o \
         -name '*.el' -o \
         -name '*.m4' -o \
         -name '*.in' -o \
         -name '*.ac' -o \
         -name '*.tr' -o \
         -name '*.vim' -o \
         -name '*.gnuplot' -o \
         -name 'Make*' -o \
         -path 'test/*.ll' -o \
         -path 'runtime/*.ll' \
      \) \
      \! -name '.*' \
      \! -name '*~' \
      \! -name '#*' \
      \! -name 'Lexer.cpp' \
      \! -name 'llvmAsmParser.cpp' \
      \! -name 'llvmAsmParser.h' \
      \! -name 'FileLexer.cpp' \
      \! -name 'FileParser.cpp' \
      \! -name 'FileParser.h' \
      \! -name 'StackerParser.h' \
      \! -name 'StackerParser.cpp' \
      \! -name 'ConfigLexer.cpp' \
      \! -name 'PPCPerfectShuffle.h' \
     -exec $PROGRAM "$@" {} \; \
    \)
else
  echo "Can't find LLVM top directory in $TOPDIR"
fi