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,
38 BUILTIN_COMPLEX64 = -17,
39 BUILTIN_COMPLEX128 = -18,
41 SMALLEST_BUILTIN_CODE = -18
44 // This class manages exporting Go declarations. It handles the main
45 // loop of exporting. A pointer to this class is also passed to the
46 // various specific export implementations.
51 // The Stream class is an interface used to output the exported
52 // information. The caller should instantiate a child of this
62 write_string(const std::string& s)
63 { this->write_and_sum_bytes(s.data(), s.length()); }
65 // Write a nul terminated string.
67 write_c_string(const char* s)
68 { this->write_and_sum_bytes(s, strlen(s)); }
72 write_bytes(const char* bytes, size_t length)
73 { this->write_and_sum_bytes(bytes, length); }
75 // Return the raw bytes of the checksum data.
79 // Write a checksum string to the stream. This will be called at
80 // the end of the other output.
82 write_checksum(const std::string&);
85 // This function is called with data to export. This data must be
86 // made available as a contiguous stream for the importer.
88 do_write(const char* bytes, size_t length) = 0;
92 write_and_sum_bytes(const char*, size_t);
100 // The magic code for version 1 export data.
101 static const int v1_magic_len = 4;
102 static const char v1_magic[v1_magic_len];
104 // The length of the v1 checksum string.
105 static const int v1_checksum_len = 20;
107 // Register the builtin types.
109 register_builtin_types(Gogo*);
111 // Export the identifiers in BINDINGS which are marked for export.
112 // The exporting is done via a series of calls to THIS->STREAM_. If
113 // is nothing to export, this->stream_->write will not be called.
114 // UNIQUE_PREFIX is a prefix for all global symbols.
115 // PACKAGE_PRIORITY is the priority to use for this package.
116 // IMPORT_INIT_FN is the name of the import initialization function
117 // for this package; it will be empty if none is needed.
118 // IMPORTED_INIT_FNS is the list of initialization functions for
119 // imported packages.
121 export_globals(const std::string& package_name,
122 const std::string& unique_prefix,
123 int package_priority,
124 const std::string& import_init_fn,
125 const std::set<Import_init>& imported_init_fns,
126 const Bindings* bindings);
128 // Write a string to the export stream.
130 write_string(const std::string& s)
131 { this->stream_->write_string(s); }
133 // Write a nul terminated string to the export stream.
135 write_c_string(const char* s)
136 { this->stream_->write_c_string(s); }
138 // Write some bytes to the export stream.
140 write_bytes(const char* bytes, size_t length)
141 { this->stream_->write_bytes(bytes, length); }
143 // Write out a type. This handles references back to previous
146 write_type(const Type*);
149 Export(const Export&);
150 Export& operator=(const Export&);
152 // Write out the imported initialization functions.
154 write_imported_init_fns(const std::string& package_name, int priority,
155 const std::string&, const std::set<Import_init>&);
157 // Register one builtin type.
159 register_builtin_type(Gogo*, const char* name, Builtin_code);
161 // Mapping from Type objects to a constant index.
162 typedef Unordered_map(const Type*, int) Type_refs;
164 // The stream to which we are writing data.
167 Type_refs type_refs_;
168 // Index number of next type.
172 // An export streamer which puts the export stream in a named section.
174 class Stream_to_section : public Export::Stream
181 do_write(const char*, size_t);
184 #endif // !defined(GO_EXPORT_H)