From: Jacob Lifshay Date: Wed, 17 Oct 2018 08:23:42 +0000 (-0700) Subject: add function parameters X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fd98ca6e55f64a798a0ce19421e81ad496efd0a2;p=kazan.git add function parameters --- diff --git a/shader-compiler-llvm-7/src/backend.rs b/shader-compiler-llvm-7/src/backend.rs index 3e02ad7..26964bf 100644 --- a/shader-compiler-llvm-7/src/backend.rs +++ b/shader-compiler-llvm-7/src/backend.rs @@ -223,6 +223,7 @@ impl<'a> backend::BuildableBasicBlock<'a> for LLVM7BasicBlock { pub struct LLVM7Function { context: llvm::LLVMContextRef, function: llvm::LLVMValueRef, + parameters: Box<[LLVM7Value]>, } impl fmt::Debug for LLVM7Function { @@ -250,6 +251,9 @@ impl<'a> backend::Function<'a> for LLVM7Function { )) } } + fn parameters(&self) -> &[LLVM7Value] { + &self.parameters + } } pub struct LLVM7Context { @@ -424,9 +428,15 @@ impl<'a> backend::Module<'a> for LLVM7Module { assert!(self.name_set.insert(name.into())); let name = CString::new(name).unwrap(); unsafe { + let function = llvm::LLVMAddFunction(self.module, name.as_ptr(), ty.0); + let mut parameters = Vec::new(); + parameters.resize(llvm::LLVMCountParams(function) as usize, null_mut()); + llvm::LLVMGetParams(function, parameters.as_mut_ptr()); + let parameters: Vec<_> = parameters.into_iter().map(LLVM7Value).collect(); LLVM7Function { context: self.context, function: llvm::LLVMAddFunction(self.module, name.as_ptr(), ty.0), + parameters: parameters.into_boxed_slice(), } } } diff --git a/shader-compiler/src/backend/mod.rs b/shader-compiler/src/backend/mod.rs index f3418b8..97f7441 100644 --- a/shader-compiler/src/backend/mod.rs +++ b/shader-compiler/src/backend/mod.rs @@ -75,6 +75,8 @@ pub trait Function<'a>: Debug + Sized { &mut self, name: Option<&str>, ) -> >::BuildableBasicBlock; + /// get this function's parameters + fn parameters(&self) -> &[>::Value]; } /// module verification failure; returned from `Module::verify`