EVMC
example_vm.c File Reference

Example implementation of the EVMC VM interface. More...

#include "example_vm.h"
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Classes

struct  example_vm
 The example VM instance struct extending the evmc_vm. More...
 

Functions

static void destroy (struct evmc_vm *vm)
 The implementation of the evmc_vm::destroy() method.
 
static evmc_capabilities_flagset get_capabilities (struct evmc_vm *vm)
 The example implementation of the evmc_vm::get_capabilities() method.
 
static enum evmc_set_option_result set_option (struct evmc_vm *instance, const char *name, const char *value)
 Example VM options. More...
 
static void free_result_output_data (const struct evmc_result *result)
 The implementation of the evmc_result::release() method that frees the output buffer attached to the result object. More...
 
static struct evmc_result execute (struct evmc_vm *instance, const struct evmc_host_interface *host, struct evmc_host_context *context, enum evmc_revision rev, const struct evmc_message *msg, const uint8_t *code, size_t code_size)
 The example implementation of the evmc_vm::execute() method.
 
struct evmc_vmevmc_create_example_vm ()
 Example of a function creating an instance of an example EVM implementation. More...
 

Detailed Description

Example implementation of the EVMC VM interface.

This VM does not do anything useful except for showing how EVMC VM API should be implemented. The implementation is done in C only, but could be done in C++ in very similar way.

Definition in file example_vm.c.

Function Documentation

◆ free_result_output_data()

static void free_result_output_data ( const struct evmc_result result)
static

The implementation of the evmc_result::release() method that frees the output buffer attached to the result object.

Definition at line 71 of file example_vm.c.

72 {
73  free((uint8_t*)result->output_data);
74 }
const uint8_t * output_data
The reference to output data.
Definition: evmc.h:364

◆ set_option()

static enum evmc_set_option_result set_option ( struct evmc_vm instance,
const char *  name,
const char *  value 
)
static

Example VM options.

The implementation of the evmc_vm::set_option() method. VMs are allowed to omit this method implementation.

Definition at line 46 of file example_vm.c.

49 {
50  struct example_vm* vm = (struct example_vm*)instance;
51  if (strcmp(name, "verbose") == 0)
52  {
53  if (!value)
54  return EVMC_SET_OPTION_INVALID_VALUE;
55 
56  char* end = NULL;
57  long int v = strtol(value, &end, 0);
58  if (end == value) // Parsing the value failed.
59  return EVMC_SET_OPTION_INVALID_VALUE;
60  if (v > 9 || v < -1) // Not in the valid range.
61  return EVMC_SET_OPTION_INVALID_VALUE;
62  vm->verbose = (int)v;
63  return EVMC_SET_OPTION_SUCCESS;
64  }
65 
66  return EVMC_SET_OPTION_INVALID_NAME;
67 }
The example VM instance struct extending the evmc_vm.
Definition: example_vm.c:23
int verbose
The verbosity level.
Definition: example_vm.c:26