11use crate :: ast:: data:: Constant ;
22use crate :: ast:: functions:: {
3- EnvironmentParamDef , FunctionBlock , FunctionBody , FunctionDef , InsnDestInfo , JumpInstruction ,
4- JumpInstructionKind , ParamDef , PhiArg , PhiInstruction , RegularInstruction , RegularParamDef ,
5- SimpleInstruction , SimpleInstructionArgs , ThreadLocalRef , Value , VariadicParamDef ,
3+ CallArgument , CallInstruction , EnvironmentParamDef , FunctionBlock , FunctionBody , FunctionDef ,
4+ InsnDestInfo , JumpInstruction , JumpInstructionKind , ParamDef , PhiArg , PhiInstruction ,
5+ RegularCallArgument , RegularInstruction , RegularParamDef , SimpleInstruction ,
6+ SimpleInstructionArgs , ThreadLocalRef , Value , VariadicParamDef ,
67} ;
78use crate :: ast:: linkage:: Linkage ;
89use crate :: ast:: types:: { AbiType , BaseType } ;
@@ -114,7 +115,7 @@ impl Parse for RegularParamDef {
114115impl Parse for EnvironmentParamDef {
115116 const DESC : & ' static str = "environment parameter" ;
116117 fn parser < ' a > ( ) -> impl TokenParser < ' a , Self > {
117- operator ! ( ... )
118+ keyword ! ( env )
118119 . parser ( )
119120 . ignore_then ( TemporaryName :: parser ( ) )
120121 . map_with ( |name, extra| EnvironmentParamDef {
@@ -269,9 +270,11 @@ impl Parse for PhiArg {
269270impl Parse for RegularInstruction {
270271 const DESC : & ' static str = "regular instruction" ;
271272 fn parser < ' a > ( ) -> impl TokenParser < ' a , Self > {
272- SimpleInstruction :: parser ( )
273- . map ( RegularInstruction :: Simple )
274- . labelled ( Self :: DESC )
273+ choice ( (
274+ SimpleInstruction :: parser ( ) . map ( RegularInstruction :: Simple ) ,
275+ CallInstruction :: parser ( ) . map ( RegularInstruction :: Call ) ,
276+ ) )
277+ . labelled ( Self :: DESC )
275278 }
276279}
277280impl_fromstr_via_parse ! ( RegularInstruction ) ;
@@ -298,6 +301,57 @@ impl Parse for SimpleInstruction {
298301 }
299302}
300303impl_fromstr_via_parse ! ( SimpleInstruction ) ;
304+ impl Parse for CallInstruction {
305+ const DESC : & ' static str = "call instruction" ;
306+ fn parser < ' a > ( ) -> impl TokenParser < ' a , Self > {
307+ let args = CallArgument :: parser ( )
308+ . separated_by ( operator ! ( , ) . parser ( ) )
309+ . collect :: < Vec < _ > > ( )
310+ . delimited_by ( just ( Token :: OpenParen ) , just ( Token :: CloseParen ) ) ;
311+ InsnDestInfo :: parser ( )
312+ . or_not ( )
313+ . then ( keyword ! ( call) . parser ( ) . to_span ( ) )
314+ . then ( Value :: parser ( ) )
315+ . then ( args)
316+ . map_with (
317+ |( ( ( dest_info, call_kw_span) , target) , args) , extra| CallInstruction {
318+ span : extra. span ( ) ,
319+ call_kw_span,
320+ target,
321+ args,
322+ dest_info,
323+ } ,
324+ )
325+ }
326+ }
327+ impl Parse for CallArgument {
328+ const DESC : & ' static str = "call argument" ;
329+ fn parser < ' a > ( ) -> impl TokenParser < ' a , Self > {
330+ choice ( (
331+ RegularCallArgument :: parser ( ) . map ( CallArgument :: Regular ) ,
332+ keyword ! ( env)
333+ . parser ( )
334+ . ignore_then ( Value :: parser ( ) )
335+ . map ( CallArgument :: Environment ) ,
336+ operator ! ( ...)
337+ . parser ( )
338+ . to_span ( )
339+ . map ( CallArgument :: VariadicMarker ) ,
340+ ) )
341+ }
342+ }
343+ impl Parse for RegularCallArgument {
344+ const DESC : & ' static str = "regular call argument" ;
345+ fn parser < ' a > ( ) -> impl TokenParser < ' a , Self > {
346+ AbiType :: parser ( )
347+ . then ( Value :: parser ( ) )
348+ . map_with ( |( ty, value) , extra| RegularCallArgument {
349+ ty,
350+ value,
351+ span : extra. span ( ) ,
352+ } )
353+ }
354+ }
301355impl Parse for InsnDestInfo {
302356 const DESC : & ' static str = "instruction destination" ;
303357 fn parser < ' a > ( ) -> impl TokenParser < ' a , Self > {
0 commit comments