2023-09-07 12:51:48 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* Orca
|
|
|
|
* Copyright 2023 Martin Fouilleul and the Orca project contributors
|
|
|
|
* See LICENSE.txt for licensing information
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
2023-03-05 15:05:43 +00:00
|
|
|
#ifndef __PLATFORM_H_
|
|
|
|
#define __PLATFORM_H_
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
// Compiler identification
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
#if defined(__clang__)
|
2023-08-19 12:49:23 +00:00
|
|
|
#define OC_COMPILER_CLANG 1
|
|
|
|
#if defined(__apple_build_version__)
|
|
|
|
#define OC_COMPILER_CLANG_APPLE 1
|
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
#define OC_COMPILER_CLANG_CL 1
|
|
|
|
#endif
|
2023-03-05 15:05:43 +00:00
|
|
|
|
|
|
|
#elif defined(_MSC_VER)
|
2023-08-19 12:49:23 +00:00
|
|
|
#define OC_COMPILER_CL 1
|
2023-03-05 15:05:43 +00:00
|
|
|
#elif defined(__GNUC__)
|
2023-08-19 12:49:23 +00:00
|
|
|
#define OC_COMPILER_GCC 1
|
2023-03-05 15:05:43 +00:00
|
|
|
#else
|
2023-08-19 12:49:23 +00:00
|
|
|
#error "Can't identify compiler"
|
2023-03-05 15:05:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
// OS identification
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
#if defined(_WIN64)
|
2023-08-19 12:49:23 +00:00
|
|
|
#define OC_PLATFORM_WINDOWS 1
|
2023-03-05 15:05:43 +00:00
|
|
|
#elif defined(_WIN32)
|
2023-08-19 12:49:23 +00:00
|
|
|
#error "Unsupported OS (32bit only version of Windows)"
|
2023-03-05 15:05:43 +00:00
|
|
|
#elif defined(__APPLE__) && defined(__MACH__)
|
2023-08-19 12:49:23 +00:00
|
|
|
#define OC_PLATFORM_MACOS 1
|
2023-03-05 15:05:43 +00:00
|
|
|
#elif defined(__gnu_linux__)
|
2023-08-19 12:49:23 +00:00
|
|
|
#define PLATFORM_LINUX 1
|
2023-04-17 08:55:19 +00:00
|
|
|
#elif defined(__ORCA__)
|
2023-08-19 12:49:23 +00:00
|
|
|
#define OC_PLATFORM_ORCA 1
|
2023-03-05 15:05:43 +00:00
|
|
|
#else
|
2023-08-19 12:49:23 +00:00
|
|
|
#error "Can't identify platform"
|
2023-03-05 15:05:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
// Architecture identification
|
|
|
|
//-----------------------------------------------------------------
|
2023-08-14 08:26:11 +00:00
|
|
|
#if defined(OC_COMPILER_CL)
|
2023-08-19 12:49:23 +00:00
|
|
|
#if defined(_M_AMD64)
|
|
|
|
#define OC_ARCH_X64 1
|
|
|
|
#elif defined(_M_I86)
|
|
|
|
#define OC_ARCH_X86 1
|
|
|
|
#elif defined(_M_ARM64)
|
|
|
|
#define OC_ARCH_ARM64 1
|
|
|
|
#elif defined(_M_ARM)
|
|
|
|
#define OC_ARCH_ARM32 1
|
|
|
|
#else
|
|
|
|
#error "Can't identify architecture"
|
|
|
|
#endif
|
2023-03-05 15:05:43 +00:00
|
|
|
#else
|
2023-08-19 12:49:23 +00:00
|
|
|
#if defined(__x86_64__)
|
|
|
|
#define OC_ARCH_X64 1
|
|
|
|
#elif defined(__i386__)
|
|
|
|
#define OC_ARCH_X86 1
|
|
|
|
#elif defined(__arm__)
|
|
|
|
#define OC_ARCH_ARM32 1
|
|
|
|
#elif defined(__aarch64__)
|
|
|
|
#define OC_ARCH_ARM64 1
|
|
|
|
#elif defined(__ORCA__)
|
|
|
|
#define OC_ARCH_WASM32 1
|
|
|
|
#else
|
|
|
|
#error "Can't identify architecture"
|
|
|
|
#endif
|
2023-03-05 15:05:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
// platform helper macros
|
|
|
|
//-----------------------------------------------------------------
|
2023-08-14 08:26:11 +00:00
|
|
|
#if defined(OC_COMPILER_CL)
|
2023-08-19 12:49:23 +00:00
|
|
|
#if defined(OC_BUILD_DLL)
|
|
|
|
#define ORCA_API __declspec(dllexport)
|
|
|
|
#else
|
|
|
|
#define ORCA_API __declspec(dllimport)
|
|
|
|
#endif
|
2023-08-14 08:26:11 +00:00
|
|
|
#elif defined(OC_COMPILER_GCC) || defined(OC_COMPILER_CLANG)
|
2023-08-19 12:49:23 +00:00
|
|
|
#define ORCA_API
|
2023-06-25 15:28:31 +00:00
|
|
|
#endif
|
2023-03-05 15:05:43 +00:00
|
|
|
|
2023-08-14 08:26:11 +00:00
|
|
|
#if OC_PLATFORM_ORCA
|
2023-08-19 12:49:23 +00:00
|
|
|
#define oc_thread_local // no tls (or threads) for now on wasm orca
|
2023-08-14 08:26:11 +00:00
|
|
|
#elif defined(OC_COMPILER_CL)
|
2023-08-19 12:49:23 +00:00
|
|
|
#define oc_thread_local __declspec(thread)
|
2023-08-14 08:26:11 +00:00
|
|
|
#elif defined(OC_COMPILER_GCC) || defined(OC_COMPILER_CLANG)
|
2023-08-19 12:49:23 +00:00
|
|
|
#define oc_thread_local __thread
|
2023-03-05 15:05:43 +00:00
|
|
|
#endif
|
|
|
|
|
2023-08-14 08:26:11 +00:00
|
|
|
#if OC_PLATFORM_ORCA
|
2023-08-19 12:49:23 +00:00
|
|
|
#define ORCA_IMPORT(f) __attribute__((import_name(#f))) f
|
2023-08-09 11:06:32 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
#if OC_COMPILER_CLANG
|
|
|
|
#define ORCA_EXPORT __attribute__((visibility("default")))
|
|
|
|
#else
|
|
|
|
#error "Orca apps can only be compiled with clang for now"
|
|
|
|
#endif
|
2023-06-25 18:17:01 +00:00
|
|
|
#endif
|
|
|
|
|
2023-08-22 08:08:23 +00:00
|
|
|
#ifdef __cplusplus
|
2023-09-07 12:51:48 +00:00
|
|
|
extern "C" {
|
2023-08-22 08:08:23 +00:00
|
|
|
#endif
|
|
|
|
|
2023-09-07 12:51:48 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
OC_HOST_PLATFORM_MACOS,
|
|
|
|
OC_HOST_PLATFORM_WINDOWS,
|
|
|
|
} oc_host_platform;
|
2023-08-22 08:08:23 +00:00
|
|
|
|
2023-09-07 12:51:48 +00:00
|
|
|
ORCA_API oc_host_platform oc_get_host_platform();
|
2023-08-22 08:08:23 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
2023-03-05 15:05:43 +00:00
|
|
|
#endif // __PLATFORM_H_
|