[commit: packages/hoopl] master: Fix parsing of memory accesses in tests (19526cc)

git at git.haskell.org git at git.haskell.org
Mon Dec 21 22:13:34 UTC 2015


Repository : ssh://git@git.haskell.org/hoopl

On branch  : master
Link       : http://git.haskell.org/packages/hoopl.git/commitdiff/19526cc258a8bef851d828ad038a4a40ab5b3c06

>---------------------------------------------------------------

commit 19526cc258a8bef851d828ad038a4a40ab5b3c06
Author: Michal Terepeta <michal.terepeta at gmail.com>
Date:   Sat Jun 27 16:32:12 2015 +0200

    Fix parsing of memory accesses in tests
    
    Apparently the current parser would fail on any memory accesses, both
    loads and stores. In case of the former it's enough to try parsing the
    memory accesses before variables. For stores, we can use backtracking
    so that we don't consume the initial "m" of memory assignemnt thinking
    that it's a variable identifier.


>---------------------------------------------------------------

19526cc258a8bef851d828ad038a4a40ab5b3c06
 testing/Main.hs              |  1 +
 testing/Parse.hs             | 14 ++++++--------
 testing/tests/test5          |  6 ++++++
 testing/tests/test5.expected |  6 ++++++
 4 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/testing/Main.hs b/testing/Main.hs
index 8b5d0ca..3728be6 100644
--- a/testing/Main.hs
+++ b/testing/Main.hs
@@ -30,6 +30,7 @@ goldensTests = Framework.testGroup "Goldens tests"
         , "test2"
         , "test3"
         , "test4"
+        , "test5"
         , "if-test"
         , "if-test2"
         , "if-test3"
diff --git a/testing/Parse.hs b/testing/Parse.hs
index 2d8594d..121734b 100644
--- a/testing/Parse.hs
+++ b/testing/Parse.hs
@@ -47,6 +47,9 @@ reservedOp = P.reservedOp lexer
 whitespace :: CharParser () ()
 whitespace = P.whiteSpace lexer
 
+brackets :: CharParser () a -> CharParser () a
+brackets = P.brackets lexer
+
 -- Expressions:
 expr :: Parser Expr
 expr = buildExpressionParser table factor
@@ -60,8 +63,8 @@ expr = buildExpressionParser table factor
     op o f assoc = Infix (do {reservedOp o; return f} <?> "operator") assoc
     factor =   parens expr
            <|> lit
-           <|> fetchVar
            <|> load
+           <|> fetchVar
            <?> "simple Expression"
 
 bool :: Parser Bool
@@ -75,12 +78,7 @@ lit =  (natural >>= (return . Lit . Int))
    <?> "lit"
 
 loc :: Char -> Parser x -> Parser x
-loc s addr = try (lexeme (do { char' s
-                             ; char' '['
-                             ; a <- addr
-                             ; char' ']'
-                             ; return a
-                             }))
+loc s addr = try (lexeme (char' s >> brackets addr))
           <?> "loc"
 
 var :: Parser String
@@ -104,7 +102,7 @@ labl = lexeme (do { id <- identifier
   <?> "label"
 
 mid :: Parser Insn
-mid =   asst
+mid =   try asst
     <|> store
     <?> "assignment or store"
 
diff --git a/testing/tests/test5 b/testing/tests/test5
new file mode 100644
index 0000000..49423b3
--- /dev/null
+++ b/testing/tests/test5
@@ -0,0 +1,6 @@
+-- Tests parsing of memory stores and loads.
+procName(mm, aa) {
+L0:
+  m[aa] = m[mm] + m[aa]
+  ret(m[aa])
+}
diff --git a/testing/tests/test5.expected b/testing/tests/test5.expected
new file mode 100644
index 0000000..49423b3
--- /dev/null
+++ b/testing/tests/test5.expected
@@ -0,0 +1,6 @@
+-- Tests parsing of memory stores and loads.
+procName(mm, aa) {
+L0:
+  m[aa] = m[mm] + m[aa]
+  ret(m[aa])
+}



More information about the ghc-commits mailing list