@@ -7,6 +7,7 @@ use fe_common::db::Upcast;
7
7
use fe_common:: diagnostics:: Diagnostic ;
8
8
use fe_common:: files:: FileKind ;
9
9
use fe_parser:: ast:: SmolStr ;
10
+ use fe_proof_service:: invariant:: Invariant ;
10
11
use fe_test_runner:: TestSink ;
11
12
use indexmap:: { indexmap, IndexMap } ;
12
13
use serde_json:: Value ;
@@ -86,6 +87,23 @@ pub fn compile_single_file_tests(
86
87
}
87
88
}
88
89
90
+ #[ cfg( feature = "solc-backend" ) ]
91
+ pub fn compile_single_file_invariants (
92
+ db : & mut Db ,
93
+ path : & str ,
94
+ src : & str ,
95
+ optimize : bool ,
96
+ ) -> Result < Vec < Invariant > , CompileError > {
97
+ let module = ModuleId :: new_standalone ( db, path, src) ;
98
+ let diags = module. diagnostics ( db) ;
99
+
100
+ if diags. is_empty ( ) {
101
+ Ok ( compile_module_invariants ( db, module, optimize) )
102
+ } else {
103
+ Err ( CompileError ( diags) )
104
+ }
105
+ }
106
+
89
107
// Run analysis with ingot
90
108
// Return vector error,waring...
91
109
pub fn check_ingot (
@@ -196,6 +214,7 @@ fn compile_test(db: &mut Db, test: FunctionId, optimize: bool) -> CompiledTest {
196
214
let yul_test = fe_codegen:: yul:: isel:: lower_test ( db, test)
197
215
. to_string ( )
198
216
. replace ( '"' , "\\ \" " ) ;
217
+ // panic!("{}", yul_test);
199
218
let bytecode = compile_to_evm ( "test" , & yul_test, optimize) ;
200
219
CompiledTest :: new ( test. name ( db) , bytecode)
201
220
}
@@ -209,6 +228,26 @@ fn compile_module_tests(db: &mut Db, module_id: ModuleId, optimize: bool) -> Vec
209
228
. collect ( )
210
229
}
211
230
231
+ #[ cfg( feature = "solc-backend" ) ]
232
+ fn compile_module_invariants ( db : & mut Db , module_id : ModuleId , optimize : bool ) -> Vec < Invariant > {
233
+ use fe_proof_service:: invariant:: Invariant ;
234
+
235
+ module_id
236
+ . invariants ( db)
237
+ . iter ( )
238
+ . map ( |test| {
239
+ let args = test
240
+ . signature ( db)
241
+ . params
242
+ . iter ( )
243
+ . map ( |param| param. typ . as_ref ( ) . unwrap ( ) . name ( db) )
244
+ . collect ( ) ;
245
+ let test = compile_test ( db, * test, optimize) ;
246
+ Invariant :: new ( test. name , args, test. bytecode )
247
+ } )
248
+ . collect ( )
249
+ }
250
+
212
251
#[ cfg( feature = "solc-backend" ) ]
213
252
fn compile_module (
214
253
db : & mut Db ,
0 commit comments