From 4e9105717ba27abbada1a20549ffc7ec9fc46917 Mon Sep 17 00:00:00 2001 From: Ilya Rezvov Date: Mon, 6 Jun 2022 18:41:22 -0600 Subject: [PATCH] parse externref elems, but fail on validation --- src/Language/Wasm/Parser.y | 11 ++++++----- src/Language/Wasm/Validate.hs | 2 ++ tests/Test.hs | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Language/Wasm/Parser.y b/src/Language/Wasm/Parser.y index 0003310..9160142 100644 --- a/src/Language/Wasm/Parser.y +++ b/src/Language/Wasm/Parser.y @@ -479,11 +479,11 @@ plaininstr :: { PlainInstr } Nothing -> TableInit (Index 0) $2 Just elemIdx -> TableInit $2 elemIdx } - | 'table.get' index { TableGet $2 } - | 'table.set' index { TableSet $2 } - | 'table.copy' index index { TableCopy $2 $3 } - | 'table.size' index { TableSize $2 } - | 'table.grow' index { TableGrow $2 } + | 'table.get' opt(index) { TableGet (fromMaybe (Index 0) $2) } + | 'table.set' opt(index) { TableSet (fromMaybe (Index 0) $2) } + | 'table.copy' opt(index) opt(index) { TableCopy (fromMaybe (Index 0) $2) (fromMaybe (Index 0) $3) } + | 'table.size' opt(index) { TableSize (fromMaybe (Index 0) $2) } + | 'table.grow' opt(index) { TableGrow (fromMaybe (Index 0) $2) } | 'elem.drop' index { ElemDrop $2 } -- numeric instructions | 'i32.const' int32 { I32Const $2 } @@ -977,6 +977,7 @@ elem1_active_offset :: { ([Instruction], ElemType, [[Instruction]]) } elemlist :: { (ElemType, [[Instruction]]) } : 'func' list(index) { (FuncRef, funcIndexToExpr $2) } | 'funcref' list(elemexpr) { (FuncRef, $2) } + | 'externref' { (ExternRef, []) } | list(index) { (FuncRef, funcIndexToExpr $1) } elemexpr :: { [Instruction] } diff --git a/src/Language/Wasm/Validate.hs b/src/Language/Wasm/Validate.hs index c8f068b..315e6bd 100644 --- a/src/Language/Wasm/Validate.hs +++ b/src/Language/Wasm/Validate.hs @@ -615,6 +615,8 @@ elemsShouldBeValid m@Module { elems, functions, tables, imports } = where isElemValid :: Ctx -> ElemSegment -> ValidationResult isElemValid ctx (ElemSegment elemType mode elements) = do + unless (elemType == FuncRef) + $ throwError $ RefTypeMismatch FuncRef elemType forM_ elements $ \elem -> runChecker ctx $ do arr <- getExpressionType elem isConstExpression elem diff --git a/tests/Test.hs b/tests/Test.hs index afdd538..eb17f3c 100644 --- a/tests/Test.hs +++ b/tests/Test.hs @@ -19,7 +19,7 @@ main = do files <- filter (not . List.isPrefixOf "simd") . filter (List.isSuffixOf ".wast") <$> Directory.listDirectory "tests/spec" - let files = ["table_copy.wast"] + let files = ["table_get.wast"] scriptTestCases <- (`mapM` files) $ \file -> do test <- LBS.readFile ("tests/spec/" ++ file) return $ testCase file $ do