@@ -437,7 +437,127 @@ impl TypeBuilder {
437437 result
438438 }
439439
440- // TODO : BNCreateFunctionTypeBuilder
440+ // TODO: Deprecate this for a FunctionBuilder (along with the Type variant?)
441+ /// NOTE: This is likely to be deprecated and removed in favor of a function type builder, please
442+ /// use [`Type::function`] where possible.
443+ pub fn function < ' a , T : Into < Conf < & ' a Type > > > (
444+ return_type : T ,
445+ parameters : Vec < FunctionParameter > ,
446+ variable_arguments : bool ,
447+ ) -> Self {
448+ let mut owned_raw_return_type = Conf :: < & Type > :: into_raw ( return_type. into ( ) ) ;
449+ let mut variable_arguments = Conf :: new ( variable_arguments, MAX_CONFIDENCE ) . into ( ) ;
450+ let mut can_return = Conf :: new ( true , MIN_CONFIDENCE ) . into ( ) ;
451+ let mut pure = Conf :: new ( false , MIN_CONFIDENCE ) . into ( ) ;
452+
453+ let mut raw_calling_convention: BNCallingConventionWithConfidence =
454+ BNCallingConventionWithConfidence {
455+ convention : std:: ptr:: null_mut ( ) ,
456+ confidence : MIN_CONFIDENCE ,
457+ } ;
458+
459+ let mut stack_adjust = Conf :: new ( 0 , MIN_CONFIDENCE ) . into ( ) ;
460+ let mut raw_parameters = parameters
461+ . into_iter ( )
462+ . map ( FunctionParameter :: into_raw)
463+ . collect :: < Vec < _ > > ( ) ;
464+ let reg_stack_adjust_regs = std:: ptr:: null_mut ( ) ;
465+ let reg_stack_adjust_values = std:: ptr:: null_mut ( ) ;
466+
467+ let mut return_regs: BNRegisterSetWithConfidence = BNRegisterSetWithConfidence {
468+ regs : std:: ptr:: null_mut ( ) ,
469+ count : 0 ,
470+ confidence : 0 ,
471+ } ;
472+
473+ let result = unsafe {
474+ Self :: from_raw ( BNCreateFunctionTypeBuilder (
475+ & mut owned_raw_return_type,
476+ & mut raw_calling_convention,
477+ raw_parameters. as_mut_ptr ( ) ,
478+ raw_parameters. len ( ) ,
479+ & mut variable_arguments,
480+ & mut can_return,
481+ & mut stack_adjust,
482+ reg_stack_adjust_regs,
483+ reg_stack_adjust_values,
484+ 0 ,
485+ & mut return_regs,
486+ BNNameType :: NoNameType ,
487+ & mut pure,
488+ ) )
489+ } ;
490+
491+ for raw_param in raw_parameters {
492+ FunctionParameter :: free_raw ( raw_param) ;
493+ }
494+
495+ result
496+ }
497+
498+ // TODO: Deprecate this for a FunctionBuilder (along with the Type variant?)
499+ /// NOTE: This is likely to be deprecated and removed in favor of a function type builder, please
500+ /// use [`Type::function_with_opts`] where possible.
501+ pub fn function_with_opts <
502+ ' a ,
503+ T : Into < Conf < & ' a Type > > ,
504+ C : Into < Conf < Ref < CoreCallingConvention > > > ,
505+ > (
506+ return_type : T ,
507+ parameters : & [ FunctionParameter ] ,
508+ variable_arguments : bool ,
509+ calling_convention : C ,
510+ stack_adjust : Conf < i64 > ,
511+ ) -> Self {
512+ let mut owned_raw_return_type = Conf :: < & Type > :: into_raw ( return_type. into ( ) ) ;
513+ let mut variable_arguments = Conf :: new ( variable_arguments, MAX_CONFIDENCE ) . into ( ) ;
514+ let mut can_return = Conf :: new ( true , MIN_CONFIDENCE ) . into ( ) ;
515+ let mut pure = Conf :: new ( false , MIN_CONFIDENCE ) . into ( ) ;
516+
517+ let mut owned_raw_calling_convention =
518+ Conf :: < Ref < CoreCallingConvention > > :: into_owned_raw ( & calling_convention. into ( ) ) ;
519+
520+ let mut stack_adjust = stack_adjust. into ( ) ;
521+ let mut raw_parameters = parameters
522+ . iter ( )
523+ . cloned ( )
524+ . map ( FunctionParameter :: into_raw)
525+ . collect :: < Vec < _ > > ( ) ;
526+
527+ // TODO: Update type signature and include these (will be a breaking change)
528+ let reg_stack_adjust_regs = std:: ptr:: null_mut ( ) ;
529+ let reg_stack_adjust_values = std:: ptr:: null_mut ( ) ;
530+
531+ let mut return_regs: BNRegisterSetWithConfidence = BNRegisterSetWithConfidence {
532+ regs : std:: ptr:: null_mut ( ) ,
533+ count : 0 ,
534+ confidence : 0 ,
535+ } ;
536+
537+ let result = unsafe {
538+ Self :: from_raw ( BNCreateFunctionTypeBuilder (
539+ & mut owned_raw_return_type,
540+ & mut owned_raw_calling_convention,
541+ raw_parameters. as_mut_ptr ( ) ,
542+ raw_parameters. len ( ) ,
543+ & mut variable_arguments,
544+ & mut can_return,
545+ & mut stack_adjust,
546+ reg_stack_adjust_regs,
547+ reg_stack_adjust_values,
548+ 0 ,
549+ & mut return_regs,
550+ BNNameType :: NoNameType ,
551+ & mut pure,
552+ ) )
553+ } ;
554+
555+ for raw_param in raw_parameters {
556+ FunctionParameter :: free_raw ( raw_param) ;
557+ }
558+
559+ result
560+ }
441561
442562 /// Create a pointer [`TypeBuilder`] with the given target type. Analogous to [`Type::pointer`].
443563 pub fn pointer < ' a , A : Architecture , T : Into < Conf < & ' a Type > > > ( arch : & A , ty : T ) -> Self {
0 commit comments