Beispiel #1
0
 def classical_comparison(self, op, target, left, right):
     if op == "EQ":
         return ClassicalEqual(target, left, right)
     elif op == "GT":
         return ClassicalGreaterThan(target, left, right)
     elif op == "GE":
         return ClassicalGreaterEqual(target, left, right)
     elif op == "LT":
         return ClassicalLessThan(target, left, right)
     elif op == "LE":
         return ClassicalLessEqual(target, left, right)
Beispiel #2
0
def LT(classical_reg1, classical_reg2, classical_reg3):
    """
    Produce an LT instruction.

    :param classical_reg1: Memory address to which to store the comparison result.
    :param classical_reg2: Left comparison operand.
    :param classical_reg3: Right comparison operand.
    :return: A ClassicalLessThan instance.
    """
    classical_reg1, classical_reg2, classical_reg3 = prepare_ternary_operands(
        classical_reg1, classical_reg2, classical_reg3)
    return ClassicalLessThan(classical_reg1, classical_reg2, classical_reg3)
Beispiel #3
0
def LT(classical_reg1: MemoryReferenceDesignator,
       classical_reg2: MemoryReferenceDesignator,
       classical_reg3: Union[MemoryReferenceDesignator, int, float]) -> ClassicalLessThan:
    """
    Produce an LT instruction.

    :param classical_reg1: Memory address to which to store the comparison result.
    :param classical_reg2: Left comparison operand.
    :param classical_reg3: Right comparison operand.
    :return: A ClassicalLessThan instance.
    """
    classical_reg1, classical_reg2, classical_reg3 = prepare_ternary_operands(classical_reg1,
                                                                              classical_reg2,
                                                                              classical_reg3)
    return ClassicalLessThan(classical_reg1, classical_reg2, classical_reg3)
Beispiel #4
0
    def exitClassicalComparison(self, ctx):
        # type: (QuilParser.ClassicalComparisonContext) -> None
        target = _addr(ctx.addr(0))
        left = _addr(ctx.addr(1))
        if ctx.number():
            right = _number(ctx.number())
        else:
            right = _addr(ctx.addr(2))

        if ctx.EQ():
            self.result.append(ClassicalEqual(target, left, right))
        elif ctx.GT():
            self.result.append(ClassicalGreaterThan(target, left, right))
        elif ctx.GE():
            self.result.append(ClassicalGreaterEqual(target, left, right))
        elif ctx.LT():
            self.result.append(ClassicalLessThan(target, left, right))
        elif ctx.LE():
            self.result.append(ClassicalLessEqual(target, left, right))