I have input file with data as
cell input out type fun level
AI20 A1,A2,A3 Z comb ((A1A2)) 2
INV I1 ZN comb (!I1) 1
BUF A1,A2,A3,B1 Z comb (!(((A1A2)A3)B1)) 4
CLK C Z seq Cq 1
XOR A1,A2,B1 Z comb (((A1A2)B1) 3
IAD A1,A2,A3 Z comb (!((A1A2)A3)) 3
INV I1 ZN comb (!I1) 1
I want output as below
cell ins input out
AI20 i1 .A1(A),.A2(B),.A3(C) .Z(n1)
INV i2 .I1(n1) .ZN(n2)
BUF i3 .A1(n2),.A2(1),.A3(0),.B1(0) .Z(n3)
CLK i4 .C(n3) .Z(n4)
XOR i5 .A1(n4),.A2(0),.B1(0) .Z(n5)
IAD i6 .A1(1),.A2(n5),.A3(0) .Z(n6)
INV i7 .I1(n6) .ZN(X)
The logic is
if it is first line of input file I.e
AI20assign its inputsA1,A2to user definedA and Band assign it output ton1. For next line in input file assignprevious net n1to one of input and0/1to other inputs of that line and assign its output to next netn2and so on.n1, n2,n3 so onare nets and can be assigned to an array which has no. Of rows equal tono of rows in (input file)-1(no. of rows exclude header row of input file). If it is last line or row of input file then assign that line or row output toX.i1,i2,i3...are instance name which has number of rows equal tono of rows of (input file).A,B,X are user defined. We can directly use them in code. The term inside bracket for input is basically the one present in the previous line in output(). Exception will be for first line input and last line output whose () terms are directly defined.
I used code
awk ' { print $1 ;print "."$2"()"; print "."$3"()" file }'
This gives me, but how can I build logic for inside().
AI20 .A1(), .A2(),.A3() .Z()