Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVM instruction names #252

Merged
merged 3 commits into from
Jun 25, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion evmc
Submodule evmc updated 38 files
+42 −0 .clang-format
+12 −7 CMakeLists.txt
+4 −1 circle.yml
+3 −1 cmake/cable/CableBuildInfo.cmake
+3 −2 cmake/cable/CableBuildType.cmake
+30 −4 cmake/cable/CableCompilerSettings.cmake
+1 −0 cmake/cable/CableToolchains.cmake
+83 −0 cmake/cable/README.md
+28 −9 cmake/cable/bootstrap.cmake
+7 −5 cmake/cable/buildinfo/buildinfo.c.in
+42 −5 cmake/cable/buildinfo/buildinfo.cmake
+6 −4 cmake/cable/buildinfo/buildinfo.h.in
+15 −9 cmake/cable/buildinfo/gitinfo.cmake
+1 −0 cmake/cable/defaults/HunterCacheServers-passwords.cmake
+1 −0 cmake/cable/defaults/HunterCacheServers.cmake
+1 −0 cmake/cable/toolchains/cxx11-32bit.cmake
+10 −0 cmake/cable/toolchains/cxx11-c99.cmake
+1 −0 cmake/cable/toolchains/cxx11.cmake
+1 −0 cmake/cable/toolchains/default.cmake
+1 −0 cmake/cable/toolchains/mips64.cmake
+24 −0 cmake/cable/toolchains/powerpc64.cmake
+35 −42 examples/capi.c
+7 −3 examples/examplevm/examplevm.c
+455 −359 include/evmc/evmc.h
+210 −0 include/evmc/instructions.h
+5 −0 lib/CMakeLists.txt
+15 −0 lib/instructions/CMakeLists.txt
+1,337 −0 lib/instructions/instruction_metrics.c
+1,060 −0 lib/instructions/instruction_names.c
+6 −1 test/CMakeLists.txt
+5 −0 test/integration/CMakeLists.txt
+11 −0 test/integration/compilation/CMakeLists.txt
+6 −0 test/integration/compilation/compilation_test.c
+11 −0 test/unittests/CMakeLists.txt
+110 −0 test/unittests/test_instructions.cpp
+1 −4 test/vmtester/CMakeLists.txt
+2 −2 test/vmtester/tests.cpp
+4 −3 test/vmtester/vmtester.cpp
3 changes: 1 addition & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ find_package(Threads REQUIRED)

add_library(hera
eei.cpp eei.h
evm-instructions.cpp evm-instructions.h
hera.cpp hera.h
)

Expand All @@ -15,7 +14,7 @@ if(HERA_DEBUGGING)
endif()

target_include_directories(hera PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${evm_include_dir})
target_link_libraries(hera PRIVATE evmc libevm2wasm binaryen::binaryen Threads::Threads)
target_link_libraries(hera PRIVATE evmc::evmc evmc::instructions libevm2wasm binaryen::binaryen Threads::Threads)
if(NOT WIN32)
if(CMAKE_COMPILER_IS_GNUCXX)
set_target_properties(hera PROPERTIES LINK_FLAGS "-Wl,--no-undefined")
Expand Down
9 changes: 6 additions & 3 deletions src/eei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
#include <array>
#include "eei.h"
#include "exceptions.h"
#include "evm-instructions.h"

#include <evmc/instructions.h>

using namespace std;
using namespace wasm;
Expand Down Expand Up @@ -177,8 +178,10 @@ inline int64_t maxCallGas(int64_t gas) {
heraAssert(sp <= (1024 * stackItemSize), "EVM stack pointer out of bounds.");
heraAssert(opcode >= 0x00 && opcode <= 0xff, "Invalid EVM instruction.");

auto it = evmInstructionNames.find(static_cast<uint8_t>(opcode));
string opName = (it != evmInstructionNames.end()) ? it->second : "UNKNOWN";
const char* const* const opNamesTable = evmc_get_instruction_names_table(EVMC_BYZANTIUM);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG, that looks hideous

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. If you want I can change it to const char* const* :D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any better option?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because you cannot return an array in C. It must be a const pointer to an item (which is const char*).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can just use auto or auto*.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that ensure constness though?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The best would be const auto.

const char* opName = opNamesTable[static_cast<uint8_t>(opcode)];
if (opName == nullptr)
opName = "UNDEFINED";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is undefined used by the tracing format? The code above used unknown previously.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure tests depends on this, but the "undefined" name comes from https://github.com/ethereum/evmc/blob/master/include/evmc/evmc.h#L229.


cout << "{\"depth\":" << dec << msg.depth
<< ",\"gas\":" << result.gasLeft
Expand Down
170 changes: 0 additions & 170 deletions src/evm-instructions.cpp

This file was deleted.

34 changes: 0 additions & 34 deletions src/evm-instructions.h

This file was deleted.