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.
16 // Codes used for the builtin types. These are all negative to make
17 // them easily distinct from the codes assigned by Export::write_type.
18 // Note that these codes may not be changed! Changing them would
19 // break existing export data.
32 BUILTIN_FLOAT64 = -10,
35 BUILTIN_UINTPTR = -13,
39 BUILTIN_COMPLEX64 = -17,
40 BUILTIN_COMPLEX128 = -18,
41 BUILTIN_COMPLEX = -19,
43 SMALLEST_BUILTIN_CODE = -19
46 // This class manages exporting Go declarations. It handles the main
47 // loop of exporting. A pointer to this class is also passed to the
48 // various specific export implementations.
53 // The Stream class is an interface used to output the exported
54 // information. The caller should instantiate a child of this
64 write_string(const std::string& s)
65 { this->write_and_sum_bytes(s.data(), s.length()); }
67 // Write a nul terminated string.
69 write_c_string(const char* s)
70 { this->write_and_sum_bytes(s, strlen(s)); }
74 write_bytes(const char* bytes, size_t length)
75 { this->write_and_sum_bytes(bytes, length); }
77 // Return the raw bytes of the checksum data.
81 // Write a checksum string to the stream. This will be called at
82 // the end of the other output.
84 write_checksum(const std::string&);
87 // This function is called with data to export. This data must be
88 // made available as a contiguous stream for the importer.
90 do_write(const char* bytes, size_t length) = 0;
94 write_and_sum_bytes(const char*, size_t);
102 // The magic code for version 1 export data.
103 static const int v1_magic_len = 4;
104 static const char v1_magic[v1_magic_len];
106 // The length of the v1 checksum string.
107 static const int v1_checksum_len = 20;
109 // Register the builtin types.
111 register_builtin_types(Gogo*);
113 // Export the identifiers in BINDINGS which are marked for export.
114 // The exporting is done via a series of calls to THIS->STREAM_. If
115 // is nothing to export, this->stream_->write will not be called.
116 // UNIQUE_PREFIX is a prefix for all global symbols.
117 // PACKAGE_PRIORITY is the priority to use for this package.
118 // IMPORT_INIT_FN is the name of the import initialization function
119 // for this package; it will be empty if none is needed.
120 // IMPORTED_INIT_FNS is the list of initialization functions for
121 // imported packages.
123 export_globals(const std::string& package_name,
124 const std::string& unique_prefix,
125 int package_priority,
126 const std::string& import_init_fn,
127 const std::set<Import_init>& imported_init_fns,
128 const Bindings* bindings);
130 // Write a string to the export stream.
132 write_string(const std::string& s)
133 { this->stream_->write_string(s); }
135 // Write a nul terminated string to the export stream.
137 write_c_string(const char* s)
138 { this->stream_->write_c_string(s); }
140 // Write some bytes to the export stream.
142 write_bytes(const char* bytes, size_t length)
143 { this->stream_->write_bytes(bytes, length); }
145 // Write out a type. This handles references back to previous
148 write_type(const Type*);
151 Export(const Export&);
152 Export& operator=(const Export&);
154 // Write out the imported initialization functions.
156 write_imported_init_fns(const std::string& package_name, int priority,
157 const std::string&, const std::set<Import_init>&);
159 // Register one builtin type.
161 register_builtin_type(Gogo*, const char* name, Builtin_code);
163 // Mapping from Type objects to a constant index.
164 typedef Unordered_map(const Type*, int) Type_refs;
166 // The stream to which we are writing data.
169 Type_refs type_refs_;
170 // Index number of next type.
174 // An export streamer which puts the export stream in a named section.
176 class Stream_to_section : public Export::Stream
183 do_write(const char*, size_t);
186 // The section we are writing to; this is really union section
187 // defined in output.h.
191 #endif // !defined(GO_EXPORT_H)