forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_serialization.cpp
More file actions
48 lines (39 loc) · 1.04 KB
/
python_serialization.cpp
File metadata and controls
48 lines (39 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <string>
#include <libasr/config.h>
#include <lpython/python_serialization.h>
#include <libasr/bwriter.h>
#include <libasr/string_utils.h>
namespace LCompilers::LPython {
class ASTDeserializationVisitor :
#ifdef WITH_LFORTRAN_BINARY_MODFILES
public BinaryReader,
#else
public TextReader,
#endif
public AST::DeserializationBaseVisitor<ASTDeserializationVisitor>
{
public:
ASTDeserializationVisitor(Allocator &al, const std::string &s) :
#ifdef WITH_LFORTRAN_BINARY_MODFILES
BinaryReader(s),
#else
TextReader(s),
#endif
DeserializationBaseVisitor(al, true, 0) {}
bool read_bool() {
uint8_t b = read_int8();
return (b == 1);
}
char* read_cstring() {
std::string s = read_string();
LCompilers::Str cs;
cs.from_str_view(s);
char* p = cs.c_str(al);
return p;
}
};
AST::ast_t* deserialize_ast(Allocator &al, const std::string &s) {
ASTDeserializationVisitor v(al, s);
return v.deserialize_node();
}
} // namespace LCompilers::LPython