def run(Pattern, Tokens): Ptr = importlib.__import__(Pattern) indtok = 0 Limittok = len(Tokens) Limitpat = len(PATTERNS) while indtok < Limittok: indpat = 0 while (indpat < Limitpat): Pat, Action, Mode, Verbose = PATTERNS[indpat] Tok0 = Tokens[indtok] try: Tok1 = Tokens[indtok + 1] except: Tok1 = ('eof', 'eof', 0, 0) Len, Vars = matches(indtok, Tokens, Pat, 0, Verbose) if Verbose: logs.log_info('final out %s %s %s' % (Len, Vars, Tokens[indtok])) indpat += 1 if Len > 0: indpat = Limitpat + 10 Action(Vars, Mode, indtok) indtok += Len if (indpat == Limitpat): indtok += 1
def ram(Obj): Clk = Obj.Conns['clk'] Edge,ColClk = Obj.db.Nets[Clk].posedge() Res = [],[] if Edge: if 'QQ' in Obj.Context: Res = [('q',Obj.Context.pop('QQ'),ColClk.copy())],[] cs,Colscs = Obj.vals('cs') if cs=='1': add,Colsa = Obj.vals('a') A = logs.intx(add) we,Colswe = Obj.vals('we') if we=='1': din,Colsd = Obj.vals('d') D = logs.intx(din) Obj.Context[A]=D logs.log_info('ram cswr ad=%d data=%d '%(A,D)) elif we=='0': if A in Obj.Context: QQ = bin(Obj.Context[A])[2:] else: QQ = 'x' logs.log_info('ram csrd ad=%d data=%s %s'%(A,QQ,Obj.Context)) Obj.Context['QQ']=QQ return Res
def runOne(self): self.keepClocks() while self.Queues[0] != []: Onet = self.Queues[0].pop(0) for Obj, Pin in Onet.Ins: Obj.setPin(Pin, Onet.Value, Onet.Colors, False) while self.Queues[1] != []: Onet = self.Queues[1].pop(0) Onet.setVal(Onet.Next, Onet.Colors, False) Drv, Pin = Onet.Outs[0] for Obj, Pin in Onet.Ins: Obj.setPin(Pin, Onet.Value, Onet.Colors, False) while self.Queues[0] != []: Onet = self.Queues[0].pop(0) for Obj, Pin in Onet.Ins: Obj.setPin(Pin, Onet.Value, Onet.Colors, True) if self.times == []: return self.Simtime = self.times.pop(0) logs.forcedCycles = self.Simtime if (self.Simtime >= self.LastTime) and (self.LastTime > 0): logs.log_info('lasttime reached. exiting') self.RUN = False return List = self.timeWheel.pop(self.Simtime) for Onet, Val, Colors in List: Onet.setVal(Val, Colors, True)
def uart(Obj): if 'cycles' not in Obj.Context: Obj.Context['cycles'] = 0 Obj.Context['state'] = 'idle' Clk = Obj.vals('clk') if Clk[0] == '1': return [], [] Obj.Context['cycles'] += 1 db = Obj.db if Obj.Context['cycles'] == 30: db.setNet('write_tx', 0, '1') db.setNet('txdata', 0, '11001100') if Obj.Context['cycles'] == 31: db.setNet('write_tx', 0, '0') if Obj.Context['cycles'] == 800: db.setNet('write_tx', 0, '1') db.setNet('txdata', 0, '10101010') if Obj.Context['cycles'] == 801: db.setNet('write_tx', 0, '0') txd = db.Nets['txd'].Value db.setNet('rxd', 0, txd) rx_valid = db.Nets['rx_valid'].Value db.setNet('read_rx', 0, rx_valid) if rx_valid == '1': rxdata = db.Nets['rxdata'].Value logs.log_info('rxdata=%s clk=%s' % (rxdata, Clk[1]['clk'])) return [], []
def main(): Fname = sys.argv[1] db.readme(Fname) logs.log_info('insts %d nets %d' % (len(db.Nets.keys()), len(db.Insts.keys()))) if db.script: AA = db.script.split('/') if len(AA) > 1: Path = '/'.join(AA[:-1]) sys.path.append(Path) else: sys.path.append('.') MM = AA[-1] MM = MM.replace('.py', '') exec('import %s' % MM) exec('db.Script = %s' % MM) while db.RUN: db.run() db.report()
def matches(ind, Tokens, Pat, Level=0, Verbose=False): if (ind + len(Pat)) >= logs.getVar('tokens'): return 0, [] if Verbose and (Level > 0): logs.log_info('%d enter %s %s %s %s' % (Level, Pat, ind, Tokens[ind], Tokens[ind + 1])) Tok, Kind, Lnum, Cnum = Tokens[ind] PP = Pat[0] if PP in SETS: Set = SETS[PP] for P0 in Set: if (P0 == Tok): if len(Pat) == 1: return 1, [Tokens[ind]] LL, VV = matches(ind + 1, Tokens, Pat[1:], Level + 1, Verbose) if LL > 0: return LL + 1, [Tokens[ind]] + VV else: return 0, [] if (PP == Tok): if len(Pat) == 1: return 1, [] LL, VV = matches(ind + 1, Tokens, Pat[1:], Level + 1, Verbose) if LL > 0: return LL + 1, VV else: return 0, [] elif ((PP[0] == '?') and (PP[1:] == Kind)) or (PP == '?'): if len(Pat) == 1: return 1, [Tokens[ind]] LL, VV = matches(ind + 1, Tokens, Pat[1:], Level + 1, Verbose) if LL > 0: return LL + 1, [Tokens[ind]] + VV else: return 0, [] if PP == '*': Next = Pat[1] LL = 0 org = ind while True: while (ind < logs.getVar('tokens')) and (Tokens[ind][0] != Next): ind += 1 LL += 1 if ind == logs.getVar('tokens'): return 0, [] if len(Pat) == 2: return LL, [] LL, VV = matches(ind + 1, Tokens, Pat[2:], Level + 1, Verbose) if LL > 0: return LL + 1, [Tokens[org:ind]] + VV else: ind += 1 if PP in DOUBLES: Bef, Aft = DOUBLES[PP] if Tokens[ind][0] == 'eol': ind += 1 if Tokens[ind][0] != Bef: if Verbose: logs.log_info('() failed on %s' % Bef) return 0, [] Closing = findBalancedClosing(ind, Tokens, Bef, Aft) if Closing < 0: if Verbose: logs.log_info('doubles failed on closing') return 0, [] # print('>>closingDBL>>>',Closing,Tokens[Closing]) if len(Pat) == 1: return Closing - ind, [Tokens[ind:Closing]] LL, VV = matches(Closing, Tokens, Pat[1:], Level + 1, Verbose) if LL == 0: if Verbose: logs.log_info( 'double failed on postmatch tokens=%s %s pattern=%s' % (Tokens[Closing], Tokens[Closing + 1], Pat[1:])) return 0, [] return LL + Closing - ind, [Tokens[ind:Closing]] + VV if PP in ['()', '[]']: if PP == '()': Bef, Aft = '(', ')' if PP == '[]': Bef, Aft = '[', ']' if Tokens[ind][0] == 'eol': ind += 1 if Tokens[ind][0] != Bef: if Verbose: print('() failed on %s' % Bef) return 0, [] Closing = findBalancedClosing(ind, Tokens, Bef, Aft) if Closing < 0: if Verbose: print('() failed on closing') return 0, [] # print('>>closing()()>>>',Closing,Tokens[Closing]) if len(Pat) == 1: return Closing - ind, [Tokens[ind:Closing]] LL, VV = matches(Closing, Tokens, Pat[1:], Level + 1, Verbose) if LL == 0: if Verbose: logs.log_info( 'lvl=%d ()[] failed on postmatch tokens=%s %s patern=%s' % (Level, Tokens[Closing], Tokens[Closing + 1], Pat[1:])) return 0, [] return LL + Closing - ind, [Tokens[ind:Closing]] + VV if (Level > 0) and (Tokens[ind][0] == 'eol'): return matches(ind + 1, Tokens, Pat, Level, Verbose) return 0, []