]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_utils/common.rs
Moved Backend interface into rustc_codegen_utils
[rust.git] / src / librustc_codegen_utils / common.rs
1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10 #![allow(non_camel_case_types, non_snake_case)]
11
12 use rustc::ty::{self, Ty, TyCtxt};
13 use syntax_pos::DUMMY_SP;
14
15
16 pub fn type_needs_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
17     ty.needs_drop(tcx, ty::ParamEnv::reveal_all())
18 }
19
20 pub fn type_is_sized<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
21     ty.is_sized(tcx.at(DUMMY_SP), ty::ParamEnv::reveal_all())
22 }
23
24 pub fn type_is_freeze<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
25     ty.is_freeze(tcx, ty::ParamEnv::reveal_all(), DUMMY_SP)
26 }
27
28 pub enum IntPredicate {
29     IntEQ,
30     IntNE,
31     IntUGT,
32     IntUGE,
33     IntULT,
34     IntULE,
35     IntSGT,
36     IntSGE,
37     IntSLT,
38     IntSLE
39 }
40
41
42 #[allow(dead_code)]
43 pub enum RealPredicate {
44     RealPredicateFalse,
45     RealOEQ,
46     RealOGT,
47     RealOGE,
48     RealOLT,
49     RealOLE,
50     RealONE,
51     RealORD,
52     RealUNO,
53     RealUEQ,
54     RealUGT,
55     RealUGE,
56     RealULT,
57     RealULE,
58     RealUNE,
59     RealPredicateTrue
60 }
61
62 pub enum AtomicRmwBinOp {
63     AtomicXchg,
64     AtomicAdd,
65     AtomicSub,
66     AtomicAnd,
67     AtomicNand,
68     AtomicOr,
69     AtomicXor,
70     AtomicMax,
71     AtomicMin,
72     AtomicUMax,
73     AtomicUMin
74 }
75
76 pub enum AtomicOrdering {
77     #[allow(dead_code)]
78     NotAtomic,
79     Unordered,
80     Monotonic,
81     // Consume,  // Not specified yet.
82     Acquire,
83     Release,
84     AcquireRelease,
85     SequentiallyConsistent,
86 }
87
88 pub enum SynchronizationScope {
89     // FIXME: figure out if this variant is needed at all.
90     #[allow(dead_code)]
91     Other,
92     SingleThread,
93     CrossThread,
94 }
95
96 #[derive(Copy, Clone, PartialEq, Debug)]
97 pub enum TypeKind {
98     Void,
99     Half,
100     Float,
101     Double,
102     X86_FP80,
103     FP128,
104     PPC_FP128,
105     Label,
106     Integer,
107     Function,
108     Struct,
109     Array,
110     Pointer,
111     Vector,
112     Metadata,
113     X86_MMX,
114     Token,
115 }
116
117 // FIXME(mw): Anything that is produced via DepGraph::with_task() must implement
118 //            the HashStable trait. Normally DepGraph::with_task() calls are
119 //            hidden behind queries, but CGU creation is a special case in two
120 //            ways: (1) it's not a query and (2) CGU are output nodes, so their
121 //            Fingerprints are not actually needed. It remains to be clarified
122 //            how exactly this case will be handled in the red/green system but
123 //            for now we content ourselves with providing a no-op HashStable
124 //            implementation for CGUs.
125 mod temp_stable_hash_impls {
126     use rustc_data_structures::stable_hasher::{StableHasherResult, StableHasher,
127                                                HashStable};
128     use ModuleCodegen;
129
130     impl<HCX, M> HashStable<HCX> for ModuleCodegen<M> {
131         fn hash_stable<W: StableHasherResult>(&self,
132                                               _: &mut HCX,
133                                               _: &mut StableHasher<W>) {
134             // do nothing
135         }
136     }
137 }