Skip to content

Commit be75248

Browse files
committed
Move several DWARF constants into their own submodule
The main advantage of doing this is that we can apply a single `#![allow(non_upper_case_globals)]` to the whole module, though it's also helpful when manually checking values against LLVM or the DWARF spec.
1 parent 1891c28 commit be75248

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//! Definitions of various DWARF-related constants.
2+
//! These should agree with `llvm/include/llvm/BinaryFormat/Dwarf.def`.
3+
4+
#![allow(non_upper_case_globals)] // Allow names to match their LLVM equivalents
5+
6+
use libc::c_uint;
7+
8+
/// DWARF constant representing the Rust language. Introduced in DWARF 5.
9+
/// Defined by http://www.dwarfstd.org/ShowIssue.php?issue=140129.1.
10+
pub(crate) const DW_LANG_RUST: c_uint = 0x1c;
11+
12+
// DWARF attribute type encodings
13+
14+
pub(crate) const DW_ATE_boolean: c_uint = 0x02;
15+
pub(crate) const DW_ATE_float: c_uint = 0x04;
16+
pub(crate) const DW_ATE_signed: c_uint = 0x05;
17+
pub(crate) const DW_ATE_unsigned: c_uint = 0x07;
18+
pub(crate) const DW_ATE_UTF: c_uint = 0x10;

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+6-16
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,6 @@ impl fmt::Debug for llvm::Metadata {
5959
}
6060
}
6161

62-
// From DWARF 5.
63-
// See http://www.dwarfstd.org/ShowIssue.php?issue=140129.1.
64-
const DW_LANG_RUST: c_uint = 0x1c;
65-
#[allow(non_upper_case_globals)]
66-
const DW_ATE_boolean: c_uint = 0x02;
67-
#[allow(non_upper_case_globals)]
68-
const DW_ATE_float: c_uint = 0x04;
69-
#[allow(non_upper_case_globals)]
70-
const DW_ATE_signed: c_uint = 0x05;
71-
#[allow(non_upper_case_globals)]
72-
const DW_ATE_unsigned: c_uint = 0x07;
73-
#[allow(non_upper_case_globals)]
74-
const DW_ATE_UTF: c_uint = 0x10;
75-
7662
pub(super) const UNKNOWN_LINE_NUMBER: c_uint = 0;
7763
pub(super) const UNKNOWN_COLUMN_NUMBER: c_uint = 0;
7864

@@ -89,6 +75,8 @@ mod type_map;
8975

9076
pub(crate) use type_map::TypeMap;
9177

78+
use crate::debuginfo::dwarf_const;
79+
9280
/// Returns from the enclosing function if the type debuginfo node with the given
9381
/// unique ID can be found in the type map.
9482
macro_rules! return_if_di_node_created_in_meantime {
@@ -519,7 +507,7 @@ fn recursion_marker_type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) -> &'ll D
519507
name.as_c_char_ptr(),
520508
name.len(),
521509
cx.tcx.data_layout.pointer_size.bits(),
522-
DW_ATE_unsigned,
510+
dwarf_const::DW_ATE_unsigned,
523511
)
524512
}
525513
})
@@ -778,6 +766,8 @@ fn build_basic_type_di_node<'ll, 'tcx>(
778766
// .natvis visualizers (and perhaps other existing native debuggers?)
779767
let cpp_like_debuginfo = cpp_like_debuginfo(cx.tcx);
780768

769+
use dwarf_const::{DW_ATE_UTF, DW_ATE_boolean, DW_ATE_float, DW_ATE_signed, DW_ATE_unsigned};
770+
781771
let (name, encoding) = match t.kind() {
782772
ty::Never => ("!", DW_ATE_unsigned),
783773
ty::Tuple(elements) if elements.is_empty() => {
@@ -958,7 +948,7 @@ pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>(
958948

959949
let unit_metadata = llvm::LLVMRustDIBuilderCreateCompileUnit(
960950
debug_context.builder,
961-
DW_LANG_RUST,
951+
dwarf_const::DW_LANG_RUST,
962952
compile_unit_file,
963953
producer.as_c_char_ptr(),
964954
producer.len(),

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use crate::llvm::debuginfo::{
3939
use crate::value::Value;
4040

4141
mod create_scope_map;
42+
mod dwarf_const;
4243
mod gdb;
4344
pub(crate) mod metadata;
4445
mod namespace;

0 commit comments

Comments
 (0)