diff options
| author | Yong He <yonghe@outlook.com> | 2020-08-05 10:32:52 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-05 10:32:52 -0700 |
| commit | 6fb2aa70a2681bffbac7e8de67e9598105389945 (patch) | |
| tree | f89cb433e7498bf74292bf460096f1129ef3ac13 /prelude/slang-cpp-types.h | |
| parent | 092337a67e7ef8ec108cab9cb6679e59bb2ff791 (diff) | |
`AnyValue` based dynamic dispatch code gen (#1477)
* AnyValue based dynamic code gen
* Fix aarch64 build error
Diffstat (limited to 'prelude/slang-cpp-types.h')
| -rw-r--r-- | prelude/slang-cpp-types.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/prelude/slang-cpp-types.h b/prelude/slang-cpp-types.h index fd5a9a813..49461e4f4 100644 --- a/prelude/slang-cpp-types.h +++ b/prelude/slang-cpp-types.h @@ -41,6 +41,26 @@ struct Array size_t count; }; +template<size_t N> +struct AnyValue +{ + uint8_t data[N]; +}; +template<size_t N, typename T> +AnyValue<N> packAnyValue(const T& val) +{ + AnyValue<N> result; + memcpy(&result, &val, sizeof(T)); + return result; +} +template<size_t N, typename T> +T unpackAnyValue(const AnyValue<N>& val) +{ + T result; + memcpy(&result, &val, sizeof(T)); + return result; +} + /* Constant buffers become a pointer to the contained type, so ConstantBuffer<T> becomes T* in C++ code. */ |
