Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c869907

Browse files
committed
Document almost all modules
Fixes rust-lang#1082
1 parent 934d56a commit c869907

36 files changed

+145
-66
lines changed

src/abi/comments.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Annotate the clif ir with comments describing how arguments are passed into the current function
2+
//! and where all locals are stored.
3+
14
use std::borrow::Cow;
25

36
use rustc_middle::mir;

src/abi/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Handling of everything related to the calling convention. Also fills `fx.local_map`.
2+
13
#[cfg(debug_assertions)]
24
mod comments;
35
mod pass_mode;
@@ -325,6 +327,7 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
325327
}
326328
}
327329

330+
/// Make a [`CPlace`] capable of holding value of the specified type.
328331
fn make_local_place<'tcx>(
329332
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
330333
local: Local,

src/abi/pass_mode.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Argument passing
2+
13
use crate::prelude::*;
24

35
pub(super) use EmptySinglePair::*;
@@ -118,6 +120,7 @@ pub(super) fn get_pass_mode<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>)
118120
}
119121
}
120122

123+
/// Get a set of values to be passed as function arguments.
121124
pub(super) fn adjust_arg_for_abi<'tcx>(
122125
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
123126
arg: CValue<'tcx>,
@@ -136,6 +139,8 @@ pub(super) fn adjust_arg_for_abi<'tcx>(
136139
}
137140
}
138141

142+
/// Create a [`CValue`] containing the value of a function parameter adding clif function parameters
143+
/// as necessary.
139144
pub(super) fn cvalue_for_param<'tcx>(
140145
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
141146
start_block: Block,

src/abi/returning.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
//! Return value handling
2+
13
use crate::abi::pass_mode::*;
24
use crate::prelude::*;
35

46
fn return_layout<'a, 'tcx>(fx: &mut FunctionCx<'a, 'tcx, impl Backend>) -> TyAndLayout<'tcx> {
57
fx.layout_of(fx.monomorphize(&fx.mir.local_decls[RETURN_PLACE].ty))
68
}
79

10+
/// Can the given type be returned into an ssa var or does it need to be returned on the stack.
811
pub(crate) fn can_return_to_ssa_var<'tcx>(
912
tcx: TyCtxt<'tcx>,
1013
dest_layout: TyAndLayout<'tcx>,
@@ -16,6 +19,8 @@ pub(crate) fn can_return_to_ssa_var<'tcx>(
1619
}
1720
}
1821

22+
/// Return a place where the return value of the current function can be written to. If necessary
23+
/// this adds an extra parameter pointing to where the return value needs to be stored.
1924
pub(super) fn codegen_return_param<'tcx>(
2025
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
2126
ssa_analyzed: &rustc_index::vec::IndexVec<Local, crate::analyze::SsaKind>,
@@ -59,6 +64,8 @@ pub(super) fn codegen_return_param<'tcx>(
5964
ret_place
6065
}
6166

67+
/// Invokes the closure with if necessary a value representing the return pointer. When the closure
68+
/// returns the call return value(s) if any are written to the correct place.
6269
pub(super) fn codegen_with_call_return_arg<'tcx, B: Backend, T>(
6370
fx: &mut FunctionCx<'_, 'tcx, B>,
6471
fn_sig: FnSig<'tcx>,
@@ -102,6 +109,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx, B: Backend, T>(
102109
(call_inst, meta)
103110
}
104111

112+
/// Codegen a return instruction with the right return value(s) if any.
105113
pub(crate) fn codegen_return(fx: &mut FunctionCx<'_, '_, impl Backend>) {
106114
match get_pass_mode(fx.tcx, return_layout(fx)) {
107115
PassMode::NoPass | PassMode::ByRef { size: Some(_) } => {

src/allocator.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution and at
3-
// http://rust-lang.org/COPYRIGHT.
4-
//
5-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8-
// option. This file may not be copied, modified, or distributed
9-
// except according to those terms.
1+
//! Allocator shim
2+
// Adapted from rustc
103

114
use crate::prelude::*;
125

src/analyze.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! SSA analysis
2+
13
use crate::prelude::*;
24

35
use rustc_index::vec::IndexVec;

src/archive.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Creation of ar archives like for the lib and staticlib crate type
2+
13
use std::collections::BTreeMap;
24
use std::fs::File;
35
use std::path::{Path, PathBuf};

src/backend.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Abstraction around the object writing crate
2+
13
use std::convert::{TryFrom, TryInto};
24

35
use rustc_data_structures::fx::FxHashMap;

src/base.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Codegen of a single function
2+
13
use rustc_index::vec::IndexVec;
24
use rustc_middle::ty::adjustment::PointerCast;
35

src/cast.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Various number casting functions
2+
13
use crate::prelude::*;
24

35
pub(crate) fn clif_intcast(

src/codegen_i128.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Replaces 128-bit operators with lang item calls
1+
//! Replaces 128-bit operators with lang item calls where necessary
22
33
use crate::prelude::*;
44

src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ pub(crate) struct FunctionCx<'clif, 'tcx, B: Backend + 'static> {
302302
/// When `#[track_caller]` is used, the implicit caller location is stored in this variable.
303303
pub(crate) caller_location: Option<CValue<'tcx>>,
304304

305-
/// See [crate::optimize::code_layout] for more information.
305+
/// See [`crate::optimize::code_layout`] for more information.
306306
pub(crate) cold_blocks: EntitySet<Block>,
307307

308308
pub(crate) clif_comments: crate::pretty_clif::CommentWriter,

src/constant.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Handling of `static`s, `const`s and promoted allocations
2+
13
use rustc_span::DUMMY_SP;
24

35
use rustc_data_structures::fx::FxHashSet;

src/debuginfo/emit.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Write the debuginfo into an object file.
2+
13
use rustc_data_structures::fx::FxHashMap;
24

35
use gimli::write::{Address, AttributeValue, EndianVec, Result, Sections, Writer};
@@ -55,6 +57,7 @@ pub(crate) enum DebugRelocName {
5557
Symbol(usize),
5658
}
5759

60+
/// A [`Writer`] that collects all necessary relocations.
5861
#[derive(Clone)]
5962
pub(super) struct WriterRelocate {
6063
pub(super) relocs: Vec<DebugReloc>,
@@ -69,6 +72,7 @@ impl WriterRelocate {
6972
}
7073
}
7174

75+
/// Perform the collected relocations to be usable for JIT usage.
7276
#[cfg(feature = "jit")]
7377
pub(super) fn relocate_for_jit(
7478
mut self,

src/debuginfo/line_info.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Line info generation (`.debug_line`)
2+
13
use std::ffi::OsStr;
24
use std::path::{Component, Path};
35

src/debuginfo/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Handling of everything related to debuginfo.
2+
13
mod emit;
24
mod line_info;
35
mod unwind;

src/debuginfo/unwind.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Unwind info generation (`.eh_frame`)
2+
13
use crate::prelude::*;
24

35
use cranelift_codegen::isa::{unwind::UnwindInfo, TargetIsa};

src/discriminant.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Handling of enum discriminants
2+
//!
13
//! Adapted from https://github.com/rust-lang/rust/blob/d760df5aea483aae041c9a241e7acacf48f75035/src/librustc_codegen_ssa/mir/place.rs
24
35
use rustc_target::abi::{Int, TagEncoding, Variants};

src/driver/aot.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! The AOT driver uses [`cranelift_object`] to write object files suitable for linking into a
2+
//! standalone executable.
3+
14
use std::path::PathBuf;
25

36
use rustc_codegen_ssa::back::linker::LinkerInfo;

src/driver/jit.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! The JIT driver uses [`cranelift_simplejit`] to JIT execute programs without writing any object
2+
//! files.
3+
14
use std::ffi::CString;
25
use std::os::raw::{c_char, c_int};
36

src/driver/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Drivers are responsible for calling [`codegen_mono_items`] and performing any further actions
2+
//! like JIT executing or writing object files.
3+
14
use std::any::Any;
25

36
use rustc_middle::middle::cstore::EncodedMetadata;

src/inline_asm.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Codegen of [`asm!`] invocations.
2+
13
use crate::prelude::*;
24

35
use std::fmt::Write;

src/intrinsics/cpuid.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
//! Emulation of a subset of the cpuid x86 instruction.
2+
13
use crate::prelude::*;
24

3-
/// Emulates a subset of the cpuid call.
5+
/// Emulates a subset of the cpuid x86 instruction.
46
///
57
/// This emulates an intel cpu with sse and sse2 support, but which doesn't support anything else.
68
pub(crate) fn codegen_cpuid_call<'tcx>(

src/intrinsics/llvm.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Emulate LLVM intrinsics
2+
13
use crate::intrinsics::*;
24
use crate::prelude::*;
35

src/intrinsics/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Codegen of intrinsics. This includes `extern "rust-intrinsic"`, `extern "platform-intrinsic"`
2+
//! and LLVM intrinsics that have symbol names starting with `llvm.`.
3+
14
mod cpuid;
25
mod llvm;
36
mod simd;

src/intrinsics/simd.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Codegen `extern "platform-intrinsic"` intrinsics.
2+
13
use super::*;
24
use crate::prelude::*;
35

src/metadata.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Reading and writing of the rustc metadata for rlibs and dylibs
2+
13
use std::convert::TryFrom;
24
use std::fs::File;
35
use std::path::Path;

src/num.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Various operations on integer and floating-point numbers
2+
13
use crate::prelude::*;
24

35
pub(crate) fn bin_op_to_intcc(bin_op: BinOp, signed: bool) -> Option<IntCC> {

src/optimize/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Various optimizations specific to cg_clif
2+
13
use crate::prelude::*;
24

35
mod code_layout;

src/pointer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
//! Defines [`Pointer`] which is used to improve the quality of the generated clif ir for pointer
2+
//! operations.
3+
14
use crate::prelude::*;
25

36
use rustc_target::abi::Align;
47

58
use cranelift_codegen::ir::immediates::Offset32;
69

10+
/// A pointer pointing either to a certain address, a certain stack slot or nothing.
711
#[derive(Copy, Clone, Debug)]
812
pub(crate) struct Pointer {
913
base: PointerBase,

0 commit comments

Comments
 (0)