Commit ac548cac by Zachary Snow

improved source position trace comments

- remove needless comments generated during interface conversion
- filter null statements even in verbose mode
- hoist trace comment statements if doing so would prevent the need to
  wrap a task or function body in a block
- add traces for global declarations
- add traces for parameter declaration lists
- add traces for module items within generate blocks
- avoid generating duplicate traces before declarations
parent 8f0f8b4a
...@@ -360,7 +360,7 @@ inlineInstance global ranges modportBindings items partName ...@@ -360,7 +360,7 @@ inlineInstance global ranges modportBindings items partName
-- synthetic modports to be collected and removed after inlining -- synthetic modports to be collected and removed after inlining
bundleModport = Modport "" (impliedModport items) bundleModport = Modport "" (impliedModport items)
dimensionModport = if not isArray dimensionModport = if not isArray
then MIPackageItem $ Decl $ CommentDecl "not an instance array" then Generate []
else InstArrEncoded arrayLeft arrayRight else InstArrEncoded arrayLeft arrayRight
typeModport = InterfaceTypeEncoded partName typeModport = InterfaceTypeEncoded partName
...@@ -544,12 +544,11 @@ inlineInstance global ranges modportBindings items partName ...@@ -544,12 +544,11 @@ inlineInstance global ranges modportBindings items partName
removeDeclDir other = other removeDeclDir other = other
-- capture the lower bound for each modport array binding -- capture the lower bound for each modport array binding
bindingBaseParams = map makeBindingBaseParam modportBindings bindingBaseParams = mapMaybe makeBindingBaseParam modportBindings
makeBindingBaseParam :: ModportBinding -> Decl makeBindingBaseParam :: ModportBinding -> Maybe Decl
makeBindingBaseParam (portName, (_, modportE)) = makeBindingBaseParam (portName, (_, modportE)) =
case makeBindingBaseExpr modportE of fmap (localparam $ bindingBaseName ++ portName) $
Just expr -> localparam (bindingBaseName ++ portName) expr makeBindingBaseExpr modportE
Nothing -> CommentDecl "no-op"
bindingBaseName = "_bbase_" ++ key ++ "_" bindingBaseName = "_bbase_" ++ key ++ "_"
makeBindingBaseExpr :: Expr -> Maybe Expr makeBindingBaseExpr :: Expr -> Maybe Expr
makeBindingBaseExpr modportE = makeBindingBaseExpr modportE =
......
...@@ -407,7 +407,7 @@ scopeModuleItemT declMapper moduleItemMapper genItemMapper stmtMapper = ...@@ -407,7 +407,7 @@ scopeModuleItemT declMapper moduleItemMapper genItemMapper stmtMapper =
fullStmtMapper (Block kw name decls stmts) = do fullStmtMapper (Block kw name decls stmts) = do
enterScope name "" enterScope name ""
decls' <- fmap concat $ mapM declMapper' decls decls' <- fmap concat $ mapM declMapper' decls
stmts' <- mapM fullStmtMapper stmts stmts' <- mapM fullStmtMapper $ filter (/= Null) stmts
exitScope exitScope
return $ Block kw name decls' stmts' return $ Block kw name decls' stmts'
-- TODO: Do we need to support the various procedural loops? -- TODO: Do we need to support the various procedural loops?
......
...@@ -31,6 +31,8 @@ convertPackageItem (Task ml f decls stmts) = ...@@ -31,6 +31,8 @@ convertPackageItem (Task ml f decls stmts) =
convertPackageItem other = other convertPackageItem other = other
convertTFBlock :: [Decl] -> [Stmt] -> ([Decl], [Stmt]) convertTFBlock :: [Decl] -> [Stmt] -> ([Decl], [Stmt])
convertTFBlock decls [CommentStmt c, stmt] =
convertTFBlock (decls ++ [CommentDecl c]) [stmt]
convertTFBlock decls stmts = convertTFBlock decls stmts =
(decls', [stmtsToStmt stmts']) (decls', [stmtsToStmt stmts'])
where (decls', stmts') = flattenOuterBlocks $ Block Seq "" decls stmts where (decls', stmts') = flattenOuterBlocks $ Block Seq "" decls stmts
......
...@@ -444,7 +444,7 @@ Description :: { [Description] } ...@@ -444,7 +444,7 @@ Description :: { [Description] }
: Part(ModuleKW , endmodule ) { [$1] } : Part(ModuleKW , endmodule ) { [$1] }
| Part(InterfaceKW, endinterface) { [$1] } | Part(InterfaceKW, endinterface) { [$1] }
| PackageDeclaration { [$1] } | PackageDeclaration { [$1] }
| PackageItem { map PackageItem $1 } | PITrace PackageItem { map PackageItem $ addPITrace $1 $2 }
OptAsgn :: { Expr } OptAsgn :: { Expr }
: {- empty -} { Nil } : {- empty -} { Nil }
...@@ -573,14 +573,14 @@ PIParams :: { [Decl] } ...@@ -573,14 +573,14 @@ PIParams :: { [Decl] }
| "#" "(" ")" { [] } | "#" "(" ")" { [] }
| "#" "(" ParamsFollow { $3 } | "#" "(" ParamsFollow { $3 }
ParamsFollow :: { [Decl] } ParamsFollow :: { [Decl] }
: ParamAsgn ParamsEnd { [$1] } : ParamAsgn ParamsEnd { $1 }
| ParamAsgn "," ParamsFollow { $1 : $3 } | ParamAsgn "," ParamsFollow { $1 ++ $3 }
| ParamsDecl { $1 } | ParamsDecl { $1 }
ParamsDecl :: { [Decl] } ParamsDecl :: { [Decl] }
: ModuleParameterDecl(ParamsEnd) { $1 } : ModuleParameterDecl(ParamsEnd) { $1 }
| ModuleParameterDecl(",") ParamsDecl { $1 ++ $2 } | ModuleParameterDecl(",") ParamsDecl { $1 ++ $2 }
ParamAsgn :: { Decl } ParamAsgn :: { [Decl] }
: Identifier "=" Expr { Param Parameter (Implicit Unspecified []) $1 $3 } : DeclTrace Identifier "=" Expr { [$1, Param Parameter (Implicit Unspecified []) $2 $4] }
ParamsEnd ParamsEnd
: ")" {} : ")" {}
| "," ")" {} | "," ")" {}
...@@ -689,7 +689,7 @@ DirectionP :: { (Position, Direction) } ...@@ -689,7 +689,7 @@ DirectionP :: { (Position, Direction) }
ModuleItems :: { [ModuleItem] } ModuleItems :: { [ModuleItem] }
: {- empty -} { [] } : {- empty -} { [] }
| ";" ModuleItems { $2 } | ";" ModuleItems { $2 }
| MITrace ModuleItem ModuleItems { $1 : $2 ++ $3 } | MITrace ModuleItem ModuleItems { addMITrace $1 ($2 ++ $3) }
ModuleItem :: { [ModuleItem] } ModuleItem :: { [ModuleItem] }
: NonGenerateModuleItem { $1 } : NonGenerateModuleItem { $1 }
...@@ -855,7 +855,7 @@ LHSAsgn :: { (LHS, Expr) } ...@@ -855,7 +855,7 @@ LHSAsgn :: { (LHS, Expr) }
PackageItems :: { [PackageItem] } PackageItems :: { [PackageItem] }
: {- empty -} { [] } : {- empty -} { [] }
| ";" PackageItems { $2 } | ";" PackageItems { $2 }
| PITrace PackageItem PackageItems { $1 : $2 ++ $3 } | PITrace PackageItem PackageItems { addPITrace $1 ($2 ++ $3) }
PackageItem :: { [PackageItem] } PackageItem :: { [PackageItem] }
: PackageOrClassItem { $1} : PackageOrClassItem { $1}
| TaskOrFunction { [$1] } | TaskOrFunction { [$1] }
...@@ -863,7 +863,7 @@ PackageItem :: { [PackageItem] } ...@@ -863,7 +863,7 @@ PackageItem :: { [PackageItem] }
ClassItems :: { [ClassItem] } ClassItems :: { [ClassItem] }
: {- empty -} { [] } : {- empty -} { [] }
| ";" ClassItems { $2 } | ";" ClassItems { $2 }
| CITrace ClassItem ClassItems { $1 : $2 ++ $3 } | CITrace ClassItem ClassItems { addCITrace $1 ($2 ++ $3) }
ClassItem :: { [ClassItem] } ClassItem :: { [ClassItem] }
: ClassItemQualifier PackageOrClassItem { map ($1, ) $2 } : ClassItemQualifier PackageOrClassItem { map ($1, ) $2 }
| ClassItemQualifier TaskOrFunction { [($1, $2)] } | ClassItemQualifier TaskOrFunction { [($1, $2)] }
...@@ -1130,15 +1130,15 @@ DeclOrStmt :: { ([Decl], [Stmt]) } ...@@ -1130,15 +1130,15 @@ DeclOrStmt :: { ([Decl], [Stmt]) }
ModuleParameterDecl(delim) :: { [Decl] } ModuleParameterDecl(delim) :: { [Decl] }
: ParameterDecl(delim) { $1 } : ParameterDecl(delim) { $1 }
| "type" TypeAsgns delim { map (uncurry $ ParamType Parameter) $2 } | DeclTrace "type" TypeAsgns delim { $1 : map (uncurry $ ParamType Parameter) $3 }
ParameterDecl(delim) :: { [Decl] } ParameterDecl(delim) :: { [Decl] }
: ParameterDeclKW DeclAsgns delim { makeParamDecls $1 (Implicit Unspecified []) $2 } : ParameterDeclKW DeclAsgns delim { makeParamDecls $1 (Implicit Unspecified []) $2 }
| ParameterDeclKW ParamType DeclAsgns delim { makeParamDecls $1 $2 $3 } | ParameterDeclKW ParamType DeclAsgns delim { makeParamDecls $1 $2 $3 }
| ParameterDeclKW TypeAlias DeclAsgns delim { makeParamDecls $1 $2 $3 } | ParameterDeclKW TypeAlias DeclAsgns delim { makeParamDecls $1 $2 $3 }
| ParameterDeclKW "type" TypeAsgns delim { map (uncurry $ ParamType $1) $3 } | ParameterDeclKW "type" TypeAsgns delim { makeParamTypeDecls $1 $3 }
ParameterDeclKW :: { ParamScope } ParameterDeclKW :: { (Position, ParamScope) }
: "parameter" { Parameter } : "parameter" { withPos $1 Parameter }
| "localparam" { Localparam } | "localparam" { withPos $1 Localparam }
TypeAsgns :: { [(Identifier, Type)] } TypeAsgns :: { [(Identifier, Type)] }
: TypeAsgn { [$1] } : TypeAsgn { [$1] }
...@@ -1361,11 +1361,11 @@ GenItems :: { [GenItem] } ...@@ -1361,11 +1361,11 @@ GenItems :: { [GenItem] }
| GenItems GenItem { $1 ++ [$2] } | GenItems GenItem { $1 ++ [$2] }
GenItem :: { GenItem } GenItem :: { GenItem }
: GenBlock { uncurry GenBlock $1 } : MITrace GenBlock { uncurry GenBlock $2 }
| NonGenerateModuleItem { genItemsToGenItem $ map GenModuleItem $1 } | MITrace NonGenerateModuleItem { genItemsToGenItem $ map GenModuleItem $ addMITrace $1 $2 }
| "generate" GenItems "endgenerate" { genItemsToGenItem $2 } | MITrace "generate" GenItems "endgenerate" { genItemsToGenItem $3 }
| ConditionalGenerateConstruct { $1 } | MITrace ConditionalGenerateConstruct { $2 }
| LoopGenerateConstruct { $1 } | MITrace LoopGenerateConstruct { $2 }
ConditionalGenerateConstruct :: { GenItem } ConditionalGenerateConstruct :: { GenItem }
: "if" "(" Expr ")" GenItemOrNull "else" GenItemOrNull { GenIf $3 $5 $7 } : "if" "(" Expr ")" GenItemOrNull "else" GenItemOrNull { GenIf $3 $5 $7 }
| "if" "(" Expr ")" GenItemOrNull %prec NoElse { GenIf $3 $5 GenNull } | "if" "(" Expr ")" GenItemOrNull %prec NoElse { GenIf $3 $5 GenNull }
...@@ -1435,9 +1435,11 @@ DimFn :: { DimFn } ...@@ -1435,9 +1435,11 @@ DimFn :: { DimFn }
MITrace :: { ModuleItem } MITrace :: { ModuleItem }
: PITrace { MIPackageItem $1 } : PITrace { MIPackageItem $1 }
PITrace :: { PackageItem } PITrace :: { PackageItem }
: Trace { Decl $ CommentDecl $1 } : DeclTrace { Decl $1 }
CITrace :: { ClassItem } CITrace :: { ClassItem }
: PITrace { (QNone, $1) } : PITrace { (QNone, $1) }
DeclTrace :: { Decl }
: Trace { CommentDecl $1 }
StmtTrace :: { Stmt } StmtTrace :: { Stmt }
: Trace { CommentStmt $1 } : Trace { CommentStmt $1 }
Trace :: { String } Trace :: { String }
...@@ -1536,17 +1538,26 @@ toLHS expr = ...@@ -1536,17 +1538,26 @@ toLHS expr =
Nothing -> error $ "Parse error: cannot convert expression to LHS: " Nothing -> error $ "Parse error: cannot convert expression to LHS: "
++ show expr ++ show expr
traceCommentDecl :: Position -> Decl
traceCommentDecl = CommentDecl . ("Trace: " ++) . show
makeParamDecls makeParamDecls
:: ParamScope :: (Position, ParamScope)
-> Type -> Type
-> [(Identifier, Expr, [Range])] -> [(Identifier, Expr, [Range])]
-> [Decl] -> [Decl]
makeParamDecls s t items = makeParamDecls (p, s) t items =
traceCommentDecl p :
map mapper items map mapper items
where where
(tf, rs) = typeRanges t (tf, rs) = typeRanges t
mapper (x, e, a) = Param s (tf $ a ++ rs) x e mapper (x, e, a) = Param s (tf $ a ++ rs) x e
makeParamTypeDecls :: (Position, ParamScope) -> [(Identifier, Type)] -> [Decl]
makeParamTypeDecls (p, s) items =
traceCommentDecl p :
map (uncurry $ ParamType s) items
fieldDecl :: Type -> (Identifier, [Range]) -> (Type, Identifier) fieldDecl :: Type -> (Identifier, [Range]) -> (Type, Identifier)
fieldDecl t (x, rs2) = fieldDecl t (x, rs2) =
(tf $ rs2 ++ rs1, x) (tf $ rs2 ++ rs1, x)
...@@ -1631,4 +1642,16 @@ makeTypeOf (Token _ _ pos) expr = (pos, check) ...@@ -1631,4 +1642,16 @@ makeTypeOf (Token _ _ pos) expr = (pos, check)
check Unspecified _ = unexpectedPackedRanges pos (show typ) check Unspecified _ = unexpectedPackedRanges pos (show typ)
check sg [] = unexpectedSigning pos sg (show typ) check sg [] = unexpectedSigning pos sg (show typ)
addMITrace :: ModuleItem -> [ModuleItem] -> [ModuleItem]
addMITrace _ items @ (MIPackageItem (Decl CommentDecl{}) : _) = items
addMITrace trace items = trace : items
addPITrace :: PackageItem -> [PackageItem] -> [PackageItem]
addPITrace _ items @ (Decl CommentDecl{} : _) = items
addPITrace trace items = trace : items
addCITrace :: ClassItem -> [ClassItem] -> [ClassItem]
addCITrace _ items @ ((_, Decl CommentDecl{}) : _) = items
addCITrace trace items = trace : items
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment