misc: Add panic_if / fatal_if / chatty_assert
Review Request #2164 - Created Feb. 21, 2014 and submitted
| Information | |
|---|---|
| Andreas Hansson | |
| gem5 | |
| default | |
| Reviewers | |
| Default | |
Changeset 10104:4d3c10cadce3
---------------------------
misc: Add panic_if / fatal_if / chatty_assert
This snippet can be used to replace if + {panics, fatals, asserts} constructs.
The idea is to have both the condition checking and a verbose printout in a single statement. The interface is as follows:
panic_if(foo != bar, "These should be equal: foo %i bar %i", foo, bar);
fatal_if(foo != bar, "These should be equal: foo %i bar %i", foo, bar);
chatty_assert(foo == bar, "These should be equal: foo %i bar %i", foo, bar);
All regressions pass (as it does not affect existing code).
Is the idea here to have something like assert() that does not get compiled out in gem5.fast? Or is it to have a flavor of assert that allows you to have more expressive error message? Both seem like reasonable goals, just wondering which this is intended to address.
I like the idea. Could you generalize this and add a fatal_if? There are plenty of places where we do something like "if (param > foo) fatal(...);" Also, please add Doxygen documentation to the macros.
I like the idea. Could you generalize this and add a fatal_if? There are plenty of places where we do something like "if (param > foo) fatal(...);" Also, please add Doxygen documentation to the macros.
Summary: |
|
|||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description: |
|
|||||||||||||||||||||||||||||||||||||||
Diff: |
Revision 2 (+42) |
It's not strictly a replacement for assert, since asserts get compiled out in gem5.fast. Do we need an assert_if() as well? That would certainly be more complete...
Summary: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Diff: |
Revision 3 (+63) |
Too bad "assert_if" doesn't actually make sense, as it would be a nice parallel. Can't say I really like the name "chatty_assert", but I don't have a better alternative. I'll encourage others to suggest some though. If we can't come up with something, though, I'm fine with this as it is. Thanks for all the iterations!
