Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B-ASIC - Better ASIC Toolbox
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
B-ASIC - Better ASIC Toolbox
Merge requests
!250
Changes to code generation as a result of FPL-2023
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Changes to code generation as a result of FPL-2023
fpl-2023
into
master
Overview
0
Commits
4
Pipelines
1
Changes
4
Merged
Mikael Henriksson
requested to merge
fpl-2023
into
master
2 years ago
Overview
0
Commits
4
Pipelines
1
Changes
4
Expand
0
0
Merge request reports
Viewing commit
9db003b5
Prev
Next
Show latest version
4 files
+
324
−
177
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
9db003b5
codegen: add functions 'write' and 'write_lines', reformat code
· 9db003b5
Mikael Henriksson
authored
2 years ago
b_asic/codegen/vhdl/__init__.py
+
36
−
3
Options
@@ -3,6 +3,7 @@ Module for basic VHDL code generation.
"""
from
io
import
TextIOWrapper
from
typing
import
List
,
Optional
,
Tuple
,
Union
# VHDL code generation tab length
VHDL_TAB
=
r
"
"
@@ -12,7 +13,9 @@ def write(
f
:
TextIOWrapper
,
indent_level
:
int
,
text
:
str
,
*
,
end
:
str
=
'
\n
'
,
start
:
Optional
[
str
]
=
None
,
):
"""
Base VHDL code generation utility. `f
'
{VHDL_TAB*indent_level}
'
` is first written to the :class:`io.TextIOWrapper`
@@ -21,15 +24,45 @@ def write(
Parameters
----------
f : :class:`io.TextIOWrapper`
The file object to emit
the
VHDL code to.
The file object to emit VHDL code to.
indent_level : int
Indentation level to use. Exactly `f
'
{VHDL_TAB*indent_level}` is written before the text is written.
Indentation level to use. Exactly
`
`f
'
{VHDL_TAB*indent_level}`
`
is written before the text is written.
text : str
The text to write to.
end : str, default:
'
\n
'
Text to write exactly after `text` is written to `f`.
Text to write exactly after *text* is written to *f*.
start : str, optional
Text to write before both indentation and *text*.
"""
if
start
is
not
None
:
f
.
write
(
start
)
f
.
write
(
f
'
{
VHDL_TAB
*
indent_level
}{
text
}{
end
}
'
)
def
write_lines
(
f
:
TextIOWrapper
,
lines
:
List
[
Union
[
Tuple
[
int
,
str
],
Tuple
[
int
,
str
,
str
]]]
):
"""
Multiline VHDL code generation utility. Each tuple (int, str, [int]) in the list `lines` is written to the
:class:`io.TextIOWrapper` object `f` using the :function:`vhdl.write` function.
Parameters
----------
f : :class:`io.TextIOWrapper`
The file object to emit VHDL code to.
lines : list of tuple (int,str) [1], or list of tuple (int,str,str) [2]
[1]: The first `int` of the tuple is used as indentation level for the line and
the second `str` of the tuple is the content of the line.
[2]: Same as [1], but the third `str` of the tuple is passed to parameter `end` when calling
:function:`vhdl.write`.
"""
for
tpl
in
lines
:
if
len
(
tpl
)
==
2
:
write
(
f
,
indent_level
=
tpl
[
0
],
text
=
tpl
[
1
])
elif
len
(
tpl
)
==
3
:
write
(
f
,
indent_level
=
tpl
[
0
],
text
=
tpl
[
1
],
end
=
tpl
[
2
])
else
:
raise
ValueError
(
'
All tuples in list `lines` must have length 2 or 3
'
)
from
b_asic.codegen.vhdl
import
architecture
,
common
,
entity
Loading