From 046f5f2b2e7f99d2fb0d7b4d338e444e9b10ee03 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Tue, 29 Nov 2016 13:53:02 +0100 Subject: [PATCH] Catch exceptions and write out their message --- tools/drawergen/drawergen.cpp | 142 ++++++++++++++++++---------------- 1 file changed, 75 insertions(+), 67 deletions(-) diff --git a/tools/drawergen/drawergen.cpp b/tools/drawergen/drawergen.cpp index 068fb164fa..8896e3f7b3 100644 --- a/tools/drawergen/drawergen.cpp +++ b/tools/drawergen/drawergen.cpp @@ -633,78 +633,86 @@ void AddSourceFileTimestamp(const char *timestamp) int main(int argc, char **argv) { - if (argc != 2) + try { - std::cerr << "Usage: " << argv[0] << "" << std::endl; - return 1; - } - - std::string timestamp_filename = argv[1] + std::string(".timestamp"); - - FILE *file = fopen(timestamp_filename.c_str(), "rb"); - if (file != nullptr) - { - char buffer[4096]; - int bytes_read = fread(buffer, 1, 4096, file); - fclose(file); - std::string last_timestamp; - if (bytes_read > 0) - last_timestamp = std::string(buffer, bytes_read); - - if (AllTimestamps() == last_timestamp) + if (argc != 2) { - std::cout << "Not recompiling drawers because the object file is already up to date." << std::endl; - exit(0); + std::cerr << "Usage: " << argv[0] << "" << std::endl; + return 1; } + + std::string timestamp_filename = argv[1] + std::string(".timestamp"); + + FILE *file = fopen(timestamp_filename.c_str(), "rb"); + if (file != nullptr) + { + char buffer[4096]; + int bytes_read = fread(buffer, 1, 4096, file); + fclose(file); + std::string last_timestamp; + if (bytes_read > 0) + last_timestamp = std::string(buffer, bytes_read); + + if (AllTimestamps() == last_timestamp) + { + std::cout << "Not recompiling drawers because the object file is already up to date." << std::endl; + exit(0); + } + } + + llvm::install_fatal_error_handler([](void *user_data, const std::string& reason, bool gen_crash_diag) + { + std::cerr << "LLVM fatal error: " << reason; + exit(1); + }); + + llvm::InitializeNativeTarget(); + llvm::InitializeNativeTargetAsmPrinter(); + + std::string cpuName = "pentium4"; + std::cout << "Compiling drawer code for " << cpuName << ".." << std::endl; + + LLVMDrawers drawersSSE2(cpuName, "_SSE2"); + + file = fopen(argv[1], "wb"); + if (file == nullptr) + { + std::cerr << "Unable to open " << argv[1] << " for writing." << std::endl; + return 1; + } + + int result = fwrite(drawersSSE2.ObjectFile.data(), drawersSSE2.ObjectFile.size(), 1, file); + fclose(file); + + if (result != 1) + { + std::cerr << "Could not write data to " << argv[1] << std::endl; + return 1; + } + + file = fopen(timestamp_filename.c_str(), "wb"); + if (file == nullptr) + { + std::cerr << "Could not create timestamp file" << std::endl; + return 1; + } + result = fwrite(AllTimestamps().data(), AllTimestamps().length(), 1, file); + fclose(file); + if (result != 1) + { + std::cerr << "Could not write timestamp file" << std::endl; + return 1; + } + + //LLVMDrawers drawersSSE4("core2"); + //LLVMDrawers drawersAVX("sandybridge"); + //LLVMDrawers drawersAVX2("haswell"); + + return 0; } - - llvm::install_fatal_error_handler([](void *user_data, const std::string& reason, bool gen_crash_diag) + catch (const std::exception &e) { - std::cerr << "LLVM fatal error: " << reason; - exit(1); - }); - - llvm::InitializeNativeTarget(); - llvm::InitializeNativeTargetAsmPrinter(); - - std::string cpuName = "pentium4"; - std::cout << "Compiling drawer code for " << cpuName << ".." << std::endl; - - LLVMDrawers drawersSSE2(cpuName, "_SSE2"); - - file = fopen(argv[1], "wb"); - if (file == nullptr) - { - std::cerr << "Unable to open " << argv[1] << " for writing." << std::endl; + std::cerr << e.what() << std::endl; return 1; } - - int result = fwrite(drawersSSE2.ObjectFile.data(), drawersSSE2.ObjectFile.size(), 1, file); - fclose(file); - - if (result != 1) - { - std::cerr << "Could not write data to " << argv[1] << std::endl; - return 1; - } - - file = fopen(timestamp_filename.c_str(), "wb"); - if (file == nullptr) - { - std::cerr << "Could not create timestamp file" << std::endl; - return 1; - } - result = fwrite(AllTimestamps().data(), AllTimestamps().length(), 1, file); - fclose(file); - if (result != 1) - { - std::cerr << "Could not write timestamp file" << std::endl; - return 1; - } - - //LLVMDrawers drawersSSE4("core2"); - //LLVMDrawers drawersAVX("sandybridge"); - //LLVMDrawers drawersAVX2("haswell"); - - return 0; }