mirror of
https://github.com/vosen/ZLUDA.git
synced 2025-04-19 16:04:44 +00:00
LLVM unit tests: Include emit_llvm::Context in emit_llvm::Module
This commit is contained in:
parent
32d421a282
commit
0aa8f5c142
2 changed files with 13 additions and 12 deletions
|
@ -65,17 +65,21 @@ impl Drop for Context {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct Module(LLVMModuleRef);
|
||||
pub struct Module(LLVMModuleRef, Context);
|
||||
|
||||
impl Module {
|
||||
fn new(ctx: &Context, name: &CStr) -> Self {
|
||||
Self(unsafe { LLVMModuleCreateWithNameInContext(name.as_ptr(), ctx.get()) })
|
||||
fn new(ctx: Context, name: &CStr) -> Self {
|
||||
Self(unsafe { LLVMModuleCreateWithNameInContext(name.as_ptr(), ctx.get()) }, ctx)
|
||||
}
|
||||
|
||||
fn get(&self) -> LLVMModuleRef {
|
||||
self.0
|
||||
}
|
||||
|
||||
fn context(&self) -> &Context {
|
||||
&self.1
|
||||
}
|
||||
|
||||
fn verify(&self) -> Result<(), Message> {
|
||||
let mut err = ptr::null_mut();
|
||||
let error = unsafe {
|
||||
|
@ -180,10 +184,9 @@ impl Deref for MemoryBuffer {
|
|||
pub(super) fn run<'input>(
|
||||
id_defs: GlobalStringIdentResolver2<'input>,
|
||||
directives: Vec<Directive2<'input, ast::Instruction<SpirvWord>, SpirvWord>>,
|
||||
) -> Result<(Module, Context), TranslateError> {
|
||||
let context = Context::new();
|
||||
let module = Module::new(&context, LLVM_UNNAMED);
|
||||
let mut emit_ctx = ModuleEmitContext::new(&context, &module, &id_defs);
|
||||
) -> Result<Module, TranslateError> {
|
||||
let module = Module::new(Context::new(), LLVM_UNNAMED);
|
||||
let mut emit_ctx = ModuleEmitContext::new(&module, &id_defs);
|
||||
for directive in directives {
|
||||
match directive {
|
||||
Directive2::Variable(linking, variable) => emit_ctx.emit_global(linking, variable)?,
|
||||
|
@ -193,7 +196,7 @@ pub(super) fn run<'input>(
|
|||
if let Err(err) = module.verify() {
|
||||
panic!("{:?}", err);
|
||||
}
|
||||
Ok((module, context))
|
||||
Ok(module)
|
||||
}
|
||||
|
||||
struct ModuleEmitContext<'a, 'input> {
|
||||
|
@ -206,10 +209,10 @@ struct ModuleEmitContext<'a, 'input> {
|
|||
|
||||
impl<'a, 'input> ModuleEmitContext<'a, 'input> {
|
||||
fn new(
|
||||
context: &Context,
|
||||
module: &Module,
|
||||
id_defs: &'a GlobalStringIdentResolver2<'input>,
|
||||
) -> Self {
|
||||
let context= module.context();
|
||||
ModuleEmitContext {
|
||||
context: context.get(),
|
||||
module: module.get(),
|
||||
|
|
|
@ -53,17 +53,15 @@ pub fn to_llvm_module<'input>(ast: ast::Module<'input>) -> Result<Module, Transl
|
|||
let directives = insert_implicit_conversions2::run(&mut flat_resolver, directives)?;
|
||||
let directives = replace_instructions_with_function_calls::run(&mut flat_resolver, directives)?;
|
||||
let directives = hoist_globals::run(directives)?;
|
||||
let (llvm_ir, llvm_context) = emit_llvm::run(flat_resolver, directives)?;
|
||||
let llvm_ir = emit_llvm::run(flat_resolver, directives)?;
|
||||
Ok(Module {
|
||||
llvm_ir,
|
||||
_llvm_context: llvm_context,
|
||||
kernel_info: HashMap::new(),
|
||||
})
|
||||
}
|
||||
|
||||
pub struct Module {
|
||||
pub llvm_ir: emit_llvm::Module,
|
||||
_llvm_context: emit_llvm::Context,
|
||||
pub kernel_info: HashMap<String, KernelInfo>,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue