Skip to main content

pliron_llvm/
lib.rs

1//! LLVM Dialect for [pliron]
2
3use pliron::{
4    context::{Context, Ptr},
5    derive::{op_interface, type_interface},
6    irbuild::dialect_conversion::{DialectConversionRewriter, OperandsInfo},
7    op::Op,
8    result::Result,
9    r#type::{Type, TypeObj},
10};
11
12pub mod attributes;
13pub mod from_llvm_ir;
14pub mod function_call_utils;
15pub mod interface_impls;
16pub mod llvm_sys;
17pub mod op_interfaces;
18pub mod ops;
19pub mod to_llvm_ir;
20pub mod types;
21
22/// Interface for rewriting to LLVM dialect.
23#[op_interface]
24pub trait ToLLVMDialect {
25    /// Rewrite [self] to LLVM dialect.
26    fn rewrite(
27        &self,
28        ctx: &mut Context,
29        rewriter: &mut DialectConversionRewriter,
30        operands_info: &OperandsInfo,
31    ) -> Result<()>;
32
33    fn verify(_op: &dyn Op, _ctx: &Context) -> Result<()>
34    where
35        Self: Sized,
36    {
37        Ok(())
38    }
39}
40
41/// A function pointer type for the [ToLLVMType] interface.
42pub type ToLLVMTypeFn = fn(self_ty: Ptr<TypeObj>, &mut Context) -> Result<Ptr<TypeObj>>;
43
44/// Interface for converting to an LLVM type.
45#[type_interface]
46pub trait ToLLVMType {
47    /// Get a function to convert [self] to an LLVM type.
48    // We don't directly specify a conversion function here because
49    // the caller cannot get `&dyn ToLLVMType` (&self) while also
50    // passing `&mut Context` to the conversion function.
51    fn converter(&self) -> ToLLVMTypeFn;
52
53    fn verify(_ty: &dyn Type, _ctx: &Context) -> Result<()>
54    where
55        Self: Sized,
56    {
57        Ok(())
58    }
59}