1 //! Cranelift code generation library.
2 #![deny(missing_docs)]
3 // Display feature requirements in the documentation when building on docs.rs
4 #![cfg_attr(docsrs, feature(doc_cfg))]
5 #![no_std]
6 // Various bits and pieces of this crate might only be used for one platform or
7 // another, but it's not really too useful to learn about that all the time. On
8 // CI we build at least one version of this crate with `--features all-arch`
9 // which means we'll always detect truly dead code, otherwise if this is only
10 // built for one platform we don't have to worry too much about trimming
11 // everything down.
12 #![cfg_attr(
13     not(feature = "all-arch"),
14     allow(dead_code, reason = "see comment above")
15 )]
16 
17 extern crate alloc;
18 
19 #[cfg(feature = "std")]
20 #[macro_use]
21 extern crate std;
22 
23 #[cfg(not(feature = "std"))]
24 use hashbrown::{HashMap, HashSet, hash_map};
25 #[cfg(feature = "std")]
26 use std::collections::{HashMap, hash_map};
27 
28 pub use crate::context::Context;
29 pub use crate::value_label::{LabelValueLoc, ValueLabelsRanges, ValueLocRange};
30 pub use crate::verifier::verify_function;
31 pub use crate::write::write_function;
32 
33 pub use cranelift_bforest as bforest;
34 pub use cranelift_bitset as bitset;
35 pub use cranelift_control as control;
36 pub use cranelift_entity as entity;
37 #[cfg(feature = "unwind")]
38 pub use gimli;
39 
40 // Pull in generated the `isle_numerics_methods` macro.
41 include!(concat!(env!("ISLE_DIR"), "/isle_numerics.rs"));
42 
43 #[macro_use]
44 mod machinst;
45 
46 pub mod binemit;
47 pub mod cfg_printer;
48 pub mod cursor;
49 pub mod data_value;
50 pub mod dbg;
51 pub mod dominator_tree;
52 pub mod flowgraph;
53 pub mod inline;
54 pub mod ir;
55 pub mod isa;
56 pub mod loop_analysis;
57 pub mod print_errors;
58 pub mod settings;
59 pub mod timing;
60 pub mod traversals;
61 pub mod verifier;
62 pub mod write;
63 
64 pub use crate::entity::packed_option;
65 pub use crate::machinst::buffer::{
66     ExceptionContextLoc, FinalizedMachCallSite, FinalizedMachExceptionHandler, FinalizedMachReloc,
67     FinalizedRelocTarget, MachCallSite, MachSrcLoc, MachTextSectionBuilder, MachTrap,
68     OpenPatchRegion, PatchRegion,
69 };
70 pub use crate::machinst::{
71     CallInfo, CompiledCode, Final, MachBuffer, MachBufferDebugTagList, MachBufferFinalized,
72     MachBufferFrameLayout, MachDebugTagPos, MachInst, MachInstEmit, MachInstEmitState, MachLabel,
73     RealReg, Reg, RelocDistance, TextSectionBuilder, VCodeConstant, VCodeConstantData,
74     VCodeConstants, VCodeInst, Writable,
75 };
76 
77 mod alias_analysis;
78 mod constant_hash;
79 mod context;
80 mod ctxhash;
81 mod egraph;
82 mod inst_predicates;
83 mod isle_prelude;
84 mod legalizer;
85 mod nan_canonicalization;
86 mod opts;
87 mod ranges;
88 mod remove_constant_phis;
89 mod result;
90 mod scoped_hash_map;
91 mod take_and_replace;
92 mod unreachable_code;
93 mod value_label;
94 
95 #[cfg(feature = "souper-harvest")]
96 mod souper_harvest;
97 
98 pub use crate::result::{CodegenError, CodegenResult, CompileError};
99 pub use crate::take_and_replace::TakeAndReplace;
100 
101 #[cfg(feature = "incremental-cache")]
102 pub mod incremental_cache;
103 
104 /// Even when trace logging is disabled, the trace macro has a significant performance cost so we
105 /// disable it by default.
106 #[macro_export]
107 macro_rules! trace {
108     ($($tt:tt)*) => {
109         if cfg!(any(feature = "trace-log", debug_assertions)) {
110             ::log::trace!($($tt)*);
111         }
112     };
113 }
114 
115 /// Dynamic check for whether trace logging is enabled.
116 #[macro_export]
117 macro_rules! trace_log_enabled {
118     () => {
119         cfg!(any(feature = "trace-log", debug_assertions))
120             && ::log::log_enabled!(::log::Level::Trace)
121     };
122 }
123 
124 include!(concat!(env!("OUT_DIR"), "/version.rs"));
125