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 // Codes used for the builtin types. These are all negative to make
19 // them easily distinct from the codes assigned by Export::write_type.
20 // Note that these codes may not be changed! Changing them would
21 // break existing export data.
34 BUILTIN_FLOAT64 = -10,
37 BUILTIN_UINTPTR = -13,
40 BUILTIN_COMPLEX64 = -17,
41 BUILTIN_COMPLEX128 = -18,
44 SMALLEST_BUILTIN_CODE = -19
47 // This class manages exporting Go declarations. It handles the main
48 // loop of exporting. A pointer to this class is also passed to the
49 // various specific export implementations.
51 class Export : public String_dump
54 // The Stream class is an interface used to output the exported
55 // information. The caller should instantiate a child of this
63 // Write a string. Implements the String_dump interface.
65 write_string(const std::string& s)
66 { this->write_and_sum_bytes(s.data(), s.length()); }
68 // Write a nul terminated string. Implements the String_dump interface.
70 write_c_string(const char* s)
71 { this->write_and_sum_bytes(s, strlen(s)); }
75 write_bytes(const char* bytes, size_t length)
76 { this->write_and_sum_bytes(bytes, length); }
78 // Return the raw bytes of the checksum data.
82 // Write a checksum string to the stream. This will be called at
83 // the end of the other output.
85 write_checksum(const std::string&);
88 // This function is called with data to export. This data must be
89 // made available as a contiguous stream for the importer.
91 do_write(const char* bytes, size_t length) = 0;
95 write_and_sum_bytes(const char*, size_t);
103 // The magic code for version 1 export data.
104 static const int v1_magic_len = 4;
105 static const char v1_magic[v1_magic_len];
107 // The length of the v1 checksum string.
108 static const int v1_checksum_len = 20;
110 // Register the builtin types.
112 register_builtin_types(Gogo*);
114 // Export the identifiers in BINDINGS which are marked for export.
115 // The exporting is done via a series of calls to THIS->STREAM_. If
116 // is nothing to export, this->stream_->write will not be called.
117 // UNIQUE_PREFIX is a prefix for all global symbols.
118 // PACKAGE_PRIORITY is the priority to use for this package.
119 // IMPORT_INIT_FN is the name of the import initialization function
120 // for this package; it will be empty if none is needed.
121 // IMPORTED_INIT_FNS is the list of initialization functions for
122 // imported packages.
124 export_globals(const std::string& package_name,
125 const std::string& unique_prefix,
126 int package_priority,
127 const std::string& import_init_fn,
128 const std::set<Import_init>& imported_init_fns,
129 const Bindings* bindings);
131 // Write a string to the export stream.
133 write_string(const std::string& s)
134 { this->stream_->write_string(s); }
136 // Write a nul terminated string to the export stream.
138 write_c_string(const char* s)
139 { this->stream_->write_c_string(s); }
141 // Write some bytes to the export stream.
143 write_bytes(const char* bytes, size_t length)
144 { this->stream_->write_bytes(bytes, length); }
146 // Write out a type. This handles references back to previous
149 write_type(const Type*);
152 Export(const Export&);
153 Export& operator=(const Export&);
155 // Write out the imported initialization functions.
157 write_imported_init_fns(const std::string& package_name, int priority,
158 const std::string&, const std::set<Import_init>&);
160 // Register one builtin type.
162 register_builtin_type(Gogo*, const char* name, Builtin_code);
164 // Mapping from Type objects to a constant index.
165 typedef Unordered_map(const Type*, int) Type_refs;
167 // The stream to which we are writing data.
170 Type_refs type_refs_;
171 // Index number of next type.
175 // An export streamer which puts the export stream in a named section.
177 class Stream_to_section : public Export::Stream
184 do_write(const char*, size_t);
187 #endif // !defined(GO_EXPORT_H)