Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
.swp
.gch

/build
/.idea
/deps

tmp/*
!tmp/.gitkeep
node_modules/

libs/evm2wasm/gadgets.c
16 changes: 12 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS Off)

add_compile_options(-Wall -Wextra -Wconversion -Wno-sign-conversion -Wno-unknown-pragmas)
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be removed.


project(evm2wasm)

include(ProjectBinaryen)

add_subdirectory(libs)
Copy link
Member

Choose a reason for hiding this comment

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

Please keep the libs/tools layout.

add_subdirectory(tools)
add_custom_target(gen_gadgets
${PROJECT_SOURCE_DIR}/gen_gadgets.sh
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)

add_executable(evm2wasm
evm2wasm.cpp
evm2wast.c
gadgets.c
)
add_dependencies(evm2wasm gen_gadgets)
target_link_libraries(evm2wasm PRIVATE binaryen::binaryen)
10 changes: 10 additions & 0 deletions libs/evm2wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
set(include_dir ${PROJECT_SOURCE_DIR}/include)

add_custom_target(gen_gadgets
${CMAKE_CURRENT_SOURCE_DIR}/gen_gadgets.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/gadgets.c
)

add_library(libevm2wasm
evm2wasm.cpp ${include_dir}/evm2wasm.h
evm2wast.c
gadgets.c
)
set_target_properties(libevm2wasm PROPERTIES OUTPUT_NAME evm2wasm)

add_dependencies(libevm2wasm gen_gadgets)

target_include_directories(libevm2wasm PUBLIC ${include_dir})
target_link_libraries(libevm2wasm PRIVATE binaryen::binaryen)
18 changes: 13 additions & 5 deletions libs/evm2wasm/evm2wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <wasm-s-parser.h>
#include <wasm-validator.h>

#include "evm2wast.h"

#include "evm2wast.h"

using namespace std;

namespace {
Expand Down Expand Up @@ -48,14 +52,18 @@ string wast2wasm(const string& input, bool debug = false) {
return output.str();
}

string evm2wast(const string& input) {
(void)input;
// FIXME: do evm magic here
return "(module (export \"main\" (func $main)) (func $main))";
string evm2wast_wrapper(string input) {
size_t len = 0;
char *output = NULL;
if (evm2wast(input.c_str(), input.size(), &output, &len) < 0)
return string();
string ret(output, output + len);
free(output);
return ret;
}

}

string evm2wasm(const string& input) {
return wast2wasm(evm2wast(input));
return wast2wasm(evm2wast_wrapper(input), true);
}
Loading