⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 string_plus.bdy

📁 6端口寄存器IP内核VHDL源代码
💻 BDY
字号:
-- Source: T:/hwdev/generic/VHDL/string_plus.bdy
-- Designer: Tim Pagden    

-- Description: Extensions to the std.standard.string package to allow
-- conversion functions and mixed operators
 
-- Revision history: T:/hwdev/generic/etc/string_plus_bdy.dnh
-- 29.12.97 TP   0.0   created from string_plus.pkg

library IEEE;
library vfp;

package body string_plus is
  use std.textio.all;
  use IEEE.std_logic_1164.all;
  use vfp.integer_class.all;
  
  -- extensions to std.standard.character and std.standard.string
  -- character and string defined in std.standard

  function "&" (a: string; b: integer) return string is
    use std.textio.all;
    variable intline : line;
    variable b_string : string(1 to integer_charlength(b));
    variable op_string : string(1 to a'LENGTH+integer_charlength(b));
  begin
    write(intline, b);
    read(intline, b_string);
    op_string := a & b_string;
    deallocate(intline);
    return op_string;
  end "&";

  function to_character (                -- 
    a: std_ulogic                        -- 
  ) return character is                  -- 
    variable a_char : character;         -- 
  begin                                  -- 
    case a is                            -- 
      when 'U' => a_char := 'U';         -- 
      when 'X' => a_char := 'X';         -- 
      when '0' => a_char := '0';         -- 
      when '1' => a_char := '1';         -- 
      when 'W' => a_char := 'W';         -- 
      when 'L' => a_char := 'L';         -- 
      when 'H' => a_char := 'H';         -- 
      when 'Z' => a_char := 'Z';         -- 
      when '-' => a_char := '-';         -- 
    end case;                            -- 
    return a_char;                       -- 
  end to_character;                      -- 

  function to_string (      -- 29.11.95
    a: std_ulogic_vector
  ) return string is
    constant a_length : integer := a'length;
    variable a_str: string(1 to a'length);
    variable a_copy: std_ulogic_vector(a'length-1 downto 0) := a;
    -- a copy is made of a because a may not use a 0-based index,
    -- it could be 7 downto 4, for example
  begin
    -- convert each bit of the vector to a char
    for i in 1 to a'length loop
      -- conversion is done by assigning from the msb of a_copy from the
      -- left downto the lsb so that the textual "image" of a_str follows
      -- that of a_copy and thus a itself. Without the length-i trick
      -- a_copy would effectively be reversed onto a_str as a_str is declared
      -- with a "to" range as opposed to a_copy's downto range.
      a_str(i) := to_character(std_ulogic(a_copy(a_length-i)));
    end loop;
    return a_str;
  end;  

  procedure write (
    l         : inout line;
    value     : in    std_ulogic_vector;
    justified : in    side  := right;
    field     : in    width := 0
  ) is
    variable a_str: string(1 to value'length);
  begin
    a_str := to_string(value);
    write (l, a_str, justified, field);
  end write;

end string_plus;



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -