Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.

Cpp implementation #201

Merged
merged 28 commits into from
Aug 2, 2018
Merged

Cpp implementation #201

merged 28 commits into from
Aug 2, 2018

Conversation

esteve
Copy link
Contributor

@esteve esteve commented Mar 22, 2018

This is just a quick and rather hacky C++ port of the Javascript translator. I've added a dependency on Hunter and fmtlib for the string manipulation code and also copied over the .clang-format from cpp-ethereum.

Connects to #4

@esteve
Copy link
Contributor Author

esteve commented Mar 22, 2018

I think Travis is failing because the C++ compiler/standard library is rather old, there doesn't seem to be anything wrong with that piece of code.

@lrettig
Copy link
Member

lrettig commented Mar 22, 2018

Thanks @esteve! @chfast you're probably the right person to review this.


// maps the async ops to their call back function
static std::map<opcodeEnum, std::string> callbackFuncs = {{opcodeEnum::SSTORE, "$callback"},
{opcodeEnum::SLOAD, "$callback_256"}, {opcodeEnum::CREATE, "$callback_160"},
Copy link
Member

Choose a reason for hiding this comment

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

Please do not include more of the on the same line, just one per line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in ea8ff91

Copy link
Collaborator

Choose a reason for hiding this comment

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

@axic You have to give up hand-tuning the code formatting.

Copy link
Member

Choose a reason for hiding this comment

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

This format is super hard to read, there must be a way to disable it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I've found a trick to do it in clang-format: add , after the last item.

@axic
Copy link
Member

axic commented Mar 22, 2018

Is wast-sync.h and wast-async.h handwritten, because I don't see any generator tool? Also I'd prefer them to be .cpp files to avoid recompiling them if not needed (and personally I do not like gigantic header files 😉).

bin/evm2wasm.js Outdated
@@ -1,4 +1,4 @@
#!/usr/bin/env node
#!/usr/bin/env nodejs
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one was a leftover from when @lrettig and I tried the Javascript translator, Node is installed as nodejs in Debian.

Reverted in e519924


std::string opcodeToString(opcodeEnum opcode)
{
switch (opcode)
Copy link
Member

Choose a reason for hiding this comment

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

How about a map for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to avoid callers of this function to deal with std::pair, but I can change it to a map if you prefer.

@esteve
Copy link
Contributor Author

esteve commented Mar 23, 2018

Is wast-sync.h and wast-async.h handwritten, because I don't see any generator tool?

Just a bit of sed here and there in wast.js and wast-async.js, but I'm going to write a generator so it's all done automatically.

Also I'd prefer them to be .cpp files to avoid recompiling them if not needed

Yeah, I agree, it's rather awful 😄 I'm going to split them up and see if they look better.

@chfast
Copy link
Collaborator

chfast commented Mar 23, 2018

I'm not sure how much work it is, but I'd rather stick to C++ library only. Adding additional dependencies is quite a big deal and we also want to compile that to WASM later on. If possible I'd use just std::string concatenation.

@axic axic mentioned this pull request Mar 26, 2018
@axic
Copy link
Member

axic commented Mar 26, 2018

@esteve do you want to create a new PR for the samples?

@axic
Copy link
Member

axic commented Mar 26, 2018

Also can you please rebase and squash some commits?

@lrettig
Copy link
Member

lrettig commented Mar 27, 2018 via email

@lrettig
Copy link
Member

lrettig commented Mar 27, 2018 via email

@esteve
Copy link
Contributor Author

esteve commented Mar 27, 2018

@axic do you want to create a new PR for the samples?
@lrettig But go for it if you get to it first, @esteve!

Done! :-) #215

@esteve esteve force-pushed the cpp-implementation branch from e519924 to ea70359 Compare March 27, 2018 14:10
@axic
Copy link
Member

axic commented Apr 10, 2018

@lrettig can you rebase this so it runs on circleci? Also the first and last commit are not useful anymore (the useful parts have been merged since).

@esteve esteve force-pushed the cpp-implementation branch from ea70359 to 3c49c5c Compare April 13, 2018 13:29
@esteve
Copy link
Contributor Author

esteve commented Apr 13, 2018

@axic done, sorry for the delay. Been busy lately, but I'll address the pending feedback in the upcoming days (I hope :-))

@jwasinger jwasinger force-pushed the cpp-implementation branch from 92fb153 to 4ed84b7 Compare April 22, 2018 08:18
@axic axic force-pushed the cpp-implementation branch from 4ed84b7 to fe693a9 Compare April 23, 2018 16:45
@@ -351,9 +351,9 @@ struct WastCode
std::string imports;
};

std::string evm2wasm(const std::string& input);
std::string evm2wasm(const std::vector<char>& input);
Copy link
Member

Choose a reason for hiding this comment

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

Why change the public API? And what is the desired content after the change?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is bad choice of the type. If you want to handle multiple input types consider using string_view (not in standard yet) or pass iterators.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good points guys. Maybe it wasn't the most well-thought-out change on my part, and I will revert it.. My thinking was that bytecode is better expressed as an array of bytes as opposed to a null-terminated string.

@jwasinger jwasinger force-pushed the cpp-implementation branch from 750793d to 3db366d Compare April 28, 2018 07:36
@axic axic force-pushed the cpp-implementation branch from 3db366d to 9476753 Compare May 10, 2018 11:00
@axic axic force-pushed the cpp-implementation branch 6 times, most recently from 32721ae to d9fba6a Compare May 26, 2018 15:02
esteve and others added 24 commits August 2, 2018 03:38
@axic axic force-pushed the cpp-implementation branch from 143eaf3 to a01efa5 Compare August 2, 2018 02:40
@axic axic force-pushed the cpp-implementation branch from a01efa5 to a4fc405 Compare August 2, 2018 02:45
@axic axic merged commit 0bae4c6 into ewasm:master Aug 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants