MLCompilerBridge
Tools for streamlining communication with ML models for compiler optimizations.
Loading...
Searching...
No Matches
jsonSerDes.h
Go to the documentation of this file.
1//=== SerDes/jsonSerDes.h -Json Serialization/Deserialization ---*- C++ ---===//
2//
3// Part of the MLCompilerBridge Project, under the Apache License v2.0 with LLVM
4// Exceptions. See the LICENSE file for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
12//===----------------------------------------------------------------------===//
13
14#ifndef JSON_SERIALIZER_H
15#define JSON_SERIALIZER_H
16
17#include "SerDes/baseSerDes.h"
18#include "llvm/Support/JSON.h"
19#include <string>
20#include <utility>
21
22namespace MLBridge {
24class JsonSerDes : public BaseSerDes {
25public:
27
28 static bool classof(const BaseSerDes *S) {
29 return S->getKind() == SerDesKind::Json;
30 }
31
32#define SET_FEATURE(TYPE, _) \
33 void setFeature(const std::string &name, const TYPE value) override { \
34 J[name] = value; \
35 } \
36 void setFeature(const std::string &name, const std::vector<TYPE> &value) \
37 override { \
38 J[name] = llvm::json::Array(value); \
39 }
41#undef SET_FEATURE
42
43 void *getSerializedData() override;
44
45 void cleanDataStructures() override { J = llvm::json::Object(); }
46
47private:
48 void *deserializeUntyped(void *data) override;
49 void *desJson(llvm::json::Value *V);
50
51private:
52 llvm::json::Object J;
53};
54} // namespace MLBridge
55
56#endif
Supporting new SerDes:
#define SUPPORTED_TYPES(M)
Definition baseSerDes.h:32
#define SET_FEATURE(TYPE, _)
setFeature() is used to set the features of the data structure used for communication.
Definition baseSerDes.h:54
SerDesKind getKind() const
Definition baseSerDes.h:49
JsonSerDes - Json Serialization/Deserialization using LLVM's json library.
Definition jsonSerDes.h:24
void * desJson(llvm::json::Value *V)
void * deserializeUntyped(void *data) override
void * getSerializedData() override
llvm::json::Object J
Definition jsonSerDes.h:52
static bool classof(const BaseSerDes *S)
Definition jsonSerDes.h:28
void cleanDataStructures() override
Definition jsonSerDes.h:45
SerDesKind
This is the base class for SerDes.
Definition baseSerDes.h:46