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
149d16d8
Commit
149d16d8
authored
Oct 10, 2019
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add support for `line directive
parent
e23d68a6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
4 deletions
+54
-4
src/Language/SystemVerilog/Parser/Lex.x
+33
-4
test/lex/file_line.sv
+7
-0
test/lex/line.sv
+7
-0
test/lex/line.v
+7
-0
No files found.
src/Language/SystemVerilog/Parser/Lex.x
View file @
149d16d8
...
@@ -529,12 +529,10 @@ lexFile includePaths env path = do
...
@@ -529,12 +529,10 @@ lexFile includePaths env path = do
where finalToks = coalesce $ reverse $ lsToks finalState
where finalToks = coalesce $ reverse $ lsToks finalState
where
where
setEnv = do
setEnv = do
-- standardize the file path format
path' <- includeSearch path
modify $ \s -> s
modify $ \s -> s
{ lsEnv = env
{ lsEnv = env
, lsIncludePaths = includePaths
, lsIncludePaths = includePaths
, lsCurrFile = path
'
, lsCurrFile = path
}
}
-- combines identifiers and numbers that cross macro boundaries
-- combines identifiers and numbers that cross macro boundaries
...
@@ -716,6 +714,27 @@ takeQuotedString = do
...
@@ -716,6 +714,27 @@ takeQuotedString = do
then lexicalError $ "library includes are not supported: " ++ res
then lexicalError $ "library includes are not supported: " ++ res
else return res
else return res
-- removes and returns a decimal number
takeNumber :: Alex Int
takeNumber = do
dropSpaces
leadCh <- peekChar
if '0' <= leadCh && leadCh <= '9'
then step 0
else lexicalError $ "expected number, but found unexpected char: "
++ show leadCh
where
step number = do
ch <- takeChar
if ch == ' ' || ch == '\n' then
return number
else if '0' <= ch && ch <= '9' then do
let digit = ord ch - ord '0'
step $ number * 10 + digit
else
lexicalError $ "unexpected char while reading number: "
++ show ch
peekChar :: Alex Char
peekChar :: Alex Char
peekChar = do
peekChar = do
(_, _, _, str) <- alexGetInput
(_, _, _, str) <- alexGetInput
...
@@ -881,6 +900,16 @@ handleDirective (posOrig, _, _, strOrig) len = do
...
@@ -881,6 +900,16 @@ handleDirective (posOrig, _, _, strOrig) len = do
modify $ push $ Token Lit_number tokStr tokPos
modify $ push $ Token Lit_number tokStr tokPos
alexMonadScan
alexMonadScan
"line" -> do
lineNumber <- takeNumber
quotedFilename <- takeQuotedString
_ <- takeNumber -- level, ignored
let filename = init $ tail quotedFilename
setCurrentFile filename
(AlexPn f _ c, prev, _, str) <- alexGetInput
alexSetInput (AlexPn f (lineNumber + 1) c, prev, [], str)
alexMonadScan
"include" -> do
"include" -> do
quotedFilename <- takeQuotedString
quotedFilename <- takeQuotedString
inputFollow <- alexGetInput
inputFollow <- alexGetInput
...
@@ -968,7 +997,7 @@ handleDirective (posOrig, _, _, strOrig) len = do
...
@@ -968,7 +997,7 @@ handleDirective (posOrig, _, _, strOrig) len = do
currToks <- gets lsToks
currToks <- gets lsToks
modify $ \s -> s { lsToks = [] }
modify $ \s -> s { lsToks = [] }
-- lex the macro expansion, preserving the file and line
-- lex the macro expansion, preserving the file and line
alexSetInput (AlexPn 0 l 0, ' '
, [], replacement)
alexSetInput (AlexPn 0 l 0, ' ', [], replacement)
alexMonadScan
alexMonadScan
-- re-tag and save tokens from the macro expansion
-- re-tag and save tokens from the macro expansion
newToks <- gets lsToks
newToks <- gets lsToks
...
...
test/lex/file_line.sv
View file @
149d16d8
`ifndef
INCLUDED
`define
INCLUDED
`include
"file_line.sv"
`else
`define
MACRO
(
arg
)
$
display
(
arg
,
`
__FILE__
,
`
__LINE__
)
;
`define
MACRO
(
arg
)
$
display
(
arg
,
`
__FILE__
,
`
__LINE__
)
;
`define
MACRO_NO_ARG
$
display
(`
__FILE__
,
`
__LINE__
)
;
`define
MACRO_NO_ARG
$
display
(`
__FILE__
,
`
__LINE__
)
;
module
top
;
module
top
;
...
@@ -14,3 +19,5 @@ initial begin
...
@@ -14,3 +19,5 @@ initial begin
`MACRO
(
"f"
)
`MACRO
(
"f"
)
end
end
endmodule
endmodule
`endif
test/lex/line.sv
0 → 100644
View file @
149d16d8
module
top
;
initial
begin
$
display
(
`__FILE__
,
`__LINE__
)
;
`line
101
"fake.v"
1
$
display
(
`__FILE__
,
`__LINE__
)
;
end
endmodule
test/lex/line.v
0 → 100644
View file @
149d16d8
module
top
;
initial
begin
$
display
(
"line.sv"
,
`__LINE__
)
;
;
$
display
(
"fake.v"
,
102
)
;
end
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