xref: /llvm-project-15.0.7/llvm/utils/llvmdo (revision 823a00a8)
1#!/bin/sh
2##===- 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:
20#  llvmdo [-dirs "DIRNAMES..."] PROGRAM ARGS...
21#
22# The -dirs argument allows you to specify the set of directories that are
23# 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##===----------------------------------------------------------------------===##
28
29if test $# -lt 1 ; then
30  echo "Usage: llvmdo [-dirs "DIRNAMES..."] PROGRAM ARGS...";
31  exit 1;
32fi
33
34if test "$1" = "-dirs" ; then
35  LLVMDO_DIRS="$2";
36  shift ; shift
37elif test -z "$LLVMDO_DIRS" ; then
38  LLVMDO_DIRS="include lib tools utils runtime autoconf docs test examples projects"
39fi
40PROGRAM=`which $1`
41if test ! -x "$PROGRAM" ; then
42  echo "Can't execute $1"
43  exit 1
44fi
45shift;
46TOPDIR=`pwd | sed -e 's#\(.*/llvm\).*#\1#'`
47if test -d "$TOPDIR" ; then
48  cd $TOPDIR
49  case `uname -s` in
50    SunOS) find_prog=gfind ;;
51    *) find_prog=find ;;
52  esac
53  $find_prog $LLVMDO_DIRS -type f \
54    \( \
55      -path 'docs/doxygen/*' -o \
56      -path 'docs/CommandGuide/html/*' -o \
57      -path 'docs/CommandGuide/man/*' -o \
58      -path 'docs/CommandGuide/ps/*' -o \
59      -path 'docs/CommandGuide/man/*' -o \
60      -path 'docs/HistoricalNotes/*' -o \
61      -path 'utils/Burg/*' -o \
62      -path 'docs/img/*' -o \
63      -path '*/.libs/*' \
64    \) -prune  -o \( \
65      \( \
66         -name '*.cpp' -o \
67         -name '*.h' -o \
68         -name '*.def' -o \
69         -name '*.c' -o \
70         -name '*.l' -o \
71         -name '*.y' -o \
72         -name '*.td' -o \
73         -name '*.py' -o \
74         -name '*.pl' -o \
75         -name '*.sh' -o \
76         -name '*.lst' -o \
77         -name '*.pod' -o \
78         -name '*.html' -o \
79         -name '*.css' -o \
80         -name '*.cfg' -o \
81         -name '*.cc' -o \
82         -name '*.txt' -o \
83         -name '*.TXT' -o \
84         -name '*.el' -o \
85         -name '*.m4' -o \
86         -name '*.in' -o \
87         -name '*.ac' -o \
88         -name '*.tr' -o \
89         -name '*.vim' -o \
90         -name '*.gnuplot' -o \
91         -name 'Make*' -o \
92         -path 'test/*.ll' -o \
93         -path 'runtime/*.ll' \
94      \) \
95      \! -name '.*' \
96      \! -name '*~' \
97      \! -name '#*' \
98      \! -name 'Sparc.burm.c' \
99      \! -name 'Lexer.cpp' \
100      \! -name 'llvmAsmParser.cpp' \
101      \! -name 'llvmAsmParser.h' \
102      \! -name 'FileLexer.cpp' \
103      \! -name 'FileParser.cpp' \
104      \! -name 'FileParser.h' \
105      \! -name 'StackerParser.h' \
106      \! -name 'StackerParser.cpp' \
107      \! -name 'ConfigLexer.cpp' \
108     -exec $PROGRAM "$@" {} \; \
109    \)
110else
111  echo "Can't find LLVM top directory in $TOPDIR"
112fi
113
114