@@ -53,6 +53,7 @@ use crate::ods::sol::ReturnOperation;
5353use crate :: ods:: sol:: RevertOperation ;
5454use crate :: ods:: sol:: StateVarOperation ;
5555use crate :: ods:: sol:: StoreOperation ;
56+ use crate :: ods:: sol:: StringLitOperation ;
5657use crate :: ods:: sol:: WhileOperation ;
5758use crate :: ods:: sol:: YieldOperation ;
5859
@@ -311,6 +312,31 @@ impl<'context> Builder<'context> {
311312 . into ( )
312313 }
313314
315+ // ==== String literals ====
316+
317+ /// Emits a `sol.string_lit` constant with a `!sol.string<Memory>` result.
318+ ///
319+ /// # Panics
320+ ///
321+ /// Panics if the MLIR operation cannot be constructed, indicating a bug in the builder.
322+ pub fn emit_sol_string_lit < ' block , B > ( & self , value : & str , block : & B ) -> Value < ' context , ' block >
323+ where
324+ B : BlockLike < ' context , ' block > ,
325+ ' context : ' block ,
326+ {
327+ block
328+ . append_operation (
329+ StringLitOperation :: builder ( self . context , self . unknown_location )
330+ . value ( StringAttribute :: new ( self . context , value) )
331+ . addr ( self . types . sol_string_memory )
332+ . build ( )
333+ . into ( ) ,
334+ )
335+ . result ( 0 )
336+ . expect ( "sol.string_lit always produces one result" )
337+ . into ( )
338+ }
339+
314340 // ==== Terminators ====
315341
316342 /// Emits a `sol.revert` with an empty signature (no error data).
@@ -352,27 +378,31 @@ impl<'context> Builder<'context> {
352378 ) ;
353379 }
354380
355- /// Emits a `sol.require` conditional revert with an empty signature .
381+ /// Emits a `sol.require` conditional revert with an optional message .
356382 ///
357- /// Reverts if `condition` is false. Not a terminator — execution continues
358- /// after this op when the condition is true.
383+ /// Reverts if `condition` is false. When `msg` is `Some`, the revert
384+ /// includes the string as a revert reason. Not a terminator — execution
385+ /// continues after this op when the condition is true.
359386 ///
360387 /// # Panics
361388 ///
362389 /// Panics if the MLIR operation cannot be constructed, indicating a bug in the builder.
363- pub fn emit_sol_require < ' block , B > ( & self , condition : Value < ' context , ' block > , block : & B )
364- where
390+ pub fn emit_sol_require < ' block , B > (
391+ & self ,
392+ condition : Value < ' context , ' block > ,
393+ msg : Option < & str > ,
394+ block : & B ,
395+ ) where
365396 B : BlockLike < ' context , ' block > ,
366397 ' context : ' block ,
367398 {
368- block. append_operation (
369- RequireOperation :: builder ( self . context , self . unknown_location )
370- . cond ( condition)
371- . msg ( StringAttribute :: new ( self . context , "" ) )
372- . args ( & [ ] )
373- . build ( )
374- . into ( ) ,
375- ) ;
399+ let mut builder = RequireOperation :: builder ( self . context , self . unknown_location )
400+ . cond ( condition)
401+ . args ( & [ ] ) ;
402+ if let Some ( msg) = msg {
403+ builder = builder. msg ( StringAttribute :: new ( self . context , msg) ) ;
404+ }
405+ block. append_operation ( builder. build ( ) . into ( ) ) ;
376406 }
377407
378408 /// Emits a `sol.return` terminator.
0 commit comments