-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpz_library.h
140 lines (106 loc) · 3.15 KB
/
pz_library.h
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* Plasma in-memory representation (modules)
* vim: ts=4 sw=4 et
*
* Copyright (C) Plasma Team
* Distributed under the terms of the MIT license, see ../LICENSE.code
*/
#ifndef PZ_LIBRARY_H
#define PZ_LIBRARY_H
#include "pz_common.h"
#include <unordered_map>
#include "pz_closure.h"
#include "pz_code.h"
#include "pz_data.h"
#include "pz_gc_util.h"
namespace pz {
/*
* This class tracks all the information we need to load a library, since
* loading also includes linking. Once that's complete a lot of this can be
* dropped and only the exported symbols need to be kept (anything they
* point to will be kept by the GC).
*/
class LibraryLoading : public GCNewTrace
{
private:
std::vector<Struct *> m_structs;
std::vector<void *> m_datas;
std::vector<Proc *> m_procs;
unsigned m_total_code_size;
std::vector<Closure *> m_closures;
std::unordered_map<String, Closure *> m_symbols;
friend class Library;
public:
LibraryLoading(unsigned num_structs,
unsigned num_data,
unsigned num_procs,
unsigned num_closures,
NoGCScope &no_gc);
const Struct * struct_(unsigned id) const
{
return m_structs.at(id);
}
Struct * new_struct(unsigned num_fields, GCCapability & gc_cap);
void * data(unsigned id) const
{
return m_datas.at(id);
}
void add_data(void * data);
unsigned num_procs() const
{
return m_procs.size();
}
const Proc * proc(unsigned id) const
{
return m_procs.at(id);
}
Proc * proc(unsigned id)
{
return m_procs.at(id);
}
Proc * new_proc(String name, unsigned size, bool is_builtin,
GCCapability & gc_cap);
Closure * closure(unsigned id) const
{
return m_closures.at(id);
}
void add_symbol(String name, Closure * closure);
void print_loaded_stats() const;
LibraryLoading(LibraryLoading & other) = delete;
void operator=(LibraryLoading & other) = delete;
void do_trace(HeapMarkState * marker) const override;
};
class Library : public GCNewTrace
{
private:
std::unordered_map<String, Closure *> m_symbols;
PZOptEntrySignature m_entry_signature;
Closure * m_entry_closure;
public:
Library();
Library(LibraryLoading & loading);
Closure * entry_closure() const
{
return m_entry_closure;
}
PZOptEntrySignature entry_signature() const
{
return m_entry_signature;
}
void set_entry_closure(PZOptEntrySignature sig, Closure * clo)
{
m_entry_signature = sig;
m_entry_closure = clo;
}
/*
* Symbol names are fully qualified, since one Module class (which
* really represents a library) may contain more than one modules.
*/
void add_symbol(String name, Closure * closure);
Optional<Closure *> lookup_symbol(String name) const;
void do_trace(HeapMarkState * marker) const override;
Library(Library & other) = delete;
void operator=(Library & other) = delete;
};
} // namespace pz
#endif // ! PZ_LIBRARY_H