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
1903bc19
Commit
1903bc19
authored
Jul 02, 2020
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use unbounded integers
parent
cd8af036
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
24 deletions
+31
-24
src/Convert/SizeCast.hs
+1
-3
src/Convert/TypeOf.hs
+1
-2
src/Language/SystemVerilog/AST/Expr.hs
+9
-19
test/basic/shift.sv
+20
-0
No files found.
src/Convert/SizeCast.hs
View file @
1903bc19
...
...
@@ -66,9 +66,7 @@ traverseExprM =
where
str
=
(
show
size
)
++
"'d"
++
(
show
num
)
size
=
s'
num
=
if
size
>=
32
then
n'
-- already read as 32 bits
else
n'
`
mod
`
(
2
^
s'
)
num
=
n'
`
mod
`
(
2
^
s'
)
_
->
convertCastM
(
Number
s
)
(
Number
n
)
convertExprM
(
orig
@
(
Cast
(
Right
DimsFn
{})
_
))
=
return
orig
...
...
src/Convert/TypeOf.hs
View file @
1903bc19
...
...
@@ -12,7 +12,6 @@
module
Convert.TypeOf
(
convert
)
where
import
Data.List
(
elemIndex
)
import
Data.Int
(
Int32
)
import
Data.Tuple
(
swap
)
import
qualified
Data.Map.Strict
as
Map
...
...
@@ -140,7 +139,7 @@ typeof (Repeat reps exprs) = return $ typeOfSize size
typeof
other
=
lookupTypeOf
other
-- determines the size and sign of a number literal
parseNumber
::
String
->
(
Int
32
,
Signing
)
parseNumber
::
String
->
(
Int
eger
,
Signing
)
parseNumber
s
=
case
elemIndex
'
\'
'
s
of
Nothing
->
(
32
,
Signed
)
...
...
src/Language/SystemVerilog/AST/Expr.hs
View file @
1903bc19
...
...
@@ -27,9 +27,7 @@ module Language.SystemVerilog.AST.Expr
)
where
import
Data.Bits
(
shiftL
,
shiftR
)
import
Data.Int
(
Int32
)
import
Data.List
(
intercalate
)
import
Data.Word
(
Word32
)
import
Numeric
(
readHex
)
import
Text.Printf
(
printf
)
import
Text.Read
(
readMaybe
)
...
...
@@ -191,12 +189,12 @@ showExprOrRange :: ExprOrRange -> String
showExprOrRange
(
Left
x
)
=
show
x
showExprOrRange
(
Right
x
)
=
show
x
clog2Help
::
Int
32
->
Int32
->
Int32
clog2Help
::
Int
eger
->
Integer
->
Integer
clog2Help
p
n
=
if
p
>=
n
then
0
else
1
+
clog2Help
(
p
*
2
)
n
clog2
::
Int
32
->
Int32
clog2
::
Int
eger
->
Integer
clog2
n
=
if
n
<
2
then
0
else
clog2Help
1
n
readNumber
::
String
->
Maybe
Int
32
readNumber
::
String
->
Maybe
Int
eger
readNumber
(
'3'
:
'2'
:
'
\'
'
:
'd'
:
rest
)
=
readMaybe
rest
readNumber
(
'
\'
'
:
'd'
:
rest
)
=
readMaybe
rest
readNumber
(
'3'
:
'2'
:
'
\'
'
:
'h'
:
rest
)
=
...
...
@@ -207,13 +205,7 @@ readNumber ('\'' : 'h' : rest) =
case
readHex
rest
of
[(
v
,
_
)]
->
Just
v
_
->
Nothing
readNumber
n
=
case
readMaybe
n
of
Nothing
->
Nothing
Just
res
->
if
show
res
==
n
then
Just
res
else
Nothing
readNumber
n
=
readMaybe
n
showUniOpPrec
::
Expr
->
ShowS
showUniOpPrec
(
e
@
UniOp
{})
=
(
showParen
True
.
shows
)
e
...
...
@@ -308,16 +300,14 @@ simplify (BinOp op e1 e2) =
(
ShiftAL
,
Just
x
,
Just
y
)
->
Number
$
show
$
shiftL
x
(
toInt
y
)
(
ShiftAR
,
Just
x
,
Just
y
)
->
Number
$
show
$
shiftR
x
(
toInt
y
)
(
ShiftL
,
Just
x
,
Just
y
)
->
Number
$
show
$
shiftL
x
(
toInt
y
)
(
ShiftR
,
Just
x
,
Just
y
)
->
-- does not sign extend
Number
$
show
$
toInt32
$
shiftR
(
toWord32
x
)
(
toInt
y
)
(
ShiftR
,
Just
x
,
Just
y
)
->
if
x
<
0
&&
y
>
0
then
BinOp
ShiftR
(
Number
a
)
(
Number
b
)
else
Number
$
show
$
shiftR
x
(
toInt
y
)
_
->
BinOp
op
e1'
e2'
where
toInt
::
Int
32
->
Int
toInt
::
Int
eger
->
Int
toInt
=
fromIntegral
toWord32
::
Int32
->
Word32
toWord32
=
fromIntegral
toInt32
::
Word32
->
Int32
toInt32
=
fromIntegral
(
Add
,
BinOp
Add
e
(
Number
a
),
Number
b
)
->
case
(
readNumber
a
,
readNumber
b
)
of
(
Just
x
,
Just
y
)
->
BinOp
Add
e
$
Number
$
show
(
x
+
y
)
...
...
test/basic/shift.sv
View file @
1903bc19
...
...
@@ -26,5 +26,25 @@ module top;
`TEST
(
2
,
1
)
;
`TEST
(
2
,
2
)
;
`TEST
(
2
,
3
)
;
`TEST
(
-
8589934592
,
0
)
;
`TEST
(
-
8589934592
,
1
)
;
`TEST
(
-
8589934592
,
2
)
;
`TEST
(
-
8589934592
,
3
)
;
`TEST
(
-
8589934593
,
0
)
;
`TEST
(
-
8589934593
,
1
)
;
`TEST
(
-
8589934593
,
2
)
;
`TEST
(
-
8589934593
,
3
)
;
`TEST
(
8589934592
,
0
)
;
`TEST
(
8589934592
,
1
)
;
`TEST
(
8589934592
,
2
)
;
`TEST
(
8589934592
,
3
)
;
`TEST
(
8589934593
,
0
)
;
`TEST
(
8589934593
,
1
)
;
`TEST
(
8589934593
,
2
)
;
`TEST
(
8589934593
,
3
)
;
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