Add docs and expand some wildcard patterns

This commit is contained in:
bjorn3 2018-07-18 11:55:32 +02:00
parent af3234cfd7
commit d0ef7f455c
3 changed files with 58 additions and 6 deletions

38
Readme.md Normal file
View File

@ -0,0 +1,38 @@
# Work in progress cranelift codegen backend for rust
> ⚠⚠⚠ This doesn't do anything useful yet ⚠⚠⚠
## Building
```bash
$ git clone https://github.com/bjorn3/rustc_codegen_cranelift
$ cd rustc_codegen_cranelift
$ git submodule update --init
$ cargo build
```
## Usage
```bash
$ rustc -Zcodegen-backend=$(pwd)/target/debug/librustc_codegen_cranelift.so my_crate.rs --crate-type lib -Og
```
> You must compile with `-Og`, because checked binops are not yet supported.
## Not yet supported
* [ ] Checked binops
* [ ] Statics
* [ ] Drop glue
* [ ] Ints cast
* [ ] Building libraries
* [ ] Other call abi's
* [ ] Unsized types
* [ ] Slice indexing
* [ ] Sub slice
* [ ] Closures
* [ ] Some rvalue's
* [ ] Inline assembly
* [ ] Custom sections

View File

@ -55,7 +55,9 @@ pub fn trans_mono_item<'a, 'tcx: 'a>(cx: &mut CodegenCx<'a, 'tcx, CurrentBackend
}
inst => cx.tcx.sess.warn(&format!("Unimplemented instance {:?}", inst)),
}
mono_item => cx.tcx.sess.warn(&format!("Unimplemented mono item {:?}", mono_item)),
MonoItem::Static(def_id) => cx.tcx.sess.err(&format!("Unimplemented static mono item {:?}", def_id)),
MonoItem::GlobalAsm(node_id) => cx.tcx.sess.err(&format!("Unimplemented global asm mono item {:?}", node_id)),
MonoItem::CustomSection(def_id) => cx.tcx.sess.err(&format!("Unimplemented custom section mono item {:?}", def_id)),
}
}
@ -367,6 +369,9 @@ fn trans_stmt<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, stmt: &Statement<'tcx
let layout = fx.layout_of(ty);
lval.write_cvalue(fx, operand.unchecked_cast_to(layout));
}
Rvalue::Cast(CastKind::Misc, operand, ty) => unimplemented!("rval misc {:?} {:?}", operand, ty),
Rvalue::Cast(CastKind::ClosureFnPointer, operand, ty) => unimplemented!("rval closure_fn_ptr {:?} {:?}", operand, ty),
Rvalue::Cast(CastKind::Unsize, operand, ty) => unimplemented!("rval unsize {:?} {:?}", operand, ty),
Rvalue::Discriminant(place) => {
let place = trans_place(fx, place);
let dest_cton_ty = fx.cton_type(dest_layout.ty).unwrap();
@ -428,13 +433,17 @@ fn trans_stmt<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, stmt: &Statement<'tcx
}
}
}
rval => unimplemented!("rval {:?}", rval),
Rvalue::Repeat(operand, times) => unimplemented!("rval repeat {:?} {:?}", operand, times),
Rvalue::Len(lval) => unimplemented!("rval len {:?}", lval),
Rvalue::NullaryOp(NullOp::Box, ty) => unimplemented!("rval box {:?}", ty),
Rvalue::NullaryOp(NullOp::SizeOf, ty) => unimplemented!("rval size_of {:?}", ty),
Rvalue::Aggregate(_, _) => bug!("shouldn't exist at trans {:?}", rval),
}
}
StatementKind::StorageLive(_) | StatementKind::StorageDead(_) | StatementKind::Nop => {
StatementKind::StorageLive(_) | StatementKind::StorageDead(_) | StatementKind::Nop | StatementKind::ReadForMatch(_) | StatementKind::Validate(_, _) | StatementKind::EndRegion(_) | StatementKind::UserAssertTy(_, _) => {
fx.bcx.ins().nop();
}
_ => unimplemented!("stmt {:?}", stmt),
StatementKind::InlineAsm { .. } => fx.tcx.sess.fatal("Inline assembly is not supported"),
}
let inst = fx.bcx.func.layout.next_inst(nop_inst).unwrap();
@ -481,6 +490,7 @@ fn trans_int_binop<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, bin_op: BinOp, l
fn trans_place<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, place: &Place<'tcx>) -> CPlace<'tcx> {
match place {
Place::Local(local) => fx.get_local_place(*local),
Place::Static(static_) => unimplemented!("static place {:?} ty {:?}", static_.def_id, static_.ty),
Place::Projection(projection) => {
let base = trans_place(fx, &projection.base);
match projection.elem {
@ -490,13 +500,15 @@ fn trans_place<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, place: &Place<'tcx>)
ProjectionElem::Field(field, _ty) => {
base.place_field(fx, field)
}
ProjectionElem::Index(local) => unimplemented!("projection index {:?} {:?}", projection.base, local),
ProjectionElem::ConstantIndex { offset, min_length: _, from_end: false } => unimplemented!("projection const index {:?} offset {:?} not from end", projection.base, offset),
ProjectionElem::ConstantIndex { offset, min_length: _, from_end: true } => unimplemented!("projection const index {:?} offset {:?} from end", projection.base, offset),
ProjectionElem::Subslice { from, to } => unimplemented!("projection subslice {:?} from {} to {}", projection.base, from, to),
ProjectionElem::Downcast(_adt_def, variant) => {
base.downcast_variant(fx, variant)
}
_ => unimplemented!("projection {:?}", projection),
}
}
place => unimplemented!("place {:?}", place),
}
}

View File

@ -61,6 +61,7 @@ fn cton_type_from_ty<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) ->
})
}
/// A read-only value
#[derive(Debug, Copy, Clone)]
pub enum CValue<'tcx> {
ByRef(Value, TyLayout<'tcx>),
@ -158,6 +159,7 @@ impl<'tcx> CValue<'tcx> {
}
}
/// A place where you can write a value to or read a value from
#[derive(Debug, Copy, Clone)]
pub enum CPlace<'tcx> {
Var(Variable, TyLayout<'tcx>),