@@ -126,6 +126,12 @@ class CompilerStack: public langutil::CharStreamProvider, public evmasm::Abstrac
126126 SolidityAST,
127127 };
128128
129+ enum class IRGenerationGoal {
130+ NoIR, // /< Do not generate Yul IR.
131+ Unoptimized, // /< Stop after generating unoptimized Yul IR.
132+ Optimized, // /< Generate unoptimized Yul IR and optimize it.
133+ };
134+
129135 // / Creates a new compiler stack.
130136 // / @param _readFile callback used to read files for import statements. Must return
131137 // / and must not emit exceptions.
@@ -193,7 +199,12 @@ class CompilerStack: public langutil::CharStreamProvider, public evmasm::Abstrac
193199 void enableEvmBytecodeGeneration (bool _enable = true ) { m_generateEvmBytecode = _enable; }
194200
195201 // / Enable generation of Yul IR code.
196- void enableIRGeneration (bool _enable = true ) { m_generateIR = _enable; }
202+ // / Note that @a setViaIR(true) overrides this and works as if the goal was set to @a Optimized.
203+ void enableIRGeneration (IRGenerationGoal _goal = IRGenerationGoal::Optimized)
204+ {
205+ solAssert (m_stackState < ParsedAndImported);
206+ m_irGenerationGoal = _goal;
207+ }
197208
198209 // / @arg _metadataLiteralSources When true, store sources as literals in the contract metadata.
199210 // / Must be set before parsing.
@@ -450,7 +461,7 @@ class CompilerStack: public langutil::CharStreamProvider, public evmasm::Abstrac
450461
451462 // / Generate Yul IR for a single contract.
452463 // / The IR is stored but otherwise unused.
453- void generateIR (ContractDefinition const & _contract);
464+ void generateIR (ContractDefinition const & _contract, bool _optimized );
454465
455466 // / Generate EVM representation for a single contract.
456467 // / Depends on output generated by generateIR.
@@ -515,7 +526,7 @@ class CompilerStack: public langutil::CharStreamProvider, public evmasm::Abstrac
515526 ModelCheckerSettings m_modelCheckerSettings;
516527 std::map<std::string, std::set<std::string>> m_requestedContractNames;
517528 bool m_generateEvmBytecode = true ;
518- bool m_generateIR = false ;
529+ IRGenerationGoal m_irGenerationGoal = IRGenerationGoal::NoIR ;
519530 std::map<std::string, util::h160> m_libraries;
520531 ImportRemapper m_importRemapper;
521532 std::map<std::string const , Source> m_sources;
0 commit comments