Skip to content

Commit

Permalink
Updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaby76 committed Jun 25, 2024
1 parent e5ca411 commit 998ac7b
Show file tree
Hide file tree
Showing 6 changed files with 352 additions and 2 deletions.
31 changes: 30 additions & 1 deletion normalize-lexer-rules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ EXAMPLE USAGE
cd grammars-v4/abb
$(basename $0) *.g4
cd ../java/java20
trparse *.g4 | $(basename $0)
trparse -t ANTLRv4 *.g4 | $(basename $0)
EOF
exit 0
Expand All @@ -40,6 +40,34 @@ done
shift $((OPTIND - 1))
files=("$@")
temp=`mktemp`


# Determine if prerequisites are installed. Otherwise, output error and
# exit.
if ! command -v dotnet &> /dev/null
then
echo "'dotnet' could not be found. Install Microsoft NET."
exit 1
fi
# ... referenced in this file.
for tool in trparse trxgrep trrename trsponge
do
if ! command -v $tool &> /dev/null
then
echo "'$tool' could not be found. Install Trash Toolkit."
exit 1
fi
done
# ... referenced elsewhere.
for tool in trquery trunfold
do
if ! command -v $tool &> /dev/null
then
echo "'$tool' could not be found. Install Trash Toolkit."
exit 1
fi
done

if [ ${#files[@]} -gt 0 ]
then
trparse -t ANTLRv4 ${files[@]} > $temp
Expand All @@ -51,6 +79,7 @@ fi
full_path_script=$(realpath $0)
full_path_script_dir=`dirname $full_path_script`


cat $temp | trxgrep -e '
//lexerRuleSpec
/lexerRuleBlock
Expand Down
8 changes: 8 additions & 0 deletions strip-labels.xq
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
move //labeledAlt/(POUND | identifer)/@WS ./ancestor::labeledAlt;
delete //labeledAlt/(POUND | identifier);

move //labeledLexerElement/(identifier | ASSIGN | PLUS_ASSIGN)/@WS ./ancestor::labeledLexerElement;
delete //labeledLexerElement/(identifier | ASSIGN | PLUS_ASSIGN);

move //labeledElement/identifier/@WS ./ancestor::labeledElement;
delete //labeledElement/(identifier | ASSIGN | PLUS_ASSIGN);
2 changes: 1 addition & 1 deletion strip.xq
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ delete //rulePrequel;
delete //ruleReturns;
delete //exceptionGroup;
delete //throwsSpec;
delete //prequelConstruct;
(% delete //prequelConstruct; %)
delete //elementOptions;

move //actionBlock/@WS[1] ../..;
Expand Down
25 changes: 25 additions & 0 deletions wip/delete-unused-parser-symbols.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
if [[ $# -gt 0 ]]
then
echo Arguments were provided.
echo Finding unused parser symbols in grammars...
trparse -t ANTLRv4 $@ 2> /dev/null | trquery delete ' //parserRuleSpec
[not(doc("*")//ruleBlock//RULE_REF/text() = ./RULE_REF/text())
and not(./ruleBlock//TOKEN_REF/text() = "EOF")]' | trsponge -c
else
echo No arguments were provided.
echo Finding unused parser symbols in grammars...
for i in `find . -name desc.xml | grep -v Generated\*`
do
echo $i
d=`dirname $i`
pushd $d > /dev/null 2>&1
# Parse all grammar files so that any imports can also be checked.
trparse -t ANTLRv4 *.g4 2> /dev/null \
| trquery delete ' //parserRuleSpec
[not(doc("*")//ruleBlock//RULE_REF/text() = ./RULE_REF/text())
and not(./ruleBlock//TOKEN_REF/text() = "EOF")]' | trsponge -c
popd > /dev/null 2>&1
done
fi

135 changes: 135 additions & 0 deletions wip/p.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#

set -x
set -e

cwd=`pwd`

# Check requirements.
if ! command -v dotnet &> /dev/null
then
echo "'dotnet' could not be found. Install Microsoft NET."
exit 1
fi
if ! command -v trxml2 &> /dev/null
then
local=1
fi
if ! command -v dotnet trxml2 -- --version &> /dev/null
then
echo "'dotnet' could not be found. Install Microsoft NET."
exit 1
fi

while getopts 'a:b:' opt; do
case "$opt" in
a)
after="${OPTARG}"
;;
b)
before="${OPTARG}"
;;
esac
done

if [ "$after" == "" ]
then
echo "'after' not set."
exit 1
fi
if [ "$before" == "" ]
then
echo "'before' not set."
exit 1
fi

#############################
#############################
# Get last commit/pr. Note, some of the PR merges don't
# fit the pattern, but we'll ignore them. Get "prior" commit before all these
# changes.
prs=( After Before )
com=( $after $before )
echo PRS = ${prs[@]}
echo COM = ${com[@]}
echo '#PRS' = ${#prs[@]}
echo ${#com[@]}

echo Graphing out.
rm -f $cwd/xx.m
echo "pkg load statistics" >> $cwd/xx.m
for ((i=0; i<${#prs[@]}; i++))
do
xxx=${prs[$i]}
g=${com[$i]}
echo xxx $xxx
echo $g $g
echo "p$i=["`cat "$cwd/$xxx.txt"`"];" >> $cwd/xx.m
echo "mp$i=mean(p$i);" >> $cwd/xx.m
echo "sd$i=std(p$i);" >> $cwd/xx.m
echo "printf('disp($i)\n');" >> $cwd/xx.m
echo "disp($i);" >> $cwd/xx.m
echo "printf('disp(p$i)\n');" >> $cwd/xx.m
echo "disp(p$i);" >> $cwd/xx.m
echo "printf('mp$i = %f\n', mp$i);" >> $cwd/xx.m
echo "printf('sd$i = %f\n', sd$i);" >> $cwd/xx.m
done
echo -n "x = [" >> $cwd/xx.m
for ((i=1; i<=${#prs[@]}; i++))
do
echo -n " $i" >> $cwd/xx.m
done
echo "];" >> $cwd/xx.m
echo -n "str = [ " >> $cwd/xx.m
for ((i=0; i<${#prs[@]}; i++))
do
if [ "$i" != "0" ]; then echo -n "; " >> $cwd/xx.m; fi
echo -n " '"PR${prs[$i]}"'" >> $cwd/xx.m
done
echo " ];" >> $cwd/xx.m
echo -n "data = [" >> $cwd/xx.m
for ((i=0; i<${#prs[@]}; i++))
do
echo -n " mp$i" >> $cwd/xx.m
done
echo " ];" >> $cwd/xx.m
echo -n "errhigh = [" >> $cwd/xx.m
for ((i=0; i<${#prs[@]}; i++))
do
echo -n " sd$i" >> $cwd/xx.m
done
echo " ];" >> $cwd/xx.m
echo -n "errlow = [" >> $cwd/xx.m
for ((i=0; i<${#prs[@]}; i++))
do
echo -n " sd$i" >> $cwd/xx.m
done
echo " ];" >> $cwd/xx.m
cat >> $cwd/xx.m <<EOF
bar(x,data);
set(gca, 'XTickLabel', str, 'XTick', 1:numel(x));
hold on
er = errorbar(x,data,errlow,errhigh);
hold off
set(er, "color", [0 0 0])
set(er, "linewidth", 3);
set(er, "linestyle", "none");
set(gca, "fontsize", 6)
xlabel("Target");
ylabel("Runtime (s)");
title("Comparison of Runtimes")
print("./times-$g.svg", "-dsvg")
[pval, t, df] = welch_test(p0, p1)
if (abs(pval) < 0.03 && mp0/mp1 > 1.05)
printf("The PR statistically and practically decreased performance for $g.\n");
else
printf("The PR did not signficantly negatively alter performance for $g.\n");
endif
EOF
echo ========
cat $cwd/xx.m
echo ========
exit
cat $cwd/xx.m | octave --no-gui

exit 0
153 changes: 153 additions & 0 deletions wip/perf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#

set -x
set -e

cwd=`pwd`

# Check requirements.
if ! command -v dotnet &> /dev/null
then
echo "'dotnet' could not be found. Install Microsoft NET."
exit 1
fi
if ! command -v trxml2 &> /dev/null
then
local=1
fi
if ! command -v dotnet trxml2 -- --version &> /dev/null
then
echo "'dotnet' could not be found. Install Microsoft NET."
exit 1
fi

while getopts 'a:b:' opt; do
case "$opt" in
a)
after="${OPTARG}"
;;
b)
before="${OPTARG}"
;;
esac
done

if [ "$after" == "" ]
then
echo "'after' not set."
exit 1
fi
if [ "$before" == "" ]
then
echo "'before' not set."
exit 1
fi

#############################
#############################
# Get last commit/pr. Note, some of the PR merges don't
# fit the pattern, but we'll ignore them. Get "prior" commit before all these
# changes.
prs=( After Before )
com=( $after $before )
echo PRS = ${prs[@]}
echo COM = ${com[@]}
echo '#PRS' = ${#prs[@]}
echo ${#com[@]}

#===========================
for ((i=0; i<${#prs[@]}; i++))
do
echo $i
pushd "${com[$i]}"
xxx=${prs[$i]}
echo $xxx
rm -f $xxx
# Try first and scale number of times to work in 10 minutes tops.
# Format is in seconds, in floating point format.
runtime=`bash run.sh ../examples/*.on 2>&1 | grep "Total Time" | awk '{print $3}'`
times=`python -c "print(int(min(40,600/$runtime)))"`
for ((j=1;j<=times;j++)); do
bash run.sh ../examples/*.on 2>&1 | grep "Total Time" | awk '{print $3}' >> $cwd/$xxx.txt
done
popd
done

echo Graphing out.
rm -f $cwd/xx.m
echo "pkg load statistics" >> $cwd/xx.m
for ((i=0; i<${#prs[@]}; i++))
do
xxx=${prs[$i]}
g=${com[$i]}
echo xxx $xxx
echo $g $g
echo "p$i=["`cat "$cwd/$xxx.txt"`"];" >> $cwd/xx.m
echo "mp$i=mean(p$i);" >> $cwd/xx.m
echo "sd$i=std(p$i);" >> $cwd/xx.m
echo "printf('disp($i)\n');" >> $cwd/xx.m
echo "disp($i);" >> $cwd/xx.m
echo "printf('disp(p$i)\n');" >> $cwd/xx.m
echo "disp(p$i);" >> $cwd/xx.m
echo "printf('mp$i = %f\n', mp$i);" >> $cwd/xx.m
echo "printf('sd$i = %f\n', sd$i);" >> $cwd/xx.m
done
echo -n "x = [" >> $cwd/xx.m
for ((i=1; i<=${#prs[@]}; i++))
do
echo -n " $i" >> $cwd/xx.m
done
echo "];" >> $cwd/xx.m
echo -n "str = [ " >> $cwd/xx.m
for ((i=0; i<${#prs[@]}; i++))
do
if [ "$i" != "0" ]; then echo -n "; " >> $cwd/xx.m; fi
echo -n " '"PR${prs[$i]}"'" >> $cwd/xx.m
done
echo " ];" >> $cwd/xx.m
echo -n "data = [" >> $cwd/xx.m
for ((i=0; i<${#prs[@]}; i++))
do
echo -n " mp$i" >> $cwd/xx.m
done
echo " ];" >> $cwd/xx.m
echo -n "errhigh = [" >> $cwd/xx.m
for ((i=0; i<${#prs[@]}; i++))
do
echo -n " sd$i" >> $cwd/xx.m
done
echo " ];" >> $cwd/xx.m
echo -n "errlow = [" >> $cwd/xx.m
for ((i=0; i<${#prs[@]}; i++))
do
echo -n " sd$i" >> $cwd/xx.m
done
echo " ];" >> $cwd/xx.m
cat >> $cwd/xx.m <<EOF
bar(x,data);
set(gca, 'XTickLabel', str, 'XTick', 1:numel(x));
hold on
er = errorbar(x,data,errlow,errhigh);
hold off
set(er, "color", [0 0 0])
set(er, "linewidth", 3);
set(er, "linestyle", "none");
set(gca, "fontsize", 6)
xlabel("Target");
ylabel("Runtime (s)");
title("Comparison of Runtimes")
print("./times-$g.svg", "-dsvg")
[pval, t, df] = welch_test(p0, p1)
if (abs(pval) < 0.03 && mp0/mp1 > 1.05)
printf("The PR statistically and practically decreased performance for $g.\n");
else
printf("The PR did not signficantly negatively alter performance for $g.\n");
endif
EOF
echo ========
cat $cwd/xx.m
echo ========
exit
cat $cwd/xx.m | octave --no-gui

exit 0

0 comments on commit 998ac7b

Please sign in to comment.