From 97cc968a133247e729ed1d189d35ef2b7b53b3d4 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 24 May 2017 18:34:19 +0200 Subject: Initial EVM1.5 assembly implementation. --- libjulia/backends/evm/AbstractAssembly.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'libjulia/backends/evm/AbstractAssembly.h') diff --git a/libjulia/backends/evm/AbstractAssembly.h b/libjulia/backends/evm/AbstractAssembly.h index de31be28..ba2c8e20 100644 --- a/libjulia/backends/evm/AbstractAssembly.h +++ b/libjulia/backends/evm/AbstractAssembly.h @@ -41,6 +41,9 @@ struct Identifier; namespace julia { +/// +/// Assembly class that abstracts both the libevmasm assembly and the new julia evm assembly. +/// class AbstractAssembly { public: @@ -66,6 +69,21 @@ public: /// Append a reference to a to-be-linked symobl. /// Currently, we assume that the value is always a 20 byte number. virtual void appendLinkerSymbol(std::string const& _name) = 0; + + /// Append a jump instruction. + /// @param _stackDiffAfter the stack adjustment after this instruction. + virtual void appendJump(int _stackDiffAfter) = 0; + + /// Append a jump-to-immediate operation. + virtual void appendJumpTo(LabelID _label, int _stackDiffAfter = 0) = 0; + /// Append a jump-to-if-immediate operation. + virtual void appendJumpToIf(LabelID _label) = 0; + /// Start a subroutine. + virtual void appendBeginsub(LabelID _label, int _arguments) = 0; + /// Call a subroutine. + virtual void appendJumpsub(LabelID _label, int _arguments, int _returns) = 0; + /// Return from a subroutine. + virtual void appendReturnsub(int _returns) = 0; }; enum class IdentifierContext { LValue, RValue }; @@ -74,7 +92,7 @@ enum class IdentifierContext { LValue, RValue }; /// to inline assembly (not used in standalone assembly mode). struct ExternalIdentifierAccess { - using Resolver = std::function; + using Resolver = std::function; /// Resolve a an external reference given by the identifier in the given context. /// @returns the size of the value (number of stack slots) or size_t(-1) if not found. Resolver resolve; -- cgit v1.2.3 From 0185f3cbf6aae954d8c59a556af0e150850022bc Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 31 May 2017 13:06:51 +0200 Subject: Correct stack height adjustment after returnsub. --- libjulia/backends/evm/AbstractAssembly.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libjulia/backends/evm/AbstractAssembly.h') diff --git a/libjulia/backends/evm/AbstractAssembly.h b/libjulia/backends/evm/AbstractAssembly.h index ba2c8e20..73c6699f 100644 --- a/libjulia/backends/evm/AbstractAssembly.h +++ b/libjulia/backends/evm/AbstractAssembly.h @@ -83,7 +83,7 @@ public: /// Call a subroutine. virtual void appendJumpsub(LabelID _label, int _arguments, int _returns) = 0; /// Return from a subroutine. - virtual void appendReturnsub(int _returns) = 0; + virtual void appendReturnsub(int _returns, int _stackDiffAfter = 0) = 0; }; enum class IdentifierContext { LValue, RValue }; -- cgit v1.2.3 From 19f707aeaa23b55a4a5940977a9d6351d1f06938 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 1 Jun 2017 18:16:38 +0200 Subject: Some more comments. --- libjulia/backends/evm/AbstractAssembly.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'libjulia/backends/evm/AbstractAssembly.h') diff --git a/libjulia/backends/evm/AbstractAssembly.h b/libjulia/backends/evm/AbstractAssembly.h index 73c6699f..baed833b 100644 --- a/libjulia/backends/evm/AbstractAssembly.h +++ b/libjulia/backends/evm/AbstractAssembly.h @@ -72,17 +72,22 @@ public: /// Append a jump instruction. /// @param _stackDiffAfter the stack adjustment after this instruction. + /// This is helpful to stack height analysis if there is no continuing control flow. virtual void appendJump(int _stackDiffAfter) = 0; /// Append a jump-to-immediate operation. + /// @param _stackDiffAfter the stack adjustment after this instruction. virtual void appendJumpTo(LabelID _label, int _stackDiffAfter = 0) = 0; /// Append a jump-to-if-immediate operation. virtual void appendJumpToIf(LabelID _label) = 0; - /// Start a subroutine. + /// Start a subroutine identified by @a _label that takes @a _arguments + /// stack slots as arguments. virtual void appendBeginsub(LabelID _label, int _arguments) = 0; - /// Call a subroutine. + /// Call a subroutine identified by @a _label, taking @a _arguments from the + /// stack upon call and putting @a _returns arguments onto the stack upon return. virtual void appendJumpsub(LabelID _label, int _arguments, int _returns) = 0; /// Return from a subroutine. + /// @param _stackDiffAfter the stack adjustment after this instruction. virtual void appendReturnsub(int _returns, int _stackDiffAfter = 0) = 0; }; -- cgit v1.2.3 From 6b3e7f79cf42edd031a2000978e394d818212b39 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 8 Jun 2017 15:52:15 +0200 Subject: Comments and consistent variable names. --- libjulia/backends/evm/AbstractAssembly.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'libjulia/backends/evm/AbstractAssembly.h') diff --git a/libjulia/backends/evm/AbstractAssembly.h b/libjulia/backends/evm/AbstractAssembly.h index baed833b..f667c1a7 100644 --- a/libjulia/backends/evm/AbstractAssembly.h +++ b/libjulia/backends/evm/AbstractAssembly.h @@ -77,15 +77,15 @@ public: /// Append a jump-to-immediate operation. /// @param _stackDiffAfter the stack adjustment after this instruction. - virtual void appendJumpTo(LabelID _label, int _stackDiffAfter = 0) = 0; + virtual void appendJumpTo(LabelID _labelId, int _stackDiffAfter = 0) = 0; /// Append a jump-to-if-immediate operation. - virtual void appendJumpToIf(LabelID _label) = 0; - /// Start a subroutine identified by @a _label that takes @a _arguments + virtual void appendJumpToIf(LabelID _labelId) = 0; + /// Start a subroutine identified by @a _labelId that takes @a _arguments /// stack slots as arguments. - virtual void appendBeginsub(LabelID _label, int _arguments) = 0; - /// Call a subroutine identified by @a _label, taking @a _arguments from the + virtual void appendBeginsub(LabelID _labelId, int _arguments) = 0; + /// Call a subroutine identified by @a _labelId, taking @a _arguments from the /// stack upon call and putting @a _returns arguments onto the stack upon return. - virtual void appendJumpsub(LabelID _label, int _arguments, int _returns) = 0; + virtual void appendJumpsub(LabelID _labelId, int _arguments, int _returns) = 0; /// Return from a subroutine. /// @param _stackDiffAfter the stack adjustment after this instruction. virtual void appendReturnsub(int _returns, int _stackDiffAfter = 0) = 0; -- cgit v1.2.3