c01bbf22de
Remove another piece of PHP-dependant bootstrapping
100 linhas
3.5 KiB
Bash
Arquivo Executável
100 linhas
3.5 KiB
Bash
Arquivo Executável
#!/bin/sh
|
|
|
|
check_err()
|
|
{
|
|
if [ "$1" -ne "0" ]; then
|
|
echo "ERROR # $1 : $2" 1>&2
|
|
exit $1
|
|
fi
|
|
}
|
|
|
|
[ -z "$HPHP_HOME" ] && check_err 1 "HPHP_HOME environment variable not set"
|
|
|
|
VERBOSE=1
|
|
|
|
HHVM=$HPHP_HOME/hphp/hhvm/hhvm
|
|
if [ -x "$HHVM" ]; then
|
|
export HHVM_SYSTEMLIB=$HPHP_HOME/bin/systemlib.php
|
|
else
|
|
HHVM=`which hhvm`
|
|
export HHVM_SYSTEMLIB=`dirname $HHVM`/systemlib.php
|
|
fi
|
|
|
|
[ ! -x "$HHVM" ] && check_err 1 "$HHVM is not executable"
|
|
|
|
HPHP_TOOLS=$HPHP_HOME/hphp/tools/
|
|
|
|
if [ "$1" = "help" ]; then
|
|
echo "$0 lexer - Regenerate the lexer"
|
|
echo "$0 parser - Regenerate the parser"
|
|
echo "$0 license - Add license headers to all files"
|
|
echo ""
|
|
echo "$0 all - All of the above in listed order"
|
|
exit 0
|
|
fi
|
|
|
|
if [ "$1" = "lexer" -o "$1" = "all" ]; then
|
|
cd $HPHP_HOME/hphp/util/parser
|
|
[ $VERBOSE -eq 1 ] && echo "Generating lexer"
|
|
FLEX=`which flex`
|
|
if [ -x "$FLEX" ]; then
|
|
$FLEX -i -f -Phphp -R -8 --bison-locations -o lex.yy.cpp hphp.ll
|
|
check_err $? "Failed generating lexer"
|
|
else
|
|
echo "No flex with which to generate lexer"
|
|
fi
|
|
fi
|
|
|
|
if [ "$1" = "parser" -o "$1" = "all" ]; then
|
|
cd $HPHP_HOME/hphp/util/parser
|
|
BISON=`which bison`
|
|
SED=`which sed`
|
|
if [ -x "$BISON" -a -x "$SED" ]; then
|
|
[ $VERBOSE -eq 1 ] && echo "Generating parser"
|
|
$BISON -pCompiler --verbose --locations -d -onew_hphp.tab.cpp hphp.y
|
|
rm -f new_hphp.output
|
|
|
|
# Header
|
|
cat new_hphp.tab.hpp | \
|
|
$SED -r -e 's/(T_\w+) = ([0-9]+)/YYTOKEN(\2, \1)/' | \
|
|
$SED -e "s/^\s*enum yytokentype/#ifndef YYTOKEN_MAP\n#define YYTOKEN_MAP enum yytokentype\n#define YYTOKEN(num, name) name = num\n#endif\n YYTOKEN_MAP/" > new_hphp.tab.hpp.tmp
|
|
mv new_hphp.tab.hpp.tmp new_hphp.tab.hpp
|
|
cat new_hphp.tab.hpp | grep " YYTOKEN(" | head -n 1 | \
|
|
$SED -r -e 's/ YYTOKEN.([0-9]+).*/#ifndef YYTOKEN_MIN\n#define YYTOKEN_MIN \1\n#endif/' \
|
|
>> new_hphp.tab.hpp
|
|
cat new_hphp.tab.hpp | grep " YYTOKEN(" | tail -n 1 | \
|
|
$SED -r -e 's/ YYTOKEN.([0-9]+).*/#ifndef YYTOKEN_MAX\n#define YYTOKEN_MAX \1\n#endif/' \
|
|
>> new_hphp.tab.hpp
|
|
(diff -q hphp.tab.hpp new_hphp.tab.hpp >/dev/null ||
|
|
mv -f new_hphp.tab.hpp hphp.tab.hpp) &&
|
|
rm -f new_hphp.tab.hpp
|
|
|
|
# Implementation
|
|
cat new_hphp.tab.cpp | \
|
|
$SED -e "s/first_line/line0/g" \
|
|
-e "s/last_line/line1/g" \
|
|
-e "s/first_column/char0/g" \
|
|
-e "s/last_column/char1/g" \
|
|
-e "s/union/struct/g" \
|
|
-e "s/YYSTACK_ALLOC \(YYSTACK_BYTES \(yystacksize\)\);\n/YYSTACK_ALLOC \(YYSTACK_BYTES \(yystacksize\)\);\n memset(yyptr, 0, YYSTACK_BYTES (yystacksize));\n/" \
|
|
-e "s/YYSTACK_RELOCATE \(yyvs_alloc, yyvs\)/YYSTACK_RELOCATE_RESET (yyvs_alloc, yyvs)/" \
|
|
-e "s/YYSTACK_FREE \(yyss\)/YYSTACK_FREE (yyss);\n YYSTACK_CLEANUP/" \
|
|
> new_hphp.tab.cpp.tmp
|
|
mv new_hphp.tab.cpp.tmp new_hphp.tab.cpp
|
|
(diff -q new_hphp.tab.cpp ../../compiler/parser/hphp.tab.cpp >/dev/null ||
|
|
mv -f new_hphp.tab.cpp ../../compiler/parser/hphp.tab.cpp) &&
|
|
rm -f new_hphp.tab.cpp
|
|
else
|
|
[ $VERBOSE -eq 1 ] && echo "No bison/sed with which to generate parser"
|
|
fi
|
|
fi
|
|
|
|
if [ "$1" = "license" -o "$1" = "all" ]; then
|
|
cd $HPHP_HOME
|
|
[ $VERBOSE -eq 1 ] && echo "Updating license headers"
|
|
# TODO: At the moment, license.php fails on PCRE_ERROR_MATCHLIMIT
|
|
# Fix that script then change this to detect errors properly
|
|
$HHVM $HPHP_TOOLS/license.php 2>&1 | grep -v PCRE_ERROR_MATCHLIMIT
|
|
#check_err $? "Failed updating license headers"
|
|
fi
|