summaryrefslogtreecommitdiff
path: root/src/trans/target.hpp
blob: 36e06d5792fb0ffd1dbdb14ad40f0c2a3d335f57 (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
/*
 * MRustC - Rust Compiler
 * - By John Hodge (Mutabah/thePowersGang)
 *
 * trans/target.hpp
 * - Target-specific information
 */
#pragma once

#include <cstddef>
#include <hir/type.hpp>
#include <hir_typeck/static.hpp>

enum class CodegenMode
{
    Gnu11,
    Msvc,
};

struct TargetArch
{
    ::std::string   m_name;
    unsigned    m_pointer_bits;
    bool    m_big_endian;

    struct {
        bool u8;
        bool u16;
        bool u32;
        bool u64;
        bool ptr;
    } m_atomics;
};
struct TargetSpec
{
    ::std::string   m_family;
    ::std::string   m_os_name;
    ::std::string   m_env_name;

    CodegenMode m_codegen_mode;
    TargetArch  m_arch;
};

struct StructRepr
{
    struct Ent {
        unsigned int    field_idx;
        size_t  size;
        size_t  align;
        ::HIR::TypeRef  ty;
    };
    // List of types, including padding (indicated by a UINT_MAX field idx)
    // Ordered as they would be emitted
    ::std::vector<Ent>  ents;
};

extern const TargetSpec& Target_GetCurSpec();
extern void Target_SetCfg(const ::std::string& target_name);
extern bool Target_GetSizeOf(const Span& sp, const StaticTraitResolve& resolve, const ::HIR::TypeRef& ty, size_t& out_size);
extern bool Target_GetAlignOf(const Span& sp, const StaticTraitResolve& resolve, const ::HIR::TypeRef& ty, size_t& out_align);
extern const StructRepr* Target_GetStructRepr(const Span& sp, const StaticTraitResolve& resolve, const ::HIR::TypeRef& struct_ty);