MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / ReadBinaryFile

Function ReadBinaryFile

tools/io.cpp:352–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

350} // namespace
351
352bool ReadBinaryFile(const char* filename, std::vector<uint32_t>* data) {
353 assert(data->empty());
354
355 const bool use_file = filename && strcmp("-", filename);
356 FILE* fp = nullptr;
357 if (use_file) {
358 fp = fopen(filename, "rb");
359 } else {
360 SET_STDIN_TO_BINARY_MODE();
361 fp = stdin;
362 }
363
364 // Read into a char vector first. If this is a hex stream, it needs to be
365 // processed as such.
366 std::vector<char> data_raw;
367 ReadFile(fp, &data_raw);
368 bool succeeded = WasFileCorrectlyRead(fp, filename);
369 if (use_file && fp) fclose(fp);
370
371 if (!succeeded) {
372 return false;
373 }
374
375 if (IsHexStream(data_raw)) {
376 // If a hex stream, parse it and fill |data|.
377 HexTokenizer tokenizer(filename, data_raw, data);
378 succeeded = tokenizer.Parse();
379 } else {
380 // If not a hex stream, convert it to uint32_t via memcpy.
381 succeeded = WasFileSizeAligned(filename, data_raw.size(), sizeof(uint32_t));
382 if (succeeded) {
383 data->resize(data_raw.size() / sizeof(uint32_t), 0);
384 memcpy(data->data(), data_raw.data(), data_raw.size());
385 }
386 }
387
388 return succeeded;
389}
390
391bool ConvertHexToBinary(const std::vector<char>& stream,
392 std::vector<uint32_t>* data) {

Callers 11

mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
load_moduleFunction · 0.85
process_single_fileFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
FuzzFunction · 0.85
mainFunction · 0.85

Calls 9

ReadFileFunction · 0.85
WasFileCorrectlyReadFunction · 0.85
IsHexStreamFunction · 0.85
WasFileSizeAlignedFunction · 0.85
resizeMethod · 0.80
emptyMethod · 0.45
ParseMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected