/3rd_party/llvm/utils/llvmdo

https://code.google.com/p/softart/ · Shell · 184 lines · 135 code · 7 blank · 42 comment · 8 complexity · e55876b09dd8f41dec4580401b1a2f65 MD5 · raw file

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