#!/bin/sh ##===- utils/countloc.sh - Counts Lines Of Code --------------*- Script -*-===## # # The LLVM Compiler Infrastructure # # This file is distributed under the University of Illinois Open Source # License. See LICENSE.TXT for details. # ##===----------------------------------------------------------------------===## # # This script finds all the source code files in the source code directories # (excluding certain things), runs "wc -l" on them to get the number of lines in # each file and then sums up and prints the total with awk. # # The script takes one optional option, -topdir, which specifies the top llvm # source directory. If it is not specified then the llvm-config tool is # consulted to find top source dir. # # Note that the implementation is based on llvmdo. See that script for more # details. ##===----------------------------------------------------------------------===## if test $Argc -gt 1 { if test $1 = "-topdir" { global TOPDIR := $2 shift; shift; } else { global TOPDIR := $[llvm-config --src-root] } } if test -d $TOPDIR { cd $TOPDIR ./utils/llvmdo -topdir $TOPDIR -dirs "include lib tools test utils examples" -code-only wc -l | awk '\ BEGIN { loc=0; } \ { loc += $1; } \ END { print loc; }' } else { echo "Can't find LLVM top directory" } (CommandList children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(test)} {($ VSub_Pound "$#")} {(-gt)} {(1)}) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(test)} {(DQ ($ VSub_Number "$1"))} {(Lit_Other "=")} {(DQ (-topdir))}) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TOPDIR) op: Equal rhs: {(DQ ($ VSub_Number "$2"))} spids: [98] ) ] spids: [98] ) (Sentence child:(C {(shift)}) terminator:) (Sentence child:(C {(shift)}) terminator:) ] spids: [-1 95] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TOPDIR) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(llvm-config)} {(--src-root)})]) left_token: spids: [115 119] ) } spids: [114] ) ] spids: [114] ) ] spids: [111 122] ) ] spids: [-1 76] ) ] spids: [-1 124] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(test)} {(-d)} {(DQ ($ VSub_Name "$TOPDIR"))}) terminator: ) ] action: [ (C {(cd)} {($ VSub_Name "$TOPDIR")}) (Pipeline children: [ (C {(./utils/llvmdo)} {(-topdir)} {(DQ ($ VSub_Name "$TOPDIR"))} {(-dirs)} {(DQ ("include lib tools test utils examples"))} {(-code-only)} {(wc)} {(-l)} ) (C {(awk)} { (SQ <"\\\n"> <" BEGIN { loc=0; } \\\n"> <" { loc += $1; } \\\n"> <" END { print loc; }"> ) } ) ] negated: False ) ] spids: [-1 139] ) ] else_action: [(C {(echo)} {(DQ ("Can't find LLVM top directory"))})] spids: [178 187] ) ] )