MCPcopy Create free account
hub / github.com/LPC4/Full-Stack / parse_int_reg

Function parse_int_reg

crates/asm-to-binary/src/assembler/reg_parse.rs:6–42  ·  view source on GitHub ↗

Parse an ABI integer register name (e.g. `"a0"`, `"x10"`, `"zero"`) to a hardware register number in `0..=31`. Returns `None` on unrecognised names.

(name: &str)

Source from the content-addressed store, hash-verified

4
5/// Parse an ABI integer register name (e.g. `"a0"`, `"x10"`, `"zero"`) to a
6/// hardware register number in `0..=31`. Returns `None` on unrecognised names.
7pub fn parse_int_reg(name: &str) -> Option<Reg> {
8 match name.trim() {
9 "zero" | "x0" => Some(0),
10 "ra" | "x1" => Some(1),
11 "sp" | "x2" => Some(2),
12 "gp" | "x3" => Some(3),
13 "tp" | "x4" => Some(4),
14 "t0" | "x5" => Some(5),
15 "t1" | "x6" => Some(6),
16 "t2" | "x7" => Some(7),
17 "s0" | "fp" | "x8" => Some(8),
18 "s1" | "x9" => Some(9),
19 "a0" | "x10" => Some(10),
20 "a1" | "x11" => Some(11),
21 "a2" | "x12" => Some(12),
22 "a3" | "x13" => Some(13),
23 "a4" | "x14" => Some(14),
24 "a5" | "x15" => Some(15),
25 "a6" | "x16" => Some(16),
26 "a7" | "x17" => Some(17),
27 "s2" | "x18" => Some(18),
28 "s3" | "x19" => Some(19),
29 "s4" | "x20" => Some(20),
30 "s5" | "x21" => Some(21),
31 "s6" | "x22" => Some(22),
32 "s7" | "x23" => Some(23),
33 "s8" | "x24" => Some(24),
34 "s9" | "x25" => Some(25),
35 "s10" | "x26" => Some(26),
36 "s11" | "x27" => Some(27),
37 "t3" | "x28" => Some(28),
38 "t4" | "x29" => Some(29),
39 "t5" | "x30" => Some(30),
40 "t6" | "x31" => Some(31),
41 _ => None,
42 }
43}
44
45/// Parse an ABI float register name (`"fa0"`, `"ft0"`, `"f10"`) to a number in `0..=31`.

Callers 15

try_parse_liFunction · 0.85
parse_two_regsFunction · 0.85
parse_r_i_immFunction · 0.85
parse_store_memFunction · 0.85
parse_load_memFunction · 0.85
parse_mem_refFunction · 0.85
parse_branchFunction · 0.85
parse_jalFunction · 0.85
parse_laFunction · 0.85
parse_branch_zeroFunction · 0.85
parse_csrrFunction · 0.85
parse_csrwFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected