common_funcs.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2019 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <algorithm>
  6. #include <array>
  7. #include <string>
  8. #if !defined(ARCHITECTURE_x86_64)
  9. #include <cstdlib> // for exit
  10. #endif
  11. #include "common/common_types.h"
  12. /// Textually concatenates two tokens. The double-expansion is required by the C preprocessor.
  13. #define CONCAT2(x, y) DO_CONCAT2(x, y)
  14. #define DO_CONCAT2(x, y) x##y
  15. /// Helper macros to insert unused bytes or words to properly align structs. These values will be
  16. /// zero-initialized.
  17. #define INSERT_PADDING_BYTES(num_bytes) \
  18. std::array<u8, num_bytes> CONCAT2(pad, __LINE__) {}
  19. #define INSERT_PADDING_WORDS(num_words) \
  20. std::array<u32, num_words> CONCAT2(pad, __LINE__) {}
  21. /// These are similar to the INSERT_PADDING_* macros, but are needed for padding unions. This is
  22. /// because unions can only be initialized by one member.
  23. #define INSERT_UNION_PADDING_BYTES(num_bytes) std::array<u8, num_bytes> CONCAT2(pad, __LINE__)
  24. #define INSERT_UNION_PADDING_WORDS(num_words) std::array<u32, num_words> CONCAT2(pad, __LINE__)
  25. #ifndef _MSC_VER
  26. #ifdef ARCHITECTURE_x86_64
  27. #define Crash() __asm__ __volatile__("int $3")
  28. #else
  29. #define Crash() exit(1)
  30. #endif
  31. #else // _MSC_VER
  32. // Locale Cross-Compatibility
  33. #define locale_t _locale_t
  34. extern "C" {
  35. __declspec(dllimport) void __stdcall DebugBreak(void);
  36. }
  37. #define Crash() DebugBreak()
  38. #endif // _MSC_VER ndef
  39. // Generic function to get last error message.
  40. // Call directly after the command or use the error num.
  41. // This function might change the error code.
  42. // Defined in Misc.cpp.
  43. std::string GetLastErrorMsg();
  44. namespace Common {
  45. constexpr u32 MakeMagic(char a, char b, char c, char d) {
  46. return u32(a) | u32(b) << 8 | u32(c) << 16 | u32(d) << 24;
  47. }
  48. } // namespace Common