@@ -410,19 +410,20 @@ void CompilerStack::importASTs(map<string, Json::Value> const& _sources)
410
410
m_sources[path] = std::move (source);
411
411
}
412
412
m_stackState = ParsedAndImported;
413
- m_importedSources = true ;
413
+ m_importedSourceType = ImportedSourceType::SolidityAST ;
414
414
415
415
storeContractDefinitions ();
416
416
}
417
417
418
418
void CompilerStack::importEvmAssemblyJson (std::map<std::string, Json::Value> const & _sources)
419
419
{
420
420
solAssert (_sources.size () == 1 , " " );
421
- solAssert (m_sources .empty (), " " );
421
+ solAssert (m_sourceJsons .empty (), " " );
422
422
solAssert (m_sourceOrder.empty (), " " );
423
423
if (m_stackState != Empty)
424
424
solThrow (CompilerError, " Must call importEvmAssemblyJson only before the SourcesSet state." );
425
425
426
+ m_sourceJsons = _sources;
426
427
Json::Value jsonValue = _sources.begin ()->second ;
427
428
if (jsonValue.isMember (" sourceList" ))
428
429
for (auto const & item: jsonValue[" sourceList" ])
@@ -432,8 +433,8 @@ void CompilerStack::importEvmAssemblyJson(std::map<std::string, Json::Value> con
432
433
m_sources.emplace (std::make_pair (item.asString (), source));
433
434
m_sourceOrder.push_back (&m_sources[item.asString ()]);
434
435
}
435
- m_evmAssemblyJson [_sources.begin ()->first ] = std::move (jsonValue);
436
- m_importedSources = true ;
436
+ m_sourceJsons [_sources.begin ()->first ] = std::move (jsonValue);
437
+ m_importedSourceType = ImportedSourceType::EvmAssemblyJson ;
437
438
m_stackState = SourcesSet;
438
439
}
439
440
@@ -626,7 +627,7 @@ bool CompilerStack::parseAndAnalyze(State _stopAfter)
626
627
{
627
628
m_stopAfter = _stopAfter;
628
629
629
- if (!m_evmAssemblyJson. empty () )
630
+ if (m_importedSourceType == ImportedSourceType::EvmAssemblyJson )
630
631
return true ;
631
632
632
633
bool success = parse ();
@@ -678,13 +679,12 @@ bool CompilerStack::compile(State _stopAfter)
678
679
// Only compile contracts individually which have been requested.
679
680
map<ContractDefinition const *, shared_ptr<Compiler const >> otherCompilers;
680
681
681
- if (!m_evmAssemblyJson. empty () )
682
+ if (m_importedSourceType == ImportedSourceType::EvmAssemblyJson )
682
683
{
683
- solAssert (m_importedSources, " " );
684
- solAssert (m_evmAssemblyJson.size () == 1 , " " );
684
+ solAssert (m_sourceJsons.size () == 1 , " " );
685
685
686
- string const evmSourceName = m_evmAssemblyJson .begin ()->first ;
687
- Json::Value const evmJson = m_evmAssemblyJson .begin ()->second ;
686
+ string const evmSourceName = m_sourceJsons .begin ()->first ;
687
+ Json::Value const evmJson = m_sourceJsons .begin ()->second ;
688
688
689
689
// todo: remove code duplication.
690
690
evmasm::Assembly::OptimiserSettings optimiserSettings{false , false , false , false , false , false , m_evmVersion, 0 };
@@ -697,7 +697,7 @@ bool CompilerStack::compile(State _stopAfter)
697
697
optimiserSettings.expectedExecutionsPerDeployment = m_optimiserSettings.expectedExecutionsPerDeployment ;
698
698
optimiserSettings.evmVersion = m_evmVersion;
699
699
700
- m_contracts[evmSourceName].evmAssembly = evmasm::Assembly::loadFromAssemblyJSON (m_evmAssemblyJson [evmSourceName]);
700
+ m_contracts[evmSourceName].evmAssembly = evmasm::Assembly::loadFromAssemblyJSON (m_sourceJsons [evmSourceName]);
701
701
if (m_optimiserSettings.enabled )
702
702
m_contracts[evmSourceName].evmAssembly ->optimise (optimiserSettings);
703
703
m_contracts[evmSourceName].object = m_contracts[evmSourceName].evmAssembly ->assemble ();
@@ -991,21 +991,15 @@ vector<string> CompilerStack::sourceNames() const
991
991
return names;
992
992
}
993
993
994
- map<string, unsigned > CompilerStack::sourceIndices (bool _includeInternalSources /* = true */ ) const
994
+ map<string, unsigned > CompilerStack::sourceIndices () const
995
995
{
996
996
map<string, unsigned > indices;
997
997
unsigned index = 0 ;
998
- if (m_evmAssemblyJson.empty ())
999
- {
1000
- for (auto const & s: m_sources)
998
+ for (auto const & s: m_sources)
999
+ if (s.first != CompilerContext::yulUtilityFileName ())
1001
1000
indices[s.first ] = index++;
1002
- solAssert (!indices.count (CompilerContext::yulUtilityFileName ()), " " );
1003
- if (_includeInternalSources)
1004
- indices[CompilerContext::yulUtilityFileName ()] = index++;
1005
- }
1006
- else
1007
- for (auto const & s: m_sourceOrder)
1008
- indices[s->charStream ->source ()] = index++;
1001
+ if (indices.find (CompilerContext::yulUtilityFileName ()) == indices.end ())
1002
+ indices[CompilerContext::yulUtilityFileName ()] = index++;
1009
1003
return indices;
1010
1004
}
1011
1005
@@ -1543,7 +1537,22 @@ string CompilerStack::createMetadata(Contract const& _contract, bool _forIR) con
1543
1537
{
1544
1538
Json::Value meta{Json::objectValue};
1545
1539
meta[" version" ] = 1 ;
1546
- meta[" language" ] = m_importedSources ? " SolidityAST" : " Solidity" ;
1540
+ string sourceType;
1541
+ switch (m_importedSourceType)
1542
+ {
1543
+ case ImportedSourceType::None:
1544
+ sourceType = " Solidity" ;
1545
+ break ;
1546
+ case ImportedSourceType::SolidityAST:
1547
+ sourceType = " SolidityAST" ;
1548
+ break ;
1549
+ case ImportedSourceType::EvmAssemblyJson:
1550
+ sourceType = " EvmAssemblyJson" ;
1551
+ break ;
1552
+ default :
1553
+ solAssert (false );
1554
+ }
1555
+ meta[" language" ] = sourceType;
1547
1556
meta[" compiler" ][" version" ] = VersionStringStrict;
1548
1557
1549
1558
// / All the source files (including self), which should be included in the metadata.
0 commit comments