mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-22 10:18:02 +00:00
c285a6ec3d
- Add column numbers to debug information. - Do not build allocas at entry for now. --------- Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
85 lines
2.3 KiB
Rust
85 lines
2.3 KiB
Rust
//! The runtime code function.
|
|
|
|
use std::marker::PhantomData;
|
|
|
|
use crate::polkavm::context::code_type::CodeType;
|
|
use crate::polkavm::context::function::runtime;
|
|
use crate::polkavm::context::Context;
|
|
use crate::polkavm::Dependency;
|
|
use crate::polkavm::WriteLLVM;
|
|
|
|
/// The runtime code function.
|
|
/// Is a special function that is only used by the front-end generated code.
|
|
#[derive(Debug)]
|
|
pub struct RuntimeCode<B, D>
|
|
where
|
|
B: WriteLLVM<D>,
|
|
D: Dependency + Clone,
|
|
{
|
|
/// The runtime code AST representation.
|
|
inner: B,
|
|
/// The `D` phantom data.
|
|
_pd: PhantomData<D>,
|
|
}
|
|
|
|
impl<B, D> RuntimeCode<B, D>
|
|
where
|
|
B: WriteLLVM<D>,
|
|
D: Dependency + Clone,
|
|
{
|
|
/// A shortcut constructor.
|
|
pub fn new(inner: B) -> Self {
|
|
Self {
|
|
inner,
|
|
_pd: PhantomData,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<B, D> WriteLLVM<D> for RuntimeCode<B, D>
|
|
where
|
|
B: WriteLLVM<D>,
|
|
D: Dependency + Clone,
|
|
{
|
|
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
|
let function_type = context.function_type::<inkwell::types::BasicTypeEnum>(vec![], 0);
|
|
context.add_function(
|
|
runtime::FUNCTION_RUNTIME_CODE,
|
|
function_type,
|
|
0,
|
|
Some(inkwell::module::Linkage::External),
|
|
None,
|
|
)?;
|
|
|
|
self.inner.declare(context)
|
|
}
|
|
|
|
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
|
context.set_current_function(runtime::FUNCTION_RUNTIME_CODE, None)?;
|
|
|
|
context.set_basic_block(context.current_function().borrow().entry_block());
|
|
context.set_code_type(CodeType::Runtime);
|
|
|
|
self.inner.into_llvm(context)?;
|
|
context.set_debug_location(0, 0, None)?;
|
|
|
|
match context
|
|
.basic_block()
|
|
.get_last_instruction()
|
|
.map(|instruction| instruction.get_opcode())
|
|
{
|
|
Some(inkwell::values::InstructionOpcode::Br) => {}
|
|
Some(inkwell::values::InstructionOpcode::Switch) => {}
|
|
_ => context
|
|
.build_unconditional_branch(context.current_function().borrow().return_block()),
|
|
}
|
|
|
|
context.set_basic_block(context.current_function().borrow().return_block());
|
|
context.build_unreachable();
|
|
|
|
context.pop_debug_scope();
|
|
|
|
Ok(())
|
|
}
|
|
}
|