use crate::codegen::FunctionTranslator;
use crate::compiler::{RuntimeId, JIT};
use crate::layout::stack_frame::native_calling_conv;
use cranelift_module::Linkage;
use edlc_core::prelude::mir_backend::CodeGen;
use edlc_core::prelude::mir_expr::mir_call::MirCall;
use edlc_core::prelude::mir_expr::{MirFlowGraph, MirLoc, MirValue};
use edlc_core::prelude::mir_funcs::CallSrc;
use edlc_core::prelude::{DebugInformation, MirError, MirPhase};
#[derive(Clone)]
pub struct JITExternCall {
pub symbol: String,
pub linkage: Linkage,
pub runtime: Option<RuntimeId>,
}
impl JITExternCall {
pub fn external(symbol: String, linkage: Linkage) -> Self {
JITExternCall {
symbol,
linkage,
runtime: None,
}
}
pub fn external_with_runtime<Id: Into<RuntimeId>>(symbol: String, id: Id) -> Self {
JITExternCall {
symbol,
linkage: Linkage::Import,
runtime: Some(id.into()),
}
}
}
impl<Runtime> CodeGen<JIT<Runtime>> for JITExternCall {
fn code_gen(
&self,
backend: &mut FunctionTranslator<'_, Runtime>,
phase: &mut MirPhase,
cfg: &MirFlowGraph,
call: &MirCall,
target: Option<&MirValue>,
call_src: &CallSrc,
) -> Result<(), MirError<JIT<Runtime>>> {
match call_src {
CallSrc::Expr(expr_id) => {
assert!(target.is_some());
let call_layout = backend.layout.call_layout(expr_id).clone();
let sig = call_layout.compile(backend, phase).unwrap();
sig.generate(backend, phase, self)
}
CallSrc::Headless(id) => {
let call_layout = backend.layout.headless_layout(id).clone();
let sig = call_layout.compile(backend, phase).unwrap();
sig.generate(backend, phase, self)
}
}
}
fn debug_info(
&self,
_info: &mut DebugInformation,
_loc: &MirLoc,
) {
}
}