najaeda 0.1.14__cp312-cp312-macosx_11_0_arm64.whl → 0.1.17__cp312-cp312-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of najaeda might be problematic. Click here for more details.

najaeda/netlist.py CHANGED
@@ -9,9 +9,10 @@ import logging
9
9
  import hashlib
10
10
  import struct
11
11
  import sys
12
+ import os
12
13
  from enum import Enum
13
14
 
14
- from najaeda import snl
15
+ from najaeda import naja
15
16
 
16
17
 
17
18
  def get_none_existent():
@@ -44,8 +45,8 @@ def consistent_hash(obj):
44
45
  return int(hashlib.sha256(obj_bytes).hexdigest(), 16)
45
46
 
46
47
 
47
- def get_snl_instance_from_id_list(id_list: list) -> snl.SNLInstance:
48
- design = snl.SNLUniverse.get().getTopDesign()
48
+ def get_snl_instance_from_id_list(id_list: list) -> naja.SNLInstance:
49
+ design = naja.NLUniverse.get().getTopDesign()
49
50
  # instance = None
50
51
  # for id in id_list:
51
52
  # instance = design.getInstanceByID(id)
@@ -55,14 +56,14 @@ def get_snl_instance_from_id_list(id_list: list) -> snl.SNLInstance:
55
56
  return design.getInstanceByIDList(id_list)
56
57
 
57
58
 
58
- def get_snl_path_from_id_list(id_list: list) -> snl.SNLPath:
59
- top = snl.SNLUniverse.get().getTopDesign()
59
+ def get_snl_path_from_id_list(id_list: list) -> naja.SNLPath:
60
+ top = naja.NLUniverse.get().getTopDesign()
60
61
  design = top
61
- path = snl.SNLPath()
62
+ path = naja.SNLPath()
62
63
  for id in id_list:
63
64
  instance = design.getInstanceByID(id)
64
65
  assert instance is not None
65
- path = snl.SNLPath(path, instance)
66
+ path = naja.SNLPath(path, instance)
66
67
  assert path.getTailInstance() is not None
67
68
  design = instance.getModel()
68
69
  if len(id_list) > 0:
@@ -79,7 +80,7 @@ class Equipotential:
79
80
  path = get_snl_path_from_id_list(term.pathIDs)
80
81
  snl_term = get_snl_term_for_ids_with_path(path, term.termIDs)
81
82
  inst_term = None
82
- if isinstance(snl_term, snl.SNLBusTerm):
83
+ if isinstance(snl_term, naja.SNLBusTerm):
83
84
  raise ValueError("Equipotential cannot be constructed on bus term")
84
85
  if len(term.pathIDs) == 0:
85
86
  net = term.get_lower_net()
@@ -91,14 +92,14 @@ class Equipotential:
91
92
  self.equi = None
92
93
  return
93
94
  else:
94
- path = snl.SNLPath(path, get_snl_instance_from_id_list(inst_term.pathIDs))
95
+ path = naja.SNLPath(path, get_snl_instance_from_id_list(inst_term.pathIDs))
95
96
  snl_term = get_snl_term_for_ids(inst_term.pathIDs, inst_term.termIDs)
96
97
  else:
97
98
  inst_term = term
98
- ito = snl.SNLNetComponentOccurrence(
99
+ ito = naja.SNLNetComponentOccurrence(
99
100
  path.getHeadPath(), path.getTailInstance().getInstTerm(snl_term)
100
101
  )
101
- self.equi = snl.SNLEquipotential(ito)
102
+ self.equi = naja.SNLEquipotential(ito)
102
103
 
103
104
  def __eq__(self, value):
104
105
  return self.equi == value.equi
@@ -134,7 +135,7 @@ class Equipotential:
134
135
  if self.equi is not None:
135
136
  for term in self.equi.getInstTermOccurrences():
136
137
  direction = term.getInstTerm().getDirection()
137
- if direction != snl.SNLTerm.Direction.Output:
138
+ if direction != naja.SNLTerm.Direction.Output:
138
139
  if term.getInstTerm().getInstance().getModel().isLeaf():
139
140
  path = term.getPath().getPathIDs()
140
141
  path.append(term.getInstTerm().getInstance().getID())
@@ -145,7 +146,7 @@ class Equipotential:
145
146
  if self.equi is not None:
146
147
  for term in self.equi.getInstTermOccurrences():
147
148
  direction = term.getInstTerm().getDirection()
148
- if direction != snl.SNLTerm.Direction.Input:
149
+ if direction != naja.SNLTerm.Direction.Input:
149
150
  if term.getInstTerm().getInstance().getModel().isLeaf():
150
151
  path = term.getPath().getPathIDs()
151
152
  path.append(term.getInstTerm().getInstance().getID())
@@ -156,31 +157,31 @@ class Equipotential:
156
157
  if self.equi is not None:
157
158
  for term in self.equi.getTerms():
158
159
  direction = term.getDirection()
159
- if direction != snl.SNLTerm.Direction.Input:
160
+ if direction != naja.SNLTerm.Direction.Input:
160
161
  yield Term([], term)
161
162
 
162
163
  def get_top_drivers(self):
163
164
  if self.equi is not None:
164
165
  for term in self.equi.getTerms():
165
166
  direction = term.getDirection()
166
- if direction != snl.SNLTerm.Direction.Output:
167
+ if direction != naja.SNLTerm.Direction.Output:
167
168
  yield Term([], term)
168
169
 
169
170
 
170
171
  class Net:
171
172
  class Type(Enum):
172
- STANDARD = snl.SNLNet.Type.Standard
173
- ASSIGN0 = snl.SNLNet.Type.Assign0
174
- ASSIGN1 = snl.SNLNet.Type.Assign1
175
- SUPPLY0 = snl.SNLNet.Type.Supply0
176
- SUPPLY1 = snl.SNLNet.Type.Supply1
173
+ STANDARD = naja.SNLNet.Type.Standard
174
+ ASSIGN0 = naja.SNLNet.Type.Assign0
175
+ ASSIGN1 = naja.SNLNet.Type.Assign1
176
+ SUPPLY0 = naja.SNLNet.Type.Supply0
177
+ SUPPLY1 = naja.SNLNet.Type.Supply1
177
178
 
178
179
  def __init__(self, path, net=None, net_concat=None):
179
180
  if net is not None and net_concat is not None:
180
181
  raise ValueError(
181
182
  "Only one of `net` or `net_concat` should be provided, not both."
182
183
  )
183
- if isinstance(path, snl.SNLPath):
184
+ if isinstance(path, naja.SNLPath):
184
185
  if path.size() > 0:
185
186
  self.pathIDs = path.getPathIDs()
186
187
  else:
@@ -227,7 +228,7 @@ class Net:
227
228
  :return: the most significant bit of the net if it is a bus.
228
229
  :rtype: int
229
230
  """
230
- if hasattr(self, "net") and isinstance(self.net, snl.SNLBusNet):
231
+ if hasattr(self, "net") and isinstance(self.net, naja.SNLBusNet):
231
232
  return self.net.getMSB()
232
233
  return None
233
234
 
@@ -236,7 +237,7 @@ class Net:
236
237
  :return: the least significant bit of the net if it is a bus.
237
238
  :rtype: int
238
239
  """
239
- if hasattr(self, "net") and isinstance(self.net, snl.SNLBusNet):
240
+ if hasattr(self, "net") and isinstance(self.net, naja.SNLBusNet):
240
241
  return self.net.getLSB()
241
242
  return None
242
243
 
@@ -245,21 +246,21 @@ class Net:
245
246
  :return: True if the net is a bus.
246
247
  :rtype: bool
247
248
  """
248
- return hasattr(self, "net") and isinstance(self.net, snl.SNLBusNet)
249
+ return hasattr(self, "net") and isinstance(self.net, naja.SNLBusNet)
249
250
 
250
251
  def is_bus_bit(self) -> bool:
251
252
  """
252
253
  :return: True if the net is a bit of a bus.
253
254
  :rtype: bool
254
255
  """
255
- return hasattr(self, "net") and isinstance(self.net, snl.SNLBusNetBit)
256
+ return hasattr(self, "net") and isinstance(self.net, naja.SNLBusNetBit)
256
257
 
257
258
  def is_scalar(self) -> bool:
258
259
  """
259
260
  :return: True if the net is a scalar.
260
261
  :rtype: bool
261
262
  """
262
- return hasattr(self, "net") and isinstance(self.net, snl.SNLScalarNet)
263
+ return hasattr(self, "net") and isinstance(self.net, naja.SNLScalarNet)
263
264
 
264
265
  def is_bit(self) -> bool:
265
266
  """
@@ -314,7 +315,7 @@ class Net:
314
315
  :rtype: Iterator[Net]
315
316
  """
316
317
  if hasattr(self, "net"):
317
- if isinstance(self.net, snl.SNLBusNet):
318
+ if isinstance(self.net, naja.SNLBusNet):
318
319
  for bit in self.net.getBits():
319
320
  yield Net(self.pathIDs, bit)
320
321
  else:
@@ -330,7 +331,7 @@ class Net:
330
331
  :rtype: Net
331
332
  """
332
333
  if hasattr(self, "net"):
333
- if isinstance(self.net, snl.SNLBusNet):
334
+ if isinstance(self.net, naja.SNLBusNet):
334
335
  return Net(self.pathIDs, self.net.getBit(index))
335
336
  else:
336
337
  return None
@@ -374,14 +375,14 @@ def get_snl_term_for_ids(pathIDs, termIDs):
374
375
  path = get_snl_path_from_id_list(pathIDs)
375
376
  model = None
376
377
  if len(pathIDs) == 0:
377
- model = snl.SNLUniverse.get().getTopDesign()
378
+ model = naja.NLUniverse.get().getTopDesign()
378
379
  else:
379
380
  model = path.getTailInstance().getModel()
380
381
  if termIDs[1] == get_none_existent():
381
382
  return model.getTermByID(termIDs[0])
382
383
  else:
383
384
  snlterm = model.getTermByID(termIDs[0])
384
- if isinstance(snlterm, snl.SNLBusTerm):
385
+ if isinstance(snlterm, naja.SNLBusTerm):
385
386
  return snlterm.getBusTermBit(termIDs[1])
386
387
  else:
387
388
  return snlterm
@@ -390,27 +391,27 @@ def get_snl_term_for_ids(pathIDs, termIDs):
390
391
  def get_snl_term_for_ids_with_path(path, termIDs):
391
392
  model = None
392
393
  if path.size() == 0:
393
- model = snl.SNLUniverse.get().getTopDesign()
394
+ model = naja.NLUniverse.get().getTopDesign()
394
395
  else:
395
396
  model = path.getTailInstance().getModel()
396
397
  if termIDs[1] == get_none_existent():
397
398
  return model.getTermByID(termIDs[0])
398
399
  else:
399
400
  snlterm = model.getTermByID(termIDs[0])
400
- if isinstance(snlterm, snl.SNLBusTerm):
401
+ if isinstance(snlterm, naja.SNLBusTerm):
401
402
  return snlterm.getBusTermBit(termIDs[1])
402
403
  else:
403
404
  return snlterm
404
405
 
405
406
 
406
407
  class Term:
407
- INPUT = snl.SNLTerm.Direction.Input
408
- OUTPUT = snl.SNLTerm.Direction.Output
409
- INOUT = snl.SNLTerm.Direction.InOut
408
+ INPUT = naja.SNLTerm.Direction.Input
409
+ OUTPUT = naja.SNLTerm.Direction.Output
410
+ INOUT = naja.SNLTerm.Direction.InOut
410
411
 
411
412
  def __init__(self, path, term):
412
413
  # self.termIDs = []
413
- # if isinstance(term, snl.SNLBusTerm):
414
+ # if isinstance(term, naja.SNLBusTerm):
414
415
  # self.termIDs = [term.getID(), -1]
415
416
  # else:
416
417
  self.termIDs = [term.getID(), term.getBit()]
@@ -439,7 +440,7 @@ class Term:
439
440
  def __hash__(self):
440
441
  termIDs = []
441
442
  snlterm = get_snl_term_for_ids(self.pathIDs, self.termIDs)
442
- if isinstance(snlterm, snl.SNLBusTerm):
443
+ if isinstance(snlterm, naja.SNLBusTerm):
443
444
  termIDs = [snlterm.getID(), -1]
444
445
  else:
445
446
  termIDs = [snlterm.getID(), snlterm.getBit()]
@@ -468,7 +469,7 @@ class Term:
468
469
  path = get_snl_path_from_id_list(self.pathIDs)
469
470
  if path.size() > 1:
470
471
  path = path.getHeadPath()
471
- snl.SNLUniquifier(path)
472
+ naja.SNLUniquifier(path)
472
473
 
473
474
  def is_bus(self) -> bool:
474
475
  """
@@ -476,7 +477,7 @@ class Term:
476
477
  :rtype: bool
477
478
  """
478
479
  return isinstance(
479
- get_snl_term_for_ids(self.pathIDs, self.termIDs), snl.SNLBusTerm
480
+ get_snl_term_for_ids(self.pathIDs, self.termIDs), naja.SNLBusTerm
480
481
  )
481
482
 
482
483
  def is_bus_bit(self) -> bool:
@@ -485,7 +486,7 @@ class Term:
485
486
  :rtype: bool
486
487
  """
487
488
  return isinstance(
488
- get_snl_term_for_ids(self.pathIDs, self.termIDs), snl.SNLBusTermBit
489
+ get_snl_term_for_ids(self.pathIDs, self.termIDs), naja.SNLBusTermBit
489
490
  )
490
491
 
491
492
  def is_scalar(self) -> bool:
@@ -494,7 +495,7 @@ class Term:
494
495
  :rtype: bool
495
496
  """
496
497
  return isinstance(
497
- get_snl_term_for_ids(self.pathIDs, self.termIDs), snl.SNLScalarTerm
498
+ get_snl_term_for_ids(self.pathIDs, self.termIDs), naja.SNLScalarTerm
498
499
  )
499
500
 
500
501
  def is_bit(self) -> bool:
@@ -510,7 +511,7 @@ class Term:
510
511
  :rtype: int or None
511
512
  """
512
513
  if isinstance(
513
- get_snl_term_for_ids(self.pathIDs, self.termIDs), snl.SNLBusTermBit
514
+ get_snl_term_for_ids(self.pathIDs, self.termIDs), naja.SNLBusTermBit
514
515
  ):
515
516
  return get_snl_term_for_ids(self.pathIDs, self.termIDs).getBit()
516
517
  return None
@@ -520,7 +521,7 @@ class Term:
520
521
  :return: the most significant bit of the term if it is a bus.
521
522
  :rtype: int or None
522
523
  """
523
- if isinstance(get_snl_term_for_ids(self.pathIDs, self.termIDs), snl.SNLBusTerm):
524
+ if isinstance(get_snl_term_for_ids(self.pathIDs, self.termIDs), naja.SNLBusTerm):
524
525
  return get_snl_term_for_ids(self.pathIDs, self.termIDs).getMSB()
525
526
  return None
526
527
 
@@ -529,7 +530,7 @@ class Term:
529
530
  :return: the least significant bit of the term if it is a bus.
530
531
  :rtype: int or None
531
532
  """
532
- if isinstance(get_snl_term_for_ids(self.pathIDs, self.termIDs), snl.SNLBusTerm):
533
+ if isinstance(get_snl_term_for_ids(self.pathIDs, self.termIDs), naja.SNLBusTerm):
533
534
  return get_snl_term_for_ids(self.pathIDs, self.termIDs).getLSB()
534
535
  return None
535
536
 
@@ -547,17 +548,17 @@ class Term:
547
548
  """
548
549
  return get_snl_term_for_ids(self.pathIDs, self.termIDs).getName()
549
550
 
550
- def get_direction(self) -> snl.SNLTerm.Direction:
551
+ def get_direction(self) -> naja.SNLTerm.Direction:
551
552
  """
552
553
  :return: the direction of the term.
553
- :rtype: snl.SNLTerm.Direction
554
+ :rtype: naja.SNLTerm.Direction
554
555
  """
555
556
  snlterm = get_snl_term_for_ids(self.pathIDs, self.termIDs)
556
- if snlterm.getDirection() == snl.SNLTerm.Direction.Input:
557
+ if snlterm.getDirection() == naja.SNLTerm.Direction.Input:
557
558
  return Term.INPUT
558
- elif snlterm.getDirection() == snl.SNLTerm.Direction.Output:
559
+ elif snlterm.getDirection() == naja.SNLTerm.Direction.Output:
559
560
  return Term.OUTPUT
560
- elif snlterm.getDirection() == snl.SNLTerm.Direction.InOut:
561
+ elif snlterm.getDirection() == naja.SNLTerm.Direction.InOut:
561
562
  return Term.INOUT
562
563
 
563
564
  def __get_snl_bitnet(self, bit) -> Net:
@@ -572,13 +573,13 @@ class Term:
572
573
  def __get_snl_lower_bitnet(self, bit) -> Net:
573
574
  return bit.getNet()
574
575
 
575
- def __get_snl_busnet(self, snl_nets) -> snl.SNLBusNet:
576
+ def __get_snl_busnet(self, snl_nets) -> naja.SNLBusNet:
576
577
  # iterate on all elements of the list and check if
577
578
  # a full SNLBusNet can be reconstructed
578
579
  snl_bus_net = None
579
580
  for i in range(len(snl_nets)):
580
581
  snl_net = snl_nets[i]
581
- if not isinstance(snl_net, snl.SNLBusNetBit):
582
+ if not isinstance(snl_net, naja.SNLBusNetBit):
582
583
  return None
583
584
  bit_bus = snl_net.getBus()
584
585
  if bit_bus.getWidth() != len(snl_nets):
@@ -592,7 +593,7 @@ class Term:
592
593
  return snl_bus_net
593
594
 
594
595
  def __get_net(self, path, snl_term_net_accessor) -> Net:
595
- if isinstance(get_snl_term_for_ids(self.pathIDs, self.termIDs), snl.SNLBusTerm):
596
+ if isinstance(get_snl_term_for_ids(self.pathIDs, self.termIDs), naja.SNLBusTerm):
596
597
  snl_nets = []
597
598
  for bit in get_snl_term_for_ids(self.pathIDs, self.termIDs).getBits():
598
599
  snl_net = snl_term_net_accessor(bit)
@@ -649,7 +650,7 @@ class Term:
649
650
  :rtype: bool
650
651
  """
651
652
  snlterm = get_snl_term_for_ids(self.pathIDs, self.termIDs)
652
- return snlterm.getDirection() == snl.SNLTerm.Direction.Input
653
+ return snlterm.getDirection() == naja.SNLTerm.Direction.Input
653
654
 
654
655
  def is_output(self) -> bool:
655
656
  """
@@ -657,7 +658,7 @@ class Term:
657
658
  :rtype: bool
658
659
  """
659
660
  snlterm = get_snl_term_for_ids(self.pathIDs, self.termIDs)
660
- return snlterm.getDirection() == snl.SNLTerm.Direction.Output
661
+ return snlterm.getDirection() == naja.SNLTerm.Direction.Output
661
662
 
662
663
  def get_bits(self):
663
664
  """
@@ -665,7 +666,7 @@ class Term:
665
666
  If the term is scalar, it will return an iterator over itself.
666
667
  :rtype: Iterator[Term]
667
668
  """
668
- if isinstance(get_snl_term_for_ids(self.pathIDs, self.termIDs), snl.SNLBusTerm):
669
+ if isinstance(get_snl_term_for_ids(self.pathIDs, self.termIDs), naja.SNLBusTerm):
669
670
  for bit in get_snl_term_for_ids(self.pathIDs, self.termIDs).getBits():
670
671
  yield Term(self.pathIDs, bit)
671
672
  else:
@@ -677,7 +678,7 @@ class Term:
677
678
  :return: the Term bit at the given index or None if it does not exist.
678
679
  :rtype: Term or None
679
680
  """
680
- if isinstance(get_snl_term_for_ids(self.pathIDs, self.termIDs), snl.SNLBusTerm):
681
+ if isinstance(get_snl_term_for_ids(self.pathIDs, self.termIDs), naja.SNLBusTerm):
681
682
  return Term(
682
683
  self.pathIDs,
683
684
  get_snl_term_for_ids(self.pathIDs, self.termIDs).getBusTermBit(index),
@@ -721,27 +722,27 @@ class Term:
721
722
 
722
723
  def get_instance_by_path(names: list):
723
724
  assert len(names) > 0
724
- path = snl.SNLPath()
725
+ path = naja.SNLPath()
725
726
  instance = None
726
- top = snl.SNLUniverse.get().getTopDesign()
727
+ top = naja.NLUniverse.get().getTopDesign()
727
728
  design = top
728
729
  for name in names:
729
- path = snl.SNLPath(path, design.getInstance(name))
730
+ path = naja.SNLPath(path, design.getInstance(name))
730
731
  instance = design.getInstance(name)
731
732
  assert instance is not None
732
733
  design = instance.getModel()
733
734
  return Instance(path)
734
735
 
735
736
 
736
- # def refresh_path(path: snl.SNLPath):
737
+ # def refresh_path(path: naja.SNLPath):
737
738
  # pathlist = path.getPathIDs()
738
739
  # assert len(pathlist) > 0
739
- # path = snl.SNLPath()
740
+ # path = naja.SNLPath()
740
741
  # instance = None
741
- # top = snl.SNLUniverse.get().getTopDesign()
742
+ # top = naja.NLUniverse.get().getTopDesign()
742
743
  # design = top
743
744
  # for id in pathlist:
744
- # path = snl.SNLPath(path, design.getInstanceByID(id))
745
+ # path = naja.SNLPath(path, design.getInstanceByID(id))
745
746
  # instance = design.getInstanceByID(id)
746
747
  # assert instance is not None
747
748
  # design = instance.getModel()
@@ -782,11 +783,11 @@ class Instance:
782
783
  of the snl occurrence API.
783
784
  """
784
785
 
785
- def __init__(self, path=snl.SNLPath()):
786
+ def __init__(self, path=naja.SNLPath()):
786
787
  self.inst = None
787
788
  self.revisionCount = 0
788
789
  self.SNLID = [0, 0, 0, 0, 0, 0]
789
- if isinstance(path, snl.SNLPath):
790
+ if isinstance(path, naja.SNLPath):
790
791
  if path.size() > 0:
791
792
  self.pathIDs = path.getPathIDs()
792
793
  self.revisionCount = path.getTailInstance().getModel().getRevisionCount()
@@ -799,7 +800,7 @@ class Instance:
799
800
  self.inst = get_snl_instance_from_id_list(path)
800
801
  self.revisionCount = self.inst.getModel().getRevisionCount()
801
802
  if self.inst is not None:
802
- self.SNLID = self.inst.getModel().getSNLID()
803
+ self.SNLID = self.inst.getModel().getNLID()
803
804
 
804
805
  def __eq__(self, other) -> bool:
805
806
  return self.pathIDs == other.pathIDs
@@ -832,15 +833,15 @@ class Instance:
832
833
  initial_path = get_snl_path_from_id_list(self.pathIDs)
833
834
  for inst in self.__get_snl_model().getInstances():
834
835
  if inst.getModel().isLeaf():
835
- yield Instance(snl.SNLPath(initial_path, inst))
836
- path = snl.SNLPath(initial_path, inst)
836
+ yield Instance(naja.SNLPath(initial_path, inst))
837
+ path = naja.SNLPath(initial_path, inst)
837
838
  stack = [[inst, path]]
838
839
  while stack:
839
840
  current = stack.pop()
840
841
  current_inst = current[0]
841
842
  current_path = current[1]
842
843
  for inst_child in current_inst.getModel().getInstances():
843
- path_child = snl.SNLPath(current_path, inst_child)
844
+ path_child = naja.SNLPath(current_path, inst_child)
844
845
  if inst_child.getModel().isLeaf():
845
846
  yield Instance(path_child)
846
847
  stack.append([inst_child, path_child])
@@ -919,27 +920,27 @@ class Instance:
919
920
 
920
921
  def __get_snl_model(self):
921
922
  if self.is_top():
922
- return snl.SNLUniverse.get().getTopDesign()
923
+ return naja.NLUniverse.get().getTopDesign()
923
924
  if (
924
925
  self.inst.getModel().getRevisionCount() != self.revisionCount or
925
- self.inst.getModel().getSNLID() != self.SNLID
926
+ self.inst.getModel().getNLID() != self.SNLID
926
927
  ):
927
928
  self.inst = get_snl_instance_from_id_list(self.pathIDs)
928
929
  self.revisionCount = self.inst.getModel().getRevisionCount()
929
- self.SNLID = self.inst.getModel().getSNLID()
930
+ self.SNLID = self.inst.getModel().getNLID()
930
931
 
931
932
  return self.inst.getModel()
932
933
 
933
934
  def __get_leaf_snl_object(self):
934
935
  if self.is_top():
935
- return snl.SNLUniverse.get().getTopDesign()
936
+ return naja.NLUniverse.get().getTopDesign()
936
937
  return get_snl_instance_from_id_list(self.pathIDs)
937
938
 
938
- def __find_snl_model(self, name: str) -> snl.SNLDesign:
939
- u = snl.SNLUniverse.get()
939
+ def __find_snl_model(self, name: str) -> naja.SNLDesign:
940
+ u = naja.NLUniverse.get()
940
941
  for db in u.getUserDBs():
941
942
  for lib in db.getLibraries():
942
- found_model = lib.getDesign(name)
943
+ found_model = lib.getSNLDesign(name)
943
944
  if found_model is not None:
944
945
  return found_model
945
946
  return None
@@ -973,7 +974,7 @@ class Instance:
973
974
  """
974
975
  path = get_snl_path_from_id_list(self.pathIDs)
975
976
  for inst in self.__get_snl_model().getInstances():
976
- path_child = snl.SNLPath(path, inst)
977
+ path_child = naja.SNLPath(path, inst)
977
978
  yield Instance(path_child)
978
979
  # path.pop()
979
980
 
@@ -988,14 +989,14 @@ class Instance:
988
989
  # FIXME: concat first local path with the path of the instance
989
990
  # model = self.__get_snl_model()
990
991
  # for inst in model.getInstances():
991
- # path = snl.SNLPath(inst)
992
+ # path = naja.SNLPath(inst)
992
993
  # stack = [[inst, path]]
993
994
  # while stack:
994
995
  # current = stack.pop()
995
996
  # current_inst = current[0]
996
997
  # current_path = current[1]
997
998
  # for inst_child in current_inst.getModel().getInstances():
998
- # path_child = snl.SNLPath(current_path, inst_child)
999
+ # path_child = naja.SNLPath(current_path, inst_child)
999
1000
  # if inst_child.getModel().isPrimitive():
1000
1001
  # yield Instance(path_child)
1001
1002
  # stack.append([inst_child, path_child])
@@ -1016,7 +1017,7 @@ class Instance:
1016
1017
  :rtype: Iterator[Net]
1017
1018
  """
1018
1019
  for net in self.__get_snl_model().getNets():
1019
- if isinstance(net, snl.SNLBusNet):
1020
+ if isinstance(net, naja.SNLBusNet):
1020
1021
  for bit in net.getBits():
1021
1022
  yield Net(self.pathIDs, bit)
1022
1023
  else:
@@ -1077,7 +1078,7 @@ class Instance:
1077
1078
  :rtype: Iterator[Term]
1078
1079
  """
1079
1080
  for term in self.__get_snl_model().getTerms():
1080
- if term.getDirection() != snl.SNLTerm.Direction.Output:
1081
+ if term.getDirection() != naja.SNLTerm.Direction.Output:
1081
1082
  yield Term(self.pathIDs, term)
1082
1083
 
1083
1084
  def get_flat_input_terms(self):
@@ -1088,8 +1089,8 @@ class Instance:
1088
1089
  :rtype: Iterator[Term]
1089
1090
  """
1090
1091
  for term in self.__get_snl_model().getTerms():
1091
- if term.getDirection() != snl.SNLTerm.Direction.Output:
1092
- if isinstance(term, snl.SNLBusTerm):
1092
+ if term.getDirection() != naja.SNLTerm.Direction.Output:
1093
+ if isinstance(term, naja.SNLBusTerm):
1093
1094
  for bit in term.getBits():
1094
1095
  yield Term(self.pathIDs, bit)
1095
1096
  else:
@@ -1103,7 +1104,7 @@ class Instance:
1103
1104
  :rtype: Iterator[Term]
1104
1105
  """
1105
1106
  for term in self.__get_snl_model().getTerms():
1106
- if term.getDirection() != snl.SNLTerm.Direction.Input:
1107
+ if term.getDirection() != naja.SNLTerm.Direction.Input:
1107
1108
  yield Term(self.pathIDs, term)
1108
1109
 
1109
1110
  def get_flat_output_terms(self):
@@ -1114,8 +1115,8 @@ class Instance:
1114
1115
  :rtype: Iterator[Term]
1115
1116
  """
1116
1117
  for term in self.__get_snl_model().getTerms():
1117
- if term.getDirection() != snl.SNLTerm.Direction.Input:
1118
- if isinstance(term, snl.SNLBusTerm):
1118
+ if term.getDirection() != naja.SNLTerm.Direction.Input:
1119
+ if isinstance(term, naja.SNLBusTerm):
1119
1120
  for bit in term.getBits():
1120
1121
  yield Term(self.pathIDs, bit)
1121
1122
  else:
@@ -1138,8 +1139,8 @@ class Instance:
1138
1139
  "Cannot delete instance with empty name. Try delete_instance_by_id instead."
1139
1140
  )
1140
1141
  init_path = get_snl_path_from_id_list(self.pathIDs)
1141
- path = snl.SNLPath(init_path, self.__get_snl_model().getInstance(name))
1142
- snl.SNLUniquifier(path)
1142
+ path = naja.SNLPath(init_path, self.__get_snl_model().getInstance(name))
1143
+ naja.SNLUniquifier(path)
1143
1144
  if init_path.size() > 0:
1144
1145
  # Delete the last instance in uniq_path
1145
1146
  self.__get_snl_model().getInstance(name).destroy()
@@ -1150,8 +1151,8 @@ class Instance:
1150
1151
  :param str id: the ID of the Instance to delete.
1151
1152
  """
1152
1153
  init_path = get_snl_path_from_id_list(self.pathIDs)
1153
- path = snl.SNLPath(init_path, self.__get_snl_model().getInstanceByID(id))
1154
- snl.SNLUniquifier(path)
1154
+ path = naja.SNLPath(init_path, self.__get_snl_model().getInstanceByID(id))
1155
+ naja.SNLUniquifier(path)
1155
1156
  # Delete the last instance in uniq_path
1156
1157
  self.__get_snl_model().getInstanceByID(id).destroy()
1157
1158
 
@@ -1169,7 +1170,7 @@ class Instance:
1169
1170
  def delete(self):
1170
1171
  """Delete this instance."""
1171
1172
  path = get_snl_path_from_id_list(self.pathIDs)
1172
- snl.SNLUniquifier(path)
1173
+ naja.SNLUniquifier(path)
1173
1174
  self.get_design().delete_instance_by_id(path.getTailInstance().getID())
1174
1175
 
1175
1176
  def get_name(self) -> str:
@@ -1209,7 +1210,7 @@ class Instance:
1209
1210
  """
1210
1211
  path = get_snl_path_from_id_list(self.pathIDs)
1211
1212
  if path.size() > 0:
1212
- snl.SNLUniquifier(path)
1213
+ naja.SNLUniquifier(path)
1213
1214
  path = get_snl_path_from_id_list(self.pathIDs)
1214
1215
  design = self.__get_snl_model()
1215
1216
  new_instance_model = self.__find_snl_model(model)
@@ -1217,23 +1218,23 @@ class Instance:
1217
1218
  raise ValueError(
1218
1219
  f"Cannot create instance {name} in {self}: model {model} cannot be found"
1219
1220
  )
1220
- newSNLInstance = snl.SNLInstance.create(design, new_instance_model, name)
1221
- path = snl.SNLPath(path, newSNLInstance)
1221
+ newSNLInstance = naja.SNLInstance.create(design, new_instance_model, name)
1222
+ path = naja.SNLPath(path, newSNLInstance)
1222
1223
  return Instance(path)
1223
1224
 
1224
- def create_term(self, name: str, direction: snl.SNLTerm.Direction) -> Term:
1225
+ def create_term(self, name: str, direction: naja.SNLTerm.Direction) -> Term:
1225
1226
  """Create a Term in this Instance with the given name and direction.
1226
1227
 
1227
1228
  :param str name: the name of the Term to create.
1228
- :param snl.SNLTerm.Direction direction: the direction of the Term to create.
1229
+ :param naja.SNLTerm.Direction direction: the direction of the Term to create.
1229
1230
  :return: the created Term.
1230
1231
  """
1231
1232
  path = get_snl_path_from_id_list(self.pathIDs)
1232
1233
  if path.size() > 0:
1233
- snl.SNLUniquifier(path)
1234
+ naja.SNLUniquifier(path)
1234
1235
  path = get_snl_path_from_id_list(self.pathIDs)
1235
1236
  design = self.__get_snl_model()
1236
- newSNLTerm = snl.SNLScalarTerm.create(design, direction, name)
1237
+ newSNLTerm = naja.SNLScalarTerm.create(design, direction, name)
1237
1238
  return Term(path.getPathIDs(), newSNLTerm)
1238
1239
 
1239
1240
  def create_output_term(self, name: str) -> Term:
@@ -1243,7 +1244,7 @@ class Instance:
1243
1244
  :return: the created Term.
1244
1245
  :rtype: Term
1245
1246
  """
1246
- return self.create_term(name, snl.SNLTerm.Direction.Output)
1247
+ return self.create_term(name, naja.SNLTerm.Direction.Output)
1247
1248
 
1248
1249
  def create_input_term(self, name: str) -> Term:
1249
1250
  """Create an input Term in this Instance with the given name.
@@ -1252,7 +1253,7 @@ class Instance:
1252
1253
  :return: the created Term.
1253
1254
  :rtype: Term
1254
1255
  """
1255
- return self.create_term(name, snl.SNLTerm.Direction.Input)
1256
+ return self.create_term(name, naja.SNLTerm.Direction.Input)
1256
1257
 
1257
1258
  def create_inout_term(self, name: str) -> Term:
1258
1259
  """Create an inout Term in this Instance with the given name.
@@ -1261,7 +1262,7 @@ class Instance:
1261
1262
  :return: the created Term.
1262
1263
  :rtype: Term
1263
1264
  """
1264
- return self.create_term(name, snl.SNLTerm.Direction.InOut)
1265
+ return self.create_term(name, naja.SNLTerm.Direction.InOut)
1265
1266
 
1266
1267
  def create_bus_term(self, name: str, msb: int, lsb: int, direction) -> Term:
1267
1268
  """Create a bus Term in this Instance with the given name, msb, lsb and direction.
@@ -1269,14 +1270,14 @@ class Instance:
1269
1270
  :param str name: the name of the Term to create.
1270
1271
  :param int msb: the most significant bit of the Term to create.
1271
1272
  :param int lsb: the least significant bit of the Term to create.
1272
- :param snl.SNLTerm.Direction direction: the direction of the Term to create.
1273
+ :param naja.SNLTerm.Direction direction: the direction of the Term to create.
1273
1274
  :return: the created Term.
1274
1275
  """
1275
1276
  path = get_snl_path_from_id_list(self.pathIDs)
1276
1277
  if path.size() > 0:
1277
- snl.SNLUniquifier(path)
1278
+ naja.SNLUniquifier(path)
1278
1279
  design = self.__get_snl_model()
1279
- newSNLTerm = snl.SNLBusTerm.create(design, direction, msb, lsb, name)
1280
+ newSNLTerm = naja.SNLBusTerm.create(design, direction, msb, lsb, name)
1280
1281
  return Term(self.pathIDs, newSNLTerm)
1281
1282
 
1282
1283
  def create_inout_bus_term(self, name: str, msb: int, lsb: int) -> Term:
@@ -1288,7 +1289,7 @@ class Instance:
1288
1289
  :return: the created Term.
1289
1290
  :rtype: Term
1290
1291
  """
1291
- return self.create_bus_term(name, msb, lsb, snl.SNLTerm.Direction.InOut)
1292
+ return self.create_bus_term(name, msb, lsb, naja.SNLTerm.Direction.InOut)
1292
1293
 
1293
1294
  def create_output_bus_term(self, name: str, msb: int, lsb: int) -> Term:
1294
1295
  """Create an output bus Term in this Instance with the given name, msb and lsb.
@@ -1299,7 +1300,7 @@ class Instance:
1299
1300
  :return: the created Term.
1300
1301
  :rtype: Term
1301
1302
  """
1302
- return self.create_bus_term(name, msb, lsb, snl.SNLTerm.Direction.Output)
1303
+ return self.create_bus_term(name, msb, lsb, naja.SNLTerm.Direction.Output)
1303
1304
 
1304
1305
  def create_input_bus_term(self, name: str, msb: int, lsb: int) -> Term:
1305
1306
  """Create an input bus Term in this Instance with the given name, msb and lsb.
@@ -1310,7 +1311,7 @@ class Instance:
1310
1311
  :return: the created Term.
1311
1312
  :rtype: Term
1312
1313
  """
1313
- return self.create_bus_term(name, msb, lsb, snl.SNLTerm.Direction.Input)
1314
+ return self.create_bus_term(name, msb, lsb, naja.SNLTerm.Direction.Input)
1314
1315
 
1315
1316
  def create_net(self, name: str) -> Net:
1316
1317
  """Create a scalar Net in this Instance with the given name.
@@ -1321,10 +1322,10 @@ class Instance:
1321
1322
  """
1322
1323
  path = get_snl_path_from_id_list(self.pathIDs)
1323
1324
  if path.size() > 0:
1324
- snl.SNLUniquifier(path)
1325
+ naja.SNLUniquifier(path)
1325
1326
  path = get_snl_path_from_id_list(self.pathIDs)
1326
1327
  model = self.__get_snl_model()
1327
- newSNLNet = snl.SNLScalarNet.create(model, name)
1328
+ newSNLNet = naja.SNLScalarNet.create(model, name)
1328
1329
  return Net(path, newSNLNet)
1329
1330
 
1330
1331
  def create_bus_net(self, name: str, msb: int, lsb: int) -> Net:
@@ -1338,10 +1339,10 @@ class Instance:
1338
1339
  """
1339
1340
  path = get_snl_path_from_id_list(self.pathIDs)
1340
1341
  if path.size() > 0:
1341
- snl.SNLUniquifier(path)
1342
+ naja.SNLUniquifier(path)
1342
1343
  path = get_snl_path_from_id_list(self.pathIDs)
1343
1344
  model = self.__get_snl_model()
1344
- newSNLNet = snl.SNLBusNet.create(model, msb, lsb, name)
1345
+ newSNLNet = naja.SNLBusNet.create(model, msb, lsb, name)
1345
1346
  return Net(path, newSNLNet)
1346
1347
 
1347
1348
  def dump_verilog(self, path: str, name: str):
@@ -1360,13 +1361,13 @@ class Instance:
1360
1361
  return self.__get_snl_model().getTruthTable()
1361
1362
 
1362
1363
 
1363
- def get_top_db() -> snl.SNLDB:
1364
- if snl.SNLUniverse.get() is None:
1365
- snl.SNLUniverse.create()
1366
- if snl.SNLUniverse.get().getTopDB() is None:
1367
- db = snl.SNLDB.create(snl.SNLUniverse.get())
1368
- snl.SNLUniverse.get().setTopDB(db)
1369
- return snl.SNLUniverse.get().getTopDB()
1364
+ def __get_top_db() -> naja.NLDB:
1365
+ if naja.NLUniverse.get() is None:
1366
+ naja.NLUniverse.create()
1367
+ if naja.NLUniverse.get().getTopDB() is None:
1368
+ db = naja.NLDB.create(naja.NLUniverse.get())
1369
+ naja.NLUniverse.get().setTopDB(db)
1370
+ return naja.NLUniverse.get().getTopDB()
1370
1371
 
1371
1372
 
1372
1373
  def get_top():
@@ -1374,7 +1375,7 @@ def get_top():
1374
1375
  :return: the top Instance.
1375
1376
  :rtype: Instance
1376
1377
  """
1377
- return Instance(snl.SNLPath())
1378
+ return Instance(naja.SNLPath())
1378
1379
 
1379
1380
 
1380
1381
  def create_top(name: str) -> Instance:
@@ -1385,11 +1386,11 @@ def create_top(name: str) -> Instance:
1385
1386
  :rtype: Instance
1386
1387
  """
1387
1388
  # init
1388
- db = get_top_db()
1389
+ db = __get_top_db()
1389
1390
  # create top design
1390
- lib = snl.SNLLibrary.create(db)
1391
- top = snl.SNLDesign.create(lib, name)
1392
- snl.SNLUniverse.get().setTopDesign(top)
1391
+ lib = naja.NLLibrary.create(db)
1392
+ top = naja.SNLDesign.create(lib, name)
1393
+ naja.NLUniverse.get().setTopDesign(top)
1393
1394
  return Instance()
1394
1395
 
1395
1396
 
@@ -1399,11 +1400,13 @@ class VerilogConfig:
1399
1400
 
1400
1401
 
1401
1402
  def load_verilog(files: list, config: VerilogConfig = None) -> Instance:
1403
+ if not files or len(files) == 0:
1404
+ raise Exception("No verilog files provided")
1402
1405
  if config is None:
1403
1406
  config = VerilogConfig() # Use default settings
1404
1407
  start_time = time.time()
1405
1408
  logging.info(f"Loading verilog: {', '.join(files)}")
1406
- get_top_db().loadVerilog(files, keep_assigns=config.keep_assigns)
1409
+ __get_top_db().loadVerilog(files, keep_assigns=config.keep_assigns)
1407
1410
  execution_time = time.time() - start_time
1408
1411
  logging.info(f"Loading done in {execution_time:.2f} seconds")
1409
1412
  return get_top()
@@ -1411,7 +1414,7 @@ def load_verilog(files: list, config: VerilogConfig = None) -> Instance:
1411
1414
 
1412
1415
  def load_liberty(files: list):
1413
1416
  logging.info(f"Loading liberty files: {', '.join(files)}")
1414
- get_top_db().loadLibertyPrimitives(files)
1417
+ __get_top_db().loadLibertyPrimitives(files)
1415
1418
 
1416
1419
 
1417
1420
  def load_primitives(name: str):
@@ -1422,18 +1425,39 @@ def load_primitives(name: str):
1422
1425
  - xilinx
1423
1426
  """
1424
1427
  if name == "xilinx":
1425
- logging.info("Loading xilinx primitives")
1426
1428
  from najaeda.primitives import xilinx
1427
1429
 
1428
- xilinx.load(get_top_db())
1430
+ xilinx.load(__get_top_db())
1429
1431
  else:
1430
1432
  raise ValueError(f"Unknown primitives library: {name}")
1431
1433
 
1432
1434
 
1433
- def get_primitives_library() -> snl.SNLLibrary:
1434
- lib = get_top_db().getLibrary("PRIMS")
1435
+ def load_primitives_from_file(file: str):
1436
+ """Loads a primitives library from a file.
1437
+
1438
+ :param str file: the path to the primitives library file.
1439
+ The file must define a function `load(db)`.
1440
+ """
1441
+ logging.info(f"Loading primitives from file: {file}")
1442
+ if not os.path.isfile(file):
1443
+ raise FileNotFoundError(f"Cannot load primitives from non existing file: {file}")
1444
+ import importlib.util
1445
+ spec = importlib.util.spec_from_file_location("user_module", file)
1446
+ module = importlib.util.module_from_spec(spec)
1447
+ sys.modules["user_module"] = module
1448
+ spec.loader.exec_module(module)
1449
+
1450
+ if not hasattr(module, "load"):
1451
+ raise RuntimeError(f"The file {file} must define a function named `load(db)`")
1452
+
1453
+ db = __get_top_db()
1454
+ module.load(db)
1455
+
1456
+
1457
+ def get_primitives_library() -> naja.NLLibrary:
1458
+ lib = __get_top_db().getLibrary("PRIMS")
1435
1459
  if lib is None:
1436
- lib = snl.SNLLibrary.createPrimitives(get_top_db(), "PRIMS")
1460
+ lib = naja.NLLibrary.createPrimitives(__get_top_db(), "PRIMS")
1437
1461
  return lib
1438
1462
 
1439
1463
 
@@ -1443,13 +1467,13 @@ def get_model_name(id: tuple[int, int, int]) -> str:
1443
1467
  :return: the name of the model given its id or None if it does not exist.
1444
1468
  :rtype: str or None
1445
1469
  """
1446
- u = snl.SNLUniverse.get()
1470
+ u = naja.NLUniverse.get()
1447
1471
  if u:
1448
1472
  db = u.getDB(id[0])
1449
1473
  if db:
1450
1474
  lib = db.getLibrary(id[1])
1451
1475
  if lib:
1452
- model = lib.getDesign(id[2])
1476
+ model = lib.getSNLDesign(id[2])
1453
1477
  if model:
1454
1478
  return model.getName()
1455
1479
  return None