aboutsummaryrefslogtreecommitdiffstats
path: root/libyul
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-12-04 22:03:53 +0800
committerchriseth <chris@ethereum.org>2018-12-04 22:40:50 +0800
commitc8e201e520b874439f2525e6cfe02d387654b2c1 (patch)
treee87f0d7399b779046f5674bb7c6feb4827a7706d /libyul
parent126ed2e990280b7200a7872d8d6f5b8db14e4b0a (diff)
downloaddexon-solidity-c8e201e520b874439f2525e6cfe02d387654b2c1.tar
dexon-solidity-c8e201e520b874439f2525e6cfe02d387654b2c1.tar.gz
dexon-solidity-c8e201e520b874439f2525e6cfe02d387654b2c1.tar.bz2
dexon-solidity-c8e201e520b874439f2525e6cfe02d387654b2c1.tar.lz
dexon-solidity-c8e201e520b874439f2525e6cfe02d387654b2c1.tar.xz
dexon-solidity-c8e201e520b874439f2525e6cfe02d387654b2c1.tar.zst
dexon-solidity-c8e201e520b874439f2525e6cfe02d387654b2c1.zip
Provide Yul Object builtins.
Diffstat (limited to 'libyul')
-rw-r--r--libyul/CMakeLists.txt1
-rw-r--r--libyul/Dialect.cpp76
-rw-r--r--libyul/Dialect.h1
3 files changed, 78 insertions, 0 deletions
diff --git a/libyul/CMakeLists.txt b/libyul/CMakeLists.txt
index 7ed84ff5..e7383e4a 100644
--- a/libyul/CMakeLists.txt
+++ b/libyul/CMakeLists.txt
@@ -6,6 +6,7 @@ add_library(yul
AsmPrinter.cpp
AsmScope.cpp
AsmScopeFiller.cpp
+ Dialect.cpp
Object.cpp
ObjectParser.cpp
backends/evm/EVMAssembly.cpp
diff --git a/libyul/Dialect.cpp b/libyul/Dialect.cpp
new file mode 100644
index 00000000..99718787
--- /dev/null
+++ b/libyul/Dialect.cpp
@@ -0,0 +1,76 @@
+/*
+ This file is part of solidity.
+
+ solidity is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ solidity is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with solidity. If not, see <http://www.gnu.org/licenses/>.
+*/
+/**
+ * Yul dialect.
+ */
+
+#include <libyul/Dialect.h>
+
+#include <map>
+
+using namespace yul;
+using namespace std;
+
+namespace
+{
+
+void addFunction(
+ map<YulString, BuiltinFunction>& _repository,
+ string const& _name,
+ size_t _params,
+ size_t _returns,
+ bool _movable
+)
+{
+ _repository[YulString{_name}] = BuiltinFunction{
+ YulString{_name},
+ vector<Type>(_params),
+ vector<Type>(_returns),
+ _movable
+ };
+}
+
+class GenericBuiltins: public Builtins
+{
+public:
+ GenericBuiltins(map<YulString, BuiltinFunction> const& _functions): m_functions(_functions) {}
+ BuiltinFunction const* query(YulString _name) const
+ {
+ auto it = m_functions.find(_name);
+ if (it != end(m_functions))
+ return &it->second;
+ else
+ return nullptr;
+ }
+private:
+ map<YulString, BuiltinFunction> const& m_functions;
+};
+
+}
+
+Dialect Dialect::strictAssemblyForEVMObjects()
+{
+ static map<YulString, BuiltinFunction> functions;
+ if (functions.empty())
+ {
+ addFunction(functions, "datasize", 1, 1, true);
+ addFunction(functions, "dataoffset", 1, 1, true);
+ addFunction(functions, "datacopy", 3, 0, false);
+ }
+ // The EVM instructions will be moved to builtins at some point.
+ return Dialect{AsmFlavour::Strict, std::make_shared<GenericBuiltins>(functions)};
+}
diff --git a/libyul/Dialect.h b/libyul/Dialect.h
index 3ea16014..b78f1aaf 100644
--- a/libyul/Dialect.h
+++ b/libyul/Dialect.h
@@ -72,6 +72,7 @@ struct Dialect
// The EVM instructions will be moved to builtins at some point.
return Dialect{AsmFlavour::Strict, std::make_shared<Builtins>()};
}
+ static Dialect strictAssemblyForEVMObjects();
static Dialect yul()
{
// Will have to add builtins later.