//anc.bcpl
//new analyzer for sil files

// last modified by McCreight, November 15, 1977 10:50 AM
get "sysdefs.d"
get "ana.defs"

// P R I N T I N T E R N A L D A T A S T R U C T U R E S


static
[
printsyms = false //these things are normally used and generate much
//printing. they may be turned on using Swat
printlibs = false
]

let PrintStructs() be
[
//first, print all the macro names which are used
Wss(ErFile,"*n*nMACROS USED:")
for i = 8 to 13 do PrintMacs(i)

//print the definitions in the library fonts
if printlibs then
[
Wss(ErFile,"*n*nLIBRARY MACRO DEFINITIONS:")
for i =8 to 13 do PrintLibDefs(i)
]

//print the contents of the symbol table
if printsyms then
[
Wss(ErFile,"*n*nSYMBOL TABLE:")
for i = 0 to htsize-1 do
[
let link = hashtab!i
until link eq 0 do
[
PrintStrec(link)
link = @link
]
]
]

//components
PrintThings("COMPONENTS:",PrintComp,Comps)

//vertical lines
PrintThings("VERTICAL LINES:",PrintLine,Vlines)

//horizontal lines
PrintThings("HORIZONTAL LINES:",PrintLine,Hlines)

//strings
PrintThings("STRINGS:",PrintNode,Strings)

//numbers
PrintThings("NUMBERS:",PrintNode,Numbers)

//board locations and groups
PrintThings("BOARD LOCATIONS AND PACKAGE GROUPS:",PrintNode,Locgroups)

//special font3 characters
PrintThings("SPECIAL CHARACTERS:",PrintNode,Schars)
]

and PrintMacs(font) be
[
let v = vec 128; v!0 = 0
AppendC($*n,v)
AppendN(font-4,v) //user font number
AppendS(": ",v)
let mbase = Mact+ 128*(font-8)
for i = 0 to 127 do if mbase!i ne 0 then
[
if i ls #40 then //shouldn’t be any control char. macros
[
AppendC($↑,v)
AppendC($A+i,v)
loop
]
AppendC(i,v)
]
Wss(ErFile,v)
]

and PrintLibDefs(font) be
[
let mbase = Mact+128*(font-8) //internal font number
for i = 0 to 127 do
[
if mbase!i eq 0 then loop
let v = vec 128;v!0=0
AppendS("*n*nFont: ",v)
AppendN(font-4,v)
AppendS(" Char: ",v)
if i ls #40 then AppendC($↑,v)
AppendC(i ls #40?i+$A,i,v)
AppendS(" Link=",v)
let link = mbase!i
AppendB(link,v)
Wss(ErFile,v)

until (link eq 0)%(link eq -1) do //possible that definition is not there
[
let btype = link>>node.type
if (btype eq btString)%(btype eq btSchar) then PrintNode(link)

link = @link
]
]
]



and PrintStrec(stp) be
[
let v = vec 128; v!0 = 0
AppendC($*n,v)
AppendB(stp,v)
let s = selecton stp>>strec.type into
[
case stComp: ": Component print name: ’"
case stPin: ": Pin Name: ’"
case stSig: ": Signal Name: ’"
case stRcomp: ": Component real name: ’"
case stBrdloc: ": Board location: ’"
default: ": ERROR: ’"
]

AppendS(s,v)
AppendS(lv(stp>>strec.st),v)
AppendC($’,v)
Wss(ErFile,v)
]

and PrintThings(hdrs,printfn,list)be
[
Wss(ErFile,"*n*n")
Wss(ErFile,hdrs)
let link = list
until link eq 0 do
[
printfn(link)
link = @link
]
]

and PrintLine(ptr) be
[
let v = vec 128;v!0=0
AppendC($*n,v)
AppendB(ptr,v)
AppendS(": (",v)
AppendN(ptr>>lend.x,v)
AppendC($,,v)
AppendN(ptr>>lend.y,v)
AppendS(ptr>>lend.marked eq 0?") nomark, ",") marked, ",v)
AppendS(ptr>>lend.hassig eq 0?"no","has",v)
AppendS(" sig, cp0-2:",v)
for i = 0 to 2 do
[
AppendC($*s,v)
AppendB(ptr>>lend.cp↑i,v)
]
Wss(ErFile,v)
]

and PrintNode(ptr) be
[
let v = vec 128;v!0=0;AppendC($*n,v)
AppendB(ptr,v)
AppendS(ptr>>node.used eq 0?": free ",": used ", v)
AppendB(ptr>>node.assoc,v)
AppendS(" (",v)
AppendN(ptr>>node.x,v)
AppendC($,,v)
AppendN(ptr>>node.y,v)

//the way the value is printed depends on the type of the node
switchon ptr>>node.type into
[
case btString:
[
AppendS(") Str: (",v)
let val = ptr>>node.val
AppendB(val,v)
AppendS(") Type=",v)
let stype = selecton val>>strec.type into
[

case stComp: "Compname: ’"
case stPin: "PinName: ’"
case stSig: "SigName: ’"
case stRcomp: "CompRname: ’"
default: "ERROR: ’"
]
AppendS(stype,v)
AppendS(lv val>>strec.st,v)
AppendC($’,v)
]
endcase

case btNum:
[
AppendS(") Number: ",v)
AppendN(ptr>>node.val,v)
]
endcase

case btLocgroups:
[
AppendS(") Bloc/Grp: ",v)
AppendS(lv (ptr>>node.bloc)>>strec.st, v)
AppendC(ptr>>node.group+$a-1,v)
]
endcase

case btSchar:
[
AppendS(") Schar (font3): ",v)
AppendC(ptr>>node.val,v)
]
endcase

default:
[
AppendS(") ERROR: val is #",v)
AppendB(ptr>>node.val,v)
]
]

Wss(ErFile,v)
]

and PrintComp(ptr) be
[
let v = vec 128;v!0 = 0
let cps = ptr>>comp.conpoints
AppendS("*n*n",v)
AppendB(ptr,v)
AppendS(": (",v)
AppendN(ptr>>comp.xmin,v)
AppendC($*s,v)
AppendN(ptr>>comp.ymin,v)
AppendC($*s,v)
AppendN(ptr>>comp.xmax,v)
AppendC($*s,v)
AppendN(ptr>>comp.ymax,v)
AppendS(") Font: ",v)
AppendN(((ptr>>comp.mindex)/128)+4,v)
AppendS(" Char: ",v)
AppendC((ptr>>comp.mindex)rem 128,v)
AppendS(" ",v)
AppendB(cps,v)
Wss(ErFile,v)
if cps ne 0 then //print the connection point block
[
v!0 = 0
AppendS("*n*t",v)
test cps>>compblock.comptype eq 0
ifso AppendS("Notype",v)
ifnot
[
AppendS(lv ((cps>>compblock.comptype)>>strec.st),v)
AppendS(" (",v)
AppendS(lv(((cps>>compblock.comptype)>>strec.rname)>>strec.st),v)
AppendS(")",v)
]
AppendC($*s,v)
AppendS(lv (cps>>compblock.boardloc)>>strec.st, v)
AppendC((cps>>compblock.group)+$a-1,v)
Wss(ErFile,v)
for i = 1 to cps>>compblock.numcpoints do
[
v!0=0
AppendS("*n*t",v)
AppendN(cps>>compblock.pin↑i,v)
AppendS(": (",v)
AppendN(cps>>compblock.x↑i,v)
AppendC($,,v)
AppendN(cps>>compblock.y↑i,v)
AppendS(") ’",v)
let pn = cps>>compblock.pinname↑i
test pn eq 0
ifso AppendS("nopinname",v)
ifnot AppendS(lv(pn>>strec.st),v)
AppendS("’ ",v)
AppendS(selecton cps>>compblock.cpt↑i into
[
case cptTop: "top "
case cptBot: "bottom"
case cptLeft: "left "
case cptRight: "right "
default: "bad cp type "
]
,v)
AppendB(cps>>compblock.conn↑i,v)
Wss(ErFile,v)
]
]

]