Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sv2v
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
sv2v
Commits
3c08767b
Commit
3c08767b
authored
Feb 06, 2020
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
redesigned preprocessor and lexer
parent
2dcd35ad
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
57 additions
and
12 deletions
+57
-12
README.md
+1
-1
src/Language/SystemVerilog/Parser.hs
+6
-3
src/Language/SystemVerilog/Parser/Lex.x
+0
-0
src/Language/SystemVerilog/Parser/Parse.y
+21
-2
src/Language/SystemVerilog/Parser/Preprocess.hs
+0
-0
src/Language/SystemVerilog/Parser/Tokens.hs
+9
-3
sv2v.cabal
+1
-0
test/lex/macro_boundary.sv
+19
-3
No files found.
README.md
View file @
3c08767b
...
@@ -96,7 +96,7 @@ will be given to issues which include examples or test cases.
...
@@ -96,7 +96,7 @@ will be given to issues which include examples or test cases.
## SystemVerilog Front End
## SystemVerilog Front End
This project contains a preprocessor
and lexer, a
parser, and an abstract syntax
This project contains a preprocessor
, lexer, and
parser, and an abstract syntax
tree representation for a subset of the SystemVerilog specification. The parser
tree representation for a subset of the SystemVerilog specification. The parser
is not very strict. The AST allows for the representation of syntactically (and
is not very strict. The AST allows for the representation of syntactically (and
semantically) invalid Verilog. The goal is to be more general in the
semantically) invalid Verilog. The goal is to be more general in the
...
...
src/Language/SystemVerilog/Parser.hs
View file @
3c08767b
...
@@ -9,8 +9,9 @@ import Control.Monad.Except
...
@@ -9,8 +9,9 @@ import Control.Monad.Except
import
Control.Monad.State
import
Control.Monad.State
import
qualified
Data.Map.Strict
as
Map
import
qualified
Data.Map.Strict
as
Map
import
Language.SystemVerilog.AST
(
AST
)
import
Language.SystemVerilog.AST
(
AST
)
import
Language.SystemVerilog.Parser.Lex
(
lex
File
,
Env
)
import
Language.SystemVerilog.Parser.Lex
(
lex
Str
)
import
Language.SystemVerilog.Parser.Parse
(
parse
)
import
Language.SystemVerilog.Parser.Parse
(
parse
)
import
Language.SystemVerilog.Parser.Preprocess
(
preprocess
,
Env
)
import
Language.SystemVerilog.Parser.Tokens
(
Position
(
..
),
tokenPosition
)
import
Language.SystemVerilog.Parser.Tokens
(
Position
(
..
),
tokenPosition
)
-- parses a compilation unit given include search paths and predefined macros
-- parses a compilation unit given include search paths and predefined macros
...
@@ -32,8 +33,10 @@ parseFiles' includePaths env siloed (path : paths) = do
...
@@ -32,8 +33,10 @@ parseFiles' includePaths env siloed (path : paths) = do
-- the file path
-- the file path
parseFile'
::
[
String
]
->
Env
->
FilePath
->
ExceptT
String
IO
(
AST
,
Env
)
parseFile'
::
[
String
]
->
Env
->
FilePath
->
ExceptT
String
IO
(
AST
,
Env
)
parseFile'
includePaths
env
path
=
do
parseFile'
includePaths
env
path
=
do
result
<-
liftIO
$
lexFile
includePaths
env
path
preResult
<-
liftIO
$
preprocess
includePaths
env
path
(
tokens
,
env'
)
<-
liftEither
result
(
contents
,
env'
)
<-
liftEither
preResult
result
<-
liftIO
$
uncurry
lexStr
$
unzip
contents
tokens
<-
liftEither
result
let
position
=
let
position
=
if
null
tokens
if
null
tokens
then
Position
path
1
1
then
Position
path
1
1
...
...
src/Language/SystemVerilog/Parser/Lex.x
View file @
3c08767b
This diff is collapsed.
Click to expand it.
src/Language/SystemVerilog/Parser/Parse.y
View file @
3c08767b
...
@@ -297,7 +297,15 @@ systemIdentifier { Token Id_system _ _ }
...
@@ -297,7 +297,15 @@ systemIdentifier { Token Id_system _ _ }
number { Token Lit_number _ _ }
number { Token Lit_number _ _ }
string { Token Lit_string _ _ }
string { Token Lit_string _ _ }
time { Token Lit_time _ _ }
time { Token Lit_time _ _ }
directive { Token Spe_Directive _ _ }
"`celldefine" { Token Dir_celldefine _ _ }
"`endcelldefine" { Token Dir_endcelldefine _ _ }
"`unconnected_drive" { Token Dir_unconnected_drive _ _ }
"`nounconnected_drive" { Token Dir_nounconnected_drive _ _ }
"`default_nettype" { Token Dir_default_nettype _ _ }
"`resetall" { Token Dir_resetall _ _ }
"`begin_keywords" { Token Dir_begin_keywords _ _ }
"`end_keywords" { Token Dir_end_keywords _ _ }
"(" { Token Sym_paren_l _ _ }
"(" { Token Sym_paren_l _ _ }
")" { Token Sym_paren_r _ _ }
")" { Token Sym_paren_r _ _ }
...
@@ -797,7 +805,18 @@ TimeunitsDeclaration :: { [PackageItem] }
...
@@ -797,7 +805,18 @@ TimeunitsDeclaration :: { [PackageItem] }
| "timeprecision" Time ";" { [] }
| "timeprecision" Time ";" { [] }
Directive :: { String }
Directive :: { String }
: directive { tokenString $1 }
: "`celldefine" { tokenString $1 }
| "`endcelldefine" { tokenString $1 }
| "`unconnected_drive" Drive { tokenString $1 ++ " " ++ $2 }
| "`nounconnected_drive" { tokenString $1 }
| "`default_nettype" DefaultNetType { tokenString $1 ++ " " ++ $2 }
| "`resetall" { tokenString $1 }
Drive :: { String }
: "pull0" { tokenString $1 }
| "pull1" { tokenString $1 }
DefaultNetType :: { String }
: NetType { show $1 }
| Identifier { $1 }
PackageImportItems :: { [(Identifier, Maybe Identifier)] }
PackageImportItems :: { [(Identifier, Maybe Identifier)] }
: PackageImportItem { [$1] }
: PackageImportItem { [$1] }
...
...
src/Language/SystemVerilog/Parser/Preprocess.hs
0 → 100644
View file @
3c08767b
This diff is collapsed.
Click to expand it.
src/Language/SystemVerilog/Parser/Tokens.hs
View file @
3c08767b
...
@@ -28,7 +28,7 @@ tokenPosition :: Token -> Position
...
@@ -28,7 +28,7 @@ tokenPosition :: Token -> Position
tokenPosition
(
Token
_
_
pos
)
=
pos
tokenPosition
(
Token
_
_
pos
)
=
pos
pattern
TokenEOF
::
Token
pattern
TokenEOF
::
Token
pattern
TokenEOF
=
Token
MacroBoundary
""
(
Position
""
0
0
)
pattern
TokenEOF
=
Token
Unknown
""
(
Position
""
0
0
)
data
Position
data
Position
=
Position
String
Int
Int
=
Position
String
Int
Int
...
@@ -391,7 +391,13 @@ data TokenName
...
@@ -391,7 +391,13 @@ data TokenName
|
Sym_amp_amp_amp
|
Sym_amp_amp_amp
|
Sym_lt_lt_lt_eq
|
Sym_lt_lt_lt_eq
|
Sym_gt_gt_gt_eq
|
Sym_gt_gt_gt_eq
|
Spe_Directive
|
Dir_celldefine
|
Dir_endcelldefine
|
Dir_unconnected_drive
|
Dir_nounconnected_drive
|
Dir_default_nettype
|
Dir_resetall
|
Dir_begin_keywords
|
Dir_end_keywords
|
Unknown
|
Unknown
|
MacroBoundary
deriving
(
Show
,
Eq
,
Ord
)
deriving
(
Show
,
Eq
,
Ord
)
sv2v.cabal
View file @
3c08767b
...
@@ -53,6 +53,7 @@ executable sv2v
...
@@ -53,6 +53,7 @@ executable sv2v
Language.SystemVerilog.Parser.Lex
Language.SystemVerilog.Parser.Lex
Language.SystemVerilog.Parser.Parse
Language.SystemVerilog.Parser.Parse
Language.SystemVerilog.Parser.ParseDecl
Language.SystemVerilog.Parser.ParseDecl
Language.SystemVerilog.Parser.Preprocess
Language.SystemVerilog.Parser.Tokens
Language.SystemVerilog.Parser.Tokens
-- Conversion modules
-- Conversion modules
Convert
Convert
...
...
test/lex/macro_boundary.sv
View file @
3c08767b
`define
SIZE
4
`define
SIZE
4
`define
NESTED_SIZE
`
SIZE
`define
NESTED_SIZE
`
SIZE
`define
NAME op
`define
NAME op
module
t
`NAME
;
`define
FOO ha
initial
$
display
(
`SIZE
'ha
)
;
`define
BAR
'
ha
initial
$
display
(
`NESTED_SIZE
'ha
)
;
`define
MULTI 1
,
2
,
5
`define
DULE dule
mo
`DULE
t
`NAME
;
initial
$
display
(
"%b"
,
`SIZE
'ha
)
;
initial
$
display
(
"%b"
,
`NESTED_SIZE
'ha
)
;
initial
$
display
(
"%b"
,
10
'
h
`NESTED_SIZE
)
;
initial
$
display
(
"%b"
,
10
`BAR
)
;
initial
$
display
(
"%b"
,
10
`SIZE
)
;
initial
$
display
(
"%b %b %b"
,
`MULTI
'ha
)
;
initial
begin
:
block_name
reg
[
4
:
0
]
foo
;
foo
<=
#
1
`SIZE
;
$
display
(
"%b"
,
foo
)
;
#
2
;
$
display
(
"%b"
,
foo
)
;
end
endmodule
endmodule
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment