Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quote stripping in log command #4429

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ endif
+cd tests/various && bash run-test.sh
+cd tests/select && bash run-test.sh
+cd tests/sat && bash run-test.sh
+cd tests/scripts && bash run-test.sh
+cd tests/sim && bash run-test.sh
+cd tests/svinterfaces && bash run-test.sh $(SEEDOPT)
+cd tests/svtypes && bash run-test.sh $(SEEDOPT)
Expand Down
7 changes: 4 additions & 3 deletions docs/source/code_examples/fifo/fifo.out
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,15 @@ yosys> show -color maroon3 c:fifo_reader -color cornflowerblue @new_cells -notit
Writing dot description to `rdata_proc.dot'.
Dumping selected parts of module fifo to page 1.

yosys> flatten
yosys> echo off
echo off
yosys> flatten;;

15. Executing FLATTEN pass (flatten design).
Deleting now unused module $paramod\addr_gen\MAX_DATA=s32'00000000000000000000000100000000.
<suppressed ~2 debug messages>

yosys> clean
Removed 3 unused cells and 25 unused wires.
echo on

yosys> select -set rdata_path o:rdata %ci*

Expand Down
3 changes: 3 additions & 0 deletions docs/source/code_examples/fifo/fifo.ys
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ show -color maroon3 c:fifo_reader -color cornflowerblue @new_cells -notitle -for

# ========================================================

echo off
log "yosys> flatten;;"
flatten;;
echo on
select -set rdata_path o:rdata %ci*
select -set new_cells @rdata_path o:rdata %ci3 %d i:* %d
show -color maroon3 @new_cells -notitle -format dot -prefix rdata_flat @rdata_path
Expand Down
11 changes: 2 additions & 9 deletions docs/source/getting_started/example_synth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ optimizations between modules which would otherwise be missed. Let's run

.. literalinclude:: /code_examples/fifo/fifo.out
:language: doscon
:start-at: yosys> flatten
:end-before: yosys> select
:start-at: yosys> flatten;;
:end-before: echo on
:name: flat_clean
:caption: output of :yoscrypt:`flatten;;`

Expand All @@ -313,13 +313,6 @@ and merged with the ``raddr`` wire feeding into the ``$memrd`` cell. This wire
merging happened during the call to :cmd:ref:`clean` which we can see in the
:ref:`flat_clean`.

.. note::

:cmd:ref:`flatten` and :cmd:ref:`clean` would normally be combined into a
single :yoterm:`yosys> flatten;;` output, but they appear separately here as
a side effect of using :cmd:ref:`echo` for generating the terminal style
output.

Depending on the target architecture, this stage of synthesis might also see
commands such as :cmd:ref:`tribuf` with the ``-logic`` option and
:cmd:ref:`deminout`. These remove tristate and inout constructs respectively,
Expand Down
12 changes: 9 additions & 3 deletions passes/cmds/logcmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,15 @@ struct LogPass : public Pass {
if (push) { log_push(); return; }
if (pop) { log_pop(); return; }

for (; argidx < args.size(); argidx++)
text += args[argidx] + ' ';
if (!text.empty()) text.resize(text.size()-1);
text = args[argidx++];
if (argidx < args.size()) {
for (; argidx < args.size(); argidx++) {
text += ' ' + args[argidx];
}
} else {
if (text.size() > 1 && text[0] == '"' && text[text.size()-1] == '"')
text = text.substr(1, text.size()-2);
}

const char *fmtline = newline ? "%s\n" : "%s";

Expand Down
3 changes: 3 additions & 0 deletions tests/scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.err
*.log
run-test.mk
4 changes: 4 additions & 0 deletions tests/scripts/run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -eu
source ../gen-tests-makefile.sh
run_tests --bash
41 changes: 41 additions & 0 deletions tests/scripts/test_logging.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

var=0
rm -f quotes-*.log quotes-*.err

test_log()
{
# Usage: test_log <log_str> <grep_str>
var=$((var + 1))
log_str="$1"
grep_str="$2"
log_file="quotes-$var.log"
../../yosys -QTq -l $log_file -p "log $log_str"
if ! grep -qx "$grep_str" $log_file; then
echo "ERROR: Expected 'yosys> log $log_str' to log '$grep_str'." > "quotes-$var.err"
cat "quotes-$var.err"
fi
}

test_log "test" "test"
test_log "test;" "test"
test_log "test;;" "test"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allows e.g. log "yosys> flatten;;", logging the unquoted text yosys> flatten;;.

Doesn't this line test that the semicolons would be discarded?

Copy link
Member Author

@KrystalDelusion KrystalDelusion Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, contrast with the later test_log "\"test;;\"" "test;;" which tests if putting them in quotes prevents removing them, i.e. "\"test;;\"" -> log "test;;" because bash doesn't include the outer quotes when doing the variable substitution.

test_log "\"test" "\"test"
test_log "test\"" "test\""
test_log "\"test\"" "test"
test_log "\"test;\"" "test;"
test_log "\"test;;\"" "test;;"
test_log "\"test\" abc" "\"test\" abc"
test_log "\"#comments\" #123" "#comments"
test_log "\"!bang\"" "!bang"
test_log "\"spaces are cool too\"" "spaces are cool too"
test_log "\"log a\"; log b" "log a"
test_log "\"log a\"; log b" "b"
test_log "\"" "\""
test_log "\\\"" "\\\\\"" #\" == \"
test_log "\"abc\" \"def\"" "\"abc\" \"def\"" # don't abbreviate to abc" "def

errors=( quotes-*.err )
if [ -f $errors ] ; then
exit 1
fi
Loading