bind/
bytecode_constants.rs

1// Copyright 2021 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use num_derive::FromPrimitive;
6
7// Magic number for BIND.
8pub const BIND_MAGIC_NUM: u32 = 0x42494E44;
9
10// Magic number for SYMB.
11pub const SYMB_MAGIC_NUM: u32 = 0x53594E42;
12
13// Magic number for INST.
14pub const INSTRUCTION_MAGIC_NUM: u32 = 0x494E5354;
15
16// Magic number for COMP.
17pub const COMPOSITE_MAGIC_NUM: u32 = 0x434F4D50;
18
19// Magic number for DEBG.
20pub const DEBG_MAGIC_NUM: u32 = 0x44454247;
21
22// Magic number for DBSY.
23pub const DBSY_MAGIC_NUM: u32 = 0x44425359;
24
25pub const BYTECODE_VERSION: u32 = 2;
26
27pub const MAX_STRING_LENGTH: usize = 255;
28
29// Bytecode values for enable_debug flag
30pub const BYTECODE_ENABLE_DEBUG: u8 = 1;
31pub const BYTECODE_DISABLE_DEBUG: u8 = 0;
32
33// The first key in the symbol table. The key increments by 1 with each entry.
34pub const SYMB_TBL_START_KEY: u32 = 1;
35
36// Bytecode boolean value for false.
37pub const FALSE_VAL: u32 = 0x00;
38
39// Bytecode boolean value for true.
40pub const TRUE_VAL: u32 = 0x01;
41
42// Each section header contains a uint32 magic number and a uint32 value.
43pub const HEADER_SZ: usize = 8;
44
45#[derive(FromPrimitive, PartialEq)]
46pub enum RawOp {
47    EqualCondition = 0x01,
48    InequalCondition = 0x02,
49    UnconditionalJump = 0x10,
50    JumpIfEqual = 0x11,
51    JumpIfNotEqual = 0x12,
52    JumpLandPad = 0x20,
53    Abort = 0x30,
54}
55
56#[derive(Clone, FromPrimitive)]
57pub enum RawValueType {
58    Key = 0,
59    NumberValue,
60    StringValue,
61    BoolValue,
62    EnumValue,
63}
64
65#[derive(FromPrimitive, PartialEq)]
66pub enum RawNodeType {
67    Primary = 0x50,
68    Additional = 0x51,
69    Optional = 0x52,
70}