]> git.proxmox.com Git - rustc.git/blame - src/librustc_platform_intrinsics/lib.rs
Imported Upstream version 1.8.0+dfsg1
[rustc.git] / src / librustc_platform_intrinsics / lib.rs
CommitLineData
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
18extern crate rustc_llvm as llvm;
19extern crate rustc;
20
21use rustc::middle::ty;
22
23pub struct Intrinsic {
24 pub inputs: Vec<Type>,
25 pub output: Type,
26
27 pub definition: IntrinsicDef,
28}
29
30#[derive(Clone, Hash, Eq, PartialEq)]
31pub 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
40pub enum IntrinsicDef {
41 Named(&'static str),
42}
43
44fn i(width: u8) -> Type { Type::Integer(true, width, width) }
45fn i_(width: u8, llvm_width: u8) -> Type { Type::Integer(true, width, llvm_width) }
46fn u(width: u8) -> Type { Type::Integer(false, width, width) }
47#[allow(dead_code)]
48fn u_(width: u8, llvm_width: u8) -> Type { Type::Integer(false, width, llvm_width) }
49fn f(width: u8) -> Type { Type::Float(width) }
50fn v(x: Type, length: u8) -> Type { Type::Vector(Box::new(x), None, length) }
51fn v_(x: Type, bitcast: Type, length: u8) -> Type {
52 Type::Vector(Box::new(x), Some(Box::new(bitcast)), length)
53}
54fn agg(flatten: bool, types: Vec<Type>) -> Type {
55 Type::Aggregate(flatten, types)
56}
57fn p(const_: bool, elem: Type, llvm_elem: Option<Type>) -> Type {
58 Type::Pointer(Box::new(elem), llvm_elem.map(Box::new), const_)
59}
60fn void() -> Type {
61 Type::Void
62}
63
64mod x86;
65mod arm;
66mod aarch64;
67
68impl 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}