From c93d28050e98c61bbf3fe81bd4cb24884fb4028a Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 27 Aug 2018 18:07:52 -0400 Subject: [PATCH] Fix mkdir on MSYS2, msg2614. --- examples/tracing_c/sim_main.cpp | 6 ++---- examples/tracing_sc/sc_main.cpp | 4 ++-- include/verilated.cpp | 13 +++++++++++++ include/verilated.h | 3 +++ include/verilated_threads.h | 2 +- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/examples/tracing_c/sim_main.cpp b/examples/tracing_c/sim_main.cpp index c1b86e2c2..36ba2e958 100644 --- a/examples/tracing_c/sim_main.cpp +++ b/examples/tracing_c/sim_main.cpp @@ -7,8 +7,6 @@ // Include common routines #include -#include // mkdir - // Include model header, generated from Verilating "top.v" #include "Vtop.h" @@ -51,7 +49,7 @@ int main(int argc, char** argv, char** env) { VL_PRINTF("Enabling waves into logs/vlt_dump.vcd...\n"); tfp = new VerilatedVcdC; top->trace(tfp, 99); // Trace 99 levels of hierarchy - mkdir("logs", 0777); + Verilated::mkdir("logs"); tfp->open("logs/vlt_dump.vcd"); // Open the dump file } #endif @@ -112,7 +110,7 @@ int main(int argc, char** argv, char** env) { // Coverage analysis (since test passed) #if VM_COVERAGE - mkdir("logs", 0777); + Verilated::mkdir("logs"); VerilatedCov::write("logs/coverage.dat"); #endif diff --git a/examples/tracing_sc/sc_main.cpp b/examples/tracing_sc/sc_main.cpp index ddd230445..676c3ec13 100644 --- a/examples/tracing_sc/sc_main.cpp +++ b/examples/tracing_sc/sc_main.cpp @@ -96,7 +96,7 @@ int sc_main(int argc, char* argv[]) { cout << "Enabling waves into logs/vlt_dump.vcd...\n"; tfp = new VerilatedVcdSc; top->trace(tfp, 99); - mkdir("logs", 0777); + Verilated::mkdir("logs"); tfp->open("logs/vlt_dump.vcd"); } #endif @@ -134,7 +134,7 @@ int sc_main(int argc, char* argv[]) { // Coverage analysis (since test passed) #if VM_COVERAGE - mkdir("logs", 0777); + Verilated::mkdir("logs"); VerilatedCov::write("logs/coverage.dat"); #endif diff --git a/include/verilated.cpp b/include/verilated.cpp index 2b9131257..b010c215a 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -26,6 +26,11 @@ #define _VERILATED_CPP_ #include "verilated_imp.h" #include +#include // mkdir + +#if defined(WIN32) || defined(__MINGW32__) +# include // mkdir +#endif #define VL_VALUE_STRING_MAX_WIDTH 8192 ///< Max static char array for VL_VALUE_STRING @@ -1741,6 +1746,14 @@ void Verilated::overWidthError(const char* signame) VL_MT_SAFE { VL_FATAL_MT("unknown",0,"", msg.c_str()); } +void Verilated::mkdir(const char* dirname) VL_MT_UNSAFE { +#if defined(_WIN32) || defined(__MINGW32__) + ::mkdir(dirname); +#else + ::mkdir(dirname, 0777); +#endif +} + void Verilated::quiesce() VL_MT_SAFE { #ifdef VL_THREADED // Wait until all threads under this evaluation are quiet diff --git a/include/verilated.h b/include/verilated.h index a9978f285..66ae9ce7d 100644 --- a/include/verilated.h +++ b/include/verilated.h @@ -445,6 +445,9 @@ public: static const char* productName() VL_PURE { return VERILATOR_PRODUCT; } static const char* productVersion() VL_PURE { return VERILATOR_VERSION; } + /// Convenience OS utilities + static void mkdir(const char* dirname) VL_MT_UNSAFE; + /// When multithreaded, quiesce the model to prepare for trace/saves/coverage /// This may only be called when no locks are held. static void quiesce() VL_MT_SAFE; diff --git a/include/verilated_threads.h b/include/verilated_threads.h index efd6cf48b..2f34d296b 100644 --- a/include/verilated_threads.h +++ b/include/verilated_threads.h @@ -196,7 +196,7 @@ public: #if defined(__linux) return sched_getcpu(); #elif defined(__APPLE__) - uint32_t info[4]; + vluint32_t info[4]; __cpuid_count(1, 0, info[0], info[1], info[2], info[3]); /* info[1] is EBX, bits 24-31 are APIC ID */ if ((info[3] & (1 << 9)) == 0) {