mirror of https://github.com/zachjs/sv2v.git
meaningful grammar cleanup
This commit is contained in:
parent
50996f0d67
commit
9fd79068f3
|
|
@ -172,7 +172,7 @@ ParamDecls :: { [ModuleItem] }
|
||||||
: ParamDecl(")") { $1 }
|
: ParamDecl(")") { $1 }
|
||||||
| ParamDecl(",") ParamDecls { $1 ++ $2 }
|
| ParamDecl(",") ParamDecls { $1 ++ $2 }
|
||||||
ParamDecl(delim) :: { [ModuleItem] }
|
ParamDecl(delim) :: { [ModuleItem] }
|
||||||
: "parameter" MaybeRange DeclAsgns delim { map (uncurry $ Parameter $2) $3 }
|
: "parameter" opt(Range) DeclAsgns delim { map (uncurry $ Parameter $2) $3 }
|
||||||
|
|
||||||
Identifier :: { Identifier }
|
Identifier :: { Identifier }
|
||||||
: simpleIdentifier { tokenString $1 }
|
: simpleIdentifier { tokenString $1 }
|
||||||
|
|
@ -199,7 +199,8 @@ PortDecl(delim) :: { [ModuleItem] }
|
||||||
| "input" opt(NetType) opt(Range) Identifiers delim { portDeclToModuleItems Input $2 $3 (zip $4 (repeat Nothing)) }
|
| "input" opt(NetType) opt(Range) Identifiers delim { portDeclToModuleItems Input $2 $3 (zip $4 (repeat Nothing)) }
|
||||||
| "output" opt(NetType) opt(Range) Identifiers delim { portDeclToModuleItems Output $2 $3 (zip $4 (repeat Nothing)) }
|
| "output" opt(NetType) opt(Range) Identifiers delim { portDeclToModuleItems Output $2 $3 (zip $4 (repeat Nothing)) }
|
||||||
| "output" "reg" opt(Range) VariablePortIdentifiers delim { portDeclToModuleItems Output (Just Reg) $3 $4 }
|
| "output" "reg" opt(Range) VariablePortIdentifiers delim { portDeclToModuleItems Output (Just Reg) $3 $4 }
|
||||||
|
NetType
|
||||||
|
: "wire" { Wire }
|
||||||
VariablePortIdentifiers :: { [(Identifier, Maybe Expr)] }
|
VariablePortIdentifiers :: { [(Identifier, Maybe Expr)] }
|
||||||
: VariablePortIdentifier { [$1] }
|
: VariablePortIdentifier { [$1] }
|
||||||
| VariablePortIdentifiers "," VariablePortIdentifier { $1 ++ [$3] }
|
| VariablePortIdentifiers "," VariablePortIdentifier { $1 ++ [$3] }
|
||||||
|
|
@ -208,31 +209,25 @@ VariablePortIdentifier :: { (Identifier, Maybe Expr) }
|
||||||
| Identifier "=" Expr { ($1, Just $3) }
|
| Identifier "=" Expr { ($1, Just $3) }
|
||||||
|
|
||||||
ModuleItems :: { [ModuleItem] }
|
ModuleItems :: { [ModuleItem] }
|
||||||
: { [] }
|
: {- empty -} { [] }
|
||||||
| ModuleItems ModuleItem { $1 ++ $2 }
|
| ModuleItems ModuleItem { $1 ++ $2 }
|
||||||
|
|
||||||
NetType
|
|
||||||
: "wire" { Wire }
|
|
||||||
|
|
||||||
MaybeTypeOrRange :: { Either Type (Maybe Range) }
|
|
||||||
: MaybeRange { Right $1 }
|
|
||||||
| "reg" MaybeRange { Left $ Reg $2 }
|
|
||||||
| "wire" MaybeRange { Left $ Wire $2 }
|
|
||||||
|
|
||||||
ModuleItem :: { [ModuleItem] }
|
ModuleItem :: { [ModuleItem] }
|
||||||
: "parameter" MaybeRange DeclAsgns ";" { map (uncurry $ Parameter $2) $3 }
|
: "parameter" opt(Range) DeclAsgns ";" { map (uncurry $ Parameter $2) $3 }
|
||||||
| "localparam" MaybeRange DeclAsgns ";" { map (uncurry $ Localparam $2) $3 }
|
| "localparam" opt(Range) DeclAsgns ";" { map (uncurry $ Localparam $2) $3 }
|
||||||
| PortDecl(";") { $1 }
|
| PortDecl(";") { $1 }
|
||||||
| "reg" MaybeRange VariableIdentifiers ";" { map (uncurry $ LocalNet $ Reg $2) $3 }
|
| "reg" opt(Range) VariableIdentifiers ";" { map (uncurry $ LocalNet $ Reg $2) $3 }
|
||||||
| "wire" MaybeRange VariableIdentifiers ";" { map (uncurry $ LocalNet $ Wire $2) $3 }
|
| "wire" opt(Range) VariableIdentifiers ";" { map (uncurry $ LocalNet $ Wire $2) $3 }
|
||||||
| "integer" VariableIdentifiers ";" { map (uncurry Integer) $2 }
|
| "integer" VariableIdentifiers ";" { map (uncurry Integer) $2 }
|
||||||
| "assign" LHS "=" Expr ";" { [Assign $2 $4] }
|
| "assign" LHS "=" Expr ";" { [Assign $2 $4] }
|
||||||
| "always" Stmt { [Always Nothing $2] }
|
| "always" opt(EventControl) Stmt { [Always $2 $3] }
|
||||||
| "always" "@" "(" Sense ")" Stmt { [Always (Just $4) $6] }
|
| Identifier ParameterBindings Identifier Bindings ";" { [Instance $1 $2 $3 $4] }
|
||||||
| "always" "@" "(" "*" ")" Stmt { [Always (Just SenseStar) $6] }
|
|
||||||
| "always" "@" "*" Stmt { [Always (Just SenseStar) $4] }
|
EventControl :: { Sense }
|
||||||
| "always" "@*" Stmt { [Always (Just SenseStar) $3] }
|
: "@" "(" Sense ")" { $3 }
|
||||||
| Identifier ParameterBindings Identifier Bindings ";" { [Instance $1 $2 $3 $4] }
|
| "@" "(" "*" ")" { SenseStar }
|
||||||
|
| "@" "*" { SenseStar }
|
||||||
|
| "@*" { SenseStar }
|
||||||
|
|
||||||
VariableIdentifiers :: { [(Identifier, Either [Range] (Maybe Expr))] }
|
VariableIdentifiers :: { [(Identifier, Either [Range] (Maybe Expr))] }
|
||||||
: VariableType { [$1] }
|
: VariableType { [$1] }
|
||||||
|
|
@ -249,28 +244,11 @@ Dimensions :: { [Range] }
|
||||||
DeclAsgns :: { [(Identifier, Expr)] }
|
DeclAsgns :: { [(Identifier, Expr)] }
|
||||||
: DeclAsgn { [$1] }
|
: DeclAsgn { [$1] }
|
||||||
| DeclAsgns "," DeclAsgn { $1 ++ [$3] }
|
| DeclAsgns "," DeclAsgn { $1 ++ [$3] }
|
||||||
|
|
||||||
DeclAsgn :: { (Identifier, Expr) }
|
DeclAsgn :: { (Identifier, Expr) }
|
||||||
: Identifier "=" Expr { ($1, $3) }
|
: Identifier "=" Expr { ($1, $3) }
|
||||||
|
|
||||||
RegDeclarations :: { [(Identifier, Maybe Range)] }
|
|
||||||
: Identifier MaybeRange { [($1, $2)] }
|
|
||||||
| RegDeclarations "," Identifier MaybeRange { $1 ++ [($3, $4)] }
|
|
||||||
|
|
||||||
WireDeclarations :: { [(Identifier, Maybe Expr)] }
|
|
||||||
: WireDeclaration { [$1] }
|
|
||||||
| WireDeclarations "," WireDeclaration { $1 ++ [$3] }
|
|
||||||
|
|
||||||
WireDeclaration :: { (Identifier, Maybe Expr) }
|
|
||||||
: Identifier { ($1, Nothing) }
|
|
||||||
| Identifier "=" Expr { ($1, Just $3) }
|
|
||||||
|
|
||||||
MaybeRange :: { Maybe Range }
|
|
||||||
: { Nothing }
|
|
||||||
| Range { Just $1 }
|
|
||||||
|
|
||||||
Range :: { Range }
|
Range :: { Range }
|
||||||
: "[" Expr ":" Expr "]" { ($2, $4) }
|
: "[" Expr ":" Expr "]" { ($2, $4) }
|
||||||
|
|
||||||
LHS :: { LHS }
|
LHS :: { LHS }
|
||||||
: Identifier { LHS $1 }
|
: Identifier { LHS $1 }
|
||||||
|
|
@ -304,18 +282,18 @@ Binding :: { (Identifier, Maybe Expr) }
|
||||||
| Expr { ("", Just $1) }
|
| Expr { ("", Just $1) }
|
||||||
|
|
||||||
ParameterBindings :: { [(Identifier, Maybe Expr)] }
|
ParameterBindings :: { [(Identifier, Maybe Expr)] }
|
||||||
: { [] }
|
: {- empty -} { [] }
|
||||||
| "#" Bindings { $2 }
|
| "#" Bindings { $2 }
|
||||||
|
|
||||||
Stmts :: { [Stmt] }
|
Stmts :: { [Stmt] }
|
||||||
: { [] }
|
: {- empty -} { [] }
|
||||||
| Stmts Stmt { $1 ++ [$2] }
|
| Stmts Stmt { $1 ++ [$2] }
|
||||||
|
|
||||||
Stmt :: { Stmt }
|
Stmt :: { Stmt }
|
||||||
: ";" { Null }
|
: ";" { Null }
|
||||||
| "begin" Stmts "end" { Block Nothing $2 }
|
| "begin" Stmts "end" { Block Nothing $2 }
|
||||||
| "begin" ":" Identifier Stmts "end" { Block (Just $3) $4 }
|
| "begin" ":" Identifier Stmts "end" { Block (Just $3) $4 }
|
||||||
| "reg" MaybeRange BlockRegIdentifiers ";" { stmtsToStmt $ map (uncurry $ StmtReg $2) $3 }
|
| "reg" opt(Range) BlockRegIdentifiers ";" { stmtsToStmt $ map (uncurry $ StmtReg $2) $3 }
|
||||||
| "integer" VariableIdentifiers ";" { stmtsToStmt $ map (uncurry StmtInteger) $2 }
|
| "integer" VariableIdentifiers ";" { stmtsToStmt $ map (uncurry StmtInteger) $2 }
|
||||||
| "if" "(" Expr ")" Stmt "else" Stmt { If $3 $5 $7 }
|
| "if" "(" Expr ")" Stmt "else" Stmt { If $3 $5 $7 }
|
||||||
| "if" "(" Expr ")" Stmt %prec NoElse { If $3 $5 Null }
|
| "if" "(" Expr ")" Stmt %prec NoElse { If $3 $5 Null }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue