mirror of https://github.com/status-im/evmc.git
Improve EVMC capabilities
This commit is contained in:
parent
7a8d1166d8
commit
dc495408be
|
@ -28,6 +28,12 @@ static void destroy(struct evmc_instance* evm)
|
||||||
free(evm);
|
free(evm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static evmc_capabilities_flagset get_capabilities(struct evmc_instance* vm)
|
||||||
|
{
|
||||||
|
(void)vm;
|
||||||
|
return EVMC_CAPABILITY_EVM1 | EVMC_CAPABILITY_EWASM;
|
||||||
|
}
|
||||||
|
|
||||||
/// Example options.
|
/// Example options.
|
||||||
///
|
///
|
||||||
/// VMs are allowed to omit this function implementation.
|
/// VMs are allowed to omit this function implementation.
|
||||||
|
@ -150,6 +156,7 @@ struct evmc_instance* evmc_create_example_vm()
|
||||||
.version = STR(PROJECT_VERSION),
|
.version = STR(PROJECT_VERSION),
|
||||||
.destroy = destroy,
|
.destroy = destroy,
|
||||||
.execute = execute,
|
.execute = execute,
|
||||||
|
.get_capabilites = get_capabilities,
|
||||||
.set_option = set_option,
|
.set_option = set_option,
|
||||||
.set_tracer = set_tracer,
|
.set_tracer = set_tracer,
|
||||||
};
|
};
|
||||||
|
|
|
@ -768,20 +768,27 @@ typedef struct evmc_result (*evmc_execute_fn)(struct evmc_instance* instance,
|
||||||
*/
|
*/
|
||||||
enum evmc_capabilities
|
enum evmc_capabilities
|
||||||
{
|
{
|
||||||
EVMC_CAPABILITY_EVM1 = 1, /**< The VM is capable of executing EVM1 bytecode. */
|
EVMC_CAPABILITY_EVM1 = (1u << 0), /**< The VM is capable of executing EVM1 bytecode. */
|
||||||
EVMC_CAPABILITY_EWASM = 2 /**< The VM is capable of execution ewasm bytecode. */
|
EVMC_CAPABILITY_EWASM = (1u << 1) /**< The VM is capable of execution ewasm bytecode. */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias for unsigned integer representing a set of bit flags of EVMC capabilities.
|
||||||
|
*
|
||||||
|
* @see evmc_capabilities
|
||||||
|
*/
|
||||||
|
typedef uint32_t evmc_capabilities_flagset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the supported capabilities of the VM instance.
|
* Return the supported capabilities of the VM instance.
|
||||||
*
|
*
|
||||||
* This function MAY be invoked multiple times for a single VM instance,
|
* This function MAY be invoked multiple times for a single VM instance,
|
||||||
* and its value MAY be influenced by calls to set_option.
|
* and its value MAY be influenced by calls to evmc_instance::set_option.
|
||||||
*
|
*
|
||||||
* @param instance The EVM instance.
|
* @param instance The EVM instance.
|
||||||
* @return The supported capabilities of the VM, @see ::evmc_capabilities.
|
* @return The supported capabilities of the VM. @see evmc_capabilities.
|
||||||
*/
|
*/
|
||||||
typedef int (*evmc_get_capabilities_fn)(struct evmc_instance* instance);
|
typedef evmc_capabilities_flagset (*evmc_get_capabilities_fn)(struct evmc_instance* instance);
|
||||||
|
|
||||||
/** The opaque type representing a Client-side tracer object. */
|
/** The opaque type representing a Client-side tracer object. */
|
||||||
struct evmc_tracer_context;
|
struct evmc_tracer_context;
|
||||||
|
@ -890,7 +897,7 @@ struct evmc_instance
|
||||||
evmc_execute_fn execute;
|
evmc_execute_fn execute;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pointer to function returning capabilities supported by the EVM instance.
|
* Pointer to function returning capabilities supported by the VM instance.
|
||||||
*
|
*
|
||||||
* The value returned might change when different options are requested via set_option.
|
* The value returned might change when different options are requested via set_option.
|
||||||
*
|
*
|
||||||
|
|
|
@ -41,6 +41,17 @@ static inline const char* evmc_vm_version(struct evmc_instance* instance)
|
||||||
return instance->version;
|
return instance->version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the VM instance has the given capability.
|
||||||
|
*
|
||||||
|
* @see evmc_get_capabilities_fn
|
||||||
|
*/
|
||||||
|
static inline bool evmc_vm_has_capability(struct evmc_instance* vm,
|
||||||
|
enum evmc_capabilities capability)
|
||||||
|
{
|
||||||
|
return (vm->get_capabilites(vm) & (evmc_capabilities_flagset)capability) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroys the VM instance.
|
* Destroys the VM instance.
|
||||||
*
|
*
|
||||||
|
|
|
@ -117,3 +117,10 @@ TEST_F(evmc_vm_test, set_tracer)
|
||||||
if (vm->set_tracer)
|
if (vm->set_tracer)
|
||||||
vm->set_tracer(vm, tracer_callback, nullptr);
|
vm->set_tracer(vm, tracer_callback, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(evmc_vm_test, capabilities)
|
||||||
|
{
|
||||||
|
// The VM should have at least one of EVM1 or EWASM capabilities.
|
||||||
|
EXPECT_TRUE(evmc_vm_has_capability(vm, EVMC_CAPABILITY_EVM1) ||
|
||||||
|
evmc_vm_has_capability(vm, EVMC_CAPABILITY_EWASM));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue