aboutsummaryrefslogtreecommitdiff
path: root/src/target.hpp
blob: 614b0627d522bff8c6c3537a137805e0b8b8114b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Copyright (c) 2016 Andrew Kelley
 *
 * This file is part of zig, which is MIT licensed.
 * See http://opensource.org/licenses/MIT
 */

#ifndef ZIG_TARGET_HPP
#define ZIG_TARGET_HPP

#include <zig_llvm.h>

struct Buf;

struct ArchType {
    ZigLLVM_ArchType arch;
    ZigLLVM_SubArchType sub_arch;
};

enum Os {
    OsFreestanding,
    OsAnanas,
    OsCloudABI,
    OsDragonFly,
    OsFreeBSD,
    OsFuchsia,
    OsIOS,
    OsKFreeBSD,
    OsLinux,
    OsLv2,        // PS3
    OsMacOSX,
    OsNetBSD,
    OsOpenBSD,
    OsSolaris,
    OsWindows,
    OsHaiku,
    OsMinix,
    OsRTEMS,
    OsNaCl,       // Native Client
    OsCNK,        // BG/P Compute-Node Kernel
    OsBitrig,
    OsAIX,
    OsCUDA,       // NVIDIA CUDA
    OsNVCL,       // NVIDIA OpenCL
    OsAMDHSA,     // AMD HSA Runtime
    OsPS4,
    OsELFIAMCU,
    OsTvOS,       // Apple tvOS
    OsWatchOS,    // Apple watchOS
    OsMesa3D,
    OsContiki,
    OsZen,
};

struct ZigTarget {
    ArchType arch;
    ZigLLVM_VendorType vendor;
    Os os;
    ZigLLVM_EnvironmentType env_type;
    ZigLLVM_ObjectFormatType oformat;
};

enum CIntType {
    CIntTypeShort,
    CIntTypeUShort,
    CIntTypeInt,
    CIntTypeUInt,
    CIntTypeLong,
    CIntTypeULong,
    CIntTypeLongLong,
    CIntTypeULongLong,

    CIntTypeCount,
};

size_t target_arch_count(void);
const ArchType *get_target_arch(size_t index);
void get_arch_name(char *out_str, const ArchType *arch);

size_t target_vendor_count(void);
ZigLLVM_VendorType get_target_vendor(size_t index);

size_t target_os_count(void);
Os get_target_os(size_t index);
const char *get_target_os_name(Os os_type);

size_t target_environ_count(void);
ZigLLVM_EnvironmentType get_target_environ(size_t index);


size_t target_oformat_count(void);
const ZigLLVM_ObjectFormatType get_target_oformat(size_t index);
const char *get_target_oformat_name(ZigLLVM_ObjectFormatType oformat);

void get_native_target(ZigTarget *target);
void get_unknown_target(ZigTarget *target);

int parse_target_arch(const char *str, ArchType *arch);
int parse_target_os(const char *str, Os *os);
int parse_target_environ(const char *str, ZigLLVM_EnvironmentType *env_type);

void init_all_targets(void);

void get_target_triple(Buf *triple, const ZigTarget *target);

void resolve_target_object_format(ZigTarget *target);

uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id);

const char *target_o_file_ext(ZigTarget *target);
const char *target_asm_file_ext(ZigTarget *target);
const char *target_llvm_ir_file_ext(ZigTarget *target);
const char *target_exe_file_ext(ZigTarget *target);

Buf *target_dynamic_linker(ZigTarget *target);

bool target_can_exec(const ZigTarget *host_target, const ZigTarget *guest_target);


#endif