reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    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
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176
  177
  178
  179
  180
  181
  182
  183
#!/bin/sh
##===- utils/llvmdo - Counts Lines Of Code -------------------*- Script -*-===##
# 
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# 
##===----------------------------------------------------------------------===##
#
# 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,userloc.sh) are
# all based on this script.  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 [-topdir DIR] [-dirs "DIRNAMES..."] [-code-only] PROGRAM ARGS...
#
# The -topdir option allows you to specify the llvm source root directly. If it
# is not specified then it will be obtained with llvm-config which must be built
# and in your path.
#
# The -dirs argument allows you to specify the set of directories that are 
# searched. The default list of directories searched is:
#   include lib tools utils runtime autoconf docs test examples projects
# Note that you must use quotes around the list of directory names. 
#
# The -code-only option specifies that only those files that are considered 
# "code" should be visited. HTML documentation is considered code, but things 
# like README files, etc. are not.
#
# Finally, 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 [-topdir DIR] [-dirs "DIRNAMES..."] [-code-only] PROGRAM ARGS..."
  exit 1
fi

if test "$1" = "-topdir" ; then
  TOPDIR="$2"
  shift; shift;
else
  TOPDIR=`llvm-config --src-root`
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 cmake"
fi

if test "$1" = "-code-only" ; then
  CODE_ONLY="set"
  shift
else
  CODE_ONLY=""
fi

if test "$1" = "" ; then
  echo "Missing program name to run"
  exit 1
fi

PROGRAM=`which $1`
if test ! -x "$PROGRAM" ; then
  echo "Can't execute $1"
  exit 1
fi
shift;

paths_to_ignore="\
  -path */.svn/ -o \
  -path */.svn/* -o \
  -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/* -o \
  -path lib/Support/bzip2/* -o \
  -path projects/llvm-test/* \
"
files_to_match="\
     -name *.ac \
  -o -name *.b \
  -o -name *.c \
  -o -name *.cc \
  -o -name *.cfg \
  -o -name *.cpp \
  -o -name *.css \
  -o -name *.def \
  -o -name *.el \
  -o -name *.exp \
  -o -name *.footer \
  -o -name *.gnuplot' \
  -o -name *.h \
  -o -name *.header \
  -o -name *.html \
  -o -name *.in \
  -o -name *.inc \
  -o -name *.intro \
  -o -name *.l \
  -o -name *.ll \
  -o -name *.lst \
  -o -name *.m4 \
  -o -name *.pod \
  -o -name *.pl \
  -o -name *.py \
  -o -name *.sh \
  -o -name *.schema \
  -o -name *.st \
  -o -name *.tcl \
  -o -name *.td \
  -o -name *.tr \
  -o -name *.y \
  -o -name Make* \
  -o -name *.cmake \
  -o -name llvmdo \
  -o -name llvmgrep \
  -o -name check-each-file \
  -o -name codgen-diff \
  -o -name llvm-native-gcc \
  -o -name llvm-native-gxx \
  -o -name makellvm \
  -o -path include/llvm/ADT/ilist \
  -o -path test/\*.ll \
  -o -path test/Scripts/not \
  -o -path runtime/\*.ll \
"
if test -z "$CODE_ONLY" ; then
  files_to_match="$files_to_match \
    -o -name *.txt \
    -o -name *.TXT \
    -o -name *.vim \
    -o -name vimrc \
    -o -name README \
    -o -name COPYING.LIB \
    -o -name LICENSE* "
fi
files_to_ignore="\
     -name \.* \
  -o -name *~ \
  -o -name #* \
  -o -name configure \
  -o -name slow.ll \
  -o -name *libtool* \
  -o -name ltdl* \
  -o -name ltdl.m4 \
  -o -name ltmain.m4 \
  -o -name ltmain.sh \
  -o -name aclocal.m4 \
  -o -name acinclude.m4 \
  -o -name *LoopSimplifyCrash.ll \
  -o -name *AST-Remove.ll \
  -o -name PPCPerfectShuffle.h \
"

if test -d "$TOPDIR" ; then
  cd $TOPDIR
  # Have to use the right "find" on a per-platform basis. Most platforms have
  # Gnu find as "find", but Solaris does not.
  case `uname -s` in
    SunOS) find_prog=gfind ;;
    *) find_prog=find ;;
  esac
  # Turn off file name generation (globbing) so that substitution of the
  # variables doesn't cause the shell to create lists of file names
  set -f
  $find_prog $LLVMDO_DIRS -type f \
    \( $paths_to_ignore \) -prune \
    -o \( \( $files_to_match \) \! \( $files_to_ignore \) \
    -exec $PROGRAM "$@" {} \; \)
else
  echo "Can't find LLVM top directory in $TOPDIR"
fi