compiler_gym/util
EnumUtil.h
#include "compiler_gym/util/EnumUtil.h"
-
namespace compiler_gym
-
namespace util
Functions
-
template<typename Enum>
std::string enumNameToPascalCase(Enum value) Convert an UPPER_SNAKE_CASE enum name to PascalCase.
E.g.
MyEnum::MY_ENUM_VALUE -> "MyEnumValue"
.- Parameters
value – An enum.
- Returns
A string.
-
template<typename Enum>
std::string enumNameToPascalCase(std::optional<Enum> value) Convert an UPPER_SNAKE_CASE enum name to PascalCase.
E.g.
MyEnum::MY_ENUM_VALUE -> "MyEnumValue"
.- Parameters
value – An enum.
- Returns
A string.
-
template<typename Enum>
std::string enumNameToCommandlineFlag(Enum value) Convert an UPPER_SNAKE_CASE enum name to -flag-name.
E.g.
MyEnum::MY_ENUM_VALUE -> "-my-enum-value"
.- Parameters
value – An enum.
- Returns
A string.
-
template<typename Enum>
std::vector<std::optional<Enum>> optionalEnumValues() Enumerate all values of an optional Enum, including
std::nullopt
.- Returns
A vector of optional enum values.
-
template<typename Enum>
std::string demangle() Return the name of an enum, e.g.
demangle<foo::MyEnum>() -> "MyEnum"
.- Returns
A string.
-
template<typename Enum>
grpc::Status pascalCaseToEnum(const std::string &name, Enum *value) Convert a PascalCase enum name to enum value.
E.g.
pascalCaseToEnum("MyEnumVal", &myEnum) -> MyEnum::MY_ENUM_VAL
.- Template Parameters
Enum – Enum type.
- Parameters
name – A string.
value – The value to write to.
- Returns
Status::OK
on success.Status::INVALID_ARGUMENT
if the string name is not recognized.
-
template<typename Enum>
std::unordered_map<std::string, Enum> createPascalCaseToEnumLookupTable() Create a map from PascalCase enum value names to enum values.
- Template Parameters
Enum – Enum type.
- Returns
A
name -> value
lookup table.
-
template<typename Enum>
inline grpc::Status intToEnum(int numericValue, Enum *enumValue) Convert an integer to an enum with bounds checking.
E.g.
intToEnum(3, &myEnum);
- Template Parameters
Enum – Enum type.
- Parameters
numericValue – An integer.
enumValue – An enum to write.
- Returns
Status::OK
on success.Status::INVALID_ARGUMENT
if out of bounds.
-
template<typename Enum>
-
namespace util
GrpcStatusMacros.h
#include "compiler_gym/util/GrpcStatusMacros.h"
Defines
-
ASSERT_OK(expr)
Fatal error if expression returns an error status.
- Parameters
expr – An expression that returns a
grpc::Status
.
-
RETURN_IF_ERROR(expr)
Return from the current function if the expression returns an error status, or if a std::exception is thrown.
This is equivalent to:
\code{.cpp} try { Status status = expr; if (!status.ok()) { return status; } } catch (std::exception& e) { return E_STATUS; } \endcode
- Parameters
expr – An expression that return a
grpc::Status
.
RunfilesPath.h
#include "compiler_gym/util/RunfilesPath.h"
-
namespace compiler_gym
-
namespace util
-
namespace util
StrLenConstexpr.h
#include "compiler_gym/util/StrLenConstexpr.h"
-
namespace compiler_gym
-
namespace util
-
namespace util
Subprocess.h
#include "compiler_gym/util/Subprocess.h"
-
namespace compiler_gym
-
namespace util
Functions
-
class LocalShellCommand
- #include <Subprocess.h>
A representation of a Command protocol buffer that describes a command that is run in a subshell locally on the current machine.
Public Functions
-
explicit LocalShellCommand(const Command &cmd)
Constructor.
- Parameters
cmd – The Command protocol buffer.
-
grpc::Status checkCall() const
Run the given command in a subshell.
- Returns
OK
on success,DEADLINE_EXCEEDED
on timeout, orINTERNAL
if the command returns with a non-zero returncode.
-
grpc::Status checkOutput(std::string &stdout) const
Run the given command in a subshell and capture its stdout to string.
- Parameters
stdout – The string to set the stdout to.
- Returns
OK
on success,DEADLINE_EXCEEDED
on timeout, orINTERNAL
if the command returns with a non-zero returncode.
-
grpc::Status checkInfiles() const
Check that the specified infiles exist.
- Returns
OK
on success,INTERNAL
if a file is missing.
-
grpc::Status checkOutfiles() const
Check that the specified outfiles exist.
- Returns
OK
on success,INTERNAL
if a file is missing.
-
inline const std::vector<std::string> &arguments() const
-
inline const std::chrono::seconds &timeout() const
-
inline const int timeoutSeconds() const
-
inline const boost::process::environment &env() const
-
inline const std::vector<boost::filesystem::path> &infiles() const
-
inline const std::vector<boost::filesystem::path> &outfiles() const
-
std::string commandline() const
Get the list of command line arguments as a concatenated string.
This is for debugging purposes, it should not be used to execute commands as it does no escaping of arguments.
-
inline const bool empty() const
Returns whether this command instance has any arguments to execute.
-
explicit LocalShellCommand(const Command &cmd)
-
class LocalShellCommand
-
namespace util
Unreachable.h
#include "compiler_gym/util/Unreachable.h"
Defines
-
UNREACHABLE(msg)
Declare a program point as unreachable.
For debug builds, this will trigger a fatal error if reached. For optimized builds (i.e. ones built using
bazel build -c opt
), this is undefined.- Parameters
msg – A message that will be printed if this program point is reached in a debug build.