mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Add Int ty to SMIR
This commit is contained in:
parent
73e816e37c
commit
458ead41d6
@ -7,7 +7,7 @@
|
|||||||
//!
|
//!
|
||||||
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
|
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
|
||||||
|
|
||||||
use crate::stable_mir::ty::{RigidTy, TyKind};
|
use crate::stable_mir::ty::{IntTy, RigidTy, TyKind};
|
||||||
use crate::stable_mir::{self, Context};
|
use crate::stable_mir::{self, Context};
|
||||||
use rustc_middle::mir;
|
use rustc_middle::mir;
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
@ -72,7 +72,14 @@ impl<'tcx> Tables<'tcx> {
|
|||||||
match ty.kind() {
|
match ty.kind() {
|
||||||
ty::Bool => TyKind::RigidTy(RigidTy::Bool),
|
ty::Bool => TyKind::RigidTy(RigidTy::Bool),
|
||||||
ty::Char => TyKind::RigidTy(RigidTy::Char),
|
ty::Char => TyKind::RigidTy(RigidTy::Char),
|
||||||
ty::Int(_) => todo!(),
|
ty::Int(int_ty) => match int_ty {
|
||||||
|
ty::IntTy::Isize => TyKind::RigidTy(RigidTy::Int(IntTy::Isize)),
|
||||||
|
ty::IntTy::I8 => TyKind::RigidTy(RigidTy::Int(IntTy::I8)),
|
||||||
|
ty::IntTy::I16 => TyKind::RigidTy(RigidTy::Int(IntTy::I16)),
|
||||||
|
ty::IntTy::I32 => TyKind::RigidTy(RigidTy::Int(IntTy::I32)),
|
||||||
|
ty::IntTy::I64 => TyKind::RigidTy(RigidTy::Int(IntTy::I64)),
|
||||||
|
ty::IntTy::I128 => TyKind::RigidTy(RigidTy::Int(IntTy::I128)),
|
||||||
|
},
|
||||||
ty::Uint(_) => todo!(),
|
ty::Uint(_) => todo!(),
|
||||||
ty::Float(_) => todo!(),
|
ty::Float(_) => todo!(),
|
||||||
ty::Adt(_, _) => todo!(),
|
ty::Adt(_, _) => todo!(),
|
||||||
|
@ -18,5 +18,16 @@ pub enum TyKind {
|
|||||||
pub enum RigidTy {
|
pub enum RigidTy {
|
||||||
Bool,
|
Bool,
|
||||||
Char,
|
Char,
|
||||||
|
Int(IntTy),
|
||||||
Tuple(Vec<Ty>),
|
Tuple(Vec<Ty>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
pub enum IntTy {
|
||||||
|
Isize,
|
||||||
|
I8,
|
||||||
|
I16,
|
||||||
|
I32,
|
||||||
|
I64,
|
||||||
|
I128,
|
||||||
|
}
|
||||||
|
@ -67,7 +67,7 @@ fn test_stable_mir(tcx: TyCtxt<'_>) {
|
|||||||
|
|
||||||
let types = get_item(tcx, &items, (DefKind::Fn, "types")).unwrap();
|
let types = get_item(tcx, &items, (DefKind::Fn, "types")).unwrap();
|
||||||
let body = types.body();
|
let body = types.body();
|
||||||
assert_eq!(body.locals.len(), 3);
|
assert_eq!(body.locals.len(), 4);
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
body.locals[0].kind(),
|
body.locals[0].kind(),
|
||||||
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool)
|
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool)
|
||||||
@ -80,6 +80,10 @@ fn test_stable_mir(tcx: TyCtxt<'_>) {
|
|||||||
body.locals[2].kind(),
|
body.locals[2].kind(),
|
||||||
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Char)
|
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Char)
|
||||||
);
|
);
|
||||||
|
assert_matches!(
|
||||||
|
body.locals[3].kind(),
|
||||||
|
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Int(stable_mir::ty::IntTy::I32))
|
||||||
|
);
|
||||||
|
|
||||||
let drop = get_item(tcx, &items, (DefKind::Fn, "drop")).unwrap();
|
let drop = get_item(tcx, &items, (DefKind::Fn, "drop")).unwrap();
|
||||||
let body = drop.body();
|
let body = drop.body();
|
||||||
@ -171,7 +175,7 @@ fn generate_input(path: &str) -> std::io::Result<()> {
|
|||||||
x_64.wrapping_add(y_64)
|
x_64.wrapping_add(y_64)
|
||||||
}}
|
}}
|
||||||
|
|
||||||
pub fn types(b: bool, _: char) -> bool {{
|
pub fn types(b: bool, _: char, _: i32) -> bool {{
|
||||||
b
|
b
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user