/* * MRustC - Rust Compiler * - By John Hodge (Mutabah/thePowersGang) * * trans/target.hpp * - Target-specific information */ #pragma once #include #include #include 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 BackendOptsC { CodegenMode m_codegen_mode; ::std::string m_c_compiler; // MSVC arch / GNU triplet ::std::vector< ::std::string> m_compiler_opts; ::std::vector< ::std::string> m_linker_opts; }; struct TargetSpec { ::std::string m_family; ::std::string m_os_name; ::std::string m_env_name; BackendOptsC m_backend_c; TargetArch m_arch; }; struct TypeRepr { size_t align = 0; size_t size = 0; struct FieldPath { size_t index; size_t size; ::std::vector sub_fields; }; TAGGED_UNION(VariantMode, None, (None, struct { }), // Tag is a fixed set of values in an offset. (Values, struct { FieldPath field; ::std::vector values; }), // Tag is based on a range of values //(Ranges, struct { // size_t offset; // size_t size; // ::std::vector<::std::pair> values; // }), // Tag is a boolean based on if a region is zero/non-zero // Only valid for two-element enums (NonZero, struct { FieldPath field; uint8_t zero_variant; }) ); VariantMode variants; struct Field { size_t offset; ::HIR::TypeRef ty; }; ::std::vector fields; }; extern const TargetSpec& Target_GetCurSpec(); extern void Target_SetCfg(const ::std::string& target_name); extern void Target_ExportCurSpec(const ::std::string& filename); 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 bool Target_GetSizeAndAlignOf(const Span& sp, const StaticTraitResolve& resolve, const ::HIR::TypeRef& ty, size_t& out_size, size_t& out_align); extern const TypeRepr* Target_GetTypeRepr(const Span& sp, const StaticTraitResolve& resolve, const ::HIR::TypeRef& ty); extern const ::HIR::TypeRef& Target_GetInnerType(const Span& sp, const StaticTraitResolve& resolve, const TypeRepr& repr, size_t idx, const ::std::vector& sub_fields={}, size_t ofs=0);