Skip to content

Commit

Permalink
twopass.tcl: improve conflict word handling
Browse files Browse the repository at this point in the history
Halcmd commands 'list' and 'gets' conflict with normal tcl commands.
Improve handling in hal_to_tcl proc:
  list: puts to stdout
  gets: error (since unexpected in a conventional halfile)

Update tests/twopass*/ to
  a) use 'list' not 'show' to preclude possibly variable Owner id
  b) list more hal items for completeness
  • Loading branch information
dngarrett committed Apr 22, 2020
1 parent f3c6832 commit 4aed3e2
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 28 deletions.
35 changes: 26 additions & 9 deletions tcl/twopass.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@ proc ::tp::hal_to_tcl {ifile ofile} {
# I couldn't find any usage examples.

set ::TP(conflictwords) {list gets}
# in a .tcl file, use "hal list" and "hal gets" instead
# 1) list: in the created .tcl file, use "hal list"
# 2) gets: is not epected in a conventional (so err exit)

if [catch {set fdin [open $ifile r]
set fdout [open $ofile w]
Expand Down Expand Up @@ -505,16 +506,27 @@ proc ::tp::hal_to_tcl {ifile ofile} {
break
}

set conflict_tag "_LIST_TAG_"
if {[string first # $line] == 0} continue
foreach suspect $::TP(conflictwords) {
if { ([string first "$suspect " $line] == 0)
|| ([string first " $suspect " $line] >= 0)
} {
puts "hal_to_tcl:NOTE: in file $ifile, line $lno: \"$suspect\"\
conflicts with haltcl usage,\nprepended with 'hal' for compatibility"
puts "$lno:<$theline>"
# prepend hal command to convert conflictword:
set line "# hal_to_tcl prepended hal:\nhal $line"
if { [string first "$suspect" [string trim $line]] == 0 } {
# use stderr to make runtests expected cleaner
switch $suspect {
list {
puts stderr "hal_to_tcl:NOTE: \"$suspect\> in file $ifile\
conflicts with haltcl usage"
puts stderr "near line $lno:<$line>"
puts stderr "prepended with 'hal' for compatibility"
# tag to fix in converted file (after line extends etc)
set line "$conflict_tag $line"
}
default {
# no other conflict words are expected in a conventional halfile
puts stderr "hal_to_tcl:Unexpected <$suspect>: in file $ifile"
puts stderr "$lno:<$line>"
exit 1
}
}
}
}
set idx 0
Expand Down Expand Up @@ -561,6 +573,11 @@ proc ::tp::hal_to_tcl {ifile ofile} {
set comment ";[string range $line $cidx end]"
set line "$notcomment$comment"
}
if {[string first $conflict_tag $line] == 0} {
# remove tag, use puts to output result of list command
# like: puts [hal list ...]
set line "puts \[hal [string range $line [string len $conflict_tag] end] \]"
}
puts $fdout $line
if {[string trim "$theline"] != [string trim "$line"]} {
verbose "converted hal line for tcl from $ifile:"
Expand Down
5 changes: 4 additions & 1 deletion tests/twopass-personality/b.hal
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
loadrt logic names=gateC personality=0x503
loadusr -w halcmd list pin
list pin
list param
list funct
list sig
9 changes: 6 additions & 3 deletions tests/twopass-personality/expected
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
twopass:invoked with <> options
twopass:found ./a.hal
twopass:found ./b.hal
hal_to_tcl:NOTE: in file ./b.hal, line 2: "list" conflicts with haltcl usage,
prepended with 'hal' for compatibility
2:<loadusr -w halcmd list pin>




gateA.and gateA.in-00 gateA.in-01 gateA.in-02 gateA.in-03 gateA.time gateB.in-00 gateB.in-01 gateB.or gateB.time gateC.and gateC.in-00 gateC.in-01 gateC.in-02 gateC.time gateC.xor
gateA.tmax gateA.tmax-increased gateB.tmax gateB.tmax-increased gateC.tmax gateC.tmax-increased
gateA gateB gateC

5 changes: 4 additions & 1 deletion tests/twopass/b.hal
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
loadrt and2 names=andZ
net p andZ.in0
show pin
list pin
list param
list funct
list sig
21 changes: 7 additions & 14 deletions tests/twopass/expected
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
twopass:invoked with <> options
twopass:found ./a.hal
twopass:found ./b.hal
Component Pins:
Owner Type Dir Value Name
4 bit IN FALSE andX.in0 <== p
4 bit IN FALSE andX.in1 <== p
4 bit OUT FALSE andX.out
4 s32 OUT 0 andX.time
4 bit IN FALSE andY.in0
4 bit IN FALSE andY.in1
4 bit OUT FALSE andY.out ==> p
4 s32 OUT 0 andY.time
4 bit IN FALSE andZ.in0 <== p
4 bit IN FALSE andZ.in1
4 bit OUT FALSE andZ.out
4 s32 OUT 0 andZ.time




andX.in0 andX.in1 andX.out andX.time andY.in0 andY.in1 andY.out andY.time andZ.in0 andZ.in1 andZ.out andZ.time
andX.tmax andX.tmax-increased andY.tmax andY.tmax-increased andZ.tmax andZ.tmax-increased
andX andY andZ
p

0 comments on commit 4aed3e2

Please sign in to comment.