zig

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

blob c0b04b80 (4648B) - Raw


      1 /*
      2  * Copyright (c) 2020 Andrew Kelley
      3  *
      4  * This file is part of zig, which is MIT licensed.
      5  * See http://opensource.org/licenses/MIT
      6  */
      7 
      8 // This file deals with exposing stage1 C++ code to stage2 Zig code.
      9 
     10 #ifndef ZIG_STAGE1_H
     11 #define ZIG_STAGE1_H
     12 
     13 #include "zig_llvm.h"
     14 
     15 #include <stddef.h>
     16 
     17 #ifdef __cplusplus
     18 #define ZIG_EXTERN_C extern "C"
     19 #else
     20 #define ZIG_EXTERN_C
     21 #endif
     22 
     23 // ABI warning
     24 enum ErrColor {
     25     ErrColorAuto,
     26     ErrColorOff,
     27     ErrColorOn,
     28 };
     29 
     30 // ABI warning
     31 enum CodeModel {
     32     CodeModelDefault,
     33     CodeModelTiny,
     34     CodeModelSmall,
     35     CodeModelKernel,
     36     CodeModelMedium,
     37     CodeModelLarge,
     38 };
     39 
     40 // ABI warning
     41 enum TargetSubsystem {
     42     TargetSubsystemConsole,
     43     TargetSubsystemWindows,
     44     TargetSubsystemPosix,
     45     TargetSubsystemNative,
     46     TargetSubsystemEfiApplication,
     47     TargetSubsystemEfiBootServiceDriver,
     48     TargetSubsystemEfiRom,
     49     TargetSubsystemEfiRuntimeDriver,
     50 
     51     // This means Zig should infer the subsystem.
     52     // It's last so that the indexes of other items can line up
     53     // with the enum in builtin.zig.
     54     TargetSubsystemAuto
     55 };
     56 
     57 
     58 // ABI warning
     59 // Synchronize with std.Target.Os.Tag and target.cpp::os_list
     60 enum Os {
     61     OsFreestanding,
     62     OsAnanas,
     63     OsCloudABI,
     64     OsDragonFly,
     65     OsFreeBSD,
     66     OsFuchsia,
     67     OsIOS,
     68     OsKFreeBSD,
     69     OsLinux,
     70     OsLv2,        // PS3
     71     OsMacOSX,
     72     OsNetBSD,
     73     OsOpenBSD,
     74     OsSolaris,
     75     OsWindows,
     76     OsZOS,
     77     OsHaiku,
     78     OsMinix,
     79     OsRTEMS,
     80     OsNaCl,       // Native Client
     81     OsAIX,
     82     OsCUDA,       // NVIDIA CUDA
     83     OsNVCL,       // NVIDIA OpenCL
     84     OsAMDHSA,     // AMD HSA Runtime
     85     OsPS4,
     86     OsELFIAMCU,
     87     OsTvOS,       // Apple tvOS
     88     OsWatchOS,    // Apple watchOS
     89     OsMesa3D,
     90     OsContiki,
     91     OsAMDPAL,
     92     OsHermitCore,
     93     OsHurd,
     94     OsWASI,
     95     OsEmscripten,
     96     OsUefi,
     97     OsOpenCL,
     98     OsGLSL450,
     99     OsVulkan,
    100     OsOther,
    101 };
    102 
    103 // ABI warning
    104 struct ZigTarget {
    105     enum ZigLLVM_ArchType arch;
    106     enum Os os;
    107     enum ZigLLVM_EnvironmentType abi;
    108 
    109     bool is_native_os;
    110     bool is_native_cpu;
    111 
    112     const char *llvm_cpu_name;
    113     const char *llvm_cpu_features;
    114 };
    115 
    116 // ABI warning
    117 struct Stage2Progress;
    118 // ABI warning
    119 struct Stage2ProgressNode;
    120 
    121 enum BuildMode {
    122     BuildModeDebug,
    123     BuildModeSafeRelease,
    124     BuildModeFastRelease,
    125     BuildModeSmallRelease,
    126 };
    127 
    128 
    129 struct ZigStage1Pkg {
    130     const char *name_ptr;
    131     size_t name_len;
    132 
    133     const char *path_ptr;
    134     size_t path_len;
    135 
    136     struct ZigStage1Pkg **children_ptr;
    137     size_t children_len;
    138 
    139     struct ZigStage1Pkg *parent;
    140 };
    141 
    142 // This struct is used by both main.cpp and stage1.zig.
    143 struct ZigStage1 {
    144     const char *root_name_ptr;
    145     size_t root_name_len;
    146 
    147     const char *emit_o_ptr;
    148     size_t emit_o_len;
    149 
    150     const char *emit_h_ptr;
    151     size_t emit_h_len;
    152 
    153     const char *emit_asm_ptr;
    154     size_t emit_asm_len;
    155 
    156     const char *emit_llvm_ir_ptr;
    157     size_t emit_llvm_ir_len;
    158 
    159     const char *emit_analysis_json_ptr;
    160     size_t emit_analysis_json_len;
    161 
    162     const char *emit_docs_ptr;
    163     size_t emit_docs_len;
    164 
    165     const char *builtin_zig_path_ptr;
    166     size_t builtin_zig_path_len;
    167 
    168     const char *test_filter_ptr;
    169     size_t test_filter_len;
    170 
    171     const char *test_name_prefix_ptr;
    172     size_t test_name_prefix_len;
    173 
    174     void *userdata;
    175     struct ZigStage1Pkg *root_pkg;
    176     struct Stage2ProgressNode *main_progress_node;
    177 
    178     enum CodeModel code_model;
    179     enum TargetSubsystem subsystem;
    180     enum ErrColor err_color;
    181 
    182     bool pic;
    183     bool pie;
    184     bool lto;
    185     bool link_libc;
    186     bool link_libcpp;
    187     bool strip;
    188     bool is_single_threaded;
    189     bool dll_export_fns;
    190     bool link_mode_dynamic;
    191     bool valgrind_enabled;
    192     bool tsan_enabled;
    193     bool function_sections;
    194     bool enable_stack_probing;
    195     bool red_zone;
    196     bool enable_time_report;
    197     bool enable_stack_report;
    198     bool test_is_evented;
    199     bool verbose_ir;
    200     bool verbose_llvm_ir;
    201     bool verbose_cimport;
    202     bool verbose_llvm_cpu_features;
    203 
    204     // Set by stage1
    205     bool have_c_main;
    206     bool have_winmain;
    207     bool have_wwinmain;
    208     bool have_winmain_crt_startup;
    209     bool have_wwinmain_crt_startup;
    210     bool have_dllmain_crt_startup;
    211 };
    212 
    213 ZIG_EXTERN_C void zig_stage1_os_init(void);
    214 
    215 ZIG_EXTERN_C struct ZigStage1 *zig_stage1_create(enum BuildMode optimize_mode,
    216     const char *main_pkg_path_ptr, size_t main_pkg_path_len,
    217     const char *root_src_path_ptr, size_t root_src_path_len,
    218     const char *zig_lib_dir_ptr, size_t zig_lib_dir_len,
    219     const struct ZigTarget *target, bool is_test_build);
    220 
    221 ZIG_EXTERN_C void zig_stage1_build_object(struct ZigStage1 *);
    222 
    223 ZIG_EXTERN_C void zig_stage1_destroy(struct ZigStage1 *);
    224 
    225 #endif