aboutsummaryrefslogtreecommitdiffstats
path: root/LinkerObject.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-09-10 18:02:18 +0800
committerchriseth <c@ethdev.com>2015-09-11 01:31:15 +0800
commit129b4142d81d91138efe4a47392a87702e066441 (patch)
treeaf3d818571557ded88d71ee328fc5ebc2369c5b1 /LinkerObject.cpp
parent3ca3fb492d2f710f45d690db85089036bfc77b68 (diff)
downloaddexon-solidity-129b4142d81d91138efe4a47392a87702e066441.tar
dexon-solidity-129b4142d81d91138efe4a47392a87702e066441.tar.gz
dexon-solidity-129b4142d81d91138efe4a47392a87702e066441.tar.bz2
dexon-solidity-129b4142d81d91138efe4a47392a87702e066441.tar.lz
dexon-solidity-129b4142d81d91138efe4a47392a87702e066441.tar.xz
dexon-solidity-129b4142d81d91138efe4a47392a87702e066441.tar.zst
dexon-solidity-129b4142d81d91138efe4a47392a87702e066441.zip
Transition from bytecode to more general linker objects.
Diffstat (limited to 'LinkerObject.cpp')
-rw-r--r--LinkerObject.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/LinkerObject.cpp b/LinkerObject.cpp
new file mode 100644
index 00000000..ceb864a1
--- /dev/null
+++ b/LinkerObject.cpp
@@ -0,0 +1,62 @@
+/*
+ This file is part of cpp-ethereum.
+
+ cpp-ethereum 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.
+
+ cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
+*/
+/** @file LinkerObject.cpp
+ * @author Christian R <c@ethdev.com>
+ * @date 2015
+ */
+
+#include <libevmasm/LinkerObject.h>
+#include <libdevcore/CommonData.h>
+
+using namespace dev;
+using namespace dev::eth;
+using namespace std;
+
+void LinkerObject::append(LinkerObject const& _other)
+{
+ for (auto const& ref: _other.linkReferences)
+ linkReferences[ref.first + bytecode.size()] = ref.second;
+ bytecode += _other.bytecode;
+}
+
+void LinkerObject::link(map<string, h160> const& _libraryAddresses)
+{
+ std::map<size_t, std::string> remainingRefs;
+ for (auto const& linkRef: linkReferences)
+ {
+ auto it = _libraryAddresses.find(linkRef.second);
+ if (it == _libraryAddresses.end())
+ remainingRefs.insert(linkRef);
+ else
+ it->second.ref().copyTo(ref(bytecode).cropped(linkRef.first, 20));
+ }
+ linkReferences.swap(remainingRefs);
+}
+
+string LinkerObject::toHex() const
+{
+ string hex = dev::toHex(bytecode);
+ for (auto const& ref: linkReferences)
+ {
+ size_t pos = ref.first * 2;
+ string const& name = ref.second;
+ hex[pos] = hex[pos + 1] = hex[pos + 38] = hex[pos + 39] = '_';
+ for (size_t i = 0; i < 36; ++i)
+ hex[pos + 2 + i] = i < name.size() ? name[i] : '_';
+ }
+ return hex;
+}