2015-02-27 02:40:45 +01:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
// DESCRIPTION: Verilator: Os-specific function wrapper
|
|
|
|
|
//
|
2019-11-08 04:33:59 +01:00
|
|
|
// Code available from: https://verilator.org
|
2015-02-27 02:40:45 +01:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2024-01-01 09:19:59 +01:00
|
|
|
// Copyright 2003-2024 by Wilson Snyder. This program is free software; you
|
2020-03-21 16:24:24 +01:00
|
|
|
// can redistribute it and/or modify it under the terms of either the GNU
|
2015-02-27 02:40:45 +01:00
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
|
// Version 2.0.
|
2020-03-21 16:24:24 +01:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
2015-02-27 02:40:45 +01:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
2019-10-05 02:17:11 +02:00
|
|
|
|
2021-03-04 03:57:07 +01:00
|
|
|
#ifndef VERILATOR_V3OS_H_
|
|
|
|
|
#define VERILATOR_V3OS_H_
|
2018-10-14 19:43:24 +02:00
|
|
|
|
2015-02-27 02:40:45 +01:00
|
|
|
#include "config_build.h"
|
|
|
|
|
#include "verilatedos.h"
|
2018-10-14 19:43:24 +02:00
|
|
|
|
2020-11-16 13:31:12 +01:00
|
|
|
#include <array>
|
|
|
|
|
|
2019-10-03 03:38:06 +02:00
|
|
|
// Limited V3 headers here - this is a base class for Vlc etc
|
2015-02-27 02:40:45 +01:00
|
|
|
#include "V3Error.h"
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
// V3Os: OS static class
|
|
|
|
|
|
2020-11-19 03:32:16 +01:00
|
|
|
class V3Os final {
|
2015-02-27 02:40:45 +01:00
|
|
|
public:
|
|
|
|
|
// METHODS (environment)
|
|
|
|
|
static string getenvStr(const string& envvar, const string& defaultValue);
|
|
|
|
|
static void setenvStr(const string& envvar, const string& value, const string& why);
|
|
|
|
|
|
|
|
|
|
// METHODS (generic filename utilities)
|
2023-09-26 21:42:15 +02:00
|
|
|
///< @return concatenated path
|
|
|
|
|
static string filenameJoin(std::initializer_list<const std::string> paths) VL_PURE;
|
|
|
|
|
template <typename... Args>
|
|
|
|
|
static string filenameJoin(Args... args) VL_PURE {
|
|
|
|
|
return filenameJoin({args...});
|
|
|
|
|
};
|
|
|
|
|
///< @return file path without repeated separators and ./ prefix
|
|
|
|
|
static string filenameCleanup(const string& filename) VL_PURE;
|
|
|
|
|
///< @return non-directory part of filename
|
2023-03-17 00:48:56 +01:00
|
|
|
static string filenameNonDir(const string& filename) VL_PURE;
|
2023-09-26 21:42:15 +02:00
|
|
|
///< @return non-extensioned (no .) part of filename
|
2023-03-17 00:48:56 +01:00
|
|
|
static string filenameNonExt(const string& filename) VL_PURE;
|
2023-09-26 21:42:15 +02:00
|
|
|
///< @return basename of filename
|
|
|
|
|
static string filenameNonDirExt(const string& filename) VL_PURE;
|
|
|
|
|
///< @return directory part of filename
|
2023-08-16 13:34:57 +02:00
|
|
|
static string filenameDir(const string& filename) VL_PURE;
|
2023-09-26 21:42:15 +02:00
|
|
|
///< @return filename with env vars removed
|
2020-04-14 04:51:35 +02:00
|
|
|
static string filenameSubstitute(const string& filename);
|
2023-09-26 21:42:15 +02:00
|
|
|
///< @return realpath of filename
|
2023-08-16 13:34:57 +02:00
|
|
|
static string filenameRealPath(const string& filename) VL_PURE;
|
2023-09-26 21:42:15 +02:00
|
|
|
///< @return filename is relative
|
|
|
|
|
static bool filenameIsRel(const string& filename) VL_PURE;
|
2015-02-27 02:40:45 +01:00
|
|
|
|
2018-11-27 01:09:08 +01:00
|
|
|
// METHODS (file utilities)
|
2020-04-14 04:51:35 +02:00
|
|
|
static string getline(std::istream& is, char delim = '\n');
|
2018-11-27 01:09:08 +01:00
|
|
|
|
2015-02-27 02:40:45 +01:00
|
|
|
// METHODS (directory utilities)
|
|
|
|
|
static void createDir(const string& dirname);
|
2023-11-22 03:22:35 +01:00
|
|
|
static void filesystemFlush(const string& dirname);
|
2023-11-22 11:18:13 +01:00
|
|
|
static void filesystemFlushBuildDir(const string& dirname);
|
2015-02-27 02:40:45 +01:00
|
|
|
static void unlinkRegexp(const string& dir, const string& regexp);
|
2017-09-18 04:52:57 +02:00
|
|
|
|
2018-09-21 00:09:19 +02:00
|
|
|
// METHODS (random)
|
2022-03-27 21:27:40 +02:00
|
|
|
static uint64_t rand64(std::array<uint64_t, 2>& stater);
|
2023-03-18 01:24:15 +01:00
|
|
|
static string trueRandom(size_t size) VL_MT_SAFE;
|
2018-09-21 00:09:19 +02:00
|
|
|
|
2019-12-28 17:44:24 +01:00
|
|
|
// METHODS (time & performance)
|
|
|
|
|
static void u_sleep(int64_t usec); ///< Sleep for a given number of microseconds.
|
2020-04-14 04:51:35 +02:00
|
|
|
/// Return wall time since epoch in microseconds, or 0 if not implemented
|
|
|
|
|
static uint64_t timeUsecs();
|
2019-05-19 22:13:13 +02:00
|
|
|
static uint64_t memUsageBytes(); ///< Return memory usage in bytes, or 0 if not implemented
|
2020-04-15 23:44:21 +02:00
|
|
|
|
|
|
|
|
// METHODS (sub command)
|
|
|
|
|
/// Run system command, returns the exit code of the child process.
|
|
|
|
|
static int system(const string& command);
|
2023-09-26 21:42:15 +02:00
|
|
|
static void selfTest();
|
2015-02-27 02:40:45 +01:00
|
|
|
};
|
|
|
|
|
|
2019-05-19 22:13:13 +02:00
|
|
|
#endif // Guard
|