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 PreSubroutine, 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_presubroutine(text)

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

Parameters

text (str) –

Return type

PreSubroutine

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 PreSubroutine 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 PreSubroutine 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]