diff options
Diffstat (limited to 'ortho/mcode')
-rw-r--r-- | ortho/mcode/ortho_code-consts.adb | 6 | ||||
-rw-r--r-- | ortho/mcode/ortho_code-consts.ads | 7 | ||||
-rw-r--r-- | ortho/mcode/ortho_code-types.adb | 9 | ||||
-rw-r--r-- | ortho/mcode/ortho_code-types.ads | 3 | ||||
-rw-r--r-- | ortho/mcode/ortho_mcode.ads | 7 |
5 files changed, 24 insertions, 8 deletions
diff --git a/ortho/mcode/ortho_code-consts.adb b/ortho/mcode/ortho_code-consts.adb index 1122b8e..d09a13c 100644 --- a/ortho/mcode/ortho_code-consts.adb +++ b/ortho/mcode/ortho_code-consts.adb @@ -496,8 +496,12 @@ package body Ortho_Code.Consts is return To_Cnode_Sizeof (Cnodes.Table (Cst + 1)).Atype; end Get_Alignof_Type; - function New_Offsetof (Field : O_Fnode; Rtype : O_Tnode) return O_Cnode is + function New_Offsetof (Rec_Type : O_Tnode; Field : O_Fnode; Rtype : O_Tnode) + return O_Cnode is begin + if Get_Field_Parent (Field) /= Rec_Type then + raise Syntax_Error; + end if; return New_Unsigned_Literal (Rtype, Unsigned_64 (Get_Field_Offset (Field))); end New_Offsetof; diff --git a/ortho/mcode/ortho_code-consts.ads b/ortho/mcode/ortho_code-consts.ads index 7059b56..0076bc6 100644 --- a/ortho/mcode/ortho_code-consts.ads +++ b/ortho/mcode/ortho_code-consts.ads @@ -126,9 +126,10 @@ package Ortho_Code.Consts is -- unsgined type RTYPE. function New_Alignof (Atype : O_Tnode; Rtype : O_Tnode) return O_Cnode; - -- Returns the offset of FIELD in its record. The result is a literal - -- of unsigned type RTYPE. - function New_Offsetof (Field : O_Fnode; Rtype : O_Tnode) return O_Cnode; + -- Returns the offset of FIELD in its record REC_TYPE. The result is a + -- literal of unsigned type or access type RTYPE. + function New_Offsetof (Rec_Type : O_Tnode; Field : O_Fnode; Rtype : O_Tnode) + return O_Cnode; procedure Disp_Stats; diff --git a/ortho/mcode/ortho_code-types.adb b/ortho/mcode/ortho_code-types.adb index d157228..e0c070c 100644 --- a/ortho/mcode/ortho_code-types.adb +++ b/ortho/mcode/ortho_code-types.adb @@ -77,6 +77,7 @@ package body Ortho_Code.Types is Table_Increment => 100); type Field_Type is record + Parent : O_Tnode; Ident : O_Ident; Ftype : O_Tnode; Offset : Uns32; @@ -226,6 +227,11 @@ package body Ortho_Code.Types is Fnodes.Table (Field).Offset := Offset; end Set_Field_Offset; + function Get_Field_Parent (Field : O_Fnode) return O_Tnode is + begin + return Fnodes.Table (Field).Parent; + end Get_Field_Parent; + function Get_Field_Type (Field : O_Fnode) return O_Tnode is begin return Fnodes.Table (Field).Ftype; @@ -592,7 +598,8 @@ package body Ortho_Code.Types is begin Elements.Off := Do_Align (Elements.Off, Etype); - Fnodes.Append (Field_Type'(Ident => Ident, + Fnodes.Append (Field_Type'(Parent => Elements.Res, + Ident => Ident, Ftype => Etype, Offset => Elements.Off, Next => O_Fnode_Null)); diff --git a/ortho/mcode/ortho_code-types.ads b/ortho/mcode/ortho_code-types.ads index 86a6c2c..da65498 100644 --- a/ortho/mcode/ortho_code-types.ads +++ b/ortho/mcode/ortho_code-types.ads @@ -93,6 +93,9 @@ package Ortho_Code.Types is function Get_Type_Bool_False (Atype : O_Tnode) return O_Cnode; function Get_Type_Bool_True (Atype : O_Tnode) return O_Cnode; + -- Return the union/record type which contains FIELD. + function Get_Field_Parent (Field : O_Fnode) return O_Tnode; + -- Get the offset of FIELD in its record/union. function Get_Field_Offset (Field : O_Fnode) return Uns32; procedure Set_Field_Offset (Field : O_Fnode; Offset : Uns32); diff --git a/ortho/mcode/ortho_mcode.ads b/ortho/mcode/ortho_mcode.ads index ea06573..369e743 100644 --- a/ortho/mcode/ortho_mcode.ads +++ b/ortho/mcode/ortho_mcode.ads @@ -280,9 +280,10 @@ package Ortho_Mcode is function New_Alignof (Atype : O_Tnode; Rtype : O_Tnode) return O_Cnode renames Ortho_Code.Consts.New_Alignof; - -- Returns the offset of FIELD in its record. The result is a literal - -- of unsigned type RTYPE. - function New_Offsetof (Field : O_Fnode; Rtype : O_Tnode) return O_Cnode + -- Returns the offset of FIELD in its record REC_TYPE. The result is a + -- literal of unsigned type or access type RTYPE. + function New_Offsetof (Rec_Type : O_Tnode; Field : O_Fnode; Rtype : O_Tnode) + return O_Cnode renames Ortho_Code.Consts.New_Offsetof; -- Get an element of an array. |