EVMC
evmc::VM Class Reference

The VM instance. More...

#include <evmc.hpp>

Public Member Functions

 VM (evmc_vm *vm) noexcept
 Converting constructor from evmc_vm.
 
 ~VM () noexcept
 Destructor responsible for automatically destroying the VM instance.
 
 VM (const VM &)=delete
 
VMoperator= (const VM &)=delete
 
 VM (VM &&other) noexcept
 Move constructor.
 
VMoperator= (VM &&other) noexcept
 Move assignment operator.
 
 VM (evmc_vm *vm, std::initializer_list< std::pair< const char *, const char * > > options) noexcept
 The constructor that captures a VM instance and configures the instance with the provided list of options.
 
 operator bool () const noexcept
 Checks if contains a valid pointer to the VM instance.
 
bool is_abi_compatible () const noexcept
 Checks whenever the VM instance is ABI compatible with the current EVMC API.
 
char const * name () const noexcept
 The name of the EVMC VM implementation.
 
char const * version () const noexcept
 The version of the EVMC VM implementation, e.g.
 
bool has_capability (evmc_capabilities capability) const noexcept
 Checks if the VM has the given capability.
 
evmc_capabilities_flagset get_capabilities () const noexcept
 A method returning capabilities supported by the VM instance.
 
evmc_set_option_result set_option (const char name[], const char value[]) noexcept
 Sets the option for the VM, if the feature is supported by the VM.
 
Result execute (const evmc_host_interface &host, evmc_host_context *ctx, evmc_revision rev, const evmc_message &msg, const uint8_t *code, size_t code_size) noexcept
 Executes code in the VM instance.
 
Result execute (Host &host, evmc_revision rev, const evmc_message &msg, const uint8_t *code, size_t code_size) noexcept
 Convenient variant of the VM::execute() that takes reference to evmc::Host class.
 
Result execute (evmc_revision rev, const evmc_message &msg, const uint8_t *code, size_t code_size) noexcept
 Executes code without the Host context.
 
evmc_vmget_raw_pointer () const noexcept
 Returns the pointer to C EVMC struct representing the VM.
 

Detailed Description

The VM instance.

This is a RAII wrapper for evmc_vm, and object of this type automatically destroys the VM instance.

Definition at line 654 of file evmc.hpp.

Constructor & Destructor Documentation

◆ VM() [1/3]

evmc::VM::VM ( evmc_vm vm)
inlineexplicitnoexcept

Converting constructor from evmc_vm.

Definition at line 660 of file evmc.hpp.

660: m_instance{vm} {}

◆ ~VM()

evmc::VM::~VM ( )
inlinenoexcept

Destructor responsible for automatically destroying the VM instance.

Definition at line 663 of file evmc.hpp.

664 {
665 if (m_instance != nullptr)
666 m_instance->destroy(m_instance);
667 }
evmc_destroy_fn destroy
Pointer to function destroying the VM instance.
Definition: evmc.h:1164

◆ VM() [2/3]

evmc::VM::VM ( VM &&  other)
inlinenoexcept

Move constructor.

Definition at line 673 of file evmc.hpp.

673: m_instance{other.m_instance} { other.m_instance = nullptr; }

◆ VM() [3/3]

evmc::VM::VM ( evmc_vm vm,
std::initializer_list< std::pair< const char *, const char * > >  options 
)
inlinenoexcept

The constructor that captures a VM instance and configures the instance with the provided list of options.

Definition at line 768 of file evmc.hpp.

770 : m_instance{vm}
771{
772 // This constructor is implemented outside of the class definition to workaround a doxygen bug.
773 for (const auto& option : options)
774 set_option(option.first, option.second);
775}
evmc_set_option_result set_option(const char name[], const char value[]) noexcept
Sets the option for the VM, if the feature is supported by the VM.
Definition: evmc.hpp:714

Member Function Documentation

◆ execute() [1/3]

Result evmc::VM::execute ( const evmc_host_interface host,
evmc_host_context ctx,
evmc_revision  rev,
const evmc_message msg,
const uint8_t *  code,
size_t  code_size 
)
inlinenoexcept

Executes code in the VM instance.

See also
evmc_execute_fn.

Definition at line 720 of file evmc.hpp.

726 {
727 return Result{m_instance->execute(m_instance, &host, ctx, rev, &msg, code, code_size)};
728 }
evmc_execute_fn execute
Pointer to function executing a code by the VM instance.
Definition: evmc.h:1171

◆ execute() [2/3]

Result evmc::VM::execute ( evmc_revision  rev,
const evmc_message msg,
const uint8_t *  code,
size_t  code_size 
)
inlinenoexcept

Executes code without the Host context.

The same as execute(const evmc_host_interface&, evmc_host_context*, evmc_revision, const evmc_message&, const uint8_t*, size_t), but without providing the Host context and interface. This method is for experimental precompiles support where execution is guaranteed not to require any Host access.

Definition at line 748 of file evmc.hpp.

752 {
753 return Result{
754 m_instance->execute(m_instance, nullptr, nullptr, rev, &msg, code, code_size)};
755 }

◆ execute() [3/3]

Result evmc::VM::execute ( Host host,
evmc_revision  rev,
const evmc_message msg,
const uint8_t *  code,
size_t  code_size 
)
inlinenoexcept

Convenient variant of the VM::execute() that takes reference to evmc::Host class.

Definition at line 731 of file evmc.hpp.

736 {
737 return execute(Host::get_interface(), host.to_context(), rev, msg, code, code_size);
738 }
static const evmc_host_interface & get_interface() noexcept
Provides access to the global host interface.
Definition: evmc.hpp:885
Result execute(const evmc_host_interface &host, evmc_host_context *ctx, evmc_revision rev, const evmc_message &msg, const uint8_t *code, size_t code_size) noexcept
Executes code in the VM instance.
Definition: evmc.hpp:720

◆ get_capabilities()

evmc_capabilities_flagset evmc::VM::get_capabilities ( ) const
inlinenoexcept

A method returning capabilities supported by the VM instance.

The value returned MAY change when different options are set via the set_option() method.

A Client SHOULD only rely on the value returned if it has queried it after it has called the set_option().

This is a mandatory method and MUST NOT be set to NULL.

Definition at line 708 of file evmc.hpp.

709 {
710 return m_instance->get_capabilities(m_instance);
711 }
evmc_get_capabilities_fn get_capabilities
A method returning capabilities supported by the VM instance.
Definition: evmc.h:1183

◆ get_raw_pointer()

evmc_vm * evmc::VM::get_raw_pointer ( ) const
inlinenoexcept

Returns the pointer to C EVMC struct representing the VM.

Gives access to the C EVMC VM struct to allow advanced interaction with the VM not supported by the C++ interface. Use as the last resort. This object still owns the VM after returning the pointer. The returned pointer MAY be null.

Definition at line 762 of file evmc.hpp.

762{ return m_instance; }

◆ has_capability()

bool evmc::VM::has_capability ( evmc_capabilities  capability) const
inlinenoexcept

Checks if the VM has the given capability.

Definition at line 702 of file evmc.hpp.

703 {
704 return (get_capabilities() & static_cast<evmc_capabilities_flagset>(capability)) != 0;
705 }
evmc_capabilities_flagset get_capabilities() const noexcept
A method returning capabilities supported by the VM instance.
Definition: evmc.hpp:708
uint32_t evmc_capabilities_flagset
Alias for unsigned integer representing a set of bit flags of EVMC capabilities.
Definition: evmc.h:1114

◆ is_abi_compatible()

bool evmc::VM::is_abi_compatible ( ) const
inlinenoexcept

Checks whenever the VM instance is ABI compatible with the current EVMC API.

Definition at line 693 of file evmc.hpp.

693{ return m_instance->abi_version == EVMC_ABI_VERSION; }
@ EVMC_ABI_VERSION
The EVMC ABI version number of the interface declared in this file.
Definition: evmc.h:47
const int abi_version
EVMC ABI version implemented by the VM instance.
Definition: evmc.h:1141

◆ name()

char const * evmc::VM::name ( ) const
inlinenoexcept

The name of the EVMC VM implementation.

It MUST be a NULL-terminated not empty string. The content MUST be UTF-8 encoded (this implies ASCII encoding is also allowed).

Definition at line 696 of file evmc.hpp.

696{ return m_instance->name; }
const char * name
The name of the EVMC VM implementation.
Definition: evmc.h:1149

◆ operator bool()

evmc::VM::operator bool ( ) const
inlineexplicitnoexcept

Checks if contains a valid pointer to the VM instance.

Definition at line 690 of file evmc.hpp.

690{ return m_instance != nullptr; }

◆ operator=()

VM & evmc::VM::operator= ( VM &&  other)
inlinenoexcept

Move assignment operator.

Definition at line 676 of file evmc.hpp.

677 {
678 this->~VM();
679 m_instance = other.m_instance;
680 other.m_instance = nullptr;
681 return *this;
682 }
~VM() noexcept
Destructor responsible for automatically destroying the VM instance.
Definition: evmc.hpp:663

◆ set_option()

evmc_set_option_result evmc::VM::set_option ( const char  name[],
const char  value[] 
)
inlinenoexcept

Sets the option for the VM, if the feature is supported by the VM.

See also
evmc_set_option_fn

Definition at line 714 of file evmc.hpp.

715 {
716 return evmc_set_option(m_instance, name, value);
717 }
char const * name() const noexcept
The name of the EVMC VM implementation.
Definition: evmc.hpp:696
static enum evmc_set_option_result evmc_set_option(struct evmc_vm *vm, char const *name, char const *value)
Sets the option for the VM, if the feature is supported by the VM.
Definition: helpers.h:78

◆ version()

char const * evmc::VM::version ( ) const
inlinenoexcept

The version of the EVMC VM implementation, e.g.

"1.2.3b4".

It MUST be a NULL-terminated not empty string. The content MUST be UTF-8 encoded (this implies ASCII encoding is also allowed).

Definition at line 699 of file evmc.hpp.

699{ return m_instance->version; }
const char * version
The version of the EVMC VM implementation, e.g.
Definition: evmc.h:1157

The documentation for this class was generated from the following file: