aboutsummaryrefslogtreecommitdiffstats
path: root/libyul/Dialect.h
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-12-03 22:49:23 +0800
committerchriseth <chris@ethereum.org>2018-12-04 19:06:33 +0800
commit99db4e3ff45c2a8d5d9c645774f099b82b7618ec (patch)
tree9f61e6b6192141bf9233f49a4a2c36e5c26ca8df /libyul/Dialect.h
parente49f37be7f64d0306c2e63cea81eb98aa1bc85f1 (diff)
downloaddexon-solidity-99db4e3ff45c2a8d5d9c645774f099b82b7618ec.tar
dexon-solidity-99db4e3ff45c2a8d5d9c645774f099b82b7618ec.tar.gz
dexon-solidity-99db4e3ff45c2a8d5d9c645774f099b82b7618ec.tar.bz2
dexon-solidity-99db4e3ff45c2a8d5d9c645774f099b82b7618ec.tar.lz
dexon-solidity-99db4e3ff45c2a8d5d9c645774f099b82b7618ec.tar.xz
dexon-solidity-99db4e3ff45c2a8d5d9c645774f099b82b7618ec.tar.zst
dexon-solidity-99db4e3ff45c2a8d5d9c645774f099b82b7618ec.zip
Introduce the concept of builtin functions.
Diffstat (limited to 'libyul/Dialect.h')
-rw-r--r--libyul/Dialect.h82
1 files changed, 82 insertions, 0 deletions
diff --git a/libyul/Dialect.h b/libyul/Dialect.h
new file mode 100644
index 00000000..3ea16014
--- /dev/null
+++ b/libyul/Dialect.h
@@ -0,0 +1,82 @@
+/*
+ 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.
+ */
+
+#pragma once
+
+#include <libyul/YulString.h>
+
+#include <memory>
+
+namespace yul
+{
+
+class YulString;
+using Type = YulString;
+
+enum class AsmFlavour
+{
+ Loose, // no types, EVM instructions as function, jumps and direct stack manipulations
+ Strict, // no types, EVM instructions as functions, but no jumps and no direct stack manipulations
+ Yul // same as Strict mode with types
+};
+
+struct BuiltinFunction
+{
+ YulString name;
+ std::vector<Type> parameters;
+ std::vector<Type> returns;
+ bool movable;
+};
+
+/**
+ * Class to query for builtin functions and their semantics.
+ */
+struct Builtins
+{
+ virtual ~Builtins() = default;
+ /// @returns the builtin function of the given name or a nullptr if it is not a builtin function.
+ virtual BuiltinFunction const* query(YulString /*_name*/) const { return nullptr; }
+};
+
+struct Dialect
+{
+ AsmFlavour flavour = AsmFlavour::Loose;
+ std::shared_ptr<Builtins> builtins;
+
+ Dialect(AsmFlavour _flavour, std::shared_ptr<Builtins> _builtins):
+ flavour(_flavour), builtins(std::move(_builtins))
+ {}
+ static Dialect looseAssemblyForEVM()
+ {
+ return Dialect{AsmFlavour::Loose, std::make_shared<Builtins>()};
+ }
+ static Dialect strictAssemblyForEVM()
+ {
+ // The EVM instructions will be moved to builtins at some point.
+ return Dialect{AsmFlavour::Strict, std::make_shared<Builtins>()};
+ }
+ static Dialect yul()
+ {
+ // Will have to add builtins later.
+ return Dialect{AsmFlavour::Yul, std::make_shared<Builtins>()};
+ }
+};
+
+}