summaryrefslogtreecommitdiff
path: root/source/slang-capture-replay/parameter-encoder.h
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2024-06-13 13:02:12 -0700
committerGitHub <noreply@github.com>2024-06-13 13:02:12 -0700
commitf0d40ad5e1d0a0dec39fe8a141d3f81d88fc576a (patch)
tree210a0a9b5bb2aea0e64776527c4ce04266709a43 /source/slang-capture-replay/parameter-encoder.h
parentecc6ecb3a25a28eb5e85cfdb2bf170448ab9a4e7 (diff)
capture/replay: implement infrastructure for capture (#4372)
* Define api call ID for each being captured methods * Add parameter encoder interface * Add outputStream and capture manager Add infrastructure for output stream This is the interface to record the method and parameter, and also provide functionality to write all the serialized data into file. Add capture manager: Capture manager is associated to global session object, it will provide the functionality to actual record all the APIs. Implement some of parameter encoder functions. * Fix some Windows & cmake build error * remove unused headers
Diffstat (limited to 'source/slang-capture-replay/parameter-encoder.h')
-rw-r--r--source/slang-capture-replay/parameter-encoder.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/source/slang-capture-replay/parameter-encoder.h b/source/slang-capture-replay/parameter-encoder.h
new file mode 100644
index 000000000..c7c2d959a
--- /dev/null
+++ b/source/slang-capture-replay/parameter-encoder.h
@@ -0,0 +1,51 @@
+#ifndef PARAMETER_ENCODER_H
+#define PARAMETER_ENCODER_H
+
+#include <cstdio>
+#include <cinttypes>
+#include <cstdint>
+
+#include "output-stream.h"
+
+namespace SlangCapture
+{
+ class ParameterEncoder
+ {
+ public:
+ ParameterEncoder(OutputStream* stream) : m_stream(stream) {};
+ void encodeInt8(int8_t value) { encodeValue(value); }
+ void encodeUint8(uint8_t value) { encodeValue(value); }
+ void encodeInt16(int16_t value) { encodeValue(value); }
+ void encodeUint16(uint16_t value) { encodeValue(value); }
+ void encodeInt32(int32_t value) { encodeValue(value); }
+ void encodeUint32(uint32_t value) { encodeValue(value); }
+ void encodeInt64(int64_t value) { encodeValue(value); }
+ void encodeUint64(uint64_t value) { encodeValue(value); }
+ void encodeFloat(float value) { encodeValue(value); }
+ void encodeDouble(double value) { encodeValue(value); }
+ void encodeBool(bool value) { encodeValue(value); }
+
+ template<typename T>
+ void encodeEnumValue(T value) { encodeValue(static_cast<uint32_t>(value)); }
+
+ void encodeString(const char* value);
+ void encodePointer(const void* value, bool omitData = false, size_t size = 0);
+ void encodeAddress(const void* value) { encodeValue(reinterpret_cast<uint64_t>(value)); }
+
+ void encodeStruct(slang::SessionDesc const& desc);
+ void encodeStruct(slang::PreprocessorMacroDesc const& desc);
+ void encodeStruct(slang::CompilerOptionEntry const& entry);
+ void encodeStruct(slang::CompilerOptionValue const& value);
+ void encodeStruct(slang::TargetDesc const& targetDesc);
+
+ private:
+ template <typename T>
+ void encodeValue(T value)
+ {
+ m_stream->write(&value, sizeof(T));
+ }
+ OutputStream* m_stream;
+ };
+} // namespace SlangCapture
+
+#endif // PARAMETER_ENCODER_H