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
bceec393
Commit
bceec393
authored
Aug 26, 2021
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
standardize input handle logic
parent
40f66e02
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
15 deletions
+14
-15
src/Language/SystemVerilog/Parser/Preprocess.hs
+14
-15
No files found.
src/Language/SystemVerilog/Parser/Preprocess.hs
View file @
bceec393
...
...
@@ -21,6 +21,7 @@ import Data.List (tails, isPrefixOf, findIndex, intercalate)
import
Data.Maybe
(
isJust
,
fromJust
)
import
System.Directory
(
findFile
)
import
System.FilePath
(
dropFileName
)
import
System.IO
(
hGetContents
,
openFile
,
stdin
,
IOMode
(
ReadMode
))
import
qualified
Data.Map.Strict
as
Map
import
Language.SystemVerilog.Parser.Tokens
(
Position
(
..
))
...
...
@@ -71,10 +72,7 @@ elsifCond defined c =
-- preprocessor entrypoint
preprocess
::
[
String
]
->
Env
->
FilePath
->
ExceptT
String
IO
(
Env
,
Contents
)
preprocess
includePaths
env
path
=
do
contents
<-
liftIO
$
if
path
==
"-"
then
getContents
else
loadFile
path
contents
<-
liftIO
$
loadFile
path
let
initialState
=
PP
{
ppInput
=
contents
,
ppOutput
=
[]
...
...
@@ -98,24 +96,25 @@ preprocess includePaths env path = do
-- preprocessing
annotate
::
FilePath
->
ExceptT
String
IO
Contents
annotate
path
=
do
contents
<-
liftIO
$
if
path
==
"-"
then
getContents
else
loadFile
path
contents
<-
liftIO
$
loadFile
path
let
positions
=
scanl
advance
(
Position
path
1
1
)
contents
return
$
zip
contents
positions
-- read in the given file
loadFile
::
FilePath
->
IO
String
loadFile
path
=
do
contents
<-
readFile
path
handle
<-
if
path
==
"-"
then
return
stdin
else
openFile
path
ReadMode
contents
<-
hGetContents
handle
return
$
normalize
contents
where
-- removes carriage returns before newlines
normalize
::
String
->
String
normalize
(
'
\r
'
:
'
\n
'
:
rest
)
=
'
\n
'
:
(
normalize
rest
)
normalize
(
ch
:
chs
)
=
ch
:
(
normalize
chs
)
normalize
[]
=
[]
-- removes carriage returns before newlines
normalize
::
String
->
String
normalize
(
'
\r
'
:
'
\n
'
:
rest
)
=
'
\n
'
:
(
normalize
rest
)
normalize
(
ch
:
chs
)
=
ch
:
(
normalize
chs
)
normalize
[]
=
[]
-- find the given file for inclusion
includeSearch
::
FilePath
->
PPS
FilePath
...
...
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