COMP: update make rules for lemon, add helper infrastructure for ragel

This commit is contained in:
Mark Olesen
2019-09-27 11:05:35 +02:00
committed by Andrew Heather
parent f7528a2ac5
commit 4a6cd8f194
5 changed files with 189 additions and 16 deletions

View File

@ -1,9 +1,9 @@
SUFFIXES += .ly .lyy
lytoo = $E $(call QUIET_MESSAGE,lemon,$(<F)) \
$(WM_SCHEDULER) $(WM_SCRIPTS)/wrap-lemon -q $< $(AND) \
$(cc) $(cFLAGS) -c $(@D)/$(<F).c -o $@
$(WM_SCHEDULER) $(WM_SCRIPTS)/wrap-lemon -d$(@D) $< $(AND) \
$(cc) $(cFLAGS) -c $(@D)/$(*F).c -o $@
lyytoo = $E $(call QUIET_MESSAGE,lemon,$(<F)) \
$(WM_SCHEDULER) $(WM_SCRIPTS)/wrap-lemon -q $< $(AND) \
$(CC) $(c++FLAGS) -c $(@D)/$(<F).cc -o $@
$(WM_SCHEDULER) $(WM_SCRIPTS)/wrap-lemon -d$(@D) -ecc $< $(AND) \
$(CC) $(c++FLAGS) -c $(@D)/$(*F).cc -o $@

View File

@ -8,7 +8,7 @@ include $(GENERAL_RULES)/flex++
## include $(GENERAL_RULES)/byacc
## include $(GENERAL_RULES)/btyacc++
include $(GENERAL_RULES)/bison
## include $(GENERAL_RULES)/lemon
include $(GENERAL_RULES)/lemon
## include $(GENERAL_RULES)/ragel
include $(GENERAL_RULES)/moc
include $(GENERAL_RULES)/X

102
wmake/scripts/makeParser Executable file
View File

@ -0,0 +1,102 @@
#!/bin/sh
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
# \\/ M anipulation |
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
# <http://www.gnu.org/licenses/>.
#
# Script
# makeParser
#
# Description
# Pregenerate ragel code and/or lemon parser headers
#
#------------------------------------------------------------------------------
usage() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE
Usage: ${0##*/} [options]
options:
-parser=FILE Generate lemon parser header
-scanner=FILE Generate ragel scanner code
-remove Remove generated code
-h, -help Print the usage
Pregenerate ragel code and/or lemon parser headers
USAGE
exit 1
}
#------------------------------------------------------------------------------
# Parse arguments and options
#------------------------------------------------------------------------------
unset parser scanner optRemove
while [ "$#" -gt 0 ]
do
case "$1" in
(-h | -help*) usage ;;
(-parser=*) parser="${1#*=}" ;;
(-scanner=*) scanner="${1#*=}" ;;
(-remove) optRemove=true ;;
(*) break ;;
esac
shift
done
#------------------------------------------------------------------------------
# Remove file, with feedback. $1 = file, $2 = message
removeFile() {
if test -f "$1" && rm -f "$1" 2>/dev/null
then
echo "Removed generated $2 file"
else
echo "No generated $2 file to remove"
fi
}
case "$scanner" in
(*.rl)
output="${scanner%.*}.cc"
if [ "$optRemove" = true ]
then
removeFile "$output" "ragel scanner"
elif command -v ragel >/dev/null
then
echo "Generating ragel scanner"
ragel -G2 -o "$output" "$scanner"
else
echo "No ragel, leaving scanner intact"
fi
;;
esac
case "$parser" in
(*.ly | *.lyy)
output="${parser%.*}.h"
if [ "$optRemove" = true ]
then
removeFile "$output" "lemon header"
else
echo "Generating lemon parser header"
"$WM_PROJECT_DIR/wmake/scripts/wrap-lemon" -header "$parser"
fi
;;
esac
#------------------------------------------------------------------------------

View File

@ -49,20 +49,20 @@ usage() {
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE
Usage: ${0##*/} -file=<name> [bison-options]
Usage: ${0##*/} [options] [bison args/options]
options:
-input=NAME Perform the renaming actions
-output=NAME Perform the renaming actions
-h, -help Print the usage
A bison wrapper to handle renaming of the skeleton files
A bison wrapper with renaming of skeleton files
USAGE
exit 1
}
# The file extensions used
# File extensions used
extCode="cc"
extHead="hh"
@ -70,15 +70,15 @@ extHead="hh"
# Parse arguments and options
#------------------------------------------------------------------------------
# bison -input=... -output=...
# wrap-bison -input=... -output=...
unset inputFile outputFile
while [ "$#" -gt 0 ]
do
case "$1" in
(-h | -help*) usage ;;
(-input=*) inputFile="${1#*=}" ;;
(-output=*) outputFile="${1#*=}" ;;
(-input=*) inputFile="${1#*=}" ;;
(-output=*) outputFile="${1#*=}" ;;
(*) break ;;
esac
@ -112,7 +112,7 @@ then
outputFile="$(dirname ${inputFile})/${baseName}.$extCode"
fi
# Run bison in temporary directory (keeps files together)
# Execute in a temporary directory (keeps files together)
cwd="$(pwd -L)"
tmpDir="Make/bisonWrapper-$baseName"
rm -rf "$tmpDir" 2>/dev/null
@ -131,7 +131,7 @@ cd "../.." || exit 1
if [ "$rc" -ne 0 ]
then
rm -rf $tmpDir 2>/dev/null
rm -rf "$tmpDir" 2>/dev/null
exit "$rc" # Exit with bison return code
fi
@ -185,7 +185,7 @@ filterRename \
"${outputFile}"
rm -rf $tmpDir 2>/dev/null
rm -rf "$tmpDir" 2>/dev/null
exit "$rc" # Exit with bison return code
#------------------------------------------------------------------------------

View File

@ -25,10 +25,81 @@
binDir="${WMAKE_BIN:-$WM_PROJECT_DIR/wmake/platforms/$WM_ARCH$WM_COMPILER}"
etcDir="${WM_DIR:-$WM_PROJECT_DIR/wmake}/etc"
# Or another location
"$binDir/lemon" "-T${etcDir}/lempar.c" $*
# Executable and skeleton locations
lemon="$binDir/lemon"
skel="-T${etcDir}/lempar.c"
usage() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE
Usage: ${0##*/} [options] [lemon args/options]
options:
-header Generate header only, suppressing other output
-h, -help Print the usage
A lemon wrapper using predefined executable and skeleton locations
USAGE
exit 1
}
#------------------------------------------------------------------------------
# Parse arguments and options
#------------------------------------------------------------------------------
# wrap-lemon -header-only
unset optHeader
while [ "$#" -gt 0 ]
do
case "$1" in
(-h | -help*) usage ;;
(-header*) optHeader=true ;;
(*) break ;;
esac
shift
done
#------------------------------------------------------------------------------
# No special handling
if [ -z "$optHeader" ]
then
"$lemon" "$skel" $*
exit $?
fi
# Header only, which means we create a temp directory for the output
tmpDir="lemonWrapper-$$"
rm -rf "$tmpDir" 2>/dev/null
mkdir "$tmpDir" 2>/dev/null
# DO WE WANT THIS?
# trap 'rm -f $tmpDir 2>/dev/null; exit $rc' EXIT TERM INT
"$lemon" "$skel" "-d$tmpDir" $*
rc=$?
for src in "$tmpDir"/*.h
do
dst="${src##*/}"
if [ -f "$src" ]
then
if ! cmp "$src" "$dst" 2>/dev/null
then
mv "$src" "$dst"
echo "Updating $dst" 1>&2
fi
fi
done
rm -rf "$tmpDir" 2>/dev/null
exit "$rc" # Exit with lemon return code
#------------------------------------------------------------------------------