Skip to content

Commit f79fbae

Browse files
committed
WIP
1 parent 9e50f8c commit f79fbae

File tree

3 files changed

+68
-31
lines changed

3 files changed

+68
-31
lines changed

test/libsolidity/util/compiler/Compiler.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ std::optional<CompiledContract> CompilerOutput::contract(
1616
if (pos != m_sourceUnits.end())
1717
contracts = pos->second;
1818

19+
std::cout << "_name: " << _name.source() << ":" << _name.contract() << std::endl;
20+
21+
for (auto su: m_sourceUnits)
22+
{
23+
std::cout << "sourceUnit: " << su.first << std::endl;
24+
for (auto c: su.second) {
25+
std::cout << " name: " << c.name << std::endl;
26+
}
27+
}
28+
1929
if (contracts.empty())
2030
return std::nullopt;
2131

test/libsolidity/util/compiler/InternalCompiler.cpp

+56-31
Original file line numberDiff line numberDiff line change
@@ -75,42 +75,37 @@ std::pair<MappedContracts, Errors> InternalCompiler::compile()
7575
m_stack.compile();
7676

7777
auto mappedContracts = MappedContracts{};
78-
for (auto sourceName: m_stack.sourceNames())
78+
79+
std::cout << std::endl << "[ENTER] InternalCompiler::compile()" << std::endl;
80+
for (auto const& contractName: m_stack.contractNames())
7981
{
80-
std::vector<CompiledContract> contracts;
82+
auto compiledContract = assembleContract(contractName);
8183

82-
auto const& sourceUnit = m_stack.ast(sourceName);
83-
for (auto const* contract: ASTNode::filteredNodes<ContractDefinition>(sourceUnit.nodes()))
84+
ContractName name{contractName};
85+
if (auto pos = mappedContracts.find(name.source()); pos != mappedContracts.end())
86+
pos->second.emplace_back(compiledContract);
87+
else
8488
{
85-
auto contractName = contract->fullyQualifiedName();
86-
auto object = m_stack.object(contractName);
87-
auto runtimeObject = m_stack.runtimeObject(contractName);
88-
auto hasUnlinkedReferences = !object.linkReferences.empty();
89-
auto assemblyItems = m_stack.assemblyItems(contractName);
90-
auto runtimeAssemblyItems = m_stack.runtimeAssemblyItems(contractName);
91-
auto metadata = m_stack.metadata(contractName);
92-
auto cborMetadata = m_stack.cborMetadata(contractName);
93-
auto contractABI = m_stack.contractABI(contractName);
94-
auto interfaceSymbols = m_stack.interfaceSymbols(contractName);
95-
auto eventSignatures = generateEventSignatures(contractName);
96-
97-
auto compiledContract = CompiledContract{
98-
contractName,
99-
object.bytecode,
100-
runtimeObject.bytecode,
101-
hasUnlinkedReferences,
102-
assemblyItems != nullptr ? *assemblyItems : evmasm::AssemblyItems{},
103-
runtimeAssemblyItems != nullptr ? *runtimeAssemblyItems : evmasm::AssemblyItems{},
104-
metadata,
105-
cborMetadata,
106-
contractABI,
107-
interfaceSymbols,
108-
eventSignatures
109-
};
110-
contracts.emplace_back(compiledContract);
89+
std::vector<CompiledContract> contracts{compiledContract};
90+
mappedContracts.insert(std::make_pair(name.source(), contracts));
11191
}
112-
mappedContracts.insert(std::make_pair(sourceName, contracts));
11392
}
93+
94+
95+
96+
// for (auto sourceName: m_stack.sourceNames())
97+
// {
98+
// std::cout << "sourceName: " << sourceName << std::endl;
99+
// std::vector<CompiledContract> contracts;
100+
101+
// auto const& sourceUnit = m_stack.ast(sourceName);
102+
// for (auto const* contract: ASTNode::filteredNodes<ContractDefinition>(sourceUnit.nodes()))
103+
// {
104+
105+
// contracts.emplace_back(compiledContract);
106+
// }
107+
// mappedContracts.insert(std::make_pair(sourceName, contracts));
108+
// }
114109

115110
return std::make_pair(mappedContracts, m_stack.errors());
116111
}
@@ -163,3 +158,33 @@ std::string InternalCompiler::formatErrorInformation() const
163158

164159
return errorInformation;
165160
}
161+
162+
CompiledContract InternalCompiler::assembleContract(
163+
std::string const& _contractName
164+
) const
165+
{
166+
auto object = m_stack.object(_contractName);
167+
auto runtimeObject = m_stack.runtimeObject(_contractName);
168+
auto hasUnlinkedReferences = !object.linkReferences.empty();
169+
auto assemblyItems = m_stack.assemblyItems(_contractName);
170+
auto runtimeAssemblyItems = m_stack.runtimeAssemblyItems(_contractName);
171+
auto metadata = m_stack.metadata(_contractName);
172+
auto cborMetadata = m_stack.cborMetadata(_contractName);
173+
auto contractABI = m_stack.contractABI(_contractName);
174+
auto interfaceSymbols = m_stack.interfaceSymbols(_contractName);
175+
auto eventSignatures = generateEventSignatures(_contractName);
176+
177+
return CompiledContract{
178+
_contractName,
179+
object.bytecode,
180+
runtimeObject.bytecode,
181+
hasUnlinkedReferences,
182+
assemblyItems != nullptr ? *assemblyItems : evmasm::AssemblyItems{},
183+
runtimeAssemblyItems != nullptr ? *runtimeAssemblyItems : evmasm::AssemblyItems{},
184+
metadata,
185+
cborMetadata,
186+
contractABI,
187+
interfaceSymbols,
188+
eventSignatures
189+
};
190+
}

test/libsolidity/util/compiler/InternalCompiler.h

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class InternalCompiler
6161
std::string const& _contractName
6262
) const;
6363

64+
CompiledContract assembleContract(std::string const& _contractName) const;
65+
6466
/// @returns a formatted output of all errors that occurred during
6567
/// compilation.
6668
std::string formatErrorInformation() const;

0 commit comments

Comments
 (0)