From 4a6cd8f1946837f7ebdac91b8dcad8c41410d4e7 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 27 Sep 2019 11:05:35 +0200 Subject: [PATCH] COMP: update make rules for lemon, add helper infrastructure for ragel --- wmake/rules/General/lemon | 8 +-- wmake/rules/General/standard | 2 +- wmake/scripts/makeParser | 102 +++++++++++++++++++++++++++++++++++ wmake/scripts/wrap-bison | 18 +++---- wmake/scripts/wrap-lemon | 75 +++++++++++++++++++++++++- 5 files changed, 189 insertions(+), 16 deletions(-) create mode 100755 wmake/scripts/makeParser diff --git a/wmake/rules/General/lemon b/wmake/rules/General/lemon index 9c2a5096b4..57cb0ad5a1 100644 --- a/wmake/rules/General/lemon +++ b/wmake/rules/General/lemon @@ -1,9 +1,9 @@ SUFFIXES += .ly .lyy lytoo = $E $(call QUIET_MESSAGE,lemon,$(. +# +# Script +# makeParser +# +# Description +# Pregenerate ragel code and/or lemon parser headers +# +#------------------------------------------------------------------------------ +usage() { + exec 1>&2 + while [ "$#" -ge 1 ]; do echo "$1"; shift; done + cat</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 + +#------------------------------------------------------------------------------ diff --git a/wmake/scripts/wrap-bison b/wmake/scripts/wrap-bison index ae4ec0b862..bf65e816e6 100755 --- a/wmake/scripts/wrap-bison +++ b/wmake/scripts/wrap-bison @@ -49,20 +49,20 @@ usage() { while [ "$#" -ge 1 ]; do echo "$1"; shift; done cat< [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 #------------------------------------------------------------------------------ diff --git a/wmake/scripts/wrap-lemon b/wmake/scripts/wrap-lemon index 7a16d2e603..3f1b8ae05b 100755 --- a/wmake/scripts/wrap-lemon +++ b/wmake/scripts/wrap-lemon @@ -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</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 #------------------------------------------------------------------------------