aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/Core
diff options
context:
space:
mode:
authorMartin Nowack <martin.nowack@gmail.com>2015-08-10 08:59:00 +0200
committerDan Liew <daniel.liew@imperial.ac.uk>2015-12-17 19:30:14 +0000
commit771cdf39d9c1e142269e2cafc4365d0d68e05f9a (patch)
treee4d0c7a9eb9a5aee2ed350d77625aec89cc05ed5 /lib/Core
parentd8f9c929f69cdfb739f03b6512035071c02108c9 (diff)
downloadklee-771cdf39d9c1e142269e2cafc4365d0d68e05f9a.tar.gz
Refactoring: Moving klee_warning/_error functions to ErrorHandling in Support directory
Diffstat (limited to 'lib/Core')
-rw-r--r--lib/Core/Common.cpp168
-rw-r--r--lib/Core/Common.h56
-rw-r--r--lib/Core/Executor.cpp2
-rw-r--r--lib/Core/ExecutorTimers.cpp3
-rw-r--r--lib/Core/Memory.cpp3
-rw-r--r--lib/Core/MemoryManager.cpp3
-rw-r--r--lib/Core/Searcher.cpp3
-rw-r--r--lib/Core/SeedInfo.cpp3
-rw-r--r--lib/Core/SpecialFunctionHandler.cpp3
-rw-r--r--lib/Core/StatsTracker.cpp3
-rw-r--r--lib/Core/UserSearcher.cpp3
11 files changed, 9 insertions, 241 deletions
diff --git a/lib/Core/Common.cpp b/lib/Core/Common.cpp
deleted file mode 100644
index c58e121a..00000000
--- a/lib/Core/Common.cpp
+++ /dev/null
@@ -1,168 +0,0 @@
-//===-- Common.cpp --------------------------------------------------------===//
-//
-// The KLEE Symbolic Virtual Machine
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "Common.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/raw_ostream.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <assert.h>
-#include <string.h>
-
-#include <set>
-
-using namespace klee;
-
-FILE* klee::klee_warning_file = NULL;
-FILE* klee::klee_message_file = NULL;
-
-static const char* warningPrefix = "WARNING";
-static const char* warningOncePrefix = "WARNING ONCE";
-static const char* errorPrefix = "ERROR";
-static const char* notePrefix = "NOTE";
-
-static bool shouldSetColor(const char* pfx, const char* msg, const char* prefixToSearchFor)
-{
- if (pfx && strcmp(pfx, prefixToSearchFor) == 0)
- return true;
-
- if (llvm::StringRef(msg).startswith(prefixToSearchFor))
- return true;
-
- return false;
-}
-
-static void klee_vfmessage(FILE *fp, const char *pfx, const char *msg,
- va_list ap) {
- if (!fp)
- return;
-
- llvm::raw_fd_ostream fdos(fileno(fp), /*shouldClose=*/false, /*unbuffered=*/ true);
- bool modifyConsoleColor = fdos.is_displayed() && (fp == stderr);
-
- if (modifyConsoleColor) {
-
- // Warnings
- if (shouldSetColor(pfx, msg, warningPrefix))
- fdos.changeColor(llvm::raw_ostream::MAGENTA,
- /*bold=*/ false,
- /*bg=*/ false);
-
- // Once warning
- if (shouldSetColor(pfx, msg, warningOncePrefix))
- fdos.changeColor(llvm::raw_ostream::MAGENTA,
- /*bold=*/ true,
- /*bg=*/ false);
-
- // Errors
- if (shouldSetColor(pfx, msg, errorPrefix))
- fdos.changeColor(llvm::raw_ostream::RED,
- /*bold=*/ true,
- /*bg=*/ false);
-
- // Notes
- if (shouldSetColor(pfx, msg, notePrefix))
- fdos.changeColor(llvm::raw_ostream::WHITE,
- /*bold=*/ true,
- /*bg=*/ false);
-
- }
-
- fdos << "KLEE: ";
- if (pfx) fdos << pfx << ": ";
-
- // FIXME: Can't use fdos here because we need to print
- // a variable number of arguments and do substitution
- vfprintf(fp, msg, ap);
- fflush(fp);
-
- fdos << "\n";
-
- if (modifyConsoleColor)
- fdos.resetColor();
-
- fdos.flush();
-}
-
-/* Prints a message/warning.
-
- If pfx is NULL, this is a regular message, and it's sent to
- klee_message_file (messages.txt). Otherwise, it is sent to
- klee_warning_file (warnings.txt).
-
- Iff onlyToFile is false, the message is also printed on stderr.
-*/
-static void klee_vmessage(const char *pfx, bool onlyToFile, const char *msg,
- va_list ap) {
- if (!onlyToFile) {
- va_list ap2;
- va_copy(ap2, ap);
- klee_vfmessage(stderr, pfx, msg, ap2);
- va_end(ap2);
- }
-
- klee_vfmessage(pfx ? klee_warning_file : klee_message_file, pfx, msg, ap);
-}
-
-
-void klee::klee_message(const char *msg, ...) {
- va_list ap;
- va_start(ap, msg);
- klee_vmessage(NULL, false, msg, ap);
- va_end(ap);
-}
-
-/* Message to be written only to file */
-void klee::klee_message_to_file(const char *msg, ...) {
- va_list ap;
- va_start(ap, msg);
- klee_vmessage(NULL, true, msg, ap);
- va_end(ap);
-}
-
-void klee::klee_error(const char *msg, ...) {
- va_list ap;
- va_start(ap, msg);
- klee_vmessage(errorPrefix, false, msg, ap);
- va_end(ap);
- exit(1);
-}
-
-void klee::klee_warning(const char *msg, ...) {
- va_list ap;
- va_start(ap, msg);
- klee_vmessage(warningPrefix, false, msg, ap);
- va_end(ap);
-}
-
-
-/* Prints a warning once per message. */
-void klee::klee_warning_once(const void *id, const char *msg, ...) {
- static std::set< std::pair<const void*, const char*> > keys;
- std::pair<const void*, const char*> key;
-
-
- /* "calling external" messages contain the actual arguments with
- which we called the external function, so we need to ignore them
- when computing the key. */
- if (strncmp(msg, "calling external", strlen("calling external")) != 0)
- key = std::make_pair(id, msg);
- else key = std::make_pair(id, "calling external");
-
- if (!keys.count(key)) {
- keys.insert(key);
-
- va_list ap;
- va_start(ap, msg);
- klee_vmessage(warningOncePrefix, false, msg, ap);
- va_end(ap);
- }
-}
diff --git a/lib/Core/Common.h b/lib/Core/Common.h
deleted file mode 100644
index ce05b536..00000000
--- a/lib/Core/Common.h
+++ /dev/null
@@ -1,56 +0,0 @@
-//===-- Common.h ------------------------------------------------*- C++ -*-===//
-//
-// The KLEE Symbolic Virtual Machine
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef __KLEE_COMMON_H__
-#define __KLEE_COMMON_H__
-
-#ifdef __CYGWIN__
-#ifndef WINDOWS
-#define WINDOWS
-#endif
-#endif
-
-#include <stdio.h>
-
-// XXX ugh
-namespace klee {
- class Solver;
-
- extern FILE* klee_warning_file;
- extern FILE* klee_message_file;
-
- /// Print "KLEE: ERROR" followed by the msg in printf format and a
- /// newline on stderr and to warnings.txt, then exit with an error.
- void klee_error(const char *msg, ...)
- __attribute__ ((format (printf, 1, 2), noreturn));
-
- /// Print "KLEE: " followed by the msg in printf format and a
- /// newline on stderr and to messages.txt.
- void klee_message(const char *msg, ...)
- __attribute__ ((format (printf, 1, 2)));
-
- /// Print "KLEE: " followed by the msg in printf format and a
- /// newline to messages.txt.
- void klee_message_to_file(const char *msg, ...)
- __attribute__ ((format (printf, 1, 2)));
-
- /// Print "KLEE: WARNING" followed by the msg in printf format and a
- /// newline on stderr and to warnings.txt.
- void klee_warning(const char *msg, ...)
- __attribute__ ((format (printf, 1, 2)));
-
- /// Print "KLEE: WARNING" followed by the msg in printf format and a
- /// newline on stderr and to warnings.txt. However, the warning is only
- /// printed once for each unique (id, msg) pair (as pointers).
- void klee_warning_once(const void *id,
- const char *msg, ...)
- __attribute__ ((format (printf, 2, 3)));
-}
-
-#endif /* __KLEE_COMMON_H__ */
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index 49e526f5..0b34c357 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-#include "Common.h"
#include "Executor.h"
#include "Context.h"
#include "CoreStats.h"
@@ -44,6 +43,7 @@
#include "klee/Internal/Module/InstructionInfoTable.h"
#include "klee/Internal/Module/KInstruction.h"
#include "klee/Internal/Module/KModule.h"
+#include "klee/Internal/Support/ErrorHandling.h"
#include "klee/Internal/Support/FloatEvaluation.h"
#include "klee/Internal/System/Time.h"
#include "klee/Internal/System/MemoryUsage.h"
diff --git a/lib/Core/ExecutorTimers.cpp b/lib/Core/ExecutorTimers.cpp
index e4622d85..38411c4f 100644
--- a/lib/Core/ExecutorTimers.cpp
+++ b/lib/Core/ExecutorTimers.cpp
@@ -7,8 +7,6 @@
//
//===----------------------------------------------------------------------===//
-#include "Common.h"
-
#include "CoreStats.h"
#include "Executor.h"
#include "PTree.h"
@@ -20,6 +18,7 @@
#include "klee/Internal/Module/KInstruction.h"
#include "klee/Internal/Module/KModule.h"
#include "klee/Internal/System/Time.h"
+#include "klee/Internal/Support/ErrorHandling.h"
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
#include "llvm/IR/Function.h"
diff --git a/lib/Core/Memory.cpp b/lib/Core/Memory.cpp
index 07c292a0..50e9aa9f 100644
--- a/lib/Core/Memory.cpp
+++ b/lib/Core/Memory.cpp
@@ -7,14 +7,13 @@
//
//===----------------------------------------------------------------------===//
-#include "Common.h"
-
#include "Memory.h"
#include "Context.h"
#include "klee/Expr.h"
#include "klee/Solver.h"
#include "klee/util/BitArray.h"
+#include "klee/Internal/Support/ErrorHandling.h"
#include "ObjectHolder.h"
#include "MemoryManager.h"
diff --git a/lib/Core/MemoryManager.cpp b/lib/Core/MemoryManager.cpp
index a1198007..7c76d480 100644
--- a/lib/Core/MemoryManager.cpp
+++ b/lib/Core/MemoryManager.cpp
@@ -7,8 +7,6 @@
//
//===----------------------------------------------------------------------===//
-#include "Common.h"
-
#include "CoreStats.h"
#include "Memory.h"
#include "MemoryManager.h"
@@ -16,6 +14,7 @@
#include "klee/ExecutionState.h"
#include "klee/Expr.h"
#include "klee/Solver.h"
+#include "klee/Internal/Support/ErrorHandling.h"
#include "llvm/Support/CommandLine.h"
diff --git a/lib/Core/Searcher.cpp b/lib/Core/Searcher.cpp
index e33d2a56..cbb88727 100644
--- a/lib/Core/Searcher.cpp
+++ b/lib/Core/Searcher.cpp
@@ -7,8 +7,6 @@
//
//===----------------------------------------------------------------------===//
-#include "Common.h"
-
#include "Searcher.h"
#include "CoreStats.h"
@@ -25,6 +23,7 @@
#include "klee/Internal/ADT/RNG.h"
#include "klee/Internal/Support/ModuleUtil.h"
#include "klee/Internal/System/Time.h"
+#include "klee/Internal/Support/ErrorHandling.h"
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
#include "llvm/IR/Constants.h"
#include "llvm/IR/Instructions.h"
diff --git a/lib/Core/SeedInfo.cpp b/lib/Core/SeedInfo.cpp
index b540d271..90de17ff 100644
--- a/lib/Core/SeedInfo.cpp
+++ b/lib/Core/SeedInfo.cpp
@@ -7,8 +7,6 @@
//
//===----------------------------------------------------------------------===//
-#include "Common.h"
-
#include "Memory.h"
#include "SeedInfo.h"
#include "TimingSolver.h"
@@ -17,6 +15,7 @@
#include "klee/Expr.h"
#include "klee/util/ExprUtil.h"
#include "klee/Internal/ADT/KTest.h"
+#include "klee/Internal/Support/ErrorHandling.h"
using namespace klee;
diff --git a/lib/Core/SpecialFunctionHandler.cpp b/lib/Core/SpecialFunctionHandler.cpp
index fdd4cdd9..caec5e39 100644
--- a/lib/Core/SpecialFunctionHandler.cpp
+++ b/lib/Core/SpecialFunctionHandler.cpp
@@ -7,8 +7,6 @@
//
//===----------------------------------------------------------------------===//
-#include "Common.h"
-
#include "Memory.h"
#include "SpecialFunctionHandler.h"
#include "TimingSolver.h"
@@ -18,6 +16,7 @@
#include "klee/Internal/Module/KInstruction.h"
#include "klee/Internal/Module/KModule.h"
#include "klee/Internal/Support/Debug.h"
+#include "klee/Internal/Support/ErrorHandling.h"
#include "Executor.h"
#include "MemoryManager.h"
diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp
index cf8a1654..4633a5c5 100644
--- a/lib/Core/StatsTracker.cpp
+++ b/lib/Core/StatsTracker.cpp
@@ -7,8 +7,6 @@
//
//===----------------------------------------------------------------------===//
-#include "Common.h"
-
#include "StatsTracker.h"
#include "klee/ExecutionState.h"
@@ -19,6 +17,7 @@
#include "klee/Internal/Module/KInstruction.h"
#include "klee/Internal/Support/ModuleUtil.h"
#include "klee/Internal/System/Time.h"
+#include "klee/Internal/Support/ErrorHandling.h"
#include "CallPathManager.h"
#include "CoreStats.h"
diff --git a/lib/Core/UserSearcher.cpp b/lib/Core/UserSearcher.cpp
index 72f3351f..fcda26f2 100644
--- a/lib/Core/UserSearcher.cpp
+++ b/lib/Core/UserSearcher.cpp
@@ -7,13 +7,12 @@
//
//===----------------------------------------------------------------------===//
-#include "Common.h"
-
#include "UserSearcher.h"
#include "Searcher.h"
#include "Executor.h"
+#include "klee/Internal/Support/ErrorHandling.h"
#include "llvm/Support/CommandLine.h"
using namespace llvm;