MCPcopy Create free account
hub / github.com/Sin7Y/olavm / encode_to_binary

Function encode_to_binary

assembler/src/encoder.rs:26–121  ·  view source on GitHub ↗
(bundle: RelocatedAsmBundle)

Source from the content-addressed store, hash-verified

24
25 let mut binary_instructions: Vec<BinaryInstruction> = vec![];
26 let mut iter = asm_instructions.iter();
27 let mut binary_counter: usize = 0;
28 let mut origin_asm = BTreeMap::new();
29
30 while let Some(asm) = iter.next() {
31 let ops_result: Result<
32 (Option<OlaOperand>, Option<OlaOperand>, Option<OlaOperand>),
33 String,
34 > = if is_adjusted_operand(asm) {
35 let r = handle_mem_operand(asm);
36 if r.is_err() {
37 return Err(format!(
38 "relocated asm to binary error: ops convert error ==> {}",
39 r.err().unwrap()
40 ));
41 } else {
42 let tuple = r.unwrap();
43 Ok((Some(tuple.0), Some(tuple.1), Some(tuple.2)))
44 }
45 } else {
46 let op0_result =
47 operand_asm_to_binary(asm.clone().op0, mapper_label_call, mapper_label_jmp);
48 if op0_result.is_err() {
49 return Err(format!(
50 "relocated asm to binary error: op0 convert error ==> {}",
51 op0_result.err().unwrap()
52 ));
53 }
54 let op0 = op0_result.unwrap();
55
56 let op1_result =
57 operand_asm_to_binary(asm.clone().op1, mapper_label_call, mapper_label_jmp);
58 if op1_result.is_err() {
59 return Err(format!(
60 "relocated asm to binary error: op1 convert error ==> {}",
61 op1_result.err().unwrap()
62 ));
63 }
64 let op1 = op1_result.unwrap();
65
66 let dst_result =
67 operand_asm_to_binary(asm.clone().dst, mapper_label_call, mapper_label_jmp);
68 if dst_result.is_err() {
69 return Err(format!(
70 "relocated asm to binary error: dst convert error ==> {}",
71 dst_result.err().unwrap()
72 ));
73 }
74 let dst = dst_result.unwrap();
75 Ok((op0, op1, dst))
76 };
77 if ops_result.is_err() {
78 return Err(format!(
79 "relocated asm to binary error: ==> {}",
80 ops_result.err().unwrap()
81 ));
82 }
83 let (op0, op1, dst) = ops_result.unwrap();

Callers 5

dump_from_asm_fileFunction · 0.85
generate_from_fileFunction · 0.85
generate_all_dirFunction · 0.85

Calls 9

is_adjusted_operandFunction · 0.85
handle_mem_operandFunction · 0.85
operand_asm_to_binaryFunction · 0.85
insertMethod · 0.80
iterMethod · 0.45
nextMethod · 0.45
getMethod · 0.45
pushMethod · 0.45
binary_lengthMethod · 0.45

Tested by 3

dump_from_asm_fileFunction · 0.68
generate_from_fileFunction · 0.68
generate_all_dirFunction · 0.68