Yarn: Add Debug.hpp and Debug.cpp

Provides a number of standard debug macros.

assert_has_bound_scheduler() is stubbed as it depends on the Scheduler (coming in a later change).

Bug: b/139010488
Change-Id: I1854404477efb982c26e7ad3273c2ca544fd1725
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/34770
Tested-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Yarn/Debug.cpp b/src/Yarn/Debug.cpp
new file mode 100644
index 0000000..566cce4
--- /dev/null
+++ b/src/Yarn/Debug.cpp
@@ -0,0 +1,39 @@
+// Copyright 2019 The yarniftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Debug.hpp"
+
+#include <cstdlib>
+
+#include <stdarg.h>
+#include <stdio.h>
+
+namespace yarn
+{
+
+void fatal(const char* msg, ...)
+{
+    va_list vararg;
+    va_start(vararg, msg);
+    vfprintf(stderr, msg, vararg);
+    va_end(vararg);
+    abort();
+}
+
+void assert_has_bound_scheduler(const char* feature)
+{
+    // TODO
+}
+
+}  // namespace yarn
diff --git a/src/Yarn/Debug.hpp b/src/Yarn/Debug.hpp
new file mode 100644
index 0000000..76945b0
--- /dev/null
+++ b/src/Yarn/Debug.hpp
@@ -0,0 +1,45 @@
+// Copyright 2019 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef yarn_debug_hpp
+#define yarn_debug_hpp
+
+#if !defined(YARN_DEBUG_ENABLED)
+#    if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
+#        define YARN_DEBUG_ENABLED 1
+#    else
+#        define YARN_DEBUG_ENABLED 0
+#    endif
+#endif
+
+namespace yarn {
+
+void fatal(const char* msg, ...);
+void assert_has_bound_scheduler(const char* feature);
+
+#if YARN_DEBUG_ENABLED
+#define YARN_FATAL(msg, ...) yarn::fatal(msg "\n", ##__VA_ARGS__);
+#define YARN_ASSERT(cond, msg, ...) do { if (!(cond)) { YARN_FATAL("ASSERT: " msg, ##__VA_ARGS__); } } while (false);
+#define YARN_ASSERT_HAS_BOUND_SCHEDULER(feature) assert_has_bound_scheduler(feature);
+#define YARN_UNREACHABLE() YARN_FATAL("UNREACHABLE");
+#else
+#define YARN_FATAL(msg, ...)
+#define YARN_ASSERT(cond, msg, ...)
+#define YARN_ASSERT_HAS_BOUND_SCHEDULER(feature)
+#define YARN_UNREACHABLE()
+#endif
+
+} // namespace yarn
+
+#endif  // yarn_debug_hpp
diff --git a/src/Yarn/Yarn.cpp b/src/Yarn/Yarn.cpp
deleted file mode 100644
index 154d205..0000000
--- a/src/Yarn/Yarn.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2019 The SwiftShader Authors. All Rights Reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//    http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-// A dummy function and file.
-// Will be removed once there's some library code to compile.
-void dummy() {}
\ No newline at end of file