Beispiel #1
0
 def logical_binary_op(self, op, left, right):
     if op == "AND":
         return ClassicalAnd(left, right)
     elif op == "OR":
         return ClassicalInclusiveOr(left, right)
     elif op == "IOR":
         return ClassicalInclusiveOr(left, right)
     elif op == "XOR":
         return ClassicalExclusiveOr(left, right)
Beispiel #2
0
def IOR(classical_reg1, classical_reg2):
    """
    Produce an inclusive OR instruction.

    :param classical_reg1: The first classical register, which gets modified.
    :param classical_reg2: The second classical register or immediate value.
    :return: A ClassicalOr instance.
    """
    left, right = unpack_reg_val_pair(classical_reg1, classical_reg2)
    return ClassicalInclusiveOr(left, right)
Beispiel #3
0
def IOR(classical_reg1: MemoryReferenceDesignator,
        classical_reg2: Union[MemoryReferenceDesignator, int]) -> ClassicalInclusiveOr:
    """
    Produce an inclusive OR instruction.

    :param classical_reg1: The first classical register, which gets modified.
    :param classical_reg2: The second classical register or immediate value.
    :return: A ClassicalInclusiveOr instance.
    """
    left, right = unpack_reg_val_pair(classical_reg1, classical_reg2)
    assert isinstance(right, (MemoryReference, int))  # placate mypy
    return ClassicalInclusiveOr(left, right)
Beispiel #4
0
    def exitLogicalBinaryOp(self, ctx):
        # type: (QuilParser.LogicalBinaryOpContext) -> None
        left = _addr(ctx.addr(0))
        if ctx.INT():
            right = int(ctx.INT().getText())
        else:
            right = _addr(ctx.addr(1))

        if ctx.AND():
            self.result.append(ClassicalAnd(left, right))
        elif ctx.OR():
            self.result.append(ClassicalOr(left, right))
        elif ctx.IOR():
            self.result.append(ClassicalInclusiveOr(left, right))
        elif ctx.XOR():
            self.result.append(ClassicalExclusiveOr(left, right))
Beispiel #5
0
    def exitLogicalBinaryOp(self, ctx):
        # type: (QuilParser.LogicalBinaryOpContext) -> None
        left = _addr(ctx.addr(0))
        right: Union[int, MemoryReference]
        if ctx.INT():
            right = int(ctx.INT().getText())
        else:
            right = _addr(ctx.addr(1))

        if ctx.AND():
            self.result.append(ClassicalAnd(left, right))
        elif ctx.OR():
            if isinstance(right, MemoryReference):
                self.result.append(ClassicalOr(left, right))
            else:
                raise RuntimeError(
                    "Right operand of deprecated OR instruction must be a"
                    f" MemoryReference, but found '{right}'")
        elif ctx.IOR():
            self.result.append(ClassicalInclusiveOr(left, right))
        elif ctx.XOR():
            self.result.append(ClassicalExclusiveOr(left, right))