mirror of https://github.com/status-im/evmc.git
Merge pull request #14 from ethereum/clang-format-config
Add clang-format config
This commit is contained in:
commit
cb2288b49d
|
@ -0,0 +1,42 @@
|
|||
---
|
||||
Language: Cpp
|
||||
BasedOnStyle: Chromium
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: Align
|
||||
BinPackParameters: false
|
||||
BraceWrapping:
|
||||
AfterClass: true
|
||||
AfterControlStatement: true
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
AfterObjCDeclaration: true
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
BeforeCatch: true
|
||||
BeforeElse: true
|
||||
SplitEmptyFunction: false
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeTernaryOperators: false
|
||||
ColumnLimit: 100
|
||||
ConstructorInitializerIndentWidth: 2
|
||||
IncludeCategories:
|
||||
- Regex: '^".*'
|
||||
Priority: 1
|
||||
- Regex: '^<boost.*'
|
||||
Priority: 98
|
||||
- Regex: '^<.*\.h>'
|
||||
Priority: 2
|
||||
- Regex: '^<.*'
|
||||
Priority: 99
|
||||
- Regex: '.*'
|
||||
Priority: 4
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IndentCaseLabels: false
|
||||
IndentWidth: 4
|
||||
MaxEmptyLinesToKeep: 2
|
||||
PenaltyBreakAssignment: 1
|
||||
PenaltyBreakComment: 50
|
||||
TabWidth: 4
|
||||
...
|
||||
|
|
@ -1,15 +1,14 @@
|
|||
#include <evmc/evmc.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "examplevm/examplevm.h"
|
||||
|
||||
|
||||
struct evmc_uint256be balance(struct evmc_context* context,
|
||||
const struct evmc_address* address)
|
||||
struct evmc_uint256be balance(struct evmc_context* context, const struct evmc_address* address)
|
||||
{
|
||||
struct evmc_uint256be ret = {.bytes = {1, 2, 3, 4}};
|
||||
return ret;
|
||||
|
@ -28,8 +27,8 @@ static void print_address(const struct evmc_address* address)
|
|||
printf("%x", address->bytes[i] & 0xff);
|
||||
}
|
||||
|
||||
static int account_exists(struct evmc_context* context,
|
||||
const struct evmc_address* address) {
|
||||
static int account_exists(struct evmc_context* context, const struct evmc_address* address)
|
||||
{
|
||||
printf("EVM-C: EXISTS @");
|
||||
print_address(address);
|
||||
printf("\n");
|
||||
|
@ -74,8 +73,11 @@ static size_t get_code_size(struct evmc_context* context, const struct evmc_addr
|
|||
return 0;
|
||||
}
|
||||
|
||||
static size_t copy_code(struct evmc_context* context, const struct evmc_address* address,
|
||||
size_t code_offset, uint8_t* buffer_data, size_t buffer_size)
|
||||
static size_t copy_code(struct evmc_context* context,
|
||||
const struct evmc_address* address,
|
||||
size_t code_offset,
|
||||
uint8_t* buffer_data,
|
||||
size_t buffer_size)
|
||||
{
|
||||
printf("EVM-C: COPYCODE @");
|
||||
print_address(address);
|
||||
|
@ -102,76 +104,67 @@ static void call(struct evmc_result* result,
|
|||
result->status_code = EVMC_FAILURE;
|
||||
}
|
||||
|
||||
static void get_tx_context(struct evmc_tx_context* result, struct evmc_context* context)
|
||||
{
|
||||
static void get_tx_context(struct evmc_tx_context* result, struct evmc_context* context) {}
|
||||
|
||||
}
|
||||
|
||||
static void get_block_hash(struct evmc_uint256be* result, struct evmc_context* context,
|
||||
static void get_block_hash(struct evmc_uint256be* result,
|
||||
struct evmc_context* context,
|
||||
int64_t number)
|
||||
{
|
||||
|
||||
}
|
||||
{}
|
||||
|
||||
/// EVM log callback.
|
||||
///
|
||||
/// @note The `evm_log` name is used to avoid conflict with `log()` C function.
|
||||
static void evm_log(struct evmc_context* context, const struct evmc_address* address,
|
||||
const uint8_t* data, size_t data_size,
|
||||
const struct evmc_uint256be topics[], size_t topics_count)
|
||||
static void evm_log(struct evmc_context* context,
|
||||
const struct evmc_address* address,
|
||||
const uint8_t* data,
|
||||
size_t data_size,
|
||||
const struct evmc_uint256be topics[],
|
||||
size_t topics_count)
|
||||
{
|
||||
printf("EVM-C: LOG%d\n", (int)topics_count);
|
||||
}
|
||||
|
||||
static const struct evmc_context_fn_table ctx_fn_table = {
|
||||
account_exists,
|
||||
get_storage,
|
||||
set_storage,
|
||||
get_balance,
|
||||
get_code_size,
|
||||
copy_code,
|
||||
selfdestruct,
|
||||
call,
|
||||
get_tx_context,
|
||||
get_block_hash,
|
||||
evm_log
|
||||
account_exists, get_storage, set_storage, get_balance, get_code_size, copy_code,
|
||||
selfdestruct, call, get_tx_context, get_block_hash, evm_log,
|
||||
};
|
||||
|
||||
/// Example how the API is supposed to be used.
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
struct evmc_instance* jit = evmc_create_examplevm();
|
||||
if (jit->abi_version != EVMC_ABI_VERSION)
|
||||
return 1; // Incompatible ABI version.
|
||||
|
||||
uint8_t const code[] = "Place some EVM bytecode here";
|
||||
const size_t code_size = sizeof(code);
|
||||
struct evmc_uint256be code_hash = {.bytes = {1, 2, 3,}};
|
||||
struct evmc_uint256be code_hash = {.bytes = {1, 2, 3}};
|
||||
uint8_t const input[] = "Hello World!";
|
||||
struct evmc_uint256be value = {{1, 0,}};
|
||||
struct evmc_address addr = {{0, 1, 2,}};
|
||||
struct evmc_uint256be value = {{1, 0}};
|
||||
struct evmc_address addr = {{0, 1, 2}};
|
||||
int64_t gas = 200000;
|
||||
|
||||
struct evmc_context ctx = {&ctx_fn_table};
|
||||
|
||||
struct evmc_message msg = {addr, addr, value, input, sizeof(input),
|
||||
code_hash, gas, 0};
|
||||
struct evmc_message msg = {addr, addr, value, input, sizeof(input), code_hash, gas, 0};
|
||||
|
||||
struct evmc_result result =
|
||||
jit->execute(jit, &ctx, EVMC_HOMESTEAD, &msg, code, code_size);
|
||||
struct evmc_result result = jit->execute(jit, &ctx, EVMC_HOMESTEAD, &msg, code, code_size);
|
||||
|
||||
printf("Execution result:\n");
|
||||
if (result.status_code != EVMC_SUCCESS) {
|
||||
printf(" EVM execution failure: %d\n", result.status_code);
|
||||
} else {
|
||||
if (result.status_code != EVMC_SUCCESS)
|
||||
{
|
||||
printf(" EVM execution failure: %d\n", result.status_code);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(" Gas used: %" PRId64 "\n", gas - result.gas_left);
|
||||
printf(" Gas left: %" PRId64 "\n", result.gas_left);
|
||||
printf(" Output size: %zd\n", result.output_size);
|
||||
|
||||
printf(" Output: ");
|
||||
size_t i = 0;
|
||||
for (i = 0; i < result.output_size; i++) {
|
||||
for (i = 0; i < result.output_size; i++)
|
||||
printf("%02x ", result.output_data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -44,8 +44,12 @@ static void free_result_output_data(struct evmc_result const* result)
|
|||
free((uint8_t*)result->output_data);
|
||||
}
|
||||
|
||||
static struct evmc_result execute(struct evmc_instance* instance, struct evmc_context* context,
|
||||
enum evmc_revision rev, const struct evmc_message* msg, const uint8_t* code, size_t code_size)
|
||||
static struct evmc_result execute(struct evmc_instance* instance,
|
||||
struct evmc_context* context,
|
||||
enum evmc_revision rev,
|
||||
const struct evmc_message* msg,
|
||||
const uint8_t* code,
|
||||
size_t code_size)
|
||||
{
|
||||
struct evmc_result ret = {.status_code = EVMC_INTERNAL_ERROR};
|
||||
if (code_size == 0)
|
||||
|
|
|
@ -4,4 +4,3 @@
|
|||
*/
|
||||
|
||||
#include <evmc/evmc.h>
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@ static_assert(offsetof(evmc_message, code_hash) % 8 == 0, "evmc_message.code_has
|
|||
|
||||
// Check enums match int size.
|
||||
// On GCC/clang the underlying type should be unsigned int, on MSVC int
|
||||
static_assert(
|
||||
sizeof(evmc_call_kind) == sizeof(int), "Enum `evmc_call_kind` is not the size of int");
|
||||
static_assert(sizeof(evmc_call_kind) == sizeof(int),
|
||||
"Enum `evmc_call_kind` is not the size of int");
|
||||
static_assert(sizeof(evmc_revision) == sizeof(int), "Enum `evmc_revision` is not the size of int");
|
||||
|
||||
static constexpr size_t optionalDataSize =
|
||||
|
|
|
@ -45,7 +45,7 @@ int main(int argc, char* argv[])
|
|||
auto add_option = desc.add_options();
|
||||
add_option("help", "Show help message");
|
||||
add_option("vm", opts::value(&vm_path)->value_name("path")->required(),
|
||||
"Path to the VM shared library to be tested");
|
||||
"Path to the VM shared library to be tested");
|
||||
|
||||
opts::positional_options_description positional;
|
||||
positional.add("vm", 1);
|
||||
|
@ -66,8 +66,9 @@ int main(int argc, char* argv[])
|
|||
opts::notify(variables_map);
|
||||
|
||||
auto symbols = dll::library_info{vm_path}.symbols();
|
||||
auto it = std::find_if(symbols.begin(), symbols.end(),
|
||||
[](const std::string& symbol) { return symbol.find("evmc_create_") == 0; });
|
||||
auto it = std::find_if(symbols.begin(), symbols.end(), [](const std::string& symbol) {
|
||||
return symbol.find("evmc_create_") == 0;
|
||||
});
|
||||
if (it == symbols.end())
|
||||
{
|
||||
std::cerr << "EVMC create function not found in " << vm_path.string() << "\n";
|
||||
|
|
Loading…
Reference in New Issue