Skip to main content

ironwork_rt/lir/
place.rs

1//! Places (lir.md ยง5): data references resolved at lowering, which an executor evaluates to a `Loc`.
2
3use super::{DebugId, IntExpr, PlaceNumcheck, SymId, XmlRegister};
4use crate::storage::Kind;
5use crate::{codec_enum, codec_struct};
6
7#[derive(Clone, Debug, PartialEq, Eq)]
8pub struct Place {
9    pub base: Base,
10    pub offset: u32,
11    /// One occurrence, before OCCURS DEPENDING ON and reference modification.
12    pub len: u32,
13    pub kind: Kind,
14    /// PICTURE P positions right of the item's digits: its value is its digits times ten to this.
15    pub scaling: u32,
16    /// The OCCURS DEPENDING ON tables ahead of the item in its record, not within it: each moves
17    /// the item back by its occurrences past the current count, evaluated before the subscripts.
18    pub moved: Vec<Odo>,
19    /// One per OCCURS level, outermost first.
20    pub subscripts: Vec<Subscript>,
21    /// The OCCURS DEPENDING ON tables within the item, other than one within another of them: each
22    /// leaves its occurrences past the current count out of the length.
23    pub odo: Vec<Odo>,
24    pub refmod: Option<RefMod>,
25    pub name: SymId,
26    pub at: DebugId,
27    pub numcheck: PlaceNumcheck,
28}
29
30#[derive(Clone, Copy, Debug, PartialEq, Eq)]
31pub enum Base {
32    Program,
33    Local,
34    Linkage(u16),
35    /// RETURN-CODE at run-unit offset 0, when the program declares none.
36    ReturnCode,
37    Eib,
38    SelfRef,
39    JniEnv,
40    /// An XML PARSE fragment register, the current event's text: `offset` and `len` are 0 and the
41    /// fragment gives both. Its reference modification is checked whatever `check` says, abending
42    /// IRONWORK "reference modification (s:l) of NAME is outside its N bytes".
43    Xml(XmlRegister),
44}
45
46/// `check` is the occurrence count, present only under SSRANGE.
47#[derive(Clone, Debug, PartialEq, Eq)]
48pub struct Subscript {
49    pub stride: u32,
50    pub value: IntExpr,
51    pub check: Option<u32>,
52}
53
54#[derive(Clone, Debug, PartialEq, Eq)]
55pub struct Odo {
56    pub object: IntExpr,
57    pub max: u32,
58    pub element: u32,
59    pub check: bool,
60}
61
62/// Start and length count character positions: two bytes each when the place's kind is national.
63#[derive(Clone, Debug, PartialEq, Eq)]
64pub struct RefMod {
65    pub start: IntExpr,
66    pub length: Option<IntExpr>,
67    pub check: bool,
68}
69
70codec_struct!(Place { base, offset, len, kind, scaling, moved, subscripts, odo, refmod, name, at, numcheck });
71codec_enum!(Base {
72    Program = 0,
73    Local = 1,
74    Linkage(record) = 2,
75    ReturnCode = 3,
76    Eib = 4,
77    SelfRef = 5,
78    JniEnv = 6,
79    Xml(register) = 7,
80});
81codec_struct!(Subscript { stride, value, check });
82codec_struct!(Odo { object, max, element, check });
83codec_struct!(RefMod { start, length, check });