|
| 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 | + |
| 11 | +// force-host |
| 12 | + |
| 13 | +#![feature(plugin_registrar, rustc_private)] |
| 14 | +#![deny(plugin_as_library)] // should have no effect in a plugin crate |
| 15 | + |
| 16 | +extern crate rustc; |
| 17 | +extern crate rustc_plugin; |
| 18 | + |
| 19 | + |
| 20 | +use rustc::mir::*; |
| 21 | +use rustc::ty::{Ty, TyCtxt, FnSig, subst::Substs, }; |
| 22 | +use rustc_plugin::Registry; |
| 23 | + |
| 24 | +#[plugin_registrar] |
| 25 | +pub fn plugin_registrar(reg: &mut Registry) { |
| 26 | + let codegen = Box::new(GenericCountMismatch) as Box<_>; |
| 27 | + reg.register_intrinsic("generic_count_mismatch".into(), codegen); |
| 28 | + let codegen = Box::new(InputOutputMismatch) as Box<_>; |
| 29 | + reg.register_intrinsic("type_mismatch".into(), codegen); |
| 30 | +} |
| 31 | + |
| 32 | +struct GenericCountMismatch; |
| 33 | +impl PluginIntrinsicCodegen for GenericCountMismatch { |
| 34 | + fn codegen_simple_intrinsic<'a, 'tcx>(&self, |
| 35 | + _tcx: TyCtxt<'a, 'tcx, 'tcx>, |
| 36 | + _source_info: SourceInfo, |
| 37 | + _sig: &FnSig<'tcx>, |
| 38 | + _parent_mir: &Mir<'tcx>, |
| 39 | + _parent_param_substs: &'tcx Substs<'tcx>, |
| 40 | + _args: &Vec<Operand<'tcx>>, |
| 41 | + _dest: Place<'tcx>, |
| 42 | + _extra_stmts: &mut Vec<StatementKind<'tcx>>) |
| 43 | + where 'tcx: 'a, |
| 44 | + { |
| 45 | + unreachable!() |
| 46 | + } |
| 47 | + |
| 48 | + /// The number of generic parameters expected. |
| 49 | + fn generic_parameter_count<'a, 'tcx>(&self, _tcx: TyCtxt<'a, 'tcx, 'tcx>) -> usize { 5 } |
| 50 | + /// The types of the input args. |
| 51 | + fn inputs<'a, 'tcx>(&self, _tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Vec<Ty<'tcx>> { vec![] } |
| 52 | + /// The return type. |
| 53 | + fn output<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> { |
| 54 | + tcx.mk_nil() |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +struct InputOutputMismatch; |
| 59 | +impl PluginIntrinsicCodegen for InputOutputMismatch { |
| 60 | + fn codegen_simple_intrinsic<'a, 'tcx>(&self, |
| 61 | + _tcx: TyCtxt<'a, 'tcx, 'tcx>, |
| 62 | + _source_info: SourceInfo, |
| 63 | + _sig: &FnSig<'tcx>, |
| 64 | + _parent_mir: &Mir<'tcx>, |
| 65 | + _parent_param_substs: &'tcx Substs<'tcx>, |
| 66 | + _args: &Vec<Operand<'tcx>>, |
| 67 | + _dest: Place<'tcx>, |
| 68 | + _extra_stmts: &mut Vec<StatementKind<'tcx>>) |
| 69 | + where 'tcx: 'a, |
| 70 | + { |
| 71 | + unreachable!() |
| 72 | + } |
| 73 | + |
| 74 | + /// The number of generic parameters expected. |
| 75 | + fn generic_parameter_count<'a, 'tcx>(&self, _tcx: TyCtxt<'a, 'tcx, 'tcx>) -> usize { 0 } |
| 76 | + /// The types of the input args. |
| 77 | + fn inputs<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Vec<Ty<'tcx>> { |
| 78 | + vec![tcx.types.u64] |
| 79 | + } |
| 80 | + /// The return type. |
| 81 | + fn output<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> { |
| 82 | + tcx.types.u64 |
| 83 | + } |
| 84 | +} |
0 commit comments