Skip to content

Commit

Permalink
Add custom assertion routine
Browse files Browse the repository at this point in the history
  • Loading branch information
sgizler committed Oct 10, 2024
1 parent bab424d commit 092b203
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
std::string tryDemangle(const char* mangled) {
int rc;
char* out = abi::__cxa_demangle(mangled, NULL, NULL, &rc);
assert(rc == 0 && "demangling failed");
ASSERT(rc == 0, "demangling failed");
std::string outStr = out;
free(out);
return outStr;
Expand Down
14 changes: 14 additions & 0 deletions source/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,17 @@ std::string prefixLines(const std::string& str, const std::string& linePrefix);
fprintf(stderr, "sv-bugpoint: "); \
fprintf(stderr, __VA_ARGS__); \
} while (0)

#define PRINTF_INTERNAL_ERR(...) \
do { \
PRINTF_ERR("Internal error: %s:%d: ", __FILE__, __LINE__); \
fprintf(stderr, __VA_ARGS__); \
} while (0)

#define ASSERT(cond, msg) \
do { \
if (!(cond)) { \
PRINTF_INTERNAL_ERR("Assertion `%s` failed: %s\n", #cond, msg); \
exit(1); \
} \
} while (0)

0 comments on commit 092b203

Please sign in to comment.