@@ -75,42 +75,37 @@ std::pair<MappedContracts, Errors> InternalCompiler::compile()
75
75
m_stack.compile ();
76
76
77
77
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 ())
79
81
{
80
- std::vector<CompiledContract> contracts ;
82
+ auto compiledContract = assembleContract (contractName) ;
81
83
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
84
88
{
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));
111
91
}
112
- mappedContracts.insert (std::make_pair (sourceName, contracts));
113
92
}
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
+ // }
114
109
115
110
return std::make_pair (mappedContracts, m_stack.errors ());
116
111
}
@@ -163,3 +158,33 @@ std::string InternalCompiler::formatErrorInformation() const
163
158
164
159
return errorInformation;
165
160
}
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
+ }
0 commit comments