netqasm.lang.parsing

netqasm.lang.parsing.binary

class netqasm.lang.parsing.binary.Deserializer(flavour)

Bases: object

Deserializes raw bytes into a Subroutine, given a Flavour. NetQASMInstructions are immediately created from the binary encoding.

(This is in contrast with the parsing.text module, which first converts the input to a ProtoSubroutine, consisting of ICmd s, before transforming it into a Subroutine containing NetQASMInstruction s.)

Parameters:

flavour (Flavour)

deserialize_subroutine(raw)
Parameters:

raw (bytes)

Return type:

Subroutine

deserialize_command(raw)
Parameters:

raw (bytes)

Return type:

NetQASMInstruction

netqasm.lang.parsing.binary.deserialize(data, flavour=None)

Convert a binary encoding into a Subroutine object. The Vanilla flavour is used by default.

Parameters:
  • data (bytes)

  • flavour (Optional[Flavour])

Return type:

Subroutine

netqasm.lang.parsing.text

netqasm.lang.parsing.text.parse_text_protosubroutine(text)

Convert a text representation of a subroutine into a ProtoSubroutine object.

Parameters:

text (str)

Return type:

ProtoSubroutine

netqasm.lang.parsing.text.parse_text_subroutine(subroutine, assign_branch_labels=True, make_args_operands=True, replace_constants=True, flavour=None)

Convert a text representation of a subroutine into a Subroutine object.

Internally, first a ProtoSubroutine object is created, consisting of ICmd`s. This is then converted into a `Subroutine using assemble_subroutine.

Parameters:
  • subroutine (str)

  • flavour (Optional[Flavour])

Return type:

Subroutine

netqasm.lang.parsing.text.assemble_subroutine(pre_subroutine, assign_branch_labels=True, make_args_operands=True, replace_constants=True, flavour=None)

Convert a ProtoSubroutine into a Subroutine, given a Flavour (default: vanilla).

Parameters:
Return type:

Subroutine

netqasm.lang.parsing.text.parse_register(register)
Parameters:

register (str)

Return type:

Register

netqasm.lang.parsing.text.parse_address(address)
Parameters:

address (str)

Return type:

Union[Address, ArraySlice, ArrayEntry]

netqasm.lang.parsing.text.get_current_registers(commands)
Parameters:

commands (List[Union[ICmd, BranchLabel]])

Return type:

Set[str]