1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! Open registry of [`ArchCodec`] factories.
//!
//! Arch crates register a factory function at process startup
//! (typically from `<crate>::register()`); resolution happens at
//! the entry of every compile / decompile pipeline call that needs
//! to encode arch-specific instructions.
//!
//! The registry takes raw `(arch_name, e_machine)` pairs rather
//! than an AST type — that's how this crate stays independent of
//! `ud-ast` (which would otherwise cause a cycle through
//! `ud-arch-x86`). Callers (`ud-translate`) extract the pair from
//! a parsed `ud_ast::Module` and feed it in.
use ;
use crate::;
/// A codec factory: inspects an `(arch_name, e_machine)` pair and
/// returns a codec instance if it recognises the arch, else
/// `None`. `arch_name` is the lowercase friendly arch identifier
/// from the parsed `@module` block (`"x86_64"`, `"bpf"`, etc.);
/// `e_machine` is the numeric ELF machine type (`EM_BPF = 247`,
/// `EM_SBF = 263`, …) — useful for sub-arch dispatch (e.g.
/// distinguishing Linux eBPF from Solana SBF when both carry
/// `arch = "bpf"`).
pub type CodecFactory =
fn ;
static REGISTRY: = new;
/// Register a codec factory. Each arch crate exposes a
/// `register()` pub fn that calls this once.
///
/// Re-registering the same factory is harmless but wasteful; the
/// registry doesn't dedupe. Production binaries call
/// `<arch_crate>::register()` once at startup.
/// Resolve the codec for an `(arch_name, e_machine)` pair.
/// Returns the first matching factory's result, or
/// [`ArchError::UnknownArch`] if nothing claims it.
///
/// Pass `None` for either component when it's unknown — factories
/// must tolerate that and either match on the other or decline.
/// Number of factories currently registered. Cheap; intended for
/// tests and diagnostics.