1 //! Cranelift code generation library.
2 #![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)]
3 #![warn(unused_import_braces)]
4 #![cfg_attr(feature = "std", deny(unstable_features))]
5 #![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))]
6 #![cfg_attr(feature="cargo-clippy", allow(
7 // Produces only a false positive:
8                 clippy::while_let_loop,
9 // Produces many false positives, but did produce some valid lints, now fixed:
10                 clippy::needless_lifetimes,
11 // Generated code makes some style transgressions, but readability doesn't suffer much:
12                 clippy::many_single_char_names,
13                 clippy::identity_op,
14                 clippy::needless_borrow,
15                 clippy::cast_lossless,
16                 clippy::unreadable_literal,
17                 clippy::assign_op_pattern,
18                 clippy::empty_line_after_outer_attr,
19 // Hard to avoid in generated code:
20                 clippy::cognitive_complexity,
21                 clippy::too_many_arguments,
22 // Code generator doesn't have a way to collapse identical arms:
23                 clippy::match_same_arms,
24 // These are relatively minor style issues, but would be easy to fix:
25                 clippy::new_without_default,
26                 clippy::should_implement_trait,
27                 clippy::len_without_is_empty))]
28 #![cfg_attr(
29     feature = "cargo-clippy",
30     warn(
31         clippy::float_arithmetic,
32         clippy::mut_mut,
33         clippy::nonminimal_bool,
34         clippy::map_unwrap_or,
35         clippy::unicode_not_nfc,
36         clippy::use_self
37     )
38 )]
39 #![no_std]
40 // Various bits and pieces of this crate might only be used for one platform or
41 // another, but it's not really too useful to learn about that all the time. On
42 // CI we build at least one version of this crate with `--features all-arch`
43 // which means we'll always detect truly dead code, otherwise if this is only
44 // built for one platform we don't have to worry too much about trimming
45 // everything down.
46 #![cfg_attr(not(feature = "all-arch"), allow(dead_code))]
47 
48 #[allow(unused_imports)] // #[macro_use] is required for no_std
49 #[macro_use]
50 extern crate alloc;
51 
52 #[cfg(feature = "std")]
53 #[macro_use]
54 extern crate std;
55 
56 #[cfg(not(feature = "std"))]
57 use hashbrown::{hash_map, HashMap, HashSet};
58 #[cfg(feature = "std")]
59 use std::collections::{hash_map, HashMap, HashSet};
60 
61 pub use crate::context::Context;
62 pub use crate::value_label::{LabelValueLoc, ValueLabelsRanges, ValueLocRange};
63 pub use crate::verifier::verify_function;
64 pub use crate::write::write_function;
65 
66 pub use cranelift_bforest as bforest;
67 pub use cranelift_control as control;
68 pub use cranelift_entity as entity;
69 #[cfg(feature = "unwind")]
70 pub use gimli;
71 
72 #[macro_use]
73 mod machinst;
74 
75 pub mod binemit;
76 pub mod cfg_printer;
77 pub mod cursor;
78 pub mod data_value;
79 pub mod dbg;
80 pub mod dominator_tree;
81 pub mod flowgraph;
82 pub mod ir;
83 pub mod isa;
84 pub mod loop_analysis;
85 pub mod print_errors;
86 pub mod settings;
87 pub mod timing;
88 pub mod verifier;
89 pub mod write;
90 
91 pub use crate::entity::packed_option;
92 pub use crate::machinst::buffer::{
93     MachCallSite, MachReloc, MachSrcLoc, MachStackMap, MachTextSectionBuilder, MachTrap,
94 };
95 pub use crate::machinst::{
96     CompiledCode, Final, MachBuffer, MachBufferFinalized, MachInst, MachInstEmit,
97     MachInstEmitState, MachLabel, Reg, TextSectionBuilder, Writable,
98 };
99 
100 mod alias_analysis;
101 mod bitset;
102 mod constant_hash;
103 mod context;
104 mod ctxhash;
105 mod dce;
106 mod egraph;
107 mod fx;
108 mod inst_predicates;
109 mod isle_prelude;
110 mod iterators;
111 mod legalizer;
112 mod nan_canonicalization;
113 mod opts;
114 mod remove_constant_phis;
115 mod result;
116 mod scoped_hash_map;
117 mod unionfind;
118 mod unreachable_code;
119 mod value_label;
120 
121 #[cfg(feature = "souper-harvest")]
122 mod souper_harvest;
123 
124 pub use crate::result::{CodegenError, CodegenResult, CompileError};
125 
126 #[cfg(feature = "incremental-cache")]
127 pub mod incremental_cache;
128 
129 /// Even when trace logging is disabled, the trace macro has a significant performance cost so we
130 /// disable it by default.
131 #[macro_export]
132 macro_rules! trace {
133     ($($tt:tt)*) => {
134         if cfg!(feature = "trace-log") {
135             ::log::trace!($($tt)*);
136         }
137     };
138 }
139 
140 include!(concat!(env!("OUT_DIR"), "/version.rs"));
141