comparison gcc/go/gofrontend/export.h @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
9 9
10 #include "string-dump.h" 10 #include "string-dump.h"
11 11
12 class Go_sha1_helper; 12 class Go_sha1_helper;
13 class Gogo; 13 class Gogo;
14 class Named_object;
14 class Import_init; 15 class Import_init;
16 class Named_object;
15 class Bindings; 17 class Bindings;
16 class Type; 18 class Type;
17 class Package; 19 class Package;
18 class Import_init_set; 20 class Import_init_set;
19 class Backend; 21 class Backend;
55 57
56 enum Export_data_version { 58 enum Export_data_version {
57 EXPORT_FORMAT_UNKNOWN = 0, 59 EXPORT_FORMAT_UNKNOWN = 0,
58 EXPORT_FORMAT_V1 = 1, 60 EXPORT_FORMAT_V1 = 1,
59 EXPORT_FORMAT_V2 = 2, 61 EXPORT_FORMAT_V2 = 2,
60 EXPORT_FORMAT_CURRENT = EXPORT_FORMAT_V2 62 EXPORT_FORMAT_V3 = 3,
63 EXPORT_FORMAT_CURRENT = EXPORT_FORMAT_V3
61 }; 64 };
62 65
63 // This class manages exporting Go declarations. It handles the main 66 // This class manages exporting Go declarations. It handles the main
64 // loop of exporting. A pointer to this class is also passed to the 67 // loop of exporting. A pointer to this class is also passed to the
65 // various specific export implementations. 68 // various specific export implementations.
117 Export(Stream*); 120 Export(Stream*);
118 121
119 // Size of export data magic string (which includes version number). 122 // Size of export data magic string (which includes version number).
120 static const int magic_len = 4; 123 static const int magic_len = 4;
121 124
122 // Magic strings (current version and older v1 version). 125 // Magic strings (current version and older versions).
123 static const char cur_magic[magic_len]; 126 static const char cur_magic[magic_len];
124 static const char v1_magic[magic_len]; 127 static const char v1_magic[magic_len];
128 static const char v2_magic[magic_len];
125 129
126 // The length of the checksum string. 130 // The length of the checksum string.
127 static const int checksum_len = 20; 131 static const int checksum_len = 20;
128 132
129 // Register the builtin types. 133 // Register the builtin types.
149 const std::map<std::string, Package*>& imports, 153 const std::map<std::string, Package*>& imports,
150 const std::string& import_init_fn, 154 const std::string& import_init_fn,
151 const Import_init_set& imported_init_fns, 155 const Import_init_set& imported_init_fns,
152 const Bindings* bindings); 156 const Bindings* bindings);
153 157
158 // Set the index of a type.
159 bool
160 set_type_index(Type*);
161
154 // Write a string to the export stream. 162 // Write a string to the export stream.
155 void 163 void
156 write_string(const std::string& s) 164 write_string(const std::string& s)
157 { this->stream_->write_string(s); } 165 { this->stream_->write_string(s); }
158 166
189 write_unsigned(unsigned); 197 write_unsigned(unsigned);
190 198
191 private: 199 private:
192 Export(const Export&); 200 Export(const Export&);
193 Export& operator=(const Export&); 201 Export& operator=(const Export&);
202
203 // Prepare types for exporting.
204 int
205 prepare_types(const std::vector<Named_object*>* exports,
206 Unordered_set(const Package*)* imports);
194 207
195 // Write out all known packages. 208 // Write out all known packages.
196 void 209 void
197 write_packages(const std::map<std::string, Package*>& packages); 210 write_packages(const std::map<std::string, Package*>& packages);
198 211
206 const Import_init_set& imported_init_fns, 219 const Import_init_set& imported_init_fns,
207 const std::map<std::string, unsigned>& init_idx); 220 const std::map<std::string, unsigned>& init_idx);
208 221
209 // Write out the imported packages. 222 // Write out the imported packages.
210 void 223 void
211 write_imports(const std::map<std::string, Package*>& imports); 224 write_imports(const std::map<std::string, Package*>& imports,
225 const Unordered_set(const Package*)& type_imports);
212 226
213 // Write out the imported initialization functions and init graph. 227 // Write out the imported initialization functions and init graph.
214 void 228 void
215 write_imported_init_fns(const std::string& package_name, 229 write_imported_init_fns(const std::string& package_name,
216 const std::string&, const Import_init_set&); 230 const std::string&, const Import_init_set&);
217 231
232 // Write out all types.
233 void
234 write_types(int unexported_type_index);
235
236 // Write out one type definition.
237 void
238 write_type_definition(const Type* type, int index);
239
218 // Register one builtin type. 240 // Register one builtin type.
219 void 241 void
220 register_builtin_type(Gogo*, const char* name, Builtin_code); 242 register_builtin_type(Gogo*, const char* name, Builtin_code);
221
222 // Mapping from Type objects to a constant index.
223 typedef Unordered_map(const Type*, int) Type_refs;
224 243
225 // The stream to which we are writing data. 244 // The stream to which we are writing data.
226 Stream* stream_; 245 Stream* stream_;
227 // Type mappings.
228 Type_refs type_refs_;
229 // Index number of next type. 246 // Index number of next type.
230 int type_index_; 247 int type_index_;
231 // Packages we have written out. 248 // Packages we have written out.
232 Unordered_set(const Package*) packages_; 249 Unordered_set(const Package*) packages_;
233 }; 250 };
234 251
235 // An export streamer which puts the export stream in a named section. 252 // An export streamer that puts the export stream in a named section.
236 253
237 class Stream_to_section : public Export::Stream 254 class Stream_to_section : public Export::Stream
238 { 255 {
239 public: 256 public:
240 Stream_to_section(Backend*); 257 Stream_to_section(Backend*);
245 262
246 private: 263 private:
247 Backend* backend_; 264 Backend* backend_;
248 }; 265 };
249 266
267 // An export streamer that puts the export stream in a string.
268
269 class Stream_to_string : public Export::Stream
270 {
271 public:
272 Stream_to_string()
273 : string_()
274 {}
275
276 const std::string&
277 string() const
278 { return this->string_; }
279
280 protected:
281 void
282 do_write(const char* s, size_t len)
283 { this->string_.append(s, len); }
284
285 private:
286 std::string string_;
287 };
288
250 #endif // !defined(GO_EXPORT_H) 289 #endif // !defined(GO_EXPORT_H)