ruby: remove Ruby asserts for m5.fast
authorBrad Beckmann <Brad.Beckmann@amd.com>
Wed, 8 Dec 2010 19:52:02 +0000 (11:52 -0800)
committerBrad Beckmann <Brad.Beckmann@amd.com>
Wed, 8 Dec 2010 19:52:02 +0000 (11:52 -0800)
This diff is for changing the way ASSERT is handled in Ruby. m5.fast
compiles out the assert statements by using the macro NDEBUG. Ruby uses the
macro RUBY_NO_ASSERT to do so. This macro has been removed and NDEBUG has
been put in its place.

src/mem/ruby/common/Debug.hh
src/mem/slicc/ast/FuncCallExprAST.py

index 7005d95f7d6f298ef1642a81a830169eb66aec10..8a2b75de32a291ba8badbf1e8b46a79dffeb208d 100644 (file)
@@ -122,60 +122,45 @@ operator<<(std::ostream& out, const Debug& obj)
 const bool ERROR_MESSAGE_FLAG = true;
 const bool WARNING_MESSAGE_FLAG = true;
 
-#ifdef RUBY_NO_ASSERT
-const bool ASSERT_FLAG = false;
-#else
-const bool ASSERT_FLAG = true;
-#endif
-
 #undef assert
 #define assert(EXPR) ASSERT(EXPR)
 #undef ASSERT
-#define ASSERT(EXPR) do {                                               \
-    using namespace std;                                                \
-    if (ASSERT_FLAG) {                                                  \
-        if (!(EXPR)) {                                                  \
-            cerr << "failed assertion '"                                \
-                 << #EXPR << "' at fn "                                 \
-                 << __PRETTY_FUNCTION__ << " in "                       \
-                 << __FILE__ << ":"                                     \
-                 << __LINE__ << endl << flush;                          \
-            (*debug_cout_ptr) << "failed assertion '"                   \
-                               << #EXPR << "' at fn "                   \
-                               << __PRETTY_FUNCTION__ << " in "         \
-                               << __FILE__ << ":"                       \
-                               << __LINE__ << endl << flush;            \
-            if (isatty(STDIN_FILENO)) {                                 \
-                cerr << "At this point you might want to attach a debug to " \
-                     << "the running and get to the" << endl            \
-                     << "crash site; otherwise press enter to continue" \
-                     << endl                                            \
-                     << "PID: " << getpid()                             \
-                     << endl << flush;                                  \
-                char c;                                                 \
-                cin.get(c);                                             \
-            }                                                           \
-            abort();                                                    \
-        }                                                               \
-    }                                                                   \
-} while (0)
 
-#define BREAK(X) do {                                   \
-    using namespace std;                                \
-    cerr << "breakpoint '"                              \
-         << #X << "' reached at fn "                    \
-         << __PRETTY_FUNCTION__ << " in "               \
-         << __FILE__ << ":"                             \
-         << __LINE__ << endl << flush;                  \
-    if(isatty(STDIN_FILENO)) {                          \
-        cerr << "press enter to continue" << endl;      \
-        cerr << "PID: " << getpid();                    \
-        cerr << endl << flush;                          \
-        char c;                                         \
-        cin.get(c);                                     \
-    }                                                   \
+#ifndef NDEBUG
+
+#define ASSERT(EXPR) do {                                           \
+    using namespace std;                                            \
+    if (!(EXPR)) {                                                  \
+        cerr << "failed assertion '"                                \
+             << #EXPR << "' at fn "                                 \
+             << __PRETTY_FUNCTION__ << " in "                       \
+             << __FILE__ << ":"                                     \
+             << __LINE__ << endl << flush;                          \
+        (*debug_cout_ptr) << "failed assertion '"                   \
+                          << #EXPR << "' at fn "                    \
+                          << __PRETTY_FUNCTION__ << " in "          \
+                          << __FILE__ << ":"                        \
+                          << __LINE__ << endl << flush;             \
+        if (isatty(STDIN_FILENO)) {                                 \
+            cerr << "At this point you might want to attach a debug to " \
+                 << "the running and get to the" << endl            \
+                 << "crash site; otherwise press enter to continue" \
+                 << endl                                            \
+                 << "PID: " << getpid()                             \
+                 << endl << flush;                                  \
+            char c;                                                 \
+            cin.get(c);                                             \
+        }                                                           \
+        abort();                                                    \
+    }                                                               \
 } while (0)
 
+#else
+
+#define ASSERT(EXPR) do {} while (0)
+
+#endif // NDEBUG
+
 #define ERROR_MSG(MESSAGE) do {                                 \
     using namespace std;                                        \
     if (ERROR_MESSAGE_FLAG) {                                   \
index 830b10c211c6272f50fadb78b6c419f80d000261..829203d53420a9561b330ba98c06b4c1fee2e0ad 100644 (file)
@@ -165,9 +165,11 @@ class FuncCallExprAST(ExprAST):
         elif self.proc_name == "assert":
             error = self.exprs[0].embedError('"assert failure"')
             code('''
-if (ASSERT_FLAG && !(${{cvec[0]}})) {
+#ifndef NDEBUG
+if (!(${{cvec[0]}})) {
     $error
 }
+#endif
 ''')
 
         elif self.proc_name == "continueProcessing":