3232import json
3333import cicspi
3434import yaml
35+ import logging
36+
37+
38+ class ColorFormatter (logging .Formatter ):
39+ COLORS = {
40+ 'DEBUG' : '\033 [36m' , # Cyan
41+ 'INFO' : '\033 [32m' , # Green
42+ 'WARNING' : '\033 [33m' , # Yellow
43+ 'ERROR' : '\033 [31m' , # Red
44+ 'CRITICAL' : '\033 [1;31m' # Bold Red
45+ }
46+ RESET = '\033 [0m'
47+
48+ def format (self , record ):
49+ color = self .COLORS .get (record .levelname , self .RESET )
50+ message = super ().format (record )
51+ return f"{ color } { message } { self .RESET } "
52+
53+ log = logging .getLogger ("spi2mag" )
3554
3655@click .group ()
3756@click .pass_context
3857def cli (ctx ):
3958 """ Python toolbox for Custom Integrated Circuit Creator (ciccreator). """
4059 ctx .ensure_object (dict )
60+ handler = logging .StreamHandler ()
61+ formatter = ColorFormatter ('%(levelname)s: %(message)s' )
62+ handler .setFormatter (formatter )
63+
64+ logger = logging .getLogger ()
65+ logger .addHandler (handler )
66+ logger .setLevel (logging .DEBUG )
67+
4168 pass
4269
4370@cli .command ("transpile" )
@@ -251,17 +278,23 @@ def _runMethod(lcell,module,method):
251278 if (module is not None ):
252279 if (hasattr (module ,method )):
253280 fn = getattr (module ,method )
281+ log .info ("Running " + method + " from " + lcell .name + ".py" )
254282 fn (lcell )
255283
256284
257285def _spi2mag (spi ,lib ,cell ,libdir ,techlib ,xspace ,yspace ,gbreak ):
258286
287+
288+
259289 techfile = f"../tech/cic/{ techlib } .tech"
260- print (f"INFO: Loading rules { techfile } " )
290+ log . info (f"Loading rules { techfile } " )
261291 rules = cic .Rules (techfile )
262292
293+ log .info (f"Finding Magic cells in { libdir } " )
263294 design = cic .MagicDesign (techlib ,rules )
264295 design .scanLibraryPath (libdir )
296+
297+ log .info (f"Reading { spi } " )
265298 lcell = design .readFromSpice (spi ,cell )
266299
267300 if ("," in gbreak ):
@@ -288,25 +321,41 @@ def _spi2mag(spi,lib,cell,libdir,techlib,xspace,yspace,gbreak):
288321 pycell = importlib .import_module (lcell .name )
289322 dir (pycell )
290323
291-
324+ log . info ( f"Assembling layout...." )
292325
293326 _runMethod (lcell ,pycell ,"beforePlace" )
327+
328+
294329 #- Place cell
330+ log .info (f"place()" )
295331 lcell .place ()
296332
297333 _runMethod (lcell ,pycell ,"afterPlace" )
298334
335+ _runMethod (lcell ,pycell ,"beforeRoute" )
336+
337+ log .info (f"route()" )
338+ lcell .route ()
339+
340+ _runMethod (lcell ,pycell ,"afterRoute" )
299341
342+ _runMethod (lcell ,pycell ,"beforePaint" )
300343
344+ log .info (f"paint()" )
345+
346+ _runMethod (lcell ,pycell ,"afterPaint" )
347+
348+ log .info (f"addAllPorts()" )
349+ lcell .addAllPorts ()
301350
302351 obj = cic .MagicPrinter (libdir + lib ,rules )
303352 obj .print (design )
304- obj = design .toJson ()
305- with open (libdir + lib + os .path .sep + lcell .name + ".cic" ,"w" ) as fo :
306- fo .write (json .dumps (obj ,indent = 4 ))
353+ #for m in design.maglib.values():
354+ #if(m._lay is not None):
307355
308- #obj = cic.MagicPrinter(libdir + lib,cell)
309- #obj.print(design)
356+ with open (libdir + lib + os .path .sep + lcell .name + ".cic" ,"w" ) as fo :
357+ fo .write (json .dumps (design .toJson (),indent = 4 ))
358+ #fo.write(json.dumps(design.maglib["JNWTR_RPPO2"]._lay.toJson(),indent=4))
310359
311360
312361
0 commit comments