From 7414046cc73ecc16bfa2ce3af3cb529195ce120f Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Thu, 16 Nov 2017 04:43:41 +0100 Subject: mcode: add new_default_value. --- src/ortho/mcode/ortho_code-consts.adb | 10 +++++++++- src/ortho/mcode/ortho_code-consts.ads | 2 ++ src/ortho/mcode/ortho_code-exprs.adb | 3 ++- src/ortho/mcode/ortho_code-x86-emits.adb | 4 ++++ src/ortho/mcode/ortho_mcode.adb | 6 ++++++ src/ortho/mcode/ortho_mcode.ads | 4 ++++ 6 files changed, 27 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ortho/mcode/ortho_code-consts.adb b/src/ortho/mcode/ortho_code-consts.adb index 4522e674a..7cc554211 100644 --- a/src/ortho/mcode/ortho_code-consts.adb +++ b/src/ortho/mcode/ortho_code-consts.adb @@ -219,6 +219,13 @@ package body Ortho_Code.Consts is return Cnodes.Last; end New_Null_Access; + function New_Default_Value (Ltype : O_Tnode) return O_Cnode is + begin + Cnodes.Append (Cnode_Common'(Kind => OC_Zero, + Lit_Type => Ltype)); + return Cnodes.Last; + end New_Default_Value; + function To_Cnode_Common is new Ada.Unchecked_Conversion (Source => Cnode_Addr, Target => Cnode_Common); @@ -525,7 +532,8 @@ package body Ortho_Code.Consts is | OC_Sizeof | OC_Alignof | OC_Address - | OC_Subprg_Address => + | OC_Subprg_Address + | OC_Zero => raise Syntax_Error; end case; end Get_Const_Bytes; diff --git a/src/ortho/mcode/ortho_code-consts.ads b/src/ortho/mcode/ortho_code-consts.ads index 102dc59d3..0a4f347fc 100644 --- a/src/ortho/mcode/ortho_code-consts.ads +++ b/src/ortho/mcode/ortho_code-consts.ads @@ -19,6 +19,7 @@ with Interfaces; use Interfaces; package Ortho_Code.Consts is type OC_Kind is (OC_Signed, OC_Unsigned, OC_Float, OC_Lit, OC_Null, + OC_Zero, OC_Array, OC_Record, OC_Union, OC_Subprg_Address, OC_Address, OC_Sizeof, OC_Alignof); @@ -78,6 +79,7 @@ package Ortho_Code.Consts is function New_Null_Access (Ltype : O_Tnode) return O_Cnode; function New_Global_Unchecked_Address (Decl : O_Dnode; Atype : O_Tnode) return O_Cnode; + function New_Default_Value (Ltype : O_Tnode) return O_Cnode; function New_Global_Address (Decl : O_Dnode; Atype : O_Tnode) return O_Cnode; function New_Subprogram_Address (Subprg : O_Dnode; Atype : O_Tnode) diff --git a/src/ortho/mcode/ortho_code-exprs.adb b/src/ortho/mcode/ortho_code-exprs.adb index 47064e76e..4e0d6bdc4 100644 --- a/src/ortho/mcode/ortho_code-exprs.adb +++ b/src/ortho/mcode/ortho_code-exprs.adb @@ -721,7 +721,8 @@ package body Ortho_Code.Exprs is | OC_Record | OC_Union | OC_Sizeof - | OC_Alignof => + | OC_Alignof + | OC_Zero => raise Syntax_Error; end case; end if; diff --git a/src/ortho/mcode/ortho_code-x86-emits.adb b/src/ortho/mcode/ortho_code-x86-emits.adb index 48590af97..9e73b2dab 100644 --- a/src/ortho/mcode/ortho_code-x86-emits.adb +++ b/src/ortho/mcode/ortho_code-x86-emits.adb @@ -3183,6 +3183,10 @@ package body Ortho_Code.X86.Emits is Emit_Const (E); end loop; end; + when OC_Zero => + for I in 1 .. Get_Type_Size (Get_Const_Type (Val)) loop + Gen_8 (0); + end loop; when OC_Sizeof | OC_Alignof | OC_Union => diff --git a/src/ortho/mcode/ortho_mcode.adb b/src/ortho/mcode/ortho_mcode.adb index cb2ab6663..fac45e438 100644 --- a/src/ortho/mcode/ortho_mcode.adb +++ b/src/ortho/mcode/ortho_mcode.adb @@ -253,6 +253,12 @@ package body Ortho_Mcode is (Ortho_Code.Consts.New_Null_Access (Ortho_Code.O_Tnode (Ltype))); end New_Null_Access; + function New_Default_Value (Ltype : O_Tnode) return O_Cnode is + begin + return O_Cnode + (Ortho_Code.Consts.New_Default_Value (Ortho_Code.O_Tnode (Ltype))); + end New_Default_Value; + procedure Start_Record_Aggr (List : out O_Record_Aggr_List; Atype : O_Tnode) is begin diff --git a/src/ortho/mcode/ortho_mcode.ads b/src/ortho/mcode/ortho_mcode.ads index ec65fab5c..dda220f1c 100644 --- a/src/ortho/mcode/ortho_mcode.ads +++ b/src/ortho/mcode/ortho_mcode.ads @@ -145,6 +145,10 @@ package Ortho_Mcode is -- Create a null access literal. function New_Null_Access (Ltype : O_Tnode) return O_Cnode; + -- Create a literal with default (null) values. Can only be used to + -- define the initial value of a static decalaration. + function New_Default_Value (Ltype : O_Tnode) return O_Cnode; + -- Build a record/array aggregate. -- The aggregate is constant, and therefore can be only used to initialize -- constant declaration. -- cgit v1.2.3