Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simuDAtor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Computer Engineering
simuDAtor
Commits
b50a0fdd
Commit
b50a0fdd
authored
10 months ago
by
Martin
Browse files
Options
Downloads
Patches
Plain Diff
added back doc string comments that magically disappears from my branch :(
parent
898406ab
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!40
started to seperate state and parameters, ended up doing more work on keeping private variables private
Pipeline
#133246
failed
10 months ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/simudator/core/modules/register.py
+56
-30
56 additions, 30 deletions
src/simudator/core/modules/register.py
with
56 additions
and
30 deletions
src/simudator/core/modules/register.py
+
56
−
30
View file @
b50a0fdd
...
...
@@ -8,23 +8,34 @@ from simudator.core.signal import Signal
class
Register
(
Module
):
"""
A simple module that can store a value.
A simple module that can store and output a value.
Parameters
----------
input : Signal
Signal from which the value is stored in the register.
output : Signal
Signal onto which the value of the register is outputted.
value : Any
Initial value of the register.
name : str
Name of the register.
"""
__slots__
=
"
_value
"
def
__init__
(
self
,
input
_signal
:
Signal
,
output
_signal
:
Signal
,
input
:
Signal
,
output
:
Signal
,
value
:
Any
=
0
,
name
:
str
=
"
Register
"
,
)
->
None
:
# signals
signals
=
{
"
in_content
"
:
input
_signal
,
"
out_content
"
:
output
_signal
,
"
in_content
"
:
input
,
"
out_content
"
:
output
,
}
# init the instance
...
...
@@ -32,9 +43,10 @@ class Register(Module):
self
.
_value
=
value
def
update_register
(
self
)
->
None
:
"""
Propagate the input signal to the registers internal state.
Throw away bits larger than the length of the register.
"""
Update the internal value of the register with the input signal.
Any extra bits that do not fit the bit length of the register are
thrown away.
"""
input_value
=
self
.
signals
[
"
in_content
"
].
get_value
()
if
input_value
is
None
:
...
...
@@ -44,6 +56,7 @@ class Register(Module):
def
output_register
(
self
)
->
None
:
"""
Propagate the value of the register to the output signal.
It is the response of the destination to know when it should
read the output.
"""
...
...
@@ -51,6 +64,8 @@ class Register(Module):
def
update_logic
(
self
):
"""
Do nothing.
The register has no logic.
"""
pass
...
...
@@ -58,7 +73,8 @@ class Register(Module):
def
get_state
(
self
)
->
dict
[
str
,
Any
]:
"""
Returns a dict of the register state.
These states are changable via set_states.
These states are changeable via set_states.
"""
state
=
super
().
get_state
()
state
[
"
value
"
]
=
self
.
_value
...
...
@@ -70,7 +86,13 @@ class Register(Module):
def
set_state
(
self
,
state
:
dict
[
str
,
Any
])
->
None
:
"""
Sets the register state to one given in dict.
Set the state of the register.
Parameters
----------
state : dict[str, Any]
The state of the register to load. Should contain the keys
"
name
"
and
"
value
"
with values of type ``str`` and ``int`` respectively.
"""
self
.
name
=
state
[
"
name
"
]
self
.
_value
=
state
[
"
value
"
]
...
...
@@ -81,9 +103,10 @@ class Register(Module):
"""
self
.
_value
=
0
def
save_state_to_file
(
self
,
file_path
:
str
)
->
True
:
def
save_state_to_file
(
self
,
file_path
:
str
)
->
bool
:
"""
Tries to save the modules state to a given file.
Returns true on success and false if something went wrong.
"""
content
=
self
.
name
+
"
:
\n
"
+
"
value:
"
+
str
(
self
.
_value
)
+
"
\n\n
"
...
...
@@ -101,15 +124,29 @@ class Register(Module):
class
IntegerRegister
(
Register
):
"""
A simple module that can store an integer value with a given bit-length.
A register intended to store integers only.
Parameters
----------
input : Signal
Signal from which the value is stored in the register.
output : Signal
Signal onto which the value of the register is outputted.
bit_length : int
Maximum number of bits of the input to store in the register. All extra
bits of the input value are discarded.
value : Any
Initial value of the register.
name : str
Name of the register.
"""
__slots__
=
"
_bit_length
"
def
__init__
(
self
,
input
_signal
:
Signal
,
output
_signal
:
Signal
,
input
:
Signal
,
output
:
Signal
,
bit_length
:
int
,
value
:
int
=
0
,
name
:
str
|
None
=
None
,
...
...
@@ -119,25 +156,17 @@ class IntegerRegister(Register):
if
name
is
None
:
name
=
f
"
{
bit_length
}
-bit register
"
super
().
__init__
(
input
_signal
,
output
_signal
,
value
=
value
,
name
=
name
)
super
().
__init__
(
input
,
output
,
value
=
value
,
name
=
name
)
# set the bit length of the register
self
.
_bit_length
=
bit_length
def
update_register
(
self
)
->
None
:
"""
Propagate the input signal to the registers internal state.
Throw away bits larger than the length of the register.
"""
super
().
update_register
()
mask
=
2
**
self
.
_bit_length
-
1
self
.
_value
=
self
.
_value
&
mask
def
get_state
(
self
)
->
dict
[
str
,
Any
]:
"""
Returns a dict of the register state.
These states are changable via set_states.
"""
state
=
super
().
get_state
()
return
state
...
...
@@ -150,9 +179,6 @@ class IntegerRegister(Register):
return
parameter
def
set_state
(
self
,
state
:
dict
[
str
,
Any
])
->
None
:
"""
Sets the register state to one given in dict.
"""
super
().
set_state
(
state
)
def
save_state_to_file
(
self
,
file_path
:
str
)
->
None
:
...
...
@@ -177,8 +203,8 @@ class Flag(IntegerRegister):
def
__init__
(
self
,
input
_signal
:
Signal
,
output
_signal
:
Signal
,
input
:
Signal
,
output
:
Signal
,
bit_length
=
1
,
value
=
0
,
name
=
"
Flag
"
,
...
...
@@ -186,8 +212,8 @@ class Flag(IntegerRegister):
# set the flags name
super
().
__init__
(
input
_signal
=
input_signal
,
output
_signal
=
output_signal
,
input
=
input
,
output
=
output
,
bit_length
=
bit_length
,
value
=
value
,
name
=
name
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment