Skip to content

Commit

Permalink
Clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
JosseVanDelm committed Nov 25, 2024
1 parent 171c42d commit ba027aa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
41 changes: 24 additions & 17 deletions target/common/test/tb_bin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@
// SPDX-License-Identifier: SHL-0.51

#include <printf.h>
#include <cstring>
#include <iostream>
#include <vector>
#include <cstring>

#include "sim.hh"

// Declare these as global variables
bool WRAPPER_disable_tracing = false;
char* WRAPPER_trace_prefix = nullptr;
char *WRAPPER_trace_prefix = nullptr;

void print_usage(const char *prog_name) {
std::cout << "Usage: " << prog_name << " [SNAX WRAPPER Options] [HTIF Options]\n"
std::cout << "Usage: " << prog_name
<< " [SNAX WRAPPER Options] [HTIF Options]\n"
<< " Wrap Rocket Chip Emulator in SNAX RTL Simulator\n\n"
<< "SNAX WRAPPER Options:\n"
<< " --disable-tracing Disable Snitch tracing\n"
<< " --prefix-trace=PREFIX Set trace prefix (cannot be used with --disable-tracing)\n\n";
<< " --prefix-trace=PREFIX Set trace prefix (cannot be used "
"with --disable-tracing)\n\n";
}

int main(int argc, char **argv, char **env) {
Expand All @@ -37,36 +39,41 @@ int main(int argc, char **argv, char **env) {
if (strcmp(argv[i], "--disable-tracing") == 0) {
WRAPPER_disable_tracing = true;
} else if (strncmp(argv[i], "--prefix-trace=", 15) == 0) {
WRAPPER_trace_prefix = argv[i] + 15; // Extract the value after `--prefix-trace=`
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
WRAPPER_trace_prefix =
argv[i] + 15; // Extract the value after `--prefix-trace=`
} else if (strcmp(argv[i], "-h") == 0 ||
strcmp(argv[i], "--help") == 0) {
print_usage(argv[0]);
// Also show help from underlying fesvr function
// Note:
// If a binary is supplied, it will show both the snax wrapper help,
// AND continue with the execution of the program...
auto sim = std::make_unique<sim::Sim>(argc, argv);
return sim->run();
// Also show help from underlying fesvr function
// Note:
// If a binary is supplied, it will show both the snax wrapper help,
// AND continue with the execution of the program...
auto sim = std::make_unique<sim::Sim>(argc, argv);
return sim->run();
return -1;
}
}
// Validate conflicting options
if (WRAPPER_disable_tracing && WRAPPER_trace_prefix != nullptr) {
std::cerr << "Error: --disable-tracing and --prefix-trace cannot be used together.\n";
return 1; // Indicate an error
std::cerr << "Error: --disable-tracing and --prefix-trace cannot be "
"used together.\n";
return 1;
}
// Prepare filtered arguments
std::vector<char *> filtered_argv;
for (int i = 0; i < argc; ++i) {
// Skip custom options
if (strcmp(argv[i], "--disable-tracing") == 0 || strncmp(argv[i], "--prefix-trace=", 15) == 0) {
if (strcmp(argv[i], "--disable-tracing") == 0 ||
strncmp(argv[i], "--prefix-trace=", 15) == 0) {
continue;
}
filtered_argv.push_back(argv[i]);
}
filtered_argv.push_back(nullptr); // Null-terminate for compatibility
filtered_argv.push_back(nullptr); // Null-terminate for compatibility

// Pass the filtered arguments to fesvr argument handling
int filtered_argc = static_cast<int>(filtered_argv.size()) - 1; // Exclude null terminator
int filtered_argc =
static_cast<int>(filtered_argv.size()) - 1; // Exclude null terminator
char **filtered_argv_ptr = filtered_argv.data();
auto sim = std::make_unique<sim::Sim>(filtered_argc, filtered_argv_ptr);
return sim->run();
Expand Down
10 changes: 5 additions & 5 deletions target/common/test/verilator_lib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// SPDX-License-Identifier: SHL-0.51

#include <printf.h>
#include <string>
#include <filesystem>
#include <string>

#include "Vtestharness.h"
#include "Vtestharness__Dpi.h"
Expand All @@ -15,7 +15,7 @@

// Declare these as globally declared (and parsed) in tb_bin.cc
extern bool WRAPPER_disable_tracing;
extern char* WRAPPER_trace_prefix;
extern char *WRAPPER_trace_prefix;

namespace sim {

Expand Down Expand Up @@ -118,9 +118,9 @@ svBit disable_tracing() {
return WRAPPER_disable_tracing;
}

const char* get_trace_file_prefix() {
if (WRAPPER_trace_prefix == nullptr){
// Use the standard prefix, and create a logs directory if necessary
const char *get_trace_file_prefix() {
if (WRAPPER_trace_prefix == nullptr) {
// Use the standard prefix, and create a logs directory if necessary
std::string foldername = "logs/";
std::filesystem::create_directories(foldername);
static std::string log_file_name = "logs/";
Expand Down

0 comments on commit ba027aa

Please sign in to comment.