예제 #1
0
    def readgatewithoutput(self, output_pin):

        """
        Reads from the VerilogSQL file the data from the gates table the
        gate that has inputoutput pin that is given by the passed
        output_pin.

        output_pin: output pin desired.

        Returns a GateDB.db object of the gate element which adheres to the
        criterion.
        """

        returngatedb = GateDB()

        s_circuit = self.circuit
        s_outputpin = output_pin

        # SQL code to find gate that has the given output pin in a given.
        #
        # select *
        # from gates
        # where circuit = 'c17'
        # and output_pin = 'N11'
        # ;

        SQL_text = text(
                        "SELECT * "
                        "FROM gates "
                        "WHERE circuit = :textcircuit "
                        "AND output_pin = :textoutputpin "
                        ";"
                        )

        if self.loaded is True:
            SQL_text = SQL_text.bindparams(textcircuit=s_circuit,
                                           textoutputpin=s_outputpin
                                           )
            query = self.conn.execute(SQL_text)

        else:
            raise IOError("SQL file not opened before executing \
                          readgateswithoutputs")

        # Only one line from SQL query should have returned.
        for line in query:
            result = line

        # Remove parantheses and single quotes from results
        if not result:
            raise ValueError("findgatewithouputs did not return gate.")
        else:
            result = self.parse_SQL_query(result)

        # result[0] is ID
        # result[1] is circuit
        gate = result[2]
        output_pin = result[3]
        input_pins = set([pin for pin in result[4:] if pin != 'None'])

        returngatedb.add(gate, output_pin, input_pins)

        return returngatedb
예제 #2
0
    def readgateswithinputs(self, input_pins, req_input_pins):
        """
        Reads from the VerilogSQL file the data from the gates table the
        gates that have input pins that are all in the input_pins passed to
        the method, and which must have input pins in the req_input_pins
        list.

        input_pins: set of input pins
        req_input_pins: set of input pins which must be inputs to gate.

        Returns a GateDB.db object of gate elements which adhere to the
        criterion.
        """

        returngatedb = GateDB()

        s_circuit = self.circuit

        if len(input_pins) > 10 or len(req_input_pins) > 10:
            raise ValueError("readgateswithinputs received more than 10 " +
                             "input or required input pins.")
        elif any(input_pins & req_input_pins):
            raise ValueError("readgateswithinputs received pins that were " +
                             "in both input_pins and req_input_pins: " +
                             str(input_pins & req_input_pins))
        else:
            s_textinputpins = (list(input_pins) +
                               ['none']*(10-len(input_pins)))
            s_textreqinputpins = (list(req_input_pins) +
                                  ['none']*(10-len(req_input_pins)))

        # SQL code to find gates that have all its input pins in a given
        # set of pins. Assume we have values for N1, N2, N11 and we have new
        # values for N3 and N4 which must be in the gates we find.
        #
        # select gate, ouput_pin, input_pin0, input_pin1, input_pin2,
        #         input_pin3, input_pin4, input_pin5, input_pin6,
        #         input_pin7, input_pin8, input_pin9
        # from gates
        # where circuit = 'c17'
        # and (input_pin0 in ('N1', 'N2', 'N11', 'N3', 'N4')
        #                             or input_pin0 is null)
        # and (input_pin1 in ('N1', 'N2', 'N11', 'N3', 'N4')
        #                             or input_pin1 is null)
        # and ('N3' in (input_pin0, input_pin1)
        # or 'N4' in (input_pin0, input_pin1))
        # ;

        # SQLAlchemy does not seem to be able to bind multiple items per param?

        SQL_text = text(
                   "SELECT gate, output_pin, input_pin0, input_pin1, "
                   "input_pin2, input_pin3, input_pin4, input_pin5, "
                   "input_pin6, input_pin7, input_pin8, input_pin9 "
                   "FROM gates "
                   "WHERE circuit = :textcircuit "
                   "AND (input_pin0 IN (:t0, :t1, :t2, :t3, :t4, :t5, :t6, \
                         :t7, :t8, :t9, :rt0, :rt1, :rt2, :rt3, :rt4, :rt5, \
                         :rt6, :rt7, :rt8, :rt9) OR input_pin0 IS null) "
                   "AND (input_pin1 IN (:t0, :t1, :t2, :t3, :t4, :t5, :t6, \
                         :t7, :t8, :t9, :rt0, :rt1, :rt2, :rt3, :rt4, :rt5, \
                         :rt6, :rt7, :rt8, :rt9) OR input_pin1 IS null) "
                   "AND (input_pin2 IN (:t0, :t1, :t2, :t3, :t4, :t5, :t6, \
                         :t7, :t8, :t9, :rt0, :rt1, :rt2, :rt3, :rt4, :rt5, \
                         :rt6, :rt7, :rt8, :rt9) OR input_pin2 IS null) "
                   "AND (input_pin3 IN (:t0, :t1, :t2, :t3, :t4, :t5, :t6, \
                         :t7, :t8, :t9, :rt0, :rt1, :rt2, :rt3, :rt4, :rt5, \
                         :rt6, :rt7, :rt8, :rt9) OR input_pin3 IS null) "
                   "AND (input_pin4 IN (:t0, :t1, :t2, :t3, :t4, :t5, :t6, \
                         :t7, :t8, :t9, :rt0, :rt1, :rt2, :rt3, :rt4, :rt5, \
                         :rt6, :rt7, :rt8, :rt9) OR input_pin4 IS null) "
                   "AND (input_pin5 IN (:t0, :t1, :t2, :t3, :t4, :t5, :t6, \
                         :t7, :t8, :t9, :rt0, :rt1, :rt2, :rt3, :rt4, :rt5, \
                         :rt6, :rt7, :rt8, :rt9) OR input_pin5 IS null) "
                   "AND (input_pin6 IN (:t0, :t1, :t2, :t3, :t4, :t5, :t6, \
                         :t7, :t8, :t9, :rt0, :rt1, :rt2, :rt3, :rt4, :rt5, \
                         :rt6, :rt7, :rt8, :rt9) OR input_pin6 IS null) "
                   "AND (input_pin7 IN (:t0, :t1, :t2, :t3, :t4, :t5, :t6, \
                         :t7, :t8, :t9, :rt0, :rt1, :rt2, :rt3, :rt4, :rt5, \
                         :rt6, :rt7, :rt8, :rt9) OR input_pin7 IS null) "
                   "AND (input_pin8 IN (:t0, :t1, :t2, :t3, :t4, :t5, :t6, \
                         :t7, :t8, :t9, :rt0, :rt1, :rt2, :rt3, :rt4, :rt5, \
                         :rt6, :rt7, :rt8, :rt9) OR input_pin8 IS null) "
                   "AND (input_pin9 IN (:t0, :t1, :t2, :t3, :t4, :t5, :t6, \
                         :t7, :t8, :t9, :rt0, :rt1, :rt2, :rt3, :rt4, :rt5, \
                         :rt6, :rt7, :rt8, :rt9) OR input_pin9 IS null) "
                   "AND (:rt0 IN (input_pin0, input_pin1, input_pin2, \
                        input_pin3, input_pin4, input_pin5, input_pin6, \
                        input_pin7, input_pin8, input_pin9) "
                   "OR :rt1 IN (input_pin0, input_pin1, input_pin2, \
                        input_pin3, input_pin4, input_pin5, input_pin6, \
                        input_pin7, input_pin8, input_pin9) "
                   "OR :rt2 IN (input_pin0, input_pin1, input_pin2, \
                        input_pin3, input_pin4, input_pin5, input_pin6, \
                        input_pin7, input_pin8, input_pin9) "
                   "OR :rt3 IN (input_pin0, input_pin1, input_pin2, \
                        input_pin3, input_pin4, input_pin5, input_pin6, \
                        input_pin7, input_pin8, input_pin9) "
                   "OR :rt4 IN (input_pin0, input_pin1, input_pin2, \
                        input_pin3, input_pin4, input_pin5, input_pin6, \
                        input_pin7, input_pin8, input_pin9) "
                   "OR :rt5 IN (input_pin0, input_pin1, input_pin2, \
                        input_pin3, input_pin4, input_pin5, input_pin6, \
                        input_pin7, input_pin8, input_pin9) "
                   "OR :rt6 IN (input_pin0, input_pin1, input_pin2, \
                        input_pin3, input_pin4, input_pin5, input_pin6, \
                        input_pin7, input_pin8, input_pin9) "
                   "OR :rt7 IN (input_pin0, input_pin1, input_pin2, \
                        input_pin3, input_pin4, input_pin5, input_pin6, \
                        input_pin7, input_pin8, input_pin9) "
                   "OR :rt8 IN (input_pin0, input_pin1, input_pin2, \
                        input_pin3, input_pin4, input_pin5, input_pin6, \
                        input_pin7, input_pin8, input_pin9) "
                   "OR :rt9 IN (input_pin0, input_pin1, input_pin2, \
                        input_pin3, input_pin4, input_pin5, input_pin6, \
                        input_pin7, input_pin8, input_pin9)) "
                   ";"
        )

        if self.loaded is True:
            SQL_text = SQL_text.bindparams(textcircuit=s_circuit,
                                           t0=s_textinputpins[0],
                                           t1=s_textinputpins[1],
                                           t2=s_textinputpins[2],
                                           t3=s_textinputpins[3],
                                           t4=s_textinputpins[4],
                                           t5=s_textinputpins[5],
                                           t6=s_textinputpins[6],
                                           t7=s_textinputpins[7],
                                           t8=s_textinputpins[8],
                                           t9=s_textinputpins[9],
                                           rt0=s_textreqinputpins[0],
                                           rt1=s_textreqinputpins[1],
                                           rt2=s_textreqinputpins[2],
                                           rt3=s_textreqinputpins[3],
                                           rt4=s_textreqinputpins[4],
                                           rt5=s_textreqinputpins[5],
                                           rt6=s_textreqinputpins[6],
                                           rt7=s_textreqinputpins[7],
                                           rt8=s_textreqinputpins[8],
                                           rt9=s_textreqinputpins[9]
                                           )

            query = self.conn.execute(SQL_text)

        else:
            raise IOError("SQL file not opened before executing \
                          readgateswithinputs")

        results = self.parse_SQL_query(query)

        for result in results:
            gate = result[0]
            output_pin = result[1]
            input_pins = set([pin for pin in result[2:] if pin != 'None'])
            returngatedb.add(gate, output_pin, input_pins)

        return returngatedb