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