-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from QuTech-Delft/v1x_and_v3x_generators
Add V1xGenerator and V3xGenerator.
- Loading branch information
Showing
15 changed files
with
425 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
include(default) | ||
|
||
[settings] | ||
compiler.cppstd=17 | ||
compiler.cppstd=23 | ||
func-gen/*:build_type=Debug | ||
|
||
[options] | ||
func-gen/*:asan_enabled=False | ||
func-gen/*:build_tests=False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
include(default) | ||
|
||
[settings] | ||
compiler.cppstd=17 | ||
compiler.cppstd=23 | ||
func-gen/*:build_type=Release | ||
|
||
[options] | ||
func-gen/*:asan_enabled=False | ||
func-gen/*:build_tests=False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
include(default) | ||
|
||
[settings] | ||
compiler.cppstd=17 | ||
compiler.cppstd=23 | ||
func-gen/*:build_type=Debug | ||
|
||
[options] | ||
func-gen/*:asan_enabled=True | ||
func-gen/*:build_tests=True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
include(default) | ||
|
||
[settings] | ||
compiler.cppstd=17 | ||
compiler.cppstd=23 | ||
func-gen/*:build_type=Release | ||
|
||
[options] | ||
func-gen/*:asan_enabled=True | ||
func-gen/*:build_tests=True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#pragma once | ||
|
||
#include "../generator.hpp" | ||
|
||
#include <string_view> | ||
|
||
|
||
/** | ||
* Namespace for the \ref func-gen program. | ||
*/ | ||
namespace func_gen { | ||
|
||
constinit const std::string_view v1x_version{ "v1x" }; | ||
|
||
/** | ||
* Generator class. | ||
*/ | ||
class V1xGenerator : public Generator { | ||
/** | ||
* Like generate_impl_header(), but in addition, | ||
* generates some boilerplate code for safely casting all the arguments to constant values | ||
* (throwing a compile error if they're not constant) and | ||
* storing them in variables a..z. | ||
* This is, of course, only applicable for functions that are only evaluable during semantic analysis. | ||
*/ | ||
void generate_const_impl_header(const Function &func) override; | ||
|
||
/** | ||
* Generates the end of a function body, with an appropriate return statement. | ||
* return_type must be one of: | ||
* | ||
* - 'a': returns a ConstAxis, return_expr must be a primitive::Axis. | ||
* - 'b': returns a ConstBool, return_expr must be a primitive::Bool. | ||
* - 'i': returns a ConstInt, return_expr must be a primitive::Int. | ||
* - 'r': returns a ConstReal, return_expr must be a primitive::Real. | ||
* - 'c': returns a ConstComplex, return_expr must be a primitive::Complex. | ||
* - 'm': returns a ConstRealMatrix, return_expr must be a primitive::RMatrix. | ||
* - 'n': returns a ConstComplexMatrix, return_expr must be a primitive::CMatrix. | ||
* - 's': returns a ConstString, return_expr must be a primitive::Str. | ||
* - 'j': returns a ConstJson, return_expr must be a primitive::Str. | ||
* - 'Q': returns a QubitRefs, return_expr must be a Many<ConstInt>. | ||
* - 'B': returns a BitRefs, return_expr must be a Many<ConstInt>. | ||
*/ | ||
void generate_impl_footer(const std::string &return_expr, char return_type) override; | ||
|
||
public: | ||
/** | ||
* Constructs a v1x generator for the function table. | ||
*/ | ||
V1xGenerator(const std::string &header_filename, const std::string &source_filename); | ||
|
||
/** | ||
* Finishes writing the header & source file, then destroys the v1x generator. | ||
*/ | ||
~V1xGenerator() override = default; | ||
}; | ||
|
||
} // namespace func_gen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#pragma once | ||
|
||
#include "../generator.hpp" | ||
|
||
#include <string_view> | ||
|
||
|
||
/** | ||
* Namespace for the \ref func-gen program. | ||
*/ | ||
namespace func_gen { | ||
|
||
constinit const std::string_view v3x_version{ "v3x" }; | ||
|
||
/** | ||
* Generator class. | ||
*/ | ||
class V3xGenerator : public Generator { | ||
/** | ||
* Like generate_impl_header(), but in addition, | ||
* generates some boilerplate code for safely casting all the arguments to constant values | ||
* (throwing a compile error if they're not constant) and | ||
* storing them in variables a..z. | ||
* This is, of course, only applicable for functions that are only evaluable during semantic analysis. | ||
*/ | ||
void generate_const_impl_header(const Function &func) override; | ||
|
||
/** | ||
* Generates the end of a function body, with an appropriate return statement. | ||
* return_type must be one of: | ||
* | ||
* - 'a': returns a ConstAxis, return_expr must be a primitive::Axis. | ||
* - 'b': returns a ConstBool, return_expr must be a primitive::Bool. | ||
* - 'i': returns a ConstInt, return_expr must be a primitive::Int. | ||
* - 'r': returns a ConstReal, return_expr must be a primitive::Real. | ||
* - 'c': returns a ConstComplex, return_expr must be a primitive::Complex. | ||
* - 'X': returns a ConstBoolArray, return_expr must be a Many<ConstBool>. | ||
* - 'Y': returns a ConstIntArray, return_expr must be a Many<ConstInt>. | ||
* - 'Z': returns a ConstRealArray, return_expr must be a Many<ConstReal>. | ||
* - 'I': returns an IndexRef, return_expr must be a Many<ConstReal>. | ||
*/ | ||
void generate_impl_footer(const std::string &return_expr, char return_type) override; | ||
|
||
public: | ||
/** | ||
* Constructs a v3x generator for the function table. | ||
*/ | ||
V3xGenerator(const std::string &header_filename, const std::string &source_filename); | ||
|
||
/** | ||
* Finishes writing the header & source file, then destroys the v3x generator. | ||
*/ | ||
~V3xGenerator() override = default; | ||
}; | ||
|
||
} // namespace func_gen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.