]> git.lizzy.rs Git - rust.git/blob - src/librustc_platform_intrinsics/lib.rs
Register new snapshots
[rust.git] / src / librustc_platform_intrinsics / lib.rs
1 // Copyright 2015 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
11 #![crate_name = "rustc_platform_intrinsics"]
12 #![unstable(feature = "rustc_private", issue = "27812")]
13 #![crate_type = "dylib"]
14 #![crate_type = "rlib"]
15 #![feature(staged_api, rustc_private)]
16
17 extern crate rustc_llvm as llvm;
18 extern crate rustc;
19
20 use rustc::middle::ty;
21
22 pub struct Intrinsic {
23     pub inputs: Vec<Type>,
24     pub output: Type,
25
26     pub definition: IntrinsicDef,
27 }
28
29 #[derive(Clone, Hash, Eq, PartialEq)]
30 pub enum Type {
31     Void,
32     Integer(/* signed */ bool, u8, /* llvm width */ u8),
33     Float(u8),
34     Pointer(Box<Type>, Option<Box<Type>>, /* const */ bool),
35     Vector(Box<Type>, Option<Box<Type>>, u8),
36     Aggregate(bool, Vec<Type>),
37 }
38
39 pub enum IntrinsicDef {
40     Named(&'static str),
41 }
42
43 fn i(width: u8) -> Type { Type::Integer(true, width, width) }
44 fn i_(width: u8, llvm_width: u8) -> Type { Type::Integer(true, width, llvm_width) }
45 fn u(width: u8) -> Type { Type::Integer(false, width, width) }
46 #[allow(dead_code)]
47 fn u_(width: u8, llvm_width: u8) -> Type { Type::Integer(false, width, llvm_width) }
48 fn f(width: u8) -> Type { Type::Float(width) }
49 fn v(x: Type, length: u8) -> Type { Type::Vector(Box::new(x), None, length) }
50 fn v_(x: Type, bitcast: Type, length: u8) -> Type {
51     Type::Vector(Box::new(x), Some(Box::new(bitcast)), length)
52 }
53 fn agg(flatten: bool, types: Vec<Type>) -> Type {
54     Type::Aggregate(flatten, types)
55 }
56 fn p(const_: bool, elem: Type, llvm_elem: Option<Type>) -> Type {
57     Type::Pointer(Box::new(elem), llvm_elem.map(Box::new), const_)
58 }
59 fn void() -> Type {
60     Type::Void
61 }
62
63 mod x86;
64 mod arm;
65 mod aarch64;
66
67 impl Intrinsic {
68     pub fn find<'tcx>(tcx: &ty::ctxt<'tcx>, name: &str) -> Option<Intrinsic> {
69         if name.starts_with("x86_") {
70             x86::find(tcx, name)
71         } else if name.starts_with("arm_") {
72             arm::find(tcx, name)
73         } else if name.starts_with("aarch64_") {
74             aarch64::find(tcx, name)
75         } else {
76             None
77         }
78     }
79 }