libqasm
library for handling cQASM files
|
Main class used for analyzing cQASM files. More...
Public Member Functions | |
Analyzer (const std::string &api_version="1.0") | |
Creates a new semantic analyzer. More... | |
Analyzer (const primitives::Version &api_version) | |
Creates a new semantic analyzer. More... | |
void | register_mapping (const std::string &name, const values::Value &value) |
Registers an initial mapping from the given name to the given value. More... | |
void | register_function (const std::string &name, const types::Types ¶m_types, const resolver::FunctionImpl &impl) |
Registers a function, usable within expressions. More... | |
void | register_function (const std::string &name, const std::string ¶m_types, const resolver::FunctionImpl &impl) |
Convenience method for registering a function. More... | |
void | register_default_functions_and_mappings () |
Registers a number of default functions and mappings, such as the operator functions, the usual trigonometric functions, mappings for pi, eu (aka e, 2.718...), im (imaginary unit) and so on. More... | |
void | register_instruction (const instruction::Instruction &instruction) |
Registers an instruction type. More... | |
void | register_instruction (const std::string &name, const std::string ¶m_types="", bool allow_conditional=true, bool allow_parallel=true, bool allow_reused_qubits=false, bool allow_different_index_sizes=false) |
Convenience method for registering an instruction type. More... | |
template<typename T > | |
void | register_instruction_with_annotation (T &&annotation, const std::string &name, const std::string ¶m_types="", bool allow_conditional=true, bool allow_parallel=true, bool allow_reused_qubits=false, bool allow_different_index_sizes=false) |
Convenience method for registering an instruction type with a single user-specified annotation. More... | |
void | register_error_model (const error_model::ErrorModel &error_model) |
Registers an error model. More... | |
void | register_error_model (const std::string &name, const std::string ¶m_types="") |
Convenience method for registering an error model. More... | |
template<typename T > | |
void | register_error_model_with_annotation (T &&annotation, const std::string &name, const std::string ¶m_types="") |
Convenience method for registering an error model with a single user-specified annotation. More... | |
AnalysisResult | analyze (const ast::Program &program) const |
Analyzes the given program AST node. More... | |
AnalysisResult | analyze (const parser::ParseResult &parse_result) const |
Analyzes the given parse result. More... | |
AnalysisResult | analyze (const std::function< version::Version()> &version_parser, const std::function< parser::ParseResult()> &file_parser) const |
Parses and analyzes using the given version and file parser closures. More... | |
AnalysisResult | analyze (const std::string &filename) const |
Parses and analyzes the given file. More... | |
AnalysisResult | analyze (FILE *file, const std::string &filename="<unknown>") const |
Parses and analyzes the given file pointer. More... | |
AnalysisResult | analyze_string (const std::string &data, const std::string &filename="<unknown>") const |
Parses and analyzes the given string. More... | |
Friends | |
class | AnalyzerHelper |
Main class used for analyzing cQASM files.
Construction of this class is the entry point for libqasm whenever you need to modify the default instruction set, have a different set of supported error models, or want to add additional initial mappings, operators, or functions. The process is simple:
register_*()
methods to configure the Analyzer.analyze*()
methods to analyze cQASM files or string representations thereof.Note that the only state maintained by the Analyzer object is its configuration, and the analyze*()
functions never change this state (hence they are const).
Definition at line 101 of file cqasm-v1-analyzer.hpp.
#include <cqasm-v1-analyzer.hpp>
cqasm::v1::analyzer::Analyzer::Analyzer | ( | const std::string & | api_version = "1.0" | ) |
Creates a new semantic analyzer.
Definition at line 40 of file cqasm-v1-analyzer.cpp.
cqasm::v1::analyzer::Analyzer::Analyzer | ( | const primitives::Version & | api_version | ) |
Creates a new semantic analyzer.
Definition at line 51 of file cqasm-v1-analyzer.cpp.
void cqasm::v1::analyzer::Analyzer::register_mapping | ( | const std::string & | name, |
const values::Value & | value | ||
) |
Registers an initial mapping from the given name to the given value.
Definition at line 63 of file cqasm-v1-analyzer.cpp.
void cqasm::v1::analyzer::Analyzer::register_function | ( | const std::string & | name, |
const types::Types & | param_types, | ||
const resolver::FunctionImpl & | impl | ||
) |
Registers a function, usable within expressions.
values::check_const() can be used in the function implementation to assert that the values must be constant when the function can only be used during constant propagation. When the function also (or only) supports dynamic evaluation, the implementation will have to check whether the inputs are const manually (for instance using as_constant()
) to determine when to return a dynamic values::Function node instead.
Definition at line 70 of file cqasm-v1-analyzer.cpp.
void cqasm::v1::analyzer::Analyzer::register_function | ( | const std::string & | name, |
const std::string & | param_types, | ||
const resolver::FunctionImpl & | impl | ||
) |
Convenience method for registering a function.
The param_types are specified as a string, converted to types::Types for the other overload using types::from_spec.
Definition at line 83 of file cqasm-v1-analyzer.cpp.
void cqasm::v1::analyzer::Analyzer::register_default_functions_and_mappings | ( | ) |
Registers a number of default functions and mappings, such as the operator functions, the usual trigonometric functions, mappings for pi, eu (aka e, 2.718...), im (imaginary unit) and so on.
Definition at line 96 of file cqasm-v1-analyzer.cpp.
void cqasm::v1::analyzer::Analyzer::register_instruction | ( | const instruction::Instruction & | instruction | ) |
Registers an instruction type.
If you never call this, instructions are not resolved (i.e. anything goes name- and operand type-wise). Once you do, only instructions with signatures as added are legal, so anything that doesn't match returns an error.
Definition at line 114 of file cqasm-v1-analyzer.cpp.
void cqasm::v1::analyzer::Analyzer::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 |
||
) |
Convenience method for registering an instruction type.
The arguments are passed straight to instruction::Instruction's constructor.
Definition at line 123 of file cqasm-v1-analyzer.cpp.
|
inline |
Convenience method for registering an instruction type with a single user-specified annotation.
The arguments are passed straight to instruction::Instruction's constructor and set_annotation.
Definition at line 241 of file cqasm-v1-analyzer.hpp.
void cqasm::v1::analyzer::Analyzer::register_error_model | ( | const error_model::ErrorModel & | error_model | ) |
Registers an error model.
If you never call this, error models are not resolved (i.e. anything goes name- and operand type-wise). Once you do, only error models with signatures as added are legal, so anything that doesn't match returns an error.
Definition at line 142 of file cqasm-v1-analyzer.cpp.
void cqasm::v1::analyzer::Analyzer::register_error_model | ( | const std::string & | name, |
const std::string & | param_types = "" |
||
) |
Convenience method for registering an error model.
The arguments are passed straight to error_model::ErrorModel's constructor.
Definition at line 151 of file cqasm-v1-analyzer.cpp.
|
inline |
Convenience method for registering an error model with a single user-specified annotation.
The arguments are passed straight to instruction::Instruction's constructor and set_annotation.
Definition at line 285 of file cqasm-v1-analyzer.hpp.
AnalysisResult cqasm::v1::analyzer::Analyzer::analyze | ( | const ast::Program & | program | ) | const |
Analyzes the given program AST node.
Analyzes the given AST.
Definition at line 489 of file cqasm-v1-analyzer.cpp.
AnalysisResult cqasm::v1::analyzer::Analyzer::analyze | ( | const parser::ParseResult & | parse_result | ) | const |
Analyzes the given parse result.
If there are parse errors, they are copied into the AnalysisResult error list, and the root node will be empty.
Definition at line 502 of file cqasm-v1-analyzer.cpp.
AnalysisResult cqasm::v1::analyzer::Analyzer::analyze | ( | const std::function< version::Version()> & | version_parser, |
const std::function< parser::ParseResult()> & | file_parser | ||
) | const |
Parses and analyzes using the given version and file parser closures.
Definition at line 515 of file cqasm-v1-analyzer.cpp.
AnalysisResult cqasm::v1::analyzer::Analyzer::analyze | ( | const std::string & | filename | ) | const |
Parses and analyzes the given file.
Definition at line 539 of file cqasm-v1-analyzer.cpp.
AnalysisResult cqasm::v1::analyzer::Analyzer::analyze | ( | FILE * | file, |
const std::string & | filename = "<unknown>" |
||
) | const |
Parses and analyzes the given file pointer.
The optional filename argument will be used only for error messages.
Definition at line 550 of file cqasm-v1-analyzer.cpp.
AnalysisResult cqasm::v1::analyzer::Analyzer::analyze_string | ( | const std::string & | data, |
const std::string & | filename = "<unknown>" |
||
) | const |
Parses and analyzes the given string.
The optional filename argument will be used only for error messages.
Definition at line 561 of file cqasm-v1-analyzer.cpp.
|
friend |
Definition at line 103 of file cqasm-v1-analyzer.hpp.