diff --git a/tools/evmc/utils.cpp b/tools/evmc/utils.cpp index 51ff6e9..fdb87b0 100644 --- a/tools/evmc/utils.cpp +++ b/tools/evmc/utils.cpp @@ -3,6 +3,7 @@ // Licensed under the Apache License, Version 2.0. #include "utils.hpp" +#include #include namespace evmc @@ -45,4 +46,75 @@ std::string hex(const uint8_t* data, size_t size) return str; } +std::ostream& operator<<(std::ostream& os, evmc_status_code status_code) +{ + const char* s = nullptr; + switch (status_code) + { + case EVMC_SUCCESS: + s = "success"; + break; + case EVMC_FAILURE: + s = "failure"; + break; + case EVMC_REVERT: + s = "revert"; + break; + case EVMC_OUT_OF_GAS: + s = "out of gas"; + break; + case EVMC_INVALID_INSTRUCTION: + s = "invalid instruction"; + break; + case EVMC_UNDEFINED_INSTRUCTION: + s = "undefined instruction"; + break; + case EVMC_STACK_OVERFLOW: + s = "stack overflow"; + break; + case EVMC_STACK_UNDERFLOW: + s = "stack underflow"; + break; + case EVMC_BAD_JUMP_DESTINATION: + s = "bad jump destination"; + break; + case EVMC_INVALID_MEMORY_ACCESS: + s = "invalid memory access"; + break; + case EVMC_CALL_DEPTH_EXCEEDED: + s = "call depth exceeded"; + break; + case EVMC_STATIC_MODE_VIOLATION: + s = "static mode violation"; + break; + case EVMC_PRECOMPILE_FAILURE: + s = "precompile failure"; + break; + case EVMC_CONTRACT_VALIDATION_FAILURE: + s = "contract validation failure"; + break; + case EVMC_ARGUMENT_OUT_OF_RANGE: + s = "argument out of range"; + break; + case EVMC_WASM_UNREACHABLE_INSTRUCTION: + s = "wasm unreachable instruction"; + break; + case EVMC_WASM_TRAP: + s = "wasm trap"; + break; + case EVMC_INTERNAL_ERROR: + s = "internal error"; + break; + case EVMC_REJECTED: + s = "rejected"; + break; + case EVMC_OUT_OF_MEMORY: + s = "out of memory"; + break; + default: + throw std::invalid_argument{"invalid EVMC status code: " + std::to_string(status_code)}; + } + return os << s; +} + } // namespace evmc diff --git a/tools/evmc/utils.hpp b/tools/evmc/utils.hpp index 97402c1..8591fa7 100644 --- a/tools/evmc/utils.hpp +++ b/tools/evmc/utils.hpp @@ -3,7 +3,9 @@ // Licensed under the Apache License, Version 2.0. #pragma once +#include #include +#include #include namespace evmc @@ -27,4 +29,8 @@ bytes from_hex(const std::string& hex); /// Encodes bytes as hex string. std::string hex(const uint8_t* data, size_t size); + +/// Output stream operator for evmc_status_code. +std::ostream& operator<<(std::ostream& os, evmc_status_code status_code); + } // namespace evmc