Skip to content

Commit ee5bd9f

Browse files
Merge pull request #54 from UnionCompilerDesign/ir_hotfix
Ir hotfix
2 parents a2508e2 + 064c8c1 commit ee5bd9f

20 files changed

+711
-707
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ members = [
3131
"./jit",
3232
"./logging",
3333
]
34+
35+
[build-dependencies]
36+
pkg-config = "0.3"

ir/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The `core` submodule of the `ir` module is primarily intended for internal usage
1616

1717
#### Creating a new Context
1818
```rust
19-
let ir_gen = IRGenerator::new();
19+
let ir_gen = IRManager::new();
2020
let context_tag = ir_gen.create_context().expect("Failed to create context");
2121
```
2222

ir/src/block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ extern crate llvm_sys as llvm;
88
use llvm::{core, prelude::{LLVMBasicBlockRef, LLVMBuilderRef, LLVMContextRef, LLVMValueRef}};
99
use std::ffi::CString;
1010
use common::pointer::{LLVMRef, LLVMRefType};
11-
use crate::core::{BasicBlockTag, BuilderTag, ContextTag, IRGenerator, ValueTag};
11+
use crate::core::{BasicBlockTag, BuilderTag, ContextTag, IRManager, ValueTag};
1212

13-
impl IRGenerator {
13+
impl IRManager {
1414
/// Creates a basic block in the specified function and context.
1515
///
1616
/// # Parameters

ir/src/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ extern crate llvm_sys as llvm;
88
use std::ffi::CString;
99
use llvm::{core, prelude::LLVMBuilderRef, LLVMIntPredicate};
1010
use common::pointer::{LLVMRef, LLVMRefType};
11-
use crate::core::{BuilderTag, ContextTag, IRGenerator, ModuleTag, TypeTag, ValueTag};
11+
use crate::core::{BuilderTag, ContextTag, IRManager, ModuleTag, TypeTag, ValueTag};
1212

13-
impl IRGenerator {
13+
impl IRManager {
1414
/// Allocates a builder in a specified context and stores it in the resource pool.
1515
///
1616
/// # Parameters

ir/src/core.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ pub struct EnumDefinition {
1717
}
1818

1919
/// Tag associated with an LLVM Context.
20-
/// Provides access to stored context resources within the IRGenerator pools.
20+
/// Provides access to stored context resources within the IRManager pools.
2121
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
2222
pub struct ContextTag(usize);
2323

2424
/// Tag associated with an LLVM Module.
25-
/// Allows for retrieval and management of module resources in the IRGenerator pools.
25+
/// Allows for retrieval and management of module resources in the IRManager pools.
2626
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
2727
pub struct ModuleTag(usize);
2828

2929
/// Tag associated with an LLVM Value.
30-
/// Used for accessing and manipulating value resources in the IRGenerator pools.
30+
/// Used for accessing and manipulating value resources in the IRManager pools.
3131
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
3232
pub struct ValueTag(usize);
3333

@@ -37,12 +37,12 @@ pub struct ValueTag(usize);
3737
pub struct BasicBlockTag(usize);
3838

3939
/// Tag associated with an LLVM Builder.
40-
/// Used to access builder resources stored within the IRGenerator pools.
40+
/// Used to access builder resources stored within the IRManager pools.
4141
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
4242
pub struct BuilderTag(usize);
4343

4444
/// Tag associated with an LLVM Type.
45-
/// Enables the handling and retrieval of type resources from the IRGenerator pools.
45+
/// Enables the handling and retrieval of type resources from the IRManager pools.
4646
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
4747
pub struct TypeTag(usize);
4848

@@ -89,10 +89,10 @@ impl EnumDefinition {
8989
}
9090

9191

92-
/// Enum representing unique tags for various types of LLVM objects managed within the IRGenerator.
92+
/// Enum representing unique tags for various types of LLVM objects managed within the IRManager.
9393
/// Each tag is unique and provides a way to retrieve specific LLVM objects from internal resource pools.
9494
pub enum Tag {
95-
/// Tag for identifying and retrieving LLVM `Context` objects from the IRGenerator's resource pools.
95+
/// Tag for identifying and retrieving LLVM `Context` objects from the IRManager's resource pools.
9696
/// Contexts represent environments in which LLVM IR generation and manipulation occur.
9797
Context(ContextTag),
9898

@@ -119,7 +119,7 @@ pub enum Tag {
119119
}
120120

121121
/// Core structure for managing IR generation. This includes creation, storage, and retrieval of LLVM related objects.
122-
pub struct IRGenerator {
122+
pub struct IRManager {
123123
contexts: Option<HashMap<ContextTag, Arc<RwLock<SafeLLVMPointer>>>>,
124124
modules: Option<HashMap<ModuleTag, Arc<RwLock<SafeLLVMPointer>>>>,
125125
values: Option<HashMap<ValueTag, Arc<RwLock<SafeLLVMPointer>>>>,
@@ -131,11 +131,11 @@ pub struct IRGenerator {
131131
next_tag: usize,
132132
}
133133

134-
impl IRGenerator {
135-
/// Constructs a new instance of `IRGenerator`.
134+
impl IRManager {
135+
/// Constructs a new instance of `IRManager`.
136136
///
137137
/// # Returns
138-
/// A new `IRGenerator` instance with empty pools and a tag counter initialized to zero.
138+
/// A new `IRManager` instance with empty pools and a tag counter initialized to zero.
139139
pub fn new() -> Self {
140140
Self {
141141
contexts: None,

ir/src/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ extern crate llvm_sys as llvm;
77
use std::collections::HashMap;
88
use llvm::{core, prelude::LLVMTypeRef};
99
use common::pointer::{LLVMRef, LLVMRefType};
10-
use super::core::{EnumDefinition, BuilderTag, ContextTag, IRGenerator, TypeTag, ValueTag};
10+
use super::core::{EnumDefinition, BuilderTag, ContextTag, IRManager, TypeTag, ValueTag};
1111

12-
impl IRGenerator {
12+
impl IRManager {
1313
/// Returns the LLVM type for void in a specified context.
1414
///
1515
/// # Parameters

ir/src/values.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ extern crate llvm_sys as llvm;
77
use llvm::core;
88
use std::ffi::CString;
99
use common::pointer::{LLVMRef, LLVMRefType};
10-
use super::core::{BasicBlockTag, BuilderTag, ContextTag, IRGenerator, TypeTag, ValueTag};
10+
use super::core::{BasicBlockTag, BuilderTag, ContextTag, IRManager, TypeTag, ValueTag};
1111

12-
impl IRGenerator {
12+
impl IRManager {
1313
/// Creates a 64-bit integer constant in a specified context.
1414
///
1515
/// # Parameters

ir/src/variables.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ extern crate llvm_sys as llvm;
77
use llvm::core;
88
use std::ffi::CString;
99
use common::pointer::{LLVMRef, LLVMRefType};
10-
use super::core::{BuilderTag, IRGenerator, TypeTag, ValueTag};
10+
use super::core::{BuilderTag, IRManager, TypeTag, ValueTag};
1111

12-
impl IRGenerator {
12+
impl IRManager {
1313
/// Initializes a variable with an optional initial value in the specified builder context.
1414
///
1515
/// # Parameters

ir/tests/block_tests.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use analysis::validator::Validator;
22
use common::constants::{DEFAULT_BASIC_BLOCK_NAME, DEFAULT_FUNCTION_NAME, DEFAULT_MODULE_NAME};
3-
use ir::core::IRGenerator;
3+
use ir::core::IRManager;
44

55
#[test]
66
fn test_create_basic_block() {
7-
let mut resource_pools = IRGenerator::new();
7+
let mut resource_pools = IRManager::new();
88

99
let context_tag = resource_pools.create_context().expect("Failed to create context");
1010
let module_tag = resource_pools.create_module(DEFAULT_MODULE_NAME, context_tag).expect("Failed to create module within context");
@@ -39,7 +39,7 @@ fn test_create_basic_block() {
3939

4040
#[test]
4141
fn test_get_current_block() {
42-
let mut resource_pools = IRGenerator::new();
42+
let mut resource_pools = IRManager::new();
4343

4444
let context_tag = resource_pools.create_context().expect("Failed to create context");
4545
let module_tag = resource_pools.create_module(DEFAULT_MODULE_NAME, context_tag).expect("Failed to create module within context");
@@ -72,7 +72,7 @@ fn test_get_current_block() {
7272

7373
#[test]
7474
fn test_get_next_and_previous_block() {
75-
let mut resource_pools = IRGenerator::new();
75+
let mut resource_pools = IRManager::new();
7676

7777
let context_tag = resource_pools.create_context().expect("Failed to create context");
7878
let module_tag = resource_pools.create_module(DEFAULT_MODULE_NAME, context_tag).expect("Failed to create module within context");
@@ -92,7 +92,7 @@ fn test_get_next_and_previous_block() {
9292

9393
#[test]
9494
fn test_create_after_block() {
95-
let mut resource_pools = IRGenerator::new();
95+
let mut resource_pools = IRManager::new();
9696

9797
let context_tag = resource_pools.create_context().expect("Failed to create context");
9898
let module_tag = resource_pools.create_module(DEFAULT_MODULE_NAME, context_tag).expect("Failed to create module within context");
@@ -120,7 +120,7 @@ fn test_create_after_block() {
120120

121121
#[test]
122122
fn test_create_cond_br() {
123-
let mut resource_pools = IRGenerator::new();
123+
let mut resource_pools = IRManager::new();
124124

125125
let context_tag = resource_pools.create_context().expect("Failed to create context");
126126
let module_tag = resource_pools.create_module(DEFAULT_MODULE_NAME, context_tag).expect("Failed to create module within context");
@@ -159,7 +159,7 @@ fn test_create_cond_br() {
159159

160160
#[test]
161161
fn test_create_br() {
162-
let mut resource_pools = IRGenerator::new();
162+
let mut resource_pools = IRManager::new();
163163

164164
let context_tag = resource_pools.create_context().expect("Failed to create context");
165165
let module_tag = resource_pools.create_module(DEFAULT_MODULE_NAME, context_tag).expect("Failed to create module within context");
@@ -199,7 +199,7 @@ fn test_create_br() {
199199

200200
#[test]
201201
fn test_insert_before_basic_block() {
202-
let mut resource_pools = IRGenerator::new();
202+
let mut resource_pools = IRManager::new();
203203

204204
let context_tag = resource_pools.create_context().expect("Failed to create context");
205205
let module_tag = resource_pools.create_module(DEFAULT_MODULE_NAME, context_tag).expect("Failed to create module within context"); let function_type = resource_pools.void_type(context_tag).expect("Failed to create function type");
@@ -238,7 +238,7 @@ fn test_insert_before_basic_block() {
238238

239239
#[test]
240240
fn test_position_builder_at_end() {
241-
let mut resource_pools = IRGenerator::new();
241+
let mut resource_pools = IRManager::new();
242242

243243
let context_tag = resource_pools.create_context().expect("Failed to create context");
244244
let module_tag = resource_pools.create_module(DEFAULT_MODULE_NAME, context_tag).expect("Failed to create module within context");
@@ -275,7 +275,7 @@ fn test_position_builder_at_end() {
275275

276276
#[test]
277277
fn test_delete_basic_block() {
278-
let mut resource_pools = IRGenerator::new();
278+
let mut resource_pools = IRManager::new();
279279

280280
let context_tag = resource_pools.create_context().expect("Failed to create context");
281281
let module_tag = resource_pools.create_module(DEFAULT_MODULE_NAME, context_tag).expect("Failed to create module within context");
@@ -312,7 +312,7 @@ fn test_delete_basic_block() {
312312

313313
#[test]
314314
fn test_get_first_instruction() {
315-
let mut resource_pools = IRGenerator::new();
315+
let mut resource_pools = IRManager::new();
316316

317317
let context_tag = resource_pools.create_context().expect("Failed to create context");
318318
let module_tag = resource_pools.create_module(DEFAULT_MODULE_NAME, context_tag).expect("Failed to create module within context");
@@ -348,7 +348,7 @@ fn test_get_first_instruction() {
348348

349349
#[test]
350350
fn test_get_last_instruction() {
351-
let mut resource_pools = IRGenerator::new();
351+
let mut resource_pools = IRManager::new();
352352

353353
let context_tag = resource_pools.create_context().expect("Failed to create context");
354354
let module_tag = resource_pools.create_module(DEFAULT_MODULE_NAME, context_tag).expect("Failed to create module within context");

ir/tests/builder_tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use analysis::validator::Validator;
22
use common::constants::{DEFAULT_BASIC_BLOCK_NAME, DEFAULT_FUNCTION_NAME};
3-
use ir::core::{IRGenerator, TypeTag};
3+
use ir::core::{IRManager, TypeTag};
44

55
#[test]
66
fn test_builder_creation() {
7-
let mut llvm_resource_pool = IRGenerator::new();
7+
let mut llvm_resource_pool = IRManager::new();
88
let context_tag = llvm_resource_pool.create_context()
99
.expect("Failed to create context");
1010

@@ -14,7 +14,7 @@ fn test_builder_creation() {
1414

1515
#[test]
1616
fn test_create_function_no_params_void_return() {
17-
let mut llvm_resource_pool = IRGenerator::new();
17+
let mut llvm_resource_pool = IRManager::new();
1818

1919
let context_tag = llvm_resource_pool.create_context().expect("Failed to create context");
2020
let module_tag = llvm_resource_pool.create_module("test_module", context_tag).expect("Failed to create module");
@@ -46,7 +46,7 @@ fn test_create_function_no_params_void_return() {
4646
}
4747
#[test]
4848
fn test_create_function_with_params() {
49-
let mut llvm_resource_pool = IRGenerator::new();
49+
let mut llvm_resource_pool = IRManager::new();
5050
let context_tag = llvm_resource_pool.create_context().expect("Failed to create context");
5151
let module_tag = llvm_resource_pool.create_module("test_module_with_params", context_tag).expect("Failed to create module");
5252
let int_type_tag = llvm_resource_pool.int_type(context_tag, 32).expect("Failed to create integer type");

0 commit comments

Comments
 (0)