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

Function OutputSourceFiles

tools/objdump/objdump.cpp:61–97  ·  view source on GitHub ↗

Write each HLSL file described in `sources` in a file in `outdirPath`. Doesn't ovewrite existing files, unless `overwrite` is set to true. The created HLSL file's filename is the path's filename obtained from `sources`. Returns true if all files could be written. False otherwise.

Source from the content-addressed store, hash-verified

59// created HLSL file's filename is the path's filename obtained from `sources`.
60// Returns true if all files could be written. False otherwise.
61bool OutputSourceFiles(
62 const std::unordered_map<std::string, std::string>& sources,
63 const std::string& outdirPath, bool overwrite) {
64 std::filesystem::path outdir(fixPathForLLVM(outdirPath));
65 if (!std::filesystem::is_directory(outdir)) {
66 if (!std::filesystem::create_directories(outdir)) {
67 std::cerr << "error: could not create output directory " << outdir
68 << std::endl;
69 return false;
70 }
71 }
72
73 for (const auto & [ filepath, code ] : sources) {
74 if (code.empty()) {
75 std::cout << "Ignoring source for " << filepath
76 << ": no code source in debug infos." << std::endl;
77 continue;
78 }
79
80 std::filesystem::path old_path(filepath);
81 std::filesystem::path new_path = outdir / old_path.filename();
82
83 if (!overwrite && std::filesystem::exists(new_path)) {
84 std::cerr << "file " << filepath
85 << " already exists, aborting (use --overwrite to allow it)."
86 << std::endl;
87 return false;
88 }
89
90 std::cout << "Exporting " << new_path << std::endl;
91 if (!WriteFile<char>(new_path.string().c_str(), "w", code.c_str(),
92 code.size())) {
93 return false;
94 }
95 }
96 return true;
97}
98
99} // namespace
100

Callers 1

mainFunction · 0.85

Calls 5

fixPathForLLVMFunction · 0.85
c_strMethod · 0.80
stringMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected