@@ -11,8 +11,10 @@ use huff_parser::*;
1111#[ cfg( all( target_arch = "wasm32" , target_os = "unknown" ) ) ]
1212use huff_utils:: wasm:: IntoParallelIterator ;
1313use huff_utils:: {
14+ config:: HuffConfig ,
1415 file_provider:: { FileProvider , FileSystemFileProvider , InMemoryFileProvider } ,
1516 prelude:: * ,
17+ remapper:: Remapper ,
1618 time,
1719} ;
1820#[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
@@ -59,9 +61,9 @@ pub(crate) mod cache;
5961/// );
6062/// ```
6163#[ derive( Debug , Clone ) ]
62- pub struct Compiler < ' a , ' l > {
63- /// The EVM version to compile for
64- pub evm_version : & ' l EVMVersion ,
64+ pub struct Compiler < ' a > {
65+ /// Huff Config
66+ pub huff_config : HuffConfig ,
6567 /// The location of the files to compile
6668 pub sources : Arc < Vec < String > > ,
6769 /// The output location
@@ -84,11 +86,11 @@ pub struct Compiler<'a, 'l> {
8486 pub file_provider : Arc < dyn FileProvider < ' a > > ,
8587}
8688
87- impl < ' a , ' l > Compiler < ' a , ' l > {
89+ impl < ' a > Compiler < ' a > {
8890 /// Public associated function to instantiate a new compiler.
8991 #[ allow( clippy:: too_many_arguments) ]
9092 pub fn new (
91- evm_version : & ' l EVMVersion ,
93+ huff_config : HuffConfig ,
9294 sources : Arc < Vec < String > > ,
9395 output : Option < String > ,
9496 alternative_main : Option < String > ,
@@ -102,7 +104,7 @@ impl<'a, 'l> Compiler<'a, 'l> {
102104 Compiler :: init_tracing_subscriber ( Some ( vec ! [ tracing:: Level :: INFO . into( ) ] ) ) ;
103105 }
104106 Self {
105- evm_version ,
107+ huff_config ,
106108 sources,
107109 output,
108110 alternative_main,
@@ -120,7 +122,7 @@ impl<'a, 'l> Compiler<'a, 'l> {
120122 /// map.
121123 #[ allow( clippy:: too_many_arguments) ]
122124 pub fn new_in_memory (
123- evm_version : & ' l EVMVersion ,
125+ evm_version : & EVMVersion ,
124126 sources : Arc < Vec < String > > ,
125127 file_sources : HashMap < String , String > ,
126128 alternative_main : Option < String > ,
@@ -132,8 +134,9 @@ impl<'a, 'l> Compiler<'a, 'l> {
132134 if cfg ! ( feature = "verbose" ) || verbose {
133135 Compiler :: init_tracing_subscriber ( Some ( vec ! [ tracing:: Level :: INFO . into( ) ] ) ) ;
134136 }
137+ let huff_config = HuffConfig :: from_evm_version ( evm_version. clone ( ) ) ;
135138 Self {
136- evm_version ,
139+ huff_config ,
137140 sources,
138141 output : None ,
139142 alternative_main,
@@ -226,7 +229,7 @@ impl<'a, 'l> Compiler<'a, 'l> {
226229 let recursed_file_sources: Vec < Result < Arc < FileSource > , Arc < CompilerError > > > = files
227230 . into_par_iter ( )
228231 . map ( |v| {
229- Self :: recurse_deps ( v, & Remapper :: new ( "./" ) , self . file_provider . clone ( ) )
232+ Self :: recurse_deps ( v, self . huff_config . clone ( ) , self . file_provider . clone ( ) )
230233 } )
231234 . collect ( ) ;
232235
@@ -307,13 +310,7 @@ impl<'a, 'l> Compiler<'a, 'l> {
307310
308311 let recursed_file_sources: Vec < Result < Arc < FileSource > , Arc < CompilerError > > > = files
309312 . into_par_iter ( )
310- . map ( |f| {
311- Self :: recurse_deps (
312- f,
313- & huff_utils:: files:: Remapper :: new ( "./" ) ,
314- self . file_provider . clone ( ) ,
315- )
316- } )
313+ . map ( |f| Self :: recurse_deps ( f, self . huff_config . clone ( ) , self . file_provider . clone ( ) ) )
317314 . collect ( ) ;
318315
319316 // Collect Recurse Deps errors and try to resolve to the first one
@@ -358,7 +355,8 @@ impl<'a, 'l> Compiler<'a, 'l> {
358355 tracing:: info!( target: "core" , "└─ TOKEN COUNT: {}" , tokens. len( ) ) ;
359356
360357 // Parser incantation
361- let mut parser = Parser :: new ( tokens, Some ( file. path . clone ( ) ) ) ;
358+ let mut parser =
359+ Parser :: new ( self . huff_config . clone ( ) , tokens, Some ( file. path . clone ( ) ) ) ;
362360
363361 // Parse into an AST
364362 let parse_res = parser. parse ( ) . map_err ( CompilerError :: ParserError ) ;
@@ -396,7 +394,7 @@ impl<'a, 'l> Compiler<'a, 'l> {
396394 tracing:: info!( target: "core" , "└─ TOKEN COUNT: {}" , tokens. len( ) ) ;
397395
398396 // Parser incantation
399- let mut parser = Parser :: new ( tokens, Some ( file. path . clone ( ) ) ) ;
397+ let mut parser = Parser :: new ( self . huff_config . clone ( ) , tokens, Some ( file. path . clone ( ) ) ) ;
400398
401399 // Parse into an AST
402400 let parse_res = parser. parse ( ) . map_err ( CompilerError :: ParserError ) ;
@@ -408,7 +406,7 @@ impl<'a, 'l> Compiler<'a, 'l> {
408406 // Primary Bytecode Generation
409407 let mut cg = Codegen :: new ( ) ;
410408 let main_bytecode = match Codegen :: generate_main_bytecode (
411- self . evm_version ,
409+ & self . huff_config . evm_version ,
412410 & contract,
413411 self . alternative_main . clone ( ) ,
414412 ) {
@@ -436,7 +434,7 @@ impl<'a, 'l> Compiler<'a, 'l> {
436434 let inputs = self . get_constructor_args ( ) ;
437435 let ( constructor_bytecode, has_custom_bootstrap) =
438436 match Codegen :: generate_constructor_bytecode (
439- self . evm_version ,
437+ & self . huff_config . evm_version ,
440438 & contract,
441439 self . alternative_constructor . clone ( ) ,
442440 ) {
@@ -515,7 +513,7 @@ impl<'a, 'l> Compiler<'a, 'l> {
515513 /// Recurses file dependencies
516514 pub fn recurse_deps (
517515 fs : Arc < FileSource > ,
518- remapper : & Remapper ,
516+ config : HuffConfig ,
519517 reader : Arc < dyn FileProvider < ' a > > ,
520518 ) -> Result < Arc < FileSource > , Arc < CompilerError > > {
521519 tracing:: debug!( target: "core" , "RECURSING DEPENDENCIES FOR {}" , fs. path) ;
@@ -544,7 +542,7 @@ impl<'a, 'l> Compiler<'a, 'l> {
544542 . into_iter ( )
545543 . map ( |mut import| {
546544 // Check for foundry toml remappings
547- match remapper . remap ( & import) {
545+ match config . remap ( & import) {
548546 Some ( remapped) => {
549547 tracing:: debug!( target: "core" , "REMAPPED IMPORT PATH \" {}\" " , import) ;
550548 import = remapped;
@@ -575,7 +573,7 @@ impl<'a, 'l> Compiler<'a, 'l> {
575573 // Now that we have all the file sources, we have to recurse and get their source
576574 file_sources = file_sources
577575 . into_par_iter ( )
578- . map ( |inner_fs| match Self :: recurse_deps ( Arc :: clone ( & inner_fs) , remapper , reader. clone ( ) ) {
576+ . map ( |inner_fs| match Self :: recurse_deps ( Arc :: clone ( & inner_fs) , config . clone ( ) , reader. clone ( ) ) {
579577 Ok ( new_fs) => new_fs,
580578 Err ( e) => {
581579 tracing:: error!( target: "core" , "NESTED DEPENDENCY RESOLUTION FAILED: \" {:?}\" " , e) ;
0 commit comments