Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions hugr-llvm/src/emit.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{Result, anyhow};
use delegate::delegate;
use hugr_core::{
HugrView, Node,
HugrView, Node, Visibility,
ops::{FuncDecl, FuncDefn, OpType},
types::PolyFuncType,
};
Expand Down Expand Up @@ -128,13 +128,18 @@ impl<'c, 'a, H> EmitModuleContext<'c, 'a, H> {
name: impl AsRef<str>,
node: Node,
func_ty: &PolyFuncType,
visibility: &Visibility,
) -> Result<FunctionValue<'c>> {
let func_ty = (func_ty.params().is_empty())
.then_some(func_ty.body())
.ok_or(anyhow!("function has type params"))?;
let llvm_func_ty = self.llvm_func_type(func_ty)?;
let name = self.name_func(name, node);
self.get_func_impl(name, llvm_func_ty, None)
match visibility {
Visibility::Public => self.get_func_impl(name, llvm_func_ty, Some(Linkage::External)),
Visibility::Private => self.get_func_impl(name, llvm_func_ty, Some(Linkage::Private)),
_ => self.get_func_impl(name, llvm_func_ty, None),
}
}

/// Adds or gets the [`FunctionValue`] in the [Module] corresponding to the given [`FuncDefn`].
Expand All @@ -147,7 +152,12 @@ impl<'c, 'a, H> EmitModuleContext<'c, 'a, H> {
where
H: HugrView<Node = Node>,
{
self.get_hugr_func_impl(node.func_name(), node.node(), node.signature())
self.get_hugr_func_impl(
node.func_name(),
node.node(),
node.signature(),
node.visibility(),
)
}

/// Adds or gets the [`FunctionValue`] in the [Module] corresponding to the given [`FuncDecl`].
Expand All @@ -160,7 +170,12 @@ impl<'c, 'a, H> EmitModuleContext<'c, 'a, H> {
where
H: HugrView<Node = Node>,
{
self.get_hugr_func_impl(node.func_name(), node.node(), node.signature())
self.get_hugr_func_impl(
node.func_name(),
node.node(),
node.signature(),
node.visibility(),
)
}

/// Adds or get the [`FunctionValue`] in the [Module] with the given symbol
Expand Down
2 changes: 1 addition & 1 deletion ...-llvm/src/emit/ops/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define i8 @_hl.main.1(i8 %0, i8 %1) {
define private i8 @_hl.main.1(i8 %0, i8 %1) {
alloca_block:
br label %entry_block

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define i8 @_hl.main.1(i8 %0, i8 %1) {
define private i8 @_hl.main.1(i8 %0, i8 %1) {
alloca_block:
%"0" = alloca i8, align 1
%"2_0" = alloca i8, align 1
Expand Down
2 changes: 1 addition & 1 deletion hugr-llvm/src/emit/ops/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define i1 @_hl.main.1(i2 %0, i1 %1) {
define private i1 @_hl.main.1(i2 %0, i1 %1) {
alloca_block:
br label %entry_block

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define i1 @_hl.main.1(i2 %0, i1 %1) {
define private i1 @_hl.main.1(i2 %0, i1 %1) {
alloca_block:
%"0" = alloca i1, align 1
%"5_0" = alloca {}, align 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define i1 @_hl.main.1() {
define private i1 @_hl.main.1() {
alloca_block:
br label %entry_block

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define i1 @_hl.main.1() {
define private i1 @_hl.main.1() {
alloca_block:
%"0" = alloca i1, align 1
%"4_0" = alloca i1, align 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
source: src/emit/test.rs
expression: module.to_string()
source: hugr-llvm/src/emit/test.rs
expression: mod_str
---
; ModuleID = 'test_context'
source_filename = "test_context"

define void @_hl.f1.1() {
define private void @_hl.f1.1() {
alloca_block:
br label %entry_block

entry_block: ; preds = %alloca_block
ret void
}

define void @_hl.f2.4() {
define private void @_hl.f2.4() {
alloca_block:
br label %entry_block

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
source: src/emit/test.rs
expression: module.to_string()
source: hugr-llvm/src/emit/test.rs
expression: mod_str
---
; ModuleID = 'test_context'
source_filename = "test_context"

define void @_hl.f1.1() {
define private void @_hl.f1.1() {
alloca_block:
br label %entry_block

entry_block: ; preds = %alloca_block
ret void
}

define void @_hl.f2.4() {
define private void @_hl.f2.4() {
alloca_block:
br label %entry_block

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define { { i2, i2, i1 }, {} } @_hl.main.1({ i2, i2, i1 } %0, {} %1) {
define private { { i2, i2, i1 }, {} } @_hl.main.1({ i2, i2, i1 } %0, {} %1) {
alloca_block:
br label %entry_block

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define { { i2, i2, i1 }, {} } @_hl.main.1({ i2, i2, i1 } %0, {} %1) {
define private { { i2, i2, i1 }, {} } @_hl.main.1({ i2, i2, i1 } %0, {} %1) {
alloca_block:
%"0" = alloca { i2, i2, i1 }, align 8
%"1" = alloca {}, align 8
Expand Down
6 changes: 3 additions & 3 deletions ...-llvm/src/emit/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
source: src/emit/test.rs
expression: module.to_string()
source: hugr-llvm/src/emit/test.rs
expression: mod_str
---
; ModuleID = 'test_context'
source_filename = "test_context"

define i16 @_hl.main.1() {
define private i16 @_hl.main.1() {
alloca_block:
br label %entry_block

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
source: src/emit/test.rs
expression: module.to_string()
source: hugr-llvm/src/emit/test.rs
expression: mod_str
---
; ModuleID = 'test_context'
source_filename = "test_context"

define i16 @_hl.main.1() {
define private i16 @_hl.main.1() {
alloca_block:
%"0" = alloca i16, align 2
%"7_0" = alloca i16, align 2
Expand Down
2 changes: 1 addition & 1 deletion hugr-llvm/src/emit/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define {} @_hl.main.1({} %0) {
define private {} @_hl.main.1({} %0) {
alloca_block:
br label %entry_block

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define {} @_hl.main.1({} %0) {
define private {} @_hl.main.1({} %0) {
alloca_block:
%"0" = alloca {}, align 8
%"2_0" = alloca {}, align 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define { i2, i16 } @_hl.main.1() {
define private { i2, i16 } @_hl.main.1() {
alloca_block:
br label %entry_block

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define { i2, i16 } @_hl.main.1() {
define private { i2, i16 } @_hl.main.1() {
alloca_block:
%"0" = alloca { i2, i16 }, align 8
%"5_0" = alloca { i2, i16 }, align 8
Expand Down
2 changes: 1 addition & 1 deletion hugr-llvm/src/emit/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define i2 @_hl.main.1() {
define private i2 @_hl.main.1() {
alloca_block:
br label %entry_block

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define i2 @_hl.main.1() {
define private i2 @_hl.main.1() {
alloca_block:
%"0" = alloca i2, align 1
%"4_0" = alloca i2, align 1
Expand Down
6 changes: 3 additions & 3 deletions hugr-llvm/src/emit/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
source: src/emit/test.rs
expression: module.to_string()
source: hugr-llvm/src/emit/test.rs
expression: mod_str
---
; ModuleID = 'test_context'
source_filename = "test_context"

define void ()* @_hl.main.2() {
define private void ()* @_hl.main.2() {
alloca_block:
br label %entry_block

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
source: src/emit/test.rs
expression: module.to_string()
source: hugr-llvm/src/emit/test.rs
expression: mod_str
---
; ModuleID = 'test_context'
source_filename = "test_context"

define void ()* @_hl.main.2() {
define private void ()* @_hl.main.2() {
alloca_block:
%"0" = alloca void ()*, align 8
%"5_0" = alloca void ()*, align 8
Expand Down
2 changes: 1 addition & 1 deletion hugr-llvm/src/emit/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define i64 @_hl.main.1() {
define private i64 @_hl.main.1() {
alloca_block:
br label %entry_block

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define i64 @_hl.main.1() {
define private i64 @_hl.main.1() {
alloca_block:
%"0" = alloca i64, align 8
%"7_0" = alloca i64, align 8
Expand Down
2 changes: 1 addition & 1 deletion hugr-llvm/src/emit/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define {} @_hl.main.1(i64 %0) {
define private {} @_hl.main.1(i64 %0) {
alloca_block:
br label %entry_block

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define {} @_hl.main.1(i64 %0) {
define private {} @_hl.main.1(i64 %0) {
alloca_block:
%"0" = alloca {}, align 8
%"2_0" = alloca i64, align 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ source_filename = "test_context"
@4 = private unnamed_addr constant [37 x i8] c"Expected variant 1 but got variant 0\00", align 1
@prelude.panic_template.4 = private unnamed_addr constant [34 x i8] c"Program panicked (signal %i): %s\0A\00", align 1

define void @_hl.main.1() {
define private void @_hl.main.1() {
alloca_block:
br label %entry_block

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ source_filename = "test_context"
@4 = private unnamed_addr constant [37 x i8] c"Expected variant 1 but got variant 0\00", align 1
@prelude.panic_template.4 = private unnamed_addr constant [34 x i8] c"Program panicked (signal %i): %s\0A\00", align 1

define void @_hl.main.1() {
define private void @_hl.main.1() {
alloca_block:
%"12_0" = alloca i64, align 8
%"10_0" = alloca i64, align 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define { i64*, i64 } @_hl.main.1() {
define private { i64*, i64 } @_hl.main.1() {
alloca_block:
br label %entry_block

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define { i64*, i64 } @_hl.main.1() {
define private { i64*, i64 } @_hl.main.1() {
alloca_block:
%"0" = alloca { i64*, i64 }, align 8
%"5_0" = alloca { i64*, i64 }, align 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define void @_hl.main.1() {
define private void @_hl.main.1() {
alloca_block:
br label %entry_block

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define void @_hl.main.1() {
define private void @_hl.main.1() {
alloca_block:
%"7_0" = alloca i64, align 8
%"5_0" = alloca i64, align 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define void @_hl.main.1() {
define private void @_hl.main.1() {
alloca_block:
br label %entry_block

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: mod_str
; ModuleID = 'test_context'
source_filename = "test_context"

define void @_hl.main.1() {
define private void @_hl.main.1() {
alloca_block:
%"7_0" = alloca i64, align 8
%"5_0" = alloca i64, align 8
Expand Down
Loading
Loading