Skip to content

Commit d9fcdae

Browse files
authored
Refactor folder structure (#425)
* Created mir_to_goto folder, moved monomorphize into it * moved metadata files into metadata folder * moved codegen files to codegen folder * moved stubs and hooks to mir_to_goto * moved the final files into mir_to_goto * Comments * suppress warnings * added missing file * rename metadata as per PR comments * Remove pub modifier on modules that don't need it * Moved tuple_fld so that typ can be private mod * removed pub mod from stubs * moved overrides into their own folder * moved assumptions into codegen * utils folder * init debug properly * renamed backend to compiler_interface * gotoCtx should just take a MIR context at construction time * move more stuff out of utils to where it goes * names get their own util * better import in hooks
1 parent e997f75 commit d9fcdae

File tree

31 files changed

+396
-297
lines changed

31 files changed

+396
-297
lines changed

compiler/rustc_codegen_llvm/src/gotoc/assumptions.rs renamed to compiler/rustc_codegen_llvm/src/gotoc/mir_to_goto/codegen/assumptions.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33
//! this module defines functions which impose data invariant on generated data types.
44
5-
use super::cbmc::goto_program::{Expr, Location, Stmt, Symbol, Type};
6-
use super::metadata::GotocCtx;
7-
use crate::gotoc::typ::tuple_fld;
5+
use crate::gotoc::cbmc::goto_program::{Expr, Location, Stmt, Symbol, Type};
6+
use crate::gotoc::mir_to_goto::GotocCtx;
87
use rustc_middle::mir::interpret::{ConstValue, Scalar};
98
use rustc_middle::ty;
109
use rustc_middle::ty::ScalarInt;
@@ -559,7 +558,7 @@ impl<'tcx> GotocCtx<'tcx> {
559558
let field = ptr
560559
.clone()
561560
.dereference()
562-
.member(&tuple_fld(i), &tcx.symbol_table) // x->i
561+
.member(&Self::tuple_fld_name(i), &tcx.symbol_table) // x->i
563562
.address_of(); // &(x->i)
564563
invariants.push(f.call(vec![field]));
565564
}

compiler/rustc_codegen_llvm/src/gotoc/block.rs renamed to compiler/rustc_codegen_llvm/src/gotoc/mir_to_goto/codegen/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
//! This file contains functions related to codegenning MIR blocks into gotoc
55
6-
use super::metadata::*;
6+
use crate::gotoc::mir_to_goto::GotocCtx;
77
use rustc_middle::mir::{BasicBlock, BasicBlockData};
88

99
impl<'tcx> GotocCtx<'tcx> {

compiler/rustc_codegen_llvm/src/gotoc/function.rs renamed to compiler/rustc_codegen_llvm/src/gotoc/mir_to_goto/codegen/function.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
//! This file contains functions related to codegenning MIR functions into gotoc
55
6-
use super::cbmc::goto_program::{Expr, Stmt, Symbol};
7-
use super::metadata::*;
6+
use crate::gotoc::cbmc::goto_program::{Expr, Stmt, Symbol};
7+
use crate::gotoc::mir_to_goto::GotocCtx;
88
use rustc_middle::mir::{HasLocalDecls, Local};
99
use rustc_middle::ty::{self, Instance, TyS};
1010
use tracing::{debug, warn};

compiler/rustc_codegen_llvm/src/gotoc/intrinsic.rs renamed to compiler/rustc_codegen_llvm/src/gotoc/mir_to_goto/codegen/intrinsic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
//! this module handles intrinsics
44
use tracing::{debug, warn};
55

6-
use super::cbmc::goto_program::{BuiltinFn, Expr, Location, Stmt, Type};
7-
use super::metadata::GotocCtx;
6+
use crate::gotoc::cbmc::goto_program::{BuiltinFn, Expr, Location, Stmt, Type};
7+
use crate::gotoc::mir_to_goto::GotocCtx;
88
use rustc_middle::mir::Place;
99
use rustc_middle::ty::Instance;
1010
use rustc_middle::ty::{self, Ty, TyS};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
//! This module does that actual translation of MIR constructs to goto constructs.
5+
//! Each subfile is named for the MIR construct it translates.
6+
7+
mod assumptions;
8+
mod block;
9+
mod function;
10+
mod intrinsic;
11+
mod operand;
12+
mod place;
13+
mod rvalue;
14+
mod span;
15+
mod statement;
16+
mod static_var;
17+
mod typ;

compiler/rustc_codegen_llvm/src/gotoc/operand.rs renamed to compiler/rustc_codegen_llvm/src/gotoc/mir_to_goto/codegen/operand.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
3-
use super::cbmc::goto_program::{Expr, Location, Stmt, Symbol, Type};
4-
use super::metadata::*;
5-
use super::utils::slice_fat_ptr;
3+
use crate::gotoc::cbmc::goto_program::{Expr, Location, Stmt, Symbol, Type};
4+
use crate::gotoc::mir_to_goto::utils::slice_fat_ptr;
5+
use crate::gotoc::mir_to_goto::GotocCtx;
66
use rustc_ast::ast::Mutability;
77
use rustc_hir::def_id::LOCAL_CRATE;
88
use rustc_middle::mir::interpret::{

compiler/rustc_codegen_llvm/src/gotoc/place.rs renamed to compiler/rustc_codegen_llvm/src/gotoc/mir_to_goto/codegen/place.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
//! a place is an expression of specifying a location in memory, like a left value. check the cases
66
//! in [codegen_place] below.
77
8-
use super::cbmc::goto_program::{Expr, Type};
9-
use super::metadata::*;
10-
use super::typ::tuple_fld;
8+
use crate::gotoc::cbmc::goto_program::{Expr, Type};
9+
use crate::gotoc::mir_to_goto::GotocCtx;
1110
use rustc_middle::{
1211
mir::{Field, Local, Place, ProjectionElem},
1312
ty::{self, Ty, TyS, VariantDef},
@@ -41,10 +40,12 @@ pub struct ProjectedPlace<'tcx> {
4140
}
4241

4342
/// Getters
43+
#[allow(dead_code)]
4444
impl<'tcx> ProjectedPlace<'tcx> {
4545
pub fn goto_expr(&self) -> &Expr {
4646
&self.goto_expr
4747
}
48+
4849
pub fn mir_typ_or_variant(&self) -> &TypeOrVariant<'tcx> {
4950
&self.mir_typ_or_variant
5051
}
@@ -56,6 +57,7 @@ impl<'tcx> ProjectedPlace<'tcx> {
5657
pub fn fat_ptr_goto_expr(&self) -> &Option<Expr> {
5758
&self.fat_ptr_goto_expr
5859
}
60+
5961
pub fn fat_ptr_mir_typ(&self) -> &Option<Ty<'tcx>> {
6062
&self.fat_ptr_mir_typ
6163
}
@@ -137,6 +139,7 @@ impl<'tcx> TypeOrVariant<'tcx> {
137139
}
138140
}
139141

142+
#[allow(dead_code)]
140143
pub fn expect_variant(&self) -> &'tcx VariantDef {
141144
match self {
142145
TypeOrVariant::Type(t) => panic!("expect a variant but type is found: {:?}", t),
@@ -168,7 +171,9 @@ impl<'tcx> GotocCtx<'tcx> {
168171
| ty::Param(_)
169172
| ty::Infer(_)
170173
| ty::Error(_) => unreachable!("type {:?} does not have a field", t),
171-
ty::Tuple(_) => res.member(&tuple_fld(f.index()), &self.symbol_table),
174+
ty::Tuple(_) => {
175+
res.member(&Self::tuple_fld_name(f.index()), &self.symbol_table)
176+
}
172177
ty::Adt(def, _) if def.repr.simd() => {
173178
// this is a SIMD vector - the index represents one
174179
// of the elements, so we want to index as an array

compiler/rustc_codegen_llvm/src/gotoc/rvalue.rs renamed to compiler/rustc_codegen_llvm/src/gotoc/mir_to_goto/codegen/rvalue.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
3-
use super::cbmc::goto_program::{BuiltinFn, Expr, Location, Stmt, Symbol, Type};
4-
use super::cbmc::utils::{aggr_name, BUG_REPORT_URL};
5-
use super::cbmc::MachineModel;
6-
use super::metadata::*;
73
use super::typ::{is_pointer, pointee_type};
8-
use super::utils::{dynamic_fat_ptr, slice_fat_ptr};
94
use crate::btree_string_map;
5+
use crate::gotoc::cbmc::goto_program::{BuiltinFn, Expr, Location, Stmt, Symbol, Type};
6+
use crate::gotoc::cbmc::utils::{aggr_name, BUG_REPORT_URL};
7+
use crate::gotoc::cbmc::MachineModel;
8+
use crate::gotoc::mir_to_goto::utils::{dynamic_fat_ptr, slice_fat_ptr};
9+
use crate::gotoc::mir_to_goto::GotocCtx;
1010
use num::bigint::BigInt;
1111
use rustc_middle::mir::{AggregateKind, BinOp, CastKind, NullOp, Operand, Place, Rvalue, UnOp};
1212
use rustc_middle::ty::adjustment::PointerCast;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
//! MIR Span related functions
5+
6+
use crate::gotoc::cbmc::goto_program::Location;
7+
use crate::gotoc::mir_to_goto::GotocCtx;
8+
use rustc_middle::mir::{Local, VarDebugInfo, VarDebugInfoContents};
9+
use rustc_span::Span;
10+
11+
impl<'tcx> GotocCtx<'tcx> {
12+
pub fn find_debug_info(&self, l: &Local) -> Option<&VarDebugInfo<'tcx>> {
13+
self.current_fn().mir().var_debug_info.iter().find(|info| match info.value {
14+
VarDebugInfoContents::Place(p) => p.local == *l && p.projection.len() == 0,
15+
VarDebugInfoContents::Const(_) => false,
16+
})
17+
}
18+
19+
//TODO fix this name
20+
pub fn codegen_span_option2(&self, sp: Option<Span>) -> Location {
21+
sp.map_or(Location::none(), |x| self.codegen_span2(&x))
22+
}
23+
24+
//TODO fix this name
25+
pub fn codegen_span2(&self, sp: &Span) -> Location {
26+
let smap = self.tcx.sess.source_map();
27+
let lo = smap.lookup_char_pos(sp.lo());
28+
let line = lo.line;
29+
let col = 1 + lo.col_display;
30+
let filename0 = lo.file.name.prefer_remapped().to_string_lossy().to_string();
31+
let filename1 = match std::fs::canonicalize(filename0.clone()) {
32+
Ok(pathbuf) => pathbuf.to_str().unwrap().to_string(),
33+
Err(_) => filename0,
34+
};
35+
Location::new(filename1, self.current_fn.as_ref().map(|x| x.name()), line, Some(col))
36+
}
37+
}

compiler/rustc_codegen_llvm/src/gotoc/statement.rs renamed to compiler/rustc_codegen_llvm/src/gotoc/mir_to_goto/codegen/statement.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
3-
use super::cbmc::goto_program::{BuiltinFn, Expr, Location, Stmt, Type};
4-
use super::metadata::*;
53
use super::typ::FN_RETURN_VOID_VAR_NAME;
4+
use crate::gotoc::cbmc::goto_program::{BuiltinFn, Expr, Location, Stmt, Type};
5+
use crate::gotoc::mir_to_goto::GotocCtx;
66
use rustc_hir::def_id::DefId;
77
use rustc_middle::mir;
88
use rustc_middle::mir::{

0 commit comments

Comments
 (0)