buesingniklas

Untitled

Jan 4th, 2022
4,226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 2.19 KB | None | 0 0
  1. pub const CONST: u8 = 0x0;
  2. pub const LOAD_G: u8 = 0x1;
  3. pub const STORE_G: u8 = 0x2;
  4. pub const LOAD_L: u8 = 0x3;
  5. pub const STORE_L: u8 = 0x4;
  6. pub const LOAD_A: u8 = 0x5;
  7. pub const STORE_A: u8 = 0x6;
  8. pub const JMP: u8 = 0x7;
  9. pub const BRF: u8 = 0x8;
  10. pub const BRT: u8 = 0x9;
  11. pub const CALL: u8 = 0xA;
  12. pub const CALL_B: u8 = 0xB;
  13. pub const RET: u8 = 0xC;
  14. pub const LOAD_R: u8 = 0xD;
  15. pub const STORE_R: u8 = 0xE;
  16. pub const ASF: u8 = 0xF;
  17. pub const RSF: u8 = 0x10;
  18. pub const POP: u8 = 0x11;
  19. pub const ADD: u8 = 0x12;
  20. pub const SUB: u8 = 0x13;
  21. pub const MUL: u8 = 0x14;
  22. pub const DIV: u8 = 0x15;
  23. pub const MOD: u8 = 0x16;
  24. pub const EQ: u8 = 0x17;
  25. pub const NE: u8 = 0x18;
  26. pub const LT: u8 = 0x19;
  27. pub const LE: u8 = 0x1A;
  28. pub const GT: u8 = 0x1B;
  29. pub const GE: u8 = 0x1C;
  30. pub const NOT: u8 = 0x1D;
  31. pub const NEG: u8 = 0x1E;
  32. pub const HALT: u8 = 0x1F;
  33. pub const ARRAY: u8 = 0x20;
  34.  
  35. pub fn opcode_to_string(opcode: u8) -> String {
  36.     match opcode {
  37.         CONST => "CONST".to_string(),
  38.         LOAD_G => "LOAD_G".to_string(),
  39.         STORE_G => "STORE_G".to_string(),
  40.         LOAD_L => "LOAD_L".to_string(),
  41.         STORE_L => "STORE_L".to_string(),
  42.         LOAD_A => "LOAD_A".to_string(),
  43.         STORE_A => "STORE_A".to_string(),
  44.         JMP => "JMP".to_string(),
  45.         BRF => "BRF".to_string(),
  46.         BRT => "BRT".to_string(),
  47.         CALL => "CALL".to_string(),
  48.         CALL_B => "CALL_B".to_string(),
  49.         RET => "RET".to_string(),
  50.         LOAD_R => "LOAD_R".to_string(),
  51.         STORE_R => "STORE_R".to_string(),
  52.         ASF => "ASF".to_string(),
  53.         RSF => "RSF".to_string(),
  54.         POP => "POP".to_string(),
  55.         ADD => "ADD".to_string(),
  56.         SUB => "SUB".to_string(),
  57.         MUL => "MUL".to_string(),
  58.         DIV => "DIV".to_string(),
  59.         MOD => "MOD".to_string(),
  60.         EQ => "EQ".to_string(),
  61.         NE => "NE".to_string(),
  62.         LT => "LT".to_string(),
  63.         LE => "LE".to_string(),
  64.         GT => "GT".to_string(),
  65.         GE => "GE".to_string(),
  66.         NOT => "NOT".to_string(),
  67.         NEG => "NEG".to_string(),
  68.         HALT => "HALT".to_string(),
  69.         ARRAY => "ARRAY".to_string(),
  70.         _ => "UNKNOWN".to_string(),
  71.     }
  72. }
  73.  
Advertisement