-
Notifications
You must be signed in to change notification settings - Fork 15
/
runtime.py
executable file
·1131 lines (963 loc) · 29.6 KB
/
runtime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#Copyright (C) 2019 Jon Pry
#
#This file is part of Pill.
#
#Pill is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 2 of the License, or
#(at your option) any later version.
#
#Pill is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with Pill. If not, see <http://www.gnu.org/licenses/>.
import inspect
import sys
import os
import re
import props
from tools import Lazy
import klayout.db as db
import klayout.lib
import tools
import math
import context
import geom
import uuid
layout = db.Layout()
layout.dbu = .001
######## These are implementations of Skill standard library functions
def getsqg(*s):
print("*****GetSqG" + str(len(s)))
ret = None
print(s)
l = s[0]
if not l:
return l
if isinstance(l,props.PropertyDict):
print("was property dict")
if s[1] in l:
ret = l[s[1]]
else:
l = list(l.values())
if not ret:
if not isinstance(l,list):
print("not list")
if s[1] in l:
ret = l[s[1]]
else:
print("was list")
ret = []
for e in l:
if len(s) > 1 and s[1] in e:
ret.append(e[s[1]])
if len(ret) == 1:
ret = ret[0]
if len(ret) == 0:
ret = None
if len(s) > 2:
ret = getsqg(*([ret] + list(s[2:])))
print("*****GetSqG ret")
print(ret)
return ret
def setsqg(a,b):
#assert(False)
pass
def stringp(s):
return isinstance(s,str) or isinstance(s,props.StringProperty)
def floatp(s):
print("floatp")
print(type(s))
print(s)
return isinstance(s,float)
def fixp(s):
return isinstance(s,int) and not (isinstance(s,bool) or isinstance(s,props.BooleanProperty))
def numberp(s):
return fixp(s) or isinstance(s,float)
def boundp(e):
return e.expr in skill.variables
def greaterp(a,b):
return a > b
def makeTable(name,default):
return tools.SkillTable(name,default)
def mod(a,b):
return a % b
def fix(a):
r = int(math.floor(a))
print("floor: " + str(a) + "=" + str(r))
return r
def dbGet(a,b):
print(b)
if b in context.bag:
print(context.bag[b])
return context.bag[b]
else:
return None
def sprintf(foo,format,*args):
nargs = []
for i in range(len(args)):
if isinstance(args[i],Lazy):
nargs.append(args[i].deref())
else:
nargs.append(args[i])
if nargs[i] == None:
nargs[i] = 0;
nargs=tuple(nargs)
print(format)
print(nargs)
return format.replace("%L","%s") % nargs
def printf(format, *args):
print("DBG print")
print(format)
for a in args:
print(a)
print("END DBG print")
#sys.stdout.write(sprintf(None,format,*args))
def artError(format, *args):
sys.stdout.write(sprintf(None,format,*args))
assert(False)
exit(0)
def listl(*args,**kwargs):
if len(kwargs.keys()):
assert(len(args) == 0)
return kwargs
print("listl: " + str(args))
return list(args)
def car(l):
print(l)
if isinstance(l,list) or isinstance(l,tools.Lazy):
if len(l):
return l[0]
else:
return l
return l
def cadr(l):
return car(cdr(l))
def caar(l):
return car(car(l))
def cadar(l):
return car(cdr(car(l)))
def cadadr(l):
return car(cdr(car(cdr(l))))
def caadr(l):
return car(car(cdr(l)))
def cdr(l):
return l[1:]
def cddr(l):
return cdr(cdr(l))
def cdddr(l):
return cdr(cdr(cdr(l)))
def caddr(l):
return car(cdr(cdr(l)))
def cadddr(l):
return car(cdr(cdr(cdr(l))))
def cddddr(l):
return car(cdr(cdr(cdr(cdr(l)))))
def yCoord(l):
return l[1]
def evalstring(s):
print("eval: " + s)
v = interp(s)
print(v)
return v
def techGetParam(db,ob):
techParms = { "cadGrid" : 0.005 }
return techParms[ob]
def cdfParseFloatString(s):
print("cdfParseFloatString: " + str(s) + ", " + str(s[-1]) + ", " + str(type(s)))
for i in range(len(s)):
print(str(s[i]))
try:
return float(s)
except:
pass
postfix = 1.0
if s[-1] == "n":
postfix = 1e-9
s=s[:-1]
elif s[-1] == "u":
postfix = 1e-6
s=s[:-1]
elif s[-1] == "m":
postfix = 1e-3
s=s[:-1]
try:
v = float(s)*postfix
except:
print("*******" + s)
raise
print("cdfFloat: " + str(v))
return v
def maplayer(layer):
print(layer[0])
if not isinstance(layer,list):
print("drawing")
layer = [layer, "drawing"]
if isinstance(layer[0],int):
return layout.layer(int(layer[0]),int(layer[1])) #TODO: handle purpose
if (layer[0],layer[1]) in layermap:
l1 = layermap[ (layer[0],layer[1]) ]
print("layer: " + str(l1))
l1 = layout.layer(l1[0], l1[1])
return l1
return -1
def rodCreateRectBase(layer,width,length,origin=[0,0],elementsX=1,spaceX=0,termIOType=None,termName=None,pin=None,cvId=None,beginOffset=0,endOffset=0,space=0,subs=None):
r = None
l1 = maplayer(layer)
if not subs:
subs = []
if l1 >= 0:
print("found layer")
r = db.DBox.new(origin[0],origin[1],origin[0]+width,origin[1]+length).to_itype(0.001)
r = top.shapes(l1).insert(r)
subs.append(r)
return createObj(subs=subs,lpp=layer)
rodsByName = {}
def rodCreateRect(layer,width=0,length=0,origin=[0,0],name="",elementsX=1,elementsY=1,spaceX=0,spaceY=0,termIOType=None,
termName=None,pin=None,cvId=None,beginOffset=0,endOffset=0,space=0,fromObj=None,bBox=None,pinLabel=None,
pinLabelLayer=None,subRectArray=None,size=0,pinAccessDir=None,pinLabelHeight=None,pinLabelFont=None,netName=None):
#if subRectArray:
# return
if fromObj:
width=fromObj['width']+size
length=fromObj['length']+size
origin=fromObj['lL']
origin[0] -= size/2
origin[1] -= size/2
if bBox:
origin = bBox[0]
width = bBox[1][0] - bBox[0][0]
length = bBox[1][1] - bBox[0][1]
flocals = locals()
print("rodCreateRect: " + str([arg + ":" + str(flocals[arg]) for arg in inspect.getargspec(rodCreateRect).args]))
objs = []
subs = []
if subRectArray:
assert(elementsX==1 and elementsY==1)
for subRect in subRectArray:
torigin = origin[:]
twidth = width
tlength = length
if "lowerLeftOffsetY" in subRect:
ofst = subRect["lowerLeftOffsetY"]
print("lowerLeftOffsetY: " + str(ofst))
tlength -= ofst
torigin[1] += ofst/2
if "upperRightOffsetY" in subRect:
ofst = subRect["upperRightOffsetY"]
tlength += ofst
torigin[1] -= ofst/2
print("upperRightOffsetY: " + str(ofst))
if "lowerLeftOffsetX" in subRect:
ofst = subRect["lowerLeftOffsetX"]
twidth -= ofst
torigin[0] += ofst/2
if "upperRightOffsetX" in subRect:
ofst = subRect["upperRightOffsetX"]
twidth += ofst
torigin[0] -= ofst/2
swidth = subRect["width"]
slength = subRect["length"]
sspaceX = subRect["spaceX"]
sspaceY = subRect["spaceY"]
#assert(subRect["gap"] == "minimum")
telementsX, fooX = maxNinN(twidth,swidth,sspaceX)
telementsY, fooY = maxNinN(tlength,slength,sspaceY)
for x in range(telementsX):
for y in range(telementsY):
p = addPoint(torigin,[x * (sspaceX+swidth), y * (sspaceY+slength)])
l1 = maplayer(subRect["layer"])
if l1 >= 0:
print("found layer")
r = db.DBox.new(p[0],p[1],p[0]+swidth,p[1]+slength).to_itype(0.001)
r = top.shapes(l1).insert(r)
subs.append(r)
for x in range(int(elementsX)):
for y in range(int(elementsY)):
p = addPoint(origin,[x * (spaceX+width), y * (spaceY+length)])
objs.append(rodCreateRectBase(layer,width,length,origin=p,subs=subs))
print("Hmm")
print(objs)
objs.reverse()
if len(objs)==1:
print(objs[0])
rodsByName[name] = objs[0]
return objs[0]
rodsByName[name] = objs
return objs
def rodTranslate(alignObj,delta,internal=False,done=None):
m = ["lowerLeft","lL", "upperLeft", "uL", "lowerRight", "lR", "upperRight", "uR", "lC",
"uC", "cC", "cR", "cL"]
for h in m:
alignObj[h] = addPoint(alignObj[h],delta)
alignObj['bBox'][0][0] += delta[0]
alignObj['bBox'][1][0] += delta[1]
print("ao: " + str(alignObj))
shapes = alignObj['_shapes']
print("shapes: " + str(shapes))
if not internal:
done = set()
for s in shapes:
print("s: " + str(s))
s.transform(db.DTrans.new(float(delta[0]),float(delta[1])))
done.add(alignObj['_id'])
for m in alignObj['_masters']:
if not m['_id'] in done:
rodTranslate(m,delta,True,done)
for s in alignObj['_slaves']:
if not s['_id'] in done:
rodTranslate(s,delta,True,done)
def rodAlign(alignObj,alignHandle,refObj=None,refHandle=None,ySep=0,xSep=0,refPoint=None):
print("ref: " + str(refObj))
print("alg: " + str(alignObj))
print("pnt: " + str(refPoint))
flocals = locals()
print("rodAlign: " + str([arg + ":" + str(flocals[arg]) for arg in inspect.getargspec(rodAlign).args]))
if not refObj and not alignObj:
return
m = { "lowerLeft" : "lL", "upperLeft" : "uL", "lowerRight" : "lR", "upperRight" : "uR", "lowerCenter" : "lC",
"upperCenter" : "uC", "centerCenter" : "cC", "centerRight" : "cR", "centerLeft" : "cL"}
try:
alignHandle = m[alignHandle]
except:
pass
try:
refHandle = m[refHandle]
except:
pass
if refObj:
refPoint=refObj[refHandle]
delta = subPoint(refPoint,alignObj[alignHandle])
delta = addPoint(delta,[xSep,ySep])
print("Align: " + str(delta))
rodTranslate(alignObj,delta)
if refObj:
alignObj['_masters'].append(refObj)
refObj['_slaves'].append(alignObj)
def leftEdge(rod):
if isinstance(rod,list):
return rod[0][0]
return rod['lL'][0]
def topEdge(rod):
if isinstance(rod,list):
return rod[1][0] + rod[1][1]
return rod['uR'][1]
def bottomEdge(rod):
if isinstance(rod,list):
return rod[1][0]
return rod['lL'][1]
def rightEdge(rod):
if isinstance(rod,list):
return rod[0][0] + rod[0][1]
return rod['uR'][0]
def addPoint(a,b):
return [a[0]+b[0],a[1]+b[1]]
def subPoint(a,b):
return [a[0]-b[0],a[1]-b[1]]
def maxNinN(limit,obj,space):
n = int(limit / (obj + space))
#sometimes an extra can fit
if n*space + (n+1)*obj <= limit:
n += 1
if n <= 1:
space = (limit - n * obj)/2
else:
space = (limit - n * obj) / (n-1)
return (n,space)
def rodFillBBoxWithRects(layer,fillBBox,width,length,spaceX,spaceY,gap="distribute",cvId=None):
print("filBbox")
#assert(gap=="distribute")
origin = fillBBox[0]
bwidth = fillBBox[1][0] - fillBBox[0][0]
blength = fillBBox[1][1] - fillBBox[0][1]
p = addPoint(origin,[bwidth/2,0])
p = addPoint(p,[-width/2,0])
rects = []
ny,spaceY = maxNinN(blength,length,spaceY)
for i in range(ny):
rects = rects + rodCreateRect(layer,width,length,p)['_shapes']
p[1] += spaceY + length
return createObj(subs=rects,lpp=layer)
def createObj(dbox=None,subs=None,lpp=None):
if not(dbox or (subs and len(subs) > 0 and subs[0])):
return None
print("dbox: " + str(dbox))
if subs:
for s in subs:
if dbox:
dbox = dbox + s.dbbox()
else:
dbox = s.dbbox()
ibox = dbox.to_itype(0.001)
dbox = ibox.to_dtype(0.001)
origin = [dbox.p1.x,dbox.p1.y]
twidth = (ibox.p2.x-ibox.p1.x)*0.001
tlength = (ibox.p2.y-ibox.p1.y)*0.001
if twidth > .09999999 and twidth < .1:
print("%.20e %.20e %.20e %d %d %.20e %.20e" % (twidth, dbox.p2.x, dbox.p1.x, ibox.p2.x, ibox.p1.x, 105*.001, 5*.001))
assert(False)
if not subs:
subs = []
obj = { "lL" : [origin[0],origin[1]],
"uL" : [origin[0],origin[1]+tlength],
'lR' : [origin[0]+twidth,origin[1]],
'uR' : [origin[0]+twidth,origin[1]+tlength],
'lC' : [origin[0]+twidth/2,origin[1]],
'uC' : [origin[0]+twidth/2,origin[1]+tlength],
'cC' : [origin[0]+twidth/2,origin[1]+tlength/2],
'cR' : [origin[0]+twidth,origin[1]+tlength/2],
'cL' : [origin[0],origin[1]+tlength/2],
'length' : tlength,
'width' : twidth,
'dbId' : {'pin' : None},
'_shapes' : subs,
'_slaves' : [],
'_masters' : [],
'_transform' : None,
'_id' : uuid.uuid1(),
'_ttype' : 'ROD'}
obj['lowerLeft'] = obj['lL']
obj['lowerRight'] = obj['lR']
obj['upperRight'] = obj['uR']
obj['upperLeft'] = obj['uL']
obj['dbId'] = obj['_id']
obj['lpp'] = lpp
obj['bBox'] = [[origin[0],origin[1]],[origin[0]+twidth,origin[1]+tlength]]
print("createObj: " + str(obj))
context.shapes.append(obj)
return obj
def rodCreatePath(layer,width,pts,termIOType=None,termName=None,pin=None,subRect=None,name="",justification="center"):
subs = []
print("createPath: " + str(pts) + ", layer: " + str(layer) + ", sub: " + str(subRect) + ", just: " + justification)
r = None
if (layer[0],layer[1]) in layermap:
l1 = maplayer(layer)
assert(l1 >= 0)
dpts = []
for p in pts:
dpts.append(db.DPoint.new(p[0],p[1]))
r = geom.Path(dpts,width,justification)
r = top.shapes(l1).insert(r)
subs.append(r)
if subRect:
assert(len(pts) == 2)
assert(env['distributeSingleSubRect'])
assert(len(subRect)==1)
for s in subRect:
n,space = maxNinN(width+s['beginOffset']+s['endOffset'],width,s['space'])
s['elementsX'] = n
s['spaceX'] = space
#s['pin'] = pin
sub = rodCreateRect(**s)
if n==1:
sub = [sub]
for e in sub:
rodTranslate(e,[-width/2,-width/2])
if n==1:
rodTranslate(e,[twidth/2,0])
else:
rodTranslate(e,[-s['beginOffset']+width/2,0])
subs = subs + e['_shapes']
obj = createObj(subs=subs,lpp=layer)
print("Path: " + str(obj))
rodsByName[name] = obj
return obj
def rodAddPoints(a,b):
return [a[0]+b[0],a[1] + b[1]]
def rodAddToY(a,b):
return [a[0],a[1] + b]
def rodAddToX(a,b):
return [a[0]+b,a[1]]
def makeVector(l,init=None):
return [init]*l
def rodCreatePolygon(name="",layer=None,fromObj=None,pts=None,pin=None,termName=None,termIOType=None,pinAccessDir=None):
print("rodCreatePolygon: \"" + name + "\", " + str(layer))
l1 = maplayer(layer)
assert(l1 >= 0)
if pts:
dpts = []
print("Pts: " + str(len(pts)))
for p in pts:
print(p)
dpts.append(db.DPoint.new(p[0],p[1]))
r = db.DPolygon.new(dpts)
else:
r = db.DPolygon.new(db.DBox.new(fromObj['lL'][0],fromObj['lL'][1],fromObj['uR'][0],fromObj['uR'][1]))
r = top.shapes(l1).insert(r)
obj = createObj(subs=[r],lpp=layer)
rodsByName[name] = obj
return obj
def dbCreatePolygon(cv,layer,pts):
print("dbCreatePolygon: \"" + str(cv) + "\", " + str(layer))
l1 = maplayer(layer)
assert(l1 >= 0)
dpts = []
for p in pts:
dpts.append(db.DPoint.new(p[0],p[1]))
r = db.DPolygon.new(dpts)
r = top.shapes(l1).insert(r)
def rodAssignHandleToParameter(**kwargs):
print("assignHandle: " + str(kwargs))
return None
def rodGetObj(i,cv=None):
print("rodGetObject: " + str(i))
if '_ttype' in i:
if i['_ttype'] == "ROD":
return i
print(rodsByName.keys())
if i in rodsByName:
print(rodsByName[i])
return rodsByName[i]
s = i.split("/")
if len(s) > 1:
tx = []
print("rod subobject query: " + str(s))
cmap = rodsByName
inst = rodsByName[s[0]]
dbox = None
got_shape=False
for e in s:
e = cmap[e]
cell = e['_shapes'][0]
if isinstance(cell,db.Instance):
cmap = rod_map[cell.cell.basic_name()]
tx.append(cell.dtrans)
else:
got_shape=True
dbox = e['_shapes'][0].dbbox()
#accumulate the transforms
if not got_shape:
print(dbox)
dbox.p1 = db.DPoint.new(0,0) #If only have a cell, then all stuff relative to origin
dbox.p2 = dbox.p1
total = db.DTrans()
for t in tx:
total = total * t
if not dbox:
write()
exit()
dbox = total.trans(dbox)
obj = createObj(dbox=dbox)
obj['_slaves'].append(inst)
inst['_masters'].append(obj)
obj['_transform'] = total
rodsByName[i] = obj
return obj
write()
assert(False)
exit(0)
print("****************getObject failed")
return None
def rodPointX(l):
return l[0]
def rodPointY(l):
return l[1]
def snapToGrid(v,g):
ret = round(v/float(g))*g
return ret
#dbCreateLabel(cv 4 1:1 "myLabel" "centerLeft" "R0" "roman" 2)
def dbCreateLabel(cell,layer,origin,text,justification=None,orientation=None,font=None,height=1):
l1 = maplayer(layer)
t = db.DText.new(text,origin[0],origin[1])
t.size = height
t.halign = 1 #center
t.valign = 1 #center
top.shapes(l1).insert(t)
flocals = locals()
print("createLabel: " + str([flocals[arg] for arg in inspect.getargspec(dbCreateLabel).args]))
def dbCreateProp(cv,prop,t,val):
print("dbCreateProp: " + prop + ", " + str(val))
def dbOpenCellViewByType(lib,cell,purpose,t):
print("dbOpenCellViewByType: " + cell)
ret = { 'name' : cell, 'isParamCell' : True}
ret.update(iprops(cell))
return ret
def dbOpenCellView(lib,cell,purpose,t,m):
print("dbOpenCellView: " + cell)
ret = { 'name' : cell, 'isParamCell' : True}
ret.update(iprops(cell))
return ret
def dbCreateRect(cell,layer,coord):
print("dbCreateRect: " + str(layer) + ", " + str(coord))
#assert(False)
return rodCreateRect(layer,coord[1][0] - coord[0][0],coord[1][1] - coord[0][1],coord[0])
def getRot(o):
if o == "R0":
return db.DTrans.R0
if o == "MY":
return db.DTrans.M90
if o == "MX":
return db.DTrans.M0
if o == "R90":
return db.DTrans.R90
if o == "R180":
return db.DTrans.R180
if o == "R270":
return db.DTrans.R270
print(o)
assert(False)
def dbCreateParamInst(view, master, name, origin, orient, num=1, parm=None, phys=False):
cell = master['name']
print("dbCreateParamInst: \"" + str(cell) + "\", " + str(name) + ", " + str(origin) + "," + str(orient) + ", " + str(parm))
assert(num==1)
kobj = ilayout(cell,parm)
if not kobj:
print("Instantiation failed")
assert(False)
return None
dcell = db.DCellInstArray.new(kobj.cell_index(),db.DTrans.new(getRot(orient),0,0))
ctr = dcell.bbox(layout).center()
trans = dcell.trans
trans = db.DTrans.new(0,False,origin[0],origin[1]) * trans
# if orient=="MY":
# trans = db.DTrans.new(0,False,ctr.x*4,ctr.y*2) * trans
dcell.trans = trans
print("CREATEPARAM")
print(ctr)
ctr = dcell.bbox(layout).center()
print(ctr)
dcell = top.insert(dcell)
ctr2 = dcell.dbbox().transformed(trans).center()
print(ctr2)
print(trans)
##exit(0)
rodobj = createObj(subs=[dcell])
rodsByName[name] = rodobj
rodobj['master'] = master
return rodobj
def dbMoveFig(inst,cv,tr):
print("dbMoveFig: \"" + str(tr) )
#tr[0][1] *= -1
rodTranslate(inst,tr[0])
def dbCreateParamInstByMasterName(view, lib, cell, purpose, name, origin, orient, num=1, params=None, phys=False):
print("paraminst")
dbCreateParamInst(view,cell,name,origin,orient,num,params,phys)
return True
def dbCreateInstByMasterName(view, lib, cell, purpose, name, origin, orient="R0"):
print("createinst")
dbCreateParamInst(view,cell,name,origin,orient,1,None)
return True
def get_pname(s):
print("get_pname: " + str(s))
return s
env = {}
def envSetVal(domain,key,t,v):
env[key] = v
def concat(*args):
ret = ""
for a in args:
ret += str(a)
print("Concat: " + ret)
return ret
def rexMatchp(r,s):
return re.match(r,s)
def nullfunc(*args):
return None
def oddp(v):
return v%2==1
def evenp(v):
return v%2==0
def plusp(v):
return v>=0
def minus(a,b=None):
if b is None:
return -a
return a-b
def listp(v):
return isinstance(v,list)
def isCallable(l):
if not l.expr in skill.procedures:
return False
return not not skill.procedures[l.expr]
def cons(a,b):
if isinstance(a,Lazy):
a = a.deref()
if isinstance(b,Lazy):
b = b.deref()
if not b:
return [a]
if isinstance(b,list):
return [a] + b
return [a,b]
def xcons(a,b):
return cons(b,a)
def parseString(s,t=None):
if not t:
return s.split()
return s.split(t)
def strcat(*a):
ret = ""
for e in a:
ret += e
return ret
def mmax(*l):
print("mmax")
print(*l)
return max(*l)
def mmin(*l):
print("mmin")
print(*l)
return min(*l)
def mapcar(l, v):
assert(False)
def nth(i,l): #TODO: not sure about this
if isinstance(l,Lazy):
print(l.expr)
# l = interp(l.expr)
return l[int(i)]
def getLast(l):
if not l:
return l
return l[-1]
def typep(v):
#TODO: handle props
if isinstance(v,float):
return Lazy('flonum',evalstring)
if isinstance(v,str):
return Lazy('string',evalstring)
if isinstance(v,list):
return Lazy('list',evalstring)
if isinstance(v,int):
return Lazy('fixnum',evalstring)
print(type(v))
assert(False) #TODO:
def null(v):
return not v
def length(l):
print("length")
if l is None:
return 0
return len(l)
#TODO: one of these is wrong
def append(a,b):
if not a:
a = []
a.append(b)
return a
def append1(a,b):
if not a:
a = []
a.append(b)
return a
def getq(a,b):
return a[b]
def snot(a):
return not a
def eval(v):
#TODO: handle props
if isinstance(v,Lazy):
return interp(v.expr)
if isinstance(v,str):
return skill.variables[v]
return v
def writeout(a):
write()
exit(0)
def ddGetObjReadPath(o):
return "."
def zerop(v):
return v == 0
def onep(v):
return v == 1
def close(f):
f.close()
def _gets(f):
s = f.readline()
if s == "":
return None
return s
def substring(s,b,l):
return s[(b-1):][:l]
def setarray(a,b,c):
a[b] = c
def arrayref(a,b):
return a[b]
def findFunc(name):
def find(*args):
print("********************" + name)
print(args)
assert(False)
exit(0)
return find
######################End skill function impls
def write():
layout.write("foo.gds")
layermap = {}
def run(layermap_file,s,r,l,p):
global skill, interp, layermap, ilayout, iprops
skill = s
interp = r
ilayout = l
iprops = p
f = open(layermap_file).read().split("\n")
for l in f:
if len(l) < 1:
continue
if l[0] == "#":
continue
l = l.split()
if len(l) != 4:
continue
layermap[ (l[0],l[1]) ] = [int(l[2]),int(l[3])]
skill.procedures['makeVector'] = makeVector
skill.procedures['stringp'] = stringp
skill.procedures['floatp'] = floatp
skill.procedures['numberp'] = numberp
skill.procedures['fixp'] = fixp
skill.procedures['plusp'] = plusp
skill.procedures['listp'] = listp
skill.procedures['boundp'] = boundp
skill.procedures['zerop'] = zerop
skill.procedures['onep'] = onep
skill.procedures['greaterp'] = greaterp
skill.procedures['null'] = null
skill.procedures['error'] = findFunc('error')
skill.procedures['errset'] = nullfunc
skill.procedures['makeTable'] = makeTable
skill.procedures['dbGet'] = dbGet
skill.procedures['mod'] = mod
skill.procedures['getq'] = getq
skill.procedures['fix'] = fix
skill.procedures['printf'] = printf
skill.procedures['list'] = listl
skill.procedures['car'] = car
skill.procedures['member'] = findFunc('member')
skill.procedures['xCoord'] = car
skill.procedures['cadr'] = cadr
skill.procedures['cdr'] = cdr
skill.procedures['caddr'] = caddr
skill.procedures['cddr'] = cddr
skill.procedures['cdddr'] = cdddr
skill.procedures['caadr'] = caadr
skill.procedures['cadddr'] = cadddr