report multiple start sections in text representation as parsing error

This commit is contained in:
Ilya Rezvov
2021-03-12 22:56:23 -08:00
parent 50c7e90772
commit d36c6fddbc
2 changed files with 11 additions and 1 deletions
+10
View File
@@ -1501,6 +1501,7 @@ constInstructionToValue _ = error "Only const instructions supported as argument
desugarize :: [ModuleField] -> Either String S.Module
desugarize fields = do
checkImportsOrder fields
checkStartCount fields
let mod = Module {
types = reverse $ foldl' extractTypeDef (reverse $ explicitTypeDefs fields) fields,
functions = extract extractFunction fields,
@@ -1562,6 +1563,15 @@ desugarize fields = do
checkDef _ (MFMem _) = return True
checkDef _ (MFTable _) = return True
checkDef nonImportOccured _ = return nonImportOccured
checkStartCount :: [ModuleField] -> Either String ()
checkStartCount fields = foldM checkDef False fields >> return ()
where
checkDef startOccured (MFStart _) =
if startOccured
then Left "Multiple start sections"
else Right True
checkDef startOccured _ = return startOccured
extractTypeDef :: [TypeDef] -> ModuleField -> [TypeDef]
extractTypeDef defs (MFType _) = defs -- should be extracted before implicit defs
+1 -1
View File
@@ -17,7 +17,7 @@ import qualified Data.List as List
main :: IO ()
main = do
files <- filter (List.isSuffixOf ".wast") <$> Directory.listDirectory "tests/spec"
-- let files = ["linking.wast"]
-- let files = ["start.wast"]
scriptTestCases <- (`mapM` files) $ \file -> do
test <- LBS.readFile ("tests/spec/" ++ file)
return $ testCase file $ do