Ejemplo n.º 1
0
 def setNet(self, Net, Time, Val, Colors=False):
     if Time not in self.times:
         self.times.append(Time)
         self.times.sort()
         self.timeWheel[Time] = []
     if Net not in self.Nets:
         logs.log_error('net %s is not defined for setNet' % Net)
         return
     Onet = self.Nets[Net]
     self.timeWheel[Time].append((Onet, Val, Colors))
Ejemplo n.º 2
0
def parseBus(Txt):
    if '[' not in Txt:
        return Txt, 1
    Bus = Txt[:Txt.index('[')]
    WW = Txt[Txt.index('[') + 1:-1]
    if ':':
        ww2 = list(map(int, WW.split(':')))
        Wid = ww2[0] - ww2[1] + 1
        return Bus, Wid
    logs.log_error('expects bus[hi:lo]')
    return Bus, 1
Ejemplo n.º 3
0
def findOutDir(Type,Pin): 
    if Pin[0] in ['o','q','z']: return 'output'
    if Pin[0] in ['a','b','c','i','s','w']: return 'input'
    logs.log_error('findOutDir %s %s'%(Type,Pin))
    return 'input'
Ejemplo n.º 4
0
def log_error(Txt):
    logs.log_error(Txt)
    db.vcdWrite('errors', bin(logs.Errors)[2:])
Ejemplo n.º 5
0
def checkVal(Obj, Val):
    if type(Val) is int:
        logs.log_error('checkVal %s %s' % (Val, Obj.Name))
    else:
        logs.log_correct('checkVal %s %s' % (Val, Obj.Name))
Ejemplo n.º 6
0
    def readme(self, Fname):
        File = open(Fname)

        while 1:
            line = File.readline()
            if line == '': return
            if '//' in line:
                line = line[:line.index('//')]
            line = line.replace(';', '')
            wrds = line.split()
            if len(wrds) == 0:
                pass
            elif wrds[0] == 'include':
                self.readme(wrds[1])
            elif wrds[0] == 'conn':
                Inst = wrds[1]
                Obj = self.Insts[Inst]
                Conns = wrds[2:]
                if Conns[-1] == ';': Conns.pop(-1)
                Obj.addConns(Conns)
            elif wrds[0] == 'net':
                Net = wrds[1]
                if '|' in wrds:
                    wrds = wrds[wrds.index('|') + 1:]
                    for Prm in wrds:
                        ww = Prm.split('=')
                        if (len(ww) == 2) and (ww[0] == 'width'):
                            Wid = int(ww[1])
                            if Net not in self.Nets:
                                netClass(self, Net, Wid)
                            else:
                                self.Nets[Net].Width = Wid
                        elif (len(ww) == 2):
                            if Net not in self.Nets:
                                netClass(self, Net, 1)
                            self.Nets[Net].Colors[ww[0]] = ww[1]
                        elif (Prm != ';'):
                            logs.log_error('bad param for net %s -- %s' %
                                           (Net, Prm))
                else:
                    logs.log_error('bad net line %s' % (wrds.join(' ')))

            elif wrds[0] == 'inst':
                Type = wrds[1]
                Inst = wrds[2]
                LL = wrds[3:]
                Conns = []
                Params = {}
                Wids = []
                while (LL != []) and (LL[0] not in ['|', ';']):
                    Conn = LL.pop(0)
                    if '<' in Conn:
                        ww = Conn.split('<')
                        Bus, Wid = parseBus(ww[1])
                        Conns.append(('input', ww[0], Bus))
                        Wids.append((Bus, Wid))
                    elif '>' in Conn:
                        ww = Conn.split('>')
                        Bus, Wid = parseBus(ww[1])
                        Conns.append(('output', ww[0], Bus))
                        Wids.append((Bus, Wid))
                    else:
                        ww = Conn.split('=')
                        Bus, Wid = parseBus(ww[1])
                        Conns.append((ww[0], Bus))
                        Wids.append((Bus, Wid))

                if (LL != []) and (LL[0] == '|'):
                    LL.pop(0)
                    while (LL != []) and (LL[0] != ';'):
                        Prm = LL.pop(0)
                        ww = Prm.split('=')
                        Params[ww[0]] = ww[1]
                instanceClass(self, Type, Inst, Conns, Params)
                for Bus, Wid in Wids:
                    self.Nets[Bus].Width = max(Wid, self.Nets[Bus].Width)

            elif wrds[0] == 'color':
                Net = wrds[1]
                Params = parseParam(wrds[2:])
                if Net not in self.Nets:
                    netClass(self, Net, 1)
                db.Nets[Net].Colors = Params
            elif wrds[0] == 'force':
                Net = wrds[1]
                if Net not in self.Nets:
                    netClass(self, Net, 1)

                self.setNet(Net, 0, wrds[2], self.Nets[Net].Colors)
                if len(wrds) > 3:
                    LL = wrds[3:]
                    if LL[-1] == ';': LL.pop(-1)
                    while LL != []:
                        Time = int(LL.pop(0))
                        Val = LL.pop(0)
                        self.setNet(Net, Time, Val, self.Nets[Net].Colors)
            elif wrds[0] == 'clock':
                Clk = wrds[1]
                if Clk not in self.Nets:
                    netClass(self, Clk, 1)
                self.Clocks[Clk] = (0, int(wrds[2]), int(wrds[3]))
            elif wrds[0] == 'script':
                self.script = wrds[1]
            elif wrds[0] == 'vcd':
                db.Fvcd = open(wrds[1], 'w')
                start_vcd(db)
            elif wrds[0] == 'run':
                if not db.Fvcd:
                    db.Fvcd = open('a.vcd', 'w')
                if len(wrds) > 1:
                    db.LastTime = int(wrds[1])
                return
            else:
                logs.log_error('unrecognized %s command' % wrds[0])