raw
vtools_vpatch           1 with Interfaces; use Interfaces;
vtools_vpatch 2 package body Bits is
vtools_vpatch 3 -- helper functions
vtools_vpatch 4 procedure ToBitstream(S: in String; B: out Bitstream ) is
vtools_vpatch 5 V : Unsigned_8;
vtools_vpatch 6 Pos : Natural;
vtools_vpatch 7 begin
vtools_vpatch 8 Pos := B'First;
vtools_vpatch 9 for C of S loop
vtools_vpatch 10 V := Character'Pos( C );
vtools_vpatch 11 B( Pos ) := Bit( V and 1 );
vtools_vpatch 12 B( Pos + 1 ) := Bit( Shift_Right( V, 1 ) and 1 );
vtools_vpatch 13 B( Pos + 2 ) := Bit( Shift_Right( V, 2 ) and 1 );
vtools_vpatch 14 B( Pos + 3 ) := Bit( Shift_Right( V, 3 ) and 1 );
vtools_vpatch 15 B( Pos + 4 ) := Bit( Shift_Right( V, 4 ) and 1 );
vtools_vpatch 16 B( Pos + 5 ) := Bit( Shift_Right( V, 5 ) and 1 );
vtools_vpatch 17 B( Pos + 6 ) := Bit( Shift_Right( V, 6 ) and 1 );
vtools_vpatch 18 B( Pos + 7 ) := Bit( Shift_Right( V, 7 ) and 1 );
vtools_vpatch 19 Pos := Pos + 8;
vtools_vpatch 20 end loop;
vtools_vpatch 21 end ToBitstream;
vtools_vpatch 22
vtools_vpatch 23 procedure ToString(B: in Bitstream; S: out String ) is
vtools_vpatch 24 N : Natural;
vtools_vpatch 25 Pos : Natural;
vtools_vpatch 26 begin
vtools_vpatch 27 Pos := B'First;
vtools_vpatch 28 for I in S'Range loop
vtools_vpatch 29 N := Natural( B( Pos ) ) +
vtools_vpatch 30 Natural( B( Pos + 1 ) ) * 2 +
vtools_vpatch 31 Natural( B( Pos + 2 ) ) * 4 +
vtools_vpatch 32 Natural( B( Pos + 3 ) ) * 8 +
vtools_vpatch 33 Natural( B( Pos + 4 ) ) * 16 +
vtools_vpatch 34 Natural( B( Pos + 5 ) ) * 32 +
vtools_vpatch 35 Natural( B( Pos + 6 ) ) * 64 +
vtools_vpatch 36 Natural( B( Pos + 7 ) ) * 128;
vtools_vpatch 37 Pos := Pos + 8;
vtools_vpatch 38 S( I ) := Character'Val( N );
vtools_vpatch 39 end loop;
vtools_vpatch 40 end ToString;
vtools_vpatch 41
vtools_vpatch 42 -- direction translation of C function from vdiff
vtools_vpatch 43 procedure ToHex(B: in Bitstream; S: out String) is
vtools_vpatch 44 Bytes: String(1..B'Length/8);
vtools_vpatch 45 Hex_Digits: constant String := "0123456789abcdef";
vtools_vpatch 46 I: Positive := 1;
vtools_vpatch 47 V: Unsigned_8;
vtools_vpatch 48 X: Positive := 1;
vtools_vpatch 49 begin
vtools_vpatch 50 ToString(B, Bytes);
vtools_vpatch 51 for C of S loop
vtools_vpatch 52 V := Character'Pos(C);
vtools_vpatch 53 S(I) := Hex_Digits(Integer(Shift_Right(V, 4) + 1));
vtools_vpatch 54 I := I + 1;
vtools_vpatch 55 S(I) := Hex_Digits(Integer((V and 16#F#) + 1));
vtools_vpatch 56 I := I + 1;
vtools_vpatch 57 end loop;
vtools_vpatch 58 end;
vtools_vpatch 59
vtools_vpatch 60 function ToHex(B: in Bitstream) return String is
vtools_vpatch 61 S: String(1..B'Length/4);
vtools_vpatch 62 begin
vtools_vpatch 63 ToHex(B, S);
vtools_vpatch 64 return S;
vtools_vpatch 65 end;
vtools_vpatch 66
vtools_vpatch 67 end Bits;