37 printf(
"%s\n", errorMsg);
65 template <
class T>
inline rstream &doRead(T &x) {
66 read((
char *)&x,
sizeof(T));
69 static pair<const char *, streamsize> getBuf(
const char *fileName) {
70 ifstream raw(fileName, ios::binary | ios::in);
72 stop(
"rstream.getBuf: Error opening file");
73 raw.seekg(0, ios::end);
74 streampos fileSize = raw.tellg();
76 stop(
"rstream.getBuf: Error reading file");
77 char *
buf =
new char[fileSize];
78 raw.seekg(0, ios::beg);
79 raw.read(
buf, fileSize);
80 return pair<const char *, streamsize>(
buf, fileSize);
103 map<string, unsigned> directory;
108 void makeDirectory(
void) {
111 string s = string(
data +
i);
112 directory.insert(make_pair(
s,
i));
117 void init(
const char *_data) {
118 unsigned _length = *(
unsigned *)_data;
120 if (_length <
sizeof(
unsigned) || _length != *(
unsigned *)_data)
121 stop(
"StringTable.init: Invalid symbol table");
122 if (_data[_length - 1]) {
131 length -
sizeof(
unsigned));
144 if (strSize <
sizeof(
unsigned))
145 stop(
"StringTable: Invalid string table");
146 strData =
new char[strSize];
147 *(
unsigned *)strData = strSize;
149 f.read(strData +
sizeof(
unsigned), strSize -
sizeof(unsigned));
152 stop(
"StringTable: Unexpected EOF");
159 set<string>::const_iterator it;
163 for (
length =
sizeof(
unsigned), it = strings.begin(); it != strings.end();
165 size_t l = (*it).size();
167 if (l > (
unsigned)0xFFFFFFFF)
168 stop(
"StringTable: String too long");
171 if (
length > (
unsigned)0xFFFFFFFF)
172 stop(
"StringTable: Symbol table too long");
178 for (
p =
data +
sizeof(
unsigned), it = strings.begin(); it != strings.end();
180 const string &str = *it;
181 size_t l = str.size();
183 directory.insert(make_pair(str,
p -
data));
197 if (str.size() <= 8) {
204 map<string, unsigned>::const_iterator it = directory.find(str);
205 if (it == directory.end())
206 stop(
"StringTable::encode: String now found in string table");
207 ((
unsigned *)&
r)[0] = 0;
208 ((
unsigned *)&
r)[1] = (*it).second;
215 if (*(
unsigned *)&x == 0) {
217 unsigned &
p = ((
unsigned *)&x)[1];
219 stop(
"StringTable::decode: Invalid string table lookup");
220 return string(
data +
p);
223 char *
p = (
char *)&x;
226 for (
i = 0;
i < 8 &&
p[
i]; ++
i)
238 set<string> *undefined) {
241 unsigned symTabStart, symNEntries;
244 f.seekg(0, ios::end);
245 fileSize =
f.tellg();
248 f >> symTabStart >> symNEntries;
250 f.seekg(strTabStart = symTabStart + 18 * (
size_t)symNEntries);
252 printf(
"computeExternalSymbols: fileName='%s', fileSize = %lu, symTabStart "
253 "= %u, symNEntries = %u\n",
254 fileName, (
unsigned long)fileSize, symTabStart, symNEntries);
255 stop(
"computeExternalSymbols: Unexpected EOF 1");
258 if (
f.tellg() != fileSize)
259 stop(
"computeExternalSymbols: Unexpected data after string table");
262 f.seekg(symTabStart);
266 for (
int i = 0;
i < symNEntries; ++
i) {
271 stop(
"computeExternalSymbols: Unexpected EOF 2");
274 stop(
"computeExternalSymbols: File read error");
276 f.seekg(e.
nAux * 18, ios::cur);
284 undefined->insert(stringTable.
decode(e.
name));
292 static const string prefix(
"__kmp_external_");
296 unsigned symTabStart, symNEntries;
300 in.seekg(0, ios::end);
301 fileSize = in.tellg();
304 in >> symTabStart >> symNEntries;
305 in.seekg(strTabStart = symTabStart + 18 * (
size_t)symNEntries);
307 stop(
"hideSymbols: Unexpected EOF");
310 if (in.tellg() != fileSize)
311 stop(
"hideSymbols: Unexpected data after string table");
314 for (
i = 0;
i < symNEntries; ++
i) {
317 in.seekg(symTabStart +
i * 18);
319 stop(
"hideSymbols: Unexpected EOF");
322 stop(
"hideSymbols: File read error");
332 ofstream out(fileName, ios::trunc | ios::out | ios::binary);
334 stop(
"hideSymbols: Error opening output file");
341 char *
buf =
new char[symTabStart];
342 in.read(
buf, symTabStart);
343 out.write(
buf, symTabStart);
347 for (
i = 0;
i < symNEntries; ++
i) {
350 in.seekg(symTabStart +
i * 18);
352 stop(
"hideSymbols: Unexpected EOF");
355 stop(
"hideSymbols: File read error");
357 out.seekp(symTabStart +
i * 18);
360 out.write((
char *)&e, 18);
362 stop(
"hideSymbols: File write error");
366 for (
int j = 1;
j <= nAux; ++
j) {
368 out.seekp(symTabStart + (
i +
j) * 18);
369 out.write((
char *)&e, 18);
375 stringTableNew.
write(out);
380 set<T>::const_iterator ita, itb;
382 for (ita =
a.begin(), itb =
b.begin(); ita !=
a.end() && itb !=
b.end();) {
383 const T &ta = *ita, &tb = *itb;
402 set<string> *undefined) {
403 set<int> *required =
new set<int>;
408 for (
i = nTotal - 1;
i >= nExternal; --
i)
409 fresh[cur].insert(
i);
412 for (set<int>::iterator it = fresh[cur].
begin(); it != fresh[cur].end();
414 set<string> &
s = undefined[*it];
416 for (
i = 0;
i < nExternal; ++
i) {
417 if (required->find(
i) == required->end()) {
421 fresh[1 - cur].insert(
i);
433int main(
int argc,
char **argv) {
434 int nExternal, nInternal,
i;
435 set<string> *defined, *undefined;
436 set<int>::iterator it;
439 stop(
"Please specify a positive integer followed by a list of object "
441 nExternal = atoi(argv[1]);
443 stop(
"Please specify a positive integer followed by a list of object "
445 if (nExternal + 2 > argc)
446 stop(
"Too few external objects");
447 nInternal = argc - nExternal - 2;
448 defined =
new set<string>[argc - 2];
449 undefined =
new set<string>[argc - 2];
452 for (
i = 2;
i < argc; ++
i)
456 set<int> *requiredExternal =
462 for (it = requiredExternal->begin(); it != requiredExternal->end(); ++it) {
464 set<string>::iterator it2;
468 for (it2 = defined[idx].
begin(); it2 != defined[idx].end(); ++it2)
474 for (
i = 0;
i < nExternal; ++
i)
475 if (requiredExternal->find(
i) != requiredExternal->end())
480 for (
i = nExternal + 2;
i < argc; ++
i)
StringTable(const set< string > &strings)
__int64 encode(const string &str)
string decode(__int64 x) const
unsigned short sectionNum
_rstream(pair< const char *, streamsize > p)
rstream & operator>>(Symbol &e)
rstream(const char *fileName)
rstream & operator>>(unsigned &x)
rstream(const char *buf, streamsize size)
rstream & operator>>(unsigned short &x)
rstream & operator>>(int &x)
rstream & operator>>(short &x)
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type size_t void * data
void const char const char int ITT_FORMAT __itt_group_sync s
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp begin
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t length
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t size
void const char const char int ITT_FORMAT __itt_group_sync p
#define KMP_STRNCPY_S(dst, bsz, src, cnt)