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
e4cd8f4c
Commit
e4cd8f4c
authored
Apr 09, 2019
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify handles division and unsized decimal constants
parent
2ee837f7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
4 deletions
+14
-4
src/Language/SystemVerilog/AST/Expr.hs
+14
-4
No files found.
src/Language/SystemVerilog/AST/Expr.hs
View file @
e4cd8f4c
...
...
@@ -106,17 +106,25 @@ clog2Help p n = if p >= n then 0 else 1 + clog2Help (p*2) n
clog2
::
Int
->
Int
clog2
n
=
if
n
<
2
then
0
else
clog2Help
1
n
readNumber
::
String
->
Maybe
Int
readNumber
n
=
readMaybe
n'
::
Maybe
Int
where
n'
=
case
n
of
'
\'
'
:
'd'
:
rest
->
rest
_
->
n
-- basic expression simplfication utility to help us generate nicer code in the
-- common case of ranges like `[FOO-1:0]`
simplify
::
Expr
->
Expr
simplify
(
orig
@
(
Call
"$clog2"
(
Args
[
Just
(
Number
n
)]
[]
)))
=
case
read
Maybe
n
::
Maybe
Int
of
case
read
Number
n
of
Nothing
->
orig
Just
x
->
Number
$
show
$
clog2
x
simplify
(
Mux
(
BinOp
Ge
c1
c2
)
e1
e2
)
=
case
(
c1'
,
c2'
)
of
(
Number
a
,
Number
b
)
->
case
(
read
Maybe
a
::
Maybe
Int
,
readMaybe
b
::
Maybe
Int
)
of
case
(
read
Number
a
,
readNumber
b
)
of
(
Just
x
,
Just
y
)
->
if
x
>=
y
then
e1
...
...
@@ -141,13 +149,15 @@ simplify (BinOp op e1 e2) =
(
Add
,
BinOp
Sub
e
(
Number
"1"
),
Number
"1"
)
->
e
(
Add
,
e
,
BinOp
Sub
(
Number
"0"
)
(
Number
"1"
))
->
BinOp
Sub
e
(
Number
"1"
)
(
_
,
Number
a
,
Number
b
)
->
case
(
op
,
read
Maybe
a
::
Maybe
Int
,
readMaybe
b
::
Maybe
Int
)
of
case
(
op
,
read
Number
a
,
readNumber
b
)
of
(
Add
,
Just
x
,
Just
y
)
->
Number
$
show
(
x
+
y
)
(
Sub
,
Just
x
,
Just
y
)
->
Number
$
show
(
x
-
y
)
(
Mul
,
Just
x
,
Just
y
)
->
Number
$
show
(
x
*
y
)
(
Div
,
Just
_
,
Just
0
)
->
Number
"x"
(
Div
,
Just
x
,
Just
y
)
->
Number
$
show
(
x
`
quot
`
y
)
_
->
BinOp
op
e1'
e2'
(
Add
,
BinOp
Add
e
(
Number
a
),
Number
b
)
->
case
(
read
Maybe
a
::
Maybe
Int
,
readMaybe
b
::
Maybe
Int
)
of
case
(
read
Number
a
,
readNumber
b
)
of
(
Just
x
,
Just
y
)
->
BinOp
Add
e
$
Number
$
show
(
x
+
y
)
_
->
BinOp
op
e1'
e2'
_
->
BinOp
op
e1'
e2'
...
...
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