Skip to content

[WIP] Support builtin functions in Yul#2361

Closed
axic wants to merge 3 commits intodevelopfrom
julia-builtin-funcs
Closed

[WIP] Support builtin functions in Yul#2361
axic wants to merge 3 commits intodevelopfrom
julia-builtin-funcs

Conversation

@axic
Copy link
Contributor

@axic axic commented Jun 9, 2017

Depends on #3226 and #3238.

if (m_julia)
{
Scope& rootScope = scope(&_block);
rootScope.registerFunction("abort", {}, {});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looked at making this into a vector but that looked just way more code than it needs to be.

Copy link
Contributor

Choose a reason for hiding this comment

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

The following might work:

for (auto const& f: vector<tuple<string, strings, strings>>{
    {"discardu256", { "u256" }, { }},
    {"splitu256tou64", { "u256" }, { "u64", ... }},
    ...
})
    rootScope.registerFunction(get<0>(f), get<1>(f), get<2>(f));

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 had the same code, but for some reason I got an error when providing the list as constructor parameters to the vector.

Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to write a small parsing function for something like keccak256(u256, u256) -> u256, then it is also much more readable.

Copy link
Contributor

Choose a reason for hiding this comment

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

and parsing here would just consist of boost::split(s, "(") calls.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds like a better idea.

rootScope.registerFunction("mulu256", { "u256", "u256" }, { "u256" });
rootScope.registerFunction("divu256", { "u256", "u256" }, { "u256" });
rootScope.registerFunction("modu256", { "u256", "u256" }, { "u256" });
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needs to be updated with all the functions from #2129.


m_assembly.setSourceLocation(_call.location);

if (_call.functionName.name == "abort")
Copy link
Contributor Author

@axic axic Jun 9, 2017

Choose a reason for hiding this comment

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

This could be handled with a vector which lists the name, instruction, argument and return value count.

@axic axic force-pushed the julia-builtin-funcs branch from 1b8c0fa to af02635 Compare June 9, 2017 12:59

m_assembly.setSourceLocation(_call.location);

if (m_builtinFunctions.count(_call.functionName.name))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you combine this with functionalInstruction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't see a simple way which would keep it readable. Also note we have two different kinds of builtins:

  • simple ones, which fit this scheme
  • complex ones, which don't (such as split/combine)

For the second case it might be better to inject a FunctionDefinition.

@axic axic force-pushed the julia-builtin-funcs branch 3 times, most recently from c6d81cb to 4c1142e Compare June 9, 2017 14:53
@axic axic force-pushed the julia-builtin-funcs branch 2 times, most recently from 2570a97 to 3f75966 Compare June 19, 2017 11:06
@chriseth chriseth force-pushed the julia-builtin-funcs branch from 3f75966 to 3c71937 Compare June 22, 2017 17:24
m_stackAdjustment(_stackAdjustment),
m_context(_context)
{
m_builtinFunctions["abort"] = solidity::Instruction::INVALID;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this really be a member or rather just a static variable in the cpp file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Statis variable should be fine.

@chriseth
Copy link
Contributor

Added a commit, please be careful when rebasing / pushing.

@axic axic force-pushed the julia-builtin-funcs branch from 3c71937 to 7e1673c Compare July 1, 2017 23:43
@axic axic force-pushed the julia-builtin-funcs branch 4 times, most recently from b139d31 to 1ae77fc Compare July 8, 2017 22:40
@axic
Copy link
Contributor Author

axic commented Jul 8, 2017

Rebased and squashed commits. Need to add the proper list of builtin funcs and it is ready to merge.

{
auto openParen = find(sig.begin(), sig.end(), '(');
auto closeParen = find(openParen, sig.end(), ')');
auto arrow = find(closeParen, sig.end(), '>');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should have some asserts for these three.

@axic axic force-pushed the julia-builtin-funcs branch from 1ae77fc to b069a39 Compare July 19, 2017 11:09
@axic
Copy link
Contributor Author

axic commented Jul 28, 2017

Depends on finalising the builtin list in #2129.

@axic axic force-pushed the julia-builtin-funcs branch from b069a39 to bd07b24 Compare June 12, 2018 23:00
@axic axic removed the in progress label Aug 2, 2018
@axic axic changed the title [WIP] Support builtin functions in Julia [WIP] Support builtin functions in Yul Nov 13, 2018
@chriseth
Copy link
Contributor

Replaced by #5616

@chriseth chriseth closed this Dec 10, 2018
@chriseth chriseth deleted the julia-builtin-funcs branch February 7, 2019 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants