common_funcs.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <string>
  6. #if !defined(ARCHITECTURE_x86_64)
  7. #include <cstdlib> // for exit
  8. #endif
  9. #include "common/common_types.h"
  10. /// Textually concatenates two tokens. The double-expansion is required by the C preprocessor.
  11. #define CONCAT2(x, y) DO_CONCAT2(x, y)
  12. #define DO_CONCAT2(x, y) x##y
  13. // helper macro to properly align structure members.
  14. // Calling INSERT_PADDING_BYTES will add a new member variable with a name like "pad121",
  15. // depending on the current source line to make sure variable names are unique.
  16. #define INSERT_PADDING_BYTES(num_bytes) u8 CONCAT2(pad, __LINE__)[(num_bytes)]
  17. #define INSERT_PADDING_WORDS(num_words) u32 CONCAT2(pad, __LINE__)[(num_words)]
  18. // Inlining
  19. #ifdef _WIN32
  20. #define FORCE_INLINE __forceinline
  21. #else
  22. #define FORCE_INLINE inline __attribute__((always_inline))
  23. #endif
  24. #ifndef _MSC_VER
  25. #ifdef ARCHITECTURE_x86_64
  26. #define Crash() __asm__ __volatile__("int $3")
  27. #else
  28. #define Crash() exit(1)
  29. #endif
  30. #else // _MSC_VER
  31. // Locale Cross-Compatibility
  32. #define locale_t _locale_t
  33. extern "C" {
  34. __declspec(dllimport) void __stdcall DebugBreak(void);
  35. }
  36. #define Crash() DebugBreak()
  37. #endif // _MSC_VER ndef
  38. // Generic function to get last error message.
  39. // Call directly after the command or use the error num.
  40. // This function might change the error code.
  41. // Defined in Misc.cpp.
  42. std::string GetLastErrorMsg();
  43. namespace Common {
  44. constexpr u32 MakeMagic(char a, char b, char c, char d) {
  45. return a | b << 8 | c << 16 | d << 24;
  46. }
  47. } // namespace Common