From ad1fe865088cdb4f97b3728e00d3fc2a5a34aba5 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 30 Mar 2017 02:09:42 +0100 Subject: Support linkReferences --- libsolidity/interface/StandardCompiler.cpp | 31 ++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'libsolidity/interface') diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index ada89dc3..0297a5ec 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -107,6 +107,33 @@ Json::Value methodIdentifiers(ContractDefinition const& _contract) return methodIdentifiers; } +Json::Value formatLinkReferences(std::map const& linkReferences) +{ + Json::Value ret(Json::objectValue); + + for (auto const& ref: linkReferences) + { + string const& fullname = ref.second; + size_t colon = fullname.find(':'); + solAssert(colon != string::npos, ""); + string file = fullname.substr(0, colon); + string name = fullname.substr(colon + 1); + + Json::Value fileObject = ret.get(file, Json::objectValue); + Json::Value libraryArray = fileObject.get(name, Json::arrayValue); + + Json::Value entry = Json::objectValue; + entry["start"] = Json::UInt(ref.first); + entry["length"] = 20; + + libraryArray.append(entry); + fileObject[name] = libraryArray; + ret[file] = fileObject; + } + + return ret; +} + Json::Value StandardCompiler::compileInternal(Json::Value const& _input) { m_compilerStack.reset(false); @@ -276,7 +303,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input) bytecode["opcodes"] = solidity::disassemble(m_compilerStack.object(contractName).bytecode); auto sourceMap = m_compilerStack.sourceMapping(contractName); bytecode["sourceMap"] = sourceMap ? *sourceMap : ""; - // @TODO: add linkReferences + bytecode["linkReferences"] = formatLinkReferences(m_compilerStack.object(contractName).linkReferences); evmData["bytecode"] = bytecode; // EVM deployed bytecode @@ -285,7 +312,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input) deployedBytecode["opcodes"] = solidity::disassemble(m_compilerStack.runtimeObject(contractName).bytecode); auto runtimeSourceMap = m_compilerStack.runtimeSourceMapping(contractName); deployedBytecode["sourceMap"] = runtimeSourceMap ? *runtimeSourceMap : ""; - // @TODO: add linkReferences + deployedBytecode["linkReferences"] = formatLinkReferences(m_compilerStack.runtimeObject(contractName).linkReferences); evmData["deployedBytecode"] = deployedBytecode; contractData["evm"] = evmData; -- cgit