@@ -7,6 +7,7 @@ use fe_common::db::Upcast;
77use fe_common:: diagnostics:: Diagnostic ;
88use fe_common:: files:: FileKind ;
99use fe_parser:: ast:: SmolStr ;
10+ use fe_specgen:: KSpec ;
1011use fe_test_runner:: TestSink ;
1112use indexmap:: { indexmap, IndexMap } ;
1213use serde_json:: Value ;
@@ -86,6 +87,23 @@ pub fn compile_single_file_tests(
8687 }
8788}
8889
90+ #[ cfg( feature = "solc-backend" ) ]
91+ pub fn generate_single_file_specs (
92+ db : & mut Db ,
93+ path : & str ,
94+ src : & str ,
95+ optimize : bool ,
96+ ) -> Result < Vec < KSpec > , CompileError > {
97+ let module = ModuleId :: new_standalone ( db, path, src) ;
98+ let diags = module. diagnostics ( db) ;
99+
100+ if diags. is_empty ( ) {
101+ Ok ( generate_module_specs ( db, module, optimize) )
102+ } else {
103+ Err ( CompileError ( diags) )
104+ }
105+ }
106+
89107// Run analysis with ingot
90108// Return vector error,waring...
91109pub fn check_ingot (
@@ -176,6 +194,46 @@ pub fn compile_ingot_tests(
176194 }
177195}
178196
197+ #[ cfg( feature = "solc-backend" ) ]
198+ pub fn generate_ingot_specs (
199+ db : & mut Db ,
200+ name : & str ,
201+ files : & [ ( impl AsRef < str > , impl AsRef < str > ) ] ,
202+ optimize : bool ,
203+ ) -> Result < Vec < KSpec > , CompileError > {
204+ let std = IngotId :: std_lib ( db) ;
205+ let ingot = IngotId :: from_files (
206+ db,
207+ name,
208+ IngotMode :: Main ,
209+ FileKind :: Local ,
210+ files,
211+ indexmap ! { "std" . into( ) => std } ,
212+ ) ;
213+
214+ let mut diags = ingot. diagnostics ( db) ;
215+ ingot. sink_external_ingot_diagnostics ( db, & mut diags) ;
216+ if !diags. is_empty ( ) {
217+ return Err ( CompileError ( diags) ) ;
218+ }
219+
220+ if diags. is_empty ( ) {
221+ // Ok(ingot
222+ // .all_modules(db)
223+ // .iter()
224+ // .fold(vec![], |mut accum, module| {
225+ // accum.push((
226+ // module.name(db),
227+ // generate_module_specs(db, *module, optimize),
228+ // ));
229+ // accum
230+ // }))
231+ Ok ( vec ! [ ] )
232+ } else {
233+ Err ( CompileError ( diags) )
234+ }
235+ }
236+
179237/// Returns graphviz string.
180238// TODO: This is temporary function for debugging.
181239pub fn dump_mir_single_file ( db : & mut Db , path : & str , src : & str ) -> Result < String , CompileError > {
@@ -196,6 +254,7 @@ fn compile_test(db: &mut Db, test: FunctionId, optimize: bool) -> CompiledTest {
196254 let yul_test = fe_codegen:: yul:: isel:: lower_test ( db, test)
197255 . to_string ( )
198256 . replace ( '"' , "\\ \" " ) ;
257+ // panic!("{}", yul_test);
199258 let bytecode = compile_to_evm ( "test" , & yul_test, optimize) ;
200259 CompiledTest :: new ( test. name ( db) , bytecode)
201260}
@@ -209,6 +268,21 @@ fn compile_module_tests(db: &mut Db, module_id: ModuleId, optimize: bool) -> Vec
209268 . collect ( )
210269}
211270
271+ #[ cfg( feature = "solc-backend" ) ]
272+ fn generate_spec ( db : & mut Db , test : FunctionId , optimize : bool ) -> KSpec {
273+ let code = compile_test ( db, test, optimize) . bytecode ;
274+ KSpec :: new ( test. name ( db) , code, test. signature ( db) . params . len ( ) )
275+ }
276+
277+ #[ cfg( feature = "solc-backend" ) ]
278+ fn generate_module_specs ( db : & mut Db , module_id : ModuleId , optimize : bool ) -> Vec < KSpec > {
279+ module_id
280+ . invariants ( db)
281+ . iter ( )
282+ . map ( |test| generate_spec ( db, * test, optimize) )
283+ . collect ( )
284+ }
285+
212286#[ cfg( feature = "solc-backend" ) ]
213287fn compile_module (
214288 db : & mut Db ,
0 commit comments