Code cleanup: removing config.h and cleaning up platform.h

This commit is contained in:
Ben Vanik 2015-05-02 01:41:39 -07:00
parent 30f7effa73
commit 4d15b2296e
21 changed files with 41 additions and 163 deletions

View File

@ -12,7 +12,6 @@
#include <assert.h> #include <assert.h>
#include "poly/config.h"
#include "poly/platform.h" #include "poly/platform.h"
namespace poly { namespace poly {

View File

@ -12,19 +12,18 @@
#include <cstdint> #include <cstdint>
#include "poly/config.h"
#include "poly/platform.h" #include "poly/platform.h"
#if XE_LIKE_OSX #if XE_PLATFORM_MAC
#include <libkern/OSAtomic.h> #include <libkern/OSAtomic.h>
#endif // XE_LIKE_OSX #endif // XE_PLATFORM_MAC
namespace poly { namespace poly {
// These functions are modeled off of the Apple OSAtomic routines // These functions are modeled off of the Apple OSAtomic routines
// http://developer.apple.com/library/mac/#documentation/DriversKernelHardware/Reference/libkern_ref/OSAtomic_h/ // http://developer.apple.com/library/mac/#documentation/DriversKernelHardware/Reference/libkern_ref/OSAtomic_h/
#if XE_LIKE_OSX #if XE_PLATFORM_MAC
inline int32_t atomic_inc(volatile int32_t* value) { inline int32_t atomic_inc(volatile int32_t* value) {
return OSAtomicIncrement32Barrier(reinterpret_cast<volatile int32_t*>(value)); return OSAtomicIncrement32Barrier(reinterpret_cast<volatile int32_t*>(value));
@ -58,7 +57,7 @@ inline bool atomic_cas(int64_t old_value, int64_t new_value,
old_value, new_value, reinterpret_cast<volatile int64_t*>(value)); old_value, new_value, reinterpret_cast<volatile int64_t*>(value));
} }
#elif XE_LIKE_WIN32 #elif XE_PLATFORM_WIN32
inline int32_t atomic_inc(volatile int32_t* value) { inline int32_t atomic_inc(volatile int32_t* value) {
return InterlockedIncrement(reinterpret_cast<volatile LONG*>(value)); return InterlockedIncrement(reinterpret_cast<volatile LONG*>(value));
@ -96,7 +95,7 @@ inline bool atomic_cas(int64_t old_value, int64_t new_value,
new_value, old_value) == old_value; new_value, old_value) == old_value;
} }
#elif XE_LIKE_POSIX #elif XE_PLATFORM_LINUX
inline int32_t atomic_inc(volatile int32_t* value) { inline int32_t atomic_inc(volatile int32_t* value) {
return __sync_add_and_fetch(value, 1); return __sync_add_and_fetch(value, 1);

View File

@ -12,12 +12,11 @@
#include <cstdint> #include <cstdint>
#include "poly/config.h"
#include "poly/platform.h" #include "poly/platform.h"
#if XE_LIKE_OSX #if XE_PLATFORM_MAC
#include <libkern/OSByteOrder.h> #include <libkern/OSByteOrder.h>
#endif // XE_LIKE_OSX #endif // XE_PLATFORM_MAC
namespace poly { namespace poly {
@ -25,7 +24,7 @@ namespace poly {
#define POLY_BYTE_SWAP_16 _byteswap_ushort #define POLY_BYTE_SWAP_16 _byteswap_ushort
#define POLY_BYTE_SWAP_32 _byteswap_ulong #define POLY_BYTE_SWAP_32 _byteswap_ulong
#define POLY_BYTE_SWAP_64 _byteswap_uint64 #define POLY_BYTE_SWAP_64 _byteswap_uint64
#elif XE_LIKE_OSX #elif XE_PLATFORM_MAC
#define POLY_BYTE_SWAP_16 OSSwapInt16 #define POLY_BYTE_SWAP_16 OSSwapInt16
#define POLY_BYTE_SWAP_32 OSSwapInt32 #define POLY_BYTE_SWAP_32 OSSwapInt32
#define POLY_BYTE_SWAP_64 OSSwapInt64 #define POLY_BYTE_SWAP_64 OSSwapInt64

View File

@ -1,17 +0,0 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2014 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef POLY_CONFIG_H_
#define POLY_CONFIG_H_
#if defined(DEBUG) || defined(_DEBUG)
#define XE_DEBUG 1
#endif // DEBUG
#endif // POLY_CONFIG_H_

View File

@ -12,7 +12,6 @@
#include <memory> #include <memory>
#include "poly/config.h"
// C++11 thread local storage. // C++11 thread local storage.
// http://en.cppreference.com/w/cpp/language/storage_duration // http://en.cppreference.com/w/cpp/language/storage_duration
@ -20,7 +19,7 @@
// VC++2014 may have this. // VC++2014 may have this.
#define _ALLOW_KEYWORD_MACROS 1 #define _ALLOW_KEYWORD_MACROS 1
#define thread_local __declspec(thread) #define thread_local __declspec(thread)
#elif XE_LIKE_OSX #elif XE_PLATFORM_MAC
// Clang supports it on OSX but the runtime doesn't. // Clang supports it on OSX but the runtime doesn't.
#define thread_local __thread #define thread_local __thread
#endif // XE_COMPILER_MSVC #endif // XE_COMPILER_MSVC

View File

@ -12,7 +12,6 @@
#include <cstdint> #include <cstdint>
#include "poly/config.h"
namespace poly { namespace poly {
namespace debugging { namespace debugging {

View File

@ -12,7 +12,6 @@
#include <string> #include <string>
#include "poly/config.h"
#include "poly/string.h" #include "poly/string.h"
#include <vector> #include <vector>

View File

@ -120,7 +120,7 @@ void handle_fatal(const char* file_path, const uint32_t line_number,
log_lock.unlock(); log_lock.unlock();
} }
#if XE_LIKE_WIN32 #if XE_PLATFORM_WIN32
if (!poly::has_console_attached()) { if (!poly::has_console_attached()) {
MessageBoxA(NULL, buffer, "Xenia Error", MessageBoxA(NULL, buffer, "Xenia Error",
MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND);

View File

@ -17,7 +17,6 @@
#include <cstring> #include <cstring>
#include <type_traits> #include <type_traits>
#include "poly/config.h"
#include "poly/platform.h" #include "poly/platform.h"
namespace poly { namespace poly {
@ -120,11 +119,12 @@ inline uint8_t lzcnt(int64_t v) { return lzcnt(static_cast<uint64_t>(v)); }
// Returns false if no bits are set and the output index is invalid. // Returns false if no bits are set and the output index is invalid.
#if XE_COMPILER_MSVC #if XE_COMPILER_MSVC
inline bool bit_scan_forward(uint32_t v, uint32_t* out_first_set_index) { inline bool bit_scan_forward(uint32_t v, uint32_t* out_first_set_index) {
return _BitScanForward(reinterpret_cast<DWORD*>(out_first_set_index), v) != 0; return _BitScanForward(reinterpret_cast<unsigned long*>(out_first_set_index),
v) != 0;
} }
inline bool bit_scan_forward(uint64_t v, uint32_t* out_first_set_index) { inline bool bit_scan_forward(uint64_t v, uint32_t* out_first_set_index) {
return _BitScanForward64(reinterpret_cast<DWORD*>(out_first_set_index), v) != return _BitScanForward64(
0; reinterpret_cast<unsigned long*>(out_first_set_index), v) != 0;
} }
#else #else
inline bool bit_scan_forward(uint32_t v, uint32_t* out_first_set_index) { inline bool bit_scan_forward(uint32_t v, uint32_t* out_first_set_index) {

View File

@ -11,22 +11,22 @@
#include <algorithm> #include <algorithm>
#if !XE_LIKE_WIN32 #if !XE_PLATFORM_WIN32
#include <unistd.h> #include <unistd.h>
#endif // !XE_LIKE_WIN32 #endif // !XE_PLATFORM_WIN32
namespace poly { namespace poly {
size_t page_size() { size_t page_size() {
static size_t value = 0; static size_t value = 0;
if (!value) { if (!value) {
#if XE_LIKE_WIN32 #if XE_PLATFORM_WIN32
SYSTEM_INFO si; SYSTEM_INFO si;
GetSystemInfo(&si); GetSystemInfo(&si);
value = si.dwPageSize; value = si.dwPageSize;
#else #else
value = getpagesize(); value = getpagesize();
#endif // XE_LIKE_WIN32 #endif // XE_PLATFORM_WIN32
} }
return value; return value;
} }

View File

@ -15,79 +15,16 @@
// Great resource on predefined macros: http://predef.sourceforge.net/preos.html // Great resource on predefined macros: http://predef.sourceforge.net/preos.html
/*
XE_PLATFORM: IOS | OSX | XBOX360 | WINCE | WIN32 | ANDROID | NACL | UNIX
XE_LIKE: OSX | WIN32 | POSIX
XE_PROFILE: EMBEDDED | DESKTOP (+ _SIMULATOR)
XE_COMPILER: GNUC | MSVC | CLANG | INTEL | UNKNOWN
XE_CPU: 32BIT | 64BIT | BIGENDIAN | LITTLEENDIAN
*/
#if defined(__APPLE__) #if defined(__APPLE__)
#include <TargetConditionals.h> #include <TargetConditionals.h>
#endif #endif
#if (defined(TARGET_OS_EMBEDDED) && TARGET_OS_EMBEDDED) || \ #if defined(TARGET_OS_MAC) && TARGET_OS_MAC
(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) || \ #define XE_PLATFORM_MAC 1
(defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR)
#define XE_PLATFORM_IOS 1
#define XE_LIKE_OSX 1
#define XE_PROFILE_EMBEDDED 1
#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR
// EMBEDDED *and* SIMULATOR
#define XE_PROFILE_SIMULATOR 1
#endif
#elif defined(TARGET_OS_MAC) && TARGET_OS_MAC
#define XE_PLATFORM_OSX 1
#define XE_LIKE_OSX 1
#define XE_PROFILE_DESKTOP 1
#elif defined(_XBOX)
#define XE_PLATFORM_XBOX360 1
#define XE_LIKE_WIN32 1
#define XE_PROFILE_EMBEDDED 1
#elif defined(_WIN32_WCE)
#define XE_PLATFORM_WINCE 1
#define XE_LIKE_WIN32 1
#define XE_PROFILE_EMBEDDED 1
#elif defined(__CYGWIN__)
#define XE_PLATFORM_CYGWIN 1
#define XE_LIKE_POSIX 1
#define XE_PROFILE_DESKTOP 1
#elif defined(WIN32) || defined(_WIN32) #elif defined(WIN32) || defined(_WIN32)
#define XE_PLATFORM_WIN32 1 #define XE_PLATFORM_WIN32 1
#define XE_LIKE_WIN32 1
#define XE_PROFILE_DESKTOP 1
#elif defined(ANDROID)
#define XE_PLATFORM_ANDROID 1
#define XE_LIKE_POSIX 1
#define XE_PROFILE_EMBEDDED 1
#elif defined(__native_client__)
#define XE_PLATFORM_NACL 1
#define XE_LIKE_POSIX 1
#define XE_PROFILE_DESKTOP 1
#else #else
#define XE_PLATFORM_LINUX 1
#define XE_PLATFORM_UNIX 1
#define XE_LIKE_POSIX 1
#define XE_PROFILE_DESKTOP 1
#endif #endif
#if defined(__clang__) #if defined(__clang__)
@ -104,26 +41,7 @@ XE_CPU: 32BIT | 64BIT | BIGENDIAN | LITTLEENDIAN
#define XE_COMPILER_UNKNOWN 1 #define XE_COMPILER_UNKNOWN 1
#endif #endif
#if defined(__ia64__) || defined(_M_IA64) || defined(__ppc64__) || \ #if XE_PLATFORM_WIN32
defined(__PPC64__) || defined(__arch64__) || defined(__x86_64__) || \
defined(_M_X64) || defined(_M_AMD64) || defined(__LP64__) || \
defined(__LLP64) || defined(_WIN64) || (__WORDSIZE == 64)
#define XE_CPU_64BIT 1
#else
#define XE_CPU_32BIT 1
#endif // [64bit flags]
#if defined(__ppc__) || defined(__PPC__) || defined(__powerpc__) || \
defined(__powerpc) || defined(__POWERPC__) || defined(_M_PPC) || \
defined(__PPC) || defined(__ppc64__) || defined(__PPC64__) || \
defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \
defined(__BIG_ENDIAN) || defined(__BIG_ENDIAN__)
#define XE_CPU_BIGENDIAN 1
#else
#define XE_CPU_LITTLEENDIAN 1
#endif // [big endian flags]
#if XE_PLATFORM_WINCE || XE_PLATFORM_WIN32
#ifndef WIN32_LEAN_AND_MEAN #ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#endif #endif
@ -132,19 +50,10 @@ XE_CPU: 32BIT | 64BIT | BIGENDIAN | LITTLEENDIAN
#include <ObjBase.h> #include <ObjBase.h>
#undef min #undef min
#undef max #undef max
#undef Yield
#define strdup _strdup #define strdup _strdup
#endif // WINCE || WIN32 #define strcasecmp _stricmp
#define strncasecmp _strnicmp
#if XE_PLATFORM_XBOX360 #endif // XE_PLATFORM_WIN32
#include <xtl.h>
#include <xboxmath.h>
#endif // XBOX360
#if XE_COMPILER_MSVC
// Disable warning C4068: unknown pragma
#pragma warning(disable : 4068)
#endif // XE_COMPILER_MSVC
#if XE_COMPILER_MSVC #if XE_COMPILER_MSVC
#include <intrin.h> #include <intrin.h>
@ -152,20 +61,15 @@ XE_CPU: 32BIT | 64BIT | BIGENDIAN | LITTLEENDIAN
#include <x86intrin.h> #include <x86intrin.h>
#endif // XE_COMPILER_MSVC #endif // XE_COMPILER_MSVC
#if XE_LIKE_WIN32
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#endif // XE_LIKE_WIN32
namespace poly { namespace poly {
#if XE_LIKE_WIN32 #if XE_PLATFORM_WIN32
const char path_separator = '\\'; const char path_separator = '\\';
const size_t max_path = _MAX_PATH; const size_t max_path = _MAX_PATH;
#else #else
const char path_separator = '/'; const char path_separator = '/';
const size_t max_path = 1024; // PATH_MAX const size_t max_path = 1024; // PATH_MAX
#endif // XE_LIKE_WIN32 #endif // XE_PLATFORM_WIN32
} // namespace poly } // namespace poly

View File

@ -13,7 +13,6 @@
#include "poly/assert.h" #include "poly/assert.h"
#include "poly/atomic.h" #include "poly/atomic.h"
#include "poly/byte_order.h" #include "poly/byte_order.h"
#include "poly/config.h"
#include "poly/cxx_compat.h" #include "poly/cxx_compat.h"
#include "poly/debugging.h" #include "poly/debugging.h"
#include "poly/logging.h" #include "poly/logging.h"

View File

@ -8,7 +8,6 @@
'byte_order.h', 'byte_order.h',
'debugging.h', 'debugging.h',
'delegate.h', 'delegate.h',
'config.h',
'cxx_compat.h', 'cxx_compat.h',
'fs.h', 'fs.h',
'fs.cc', 'fs.cc',

View File

@ -41,7 +41,7 @@ std::string::size_type find_first_of_case(const std::string& target,
} }
std::wstring to_absolute_path(const std::wstring& path) { std::wstring to_absolute_path(const std::wstring& path) {
#if XE_LIKE_WIN32 #if XE_PLATFORM_WIN32
wchar_t buffer[poly::max_path]; wchar_t buffer[poly::max_path];
_wfullpath(buffer, path.c_str(), sizeof(buffer) / sizeof(wchar_t)); _wfullpath(buffer, path.c_str(), sizeof(buffer) / sizeof(wchar_t));
return buffer; return buffer;
@ -49,7 +49,7 @@ std::wstring to_absolute_path(const std::wstring& path) {
char buffer[poly::max_path]; char buffer[poly::max_path];
realpath(poly::to_string(path).c_str(), buffer); realpath(poly::to_string(path).c_str(), buffer);
return poly::to_wstring(buffer); return poly::to_wstring(buffer);
#endif // XE_LIKE_WIN32 #endif // XE_PLATFORM_WIN32
} }
std::vector<std::string> split_path(const std::string& path) { std::vector<std::string> split_path(const std::string& path) {

View File

@ -18,7 +18,6 @@
#include <string> #include <string>
#include <thread> #include <thread>
#include "poly/config.h"
namespace poly { namespace poly {
namespace threading { namespace threading {

View File

@ -426,12 +426,12 @@ uint64_t ResolveFunctionSymbol(void* raw_context, uint64_t symbol_info_ptr) {
// Overwrite the call site. // Overwrite the call site.
// The return address points to ReloadRCX work after the call. // The return address points to ReloadRCX work after the call.
#if XE_LIKE_WIN32 #if XE_PLATFORM_WIN32
uint64_t return_address = reinterpret_cast<uint64_t>(_ReturnAddress()); uint64_t return_address = reinterpret_cast<uint64_t>(_ReturnAddress());
#else #else
uint64_t return_address = uint64_t return_address =
reinterpret_cast<uint64_t>(__builtin_return_address(0)); reinterpret_cast<uint64_t>(__builtin_return_address(0));
#endif // XE_LIKE_WIN32 #endif // XE_PLATFORM_WIN32
#pragma pack(push, 1) #pragma pack(push, 1)
struct Asm { struct Asm {
uint16_t mov_rax; uint16_t mov_rax;
@ -507,12 +507,12 @@ uint64_t ResolveFunctionAddress(void* raw_context, uint32_t target_address) {
uint64_t addr = reinterpret_cast<uint64_t>(x64_fn->machine_code()); uint64_t addr = reinterpret_cast<uint64_t>(x64_fn->machine_code());
// Add an IC slot, if there is room. // Add an IC slot, if there is room.
#if XE_LIKE_WIN32 #if XE_PLATFORM_WIN32
uint64_t return_address = reinterpret_cast<uint64_t>(_ReturnAddress()); uint64_t return_address = reinterpret_cast<uint64_t>(_ReturnAddress());
#else #else
uint64_t return_address = uint64_t return_address =
reinterpret_cast<uint64_t>(__builtin_return_address(0)); reinterpret_cast<uint64_t>(__builtin_return_address(0));
#endif // XE_LIKE_WIN32 #endif // XE_PLATFORM_WIN32
#pragma pack(push, 1) #pragma pack(push, 1)
struct Asm { struct Asm {
uint16_t cmp_rdx; uint16_t cmp_rdx;

View File

@ -15,7 +15,7 @@
#include "poly/main.h" #include "poly/main.h"
#include "poly/poly.h" #include "poly/poly.h"
#if !XE_LIKE_WIN32 #if !XE_PLATFORM_WIN32
#include <dirent.h> #include <dirent.h>
#endif // !WIN32 #endif // !WIN32
#include <gflags/gflags.h> #include <gflags/gflags.h>
@ -319,7 +319,7 @@ class TestRunner {
bool DiscoverTests(std::wstring& test_path, bool DiscoverTests(std::wstring& test_path,
std::vector<std::wstring>& test_files) { std::vector<std::wstring>& test_files) {
// TODO(benvanik): use PAL instead of this. // TODO(benvanik): use PAL instead of this.
#if XE_LIKE_WIN32 #if XE_PLATFORM_WIN32
std::wstring search_path = test_path; std::wstring search_path = test_path;
search_path.append(L"\\*.s"); search_path.append(L"\\*.s");
WIN32_FIND_DATA ffd; WIN32_FIND_DATA ffd;

View File

@ -29,12 +29,12 @@ int main(std::vector<std::wstring>& args) {
} }
int ret = Catch::Session().run(int(args.size()), narrow_argv); int ret = Catch::Session().run(int(args.size()), narrow_argv);
if (ret) { if (ret) {
#if XE_LIKE_WIN32 #if XE_PLATFORM_WIN32
// Visual Studio kills the console on shutdown, so prevent that. // Visual Studio kills the console on shutdown, so prevent that.
if (poly::debugging::IsDebuggerAttached()) { if (poly::debugging::IsDebuggerAttached()) {
poly::debugging::Break(); poly::debugging::Break();
} }
#endif // XE_LIKE_WIN32 #endif // XE_PLATFORM_WIN32
} }
return ret; return ret;
} }

View File

@ -294,7 +294,7 @@ X_STATUS XThread::PlatformCreate() {
int result_code; int result_code;
if (creation_params_.creation_flags & 0x1) { if (creation_params_.creation_flags & 0x1) {
#if XE_PLATFORM_OSX #if XE_PLATFORM_MAC
result_code = pthread_create_suspended_np( result_code = pthread_create_suspended_np(
reinterpret_cast<pthread_t*>(&thread_handle_), &attr, reinterpret_cast<pthread_t*>(&thread_handle_), &attr,
&XThreadStartCallbackPthreads, this); &XThreadStartCallbackPthreads, this);

View File

@ -15,9 +15,9 @@
#include "poly/string.h" #include "poly/string.h"
#define XE_OPTION_PROFILING 1 #define XE_OPTION_PROFILING 1
#if XE_LIKE_WIN32 #if XE_PLATFORM_WIN32
#define XE_OPTION_PROFILING_UI 1 #define XE_OPTION_PROFILING_UI 1
#endif // XE_LIKE_WIN32 #endif // XE_PLATFORM_WIN32
#if XE_OPTION_PROFILING #if XE_OPTION_PROFILING
// Pollutes the global namespace. Yuck. // Pollutes the global namespace. Yuck.

View File

@ -138,7 +138,7 @@
'inherit_from': ['common_base',], 'inherit_from': ['common_base',],
'defines': [ 'defines': [
'DEBUG', 'DEBUG',
'ASMJIT_DEBUG=', 'XE_DEBUG=1',
], ],
'msvs_configuration_attributes': { 'msvs_configuration_attributes': {
'OutputDirectory': '<(DEPTH)\\build\\xenia\\Debug', 'OutputDirectory': '<(DEPTH)\\build\\xenia\\Debug',