bind/compiler/
instruction.rs1use crate::compiler::Symbol;
8use num_derive::FromPrimitive;
9use std::fmt;
10
11#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
12pub struct DeviceProperty {
13 pub key: u32,
14 pub value: u32,
15}
16
17impl fmt::Display for DeviceProperty {
18 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19 write!(f, "{:#06x} = {:#010x}", self.key, self.value)
20 }
21}
22
23#[derive(Clone, PartialEq, Eq)]
26pub enum Condition {
27 Always,
28 Equal(Symbol, Symbol),
29 NotEqual(Symbol, Symbol),
30}
31
32#[derive(Clone)]
33pub enum Instruction {
34 Abort(Condition),
35 Match(Condition),
36 Goto(Condition, u32),
37 Label(u32),
38}
39
40#[derive(Clone, FromPrimitive, PartialEq)]
41pub enum RawAstLocation {
42 Invalid = 0,
43 ConditionStatement,
44 AcceptStatementValue,
45 AcceptStatementFailure,
46 IfCondition,
47 FalseStatement,
48}
49
50#[derive(Clone)]
51pub struct InstructionDebug {
52 pub line: u32,
53 pub ast_location: RawAstLocation,
54 pub extra: u32,
55}
56
57impl InstructionDebug {
58 pub fn none() -> Self {
59 InstructionDebug { line: 0, ast_location: RawAstLocation::Invalid, extra: 0 }
60 }
61}
62
63pub struct InstructionInfo {
64 pub instruction: Instruction,
65 pub debug: InstructionDebug,
66}
67
68impl InstructionInfo {
69 pub fn new(instruction: Instruction) -> Self {
70 InstructionInfo { instruction, debug: InstructionDebug::none() }
71 }
72}