Skip to content

Commit

Permalink
Replaced no-name parameters in common log interface with VUnit-specif…
Browse files Browse the repository at this point in the history
…ic parameters.
  • Loading branch information
LarsAsplund committed Jul 17, 2023
1 parent e24d818 commit 59a96ba
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1005,12 +1005,7 @@ package body AlertLogPkg is
msg => message,
log_time => log_time,
log_level => alert_level,
log_source_name => log_source_name,
int_1 => AlertLogJustifyAmountVar,
int_2 => error_count,
str_1 => AlertPrefixVar.Get(OSVVM_DEFAULT_ALERT_PREFIX),
str_2 => prefix,
str_3 => suffix
log_source_name => log_source_name
);
end if;

Expand All @@ -1021,12 +1016,7 @@ package body AlertLogPkg is
msg => message,
log_time => log_time,
log_level => alert_level,
log_source_name => log_source_name,
int_1 => AlertLogJustifyAmountVar,
int_2 => error_count,
str_1 => AlertPrefixVar.Get(OSVVM_DEFAULT_ALERT_PREFIX),
str_2 => prefix,
str_3 => suffix
log_source_name => log_source_name
);
end if;
end if ;
Expand Down Expand Up @@ -2286,11 +2276,7 @@ package body AlertLogPkg is
msg => Message,
log_time => log_time,
log_level => log_level,
log_source_name => log_source_name,
int_1 => AlertLogJustifyAmountVar,
int_2 => error_count,
str_1 => LogPrefixVar.Get(OSVVM_DEFAULT_LOG_PREFIX),
str_3 => suffix
log_source_name => log_source_name
);
end if;

Expand All @@ -2301,11 +2287,7 @@ package body AlertLogPkg is
msg => Message,
log_time => log_time,
log_level => log_level,
log_source_name => log_source_name,
int_1 => AlertLogJustifyAmountVar,
int_2 => error_count,
str_1 => LogPrefixVar.Get(OSVVM_DEFAULT_LOG_PREFIX),
str_3 => suffix
log_source_name => log_source_name
);
end if;
end procedure LocalLog ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ package body common_log_pkg is
msg : string := no_string;
log_time : time := no_time;
log_level : string := no_string;
log_source_name : string := no_string;
str_1, str_2, str_3, str_4, str_5, str_6, str_7, str_8, str_9, str_10 : string := "";
int_1, int_2, int_3, int_4, int_5, int_6, int_7, int_8, int_9, int_10 : integer := 0;
bool_1, bool_2, bool_3, bool_4, bool_5, bool_6, bool_7, bool_8, bool_9, bool_10 : boolean := false
log_source_name : string := no_string
) is

constant stripped_log_level : string := strip(log_level);
Expand Down Expand Up @@ -74,7 +71,7 @@ package body common_log_pkg is
vunit_log_level := info;
end if;

log(logger, msg, vunit_log_level, path_offset => 4);
log(logger, msg, vunit_log_level, path_offset => 4, line_num => 0, file_name => "");

if reenable_display_handler then
set_log_handlers(osvvm, (display_handler, file_log_handler));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this file,
-- You can obtain one at http://mozilla.org/MPL/2.0/.
--
-- Copyright (c) 2014-2023, Lars Asplund lars.anders.asplund@gmail.com

use std.textio.all;

package common_log_pkg is
-- Deferred constant set to true in the native implementation of the package.
-- Must be set to false in alternative implementations.
constant is_original_pkg : boolean;

-- Default interface values.
constant no_time : time := -1 ns;
constant no_string : string := "";

-- Converts a log message and associated metadata to a string written to the specified log destination.
procedure write_to_log(
----------------------------------------------------------------------
-- Log entry items mandatory for all implementations of this interface
----------------------------------------------------------------------

-- Destination of the log message is either std.textio.output (std output) or a text file object previously opened
-- for writing
file log_destination : text;
-- Path to log_destination if it's a file, empty string otherwise
log_destination_path : string := no_string;
-- Log message
msg : string := no_string;
-- Simulation time associated with the log message
log_time : time := no_time;
-- Level associated with the log message. For example "DEBUG" or "WARNING".
log_level : string := no_string;
-- Name of the producer of the log message. Hierarchical names use colon as the delimiter.
-- For example "parent_component:child_component".
log_source_name : string := no_string
);
end package;
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,24 @@ package body common_log_pkg is
log_time : time := no_time;
log_level : string := no_string;
log_source_name : string := no_string;
str_1, str_2, str_3, str_4, str_5, str_6, str_7, str_8, str_9, str_10 : string := "";
int_1, int_2, int_3, int_4, int_5, int_6, int_7, int_8, int_9, int_10 : integer := 0;
bool_1, bool_2, bool_3, bool_4, bool_5, bool_6, bool_7, bool_8, bool_9, bool_10 : boolean := false
log_source_path : string;
log_format : natural range 0 to 3;
log_source_line_number : natural;
log_sequence_number : natural;
use_color : boolean;
max_logger_name_length : natural

) is
alias sequence_number is int_3;
constant stdout : boolean := log_destination_path = no_string;
constant current_mode : natural range init_mode to mirror_mode := get(mode, 0);
variable reopen_transcript : boolean := false;
variable enable_mirror : boolean := false;
begin
if stdout and (get(last_sequence_number, stdout_idx) = sequence_number) then
if stdout and (get(last_sequence_number, stdout_idx) = log_sequence_number) then
return;
end if;

if not stdout and (get(last_sequence_number, file_idx) = sequence_number) then
if not stdout and (get(last_sequence_number, file_idx) = log_sequence_number) then
return;
end if;

Expand All @@ -61,45 +64,45 @@ package body common_log_pkg is
TranscriptClose;
SetTranscriptMirror(false);
if stdout then
set(last_sequence_number, stdout_idx, sequence_number);
set(last_sequence_number, stdout_idx, log_sequence_number);
set(mode, 0, stdout_mode);
else
TranscriptOpen(join(get_string(run_db, "output_path"), "osvvm_transcript.txt"));
set(last_sequence_number, file_idx, sequence_number);
set(last_sequence_number, file_idx, log_sequence_number);
set(mode, 0, file_mode);
end if;
when stdout_mode =>
if not stdout then
TranscriptOpen(join(get_string(run_db, "output_path"), "osvvm_transcript.txt"));
set(last_sequence_number, file_idx, sequence_number);
set(last_sequence_number, file_idx, log_sequence_number);
set(mode, 0, mirror_mode);
if get(last_sequence_number, stdout_idx) /= sequence_number then
if get(last_sequence_number, stdout_idx) /= log_sequence_number then
SetTranscriptMirror;
set(last_sequence_number, stdout_idx, sequence_number);
set(last_sequence_number, stdout_idx, log_sequence_number);
else
enable_mirror := true;
end if;
else
set(last_sequence_number, stdout_idx, sequence_number);
set(last_sequence_number, stdout_idx, log_sequence_number);
end if;
when file_mode =>
if stdout then
set(last_sequence_number, stdout_idx, sequence_number);
set(last_sequence_number, stdout_idx, log_sequence_number);
set(mode, 0, mirror_mode);

if get(last_sequence_number, file_idx) /= sequence_number then
if get(last_sequence_number, file_idx) /= log_sequence_number then
SetTranscriptMirror;
set(last_sequence_number, file_idx, sequence_number);
set(last_sequence_number, file_idx, log_sequence_number);
else
TranscriptClose;
reopen_transcript := true;
end if;
else
set(last_sequence_number, file_idx, sequence_number);
set(last_sequence_number, file_idx, log_sequence_number);
end if;
when mirror_mode =>
set(last_sequence_number, stdout_idx, sequence_number);
set(last_sequence_number, file_idx, sequence_number);
set(last_sequence_number, stdout_idx, log_sequence_number);
set(last_sequence_number, file_idx, log_sequence_number);
end case;

if (log_level = "warning") or (log_level = "error") or (log_level = "failure") then
Expand Down
2 changes: 1 addition & 1 deletion examples/vhdl/osvvm_log_integration/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
osvvm.add_source_files(root / ".." / ".." / ".." / "vunit" / "vhdl" / "osvvm" / osvvm_file)

if args.use_vunit_log:
osvvm.add_source_files(root / ".." / ".." / ".." / "vunit" / "vhdl" / "logging" / "src" / "common_log_pkg.vhd")
osvvm.add_source_files(root / "osvvm_integration" / "osvvm_to_vunit_common_log_pkg.vhd")
osvvm.add_source_files(root / "osvvm_integration" / "osvvm_to_vunit_common_log_pkg-body.vhd")
osvvm.add_source_files(root / "osvvm_integration" / "AlertLogPkg.vhd")
else:
Expand Down
53 changes: 24 additions & 29 deletions vunit/vhdl/logging/src/common_log_pkg-body.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,14 @@ package body common_log_pkg is
log_time : time := no_time;
log_level : string := no_string;
log_source_name : string := no_string;
str_1, str_2, str_3, str_4, str_5, str_6, str_7, str_8, str_9, str_10 : string := "";
int_1, int_2, int_3, int_4, int_5, int_6, int_7, int_8, int_9, int_10 : integer := 0;
bool_1, bool_2, bool_3, bool_4, bool_5, bool_6, bool_7, bool_8, bool_9, bool_10 : boolean := false
log_source_path : string;
log_format : natural range 0 to 3;
log_source_line_number : natural;
log_sequence_number : natural;
use_color : boolean;
max_logger_name_length : natural
) is

alias file_name is str_1;

alias format is int_1;
alias line_num is int_2;
alias sequence_number is int_3;
alias use_color is int_4;
alias get_max_logger_name_length is int_5;

constant max_time_str : string := time'image(1 sec);
constant max_time_length : natural := max_time_str'length;

Expand All @@ -53,13 +48,13 @@ package body common_log_pkg is
pad(l, max_time_length - time_string'length);
end if;

if use_color = 1 then
if use_color then
write(l, color_start(fg => lightcyan));
end if;

write(l, time_string);

if use_color = 1 then
if use_color then
write(l, color_end);
end if;
end procedure;
Expand All @@ -72,21 +67,21 @@ package body common_log_pkg is
pad(l, max_level_length - level_name'length);
end if;

if use_color = 1 then
if use_color then
color := get_color(log_level_t'value(log_level));
write(l, color_start(fg => color.fg, bg => color.bg, style => color.style));
end if;

write(l, upper(level_name));

if use_color = 1 then
if use_color then
write(l, color_end);
end if;
end;

procedure write_source(variable l : inout line; justify : boolean := false) is
begin
if use_color = 1 then
if use_color then
write(l, color_start(fg => white, style => bright));

for i in log_source_name 'range loop
Expand All @@ -102,20 +97,20 @@ package body common_log_pkg is
write(l, log_source_name);
end if;

if use_color = 1 then
if use_color then
write(l, color_end);
end if;

if justify then
pad(l, get_max_logger_name_length - log_source_name'length);
pad(l, max_logger_name_length - log_source_name'length);
end if;

end;

procedure write_location(variable l : inout line) is
begin
if file_name /= "" then
write(l, " (" & file_name & ":" & integer'image(line_num) & ")");
if log_source_path /= "" then
write(l, " (" & log_source_path & ":" & integer'image(log_source_line_number) & ")");
end if;
end;

Expand Down Expand Up @@ -150,15 +145,15 @@ package body common_log_pkg is

variable l : line;
begin
if format = raw_format then
if log_format = raw_format then
write_message(l);

elsif format = level_format then
elsif log_format = level_format then
write_level(l, justify => true);
write(l, string'(" - "));
write_message(l, multi_line_align => true);

elsif format = verbose_format then
elsif log_format = verbose_format then
write_time(l, justify => true);
write(l, string'(" - "));
write_source(l, justify => true);
Expand All @@ -167,19 +162,19 @@ package body common_log_pkg is
write(l, string'(" - "));
write_message(l, multi_line_align => true);

elsif format = csv_format then
write(l, string'(integer'image(sequence_number) & ','));
elsif log_format = csv_format then
write(l, string'(integer'image(log_sequence_number) & ','));
write_time(l);
write(l, ',');
write_level(l);
write(l, ',');

if line_num = 0 then
if log_source_line_number = 0 then
write(l, string'(",,"));
else
write(l, file_name);
write(l, log_source_path);
write(l, ',');
write(l, integer'image(line_num));
write(l, integer'image(log_source_line_number));
write(l, ',');
end if;

Expand All @@ -188,7 +183,7 @@ package body common_log_pkg is
write(l, msg);

else
assert false report "Illegal format: " & integer'image(format) severity failure;
assert false report "Illegal format: " & integer'image(log_format) severity failure;
end if;
writeline(log_destination, l);
end;
Expand Down
Loading

0 comments on commit 59a96ba

Please sign in to comment.