File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11use clap:: Parser ;
2+ use do_core:: instruction:: OpCode ;
3+ use do_core:: Error ;
24
35#[ derive( Parser ) ]
46#[ clap( version, author) ]
@@ -15,14 +17,6 @@ struct Instruction {
1517 op1 : u8 ,
1618}
1719
18- #[ derive( Debug ) ]
19- enum Error {
20- InvalidOpCode ( u8 ) ,
21- Op0OutOfRange ,
22- Op1OutOfRange ,
23- AdditionOverflow ( u32 , u32 ) ,
24- }
25-
2620// do-core1 register indexes range from 0 to 31.
2721const MAX_REGISTER_INDEX : u8 = 31 ;
2822
@@ -50,27 +44,6 @@ impl Instruction {
5044 }
5145}
5246
53- #[ allow( dead_code) ]
54- #[ derive( Debug , PartialEq ) ]
55- enum OpCode {
56- LDW = 0x00 ,
57- STW = 0x01 ,
58- ADD = 0x02 ,
59- XOR = 0x03 ,
60- }
61-
62- impl OpCode {
63- fn from_u8 ( opcode : u8 ) -> Result < OpCode , Error > {
64- match opcode {
65- 0x00 => Ok ( OpCode :: LDW ) ,
66- 0x01 => Ok ( OpCode :: STW ) ,
67- 0x02 => Ok ( OpCode :: ADD ) ,
68- 0x03 => Ok ( OpCode :: XOR ) ,
69- _ => Err ( Error :: InvalidOpCode ( opcode) ) ,
70- }
71- }
72- }
73-
7447fn add ( op0 : u32 , op1 : u32 ) -> Result < u32 , Error > {
7548 op0. checked_add ( op1)
7649 . ok_or ( Error :: AdditionOverflow ( op0, op1) )
You can’t perform that action at this time.
0 commit comments