summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladislav Zavialov <vlad.z.4096@gmail.com>2020-02-15 12:32:30 +0300
committerVladislav Zavialov <vlad.z.4096@gmail.com>2020-02-22 20:17:37 +0300
commita5ec380589c7e6dc9e3416b6409ad49153acdfff (patch)
tree610784e13d2cbdfe71cfe845182dcf6e71c87182
parent9d09411122b9b534b96e988b6d3f6d7eb04b8f66 (diff)
downloadhaskell-wip/pgmf.tar.gz
WIP: Use alex/happy as -pgmF preprocessorswip/pgmf
-rw-r--r--compiler/GHC/Cmm/Lexer.hs (renamed from compiler/GHC/Cmm/Lexer.x)2
-rw-r--r--compiler/GHC/Cmm/Parser.hs (renamed from compiler/GHC/Cmm/Parser.y)3
-rw-r--r--compiler/parser/Lexer.hs (renamed from compiler/parser/Lexer.x)2
-rw-r--r--compiler/parser/Parser.hs (renamed from compiler/parser/Parser.y)2
-rw-r--r--ghc.mk4
-rw-r--r--hadrian/src/Rules.hs4
-rw-r--r--hadrian/src/Rules/SourceDist.hs6
-rwxr-xr-xutils/alex.sh11
-rwxr-xr-xutils/happy.sh11
9 files changed, 31 insertions, 14 deletions
diff --git a/compiler/GHC/Cmm/Lexer.x b/compiler/GHC/Cmm/Lexer.hs
index d8f15b916c..eeb68459a2 100644
--- a/compiler/GHC/Cmm/Lexer.x
+++ b/compiler/GHC/Cmm/Lexer.hs
@@ -1,3 +1,5 @@
+{-# OPTIONS -pgmF utils/alex.sh -F #-}
+
-----------------------------------------------------------------------------
--
-- (c) The University of Glasgow, 2004-2006
diff --git a/compiler/GHC/Cmm/Parser.y b/compiler/GHC/Cmm/Parser.hs
index 69a2a9347e..8b35eda5ae 100644
--- a/compiler/GHC/Cmm/Parser.y
+++ b/compiler/GHC/Cmm/Parser.hs
@@ -6,6 +6,8 @@
--
-----------------------------------------------------------------------------
+{-# OPTIONS -pgmF utils/happy.sh -F #-}
+
{- -----------------------------------------------------------------------------
Note [Syntax of .cmm files]
@@ -261,7 +263,6 @@ import Data.Maybe
import qualified Data.Map as M
import qualified Data.ByteString.Char8 as BS8
-#include "HsVersions.h"
}
%expect 0
diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.hs
index 050a49c8c6..eea7706e0f 100644
--- a/compiler/parser/Lexer.x
+++ b/compiler/parser/Lexer.hs
@@ -1,3 +1,5 @@
+{-# OPTIONS -pgmF utils/alex.sh -F #-}
+
-----------------------------------------------------------------------------
-- (c) The University of Glasgow, 2006
--
diff --git a/compiler/parser/Parser.y b/compiler/parser/Parser.hs
index 73e3c52851..863d4481e1 100644
--- a/compiler/parser/Parser.y
+++ b/compiler/parser/Parser.hs
@@ -7,6 +7,8 @@
-- Author(s): Simon Marlow, Sven Panne 1997, 1998, 1999
-- ---------------------------------------------------------------------------
+{-# OPTIONS -pgmF utils/happy.sh -F #-}
+
{
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE TypeFamilies #-}
diff --git a/ghc.mk b/ghc.mk
index 53731ae64f..964adc2c43 100644
--- a/ghc.mk
+++ b/ghc.mk
@@ -1217,10 +1217,6 @@ sdist-ghc-prep-tree :
# Add files generated by alex and happy.
# These rules depend on sdist-ghc-prep-tree.
-$(eval $(call sdist-ghc-file,compiler,stage2,.,GHC/Cmm/Lexer,x))
-$(eval $(call sdist-ghc-file,compiler,stage2,.,GHC/Cmm/Parser,y))
-$(eval $(call sdist-ghc-file,compiler,stage2,parser,Lexer,x))
-$(eval $(call sdist-ghc-file,compiler,stage2,parser,Parser,y))
$(eval $(call sdist-ghc-file,utils/hpc,dist-install,,HpcParser,y))
$(eval $(call sdist-ghc-file,utils/genprimopcode,dist,,Lexer,x))
$(eval $(call sdist-ghc-file,utils/genprimopcode,dist,,Parser,y))
diff --git a/hadrian/src/Rules.hs b/hadrian/src/Rules.hs
index 9b9f7557f3..4a3ec0a6aa 100644
--- a/hadrian/src/Rules.hs
+++ b/hadrian/src/Rules.hs
@@ -52,10 +52,6 @@ toolArgsTarget = do
root <- buildRoot
let dir = buildDir (vanillaContext Stage0 compiler)
need [ root -/- dir -/- "Config.hs" ]
- need [ root -/- dir -/- "Parser.hs" ]
- need [ root -/- dir -/- "Lexer.hs" ]
- need [ root -/- dir -/- "GHC" -/- "Cmm" -/- "Parser.hs" ]
- need [ root -/- dir -/- "GHC" -/- "Cmm" -/- "Lexer.hs" ]
-- Find out the arguments that are needed to load a module into the
-- session
diff --git a/hadrian/src/Rules/SourceDist.hs b/hadrian/src/Rules/SourceDist.hs
index b844c54c8a..4943b49418 100644
--- a/hadrian/src/Rules/SourceDist.hs
+++ b/hadrian/src/Rules/SourceDist.hs
@@ -136,11 +136,7 @@ prepareTree dest = do
-- (stage, package, input file, output file)
alexHappyFiles =
- [ (Stage0, compiler, "GHC/Cmm/Parser.y", "GHC/Cmm/Parser.hs")
- , (Stage0, compiler, "GHC/Cmm/Lexer.x", "GHC/Cmm/Lexer.hs")
- , (Stage0, compiler, "parser/Parser.y", "Parser.hs")
- , (Stage0, compiler, "parser/Lexer.x", "Lexer.hs")
- , (Stage0, hpcBin, "HpcParser.y", "HpcParser.hs")
+ [ (Stage0, hpcBin, "HpcParser.y", "HpcParser.hs")
, (Stage0, genprimopcode, "Parser.y", "Parser.hs")
, (Stage0, genprimopcode, "Lexer.x", "Lexer.hs")
]
diff --git a/utils/alex.sh b/utils/alex.sh
new file mode 100755
index 0000000000..5f9f24f080
--- /dev/null
+++ b/utils/alex.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+
+set -e
+
+rm -f "$3"
+F2=$(mktemp --suffix=".x")
+F3=$(mktemp --suffix=".hs")
+tail -n +2 "$2" > "$F2"
+alex -g --latin1 -o "$F3" "$F2"
+ghc -E "$F3" -o "$3" # needed because alex spits out ifdef WORDS_BIGENDIAN conditionals
+rm "$F2" "$F3"
diff --git a/utils/happy.sh b/utils/happy.sh
new file mode 100755
index 0000000000..093dd1977b
--- /dev/null
+++ b/utils/happy.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+
+set -e
+
+rm -f "$3"
+F2=$(mktemp --suffix=".y")
+F3=$(mktemp --suffix=".hs")
+cp "$2" "$F2" # needed because happy rejects files that do not have the .y extension
+happy -agc --strict --outfile="$F3" "$F2"
+ghc -E "$F3" -o "$3" # needed because happy spits out #if __GLASGOW_HASKELL__ >= 710 conditionals
+rm "$F2" "$F3"