示例#1
0
    def listComponents(self):
        """Returns the list of the current available architectural components"""

        # ok: the components should have already been imported in the current python
        # session: I simply have to get the path of all the imported modules : if it contains
        # the __build__/default/component string, then this is a component and I can list it
        # Note actually that the module containing the component is listed, not the class
        # defining the component itself
        ####symbolNamespace = [self.archc]
        symbolNamespace = []
        symbolNamespace += self.components
        foundComponents = []
        for module in self.components:
            if '__file__' in dir(module) and '__name__' in dir(module):
                if module.__file__.find(os.path.split(blddir)[1] + os.sep + 'default' + os.sep + 'component') != -1:
                    for classes in dir(module):
                        realComp = getattr(module, classes, module)
                        try:
                            #It is a component usefull to the user if it a subclass of sc_module
                            #and if it can be instantiated
                            helper.getBase('sc_module', realComp)
                            if realComp.__init__.__doc__ == 'Raises an exception\nThis class cannot be instantiated from Python\n':
                                continue
                        except:
                            continue
                        comp = component.Component()
                        comp.module = module
                        comp.classs = realComp
                        try:
                            comp.constructor = helper.extractConstrSig(realComp.__init__)
                        except:
                            import traceback
                            traceback.print_exc()
                            continue
                        helper.findConnectionsRecv(comp, realComp, [], scwrapper, symbolNamespace)
                        foundComponents.append(comp)
        return foundComponents
示例#2
0
    def connectPortsByPathName(self, source, sourcePortName, target, targetPortName, sourcePortId = None, targetPortId = None):
        """Connects the source component with a target one; the path of the initiator port (in the source component) and target port
        (in the target component) are specified. Note that a check is performed to be sure that the type of the source and target port match.
        It is also possible to specify the Ids of the ports: if they are different from None it means that sourcePortName and 
        targetPortName are the names for arrays of ports and the port id refers to the array index of the desired port
        """
        #check if source and target are SystemC components
        if not helper.isSystemCComponent(source):
            exceptions.Exception(str(source) + ' is not a SystemC component')        
        if not helper.isSystemCComponent(target):
            exceptions.Exception(str(target) + ' is not a SystemC component')        

        #check if the source components contains the port with the specified name
        try:
            sourcePort = helper.getAttrInstance(source, sourcePortName)
        except Exception:
            raise exceptions.Exception('There is no port with name ' + sourcePortName + ' in the source component')
        #use the port id in case the port is contained in a vector
        if sourcePortId is not None and hasattr(sourcePort,'__getitem__'):
            if type(sourcePortId) is int:
                sourcePort = sourcePort[sourcePortId]
            else:
                raise exceptions.Exception('The source port ID must be an integer')

        #check if the target component contains the port with the specified name
        try:
            targetPort = helper.getAttrInstance(target, targetPortName)
        except Exception:
            raise exceptions.Exception('There is no port with name ' + targetPortName + ' in the target component')
        #use the port id in case the port is contained in a vector
        if targetPortId is not None and hasattr(targetPort,'__getitem__'):
            if type(targetPortId) is int:
                targetPort = targetPort[targetPortId]
            else:
                raise exceptions.Exception('The target port ID must be an integer')

        # Now I have to check that the ports are compatible, so that they carry the same
        # type of information; in order to do this I move down on the inheritance chain
        # of each of the two ports, until the name of the class starts with
        # tlm_initiator_port or tlm_target_port; then I can check the types and
        # connect them
        try:
            sourcePortTypeName = helper.getBase('tlm_base_initiator_socket_b', sourcePort.__class__)
        except Exception, e:
            raise exceptions.Exception('ports ' + sourcePortName + ' and ' + targetPortName + ' cannot be connected because' +
                  'of the following error ' + str(e))
示例#3
0
    def connectPorts(self, source, sourcePort, target, targetPort):
        """Connect two ports given their instances
        """
        #check if source and target are SystemC components
        if not helper.isSystemCComponent(source):
            exceptions.Exception(str(source) + ' is not a SystemC component')        
        if not helper.isSystemCComponent(target):
            exceptions.Exception(str(target) + ' is not a SystemC component')        
      
        #check if they are already connected
        if self.areConnected(source, sourcePort, target, targetPort):
            print '\nThe two ports are already connected!\n'
            return

        #check for name method        
        if not hasattr(target,'name'):
            raise exceptions.Exception('Component ' + str(target) + ' doesn\'t have the method name; probably it is not an sc_module')

        if not hasattr(source,'name'):
            raise exceptions.Exception('Component ' + str(source) + ' doesn\'t have the method name; probably it is not an sc_module')

        if not hasattr(targetPort,'name'):
            raise exceptions.Exception('Port ' + str(targetPort) + ' doesn\'t have the method name; probably it is not an valid port object')

        if not hasattr(sourcePort,'name'):
            raise exceptions.Exception('Port ' + str(sourcePort) + ' doesn\'t have the method name; probably it is not an valid port object')

        #get sc_name (actually the only unique identifier for sc_objects)
        sourceName = source.name()
        targetName = target.name()
        sourcePortName = sourcePort.name()
        targetPortName = targetPort.name() #super(scwrapper.sc_module, targetPort).name()

        # check of the port types
        try:
            sourcePortTypeName = helper.getBase('tlm_base_initiator_socket_b', sourcePort.__class__)
        except Exception, e:
            raise exceptions.Exception('ports ' + sourcePortName + ' and ' + targetPortName + ' cannot be connected because' +
                  'of the following error ' + str(e))
示例#4
0
    def connectSyscSignal(self, source, sourceSignal, target,
                           targetPort, sourceParams = None, targParams = None):
        """Connects together a signal with a systemc port; sourceParams[0] and targParams[0] are the
        names of the components we want to connect; target and source ports may either
        be the name of the port or the instance of it. Also the source and target
        components may either be strings (the names of the components) or the
        instances of those components
        sourceParams and targParams represent the parameters which must be passed to
        the constructor of the source and target components in case they have to
        be built (so in case source and target are string)"""
        print "DEPRECATED: method not mantained"
        # first of all I check to see if source and target are strings and in
        # case I create the instance of the corresponding component
        if type(source) == types.StringType:
            source = helper.instantiateComponent(source, sourceParams, self.components)
            if type(source) == types.StringType:
                raise exceptions.Exception('Error, there is no class with the name ' + source + ' to be used as source component')
        if type(target) == types.StringType:
            target = helper.instantiateComponent(target, targParams, self.components)
            if type(target) == types.StringType:
                raise exceptions.Exception('Error, there is no class with the name ' + target + ' to be used as target component')

        # ok, now I can check if the components contain the port with the
        # specified name (in case the name is specified). In case we already have
        # the instance, nothing is done
        if type(sourceSignal) == types.StringType:
            try:
                sourceSignal = getattr(source, sourceSignal)
            except Exception:
                raise exceptions.Exception('There is no signal with name ' + sourceSignal + ' in the source component')

        if type(targetPort) == types.StringType:
            try:
                targetPort = getattr(target, targetPort)
            except Exception:
                raise exceptions.Exception('There is no port with name ' + targetPort + ' in the target component')

        if not 'name' in dir(target):
            raise exceptions.Exception('Component ' + str(target) + ' doesn\'t have the method name; probably it is not an sc_module')

        if not 'name' in dir(source):
            raise exceptions.Exception('Component ' + str(source) + ' doesn\'t have the method name; probably it is not an sc_module')

        sourceName = source.name()
        targetName = target.name()

        # Now I can connect the ports; first of all I allocate a new element
        # which keeps track of this connection
        # ok, I simply have to allocate a new element in the compToConnection; note
        # that if an element already exists in this map I don't have to allocate a
        # new one, but I have to add a connection to the node
        if self.compToConnection.has_key(sourceName):
            sourceNode = self.compToConnection[sourceName]
        else:
            sourceNode = ConnectionNode(source, sourceName)
            self.compToConnection[sourceName] = sourceNode
        if self.compToConnection.has_key(targetName):
            targetNode = self.compToConnection[targetName]
        else:
            targetNode = ConnectionNode(target, targetName)
            self.compToConnection[targetName] = targetNode

        if not 'bind' in dir(targetPort):
            raise exceptions.Exception('Component ' + targetName + ' doesn\'t have the method bind among the ones of the port ' + str(targetPort))

        # now I create the signal, connect the components with it and finally
        # add the connection node; note that the signal depends on the type of
        # the ports we are trying to connect: so, first of all I have to
        # deterimine it
        try:
            sourceSignalTypeName = helper.getBase('sc_signal', sourceSignal.__class__)
        except Exception, e:
            raise exceptions.Exception(str(sourceSignal) + ' and ' + str(targetPort) + ' cannot be connected because' +
                  'of the following error ' + str(e))
示例#5
0
            raise exceptions.Exception('Port ' + str(sourcePort) + ' doesn\'t have the method name; probably it is not an valid port object')

        #get sc_name (actually the only unique identifier for sc_objects)
        sourceName = source.name()
        targetName = target.name()
        sourcePortName = sourcePort.name()
        targetPortName = targetPort.name() #super(scwrapper.sc_module, targetPort).name()

        # check of the port types
        try:
            sourcePortTypeName = helper.getBase('tlm_base_initiator_socket_b', sourcePort.__class__)
        except Exception, e:
            raise exceptions.Exception('ports ' + sourcePortName + ' and ' + targetPortName + ' cannot be connected because' +
                  'of the following error ' + str(e))
        try:
            targetPortTypeName = helper.getBase('tlm_base_target_socket_b', targetPort.__class__)
        except Exception, e:
            raise exceptions.Exception('ports ' + sourcePortName + ' and ' + targetPortName + ' cannot be connected because' +
                  'of the following error ' + str(e))

        #check if the component actually contains the port
        if helper.getAllChildScObjects(source).count(sourcePortName) == 0:
            raise exceptions.Exception('Component ' + sourceName + ' doesn\'t contain port ' + sourcePortName)
        if helper.getAllChildScObjects(target).count(targetPortName) == 0:
            raise exceptions.Exception('Component ' + targetName + ' doesn\'t contain port ' + targetPortName)

        if not 'bind' in dir(sourcePort):
            raise exceptions.Exception('Component ' + sourceName + ' doesn\'t have the method bind among the ones of the port ' + str(sourcePort))

        #connect the ports
        sourcePort.bind(targetPort)
示例#6
0
			else:
				entry[0] = scanForProblems(entry[0])
				string = "insert into tracker.Chars values (\""+str(entry[0])+"\","+entry[1]+","+entry[2]+","+entry[3]+","+entry[4]+","+entry[5]+")"

			cursor.execute(string)
			conn.commit()
			if i % 20 == 0:
				print("Entering entry " + str(i) + " of " + str(len(entries)))
			i = i + 1
		except:
			print("error with " + string)
	print("Done entering... Hold on a moment")

"""	Deletes data in the file """
def eraseFiles(first, second):
	clickLocData = open(base + first,"w")
	clickTimeData = open(base + second, "w")
	clickLocData.write("")
	clickTimeData.write("")



""" Main Method """
windows = helper.getWindows()
global base
base = helper.getBase(windows)

conn = helper.initServer(windows)
refreshClickDatabase()
refreshTypeDatabase()