]> git.proxmox.com Git - rustc.git/blob - src/librustc_mir/build/misc.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / 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.
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 //! Miscellaneous builder routines that are not specific to building any particular
12 //! kind of thing.
13
14 use build::Builder;
15 use rustc::ty::Ty;
16 use rustc::mir::repr::*;
17 use std::u32;
18 use syntax::codemap::Span;
19
20 impl<'a,'tcx> Builder<'a,'tcx> {
21 /// Add a new temporary value of type `ty` storing the result of
22 /// evaluating `expr`.
23 ///
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);
33 lvalue
34 }
35
36 pub fn literal_operand(&mut self,
37 span: Span,
38 ty: Ty<'tcx>,
39 literal: Literal<'tcx>)
40 -> Operand<'tcx> {
41 let constant = Constant {
42 span: span,
43 ty: ty,
44 literal: literal,
45 };
46 Operand::Constant(constant)
47 }
48
49 pub fn push_usize(&mut self,
50 block: BasicBlock,
51 scope_id: ScopeId,
52 span: Span,
53 value: u64)
54 -> Lvalue<'tcx> {
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,
59 Constant {
60 span: span,
61 ty: self.hir.usize_ty(),
62 literal: self.hir.usize_literal(value),
63 });
64 temp
65 }
66 }