]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/go/gofrontend/export.h
ee61d2752de480397d5cc12eddcefcea5cdc1216
1 // export.h -- Export declarations in Go frontend. -*- C++ -*-
3 // Copyright 2009 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
10 #include "string-dump.h"
18 class Import_init_set
;
20 // Codes used for the builtin types. These are all negative to make
21 // them easily distinct from the codes assigned by Export::write_type.
22 // Note that these codes may not be changed! Changing them would
23 // break existing export data.
36 BUILTIN_FLOAT64
= -10,
39 BUILTIN_UINTPTR
= -13,
42 BUILTIN_COMPLEX64
= -17,
43 BUILTIN_COMPLEX128
= -18,
48 SMALLEST_BUILTIN_CODE
= -21
51 // Export data version number. New export data is written with the
52 // "current" version, but there is support for reading files with
53 // older version export data (at least for now).
55 enum Export_data_version
{
56 EXPORT_FORMAT_UNKNOWN
= 0,
59 EXPORT_FORMAT_CURRENT
= EXPORT_FORMAT_V2
62 // This class manages exporting Go declarations. It handles the main
63 // loop of exporting. A pointer to this class is also passed to the
64 // various specific export implementations.
66 class Export
: public String_dump
69 // The Stream class is an interface used to output the exported
70 // information. The caller should instantiate a child of this
78 // Write a string. Implements the String_dump interface.
80 write_string(const std::string
& s
)
81 { this->write_and_sum_bytes(s
.data(), s
.length()); }
83 // Write a nul terminated string. Implements the String_dump interface.
85 write_c_string(const char* s
)
86 { this->write_and_sum_bytes(s
, strlen(s
)); }
90 write_bytes(const char* bytes
, size_t length
)
91 { this->write_and_sum_bytes(bytes
, length
); }
93 // Return the raw bytes of the checksum data.
97 // Write a checksum string to the stream. This will be called at
98 // the end of the other output.
100 write_checksum(const std::string
&);
103 // This function is called with data to export. This data must be
104 // made available as a contiguous stream for the importer.
106 do_write(const char* bytes
, size_t length
) = 0;
110 write_and_sum_bytes(const char*, size_t);
118 // Size of export data magic string (which includes version number).
119 static const int magic_len
= 4;
121 // Magic strings (current version and older v1 version).
122 static const char cur_magic
[magic_len
];
123 static const char v1_magic
[magic_len
];
125 // The length of the checksum string.
126 static const int checksum_len
= 20;
128 // Register the builtin types.
130 register_builtin_types(Gogo
*);
132 // Export the identifiers in BINDINGS which are marked for export.
133 // The exporting is done via a series of calls to THIS->STREAM_. If
134 // is nothing to export, this->stream_->write will not be called.
135 // PREFIX is the package prefix. PKGPATH is the package path.
136 // Only one of PREFIX and PKGPATH will be non-empty.
137 // PACKAGES is all the packages we have seen.
138 // IMPORTS is the explicitly imported packages.
139 // IMPORT_INIT_FN is the name of the import initialization function
140 // for this package; it will be empty if none is needed.
141 // IMPORTED_INIT_FNS is the list of initialization functions for
142 // imported packages.
144 export_globals(const std::string
& package_name
,
145 const std::string
& prefix
,
146 const std::string
& pkgpath
,
147 const std::map
<std::string
, Package
*>& packages
,
148 const std::map
<std::string
, Package
*>& imports
,
149 const std::string
& import_init_fn
,
150 const Import_init_set
& imported_init_fns
,
151 const Bindings
* bindings
);
153 // Write a string to the export stream.
155 write_string(const std::string
& s
)
156 { this->stream_
->write_string(s
); }
158 // Write a nul terminated string to the export stream.
160 write_c_string(const char* s
)
161 { this->stream_
->write_c_string(s
); }
163 // Write some bytes to the export stream.
165 write_bytes(const char* bytes
, size_t length
)
166 { this->stream_
->write_bytes(bytes
, length
); }
168 // Write a name to the export stream. If NAME is empty, write "?".
170 write_name(const std::string
& name
);
172 // Write out a type. This handles references back to previous
175 write_type(const Type
*);
177 // Write the escape note to the export stream. If NOTE is NULL, write
180 write_escape(std::string
* note
);
182 // Write an integer value.
186 // Write an unsigned value.
188 write_unsigned(unsigned);
191 Export(const Export
&);
192 Export
& operator=(const Export
&);
194 // Write out all known packages.
196 write_packages(const std::map
<std::string
, Package
*>& packages
);
198 typedef std::map
<unsigned, std::set
<unsigned> > Init_graph
;
201 add_init_graph_edge(Init_graph
* init_graph
, unsigned src
, unsigned sink
);
204 populate_init_graph(Init_graph
* init_graph
,
205 const Import_init_set
& imported_init_fns
,
206 const std::map
<std::string
, unsigned>& init_idx
);
208 // Write out the imported packages.
210 write_imports(const std::map
<std::string
, Package
*>& imports
);
212 // Write out the imported initialization functions and init graph.
214 write_imported_init_fns(const std::string
& package_name
,
215 const std::string
&, const Import_init_set
&);
217 // Register one builtin type.
219 register_builtin_type(Gogo
*, const char* name
, Builtin_code
);
221 // Mapping from Type objects to a constant index.
222 typedef Unordered_map(const Type
*, int) Type_refs
;
224 // The stream to which we are writing data.
227 Type_refs type_refs_
;
228 // Index number of next type.
230 // Packages we have written out.
231 Unordered_set(const Package
*) packages_
;
234 // An export streamer which puts the export stream in a named section.
236 class Stream_to_section
: public Export::Stream
243 do_write(const char*, size_t);
246 #endif // !defined(GO_EXPORT_H)