zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

TargetConditionals.h (18069B) - Raw


      1 /*
      2  * Copyright (c) 2000-2014 by Apple Inc.. All rights reserved.
      3  *
      4  * @APPLE_LICENSE_HEADER_START@
      5  * 
      6  * This file contains Original Code and/or Modifications of Original Code
      7  * as defined in and that are subject to the Apple Public Source License
      8  * Version 2.0 (the 'License'). You may not use this file except in
      9  * compliance with the License. Please obtain a copy of the License at
     10  * http://www.opensource.apple.com/apsl/ and read it before using this
     11  * file.
     12  * 
     13  * The Original Code and all software distributed under the License are
     14  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
     15  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
     16  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
     17  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
     18  * Please see the License for the specific language governing rights and
     19  * limitations under the License.
     20  * 
     21  * @APPLE_LICENSE_HEADER_END@
     22  */
     23  
     24 /*
     25      File:       TargetConditionals.h
     26  
     27      Contains:   Autoconfiguration of TARGET_ conditionals for Mac OS X and iPhone
     28      
     29                  Note:  TargetConditionals.h in 3.4 Universal Interfaces works
     30                         with all compilers.  This header only recognizes compilers
     31                         known to run on Mac OS X.
     32   
     33 */
     34 
     35 #ifndef __TARGETCONDITIONALS__
     36 #define __TARGETCONDITIONALS__
     37 
     38 /*
     39  *
     40  *  TARGET_CPU_*
     41  *  These conditionals specify which microprocessor instruction set is being
     42  *  generated.  At most one of these is true, the rest are false.
     43  *
     44  *      TARGET_CPU_PPC          - Compiler is generating PowerPC instructions for 32-bit mode
     45  *      TARGET_CPU_PPC64        - Compiler is generating PowerPC instructions for 64-bit mode
     46  *      TARGET_CPU_68K          - Compiler is generating 680x0 instructions
     47  *      TARGET_CPU_X86          - Compiler is generating x86 instructions for 32-bit mode
     48  *      TARGET_CPU_X86_64       - Compiler is generating x86 instructions for 64-bit mode
     49  *      TARGET_CPU_ARM          - Compiler is generating ARM instructions for 32-bit mode
     50  *      TARGET_CPU_ARM64        - Compiler is generating ARM instructions for 64-bit mode
     51  *      TARGET_CPU_MIPS         - Compiler is generating MIPS instructions
     52  *      TARGET_CPU_SPARC        - Compiler is generating Sparc instructions
     53  *      TARGET_CPU_ALPHA        - Compiler is generating Dec Alpha instructions
     54  */
     55 
     56 
     57 
     58 /*
     59  *  TARGET_OS_*
     60  *
     61  *  These conditionals specify in which Operating System the generated code will
     62  *  run.  Indention is used to show which conditionals are evolutionary subclasses.
     63  *
     64  *  The MAC/WIN32/UNIX conditionals are mutually exclusive.
     65  *  The IOS/TV/WATCH/VISION conditionals are mutually exclusive.
     66  *
     67  *    TARGET_OS_WIN32              - Generated code will run on WIN32 API
     68  *    TARGET_OS_WINDOWS            - Generated code will run on Windows
     69  *    TARGET_OS_UNIX               - Generated code will run on some Unix (not macOS)
     70  *    TARGET_OS_LINUX              - Generated code will run on Linux
     71  *    TARGET_OS_MAC                - Generated code will run on a variant of macOS
     72  *      TARGET_OS_OSX                - Generated code will run on macOS
     73  *      TARGET_OS_IPHONE             - Generated code will run on a variant of iOS (firmware, devices, simulator)
     74  *        TARGET_OS_IOS                - Generated code will run on iOS
     75  *          TARGET_OS_MACCATALYST        - Generated code will run on macOS
     76  *        TARGET_OS_TV                 - Generated code will run on tvOS
     77  *        TARGET_OS_WATCH              - Generated code will run on watchOS
     78  *        TARGET_OS_VISION             - Generated code will run on visionOS
     79  *        TARGET_OS_BRIDGE             - Generated code will run on bridge devices
     80  *      TARGET_OS_SIMULATOR          - Generated code will run on an iOS, tvOS, watchOS, or visionOS simulator
     81  *      TARGET_OS_DRIVERKIT          - Generated code will run on macOS, iOS, tvOS, watchOS, or visionOS
     82  *
     83  *    TARGET_OS_EMBEDDED           - DEPRECATED: Use TARGET_OS_IPHONE and/or TARGET_OS_SIMULATOR instead
     84  *    TARGET_IPHONE_SIMULATOR      - DEPRECATED: Same as TARGET_OS_SIMULATOR
     85  *    TARGET_OS_NANO               - DEPRECATED: Same as TARGET_OS_WATCH
     86  *
     87  *    +--------------------------------------------------------------------------------------+
     88  *    |                                    TARGET_OS_MAC                                     |
     89  *    | +-----+ +------------------------------------------------------------+ +-----------+ |
     90  *    | |     | |                  TARGET_OS_IPHONE                          | |           | |
     91  *    | |     | | +-----------------+ +----+ +-------+ +--------+ +--------+ | |           | |
     92  *    | |     | | |       IOS       | |    | |       | |        | |        | | |           | |
     93  *    | | OSX | | | +-------------+ | | TV | | WATCH | | BRIDGE | | VISION | | | DRIVERKIT | |
     94  *    | |     | | | | MACCATALYST | | |    | |       | |        | |        | | |           | |
     95  *    | |     | | | +-------------+ | |    | |       | |        | |        | | |           | |
     96  *    | |     | | +-----------------+ +----+ +-------+ +--------+ +--------+ | |           | |
     97  *    | +-----+ +------------------------------------------------------------+ +-----------+ |
     98  *    +--------------------------------------------------------------------------------------+
     99  */
    100 
    101 /*
    102  *  TARGET_RT_*
    103  *
    104  *  These conditionals specify in which runtime the generated code will
    105  *  run. This is needed when the OS and CPU support more than one runtime
    106  *  (e.g. Mac OS X supports CFM and mach-o).
    107  *
    108  *      TARGET_RT_LITTLE_ENDIAN - Generated code uses little endian format for integers
    109  *      TARGET_RT_BIG_ENDIAN    - Generated code uses big endian format for integers
    110  *      TARGET_RT_64_BIT        - Generated code uses 64-bit pointers
    111  *      TARGET_RT_MAC_CFM       - TARGET_OS_MAC is true and CFM68K or PowerPC CFM (TVectors) are used
    112  *      TARGET_RT_MAC_MACHO     - TARGET_OS_MAC is true and Mach-O/dlyd runtime is used
    113  */
    114  
    115 /*
    116  * TARGET_OS conditionals can be enabled via clang preprocessor extensions:
    117  *
    118  *      __is_target_arch
    119  *      __is_target_vendor
    120  *      __is_target_os
    121  *      __is_target_environment
    122  *
    123  *  "-target=x86_64-apple-ios12-macabi"
    124  *      TARGET_OS_MAC=1
    125  *      TARGET_OS_IPHONE=1
    126  *      TARGET_OS_IOS=1
    127  *      TARGET_OS_MACCATALYST=1
    128  *
    129  *  "-target=x86_64-apple-ios12-simulator"
    130  *      TARGET_OS_MAC=1
    131  *      TARGET_OS_IPHONE=1
    132  *      TARGET_OS_IOS=1
    133  *      TARGET_OS_SIMULATOR=1
    134  *
    135  * DYNAMIC_TARGETS_ENABLED indicates that the core TARGET_OS macros were enabled via clang preprocessor extensions.
    136  * If this value is not set, the macro enablements will fall back to the static behavior.
    137  * It is disabled by default.
    138  */
    139 
    140 #if !defined(__has_extension) || !__has_extension(define_target_os_macros)
    141 #if defined(__has_builtin)
    142  #if __has_builtin(__is_target_arch)
    143   #if __has_builtin(__is_target_vendor)
    144    #if __has_builtin(__is_target_os)
    145     #if __has_builtin(__is_target_environment)
    146 
    147     /* "-target=x86_64-apple-ios12-macabi" */
    148     /* "-target=arm64-apple-ios12-macabi" */
    149     /* "-target=arm64e-apple-ios12-macabi" */
    150     #if (__is_target_arch(x86_64) || __is_target_arch(arm64) || __is_target_arch(arm64e)) && __is_target_vendor(apple) && __is_target_os(ios) && __is_target_environment(macabi)
    151         #define TARGET_OS_MAC               1
    152         #define TARGET_OS_IPHONE            1
    153         #define TARGET_OS_IOS               1
    154         #define TARGET_OS_MACCATALYST       1
    155         #define TARGET_OS_MACCATALYST            1
    156         #ifndef TARGET_OS_UIKITFORMAC
    157          #define TARGET_OS_UIKITFORMAC      1
    158         #endif
    159     #define TARGET_OS_UNIX                  0
    160     #define DYNAMIC_TARGETS_ENABLED         1
    161     #endif 
    162 
    163     /* "-target=x86_64-apple-ios12-simulator" */
    164     /* "-target=arm64-apple-ios12-simulator" */
    165     /* "-target=arm64e-apple-ios12-simulator" */
    166     #if (__is_target_arch(x86_64) || __is_target_arch(arm64) || __is_target_arch(arm64e)) && __is_target_vendor(apple) && __is_target_os(ios) && __is_target_environment(simulator)
    167         #define TARGET_OS_MAC               1
    168         #define TARGET_OS_IPHONE            1
    169         #define TARGET_OS_IOS               1
    170         #define TARGET_OS_SIMULATOR         1
    171         #define TARGET_OS_UNIX              0
    172         #define DYNAMIC_TARGETS_ENABLED     1
    173     #endif 
    174 
    175 
    176 
    177     /* "-target=arm64e-apple-xros1.0[-simulator]" */
    178     #if __is_target_vendor(apple) && __is_target_os(xros) && (!__is_target_environment(exclavekit) && !__is_target_environment(exclavecore))
    179         #define TARGET_OS_MAC               1
    180         #define TARGET_OS_IPHONE            1
    181 
    182         #if __is_target_environment(simulator)
    183           #define TARGET_OS_SIMULATOR        1
    184         #else
    185           #define TARGET_OS_EMBEDDED        1
    186         #endif
    187         #define TARGET_OS_VISION            1
    188         #define TARGET_OS_UNIX              0
    189         #define DYNAMIC_TARGETS_ENABLED     1
    190     #endif
    191 
    192     
    193     #if (__is_target_vendor(apple) && __is_target_environment(exclavecore))
    194         
    195         #define TARGET_OS_UNIX              0
    196         #define DYNAMIC_TARGETS_ENABLED     1
    197     #endif
    198 
    199     
    200     #if (__is_target_vendor(apple) && __is_target_environment(exclavekit))
    201         #define TARGET_OS_MAC               1
    202         
    203         #define TARGET_OS_UNIX              0
    204         #define DYNAMIC_TARGETS_ENABLED     1
    205     #endif
    206 
    207     /* "-target=x86_64-apple-driverkit19.0" */
    208     /* "-target=arm64-apple-driverkit19.0" */
    209     /* "-target=arm64e-apple-driverkit19.0" */
    210     #if __is_target_vendor(apple) && __is_target_os(driverkit)
    211         #define TARGET_OS_MAC               1
    212         #define TARGET_OS_DRIVERKIT         1
    213         #define TARGET_OS_UNIX              0
    214         #define DYNAMIC_TARGETS_ENABLED     1
    215     #endif
    216 
    217     #endif /* #if __has_builtin(__is_target_environment) */
    218    #endif /* #if __has_builtin(__is_target_os) */
    219   #endif /* #if __has_builtin(__is_target_vendor) */
    220  #endif /* #if __has_builtin(__is_target_arch) */
    221 #endif /* #if defined(__has_builtin) */
    222 
    223 #ifndef DYNAMIC_TARGETS_ENABLED
    224      #define DYNAMIC_TARGETS_ENABLED   0
    225 #endif /* DYNAMIC_TARGETS_ENABLED */
    226 
    227 /*
    228  *    gcc based compiler used on Mac OS X
    229  */
    230 #if defined(__GNUC__) && ( defined(__APPLE_CPP__) || defined(__APPLE_CC__) || defined(__MACOS_CLASSIC__) )
    231     #if !DYNAMIC_TARGETS_ENABLED
    232         #define TARGET_OS_MAC               1
    233         #define TARGET_OS_OSX               1
    234         #define TARGET_OS_IPHONE            0
    235 
    236         #define TARGET_OS_IOS               0
    237 
    238         #define TARGET_OS_WATCH             0
    239         
    240         #define TARGET_OS_TV                0
    241         #define TARGET_OS_MACCATALYST       0
    242         #define TARGET_OS_MACCATALYST            0
    243         #ifndef TARGET_OS_UIKITFORMAC
    244          #define TARGET_OS_UIKITFORMAC      0
    245         #endif
    246         #define TARGET_OS_SIMULATOR         0
    247         #define TARGET_OS_EMBEDDED          0 
    248         #define TARGET_OS_UNIX              0
    249     #endif
    250 
    251 /*
    252  *   CodeWarrior compiler from Metrowerks/Motorola
    253  */
    254 #elif defined(__MWERKS__)
    255     #define TARGET_OS_MAC               1
    256 
    257 /*
    258  *   unknown compiler
    259  */
    260 #else
    261     #define TARGET_OS_MAC                1
    262 #endif
    263 #endif /* !defined(__has_extension) || !__has_extension(define_target_os_macros) */
    264 
    265 // This has to always be defined in the header due to limitations in define_target_os_macros
    266 #define TARGET_OS_RTKIT             0
    267 
    268 /*
    269  *    gcc based compiler used on Mac OS X
    270  */
    271 #if defined(__GNUC__) && ( defined(__APPLE_CPP__) || defined(__APPLE_CC__) || defined(__MACOS_CLASSIC__) )
    272     #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
    273         #define TARGET_RT_LITTLE_ENDIAN 1
    274         #define TARGET_RT_BIG_ENDIAN    0
    275     #else
    276         #define TARGET_RT_LITTLE_ENDIAN 0
    277         #define TARGET_RT_BIG_ENDIAN    1
    278     #endif
    279     #if __LP64__
    280         #define TARGET_RT_64_BIT        1
    281     #else
    282         #define TARGET_RT_64_BIT        0
    283     #endif
    284     #if defined(__ppc__) && __MACOS_CLASSIC__
    285         #define TARGET_RT_MAC_CFM       1
    286         #define TARGET_RT_MAC_MACHO     0
    287     #else
    288         #define TARGET_RT_MAC_CFM       0
    289         #define TARGET_RT_MAC_MACHO     1
    290     #endif
    291 
    292 /*
    293  *   CodeWarrior compiler from Metrowerks/Motorola
    294  */
    295 #elif defined(__MWERKS__)
    296     #if defined(__POWERPC__)
    297         #define TARGET_RT_LITTLE_ENDIAN 0
    298         #define TARGET_RT_BIG_ENDIAN    1
    299     #elif defined(__INTEL__)
    300         #define TARGET_RT_LITTLE_ENDIAN 1
    301         #define TARGET_RT_BIG_ENDIAN    0
    302     #else
    303         #error unknown Metrowerks CPU type
    304     #endif
    305     #define TARGET_RT_64_BIT            0
    306     #ifdef __MACH__
    307         #define TARGET_RT_MAC_CFM       0
    308         #define TARGET_RT_MAC_MACHO     1
    309     #else
    310         #define TARGET_RT_MAC_CFM       1
    311         #define TARGET_RT_MAC_MACHO     0
    312     #endif
    313 
    314 /*
    315  *   unknown compiler
    316  */
    317 #else
    318     #if TARGET_CPU_PPC || TARGET_CPU_PPC64
    319         #define TARGET_RT_BIG_ENDIAN     1
    320         #define TARGET_RT_LITTLE_ENDIAN  0
    321     #else
    322         #define TARGET_RT_BIG_ENDIAN     0
    323         #define TARGET_RT_LITTLE_ENDIAN  1
    324     #endif
    325     #if TARGET_CPU_PPC64 || TARGET_CPU_X86_64
    326         #define TARGET_RT_64_BIT         1
    327     #else
    328         #define TARGET_RT_64_BIT         0
    329     #endif
    330     #ifdef __MACH__
    331         #define TARGET_RT_MAC_MACHO      1
    332         #define TARGET_RT_MAC_CFM        0
    333     #else
    334         #define TARGET_RT_MAC_MACHO      0
    335         #define TARGET_RT_MAC_CFM        1
    336     #endif
    337 #endif
    338 
    339 /*
    340  *   __is_target_arch based defines
    341  */
    342 #if defined(__has_builtin) && __has_builtin(__is_target_arch)
    343     #if __is_target_arch(arm64)  || __is_target_arch(arm64e) || __is_target_arch(arm64_32)
    344         #define TARGET_CPU_ARM64        1
    345     #elif __is_target_arch(arm)
    346         #define TARGET_CPU_ARM          1
    347     #elif __is_target_arch(x86_64)
    348         #define TARGET_CPU_X86_64       1
    349     #elif __is_target_arch(i386)
    350         #define TARGET_CPU_X86          1
    351     #else
    352 
    353             #error unrecognized arch using compiler with __is_target_arch support
    354 
    355     #endif
    356 
    357 /*
    358  *   GCC and older clang fallback
    359  */
    360 #elif defined(__GNUC__) && ( defined(__APPLE_CPP__) || defined(__APPLE_CC__) || defined(__MACOS_CLASSIC__) )
    361     #if defined(__ppc__)
    362         #define TARGET_CPU_PPC          1
    363     #elif defined(__ppc64__)
    364         #define TARGET_CPU_PPC64        1
    365     #elif defined(__i386__)
    366         #define TARGET_CPU_X86          1
    367     #elif defined(__x86_64__)
    368         #define TARGET_CPU_X86_64       1
    369     #elif defined(__arm__)
    370         #define TARGET_CPU_ARM          1
    371     #elif defined(__arm64__)
    372         #define TARGET_CPU_ARM64        1
    373     #else
    374         #error unrecognized GNU C compiler
    375     #endif
    376 
    377 /*
    378  *   CodeWarrior compiler from Metrowerks/Motorola
    379  */
    380 #elif defined(__MWERKS__)
    381     #if defined(__POWERPC__)
    382         #define TARGET_CPU_PPC          1
    383     #elif defined(__INTEL__)
    384         #define TARGET_CPU_X86          1
    385     #else
    386         #error unknown Metrowerks CPU type
    387     #endif
    388 
    389 /*
    390  *   unknown compiler
    391  */
    392 #else
    393     #if !defined(TARGET_CPU_PPC) && !defined(TARGET_CPU_PPC64)      \
    394         && !defined(TARGET_CPU_X86) && !defined(TARGET_CPU_X86_64)  \
    395         && !defined(TARGET_CPU_ARM) && !defined(TARGET_CPU_ARM64)
    396         /*
    397             TargetConditionals.h is designed to be plug-and-play.  It auto detects
    398             which compiler is being run and configures the TARGET_ conditionals
    399             appropriately.
    400 
    401             The short term work around is to set the TARGET_CPU_ and TARGET_OS_
    402             on the command line to the compiler (e.g. -DTARGET_CPU_MIPS=1 -DTARGET_OS_UNIX=1)
    403 
    404             The long term solution is to add suppport for __is_target_arch and __is_target_os
    405             to your compiler.
    406         */
    407         #error TargetConditionals.h: unknown compiler (see comment above)
    408     #endif
    409 #endif
    410 
    411 
    412 
    413 // Make sure all TARGET_OS_* and TARGET_CPU_* values are defined
    414 #ifndef TARGET_OS_MAC
    415     #define TARGET_OS_MAC        0
    416 #endif
    417 
    418 #ifndef TARGET_OS_OSX
    419     #define TARGET_OS_OSX        0
    420 #endif
    421 
    422 #ifndef TARGET_OS_IPHONE
    423     #define TARGET_OS_IPHONE     0
    424 #endif
    425 
    426 #ifndef TARGET_OS_IOS
    427     #define TARGET_OS_IOS        0
    428 #endif
    429 
    430 #ifndef TARGET_OS_WATCH
    431     #define TARGET_OS_WATCH      0
    432 #endif
    433 
    434 #ifndef TARGET_OS_TV
    435     #define TARGET_OS_TV         0
    436 #endif
    437 
    438 #ifndef TARGET_OS_SIMULATOR
    439     #define TARGET_OS_SIMULATOR  0
    440 #endif
    441 
    442 #ifndef TARGET_OS_EMBEDDED
    443     #define TARGET_OS_EMBEDDED   0
    444 #endif
    445 
    446 #ifndef TARGET_OS_RTKIT
    447     #define TARGET_OS_RTKIT      0
    448 #endif
    449 
    450 #ifndef TARGET_OS_MACCATALYST
    451     #define TARGET_OS_MACCATALYST 0
    452 #endif
    453 
    454 #ifndef TARGET_OS_VISION
    455     #define TARGET_OS_VISION     0
    456 #endif
    457 
    458 #ifndef TARGET_OS_UIKITFORMAC
    459     #define TARGET_OS_UIKITFORMAC 0
    460 #endif
    461 
    462 #ifndef TARGET_OS_DRIVERKIT
    463     #define TARGET_OS_DRIVERKIT 0
    464 #endif 
    465 
    466 #ifndef TARGET_OS_WIN32
    467     #define TARGET_OS_WIN32     0
    468 #endif
    469 
    470 #ifndef TARGET_OS_WINDOWS
    471     #define TARGET_OS_WINDOWS   0
    472 #endif
    473 
    474 
    475 
    476 #ifndef TARGET_OS_LINUX
    477     #define TARGET_OS_LINUX     0
    478 #endif
    479 
    480 #ifndef TARGET_CPU_PPC
    481     #define TARGET_CPU_PPC      0
    482 #endif
    483 
    484 #ifndef TARGET_CPU_PPC64
    485     #define TARGET_CPU_PPC64    0
    486 #endif
    487 
    488 #ifndef TARGET_CPU_68K
    489     #define TARGET_CPU_68K      0
    490 #endif
    491 
    492 #ifndef TARGET_CPU_X86
    493     #define TARGET_CPU_X86      0
    494 #endif
    495 
    496 #ifndef TARGET_CPU_X86_64
    497     #define TARGET_CPU_X86_64   0
    498 #endif
    499 
    500 #ifndef TARGET_CPU_ARM
    501     #define TARGET_CPU_ARM      0
    502 #endif
    503 
    504 #ifndef TARGET_CPU_ARM64
    505     #define TARGET_CPU_ARM64    0
    506 #endif
    507 
    508 #ifndef TARGET_CPU_MIPS
    509     #define TARGET_CPU_MIPS     0
    510 #endif
    511 
    512 #ifndef TARGET_CPU_SPARC
    513     #define TARGET_CPU_SPARC    0
    514 #endif
    515 
    516 #ifndef TARGET_CPU_ALPHA
    517     #define TARGET_CPU_ALPHA    0
    518 #endif
    519 
    520 #ifndef TARGET_ABI_USES_IOS_VALUES
    521     #define TARGET_ABI_USES_IOS_VALUES  (!TARGET_CPU_X86_64 || (TARGET_OS_IPHONE && !TARGET_OS_MACCATALYST))
    522 #endif
    523 
    524 #ifndef TARGET_IPHONE_SIMULATOR
    525     #define TARGET_IPHONE_SIMULATOR     TARGET_OS_SIMULATOR /* deprecated */
    526 #endif
    527 
    528 #ifndef TARGET_OS_NANO
    529     #define TARGET_OS_NANO              TARGET_OS_WATCH /* deprecated */
    530 #endif
    531 
    532 
    533 
    534 #endif  /* __TARGETCONDITIONALS__ */