From e60477092a26a2f5986fd26cf2754363417479ca Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 28 Aug 2018 12:31:38 -0700 Subject: [PATCH] Add a `make_signature` function for making callable signatures. The `Module` can create signatures with the appropriate calling convention. --- lib/module/src/module.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/module/src/module.rs b/lib/module/src/module.rs index 185057b946..cc89ad68c0 100644 --- a/lib/module/src/module.rs +++ b/lib/module/src/module.rs @@ -339,7 +339,7 @@ where ctx } - /// Create a new `Context` initialized for use with this `Module`. + /// Clear the given `Context` and reset it for use with a new function. /// /// This ensures that the `Context` is initialized with the default calling /// convention for the `TargetIsa`. @@ -348,6 +348,21 @@ where ctx.func.signature.call_conv = self.backend.isa().flags().call_conv(); } + /// Create a new empty `Signature` with the default calling convention for + /// the `TargetIsa`, to which parameter and return types can be added for + /// declaring a function to be called by this `Module`. + pub fn make_signature(&self) -> ir::Signature { + ir::Signature::new(self.backend.isa().flags().call_conv()) + } + + /// Clear the given `Signature` and reset for use with a new function. + /// + /// This ensures that the `Signature` is initialized with the default + /// calling convention for the `TargetIsa`. + pub fn clear_signature(&self, sig: &mut ir::Signature) { + sig.clear(self.backend.isa().flags().call_conv()); + } + /// Declare a function in this module. pub fn declare_function( &mut self,