@@ -179,8 +179,7 @@ pub mod tests {
179179
180180 use super :: * ;
181181
182- #[ test]
183- fn serialize_add_transaction ( ) {
182+ pub fn create_add_transaction ( handler : & mut DiagnosticHandler ) -> ( Transaction , SymbolTable ) {
184183 // Manually create the expected result of parsing `add.prot`.
185184 // Note that the order in which things are created will be different in the parser.
186185
@@ -209,6 +208,10 @@ pub mod tests {
209208 assert_eq ! ( symbols[ "DUT.s" ] , symbols[ dut_s] ) ;
210209 assert_eq ! ( symbols[ "s" ] , symbols[ s] ) ;
211210
211+ // create fileid and read file
212+ let input = std:: fs:: read_to_string ( "tests/addStruct.prot" ) . expect ( "failed to load" ) ;
213+ let add_fileid = handler. add_file ( "add.prot" . to_string ( ) , input) ;
214+
212215 // 2) create transaction
213216 let mut add = Transaction :: new ( "add" . to_string ( ) ) ;
214217 add. args = vec ! [
@@ -220,31 +223,47 @@ pub mod tests {
220223
221224 // 3) create expressions
222225 let a_expr = add. e ( Expr :: Sym ( a) ) ;
226+ add. add_expr_loc ( a_expr, 193 , 194 , add_fileid) ;
223227 let b_expr = add. e ( Expr :: Sym ( b) ) ;
228+ add. add_expr_loc ( b_expr, 208 , 209 , add_fileid) ;
224229 let dut_s_expr = add. e ( Expr :: Sym ( dut_s) ) ;
230+ add. add_expr_loc ( dut_s_expr, 271 , 276 , add_fileid) ;
225231
226232 // 4) create statements
233+ let a_assign = add. s ( Stmt :: Assign ( dut_a, a_expr) ) ;
234+ add. add_stmt_loc ( a_assign, 184 , 195 , add_fileid) ;
235+ let b_assign = add. s ( Stmt :: Assign ( dut_b, b_expr) ) ;
236+ add. add_stmt_loc ( b_assign, 199 , 210 , add_fileid) ;
237+ let step = add. s ( Stmt :: Step ) ;
238+ add. add_stmt_loc ( step, 214 , 221 , add_fileid) ;
239+ let fork = add. s ( Stmt :: Fork ) ;
240+ add. add_stmt_loc ( fork, 225 , 232 , add_fileid) ;
241+ let dut_a_assign = add. s ( Stmt :: Assign ( dut_a, add. expr_dont_care ( ) ) ) ;
242+ add. add_stmt_loc ( dut_a_assign, 236 , 247 , add_fileid) ;
243+ let dut_b_assign = add. s ( Stmt :: Assign ( dut_b, add. expr_dont_care ( ) ) ) ;
244+ add. add_stmt_loc ( dut_b_assign, 251 , 262 , add_fileid) ;
245+ let s_assign = add. s ( Stmt :: Assign ( s, dut_s_expr) ) ;
246+ add. add_stmt_loc ( s_assign, 266 , 277 , add_fileid) ;
227247 let body = vec ! [
228- add . s ( Stmt :: Assign ( dut_a , a_expr ) ) ,
229- add . s ( Stmt :: Assign ( dut_b , b_expr ) ) ,
230- add . s ( Stmt :: Step ) ,
231- add . s ( Stmt :: Fork ) ,
232- add . s ( Stmt :: Assign ( dut_a , add . expr_dont_care ( ) ) ) ,
233- add . s ( Stmt :: Assign ( dut_b , add . expr_dont_care ( ) ) ) ,
234- add . s ( Stmt :: Assign ( s , dut_s_expr ) ) ,
248+ a_assign ,
249+ b_assign ,
250+ step ,
251+ fork ,
252+ dut_a_assign ,
253+ dut_b_assign ,
254+ s_assign ,
235255 ] ;
236256 add. body = add. s ( Stmt :: Block ( body) ) ;
237257
238- println ! ( "{}" , serialize_to_string ( & add, & symbols) . unwrap ( ) ) ;
258+ ( add, symbols)
239259 }
240260
241- #[ test]
242- fn serialize_calyx_go_down_transaction ( ) {
261+ pub fn create_calyx_go_down_transaction (
262+ handler : & mut DiagnosticHandler ,
263+ ) -> ( Transaction , SymbolTable ) {
243264 // Manually create the expected result of parsing `calyx_go_down`.
244265 // Note that the order in which things are created will be different in the parser.
245266
246- // TODO: create this into function that factors our the code to put src code into IR
247-
248267 // 1) declare symbols
249268 let mut symbols = SymbolTable :: default ( ) ;
250269 let ii = symbols. add_without_parent ( "ii" . to_string ( ) , Type :: BitVec ( 32 ) ) ;
@@ -256,7 +275,7 @@ pub mod tests {
256275 "Calyx" . to_string ( ) ,
257276 vec ! [
258277 Field :: new( "ii" . to_string( ) , Dir :: In , Type :: BitVec ( 32 ) ) ,
259- Field :: new( "go" . to_string( ) , Dir :: In , Type :: BitVec ( 1 ) ) ,
278+ Field :: new( "go" . to_string( ) , Dir :: In , Type :: BitVec ( 32 ) ) ,
260279 Field :: new( "done" . to_string( ) , Dir :: Out , Type :: BitVec ( 1 ) ) ,
261280 Field :: new( "oo" . to_string( ) , Dir :: Out , Type :: BitVec ( 32 ) ) ,
262281 ] ,
@@ -270,30 +289,48 @@ pub mod tests {
270289 assert_eq ! ( symbols[ "dut.oo" ] , symbols[ dut_oo] ) ;
271290 assert_eq ! ( symbols[ "oo" ] , symbols[ oo] ) ;
272291
292+ // create fileid and read file
293+ let input =
294+ std:: fs:: read_to_string ( "tests/calyx_go_doneStruct.prot" ) . expect ( "failed to load" ) ;
295+ let calyx_fileid = handler. add_file ( "calyx_go_done.prot" . to_string ( ) , input) ;
296+
273297 // 2) create transaction
274298 let mut calyx_go_done = Transaction :: new ( "calyx_go_done" . to_string ( ) ) ;
275299 calyx_go_done. args = vec ! [ Arg :: new( ii, Dir :: In ) , Arg :: new( oo, Dir :: Out ) ] ;
276300 calyx_go_done. type_args = vec ! [ dut] ;
277301
278302 // 3) create expressions
279303 let ii_expr = calyx_go_done. e ( Expr :: Sym ( ii) ) ;
304+ calyx_go_done. add_expr_loc ( ii_expr, 153 , 155 , calyx_fileid) ;
280305 let dut_oo_expr = calyx_go_done. e ( Expr :: Sym ( dut_oo) ) ;
306+ calyx_go_done. add_expr_loc ( dut_oo_expr, 260 , 266 , calyx_fileid) ;
281307 let one_expr = calyx_go_done. e ( Expr :: Const ( BitVecValue :: from_u64 ( 1 , 1 ) ) ) ;
308+ calyx_go_done. add_expr_loc ( one_expr, 170 , 171 , calyx_fileid) ;
282309 let zero_expr = calyx_go_done. e ( Expr :: Const ( BitVecValue :: from_u64 ( 0 , 1 ) ) ) ;
310+ calyx_go_done. add_expr_loc ( zero_expr, 232 , 233 , calyx_fileid) ;
283311 let dut_done_expr = calyx_go_done. e ( Expr :: Sym ( dut_done) ) ;
312+ calyx_go_done. add_expr_loc ( dut_done_expr, 184 , 192 , calyx_fileid) ;
284313 let cond_expr = calyx_go_done. e ( Expr :: Equal ( dut_done_expr, one_expr) ) ;
314+ calyx_go_done. add_expr_loc ( cond_expr, 183 , 198 , calyx_fileid) ;
285315 let not_expr = calyx_go_done. e ( Expr :: Not ( cond_expr) ) ;
316+ calyx_go_done. add_expr_loc ( not_expr, 182 , 198 , calyx_fileid) ;
286317
287318 // 4) create statements
288319 let while_body = vec ! [ calyx_go_done. s( Stmt :: Step ) ] ;
289320 let wbody = calyx_go_done. s ( Stmt :: Block ( while_body) ) ;
290321
291322 let dut_ii_assign = calyx_go_done. s ( Stmt :: Assign ( dut_ii, ii_expr) ) ;
292- let dut_go_assign = calyx_go_done. s ( Stmt :: Assign ( dut_go, one_expr) ) ;
323+ calyx_go_done. add_stmt_loc ( dut_ii_assign, 143 , 157 , calyx_fileid) ;
324+ let dut_go_assign = calyx_go_done. s ( Stmt :: Assign ( dut_go, one_expr) ) ; // Should cause type mismatch error
325+ calyx_go_done. add_stmt_loc ( dut_go_assign, 160 , 172 , calyx_fileid) ;
293326 let dut_while = calyx_go_done. s ( Stmt :: While ( not_expr, wbody) ) ;
294- let dut_go_reassign = calyx_go_done. s ( Stmt :: Assign ( dut_go, zero_expr) ) ;
327+ calyx_go_done. add_stmt_loc ( dut_while, 175 , 219 , calyx_fileid) ;
328+ let dut_go_reassign = calyx_go_done. s ( Stmt :: Assign ( dut_go, zero_expr) ) ; // Should cause type mismatch error
329+ calyx_go_done. add_stmt_loc ( dut_go_reassign, 222 , 234 , calyx_fileid) ;
295330 let dut_ii_dontcare = calyx_go_done. s ( Stmt :: Assign ( dut_ii, calyx_go_done. expr_dont_care ( ) ) ) ;
331+ calyx_go_done. add_stmt_loc ( dut_ii_dontcare, 238 , 250 , calyx_fileid) ;
296332 let oo_assign = calyx_go_done. s ( Stmt :: Assign ( oo, dut_oo_expr) ) ;
333+ calyx_go_done. add_stmt_loc ( oo_assign, 254 , 268 , calyx_fileid) ;
297334 let body = vec ! [
298335 dut_ii_assign,
299336 dut_go_assign,
@@ -303,6 +340,22 @@ pub mod tests {
303340 oo_assign,
304341 ] ;
305342 calyx_go_done. body = calyx_go_done. s ( Stmt :: Block ( body) ) ;
343+
344+ ( calyx_go_done, symbols)
345+ }
346+
347+ #[ test]
348+ fn serialize_add_transaction ( ) {
349+ let mut handler = DiagnosticHandler :: new ( ) ;
350+ let ( add, symbols) = create_add_transaction ( & mut handler) ;
351+
352+ println ! ( "{}" , serialize_to_string( & add, & symbols) . unwrap( ) ) ;
353+ }
354+
355+ #[ test]
356+ fn serialize_calyx_go_down_transaction ( ) {
357+ let mut handler = DiagnosticHandler :: new ( ) ;
358+ let ( calyx_go_done, symbols) = create_calyx_go_down_transaction ( & mut handler) ;
306359 println ! ( "{}" , serialize_to_string( & calyx_go_done, & symbols) . unwrap( ) ) ;
307360 }
308361
0 commit comments