Skip to content
14 changes: 7 additions & 7 deletions crates/rustc_codegen_c/src/archive.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
//! from rustc_codegen_cranelift

use std::path::{Path, PathBuf};
use rustc_codegen_ssa::back::archive::ImportLibraryItem;
use std::path::Path;

use rustc_codegen_ssa::back::archive::{
get_native_object_symbols, ArArchiveBuilder, ArchiveBuilder, ArchiveBuilderBuilder,
ArArchiveBuilder, ArchiveBuilder, ArchiveBuilderBuilder, DEFAULT_OBJECT_READER,
};
use rustc_session::Session;

pub(crate) struct ArArchiveBuilderBuilder;

impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder + 'a> {
Box::new(ArArchiveBuilder::new(sess, get_native_object_symbols))
Box::new(ArArchiveBuilder::new(sess, &DEFAULT_OBJECT_READER))
}

fn create_dll_import_lib(
&self,
_sess: &Session,
_lib_name: &str,
_dll_imports: &[rustc_session::cstore::DllImport],
_tmpdir: &Path,
_is_direct_dependency: bool,
) -> PathBuf {
_items: Vec<ImportLibraryItem>,
_output_path: &Path,
) {
unimplemented!("creating dll imports is not yet supported");
}
}
17 changes: 11 additions & 6 deletions crates/rustc_codegen_c/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::time::Instant;

use rustc_codegen_c_ast::{ModuleArena, ModuleCtx};
use rustc_codegen_ssa::mono_item::MonoItemExt;
use rustc_codegen_ssa::{ModuleCodegen, ModuleKind};
use rustc_codegen_ssa::ModuleCodegen;
use rustc_middle::dep_graph;
use rustc_middle::ty::TyCtxt;

Expand Down Expand Up @@ -44,18 +44,23 @@ fn module_codegen(tcx: TyCtxt<'_>, cgu_name: rustc_span::Symbol) -> ModuleCodege

let mcx = ModuleArena::new(HELPER);
let mcx = ModuleCtx(&mcx);
let cx = CodegenCx::new(tcx, mcx);
let mut cx = CodegenCx::new(tcx, mcx);

let mono_items = cgu.items_in_deterministic_order(tcx);
for &(mono_item, data) in &mono_items {
mono_item.predefine::<Builder<'_, '_, '_>>(&cx, data.linkage, data.visibility);
mono_item.predefine::<Builder<'_, '_, '_>>(
&mut cx,
cgu_name.as_str(),
data.linkage,
data.visibility,
);
}

// ... and now that we have everything pre-defined, fill out those definitions.
for &(mono_item, _) in &mono_items {
mono_item.define::<Builder<'_, '_, '_>>(&cx);
for &(mono_item, item_data) in &mono_items {
mono_item.define::<Builder<'_, '_, '_>>(&mut cx, cgu_name.as_str(), item_data);
}

let module = mcx.to_string();
ModuleCodegen { name: cgu_name.to_string(), module_llvm: module, kind: ModuleKind::Regular }
ModuleCodegen::new_regular(cgu_name.to_string(), module)
}
75 changes: 37 additions & 38 deletions crates/rustc_codegen_c/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ use std::ops::Deref;

use rustc_abi::{HasDataLayout, TargetDataLayout};
use rustc_codegen_c_ast::func::CFunc;
use rustc_codegen_ssa::traits::{BackendTypes, BuilderMethods, HasCodegen};
use rustc_codegen_ssa::traits::{BackendTypes, BuilderMethods};
use rustc_middle::ty;
use rustc_middle::ty::layout::{
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, LayoutOfHelpers,
TyAndLayout,
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError,
LayoutOfHelpers, TyAndLayout,
};
use rustc_middle::ty::{ParamEnv, Ty, TyCtxt};
use rustc_target::abi::call::FnAbi;
use rustc_middle::ty::{Ty, TyCtxt};
use rustc_target::callconv::FnAbi;
use rustc_target::spec::{HasTargetSpec, Target};

use crate::context::CodegenCx;
Expand Down Expand Up @@ -39,10 +40,6 @@ impl<'a, 'tcx, 'mx> Deref for Builder<'a, 'tcx, 'mx> {
}
}

impl<'tcx, 'mx> HasCodegen<'tcx> for Builder<'_, 'tcx, 'mx> {
type CodegenCx = CodegenCx<'tcx, 'mx>;
}

impl<'tcx, 'mx> HasDataLayout for Builder<'_, 'tcx, 'mx> {
fn data_layout(&self) -> &TargetDataLayout {
todo!()
Expand All @@ -55,14 +52,15 @@ impl<'tcx, 'mx> HasTyCtxt<'tcx> for Builder<'_, 'tcx, 'mx> {
}
}

impl<'tcx, 'mx> HasParamEnv<'tcx> for Builder<'_, 'tcx, 'mx> {
fn param_env(&self) -> ParamEnv<'tcx> {
self.cx.param_env()
impl<'tcx, 'mx> HasTypingEnv<'tcx> for Builder<'_, 'tcx, 'mx> {
fn typing_env(&self) -> ty::TypingEnv<'tcx> {
self.cx.typing_env()
}
}

impl<'tcx, 'mx> BackendTypes for Builder<'_, 'tcx, 'mx> {
type Value = <CodegenCx<'tcx, 'mx> as BackendTypes>::Value;
type Metadata = <CodegenCx<'tcx, 'mx> as BackendTypes>::Metadata;
type Function = <CodegenCx<'tcx, 'mx> as BackendTypes>::Function;
type BasicBlock = <CodegenCx<'tcx, 'mx> as BackendTypes>::BasicBlock;
type Type = <CodegenCx<'tcx, 'mx> as BackendTypes>::Type;
Expand Down Expand Up @@ -101,6 +99,7 @@ impl<'tcx, 'mx> FnAbiOfHelpers<'tcx> for Builder<'_, 'tcx, 'mx> {
}

impl<'a, 'tcx, 'mx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx, 'mx> {
type CodegenCx = CodegenCx<'tcx, 'mx>;
fn build(cx: &'a Self::CodegenCx, llbb: Self::BasicBlock) -> Self {
Self { cx, bb: llbb }
}
Expand Down Expand Up @@ -163,7 +162,7 @@ impl<'a, 'tcx, 'mx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx, 'mx> {
&mut self,
llty: Self::Type,
fn_attrs: Option<&rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs>,
fn_abi: Option<&rustc_target::abi::call::FnAbi<'tcx, rustc_middle::ty::Ty<'tcx>>>,
fn_abi: Option<&rustc_target::callconv::FnAbi<'tcx, rustc_middle::ty::Ty<'tcx>>>,
llfn: Self::Value,
args: &[Self::Value],
then: Self::BasicBlock,
Expand Down Expand Up @@ -356,10 +355,6 @@ impl<'a, 'tcx, 'mx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx, 'mx> {
todo!()
}

fn dynamic_alloca(&mut self, size: Self::Value, align: rustc_abi::Align) -> Self::Value {
todo!()
}

fn load(&mut self, ty: Self::Type, ptr: Self::Value, align: rustc_abi::Align) -> Self::Value {
todo!()
}
Expand All @@ -372,7 +367,7 @@ impl<'a, 'tcx, 'mx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx, 'mx> {
&mut self,
ty: Self::Type,
ptr: Self::Value,
order: rustc_codegen_ssa::common::AtomicOrdering,
order: rustc_middle::ty::AtomicOrdering,
size: rustc_abi::Size,
) -> Self::Value {
todo!()
Expand Down Expand Up @@ -425,7 +420,7 @@ impl<'a, 'tcx, 'mx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx, 'mx> {
&mut self,
val: Self::Value,
ptr: Self::Value,
order: rustc_codegen_ssa::common::AtomicOrdering,
order: rustc_middle::ty::AtomicOrdering,
size: rustc_abi::Size,
) {
todo!()
Expand Down Expand Up @@ -615,15 +610,15 @@ impl<'a, 'tcx, 'mx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx, 'mx> {
todo!()
}

fn set_personality_fn(&mut self, personality: Self::Value) {
fn set_personality_fn(&mut self, personality: Self::Function) {
todo!()
}

fn cleanup_landing_pad(&mut self, pers_fn: Self::Value) -> (Self::Value, Self::Value) {
fn cleanup_landing_pad(&mut self, pers_fn: Self::Function) -> (Self::Value, Self::Value) {
todo!()
}

fn filter_landing_pad(&mut self, pers_fn: Self::Value) -> (Self::Value, Self::Value) {
fn filter_landing_pad(&mut self, pers_fn: Self::Function) {
todo!()
}

Expand Down Expand Up @@ -657,8 +652,8 @@ impl<'a, 'tcx, 'mx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx, 'mx> {
dst: Self::Value,
cmp: Self::Value,
src: Self::Value,
order: rustc_codegen_ssa::common::AtomicOrdering,
failure_order: rustc_codegen_ssa::common::AtomicOrdering,
order: rustc_middle::ty::AtomicOrdering,
failure_order: rustc_middle::ty::AtomicOrdering,
weak: bool,
) -> (Self::Value, Self::Value) {
todo!()
Expand All @@ -669,14 +664,15 @@ impl<'a, 'tcx, 'mx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx, 'mx> {
op: rustc_codegen_ssa::common::AtomicRmwBinOp,
dst: Self::Value,
src: Self::Value,
order: rustc_codegen_ssa::common::AtomicOrdering,
order: rustc_middle::ty::AtomicOrdering,
ret_ptr: bool,
) -> Self::Value {
todo!()
}

fn atomic_fence(
&mut self,
order: rustc_codegen_ssa::common::AtomicOrdering,
order: rustc_middle::ty::AtomicOrdering,
scope: rustc_codegen_ssa::common::SynchronizationScope,
) {
todo!()
Expand All @@ -694,27 +690,17 @@ impl<'a, 'tcx, 'mx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx, 'mx> {
todo!()
}

fn instrprof_increment(
&mut self,
fn_name: Self::Value,
hash: Self::Value,
num_counters: Self::Value,
index: Self::Value,
) {
todo!()
}

fn call(
&mut self,
llty: Self::Type,
fn_attrs: Option<&rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs>,
fn_abi: Option<&rustc_target::abi::call::FnAbi<'tcx, rustc_middle::ty::Ty<'tcx>>>,
fn_abi: Option<&rustc_target::callconv::FnAbi<'tcx, rustc_middle::ty::Ty<'tcx>>>,
llfn: Self::Value,
args: &[Self::Value],
funclet: Option<&Self::Funclet>,
instance: Option<rustc_middle::ty::Instance<'tcx>>,
) -> Self::Value {
use crate::rustc_codegen_ssa::traits::LayoutTypeMethods;
use crate::rustc_codegen_ssa::traits::LayoutTypeCodegenMethods;

let fn_abi = fn_abi.unwrap();
let ret_ty = self.cx.immediate_backend_type(fn_abi.ret.layout);
Expand All @@ -729,6 +715,19 @@ impl<'a, 'tcx, 'mx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx, 'mx> {
ret
}

fn tail_call(
&mut self,
llty: Self::Type,
fn_attrs: Option<&rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs>,
fn_abi: &rustc_target::callconv::FnAbi<'tcx, rustc_middle::ty::Ty<'tcx>>,
llfn: Self::Value,
args: &[Self::Value],
funclet: Option<&Self::Funclet>,
instance: Option<rustc_middle::ty::Instance<'tcx>>,
) {
todo!()
}

fn zext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value {
todo!()
}
Expand Down
12 changes: 4 additions & 8 deletions crates/rustc_codegen_c/src/builder/abi.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use rustc_codegen_c_ast::expr::CValue;
use rustc_codegen_ssa::mir::place::PlaceRef;
use rustc_codegen_ssa::traits::{AbiBuilderMethods, ArgAbiMethods};
use rustc_codegen_ssa::traits::{AbiBuilderMethods, ArgAbiBuilderMethods};
use rustc_middle::ty::Ty;
use rustc_target::abi::call::ArgAbi;
use rustc_target::callconv::ArgAbi;

use crate::builder::Builder;

impl<'tcx, 'mx> AbiBuilderMethods<'tcx> for Builder<'_, 'tcx, 'mx> {
impl<'tcx, 'mx> AbiBuilderMethods for Builder<'_, 'tcx, 'mx> {
fn get_param(&mut self, index: usize) -> Self::Value {
// Params are first n variables in the function
CValue::Local(index)
}
}

impl<'tcx, 'mx> ArgAbiMethods<'tcx> for Builder<'_, 'tcx, 'mx> {
impl<'tcx, 'mx> ArgAbiBuilderMethods<'tcx> for Builder<'_, 'tcx, 'mx> {
fn store_fn_arg(
&mut self,
arg_abi: &ArgAbi<'tcx, Ty<'tcx>>,
Expand All @@ -31,8 +31,4 @@ impl<'tcx, 'mx> ArgAbiMethods<'tcx> for Builder<'_, 'tcx, 'mx> {
) {
todo!()
}

fn arg_memory_ty(&self, arg_abi: &ArgAbi<'tcx, Ty<'tcx>>) -> Self::Type {
todo!()
}
}
4 changes: 4 additions & 0 deletions crates/rustc_codegen_c/src/builder/debug_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ impl DebugInfoBuilderMethods for Builder<'_, '_, '_> {
fn set_var_name(&mut self, value: Self::Value, name: &str) {
todo!()
}

fn clear_dbg_loc(&mut self) {
todo!()
}
}
15 changes: 5 additions & 10 deletions crates/rustc_codegen_c/src/builder/intrinsic_call.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use rustc_codegen_ssa::mir::operand::OperandRef;
use rustc_codegen_ssa::traits::IntrinsicCallMethods;
use rustc_middle::ty::{Instance, Ty};
use rustc_target::abi::call::FnAbi;
use rustc_codegen_ssa::mir::place::PlaceRef;
use rustc_codegen_ssa::traits::IntrinsicCallBuilderMethods;
use rustc_middle::ty::Instance;

use crate::builder::Builder;

impl<'tcx, 'mx> IntrinsicCallMethods<'tcx> for Builder<'_, 'tcx, 'mx> {
impl<'tcx, 'mx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'tcx, 'mx> {
fn codegen_intrinsic_call(
&mut self,
instance: Instance<'tcx>,
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
args: &[OperandRef<'tcx, Self::Value>],
llresult: Self::Value,
llresult: PlaceRef<'tcx, Self::Value>,
span: rustc_span::Span,
) -> Result<(), Instance<'tcx>> {
todo!()
Expand All @@ -29,10 +28,6 @@ impl<'tcx, 'mx> IntrinsicCallMethods<'tcx> for Builder<'_, 'tcx, 'mx> {
todo!()
}

fn type_test(&mut self, pointer: Self::Value, typeid: Self::Value) -> Self::Value {
todo!()
}

fn type_checked_load(
&mut self,
llvtable: Self::Value,
Expand Down
18 changes: 10 additions & 8 deletions crates/rustc_codegen_c/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![allow(unused_variables)] // TODO

use rustc_middle::ty;
use rustc_middle::ty::layout::HasTypingEnv;
use std::cell::RefCell;

use rustc_abi::{HasDataLayout, TargetDataLayout};
Expand All @@ -10,11 +12,10 @@ use rustc_codegen_c_ast::ModuleCtx;
use rustc_codegen_ssa::traits::BackendTypes;
use rustc_hash::FxHashMap;
use rustc_middle::ty::layout::{
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, LayoutOfHelpers,
TyAndLayout,
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, LayoutError, LayoutOfHelpers, TyAndLayout,
};
use rustc_middle::ty::{Instance, ParamEnv, Ty, TyCtxt};
use rustc_target::abi::call::FnAbi;
use rustc_middle::ty::{Instance, Ty, TyCtxt};
use rustc_target::callconv::FnAbi;
use rustc_target::spec::{HasTargetSpec, Target};

mod asm;
Expand Down Expand Up @@ -48,6 +49,7 @@ impl<'tcx, 'mx> CodegenCx<'tcx, 'mx> {

impl<'tcx, 'mx> BackendTypes for CodegenCx<'tcx, 'mx> {
type Value = CValue<'mx>;
type Metadata = CValue<'mx>;
type Function = CFunc<'mx>;
type BasicBlock = CFunc<'mx>;
type Type = CTy<'mx>;
Expand All @@ -63,9 +65,9 @@ impl<'tcx, 'mx> HasTargetSpec for CodegenCx<'tcx, 'mx> {
}
}

impl<'tcx, 'mx> HasParamEnv<'tcx> for CodegenCx<'tcx, 'mx> {
fn param_env(&self) -> ParamEnv<'tcx> {
ParamEnv::reveal_all()
impl<'tcx, 'mx> HasTypingEnv<'tcx> for CodegenCx<'tcx, 'mx> {
fn typing_env(&self) -> ty::TypingEnv<'tcx> {
ty::TypingEnv::fully_monomorphized()
}
}

Expand All @@ -77,7 +79,7 @@ impl<'tcx, 'mx> HasTyCtxt<'tcx> for CodegenCx<'tcx, 'mx> {

impl<'tcx, 'mx> HasDataLayout for CodegenCx<'tcx, 'mx> {
fn data_layout(&self) -> &TargetDataLayout {
todo!()
&self.tcx.data_layout
}
}

Expand Down
Loading
Loading