1
// DESCRIPTION: Verilator: built-in packages and classes
3
// Code available from: https://verilator.org
5
//*************************************************************************
7
// Copyright 2022-2024 by Wilson Snyder. This program is free software; you can
8
// redistribute it and/or modify it under the terms of either the GNU Lesser
9
// General Public License Version 3 or the Perl Artistic License Version 2.0.
10
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
12
//*************************************************************************
15
/// \brief Verilated IEEE std:: header
17
/// This file is included automatically by Verilator when a std::mailbox or
18
/// std::semaphore is referenced.
20
/// This file is not part of the Verilated public-facing API.
21
/// It is only for internal use.
23
//*************************************************************************
25
// verilator lint_off DECLFILENAME
26
// verilator lint_off TIMESCALEMOD
27
// verilator lint_off UNUSEDSIGNAL
29
class mailbox #(type T);
30
protected int m_bound;
31
protected T m_queue[$];
33
function new(int bound = 0);
38
return m_queue.size();
42
`ifdef VERILATOR_TIMING
44
wait (m_queue.size() < m_bound);
45
m_queue.push_back(message);
49
function int try_put(T message);
50
if (m_bound == 0 || num() < m_bound) begin
51
m_queue.push_back(message);
57
task get(ref T message);
58
`ifdef VERILATOR_TIMING
59
wait (m_queue.size() > 0);
60
message = m_queue.pop_front();
64
function int try_get(ref T message);
66
message = m_queue.pop_front();
72
task peek(ref T message);
73
`ifdef VERILATOR_TIMING
74
wait (m_queue.size() > 0);
79
function int try_peek(ref T message);
89
protected int m_keyCount;
91
function new(int keyCount = 0);
92
m_keyCount = keyCount;
95
function void put(int keyCount = 1);
96
m_keyCount += keyCount;
99
task get(int keyCount = 1);
100
`ifdef VERILATOR_TIMING
101
wait (m_keyCount >= keyCount);
102
m_keyCount -= keyCount;
106
function int try_get(int keyCount = 1);
107
if (m_keyCount >= keyCount) begin
108
m_keyCount -= keyCount;
124
`ifdef VERILATOR_TIMING
125
// Width visitor changes it to VlProcessRef
126
protected chandle m_process;
129
static function process self();
131
`ifdef VERILATOR_TIMING
132
$c(p.m_process, " = vlProcess;");
137
protected function void set_status(state s);
138
`ifdef VERILATOR_TIMING
139
$c(m_process, "->state(", s, ");");
143
function state status();
144
`ifdef VERILATOR_TIMING
145
return state'($c(m_process, "->state()"));
151
function void kill();
155
function void suspend();
156
$error("std::process::suspend() not supported");
159
function void resume();
164
`ifdef VERILATOR_TIMING
165
wait (status() == FINISHED || status() == KILLED);
169
// When really implemented, srandom must operate on the process, but for
170
// now rely on the srandom() that is automatically generated for all
173
// function void srandom(int seed);
176
// The methods below work only if set_randstate is never applied to
177
// a state string created before another such string. Full support
178
// could use VlRNG class to store the state per process in VlProcess
180
function string get_randstate();
183
s.itoa($random); // Get a random number
184
set_randstate(s); // Pretend it's the state of RNG
188
function void set_randstate(string s);
189
$urandom(s.atoi()); // Set the seed using a string