2015-08-18 17:59:21 -04:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
|
|
//! Miscellaneous builder routines that are not specific to building any particular
|
|
|
|
|
//! kind of thing.
|
|
|
|
|
|
|
|
|
|
use build::Builder;
|
2016-03-22 17:30:57 +02:00
|
|
|
use rustc::ty::Ty;
|
2015-11-19 16:37:34 +01:00
|
|
|
use rustc::mir::repr::*;
|
2015-08-18 17:59:21 -04:00
|
|
|
use std::u32;
|
2015-10-05 12:31:48 -04:00
|
|
|
use syntax::codemap::Span;
|
2015-08-18 17:59:21 -04:00
|
|
|
|
2016-05-11 04:14:41 +03:00
|
|
|
impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
2015-08-18 17:59:21 -04:00
|
|
|
/// Add a new temporary value of type `ty` storing the result of
|
|
|
|
|
/// evaluating `expr`.
|
|
|
|
|
///
|
|
|
|
|
/// NB: **No cleanup is scheduled for this temporary.** You should
|
|
|
|
|
/// call `schedule_drop` once the temporary is initialized.
|
2015-10-05 12:31:48 -04:00
|
|
|
pub fn temp(&mut self, ty: Ty<'tcx>) -> Lvalue<'tcx> {
|
2015-08-18 17:59:21 -04:00
|
|
|
let index = self.temp_decls.len();
|
|
|
|
|
self.temp_decls.push(TempDecl { ty: ty });
|
|
|
|
|
assert!(index < (u32::MAX) as usize);
|
|
|
|
|
let lvalue = Lvalue::Temp(index as u32);
|
|
|
|
|
debug!("temp: created temp {:?} with type {:?}",
|
|
|
|
|
lvalue, self.temp_decls.last().unwrap().ty);
|
|
|
|
|
lvalue
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-21 17:29:50 -04:00
|
|
|
pub fn literal_operand(&mut self,
|
|
|
|
|
span: Span,
|
|
|
|
|
ty: Ty<'tcx>,
|
|
|
|
|
literal: Literal<'tcx>)
|
|
|
|
|
-> Operand<'tcx> {
|
2015-10-07 14:37:42 +02:00
|
|
|
let constant = Constant {
|
|
|
|
|
span: span,
|
|
|
|
|
ty: ty,
|
|
|
|
|
literal: literal,
|
|
|
|
|
};
|
2015-10-21 17:29:50 -04:00
|
|
|
Operand::Constant(constant)
|
2015-08-18 17:59:21 -04:00
|
|
|
}
|
|
|
|
|
|
2016-04-16 19:45:28 +12:00
|
|
|
pub fn unit_rvalue(&mut self) -> Rvalue<'tcx> {
|
|
|
|
|
Rvalue::Aggregate(AggregateKind::Tuple, vec![])
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-09 13:36:04 -05:00
|
|
|
pub fn push_usize(&mut self,
|
|
|
|
|
block: BasicBlock,
|
|
|
|
|
scope_id: ScopeId,
|
|
|
|
|
span: Span,
|
|
|
|
|
value: u64)
|
|
|
|
|
-> Lvalue<'tcx> {
|
2015-08-18 17:59:21 -04:00
|
|
|
let usize_ty = self.hir.usize_ty();
|
|
|
|
|
let temp = self.temp(usize_ty);
|
|
|
|
|
self.cfg.push_assign_constant(
|
2016-03-09 13:36:04 -05:00
|
|
|
block, scope_id, span, &temp,
|
2015-08-18 17:59:21 -04:00
|
|
|
Constant {
|
|
|
|
|
span: span,
|
2015-09-10 15:44:44 -04:00
|
|
|
ty: self.hir.usize_ty(),
|
|
|
|
|
literal: self.hir.usize_literal(value),
|
2015-08-18 17:59:21 -04:00
|
|
|
});
|
|
|
|
|
temp
|
|
|
|
|
}
|
|
|
|
|
}
|