├── .ci
├── Dockerfile
├── docker_entry_point.sh
├── setup_ghdl.sh
├── setup_msim.sh
└── setup_xvhdl.sh
├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── ghdl.prj
├── msim.prj
├── run.py
├── run_tests.sh
└── src
├── str_format_pkg.vhd
└── test
└── str_format_tb.vhd
/.ci/Dockerfile:
--------------------------------------------------------------------------------
1 | # This file is part of HDL string format.
2 | #
3 | # Copyright (c) 2015 - 2020 suoto (Andre Souto)
4 | #
5 | # HDL string format is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # HDL string format is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with HDL string format. If not, see .
17 |
18 | FROM suoto/hdl_checker_test:latest
19 |
20 | RUN pip3 install vunit-hdl
21 |
22 | ENV PACKAGES="libx11-6:i386 \
23 | libxrender1:i386 \
24 | libxtst6:i386 \
25 | libxi6:i386 \
26 | libxft2:i386"
27 |
28 |
29 | RUN apt-get update -qq && \
30 | apt-get install -qq $PACKAGES && \
31 | apt-get clean && \
32 | rm -rf /var/lib/apt/lists/*
33 |
34 | ENV BUILDERS /builders
35 | RUN "$BUILDERS/msim/modelsim_ase/linuxaloem/vsim" -version
36 |
--------------------------------------------------------------------------------
/.ci/docker_entry_point.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | # This file is part of HDL string format.
3 | #
4 | # Copyright (c) 2015 - 2020 suoto (Andre Souto)
5 | #
6 | # HDL string format is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation, either version 3 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # HDL string format is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with HDL string format. If not, see .
18 |
19 | set -e
20 |
21 | # Mimic the username, user ID and group ID of the env outside the container to
22 | # avoid permission issues
23 |
24 | USERNAME="${USERNAME:-user}"
25 |
26 | addgroup "$USERNAME" --gid "$GROUP_ID" > /dev/null 2>&1
27 |
28 | adduser --disabled-password \
29 | --gid "$GROUP_ID" \
30 | --uid "$USER_ID" \
31 | --home "/home/$USERNAME" "$USERNAME" > /dev/null 2>&1
32 |
33 | su -l "$USERNAME" -c " \
34 | pushd /hdl_checker && \
35 | PATH=/builders/msim/modelsim_ase/linuxaloem/:$PATH VUNIT_VHDL_STANDARD=93 ./run.py --clean && \
36 | PATH=/builders/msim/modelsim_ase/linuxaloem/:$PATH VUNIT_VHDL_STANDARD=2002 ./run.py --clean && \
37 | PATH=/builders/msim/modelsim_ase/linuxaloem/:$PATH VUNIT_VHDL_STANDARD=2008 ./run.py --clean && \
38 | PATH=/builders/ghdl/bin/:$PATH VUNIT_VHDL_STANDARD=93 ./run.py --clean && \
39 | PATH=/builders/ghdl/bin/:$PATH VUNIT_VHDL_STANDARD=2002 ./run.py --clean && \
40 | PATH=/builders/ghdl/bin/:$PATH VUNIT_VHDL_STANDARD=2008 ./run.py --clean"
41 |
42 |
--------------------------------------------------------------------------------
/.ci/setup_ghdl.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | # This file is part of HDL Code Checker.
3 | #
4 | # HDL Code Checker is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # HDL Code Checker is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with HDL Code Checker. If not, see .
16 |
17 | set -x
18 | set +e
19 |
20 | URL=http://downloads.sourceforge.net/project/ghdl-updates/Builds/ghdl-0.33/ghdl-0.33-x86_64-linux.tgz
21 | CACHE_DIR="${HOME}/cache/"
22 | GHDL_TAR_GZ="${CACHE_DIR}/ghdl.tar.gz"
23 | INSTALLATION_DIR="${HOME}/builders/ghdl/"
24 |
25 | mkdir -p ${CACHE_DIR}
26 | mkdir -p ${INSTALLATION_DIR}
27 | # CWD=$(pwd)
28 |
29 | if [ ! -f "${GHDL_TAR_GZ}" ]; then
30 | wget ${URL} -O ${GHDL_TAR_GZ}
31 | fi
32 |
33 | if [ ! -d "${INSTALLATION_DIR}/bin" ]; then
34 | mkdir -p ${INSTALLATION_DIR}
35 | tar zxvf ${GHDL_TAR_GZ} --directory ${INSTALLATION_DIR}
36 | fi
37 |
38 | ${INSTALLATION_DIR}/bin/ghdl --version
39 |
40 |
--------------------------------------------------------------------------------
/.ci/setup_msim.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | # This file is part of HDL Code Checker.
3 | #
4 | # HDL Code Checker is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # HDL Code Checker is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with HDL Code Checker. If not, see .
16 |
17 | set -x
18 | set +e
19 |
20 | URL=http://download.altera.com/akdlm/software/acdsinst/15.1/185/ib_installers/ModelSimSetup-15.1.0.185-linux.run
21 | CACHE_DIR="${HOME}/cache/"
22 | MSIM_INSTALLER="${CACHE_DIR}/modelsim.run"
23 | INSTALLATION_DIR="${HOME}/builders/msim/"
24 |
25 | mkdir -p ${CACHE_DIR}
26 | CWD=$(pwd)
27 | # cd ${CACHE_DIR}
28 |
29 | if [ ! -f "${MSIM_INSTALLER}" ]; then
30 | wget ${URL} -O ${MSIM_INSTALLER}
31 | chmod +x ${MSIM_INSTALLER}
32 | ${MSIM_INSTALLER} --help
33 | fi
34 |
35 | if [ ! -d "${INSTALLATION_DIR}" ]; then
36 | mkdir -p ${INSTALLATION_DIR}
37 | ${MSIM_INSTALLER} --mode unattended \
38 | --modelsim_edition modelsim_ase \
39 | --installdir "${INSTALLATION_DIR}"
40 | fi
41 |
42 | # uname -a
43 | # ldd ${INSTALLATION_DIR}/modelsim_ase/linux/vcom
44 | # ${INSTALLATION_DIR}/modelsim_ase/linuxaloem/vcom -version
45 |
46 | cd "${CWD}"
47 |
--------------------------------------------------------------------------------
/.ci/setup_xvhdl.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | # This file is part of HDL Code Checker.
3 | #
4 | # HDL Code Checker is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # HDL Code Checker is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with HDL Code Checker. If not, see .
16 |
17 | set -x
18 | set +e
19 |
20 | CACHE_DIR="${HOME}/cache/"
21 |
22 | INSTALLATION_DIR="${HOME}/builders/"
23 |
24 | mkdir -p ${CACHE_DIR}
25 | mkdir -p ${INSTALLATION_DIR}
26 |
27 | XVHDL_TGZ="${CACHE_DIR}/xvhdl.tar.bz2"
28 |
29 | if [ ! -f "${XVHDL_TGZ}.gpg" -a -n "${XVHDL_URL}" ]; then
30 | trap "rm -f -- '$PASS_FILE'" EXIT
31 | wget --no-check-certificate --verbose ${XVHDL_URL} -O ${XVHDL_TGZ}.gpg
32 | trap - EXIT
33 | fi
34 |
35 | echo "==============================="
36 | du -csb ${CACHE_DIR}/*
37 | echo "==============================="
38 |
39 | if [ ! -f "${XVHDL_TGZ}" ]; then
40 | # --------
41 | # Save the passphrase to a file so we don't echo it in the logs
42 | PASS_FILE=$(tempfile)
43 | trap "rm -f -- '$PASS_FILE'" EXIT
44 | set +x
45 | if [ ! -z "$PASS" ]; then
46 | echo $PASS >> $PASS_FILE
47 | else
48 | rm $PASS_FILE
49 | trap - EXIT
50 | fi
51 | set -x
52 | # --------
53 |
54 | cat $PASS_FILE | gpg --batch --passphrase-fd 0 ${XVHDL_TGZ}.gpg
55 |
56 | fi
57 |
58 | ls -ltra ${CACHE_DIR}
59 |
60 | if [ ! -d "${INSTALLATION_DIR}/xvhdl/bin" ]; then
61 | tar xvf ${XVHDL_TGZ} --directory ${INSTALLATION_DIR}
62 | fi
63 |
64 | rm ${XVHDL_TGZ}
65 |
66 | ${INSTALLATION_DIR}/xvhdl/bin/xvhdl --version
67 |
68 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.swp
2 | *.swo
3 |
4 | .msim.prj
5 | .msim/
6 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | # This file is part of HDL string format.
2 | #
3 | # HDL string format is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU General Public License as published by
5 | # the Free Software Foundation, either version 3 of the License, or
6 | # (at your option) any later version.
7 | #
8 | # HDL string format is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU General Public License
14 | # along with HDL string format. If not, see .
15 | ---
16 | language: python
17 |
18 | services:
19 | - docker
20 |
21 | before_install:
22 | - docker pull suoto/hdl_string_format:latest
23 |
24 | script: ./run_tests.sh
25 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # hdl_string_format
2 |
3 | [](https://travis-ci.org/suoto/hdl_string_format)
4 | [](https://github.com/suoto/hdl_string_format)
5 |
6 | hdl_string_format is based on Easics' [PCK_FIO][pck_fio] and aims to provide
7 | C-like string formatting.
8 |
9 | ## Usage
10 |
11 | Please note that the original PCK_FIO manual can be found at [Easics'
12 | site][pck_fio_manual].
13 |
14 | ### fprint
15 |
16 | The `fprint` procedure writes a formatted string to a `line`:
17 |
18 | ```vhdl
19 | variable L : line;
20 | fprint(L, "It's %d now", fo(2016));
21 |
22 | report L.all;
23 | ```
24 |
25 | Should print
26 |
27 | ```
28 | It's 2016 now
29 | ```
30 |
31 | ### sformat
32 |
33 | Very similar to `fprint`, only that it returns a string. The example above
34 | would look like
35 |
36 | ```vhdl
37 | report sformat("It's %d now", fo(2016));
38 | ```
39 |
40 | ### Format specifiers
41 |
42 | The general format of a format specifier is:
43 |
44 | ```
45 | %[-][n]c
46 | ```
47 |
48 | The optional - sign specifies left justified output; default is right justified.
49 |
50 | The optional number n specifies a field width. If it is not specified, fprint
51 | does something reasonable.
52 |
53 | **c** is the conversion specifier. Currently the following conversion specifiers
54 | are supported:
55 |
56 | * **r**: Reasonable output
57 |
58 | Prints the "most reasonable" representation e.g. hex for unsigned, signed and
59 | other bit-like vectors (not preferred for integers)
60 |
61 | * **b**: Bit-oriented output
62 | * **d**: Decimal output
63 | * **s**: string output (e.g. in combination with 'IMAGE for enum types)
64 | * **q**: "qualified" string output (shows internal representation from fo)
65 | * **{}**: Iteration operator, used as follows:
66 |
67 | ```
68 | %n{}
69 | ```
70 |
71 | In this case, n is the iteration count and is mandatory. Iteration can be nested.
72 | Special characters
73 |
74 | To print a double quote, use `""` in the format string (VHDL convention). To
75 | print the special characters, `\`, and `%`, escape them with `\`. To prevent `{`
76 | and `}` from being interpreted as opening and closing brackets in iteration
77 | strings, escape them with `\`.
78 |
79 | ## Copyright
80 |
81 | 1995, 2001 by Jan Decaluwe/Easics NV (under the name PCK_FIO)
82 |
83 | 2016 by Andre Souto (suoto)
84 |
85 | ## License
86 |
87 | This software is licensed under the [GPL v2 license][gpl].
88 |
89 | [pck_fio]: https://www.easics.com/products/freesics
90 | [pck_fio_manual]: https://www.easics.com/pckfio-revision-20027-manual
91 | [gpl]: https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
92 |
93 |
--------------------------------------------------------------------------------
/ghdl.prj:
--------------------------------------------------------------------------------
1 | #
2 | # hdl_string_format -- VHDL package to provide C-like string formatting
3 | #
4 | # Copyright 2016 by Andre Souto (suoto)
5 | #
6 | # This file is part of hdl_string_format.
7 |
8 | # hdl_string_format is free software: you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation, either version 2 of the License, or
11 | # (at your option) any later version.
12 |
13 | # hdl_string_format is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 |
18 | # You should have received a copy of the GNU General Public License
19 | # along with hdl_string_format. If not, see .
20 |
21 | # Compiler selection
22 |
23 | builder = ghdl
24 |
25 | vhdl str_format_tb ./src/test/str_format_tb.vhd --std=08
26 | vhdl str_format ./src/str_format_pkg.vhd --std=08
27 |
28 |
--------------------------------------------------------------------------------
/msim.prj:
--------------------------------------------------------------------------------
1 | #
2 | # hdl_string_format -- VHDL package to provide C-like string formatting
3 | #
4 | # Copyright 2016 by Andre Souto (suoto)
5 | #
6 | # This file is part of hdl_string_format.
7 |
8 | # hdl_string_format is free software: you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation, either version 2 of the License, or
11 | # (at your option) any later version.
12 |
13 | # hdl_string_format is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 |
18 | # You should have received a copy of the GNU General Public License
19 | # along with hdl_string_format. If not, see .
20 |
21 | # Compiler selection
22 |
23 | builder = msim
24 |
25 | vhdl str_format_tb ./src/test/str_format_tb.vhd -93
26 | vhdl str_format ./src/str_format_pkg.vhd -93
27 |
28 |
--------------------------------------------------------------------------------
/run.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | # hdl_string_format -- VHDL package to provide C-like string formatting
3 |
4 | #
5 | # Copyright (c) 2016 - 2020 suoto (Andre Souto)
6 | #
7 | # This file is part of hdl_string_format.
8 |
9 | # hdl_string_format is free software: you can redistribute it and/or modify
10 | # it under the terms of the GNU General Public License as published by
11 | # the Free Software Foundation, either version 2 of the License, or
12 | # (at your option) any later version.
13 |
14 | # hdl_string_format is distributed in the hope that it will be useful,
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | # GNU General Public License for more details.
18 |
19 | # You should have received a copy of the GNU General Public License
20 | # along with hdl_string_format. If not, see .
21 | "hdl_string_format unit tests"
22 |
23 | from os.path import join, dirname
24 | from vunit import VUnit
25 |
26 | def main():
27 | ui = VUnit.from_argv()
28 | ui.enable_location_preprocessing()
29 |
30 | src_path = join(dirname(__file__), "src")
31 |
32 | str_format = ui.add_library("str_format")
33 | str_format.add_source_files(join(src_path, "*.vhd"))
34 |
35 | str_format_tb = ui.add_library("str_format_tb")
36 | str_format_tb.add_source_files(join(src_path, "test", "*.vhd"))
37 |
38 | ui.set_compile_option('modelsim.vcom_flags', ['-novopt', '-explicit'])
39 | ui.set_sim_option('modelsim.vsim_flags', ['-novopt'])
40 | ui.main()
41 |
42 | import sys
43 | sys.exit(main())
44 |
--------------------------------------------------------------------------------
/run_tests.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | # This file is part of HDL string format.
3 | #
4 | # Copyright (c) 2015 - 2019 suoto (Andre Souto)
5 | #
6 | # HDL string format is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation, either version 3 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # HDL string format is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with HDL string format. If not, see .
18 |
19 | set -xe
20 |
21 | PATH_TO_THIS_SCRIPT=$(readlink -f "$(dirname "$0")")
22 |
23 | docker run \
24 | --rm \
25 | --mount type=bind,source="$PATH_TO_THIS_SCRIPT",target=/hdl_checker \
26 | --env USER_ID="$(id -u)" \
27 | --env GROUP_ID="$(id -g)" \
28 | --env USERNAME="$USER" \
29 | suoto/hdl_string_format:latest /bin/bash -c '.ci/docker_entry_point.sh'
30 |
--------------------------------------------------------------------------------
/src/str_format_pkg.vhd:
--------------------------------------------------------------------------------
1 | --
2 | -- hdl_string_format -- VHDL package to provide C-like string formatting
3 | --
4 | -- Copyright 1995, 2001 by Jan Decaluwe/Easics NV (under the name PCK_FIO)
5 | -- Copyright 2016-2018 by Andre Souto (suoto)
6 | --
7 | -- This file is part of hdl_string_format.
8 | --
9 | -- hdl_string_format is free software: you can redistribute it and/or modify
10 | -- it under the terms of the GNU General Public License as published by
11 | -- the Free Software Foundation, either version 3 of the License, or
12 | -- (at your option) any later version.
13 | --
14 | -- hdl_string_format is distributed in the hope that it will be useful,
15 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | -- GNU General Public License for more details.
18 |
19 | -- You should have received a copy of the GNU General Public License
20 | -- along with hdl_string_format. If not, see .
21 |
22 | use std.textio.all;
23 |
24 | library ieee;
25 | use ieee.std_logic_1164.all;
26 | -- signed/unsigned definition: use either std_logic_arith or numeric_std
27 | -- use ieee.std_logic_arith.all; -- the Synopsys one
28 | use ieee.numeric_std.all;
29 |
30 | package str_format_pkg is
31 | -- prefix string for hex output
32 | -- VHDL style: "X"""
33 | -- Verilog style: "h'"
34 | -- C style: "0x"
35 | constant FIO_h_PRE: string := "0x";
36 |
37 | -- postfix string for hex output
38 | -- VHDL style: """"
39 | constant FIO_h_POST: string := "";
40 |
41 | -- prefix string for bit vector output
42 | -- VHDL style: "B"""
43 | -- Verilog style: "b'"
44 | constant FIO_bv_PRE: string := "";
45 |
46 | -- postfix string for bit vector output
47 | -- VHDL style: """"
48 | constant FIO_bv_POST: string := "";
49 |
50 | -- prefix string for bit output
51 | -- VHDL style: "'"
52 | -- Verilog style: "b'"
53 | constant FIO_b_PRE: string := "";
54 |
55 | -- postfix string for bit output
56 | -- VHDL style: "'"
57 | constant FIO_b_POST: string := "";
58 |
59 | -- digit width for the string representation of integers
60 | constant FIO_d_WIDTH: integer := 10;
61 |
62 | -- bit width for the string representation of integers
63 | constant FIO_b_WIDTH: integer := 32;
64 |
65 | -- definition of the NIL string (default value for fprint arguments)
66 | -- fprint stops consuming arguments at the first NIL argument
67 | constant FIO_NIL: string := "\";
68 |
69 | procedure fprint (
70 | L : inout line;
71 | constant format : in string;
72 | A1 , A2 , A3 , A4 , A5 , A6 , A7 , A8 : in string := FIO_NIL;
73 | A9 , A10, A11, A12, A13, A14, A15, A16: in string := FIO_NIL;
74 | A17, A18, A19, A20, A21, A22, A23, A24: in string := FIO_NIL;
75 | A25, A26, A27, A28, A29, A30, A31, A32: in string := FIO_NIL
76 | );
77 |
78 | function fo (constant arg: unsigned) return string;
79 | function fo (constant arg: signed) return string;
80 | function fo (constant arg: std_logic_vector) return string;
81 | -- function fo (arg: std_ulogic_vector) return string;
82 | function fo (constant arg: bit_vector) return string;
83 | function fo (constant arg: integer) return string;
84 | function fo (constant arg: std_ulogic) return string;
85 | function fo (constant arg: bit) return string;
86 | function fo (constant arg: boolean) return string;
87 | function fo (constant arg: character) return string;
88 | function fo (constant arg: string) return string;
89 | function fo (constant arg: time) return string;
90 |
91 | -- procedure FIO_FormatExpand (
92 | -- fmt : inout line;
93 | -- constant format : in string;
94 | -- constant start_pointer : in positive);
95 |
96 | impure function sformat (
97 | constant format : in string;
98 | A1 , A2 , A3 , A4 , A5 , A6 , A7 , A8 : in string := FIO_NIL;
99 | A9 , A10, A11, A12, A13, A14, A15, A16: in string := FIO_NIL;
100 | A17, A18, A19, A20, A21, A22, A23, A24: in string := FIO_NIL;
101 | A25, A26, A27, A28, A29, A30, A31, A32: in string := FIO_NIL) return string;
102 |
103 | end str_format_pkg;
104 |
105 | package body str_format_pkg is
106 |
107 | --------------------------
108 | -- FIO Warnings support --
109 | --------------------------
110 |
111 | procedure FIO_Warning_Fsbla (
112 | L : inout line;
113 | constant format : in string;
114 | constant pointer : in positive) is
115 | begin
116 | fprint (L, "\n** Warning: FIO_PrintLastValue: " &
117 | "format specifier beyond last argument\n");
118 | fprint (L, "** in format string: ""%s""\n", format);
119 | fprint (L, "** ");
120 | for i in 1 to pointer-1 loop
121 | fprint (L, "-");
122 | end loop;
123 | fprint (L, "^\n");
124 | end FIO_Warning_Fsbla;
125 |
126 | procedure FIO_Warning_Ufs (
127 | L : inout line;
128 | constant format : in string;
129 | constant pointer : in positive;
130 | constant char : in character) is
131 | begin
132 | fprint (L, "\n** Warning: FIO_PrintArg: " &
133 | "Unexpected format specifier '%r'\n",
134 | fo(char));
135 | fprint (L, "** in format string: ""%s""\n", format) ;
136 | fprint (L, "** ");
137 | for i in 1 to pointer-1 loop
138 | fprint (L, "-");
139 | end loop;
140 | fprint (L, "^\n** Assuming 'q' to proceed: ");
141 | end FIO_Warning_Ufs;
142 |
143 |
144 | ----------------------------------
145 | -- bit conversion support --
146 | ----------------------------------
147 |
148 | type T_bit_map is array(bit) of character;
149 |
150 | constant C_BIT_MAP: T_bit_map := ('0', '1');
151 |
152 | ----------------------------------
153 | -- std_logic conversion support --
154 | ----------------------------------
155 |
156 | type T_std_logic_map is array(std_ulogic) of character;
157 |
158 | constant C_STD_LOGIC_MAP: T_std_logic_map := ('U', 'X', '0', '1', 'Z', 'W', 'L', 'H',
159 | '-');
160 |
161 | ------------------------------
162 | -- Digit conversion support --
163 | ------------------------------
164 |
165 | -- types & constants
166 |
167 | subtype S_digit_chars is character range '0' to '9';
168 | subtype S_digits is integer range 0 to 9 ;
169 |
170 | type T_digit_chars_map is array(S_digit_chars) of S_digits;
171 |
172 | constant C_DIGIT_CHARS_MAP: T_digit_chars_map := (0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
173 |
174 | type T_digits_map is array(S_digits) of S_digit_chars;
175 |
176 | constant C_DIGITS_MAP: T_digits_map := ('0', '1', '2', '3', '4', '5', '6', '7', '8',
177 | '9');
178 |
179 |
180 | --------------------------------
181 | -- Decimal conversion support --
182 | --------------------------------
183 |
184 | -- unsigned to decimal
185 |
186 | function unsigned_to_decimal (
187 | constant arg : string) return integer is
188 | constant argument : string(arg'length downto 1) := arg;
189 | variable result : integer := 0;
190 | begin
191 | for i in argument'range loop
192 | case argument(i) is
193 | when '1' => result := 2**(i-1) + result;
194 | when '0' => null;
195 | when others => return(-1);
196 | end case;
197 | end loop;
198 | return (result);
199 | end unsigned_to_decimal;
200 |
201 | -- signed to decimal
202 |
203 | function signed_to_decimal (
204 | constant arg : string) return integer is
205 | constant argument : string(arg'length downto 1) := arg;
206 | variable result : integer := 0;
207 | begin
208 | case argument(argument'left) is
209 | when '1' => result := - 2**(argument'left-1);
210 | when '0' => result := 0;
211 | when others => return (integer'low);
212 | end case;
213 |
214 | for i in argument'left-1 downto 1 loop
215 | case argument(i) is
216 | when '1' => result := 2**(i-1) + result;
217 | when '0' => null;
218 | when others => return(integer'low);
219 | end case;
220 | end loop;
221 | return (result);
222 | end signed_to_decimal;
223 |
224 | -- string to decimal
225 |
226 | function integer_to_decimal (
227 | constant arg : string(1 to FIO_d_WIDTH+1)) return integer is
228 | constant sign : character := arg(1);
229 | constant value : string(arg'length-1 downto 1) := arg(2 to arg'length);
230 | variable char : character;
231 | variable result : integer := 0;
232 | begin
233 | result := 0;
234 | for i in value'range loop
235 | result := result * 10;
236 | char := value(i);
237 | if (char /= ' ') then
238 | result := result + C_DIGIT_CHARS_MAP(char);
239 | end if;
240 | end loop;
241 |
242 | case sign is
243 | when '-' => return(-result);
244 | when others => return(result);
245 | end case;
246 | end integer_to_decimal;
247 |
248 | -- boolean (0,1) to decimal
249 |
250 | function bool_to_decimal (
251 | constant arg: string(1 to 1)) return integer is
252 | begin
253 | case arg is
254 | when "1" => return(1);
255 | when "0" => return(0);
256 | when others => return(-1);
257 | end case;
258 | end bool_to_decimal;
259 |
260 | -- boolean (T,F) to decimal
261 |
262 | function true_or_false_to_decimal (
263 | constant arg: string(1 to 1)) return integer is
264 | begin
265 | case arg is
266 | when "T" => return(1);
267 | when others => return(0);
268 | end case;
269 | end true_or_false_to_decimal;
270 |
271 |
272 |
273 | ----------------------------
274 | -- Hex conversion support --
275 | ----------------------------
276 |
277 | -- Constants & types
278 |
279 | constant C_HEX_CHARS: string(1 to 17) := "0123456789ABCDEF?";
280 |
281 | -- Function to return Hex index of a nibble
282 |
283 | function U_To_h_Index(
284 | constant arg: string(4 downto 1)) return integer is
285 | variable index: integer := 0;
286 | begin
287 | for i in arg'range loop
288 | case arg(i) is
289 | when '1' => index := 2**(i-1) + index;
290 | when '0' => null;
291 | when others => return (17);
292 | end case;
293 | end loop;
294 | return (index+1);
295 | end U_To_h_Index;
296 |
297 | -- Hex conversion
298 |
299 | function U_To_h (
300 | constant arg : string) return string is
301 | variable result : string((arg'length-1)/4 +1 downto 1);
302 | variable extarg : string(result'length*4 downto 1) := (others => '0');
303 | begin
304 | extarg(arg'length downto 1) := arg;
305 | for i in result'range loop
306 | result(i) := C_HEX_CHARS(U_To_h_Index( extarg(i*4 downto i*4 -3) ));
307 | end loop;
308 | return (FIO_h_PRE & result & FIO_h_POST);
309 | end U_To_h;
310 |
311 |
312 |
313 | ----------------------------
314 | -- Bit conversion support --
315 | ----------------------------
316 |
317 | function L_To_b (
318 | constant arg : string(1 to 1)) return string is
319 | variable result : string(1 to 1);
320 | begin
321 | case arg is
322 | when "T" => result := "1";
323 | when others => result := "0";
324 | end case;
325 | return(FIO_b_PRE & result & FIO_b_POST);
326 | end L_To_b;
327 |
328 |
329 | function I_To_b (
330 | constant arg : string(1 to FIO_d_WIDTH+1);
331 | constant justified : side;
332 | constant width : integer) return string is
333 | constant blanks : string(1 to FIO_b_WIDTH) := (others => ' ');
334 | variable intvalue : integer := integer_to_decimal(arg);
335 | variable bitvalue : string(1 to FIO_b_WIDTH) := (others => ' ');
336 | variable sign : character := ' ';
337 | variable bitwidth : integer range 0 to FIO_b_WIDTH;
338 | variable mspos : integer range 1 to bitvalue'length;
339 | variable bitvalueextended : string(1 to 2*FIO_b_WIDTH);
340 |
341 | begin
342 |
343 | if (intvalue < 0) then
344 | sign := '-';
345 | intvalue := -intvalue;
346 | end if;
347 |
348 | for i in bitvalue'reverse_range loop
349 | bitvalue(i) := C_DIGITS_MAP(intvalue mod 2);
350 | intvalue := intvalue / 2;
351 | exit when (intvalue = 0);
352 | end loop;
353 |
354 | bitvalueextended := bitvalue & blanks;
355 |
356 | if (width = 0) or (width > FIO_b_WIDTH+1) then
357 | bitwidth := FIO_b_WIDTH;
358 | else
359 | bitwidth := width-1;
360 | end if;
361 |
362 | if (justified = RIGHT) then
363 | return (FIO_bv_PRE & sign &
364 | bitvalue(bitvalue'length-bitwidth+1 to bitvalue'length) &
365 | FIO_bv_POST);
366 | else
367 | for i in bitvalue'range loop
368 | if bitvalue(i) /= ' ' then
369 | mspos := i;
370 | exit;
371 | end if;
372 | end loop;
373 | return (FIO_bv_PRE & sign &
374 | bitvalueextended(mspos to mspos+bitwidth-1) &
375 | FIO_bv_POST);
376 | end if;
377 |
378 | end I_To_b;
379 |
380 |
381 | -----------------------------------
382 | -- Reasonable conversion support --
383 | -----------------------------------
384 |
385 | function I_To_r (
386 | constant arg : string(1 to FIO_d_WIDTH+1);
387 | constant justified : side;
388 | constant width : integer) return string is
389 | constant value : string(1 to FIO_d_WIDTH) := arg(2 to FIO_d_WIDTH+1);
390 | constant sign : character := arg(1);
391 | constant blanks : string(1 to FIO_d_WIDTH) := (others => ' ');
392 | variable intwidth : integer range 0 to FIO_d_WIDTH;
393 | variable mspos : integer range 1 to value'length;
394 | variable valueextended : string(1 to 2*FIO_d_WIDTH) := value & blanks;
395 | begin
396 | if (width = 0) or (width > FIO_d_WIDTH+1) then
397 | intwidth := FIO_d_WIDTH;
398 | else
399 | intwidth := width-1;
400 | end if;
401 | if (justified = RIGHT) then
402 | return (sign & value(value'length-intwidth+1 to value'length));
403 | else
404 | for i in value'range loop
405 | if value(i) /= ' ' then
406 | mspos := i;
407 | exit;
408 | end if;
409 | end loop;
410 | return (sign & valueextended(mspos to mspos+intwidth-1));
411 | end if;
412 | end I_To_r;
413 |
414 |
415 | -------------------------------------------
416 | -- Reasonable output conversion function --
417 | -------------------------------------------
418 |
419 | function ReasonableOutput (
420 | constant arg : string;
421 | constant justified : side;
422 | constant width : integer) return string is
423 | constant argument : string(1 to arg'length) := arg;
424 | constant typespec : string (1 to 2) := argument(1 to 2);
425 | constant value : string(1 to arg'length-2) := argument(3 to arg'length);
426 | begin
427 | case typespec is
428 | when "U:" | "S:" | "V:" =>
429 | return U_To_h(value);
430 | when "I:" =>
431 | return I_To_r(value, justified, width);
432 | when "B:" | "L:" | "C:" =>
433 | return value;
434 | when others =>
435 | return argument;
436 | end case;
437 |
438 | end ReasonableOutput;
439 |
440 |
441 | ------------------------------------
442 | -- Bit output conversion function --
443 | ------------------------------------
444 |
445 | function BitOutput (
446 | constant arg : string;
447 | constant justified : side;
448 | constant width : integer) return string is
449 | constant argument : string(1 to arg'length) := arg;
450 | constant typespec : string (1 to 2) := argument(1 to 2);
451 | constant value : string(1 to arg'length-2) := argument(3 to arg'length);
452 | begin
453 | case typespec is
454 | when "U:" | "S:" | "V:" =>
455 | return (FIO_bv_PRE & value & FIO_bv_POST);
456 | when "B:" =>
457 | -- value(1 to 1) instead of value for LeapFrog
458 | return (FIO_b_PRE & value(1 to 1) & FIO_b_POST);
459 | when "I:" =>
460 | return I_To_b(value, justified, width);
461 | when "L:" =>
462 | -- value(1 to 1) instead of value for LeapFrog
463 | return L_To_b(value(1 to 1));
464 | when others =>
465 | return argument;
466 | end case;
467 |
468 | end BitOutput;
469 |
470 |
471 | -------------------------------------------
472 | -- Decimal output conversion function --
473 | -------------------------------------------
474 |
475 | function DecimalOutput (
476 | constant arg : string) return integer is
477 | constant argument : string(1 to arg'length) := arg;
478 | constant typespec : string (1 to 2) := argument(1 to 2);
479 | constant value : string(1 to arg'length-2) := argument(3 to arg'length);
480 | begin
481 | case typespec is
482 | when "U:"| "V:" =>
483 | return unsigned_to_decimal(value);
484 | when "S:" =>
485 | return signed_to_decimal(value);
486 | when "I:" =>
487 | return integer_to_decimal(value);
488 | when "B:" =>
489 | return bool_to_decimal(value);
490 | when "L:" =>
491 | return true_or_false_to_decimal(value);
492 | when others =>
493 | return integer'low;
494 | end case;
495 |
496 | end DecimalOutput;
497 |
498 |
499 | ----------------------------
500 | -- Atomic print functions --
501 | ----------------------------
502 |
503 | -- test for end of format string
504 |
505 | function FIO_EOS (
506 | constant format: in string;
507 | constant pointer: in integer) return boolean is
508 | begin
509 | return (pointer > format'length);
510 | end FIO_EOS;
511 |
512 |
513 | -- Atomic value print function
514 |
515 | procedure FIO_PrintValue (
516 | L : inout line;
517 | constant format : in string;
518 | pointer : inout integer;
519 | constant Last : in boolean := False) is
520 | variable char : character;
521 | begin
522 | while (not FIO_EOS(format, pointer)) loop
523 | char := format(pointer);
524 | case char is
525 | when '\' =>
526 | pointer := pointer + 1;
527 | exit when (FIO_EOS(format, pointer));
528 | char := format(pointer);
529 | write(L, char);
530 | when '%' =>
531 | pointer := pointer + 1;
532 | exit;
533 | when others =>
534 | write(L, char);
535 | end case;
536 | pointer := pointer + 1;
537 | end loop;
538 | end FIO_PrintValue;
539 |
540 |
541 | ---- Atomic argument print function
542 |
543 | procedure FIO_PrintArg (
544 | L : inout line;
545 | constant format : in string;
546 | pointer : inout integer;
547 | constant arg : in string) is
548 | variable char : character;
549 | variable justified : side;
550 | variable width : integer;
551 |
552 | begin
553 |
554 | FIO_PrintValue(L, format, pointer);
555 |
556 | justified := RIGHT;
557 | width := 0;
558 | while (not FIO_EOS(format, pointer)) loop
559 | char := format(pointer);
560 | case char is
561 | when '-' =>
562 | justified := LEFT;
563 | pointer := pointer + 1;
564 | when '0' to '9' =>
565 | width := width*10 + C_DIGIT_CHARS_MAP(char);
566 | pointer := pointer + 1;
567 | when 'r' =>
568 | write(L, ReasonableOutput(arg, justified, width), justified, width);
569 | pointer := pointer + 1;
570 | exit;
571 | when 'b' =>
572 | write(L, BitOutput(arg, justified, width), justified, width);
573 | pointer := pointer + 1;
574 | exit;
575 | when 'd' =>
576 | write(L, DecimalOutput(arg), justified, width);
577 | pointer := pointer + 1;
578 | exit;
579 | when 'q' | 's' =>
580 | write(L, arg, justified, width);
581 | pointer := pointer + 1;
582 | exit;
583 | when others =>
584 | -- FIO_Warning_Ufs(F, L, format, pointer, char);
585 | write(L, arg, justified, width);
586 | pointer := pointer + 1;
587 | exit;
588 | end case;
589 | end loop;
590 | end FIO_PrintArg;
591 |
592 |
593 | -----------------------------------------------------
594 | -- The format string iteration expansion procedure --
595 | -----------------------------------------------------
596 |
597 | procedure FIO_FormatExpand (
598 | fmt : inout line;
599 | constant format : in string;
600 | constant start_pointer : in positive) is
601 | variable pointer : positive := start_pointer;
602 | variable token_start : positive;
603 | variable iter_str_start : positive;
604 | variable iter_str_end : positive;
605 | variable iter_cnt : natural;
606 | variable open_brackets : natural;
607 | variable L : line;
608 |
609 | begin
610 |
611 | FORMAT_SEARCH: while not FIO_EOS(format, pointer) loop
612 |
613 | case format(pointer) is
614 |
615 | -- look for format specifier
616 | when '%' =>
617 |
618 | -- initialize iteration token search
619 | token_start := pointer;
620 | iter_cnt := 0;
621 | pointer := pointer + 1;
622 |
623 | -- start iteration token search
624 | TOKEN_READ: while not FIO_EOS(format, pointer) loop
625 |
626 | case format(pointer) is
627 |
628 | -- read iteration counter
629 | when '0' to '9' =>
630 | iter_cnt := iter_cnt*10 + C_DIGIT_CHARS_MAP(format(pointer));
631 | pointer := pointer + 1;
632 |
633 | -- expect open bracket
634 | when '{' =>
635 |
636 | -- initialize iteration string read
637 | open_brackets := 1;
638 | iter_str_start := pointer + 1;
639 | pointer := pointer + 1;
640 | -- quit prematurely when iteration count is 0
641 | next FORMAT_SEARCH when (iter_cnt = 0);
642 |
643 | -- start iteration string read
644 | ITER_STRING_READ: while not FIO_EOS(format, pointer) loop
645 |
646 | case format(pointer) is
647 | -- keep track of open brackets
648 | when '{' =>
649 | open_brackets := open_brackets + 1;
650 | pointer := pointer + 1;
651 | -- when closing bracket is found, process iteration string
652 | when '}' =>
653 | open_brackets := open_brackets - 1;
654 | if (open_brackets = 0) then
655 | iter_str_end := pointer-1;
656 | if (token_start /= 1) then
657 | write(L, format(1 to token_start-1));
658 | end if;
659 | for i in 1 to iter_cnt loop
660 | write(L, format(iter_str_start to iter_str_end));
661 | end loop;
662 | if (iter_str_end /= format'length) then
663 | write(L, format(iter_str_end+2 to format'length));
664 | end if;
665 | -- call expansion procedure recursively on expanded format
666 | FIO_FormatExpand(fmt, L.all, token_start);
667 | deallocate(L);
668 | return;
669 | end if;
670 | pointer := pointer + 1;
671 | -- skip escaped characters
672 | when '\' =>
673 | pointer := pointer + 2;
674 | -- read iteration string
675 | when others =>
676 | pointer := pointer + 1;
677 |
678 | end case;
679 |
680 | end loop ITER_STRING_READ;
681 |
682 | -- stop iteration token search when no opening bracket found
683 | when others =>
684 | pointer := pointer + 1;
685 | next FORMAT_SEARCH;
686 |
687 | end case;
688 |
689 | end loop TOKEN_READ;
690 |
691 | -- skip escaped characters
692 | when '\' =>
693 | pointer := pointer + 2;
694 |
695 | -- read other characters
696 | when others =>
697 | pointer := pointer + 1;
698 |
699 | end case;
700 |
701 | end loop FORMAT_SEARCH;
702 |
703 | write(fmt, format);
704 | deallocate(L);
705 |
706 | end FIO_FormatExpand;
707 |
708 |
709 |
710 | --------------------------
711 | -- The fprint procedure --
712 | --------------------------
713 |
714 | procedure fprint (
715 | L : inout line;
716 | constant format : in string;
717 |
718 | A1 , A2 , A3 , A4 , A5 , A6 , A7 , A8 : in string := FIO_NIL;
719 | A9 , A10, A11, A12, A13, A14, A15, A16: in string := FIO_NIL;
720 | A17, A18, A19, A20, A21, A22, A23, A24: in string := FIO_NIL;
721 | A25, A26, A27, A28, A29, A30, A31, A32: in string := FIO_NIL) is
722 |
723 | variable pointer : integer;
724 | variable fmt : line;
725 |
726 | begin
727 |
728 | pointer := 1;
729 |
730 | FIO_FormatExpand (fmt, format, format'low);
731 |
732 | if (A1 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A1 );
733 | if (A2 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A2 );
734 | if (A3 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A3 );
735 | if (A4 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A4 );
736 | if (A5 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A5 );
737 | if (A6 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A6 );
738 | if (A7 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A7 );
739 | if (A8 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A8 );
740 | if (A9 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A9 );
741 | if (A10 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A10);
742 | if (A11 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A11);
743 | if (A12 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A12);
744 | if (A13 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A13);
745 | if (A14 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A14);
746 | if (A15 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A15);
747 | if (A16 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A16);
748 | if (A17 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A17);
749 | if (A18 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A18);
750 | if (A19 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A19);
751 | if (A20 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A20);
752 | if (A21 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A21);
753 | if (A22 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A22);
754 | if (A23 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A23);
755 | if (A24 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A24);
756 | if (A25 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A25);
757 | if (A26 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A26);
758 | if (A27 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A27);
759 | if (A28 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A28);
760 | if (A29 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A29);
761 | if (A30 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A30);
762 | if (A31 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A31);
763 | if (A32 /= FIO_NIL) then FIO_PrintArg(L, fmt.all, pointer, A32);
764 | end if; end if; end if; end if; end if; end if; end if; end if;
765 | end if; end if; end if; end if; end if; end if; end if; end if;
766 | end if; end if; end if; end if; end if; end if; end if; end if;
767 | end if; end if; end if; end if; end if; end if; end if; end if;
768 |
769 | FIO_PrintValue(L, fmt.all, pointer, Last => TRUE);
770 |
771 | deallocate(fmt);
772 |
773 | end fprint;
774 |
775 |
776 | -------------------------------------------
777 | -- Formatted output conversion functions --
778 | -------------------------------------------
779 |
780 | function fo (
781 | constant arg : unsigned) return string is
782 | constant argument : unsigned(1 to arg'length) := arg;
783 | variable result : string(1 to arg'length);
784 | begin
785 | for i in argument'range loop
786 | result(i) := C_STD_LOGIC_MAP(argument(i));
787 | end loop;
788 | return ("U:" & result);
789 | end fo;
790 |
791 | function fo (
792 | constant arg : signed) return string is
793 | constant argument : signed(1 to arg'length) := arg;
794 | variable result : string(1 to arg'length);
795 | begin
796 | for i in argument'range loop
797 | result(i) := C_STD_LOGIC_MAP(argument(i));
798 | end loop;
799 | return ("S:" & result);
800 | end fo;
801 |
802 | function fo (
803 | constant arg : std_logic_vector) return string is
804 | constant argument : std_logic_vector(1 to arg'length) := arg;
805 | variable result : string(1 to arg'length);
806 | begin
807 | for i in argument'range loop
808 | result(i) := C_STD_LOGIC_MAP(argument(i));
809 | end loop;
810 | return ("V:" & result);
811 | end fo;
812 |
813 | -- function fo (arg: std_ulogic_vector) return string is
814 | -- constant argument: std_ulogic_vector(1 to arg'length) := arg;
815 | -- variable result: string(1 to arg'length);
816 | -- begin
817 | -- for i in argument'range loop
818 | -- result(i) := C_STD_LOGIC_MAP(argument(i));
819 | -- end loop;
820 | -- return ("V:" & result);
821 | -- end fo;
822 |
823 | function fo (
824 | constant arg : bit_vector) return string is
825 | constant argument : bit_vector(1 to arg'length) := arg;
826 | variable result : string(1 to arg'length);
827 | begin
828 | for i in argument'range loop
829 | result(i) := C_BIT_MAP(argument(i));
830 | end loop;
831 | return ("V:" & result);
832 | end fo;
833 |
834 | function fo (
835 | constant arg : integer) return string is
836 | variable argument : integer := arg;
837 | variable result : string(1 to FIO_d_WIDTH) := (others => ' ');
838 | variable sign : character := ' ';
839 | begin
840 | if (argument < 0) and (argument /= integer'low) then
841 | sign := '-';
842 | argument := -argument;
843 | end if;
844 | for i in result'reverse_range loop
845 | result(i) := C_DIGITS_MAP(argument mod 10);
846 | argument := argument / 10;
847 | exit when (argument = 0);
848 | end loop;
849 | return ("I:" & sign & result);
850 | end fo;
851 |
852 | function fo (
853 | constant arg: std_ulogic) return string is
854 | begin
855 | return ("B:" & C_STD_LOGIC_MAP(arg));
856 | end fo;
857 |
858 | function fo (
859 | constant arg: bit) return string is
860 | begin
861 | return ("B:" & C_BIT_MAP(arg));
862 | end fo;
863 |
864 | function fo (
865 | constant arg: boolean) return string is
866 | begin
867 | if (ARG = TRUE) then
868 | return ("L:T");
869 | else
870 | return ("L:F");
871 | end if;
872 | end fo;
873 |
874 | function fo (
875 | constant arg : character) return string is
876 | begin
877 | return ("C:" & arg);
878 | end fo;
879 |
880 | -- auxilary function fgets(arg :string)
881 | -- returns index of first NUL in arg or if no NUL is present just arg'length
882 | -- goes through arg from 1 to arg'length
883 | function fgets (
884 | constant arg : string) return integer is
885 | variable index : integer := arg'length;
886 | begin
887 | for i in 1 to arg'length loop
888 | if arg(i) = NUL then
889 | index := i - 1;
890 | exit;
891 | else
892 | null;
893 | end if;
894 | end loop;
895 | return index;
896 | end fgets;
897 |
898 | -- returns the arg string until the first NUL was encountered
899 | -- if fo is used on a string with NUL in it it will stop reading the rest
900 | -- of the string, even if a larger field width has been supplied. fo will
901 | -- then just pad the remaining characters with blanco's
902 | function fo (
903 | constant arg : string) return string is
904 | begin
905 | return arg(1 to fgets(arg));
906 | end fo;
907 |
908 | function fo (
909 | constant arg: time) return string is
910 | begin
911 | return fo (integer (arg / 1 ns));
912 | end fo;
913 |
914 |
915 | --
916 | --
917 | --
918 |
919 | impure function sformat (
920 | constant format : in string;
921 | A1 , A2 , A3 , A4 , A5 , A6 , A7 , A8 : in string := FIO_NIL;
922 | A9 , A10, A11, A12, A13, A14, A15, A16: in string := FIO_NIL;
923 | A17, A18, A19, A20, A21, A22, A23, A24: in string := FIO_NIL;
924 | A25, A26, A27, A28, A29, A30, A31, A32: in string := FIO_NIL
925 | ) return string is
926 | variable L : line;
927 |
928 | -- A helper function to prevent memory leaks.
929 | -- Similar solution as in https://stackoverflow.com/a/42716392
930 | impure function line_to_string return string is
931 | variable ret : string (1 to L'length);
932 | begin
933 | ret := L.all;
934 | deallocate(L);
935 | return ret;
936 | end function;
937 |
938 | begin
939 | fprint (L,
940 | format,
941 | A1 , A2 , A3 , A4 , A5 , A6 , A7 , A8 ,
942 | A9 , A10, A11, A12, A13, A14, A15, A16,
943 | A17, A18, A19, A20, A21, A22, A23, A24,
944 | A25, A26, A27, A28, A29, A30, A31, A32);
945 |
946 | return line_to_string;
947 | end function;
948 |
949 | end str_format_pkg;
950 |
951 |
--------------------------------------------------------------------------------
/src/test/str_format_tb.vhd:
--------------------------------------------------------------------------------
1 | --
2 | -- hdl_string_format -- VHDL package to provide C-like string formatting
3 | --
4 | -- Copyright 1995, 2001 by Jan Decaluwe/Easics NV (under the name PCK_FIO)
5 | -- Copyright 2016-2018 by Andre Souto (suoto)
6 | --
7 | -- This file is part of hdl_string_format.
8 |
9 | -- hdl_string_format is free software: you can redistribute it and/or modify
10 | -- it under the terms of the GNU General Public License as published by
11 | -- the Free Software Foundation, either version 3 of the License, or
12 | -- (at your option) any later version.
13 |
14 | -- hdl_string_format is distributed in the hope that it will be useful,
15 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | -- GNU General Public License for more details.
18 |
19 | -- You should have received a copy of the GNU General Public License
20 | -- along with hdl_string_format. If not, see .
21 | --
22 | --
23 | ---------------
24 | -- Libraries --
25 | ---------------
26 | use std.textio.all;
27 | library ieee;
28 | use ieee.std_logic_1164.all;
29 | use ieee.numeric_std.all;
30 |
31 | -- Could use 'vunit_lib.vunit_context', however, this is a VHDL 2008 construct
32 | -- whereas this library should ideally support 93, 2002 and 2008. Also, to
33 | -- reduce the likelihood of errors when VUnit is updated, we're using a subset
34 | -- of vunit_context containing only the required packages
35 | library vunit_lib;
36 | use vunit_lib.string_ops.all;
37 | use vunit_lib.logger_pkg.all;
38 | use vunit_lib.checker_pkg.all;
39 | use vunit_lib.check_pkg.all;
40 | use vunit_lib.run_pkg.all;
41 |
42 | library str_format;
43 | use str_format.str_format_pkg.all;
44 |
45 | ------------------------
46 | -- Entity declaration --
47 | ------------------------
48 | entity str_format_tb is
49 | generic (runner_cfg : string);
50 | end entity;
51 |
52 | architecture tb of str_format_tb is
53 |
54 | ---------------
55 | -- Constants --
56 | ---------------
57 |
58 | -------------
59 | -- Signals --
60 | -------------
61 |
62 | begin
63 | -------------------
64 | -- Port mappings --
65 | -------------------
66 |
67 | -----------------------------
68 | -- Asynchronous assignments --
69 | -----------------------------
70 | test_runner_watchdog(runner, 10 ms);
71 |
72 | ---------------
73 | -- Processes --
74 | ---------------
75 | main : process
76 | variable stat : checker_stat_t;
77 |
78 | --
79 | variable L : line;
80 | variable pointer : integer := 1;
81 | -- begin
82 |
83 | -- variable value : std_logic_vector(15 downto 0);
84 | constant value : std_logic_vector(15 downto 0) := x"1234";
85 |
86 | impure function colorize (
87 | constant attributes : string) return string is
88 | variable lines : lines_t := split(attributes, " ");
89 | constant attr_cnt : integer := lines'length;
90 | variable attr : line;
91 | begin
92 | for i in 0 to attr_cnt - 1 loop
93 | if lines(i).all = "blink" then write(attr, string'("5"));
94 | elsif lines(i).all = "bold" then write(attr, string'("1"));
95 | elsif lines(i).all = "dim" then write(attr, string'("2"));
96 | elsif lines(i).all = "reverse" then write(attr, string'("7"));
97 | elsif lines(i).all = "highlight" then write(attr, string'("7"));
98 | elsif lines(i).all = "highlight-off" then write(attr, string'("27"));
99 | elsif lines(i).all = "underline" then write(attr, string'("4"));
100 | elsif lines(i).all = "underline-off" then write(attr, string'("24"));
101 | elsif lines(i).all = "black" then write(attr, string'("30"));
102 | elsif lines(i).all = "red" then write(attr, string'("31"));
103 | elsif lines(i).all = "green" then write(attr, string'("32"));
104 | elsif lines(i).all = "yellow" then write(attr, string'("33"));
105 | elsif lines(i).all = "blue" then write(attr, string'("34"));
106 | elsif lines(i).all = "magenta" then write(attr, string'("35"));
107 | elsif lines(i).all = "cyan" then write(attr, string'("36"));
108 | elsif lines(i).all = "gray" then write(attr, string'("37"));
109 | elsif lines(i).all = "bg-black" then write(attr, string'("40"));
110 | elsif lines(i).all = "bg-red" then write(attr, string'("41"));
111 | elsif lines(i).all = "bg-green" then write(attr, string'("42"));
112 | elsif lines(i).all = "bg-yellow" then write(attr, string'("43"));
113 | elsif lines(i).all = "bg-blue" then write(attr, string'("44"));
114 | elsif lines(i).all = "bg-magenta" then write(attr, string'("45"));
115 | elsif lines(i).all = "bg-cyan" then write(attr, string'("46"));
116 | elsif lines(i).all = "bg-gray" then write(attr, string'("47"));
117 | elsif lines(i).all = "reset" then write(attr, string'("0"));
118 | else
119 | report "Invalid attribute name " & lines(i).all
120 | severity Error;
121 | end if;
122 |
123 | if i /= attr_cnt - 1 then
124 | write(attr, string'(";"));
125 | else
126 | write(attr, string'("m"));
127 | end if;
128 |
129 |
130 | end loop;
131 | -- info("attributes: " & attr.all);
132 | return esc & "[" & attr.all;
133 | end function;
134 |
135 | procedure cinfo(
136 | constant message : string) is
137 | begin
138 | write(output, colorize("green"));
139 | info(message & colorize("reset"));
140 | -- write(output, colorize("reset"));
141 | end procedure;
142 |
143 | procedure cwarn(
144 | constant message : string) is
145 | begin
146 | write(output, colorize("yellow"));
147 | warning(message & colorize("reset"));
148 | -- write(output, colorize("reset"));
149 | end procedure;
150 |
151 |
152 | begin
153 | test_runner_setup(runner, runner_cfg);
154 |
155 | while test_suite loop
156 | check_equal(
157 | sformat("Call with no arguments"),
158 | "Call with no arguments");
159 |
160 | check_equal(
161 | sformat("Special characters: \% \\ "),
162 | "Special characters: % \ ");
163 |
164 | check_equal(
165 | sformat("Reasonable output (integer): %r", fo(4660)),
166 | "Reasonable output (integer): 4660");
167 |
168 | check_equal(
169 | sformat("Reasonable output (std_logic_vector): %r", fo(std_logic_vector'(x"1234"))),
170 | "Reasonable output (std_logic_vector): 0x1234");
171 |
172 | check_equal(
173 | sformat("Reasonable output (unsigned): %r", fo(unsigned'(x"1234"))),
174 | "Reasonable output (unsigned): 0x1234");
175 |
176 | check_equal(
177 | sformat("Reasonable output (signed): %r", fo(signed'(x"1234"))),
178 | "Reasonable output (signed): 0x1234");
179 |
180 | -- -- value := std_logic_vector(to_unsigned(16#1234#, 16));
181 | -- cinfo(sformat("Reasonable representation %r", fo(value)));
182 | -- info(sformat("Binary representation %b", fo(value)));
183 | -- cinfo(sformat("Decimal representation: %d", fo(value)));
184 | -- info(sformat("String representation %s", fo(value)));
185 | -- cinfo(sformat("qualified (internal) representation %q", fo(value)));
186 | end loop;
187 |
188 | if not active_python_runner(runner_cfg) then
189 | get_checker_stat(stat);
190 | cinfo(LF & "Result:" & LF & to_string(stat));
191 | end if;
192 |
193 | test_runner_cleanup(runner);
194 | wait;
195 | end process;
196 |
197 | end architecture;
198 |
199 |
--------------------------------------------------------------------------------