dlx/images-body.vhdl

    1 --------------------------------------------------------------------------
    2 --
    3 --  Copyright (C) 1993, Peter J. Ashenden
    4 --  Mail:	Dept. Computer Science
    5 --		University of Adelaide, SA 5005, Australia
    6 --  e-mail:	petera@cs.adelaide.edu.au
    7 --
    8 --  This program is free software; you can redistribute it and/or modify
    9 --  it under the terms of the GNU General Public License as published by
   10 --  the Free Software Foundation; either version 1, or (at your option)
   11 --  any later version.
   12 --
   13 --  This program is distributed in the hope that it will be useful,
   14 --  but WITHOUT ANY WARRANTY; without even the implied warranty of
   15 --  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16 --  GNU General Public License for more details.
   17 --
   18 --  You should have received a copy of the GNU General Public License
   19 --  along with this program; if not, write to the Free Software
   20 --  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   21 --
   22 --------------------------------------------------------------------------
   23 --
   24 --  $RCSfile: images-body.vhdl,v $  $Revision: 1.1 $  $Date: 2000/05/08 14:36:48 $
   25 --
   26 --------------------------------------------------------------------------
   27 --
   28 --  Images package body.
   29 --
   30 --  Functions that return the string image of values.
   31 --  Each image is a correctly formed literal according to the
   32 --  rules of VHDL-93.
   33 --
   34 --------------------------------------------------------------------------
   35 
   36 package body images is
   37 
   38 
   39   -- Image of bit vector as binary bit string literal
   40   -- (in the format B"...")
   41   -- Length of result is bv'length + 3
   42 
   43   function image (bv : in bit_vector) return string is
   44 
   45     alias bv_norm : bit_vector(1 to bv'length) is bv;
   46     variable result : string(1 to bv'length + 3);
   47 
   48   begin
   49     result(1) := 'B';
   50     result(2) := '"';
   51     for index in bv_norm'range loop
   52       if bv_norm(index) = '0' then
   53         result(index + 2) := '0';
   54       else
   55         result(index + 2) := '1';
   56       end if;
   57     end loop;
   58     result(bv'length + 3) := '"';
   59     return result;
   60   end image;
   61 
   62   ----------------------------------------------------------------
   63 
   64   -- Image of bit vector as octal bit string literal
   65   -- (in the format O"...")
   66   -- Length of result is (bv'length+2)/3 + 3
   67 
   68   function image_octal (bv : in bit_vector) return string is
   69 
   70     constant nr_digits : natural := (bv'length + 2) / 3;
   71     variable result : string(1 to nr_digits + 3);
   72     variable bits : bit_vector(0 to 3*nr_digits - 1) := (others => '0');
   73     variable three_bits : bit_vector(0 to 2);
   74     variable digit : character;
   75 
   76   begin
   77     result(1) := 'O';
   78     result(2) := '"';
   79     bits(bits'right - bv'length + 1 to bits'right) := bv;
   80     for index in 0 to nr_digits - 1 loop
   81       three_bits := bits(3*index to 3*index + 2);
   82       case three_bits is
   83         when b"000" =>
   84           digit := '0';
   85         when b"001" =>
   86           digit := '1';
   87         when b"010" =>
   88           digit := '2';
   89         when b"011" =>
   90           digit := '3';
   91         when b"100" =>
   92           digit := '4';
   93         when b"101" =>
   94           digit := '5';
   95         when b"110" =>
   96           digit := '6';
   97         when b"111" =>
   98           digit := '7';
   99         end case;
  100       result(index + 3) := digit;
  101     end loop;
  102     result(nr_digits + 3) := '"';
  103     return result;
  104   end image_octal;
  105 
  106   ----------------------------------------------------------------
  107 
  108   -- Image of bit vector as hex bit string literal
  109   -- (in the format X"...")
  110   -- Length of result is (bv'length+3)/4 + 3
  111 
  112   function image_hex (bv : in bit_vector) return string is
  113 
  114     constant nr_digits : natural := (bv'length + 3) / 4;
  115     variable result : string(1 to nr_digits + 3);
  116     variable bits : bit_vector(0 to 4*nr_digits - 1) := (others => '0');
  117     variable four_bits : bit_vector(0 to 3);
  118     variable digit : character;
  119 
  120   begin
  121     result(1) := 'X';
  122     result(2) := '"';
  123     bits(bits'right - bv'length + 1 to bits'right) := bv;
  124     for index in 0 to nr_digits - 1 loop
  125       four_bits := bits(4*index to 4*index + 3);
  126       case four_bits is
  127         when b"0000" =>
  128           digit := '0';
  129         when b"0001" =>
  130           digit := '1';
  131         when b"0010" =>
  132           digit := '2';
  133         when b"0011" =>
  134           digit := '3';
  135         when b"0100" =>
  136           digit := '4';
  137         when b"0101" =>
  138           digit := '5';
  139         when b"0110" =>
  140           digit := '6';
  141         when b"0111" =>
  142           digit := '7';
  143         when b"1000" =>
  144           digit := '8';
  145         when b"1001" =>
  146           digit := '9';
  147         when b"1010" =>
  148           digit := 'A';
  149         when b"1011" =>
  150           digit := 'B';
  151         when b"1100" =>
  152           digit := 'C';
  153         when b"1101" =>
  154           digit := 'D';
  155         when b"1110" =>
  156           digit := 'E';
  157         when b"1111" =>
  158           digit := 'F';
  159         end case;
  160       result(index + 3) := digit;
  161     end loop;
  162     result(nr_digits + 3) := '"';
  163     return result;
  164   end image_hex;
  165 
  166 
  167 end images;
  168 

This page was generated using GHDL 0.14 (20040829) [Sokcho edition], a program written by Tristan Gingold