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
3b2a55a6
Commit
3b2a55a6
authored
Jun 18, 2023
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better error message for indexed atoms
parent
c103d0cb
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
23 deletions
+46
-23
src/Convert/TypeOf.hs
+33
-23
test/error/typeof_atom_bit.sv
+6
-0
test/error/typeof_atom_range.sv
+7
-0
No files found.
src/Convert/TypeOf.hs
View file @
3b2a55a6
...
@@ -214,18 +214,20 @@ typeof (Number n) =
...
@@ -214,18 +214,20 @@ typeof (Number n) =
typeof
(
Call
(
Ident
x
)
args
)
=
typeofCall
x
args
typeof
(
Call
(
Ident
x
)
args
)
=
typeofCall
x
args
typeof
orig
@
(
Bit
e
_
)
=
do
typeof
orig
@
(
Bit
e
_
)
=
do
t
<-
typeof
e
t
<-
typeof
e
let
t'
=
popRange
t
case
t
of
case
t
of
TypeOf
{}
->
lookup
TypeOf
orig
TypeOf
{}
->
return
$
TypeOf
orig
Alias
{}
->
return
$
TypeOf
orig
Alias
{}
->
return
$
TypeOf
orig
_
->
return
$
typeSignednessOverride
t'
Unsigned
t'
_
->
do
t'
<-
popRange
orig
t
return
$
typeSignednessOverride
t'
Unsigned
t'
typeof
orig
@
(
Range
e
NonIndexed
r
)
=
do
typeof
orig
@
(
Range
e
NonIndexed
r
)
=
do
t
<-
typeof
e
t
<-
typeof
e
let
t'
=
replaceRange
r
t
case
t
of
return
$
case
t
of
TypeOf
{}
->
return
$
TypeOf
orig
TypeOf
{}
->
TypeOf
orig
Alias
{}
->
return
$
TypeOf
orig
Alias
{}
->
TypeOf
orig
_
->
do
_
->
typeSignednessOverride
t'
Unsigned
t'
t'
<-
replaceRange
orig
r
t
return
$
typeSignednessOverride
t'
Unsigned
t'
typeof
(
Range
expr
mode
(
base
,
len
))
=
typeof
(
Range
expr
mode
(
base
,
len
))
=
typeof
$
Range
expr
NonIndexed
$
typeof
$
Range
expr
NonIndexed
$
endianCondRange
index
(
base
,
end
)
(
end
,
base
)
endianCondRange
index
(
base
,
end
)
(
end
,
base
)
...
@@ -398,23 +400,31 @@ injectRanges (UnpackedType t rs) unpacked = UnpackedType t $ unpacked ++ rs
...
@@ -398,23 +400,31 @@ injectRanges (UnpackedType t rs) unpacked = UnpackedType t $ unpacked ++ rs
injectRanges
t
unpacked
=
UnpackedType
t
unpacked
injectRanges
t
unpacked
=
UnpackedType
t
unpacked
-- removes the most significant range of the given type
-- removes the most significant range of the given type
popRange
::
Type
->
Type
popRange
::
Expr
->
Type
->
ST
Type
popRange
(
UnpackedType
t
[
_
])
=
t
popRange
_
(
UnpackedType
t
[
_
])
=
return
t
popRange
(
IntegerAtom
TInteger
sg
)
=
popRange
_
(
IntegerAtom
TInteger
sg
)
=
IntegerVector
TLogic
sg
[]
return
$
IntegerVector
TLogic
sg
[]
popRange
t
=
popRange
e
t
=
tf
rs
case
typeRanges
t
of
where
(
tf
,
_
:
rs
)
=
typeRanges
t
(
tf
,
_
:
rs
)
->
return
$
tf
rs
_
->
indexedAtomError
e
t
-- replaces the most significant range of the given type
-- replaces the most significant range of the given type
replaceRange
::
Range
->
Type
->
Type
replaceRange
::
Expr
->
Range
->
Type
->
ST
Type
replaceRange
r
(
UnpackedType
t
(
_
:
rs
))
=
replaceRange
_
r
(
UnpackedType
t
(
_
:
rs
))
=
UnpackedType
t
(
r
:
rs
)
return
$
UnpackedType
t
(
r
:
rs
)
replaceRange
r
(
IntegerAtom
TInteger
sg
)
=
replaceRange
_
r
(
IntegerAtom
TInteger
sg
)
=
IntegerVector
TLogic
sg
[
r
]
return
$
IntegerVector
TLogic
sg
[
r
]
replaceRange
r
t
=
replaceRange
e
r
t
=
tf
(
r
:
rs
)
case
typeRanges
t
of
where
(
tf
,
_
:
rs
)
=
typeRanges
t
(
tf
,
_
:
rs
)
->
return
$
tf
(
r
:
rs
)
_
->
indexedAtomError
e
t
-- readable error message when looking up the type of a portion of an atom
indexedAtomError
::
Expr
->
Type
->
ST
a
indexedAtomError
e
t
=
scopedErrorM
$
"can't determine the type of "
++
show
e
++
" because the"
++
" inner type "
++
show
t
++
" can't be indexed"
-- checks for a cast type which already trivially matches the expression type
-- checks for a cast type which already trivially matches the expression type
typeCastUnneeded
::
Type
->
Type
->
Bool
typeCastUnneeded
::
Type
->
Type
->
Bool
...
...
test/error/typeof_atom_bit.sv
0 → 100644
View file @
3b2a55a6
// pattern: can't determine the type of x\[1\] because the inner type reg can't be indexed
// location: typeof_atom_bit.sv:5:13
module
top
;
reg
x
;
initial
$
display
($
bits
(
x
[
1
]))
;
endmodule
test/error/typeof_atom_range.sv
0 → 100644
View file @
3b2a55a6
// pattern: can't determine the type of x\[1:0\] because the inner type reg can't be indexed
// location: typeof_atom_range.sv:5:5
module
top
;
reg
x
;
var
type
(
x
[
1
:
0
])
y
;
initial
$
display
(
y
)
;
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