]>
git.proxmox.com Git - rustc.git/blob - src/librustc_mir/build/misc.rs
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.
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.
11 //! Miscellaneous builder routines that are not specific to building any particular
16 use rustc
::mir
::repr
::*;
18 use syntax
::codemap
::Span
;
20 impl<'a
,'tcx
> Builder
<'a
,'tcx
> {
21 /// Add a new temporary value of type `ty` storing the result of
22 /// evaluating `expr`.
24 /// NB: **No cleanup is scheduled for this temporary.** You should
25 /// call `schedule_drop` once the temporary is initialized.
26 pub fn temp(&mut self, ty
: Ty
<'tcx
>) -> Lvalue
<'tcx
> {
27 let index
= self.temp_decls
.len();
28 self.temp_decls
.push(TempDecl { ty: ty }
);
29 assert
!(index
< (u32::MAX
) as usize);
30 let lvalue
= Lvalue
::Temp(index
as u32);
31 debug
!("temp: created temp {:?} with type {:?}",
32 lvalue
, self.temp_decls
.last().unwrap().ty
);
36 pub fn literal_operand(&mut self,
39 literal
: Literal
<'tcx
>)
41 let constant
= Constant
{
46 Operand
::Constant(constant
)
49 pub fn push_usize(&mut self,
55 let usize_ty
= self.hir
.usize_ty();
56 let temp
= self.temp(usize_ty
);
57 self.cfg
.push_assign_constant(
58 block
, scope_id
, span
, &temp
,
61 ty
: self.hir
.usize_ty(),
62 literal
: self.hir
.usize_literal(value
),