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    /// Under SSRANGE, where the item lies in its outermost table and the table's extent, which the
29    /// composed subscripts' address is checked against; carried at the LIR section's end.
30    pub table: Option<TableRange>,
31}
32
33/// An item's displacement within its outermost table at its first occurrence, and the table's
34/// bytes with every OCCURS at its maximum.
35#[derive(Clone, Copy, Debug, PartialEq, Eq)]
36pub struct TableRange {
37    pub displacement: u32,
38    pub extent: u32,
39}
40
41#[derive(Clone, Copy, Debug, PartialEq, Eq)]
42pub enum Base {
43    Program,
44    Local,
45    Linkage(u16),
46    /// RETURN-CODE at run-unit offset 0, when the program declares none.
47    ReturnCode,
48    Eib,
49    SelfRef,
50    JniEnv,
51    /// An XML PARSE fragment register, the current event's text: `offset` and `len` are 0 and the
52    /// fragment gives both. Its reference modification is checked whatever `check` says, abending
53    /// IRONWORK "reference modification (s:l) of NAME is outside its N bytes".
54    Xml(XmlRegister),
55}
56
57/// `check` is the occurrence count, present only under SSRANGE.
58#[derive(Clone, Debug, PartialEq, Eq)]
59pub struct Subscript {
60    pub stride: u32,
61    pub value: IntExpr,
62    pub check: Option<u32>,
63}
64
65#[derive(Clone, Debug, PartialEq, Eq)]
66pub struct Odo {
67    pub object: IntExpr,
68    pub max: u32,
69    pub element: u32,
70    pub check: bool,
71}
72
73/// Start and length count character positions: two bytes each when the place's kind is national.
74#[derive(Clone, Debug, PartialEq, Eq)]
75pub struct RefMod {
76    pub start: IntExpr,
77    pub length: Option<IntExpr>,
78    pub check: bool,
79}
80
81codec_struct!(Place { base, offset, len, kind, scaling, moved, subscripts, odo, refmod, name, at, numcheck } default { table } check crate::module::codec::unchecked);
82codec_struct!(TableRange { displacement, extent });
83codec_enum!(Base {
84    Program = 0,
85    Local = 1,
86    Linkage(record) = 2,
87    ReturnCode = 3,
88    Eib = 4,
89    SelfRef = 5,
90    JniEnv = 6,
91    Xml(register) = 7,
92});
93codec_struct!(Subscript { stride, value, check });
94codec_struct!(Odo { object, max, element, check });
95codec_struct!(RefMod { start, length, check });