libqasm
library for handling cQASM files
Public Member Functions | Static Public Member Functions | List of all members
V1Analyzer Class Reference

Main class for parsing and analyzing cQASM files with the v1 API. More...

Public Member Functions

 V1Analyzer (const std::string &max_version="1.0", bool without_defaults=false)
 Creates a new 1.x semantic analyzer. More...
 
void register_instruction (const std::string &name, const std::string &param_types="", bool allow_conditional=true, bool allow_parallel=true, bool allow_reused_qubits=false, bool allow_different_index_sizes=false)
 Registers an instruction type. More...
 
void register_error_model (const std::string &name, const std::string &param_types="")
 Registers an error model. More...
 
std::vector< std::string > analyze_file (const std::string &filename) const
 Parses and analyzes the given file. More...
 
std::vector< std::string > analyze_string (const std::string &data, const std::string &filename="<unknown>") const
 Same as analyze_file(), but instead receives the file contents directly. More...
 

Static Public Member Functions

static std::vector< std::string > parse_file (const std::string &filename)
 Only parses the given file. More...
 
static std::vector< std::string > parse_string (const std::string &data, const std::string &filename="<unknown>")
 Same as parse_file(), but instead receives the file contents directly. More...
 

Detailed Description

Main class for parsing and analyzing cQASM files with the v1 API.

Definition at line 28 of file cqasm-py.hpp.

#include <cqasm-py.hpp>

Constructor & Destructor Documentation

◆ V1Analyzer()

V1Analyzer::V1Analyzer ( const std::string &  max_version = "1.0",
bool  without_defaults = false 
)

Creates a new 1.x semantic analyzer.

When without_defaults is specified, the default instruction set and error models are not loaded into the instruction and error model tables, so you have to specify the entire instruction set using register_instruction() and register_error_model(); otherwise those functions only add to the defaults. Unlike the C++ version of the analyzer class, the initial mappings and functions are not configurable at all; the defaults for these are always used.

Definition at line 19 of file cqasm-py.cpp.

Member Function Documentation

◆ register_instruction()

void V1Analyzer::register_instruction ( const std::string &  name,
const std::string &  param_types = "",
bool  allow_conditional = true,
bool  allow_parallel = true,
bool  allow_reused_qubits = false,
bool  allow_different_index_sizes = false 
)

Registers an instruction type.

The arguments are passed straight to instruction::Instruction's constructor.

Definition at line 36 of file cqasm-py.cpp.

◆ register_error_model()

void V1Analyzer::register_error_model ( const std::string &  name,
const std::string &  param_types = "" 
)

Registers an error model.

The arguments are passed straight to error_model::ErrorModel's constructor.

Definition at line 58 of file cqasm-py.cpp.

◆ parse_file()

std::vector< std::string > V1Analyzer::parse_file ( const std::string &  filename)
static

Only parses the given file.

The file must be in 1.x syntax; no version check or conversion is performed. Returns a vector of strings, of which the first is always present and is the CBOR serialization of the v1.x AST. Any additional strings represent error messages.

Definition at line 71 of file cqasm-py.cpp.

◆ parse_string()

std::vector< std::string > V1Analyzer::parse_string ( const std::string &  data,
const std::string &  filename = "<unknown>" 
)
static

Same as parse_file(), but instead receives the file contents directly.

The filename, if specified, is only used when reporting errors.

Definition at line 87 of file cqasm-py.cpp.

◆ analyze_file()

std::vector< std::string > V1Analyzer::analyze_file ( const std::string &  filename) const

Parses and analyzes the given file.

If the file is written in a later file version, this function may try to reduce it to the maximum 1.x API version support advertised using this object's constructor. Returns a vector of strings, of which the first is always present and is the CBOR serialization of the v1.x semantic tree. Any additional strings represent error messages.

Definition at line 108 of file cqasm-py.cpp.

◆ analyze_string()

std::vector< std::string > V1Analyzer::analyze_string ( const std::string &  data,
const std::string &  filename = "<unknown>" 
) const

Same as analyze_file(), but instead receives the file contents directly.

The filename, if specified, is only used when reporting errors.

Definition at line 124 of file cqasm-py.cpp.


The documentation for this class was generated from the following files: