Skip to content

Commit

Permalink
Implement textio read procedure for time
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed Apr 17, 2021
1 parent a9d5d6d commit 71e18ae
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 1.5.2 - unreleased
- Link libexecinfo on FreeBSD.
- Add missing textio read subprogram for bit (#408).
- Implement textio READ procedure for BIT and TIME (#408).

## 1.5.1 - 2021-09-04
- Fix a compiler warning in vcode.c.
Expand Down
39 changes: 37 additions & 2 deletions lib/std/textio.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,44 @@ package body textio is
procedure read (l : inout line;
value : out time;
good : out boolean ) is
type unit_spec_t is record
name : string(1 to 3);
length : positive;
unit : time;
end record;

type unit_map_t is array (natural range <>) of unit_spec_t;

constant unit_map : unit_map_t := (
( "fs ", 2, fs ),
( "ps ", 2, ps ),
( "ns ", 2, ns ),
( "us ", 2, us ),
( "ms ", 2, ms ),
( "sec", 3, sec ),
( "min", 3, min ),
( "hr ", 2, hr ) );

variable scale, len : integer;
variable scale_good : boolean;
begin
-- TODO
report "unimplemented" severity failure;
good := false;
skip_whitespace(l);
read(l, scale, scale_good);
if not scale_good then
return;
end if;
skip_whitespace(l);
for i in unit_map'range loop
len := unit_map(i).length;
if l'length >= len
and l.all(1 to len) = unit_map(i).name(1 to len)
then
value := scale * unit_map(i).unit;
consume(l, len);
good := true;
end if;
end loop;
end procedure;

procedure read (l : inout line;
Expand Down
20 changes: 20 additions & 0 deletions test/regress/textio4.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,24 @@ begin
wait;
end process;

check_time: process is
variable l : line;
variable t : time;
variable good : boolean;
begin
l := new string'(" 1 ns 15 sec 1 hr");
read(l, t, good);
assert good;
assert t = 1 ns;
read(l, t, good);
assert good;
assert t = 15 sec;
read(l, t, good);
assert good;
assert t = 1 hr;
read(l, t, good);
assert not good;
wait;
end process;

end architecture;

0 comments on commit 71e18ae

Please sign in to comment.