📄 textio.vhd
字号:
-- File................: textio.vhd
-- Function............: Implements Basic Printing Routines for the Test Harness
-- Person Responsible..: I Bryant
-- Version.............: 5.11
-- Last Updated........: 8-24-98
-- Component of........:
-- Components Required.:
-- Compilation Notes...:
-- %d decimal
-- %h hexadecimal Integer or known vector
-- %x hexadecimal Integer or vector with X's
-- %b binary
-- %s string
--
-- Also Supports %6 i.e Width Field
-- %0 Fill with Zeros
--
-- Revision History:
-- Copyright 1998 by ACTEL
--
-- Functional Description:
--
library std;
use std.textio.all;
use work.misc.all;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
---------------------------------------------------------------------------
-- Declarations etc
--
package textio is
constant MAXSTRLEN : INTEGER := 128;
subtype TEXTSTR is string;
type T_NUMTYPE is ( NONE, INT, VECT, STRG);
--type line is access string;----SB
type T_FMT is record
f_type : T_NUMTYPE;
f_integer : INTEGER;
f_vector : DWORD;
f_length : INTEGER;
f_string : STRING (1 to MAXSTRLEN);
end record;
type T_FMT_ARRAY is array ( integer range <> ) of T_FMT;
function is01 ( v: std_logic) return BOOLEAN;
function is01 ( v: std_logic_vector; len : INTEGER) return BOOLEAN;
function strlen( str: STRING) return INTEGER;
function strcopy ( instr : STRING) return TEXTSTR;
function fmt ( x : INTEGER) return T_FMT;
function fmt ( x : std_logic_vector) return T_FMT;
function fmt ( x : string ) return T_FMT;
function fmt ( x : boolean ) return T_FMT;
function fmt ( x : std_logic) return T_FMT;
procedure printf( str : TEXTSTR; params : T_FMT_ARRAY);
procedure printf( str : TEXTSTR; params : T_FMT);
procedure printf( str : TEXTSTR );
procedure ifprintf( enable : BOOLEAN; str : TEXTSTR; params : T_FMT_ARRAY);
procedure ifprintf( enable : BOOLEAN; str : TEXTSTR; params : T_FMT);
procedure ifprintf( enable : BOOLEAN; str : TEXTSTR );
----------------------------------------------------------------------------
--
-- Copyright (c) 1990, 1991, 1992 by Synopsys, Inc. All rights reserved.
--
-- This source file may be used and distributed without restriction
-- provided that this copyright statement is not removed from the file
-- and that any derivative work contains this copyright notice.
--
-- Package name: STD_LOGIC_TEXTIO
--
-- Purpose: This package overloads the standard TEXTIO procedures
-- READ and WRITE.
--
-- Author: CRC, TS
--
----------------------------------------------------------------------------
procedure HREAD(L:inout LINE; VALUE:out STD_ULOGIC_VECTOR);
procedure HREAD(L:inout LINE; VALUE:out STD_ULOGIC_VECTOR; GOOD: out BOOLEAN);
procedure HREAD(L:inout LINE; VALUE:out STD_LOGIC_VECTOR);
procedure HREAD(L:inout LINE; VALUE:out STD_LOGIC_VECTOR; GOOD: out BOOLEAN);
end textio;
---------------------------------------------------------------------------
-- The Body
--
package body textio is
-- Hex Read and Write procedures.
--
--
-- Hex, and Octal Read and Write procedures for BIT_VECTOR
-- (these procedures are not exported, they are only used
-- by the STD_ULOGIC hex/octal reads and writes below.
--
--
procedure Char2QuadBits(C: Character;
RESULT: out Bit_Vector(3 downto 0);
GOOD: out Boolean;
ISSUE_ERROR: in Boolean) is
begin
case c is
when '0' => result := x"0"; good := TRUE;
when '1' => result := x"1"; good := TRUE;
when '2' => result := x"2"; good := TRUE;
when '3' => result := x"3"; good := TRUE;
when '4' => result := x"4"; good := TRUE;
when '5' => result := x"5"; good := TRUE;
when '6' => result := x"6"; good := TRUE;
when '7' => result := x"7"; good := TRUE;
when '8' => result := x"8"; good := TRUE;
when '9' => result := x"9"; good := TRUE;
when 'A' => result := x"A"; good := TRUE;
when 'B' => result := x"B"; good := TRUE;
when 'C' => result := x"C"; good := TRUE;
when 'D' => result := x"D"; good := TRUE;
when 'E' => result := x"E"; good := TRUE;
when 'F' => result := x"F"; good := TRUE;
when 'a' => result := x"A"; good := TRUE;
when 'b' => result := x"B"; good := TRUE;
when 'c' => result := x"C"; good := TRUE;
when 'd' => result := x"D"; good := TRUE;
when 'e' => result := x"E"; good := TRUE;
when 'f' => result := x"F"; good := TRUE;
when others =>
if ISSUE_ERROR then
assert FALSE report
"HREAD Error: Read a '" & c &
"', expected a Hex character (0-F).";
end if;
good := FALSE;
end case;
end;
procedure HREAD(L:inout LINE; VALUE:out BIT_VECTOR) is
variable ok: boolean;
variable c: character;
constant ne: integer := value'length/4;
variable bv: bit_vector(0 to value'length-1);
variable s: string(1 to ne-1);
begin
if value'length mod 4 /= 0 then
assert FALSE report
"HREAD Error: Trying to read vector " &
"with an odd (non multiple of 4) length";
return;
end if;
loop -- skip white space
read(l,c);
exit when ((c /= ' ') and (c /= CR) and (c /= HT));
end loop;
Char2QuadBits(c, bv(0 to 3), ok, TRUE);
if not ok then
return;
end if;
read(L, s, ok);
if not ok then
assert FALSE
report "HREAD Error: Failed to read the STRING";
return;
end if;
for i in 1 to ne-1 loop
Char2QuadBits(s(i), bv(4*i to 4*i+3), ok, TRUE);
if not ok then
return;
end if;
end loop;
value := bv;
end HREAD;
procedure HREAD(L:inout LINE; VALUE:out BIT_VECTOR;GOOD: out BOOLEAN) is
variable ok: boolean;
variable c: character;
constant ne: integer := value'length/4;
variable bv: bit_vector(0 to value'length-1);
variable s: string(1 to ne-1);
begin
if value'length mod 4 /= 0 then
good := FALSE;
return;
end if;
loop -- skip white space
read(l,c);
exit when ((c /= ' ') and (c /= CR) and (c /= HT));
end loop;
Char2QuadBits(c, bv(0 to 3), ok, FALSE);
if not ok then
good := FALSE;
return;
end if;
read(L, s, ok);
if not ok then
good := FALSE;
return;
end if;
for i in 1 to ne-1 loop
Char2QuadBits(s(i), bv(4*i to 4*i+3), ok, FALSE);
if not ok then
good := FALSE;
return;
end if;
end loop;
good := TRUE;
value := bv;
end HREAD;
procedure HREAD(L:inout LINE; VALUE:out STD_ULOGIC_VECTOR;GOOD:out BOOLEAN) is
variable tmp: bit_vector(VALUE'length-1 downto 0);
begin
HREAD(L, tmp, GOOD);
VALUE := To_X01(tmp);
end HREAD;
procedure HREAD(L:inout LINE; VALUE:out STD_ULOGIC_VECTOR) is
variable tmp: bit_vector(VALUE'length-1 downto 0);
begin
HREAD(L, tmp);
VALUE := To_X01(tmp);
end HREAD;
procedure HREAD(L:inout LINE; VALUE:out STD_LOGIC_VECTOR) is
variable tmp: STD_ULOGIC_VECTOR(VALUE'length-1 downto 0);
begin
HREAD(L, tmp);
VALUE := STD_LOGIC_VECTOR(tmp);
end HREAD;
procedure HREAD(L:inout LINE; VALUE:out STD_LOGIC_VECTOR; GOOD: out BOOLEAN) is
variable tmp: STD_ULOGIC_VECTOR(VALUE'length-1 downto 0);
begin
HREAD(L, tmp, GOOD);
VALUE := STD_LOGIC_VECTOR(tmp);
end HREAD;
---------------------------------------------------------------------------
-- Basic Character Converters
--
function to_char( x : INTEGER range 0 to 15) return character is
begin
case x is
when 0 => return('0');
when 1 => return('1');
when 2 => return('2');
when 3 => return('3');
when 4 => return('4');
when 5 => return('5');
when 6 => return('6');
when 7 => return('7');
when 8 => return('8');
when 9 => return('9');
when 10 => return('A');
when 11 => return('B');
when 12 => return('C');
when 13 => return('D');
when 14 => return('E');
when 15 => return('F');
end case;
end to_char;
function to_char( v : std_logic ) return CHARACTER is
begin
case v is
when '0' => return('0');
when '1' => return('1');
when 'L' => return('L');
when 'H' => return('H');
when 'Z' => return('Z');
when 'X' => return('X');
when 'U' => return('U');
when '-' => return('-');
when 'W' => return('W');
end case;
end to_char;
---------------------------------------------------------------------------
-- special std_logic_vector handling
--
function is01 ( v: std_logic) return BOOLEAN is
begin
return ( v='0' or v='1');
end is01;
function is01 ( v: std_logic_vector; len : INTEGER) return BOOLEAN is
variable ok : BOOLEAN;
begin
ok := TRUE;
for i in 0 to len-1 loop
ok := ok and is01( v(i));
end loop;
return (ok);
end is01;
---------------------------------------------------------------------------
-- String Functions
--
function strlen( str: STRING) return INTEGER is
variable i: INTEGER;
begin
i:=1;
while i<= MAXSTRLEN and str(i)/=NUL loop
i:=i+1;
end loop;
return(i-1);
end strlen;
function strcopy ( instr : STRING) return TEXTSTR is
variable outstr : STRING (1 to MAXSTRLEN);
variable i: INTEGER;
begin
outstr(1 to instr'length) := instr;
outstr(instr'length+1) := NUL;
return(outstr);
end strcopy;
---------------------------------------------------------------------------
-- Number Printing Routines
--
function hexchar ( vect : std_logic_vector) return character is
variable v : std_logic_vector ( 3 downto 0);
variable char : CHARACTER;
begin
v := vect;
if is01(v(0)) and is01(v(1)) and is01(v(2)) and is01(v(3)) then
char := to_char (conv_integer(v));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -