-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initializes codegen for function body
- Loading branch information
1 parent
e182b35
commit 6cc84e1
Showing
7 changed files
with
126 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use super::Codegen; | ||
use llvm_sys::core::{LLVMCreateBasicBlockInContext, LLVMDeleteBasicBlock}; | ||
use llvm_sys::prelude::LLVMBasicBlockRef; | ||
use std::marker::PhantomData; | ||
|
||
/// Encapsulate an LLVM basic block. | ||
pub struct BasicBlock<'a, 'b: 'a> { | ||
value: LLVMBasicBlockRef, | ||
phantom: PhantomData<&'a Codegen<'b>>, | ||
} | ||
|
||
impl<'a, 'b: 'a> BasicBlock<'a, 'b> { | ||
pub fn new(cx: &'a Codegen<'b>) -> Self { | ||
Self { | ||
value: unsafe { LLVMCreateBasicBlockInContext(cx.llvm, b"\0".as_ptr() as _) }, | ||
phantom: PhantomData, | ||
} | ||
} | ||
|
||
pub fn as_raw(&self) -> LLVMBasicBlockRef { | ||
self.value | ||
} | ||
} | ||
|
||
impl<'a, 'b: 'a> Drop for BasicBlock<'a, 'b> { | ||
fn drop(&mut self) { | ||
unsafe { LLVMDeleteBasicBlock(self.value) }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use super::{BasicBlock, Codegen}; | ||
use llvm_sys::core::{ | ||
LLVMBuildRetVoid, LLVMCreateBuilderInContext, LLVMDisposeBuilder, LLVMPositionBuilderAtEnd, | ||
}; | ||
use llvm_sys::prelude::LLVMBuilderRef; | ||
use std::marker::PhantomData; | ||
|
||
/// Encapsulate an LLVM IR builder. | ||
pub struct Builder<'a, 'b: 'a> { | ||
raw: LLVMBuilderRef, | ||
phantom: PhantomData<&'a Codegen<'b>>, | ||
} | ||
|
||
impl<'a, 'b: 'a> Builder<'a, 'b> { | ||
pub fn new(cx: &'a Codegen<'b>, block: &mut BasicBlock<'a, 'b>) -> Self { | ||
let raw = unsafe { LLVMCreateBuilderInContext(cx.llvm) }; | ||
|
||
unsafe { LLVMPositionBuilderAtEnd(raw, block.as_raw()) }; | ||
|
||
Self { | ||
raw, | ||
phantom: PhantomData, | ||
} | ||
} | ||
|
||
pub fn ret_void(&mut self) { | ||
unsafe { LLVMBuildRetVoid(self.raw) }; | ||
} | ||
} | ||
|
||
impl<'a, 'b: 'a> Drop for Builder<'a, 'b> { | ||
fn drop(&mut self) { | ||
unsafe { LLVMDisposeBuilder(self.raw) }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters