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
1de9b69e
Commit
1de9b69e
authored
Jul 10, 2021
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle size casts of string parameters
parent
91a45ce2
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
3 deletions
+59
-3
src/Convert/TypeOf.hs
+15
-3
test/core/string_cast.sv
+29
-0
test/core/string_cast.v
+2
-0
test/core/string_cast_tb.v
+6
-0
test/core/typeof_signed.sv
+7
-0
No files found.
src/Convert/TypeOf.hs
View file @
1de9b69e
...
...
@@ -131,9 +131,21 @@ traverseExprM other =
elaborateSizeCast
::
Expr
->
Expr
->
ST
Expr
elaborateSizeCast
size
value
=
do
t
<-
typeof
value
case
typeSignedness
t
of
Unspecified
->
return
$
Cast
(
Right
size
)
value
sg
->
traverseExprM
$
Cast
(
Left
$
typeOfSize
sg
size
)
value
force
<-
isStringParam
value
case
(
typeSignedness
t
,
force
)
of
(
Unspecified
,
False
)
->
return
$
Cast
(
Right
size
)
value
(
sg
,
_
)
->
traverseExprM
$
Cast
(
Left
$
typeOfSize
sg
size
)
value
-- string params use a self-referential type to enable the string param
-- conversion to add a synthetic parameter if necessary; this check enables size
-- casts to assume a string parameter is unsigned regardless of its length
isStringParam
::
Expr
->
ST
Bool
isStringParam
(
Ident
x
)
=
do
details
<-
lookupElemM
x
return
$
case
details
of
Nothing
->
False
Just
(
_
,
_
,
typ
)
->
typ
==
TypeOf
(
Ident
x
)
isStringParam
_
=
return
False
-- convert TypeOf in a Type
traverseTypeM
::
Type
->
ST
Type
...
...
test/core/string_cast.sv
0 → 100644
View file @
1de9b69e
`ifdef
REF
`define
TEST
(
size
)
\
begin
:
blk
``
size \
reg
[
size
-
1
:
0
]
trim
;
\
trim
=
P
;
$
display
(`"
size
'(
P
)
=
%
b
`",
trim
)
;
\
trim
=
L
;
$
display
(`"
size
'(
L
)
=
%
b
`",
trim
)
;
\
end
`else
`define
TEST
(
size
)
\
$
display
(`"
size
'(
P
)
=
%
b
`",
size
'(
P
))
;
\
$
display
(`"
size
'(
L
)
=
%
b
`",
size
'(
L
))
;
`endif
module
mod
;
parameter
P
=
"asdf"
;
localparam
L
=
"foobar"
;
initial
begin
`TEST
(
1
)
`TEST
(
2
)
`TEST
(
3
)
`TEST
(
4
)
`TEST
(
5
)
`TEST
(
6
)
`TEST
(
7
)
`TEST
(
8
)
`TEST
(
9
)
`TEST
(
10
)
`TEST
(
11
)
`TEST
(
12
)
`TEST
(
13
)
`TEST
(
14
)
`TEST
(
15
)
`TEST
(
16
)
`TEST
(
17
)
`TEST
(
18
)
`TEST
(
19
)
`TEST
(
20
)
`TEST
(
21
)
`TEST
(
22
)
`TEST
(
23
)
`TEST
(
24
)
`TEST
(
25
)
`TEST
(
26
)
`TEST
(
27
)
`TEST
(
28
)
`TEST
(
29
)
`TEST
(
30
)
`TEST
(
31
)
`TEST
(
32
)
`TEST
(
33
)
`TEST
(
34
)
`TEST
(
35
)
`TEST
(
36
)
`TEST
(
37
)
`TEST
(
38
)
`TEST
(
39
)
`TEST
(
40
)
`TEST
(
41
)
`TEST
(
42
)
`TEST
(
43
)
`TEST
(
44
)
`TEST
(
45
)
`TEST
(
46
)
`TEST
(
47
)
`TEST
(
48
)
`TEST
(
49
)
`TEST
(
50
)
`TEST
(
51
)
`TEST
(
52
)
`TEST
(
53
)
`TEST
(
54
)
`TEST
(
55
)
end
endmodule
test/core/string_cast.v
0 → 100644
View file @
1de9b69e
`define
REF
`include
"string_cast.sv"
test/core/string_cast_tb.v
0 → 100644
View file @
1de9b69e
module
top
;
mod
m1
()
;
mod
#(
"foo"
)
m2
()
;
mod
#(
"bar"
)
m3
()
;
mod
#(
"foobar"
)
m4
()
;
endmodule
test/core/typeof_signed.sv
View file @
1de9b69e
...
...
@@ -199,4 +199,11 @@ module top;
`ASSERT_UNSIGNED
(
integer_signed
[
1
])
`ASSERT_UNSIGNED
(
integer_unsigned
[
0
])
`ASSERT_UNSIGNED
(
integer_unsigned
[
1
])
parameter
STR_P
=
"foo"
;
localparam
STR_L
=
"foo"
;
`ASSERT_UNSIGNED
(
STR_P
)
`ASSERT_UNSIGNED
(
STR_L
)
`ASSERT_UNSIGNED
(
64
'
(
STR_P
))
`ASSERT_UNSIGNED
(
64
'
(
STR_L
))
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