Skip to content

Commit

Permalink
feat: Support values
Browse files Browse the repository at this point in the history
  • Loading branch information
lmondada committed Jun 17, 2024
1 parent 4ae1b8a commit 66d456e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ impl<'c, H: HugrView> EmitHugr<'c, H> {
/// It is safe to emit the same node multiple times, it will be detected and
/// omitted.
///
/// If any LLVM IR declaration which is to emitted already exists in the
/// If any LLVM IR declaration which is to be emitted already exists in the
/// [Module] and it differs from what would be emitted, then we fail.
pub fn emit_global(mut self, node: impl Into<Emission<'c, H>>) -> Result<Self> {
let mut worklist: EmissionSet<'c, H> = [node.into()].into_iter().collect();
Expand Down
2 changes: 1 addition & 1 deletion src/emit/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use super::{Emission, EmissionSet, EmitModuleContext};
mod mailbox;
pub use mailbox::{RowMailBox, RowPromise};

/// A context for the emitting an LLVM function.
/// A context for emitting an LLVM function.
///
/// One of the primary interfaces that impls of
/// [crate::custom::CodegenExtension] and [super::EmitOp] will interface with,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: src/types.rs
expression: "Function([[]+[]] -> [[]][[]+[]+[]])"
---
"{ i32, {}, {}, {} } ({ i32, {}, {} })*"
13 changes: 8 additions & 5 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use hugr::{types::TypeRow, HugrView};
use inkwell::builder::Builder;
use inkwell::types::{self as iw, AnyType, AsTypeRef, IntType};
use inkwell::values::{BasicValue, BasicValueEnum, StructValue};
use inkwell::AddressSpace;
use inkwell::{
context::Context,
types::{BasicMetadataTypeEnum, BasicType, BasicTypeEnum, StructType},
Expand Down Expand Up @@ -52,13 +53,14 @@ impl<'c, H: HugrView> TypingSession<'c, H> {
use hugr::types::TypeEnum;
match hugr_type.as_type_enum() {
TypeEnum::Extension(ref custom_type) => self.extensions.llvm_type(self, custom_type),
TypeEnum::Alias(ref alias) => Err(anyhow!("Invalid type: {:?}", alias)),

// TODO Function Types are fine
TypeEnum::Function(ref func_ty) => Err(anyhow!("Invalid type: {:?}", func_ty)),
TypeEnum::Sum(sum) => self.llvm_sum_type(sum.clone()).map(Into::into),
TypeEnum::Function(ref func_ty) => Ok(self
.llvm_func_type(func_ty)?
.ptr_type(AddressSpace::default()) // Note: deprecated in LLVM >= 15
.into()),

TypeEnum::Alias(ref alias) => Err(anyhow!("Invalid type: {:?}", alias)),
x @ TypeEnum::Variable(_, _) => Err(anyhow!("Invalid type: {:?}", x)),
TypeEnum::Sum(sum) => self.llvm_sum_type(sum.clone()).map(Into::into),
}
}

Expand Down Expand Up @@ -383,6 +385,7 @@ pub mod test {
#[case(4, INT_TYPES[6].clone())]
#[case(5, Type::new_sum([vec![INT_TYPES[2].clone()].into()]))]
#[case(6, Type::new_sum([vec![INT_TYPES[6].clone(),Type::new_unit_sum(1)].into(), vec![Type::new_unit_sum(2), INT_TYPES[2].clone()].into()]))]
#[case(7, Type::new_function(FunctionType::new(type_row!(Type::new_unit_sum(2)), Type::new_unit_sum(3))))]
fn ext_types(
#[case] _id: i32,
#[with(_id, add_int_extensions)] llvm_ctx: TestContext,
Expand Down

0 comments on commit 66d456e

Please sign in to comment.