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 "poly/config.h"
#include "poly/platform.h"
namespace poly {

View File

@ -12,19 +12,18 @@
#include <cstdint>
#include "poly/config.h"
#include "poly/platform.h"
#if XE_LIKE_OSX
#if XE_PLATFORM_MAC
#include <libkern/OSAtomic.h>
#endif // XE_LIKE_OSX
#endif // XE_PLATFORM_MAC
namespace poly {
// These functions are modeled off of the Apple OSAtomic routines
// 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) {
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));
}
#elif XE_LIKE_WIN32
#elif XE_PLATFORM_WIN32
inline int32_t atomic_inc(volatile int32_t* 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;
}
#elif XE_LIKE_POSIX
#elif XE_PLATFORM_LINUX
inline int32_t atomic_inc(volatile int32_t* value) {
return __sync_add_and_fetch(value, 1);

View File

@ -12,12 +12,11 @@
#include <cstdint>
#include "poly/config.h"
#include "poly/platform.h"
#if XE_LIKE_OSX
#if XE_PLATFORM_MAC
#include <libkern/OSByteOrder.h>
#endif // XE_LIKE_OSX
#endif // XE_PLATFORM_MAC
namespace poly {
@ -25,7 +24,7 @@ namespace poly {
#define POLY_BYTE_SWAP_16 _byteswap_ushort
#define POLY_BYTE_SWAP_32 _byteswap_ulong
#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_32 OSSwapInt32
#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 "poly/config.h"
// C++11 thread local storage.
// http://en.cppreference.com/w/cpp/language/storage_duration
@ -20,7 +19,7 @@
// VC++2014 may have this.
#define _ALLOW_KEYWORD_MACROS 1
#define thread_local __declspec(thread)
#elif XE_LIKE_OSX
#elif XE_PLATFORM_MAC
// Clang supports it on OSX but the runtime doesn't.
#define thread_local __thread
#endif // XE_COMPILER_MSVC

View File

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

View File

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

View File

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

View File

@ -17,7 +17,6 @@
#include <cstring>
#include <type_traits>
#include "poly/config.h"
#include "poly/platform.h"
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.
#if XE_COMPILER_MSVC
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) {
return _BitScanForward64(reinterpret_cast<DWORD*>(out_first_set_index), v) !=
0;
return _BitScanForward64(
reinterpret_cast<unsigned long*>(out_first_set_index), v) != 0;
}
#else
inline bool bit_scan_forward(uint32_t v, uint32_t* out_first_set_index) {

View File

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

View File

@ -15,79 +15,16 @@
// 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__)
#include <TargetConditionals.h>
#endif
#if (defined(TARGET_OS_EMBEDDED) && TARGET_OS_EMBEDDED) || \
(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) || \
(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
#if defined(TARGET_OS_MAC) && TARGET_OS_MAC
#define XE_PLATFORM_MAC 1
#elif defined(WIN32) || defined(_WIN32)
#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
#define XE_PLATFORM_UNIX 1
#define XE_LIKE_POSIX 1
#define XE_PROFILE_DESKTOP 1
#define XE_PLATFORM_LINUX 1
#endif
#if defined(__clang__)
@ -104,26 +41,7 @@ XE_CPU: 32BIT | 64BIT | BIGENDIAN | LITTLEENDIAN
#define XE_COMPILER_UNKNOWN 1
#endif
#if defined(__ia64__) || defined(_M_IA64) || defined(__ppc64__) || \
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
#if XE_PLATFORM_WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
@ -132,19 +50,10 @@ XE_CPU: 32BIT | 64BIT | BIGENDIAN | LITTLEENDIAN
#include <ObjBase.h>
#undef min
#undef max
#undef Yield
#define strdup _strdup
#endif // WINCE || WIN32
#if XE_PLATFORM_XBOX360
#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
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#endif // XE_PLATFORM_WIN32
#if XE_COMPILER_MSVC
#include <intrin.h>
@ -152,20 +61,15 @@ XE_CPU: 32BIT | 64BIT | BIGENDIAN | LITTLEENDIAN
#include <x86intrin.h>
#endif // XE_COMPILER_MSVC
#if XE_LIKE_WIN32
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#endif // XE_LIKE_WIN32
namespace poly {
#if XE_LIKE_WIN32
#if XE_PLATFORM_WIN32
const char path_separator = '\\';
const size_t max_path = _MAX_PATH;
#else
const char path_separator = '/';
const size_t max_path = 1024; // PATH_MAX
#endif // XE_LIKE_WIN32
#endif // XE_PLATFORM_WIN32
} // namespace poly

View File

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

View File

@ -8,7 +8,6 @@
'byte_order.h',
'debugging.h',
'delegate.h',
'config.h',
'cxx_compat.h',
'fs.h',
'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) {
#if XE_LIKE_WIN32
#if XE_PLATFORM_WIN32
wchar_t buffer[poly::max_path];
_wfullpath(buffer, path.c_str(), sizeof(buffer) / sizeof(wchar_t));
return buffer;
@ -49,7 +49,7 @@ std::wstring to_absolute_path(const std::wstring& path) {
char buffer[poly::max_path];
realpath(poly::to_string(path).c_str(), buffer);
return poly::to_wstring(buffer);
#endif // XE_LIKE_WIN32
#endif // XE_PLATFORM_WIN32
}
std::vector<std::string> split_path(const std::string& path) {

View File

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

View File

@ -426,12 +426,12 @@ uint64_t ResolveFunctionSymbol(void* raw_context, uint64_t symbol_info_ptr) {
// Overwrite the call site.
// 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());
#else
uint64_t return_address =
reinterpret_cast<uint64_t>(__builtin_return_address(0));
#endif // XE_LIKE_WIN32
#endif // XE_PLATFORM_WIN32
#pragma pack(push, 1)
struct Asm {
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());
// 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());
#else
uint64_t return_address =
reinterpret_cast<uint64_t>(__builtin_return_address(0));
#endif // XE_LIKE_WIN32
#endif // XE_PLATFORM_WIN32
#pragma pack(push, 1)
struct Asm {
uint16_t cmp_rdx;

View File

@ -15,7 +15,7 @@
#include "poly/main.h"
#include "poly/poly.h"
#if !XE_LIKE_WIN32
#if !XE_PLATFORM_WIN32
#include <dirent.h>
#endif // !WIN32
#include <gflags/gflags.h>
@ -319,7 +319,7 @@ class TestRunner {
bool DiscoverTests(std::wstring& test_path,
std::vector<std::wstring>& test_files) {
// TODO(benvanik): use PAL instead of this.
#if XE_LIKE_WIN32
#if XE_PLATFORM_WIN32
std::wstring search_path = test_path;
search_path.append(L"\\*.s");
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);
if (ret) {
#if XE_LIKE_WIN32
#if XE_PLATFORM_WIN32
// Visual Studio kills the console on shutdown, so prevent that.
if (poly::debugging::IsDebuggerAttached()) {
poly::debugging::Break();
}
#endif // XE_LIKE_WIN32
#endif // XE_PLATFORM_WIN32
}
return ret;
}

View File

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

View File

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

View File

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