@@ -10,7 +10,7 @@ mod value;
1010
1111pub  use  self :: error:: { EvalError ,  EvalResult ,  EvalErrorKind ,  AssertMessage } ; 
1212
13- pub  use  self :: value:: { PrimVal ,  PrimValKind ,  Value ,  Pointer } ; 
13+ pub  use  self :: value:: { PrimVal ,  PrimValKind ,  Value ,  Pointer ,   ConstValue } ; 
1414
1515use  std:: collections:: BTreeMap ; 
1616use  std:: fmt; 
@@ -20,8 +20,10 @@ use ty::{self, TyCtxt};
2020use  ty:: layout:: { self ,  Align ,  HasDataLayout } ; 
2121use  middle:: region; 
2222use  std:: iter; 
23+ use  std:: io; 
2324use  syntax:: ast:: Mutability ; 
2425use  rustc_serialize:: { Encoder ,  Decoder ,  Decodable ,  Encodable } ; 
26+ use  byteorder:: { WriteBytesExt ,  ReadBytesExt ,  LittleEndian ,  BigEndian } ; 
2527
2628#[ derive( Clone ,  Debug ,  PartialEq ,  RustcEncodable ,  RustcDecodable ) ]  
2729pub  enum  Lock  { 
@@ -235,7 +237,7 @@ impl fmt::Display for AllocId {
235237    } 
236238} 
237239
238- #[ derive( Debug ,  Eq ,  PartialEq ,  Hash ,  RustcEncodable ,  RustcDecodable ) ]  
240+ #[ derive( Clone ,   Debug ,  Eq ,  PartialEq ,  Hash ,  RustcEncodable ,  RustcDecodable ) ]  
239241pub  struct  Allocation  { 
240242    /// The actual bytes of the allocation. 
241243/// Note that the bytes of a pointer represent the offset of the pointer 
@@ -254,17 +256,69 @@ pub struct Allocation {
254256} 
255257
256258impl  Allocation  { 
257-     pub  fn  from_bytes ( slice :  & [ u8 ] )  -> Self  { 
259+     pub  fn  from_bytes ( slice :  & [ u8 ] ,   align :   Align )  -> Self  { 
258260        let  mut  undef_mask = UndefMask :: new ( 0 ) ; 
259261        undef_mask. grow ( slice. len ( )  as  u64 ,  true ) ; 
260262        Self  { 
261263            bytes :  slice. to_owned ( ) , 
262264            relocations :  BTreeMap :: new ( ) , 
263265            undef_mask, 
264-             align :   Align :: from_bytes ( 1 ,   1 ) . unwrap ( ) , 
266+             align, 
265267            runtime_mutability :  Mutability :: Immutable , 
266268        } 
267269    } 
270+ 
271+     pub  fn  from_byte_aligned_bytes ( slice :  & [ u8 ] )  -> Self  { 
272+         Allocation :: from_bytes ( slice,  Align :: from_bytes ( 1 ,  1 ) . unwrap ( ) ) 
273+     } 
274+ 
275+     pub  fn  undef ( size :  u64 ,  align :  Align )  -> Self  { 
276+         assert_eq ! ( size as  usize  as  u64 ,  size) ; 
277+         Allocation  { 
278+             bytes :  vec ! [ 0 ;  size as  usize ] , 
279+             relocations :  BTreeMap :: new ( ) , 
280+             undef_mask :  UndefMask :: new ( size) , 
281+             align, 
282+             runtime_mutability :  Mutability :: Immutable , 
283+         } 
284+     } 
285+ } 
286+ 
287+ impl < ' tcx >  :: serialize:: UseSpecializedDecodable  for  & ' tcx  Allocation  { } 
288+ 
289+ //////////////////////////////////////////////////////////////////////////////// 
290+ // Methods to access integers in the target endianness 
291+ //////////////////////////////////////////////////////////////////////////////// 
292+ 
293+ pub  fn  write_target_uint ( 
294+     endianness :  layout:: Endian , 
295+     mut  target :  & mut  [ u8 ] , 
296+     data :  u128 , 
297+ )  -> Result < ( ) ,  io:: Error >  { 
298+     let  len = target. len ( ) ; 
299+     match  endianness { 
300+         layout:: Endian :: Little  => target. write_uint128 :: < LittleEndian > ( data,  len) , 
301+         layout:: Endian :: Big  => target. write_uint128 :: < BigEndian > ( data,  len) , 
302+     } 
303+ } 
304+ 
305+ pub  fn  write_target_int ( 
306+     endianness :  layout:: Endian , 
307+     mut  target :  & mut  [ u8 ] , 
308+     data :  i128 , 
309+ )  -> Result < ( ) ,  io:: Error >  { 
310+     let  len = target. len ( ) ; 
311+     match  endianness { 
312+         layout:: Endian :: Little  => target. write_int128 :: < LittleEndian > ( data,  len) , 
313+         layout:: Endian :: Big  => target. write_int128 :: < BigEndian > ( data,  len) , 
314+     } 
315+ } 
316+ 
317+ pub  fn  read_target_uint ( endianness :  layout:: Endian ,  mut  source :  & [ u8 ] )  -> Result < u128 ,  io:: Error >  { 
318+     match  endianness { 
319+         layout:: Endian :: Little  => source. read_uint128 :: < LittleEndian > ( source. len ( ) ) , 
320+         layout:: Endian :: Big  => source. read_uint128 :: < BigEndian > ( source. len ( ) ) , 
321+     } 
268322} 
269323
270324//////////////////////////////////////////////////////////////////////////////// 
0 commit comments