From c40a4ddc53d785424bb3cf2ea3be9b5ce01cb892 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 27 Apr 2018 05:38:53 -0700 Subject: [PATCH] Add functions to Module for initializing Contexts. This allows Module to assign the Context the TargetIsa's default calling convention. --- lib/module/src/module.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/module/src/module.rs b/lib/module/src/module.rs index c4090404ac..f3073f8468 100644 --- a/lib/module/src/module.rs +++ b/lib/module/src/module.rs @@ -331,6 +331,25 @@ where } } + /// Create a new `Context` initialized for use with this `Module`. + /// + /// This ensures that the `Context` is initialized with the default calling + /// convention for the `TargetIsa`. + pub fn make_context(&self) -> Context { + let mut ctx = Context::new(); + ctx.func.signature.call_conv = self.backend.isa().flags().call_conv(); + ctx + } + + /// Create a new `Context` initialized for use with this `Module`. + /// + /// This ensures that the `Context` is initialized with the default calling + /// convention for the `TargetIsa`. + pub fn clear_context(&self, ctx: &mut Context) { + ctx.clear(); + ctx.func.signature.call_conv = self.backend.isa().flags().call_conv(); + } + /// Declare a function in this module. pub fn declare_function( &mut self,