diff options
Diffstat (limited to 'ortho/mcode')
-rw-r--r-- | ortho/mcode/ortho_code-consts.adb | 22 | ||||
-rw-r--r-- | ortho/mcode/ortho_code-consts.ads | 6 | ||||
-rw-r--r-- | ortho/mcode/ortho_code-exprs.adb | 3 | ||||
-rw-r--r-- | ortho/mcode/ortho_code-types.adb | 10 | ||||
-rw-r--r-- | ortho/mcode/ortho_code-types.ads | 3 | ||||
-rw-r--r-- | ortho/mcode/ortho_code-x86-abi.ads | 2 | ||||
-rw-r--r-- | ortho/mcode/ortho_code-x86-emits.adb | 1 | ||||
-rw-r--r-- | ortho/mcode/ortho_mcode.ads | 5 |
8 files changed, 43 insertions, 9 deletions
diff --git a/ortho/mcode/ortho_code-consts.adb b/ortho/mcode/ortho_code-consts.adb index b9a6512..c6d2020 100644 --- a/ortho/mcode/ortho_code-consts.adb +++ b/ortho/mcode/ortho_code-consts.adb @@ -468,6 +468,27 @@ package body Ortho_Code.Consts is return To_Cnode_Sizeof (Cnodes.Table (Cst + 1)).Atype; end Get_Sizeof_Type; + function New_Alignof (Atype : O_Tnode; Rtype : O_Tnode) return O_Cnode + is + function To_Cnode_Common is new Ada.Unchecked_Conversion + (Source => Cnode_Sizeof, Target => Cnode_Common); + + Res : O_Cnode; + begin + if Debug.Flag_Debug_Hli then + Cnodes.Append (Cnode_Common'(Kind => OC_Alignof, + Lit_Type => Rtype)); + Res := Cnodes.Last; + Cnodes.Append (To_Cnode_Common (Cnode_Sizeof'(Atype => Atype, + Pad => 0))); + return Res; + else + return New_Unsigned_Literal + (Rtype, Unsigned_64 (Get_Type_Align_Bytes (Atype))); + end if; + end New_Alignof; + + function New_Offsetof (Field : O_Fnode; Rtype : O_Tnode) return O_Cnode is begin return New_Unsigned_Literal @@ -492,6 +513,7 @@ package body Ortho_Code.Consts is | OC_Record | OC_Union | OC_Sizeof + | OC_Alignof | OC_Address | OC_Subprg_Address => raise Syntax_Error; diff --git a/ortho/mcode/ortho_code-consts.ads b/ortho/mcode/ortho_code-consts.ads index a97c93e..603a8a1 100644 --- a/ortho/mcode/ortho_code-consts.ads +++ b/ortho/mcode/ortho_code-consts.ads @@ -21,7 +21,7 @@ package Ortho_Code.Consts is type OC_Kind is (OC_Signed, OC_Unsigned, OC_Float, OC_Lit, OC_Null, OC_Array, OC_Record, OC_Union, OC_Subprg_Address, OC_Address, - OC_Sizeof); + OC_Sizeof, OC_Alignof); function Get_Const_Kind (Cst : O_Cnode) return OC_Kind; @@ -119,6 +119,10 @@ package Ortho_Code.Consts is -- ATYPE cannot be an unconstrained array type. function New_Sizeof (Atype : O_Tnode; Rtype : O_Tnode) return O_Cnode; + -- Returns the alignment in bytes for ATYPE. The result is a literal of + -- 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; diff --git a/ortho/mcode/ortho_code-exprs.adb b/ortho/mcode/ortho_code-exprs.adb index b784059..4f71407 100644 --- a/ortho/mcode/ortho_code-exprs.adb +++ b/ortho/mcode/ortho_code-exprs.adb @@ -714,7 +714,8 @@ package body Ortho_Code.Exprs is when OC_Array | OC_Record | OC_Union - | OC_Sizeof => + | OC_Sizeof + | OC_Alignof => raise Syntax_Error; end case; end if; diff --git a/ortho/mcode/ortho_code-types.adb b/ortho/mcode/ortho_code-types.adb index 1a505b7..7956965 100644 --- a/ortho/mcode/ortho_code-types.adb +++ b/ortho/mcode/ortho_code-types.adb @@ -105,10 +105,10 @@ package body Ortho_Code.Types is return Tnodes.Table (Atype).Align; end Get_Type_Align; - function Get_Type_Align_Byte (Atype : O_Tnode) return Uns32 is + function Get_Type_Align_Bytes (Atype : O_Tnode) return Uns32 is begin return 2 ** Get_Type_Align (Atype); - end Get_Type_Align_Byte; + end Get_Type_Align_Bytes; function Get_Type_Mode (Atype : O_Tnode) return Mode_Type is begin @@ -569,19 +569,17 @@ package body Ortho_Code.Types is function Do_Align (Off : Uns32; Atype : O_Tnode) return Uns32 is - Msk : Uns32; + Msk : constant Uns32 := Get_Type_Align_Bytes (Atype) - 1; begin -- Align. - Msk := Get_Type_Align_Byte (Atype) - 1; return (Off + Msk) and (not Msk); end Do_Align; function Do_Align (Off : Uns32; Mode : Mode_Type) return Uns32 is - Msk : Uns32; + Msk : constant Uns32 := (2 ** Mode_Align (Mode)) - 1; begin -- Align. - Msk := Get_Mode_Size (Mode) - 1; return (Off + Msk) and (not Msk); end Do_Align; diff --git a/ortho/mcode/ortho_code-types.ads b/ortho/mcode/ortho_code-types.ads index 73a493e..c8d8cc0 100644 --- a/ortho/mcode/ortho_code-types.ads +++ b/ortho/mcode/ortho_code-types.ads @@ -39,6 +39,9 @@ package Ortho_Code.Types is type Mode_Align_Array is array (Mode_Type) of Small_Natural; function Get_Type_Align (Atype : O_Tnode) return Small_Natural; + -- Alignment for ATYPE in bytes. + function Get_Type_Align_Bytes (Atype : O_Tnode) return Uns32; + -- Return true is the type was incomplete at creation. -- (it may - or not - have been completed later). function Get_Type_Deferred (Atype : O_Tnode) return Boolean; diff --git a/ortho/mcode/ortho_code-x86-abi.ads b/ortho/mcode/ortho_code-x86-abi.ads index 11768dc..e974438 100644 --- a/ortho/mcode/ortho_code-x86-abi.ads +++ b/ortho/mcode/ortho_code-x86-abi.ads @@ -28,7 +28,7 @@ package Ortho_Code.X86.Abi is Mode_U16 | Mode_I16 => 1, Mode_U32 | Mode_I32 | Mode_F32 | Mode_P32 => 2, Mode_U64 | Mode_I64 => 2, - Mode_F64 => 2, + Mode_F64 => 2, -- 2 for SVR4-ABI and Darwin, 3 for Windows. Mode_Blk | Mode_X1 | Mode_Nil | Mode_P64 => 0, Mode_B2 => 0); diff --git a/ortho/mcode/ortho_code-x86-emits.adb b/ortho/mcode/ortho_code-x86-emits.adb index 12f1587..ad1ef55 100644 --- a/ortho/mcode/ortho_code-x86-emits.adb +++ b/ortho/mcode/ortho_code-x86-emits.adb @@ -2233,6 +2233,7 @@ package body Ortho_Code.X86.Emits is end loop; end; when OC_Sizeof + | OC_Alignof | OC_Union => raise Program_Error; end case; diff --git a/ortho/mcode/ortho_mcode.ads b/ortho/mcode/ortho_mcode.ads index 9ea4c89..ea06573 100644 --- a/ortho/mcode/ortho_mcode.ads +++ b/ortho/mcode/ortho_mcode.ads @@ -275,6 +275,11 @@ package Ortho_Mcode is function New_Sizeof (Atype : O_Tnode; Rtype : O_Tnode) return O_Cnode renames Ortho_Code.Consts.New_Sizeof; + -- Returns the alignment in bytes for ATYPE. The result is a literal of + -- unsgined type RTYPE. + 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 |