Introducing YS_OVERRIDE, YS_FINAL, YS_ATTRIBUTE, YS_NORETURN
[yosys.git] / kernel / yosys.h
index 37d3e52f49d72d3d6bc95fbe07a30ed9914ff8f8..b64739ad4e36b60406a916cb8753a2d2c43a40f8 100644 (file)
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdint.h>
 #include <stdio.h>
 
+#ifndef _YOSYS_
+#  error It looks like you are trying to build Yosys without the config defines set. \
+         When building Yosys with a custom make system, make sure you set all the \
+         defines the Yosys Makefile would set for your build configuration.
+#endif
+
 #ifdef YOSYS_ENABLE_TCL
 #  include <tcl.h>
 #endif
 
+#ifdef _WIN32
+#  undef NOMINMAX
+#  define NOMINMAX 1
+#  undef YY_NO_UNISTD_H
+#  define YY_NO_UNISTD_H 1
+
+#  include <windows.h>
+#  include <io.h>
+#  include <direct.h>
+
+#  define strtok_r strtok_s
+#  define strdup _strdup
+#  define snprintf _snprintf
+#  define getcwd _getcwd
+#  define mkdir _mkdir
+#  define popen _popen
+#  define pclose _pclose
+#  define PATH_MAX MAX_PATH
+
+#  ifndef __MINGW32__
+#    define isatty _isatty
+#    define fileno _fileno
+#  endif
+#endif
+
 #define PRIVATE_NAMESPACE_BEGIN  namespace {
 #define PRIVATE_NAMESPACE_END    }
 #define YOSYS_NAMESPACE_BEGIN    namespace Yosys {
 #define USING_YOSYS_NAMESPACE    using namespace Yosys;
 
 #if __cplusplus >= 201103L
-#  define OVERRIDE override
-#  define FINAL final
+#  define YS_OVERRIDE override
+#  define YS_FINAL final
 #else
-#  define OVERRIDE
-#  define FINAL
+#  define YS_OVERRIDE
+#  define YS_FINAL
 #endif
 
-#if !defined(__GNUC__) && !defined(__clang__)
-#  define __attribute__(...)
+#if defined(__GNUC__) || defined(__clang__)
+#  define YS_ATTRIBUTE(...) __attribute__((__VA_ARGS__))
+#  define YS_NORETURN
+#elif defined(_MSC_VER)
+#  define YS_ATTRIBUTE(...)
+#  define YS_NORETURN __declspec(noreturn)
+#else
+#  define YS_ATTRIBUTE(...)
+#  define YS_NORETURN
 #endif
 
 YOSYS_NAMESPACE_BEGIN
@@ -90,14 +129,15 @@ namespace RTLIL {
        struct Cell;
 }
 
-std::string stringf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
+std::string stringf(const char *fmt, ...) YS_ATTRIBUTE(format(printf, 1, 2));
 std::string vstringf(const char *fmt, va_list ap);
+int readsome(std::istream &f, char *s, int n);
 std::string next_token(std::string &text, const char *sep);
 bool patmatch(const char *pattern, const char *string);
-int readsome(std::istream &f, char *s, int n);
 int run_command(const std::string &command, std::function<void(const std::string&)> process_line = std::function<void(const std::string&)>());
 std::string make_temp_file(std::string template_str = "/tmp/yosys_XXXXXX");
 std::string make_temp_dir(std::string template_str = "/tmp/yosys_XXXXXX");
+bool check_file_exists(std::string filename, bool is_exec = false);
 void remove_directory(std::string dirname);
 
 template<typename T> int GetSize(const T &obj) { return obj.size(); }