diff --git a/src/Language/SystemVerilog/Parser/ParseDecl.hs b/src/Language/SystemVerilog/Parser/ParseDecl.hs index 0c88de3..3ac79a6 100644 --- a/src/Language/SystemVerilog/Parser/ParseDecl.hs +++ b/src/Language/SystemVerilog/Parser/ParseDecl.hs @@ -116,14 +116,33 @@ parseDTsAsPortDecls pieces = parseDTsAsModuleItems :: [DeclToken] -> [ModuleItem] parseDTsAsModuleItems tokens = forbidNonEqAsgn tokens $ - if any isInstance tokens - then parseDTsAsIntantiations tokens - else map (MIPackageItem . Decl) $ parseDTsAsDecl tokens + if isElabTask $ head tokens then + asElabTask tokens + else if any isInstance tokens then + parseDTsAsIntantiations tokens + else + map (MIPackageItem . Decl) $ parseDTsAsDecl tokens where + isElabTask :: DeclToken -> Bool + isElabTask (DTIdent x) = elem x elabTasks + where elabTasks = ["$fatal", "$error", "$warning", "$info"] + isElabTask _ = False isInstance :: DeclToken -> Bool isInstance (DTInstance _) = True isInstance _ = False +-- internal; approximates the behavior of the elaboration system tasks +asElabTask :: [DeclToken] -> [ModuleItem] +asElabTask [DTIdent name, DTInstance args] = + if name == "$info" + then [] -- just drop them for simplicity + else [Instance "ThisModuleDoesNotExist" [] name' Nothing args] + where name' = "__sv2v_elab_" ++ tail name +asElabTask [DTIdent name] = + asElabTask [DTIdent name, DTInstance []] +asElabTask tokens = + error $ "could not parse elaboration system task: " ++ show tokens + -- internal; parser for module instantiations parseDTsAsIntantiations :: [DeclToken] -> [ModuleItem] @@ -142,7 +161,8 @@ parseDTsAsIntantiations (DTIdent name : tokens) = [DTIdent a, DTRange (NonIndexed, s), DTInstance b] -> (a, Just s , b) [DTIdent a, DTInstance b] -> (a, Nothing, b) - _ -> error $ "unrecognized instantiation: " ++ show inst + _ -> error $ "unrecognized instantiation of " ++ name + ++ ": " ++ show inst follow = x `seq` if null toks' then [] else step (tail toks') (params, rest) = case head tokens of diff --git a/test/basic/elab_task.sv b/test/basic/elab_task.sv new file mode 100644 index 0000000..381a427 --- /dev/null +++ b/test/basic/elab_task.sv @@ -0,0 +1,6 @@ +module top; + if (1 == 0) + wire foo; + else + $info("foo"); +endmodule diff --git a/test/basic/elab_task.v b/test/basic/elab_task.v new file mode 100644 index 0000000..4a271fc --- /dev/null +++ b/test/basic/elab_task.v @@ -0,0 +1,2 @@ +module top; +endmodule