summaryrefslogtreecommitdiff
path: root/src/vhdl
diff options
context:
space:
mode:
authorTristan Gingold2014-11-21 03:49:42 +0100
committerTristan Gingold2014-11-21 03:49:42 +0100
commit229103683af03c7286444aa12ec85bb2ba1bed59 (patch)
treee2598cf02a2b873acc080440841e4c8d8f31c714 /src/vhdl
parent232f0d5f10ecd3b99774d3dda6a7ebf914b2a2e6 (diff)
downloadghdl-229103683af03c7286444aa12ec85bb2ba1bed59.tar.gz
ghdl-229103683af03c7286444aa12ec85bb2ba1bed59.tar.bz2
ghdl-229103683af03c7286444aa12ec85bb2ba1bed59.zip
Mnode: renaming and comments to clarify.
Diffstat (limited to 'src/vhdl')
-rw-r--r--src/vhdl/translate/trans-chap3.adb14
-rw-r--r--src/vhdl/translate/trans.adb50
-rw-r--r--src/vhdl/translate/trans.ads169
3 files changed, 125 insertions, 108 deletions
diff --git a/src/vhdl/translate/trans-chap3.adb b/src/vhdl/translate/trans-chap3.adb
index bc0d9d2..9fd88f7 100644
--- a/src/vhdl/translate/trans-chap3.adb
+++ b/src/vhdl/translate/trans-chap3.adb
@@ -858,10 +858,9 @@ package body Trans.Chap3 is
Index : Iir;
Targ : Mnode;
begin
- Targ := Lv2M (Target, True,
+ Targ := Lv2M (Target, null, Mode_Value, True,
Baseinfo.T.Bounds_Type,
- Baseinfo.T.Bounds_Ptr_Type,
- null, Mode_Value);
+ Baseinfo.T.Bounds_Ptr_Type);
Open_Temp;
if Get_Nbr_Elements (Indexes_List) > 1 then
Targ := Stabilize (Targ);
@@ -2606,12 +2605,11 @@ package body Trans.Chap3 is
return Reindex_Complex_Array (Base, Atype, Index, T_Info);
else
return Lv2M (New_Slice (M2Lv (Base),
+ T_Info.T.Base_Type (Kind),
+ Index),
+ T_Info, Kind, False,
T_Info.T.Base_Type (Kind),
- Index),
- False,
- T_Info.T.Base_Type (Kind),
- T_Info.T.Base_Ptr_Type (Kind),
- T_Info, Kind);
+ T_Info.T.Base_Ptr_Type (Kind));
end if;
end Slice_Base;
diff --git a/src/vhdl/translate/trans.adb b/src/vhdl/translate/trans.adb
index 3934979..82e34ae 100644
--- a/src/vhdl/translate/trans.adb
+++ b/src/vhdl/translate/trans.adb
@@ -1078,29 +1078,30 @@ package body Trans is
function Stabilize (M : Mnode; Can_Copy : Boolean := False) return Mnode
is
+ K : constant Object_Kind_Type := M.M1.K;
D : O_Dnode;
- K : Object_Kind_Type;
begin
- K := M.M1.K;
case M.M1.State is
when Mstate_E =>
- if M.M1.Comp then
+ if M.M1.Is_Composite then
+ -- Create a pointer variable.
D := Create_Temp_Init (M.M1.Ptype, M.M1.E);
return Mnode'(M1 => (State => Mstate_Dp,
- Comp => M.M1.Comp,
+ Is_Composite => True,
K => K, T => M.M1.T, Dp => D,
Vtype => M.M1.Vtype, Ptype => M.M1.Ptype));
else
+ -- Create a scalar variable.
D := Create_Temp_Init (M.M1.Vtype, M.M1.E);
return Mnode'(M1 => (State => Mstate_Dv,
- Comp => M.M1.Comp,
+ Is_Composite => False,
K => K, T => M.M1.T, Dv => D,
Vtype => M.M1.Vtype, Ptype => M.M1.Ptype));
end if;
when Mstate_Lp =>
D := Create_Temp_Init (M.M1.Ptype, New_Value (M.M1.Lp));
return Mnode'(M1 => (State => Mstate_Dp,
- Comp => M.M1.Comp,
+ Is_Composite => M.M1.Is_Composite,
K => K, T => M.M1.T, Dp => D,
Vtype => M.M1.Vtype, Ptype => M.M1.Ptype));
when Mstate_Lv =>
@@ -1110,14 +1111,14 @@ package body Trans is
end if;
D := Create_Temp_Init (M.M1.Vtype, New_Value (M.M1.Lv));
return Mnode'(M1 => (State => Mstate_Dv,
- Comp => M.M1.Comp,
+ Is_Composite => M.M1.Is_Composite,
K => K, T => M.M1.T, Dv => D,
Vtype => M.M1.Vtype, Ptype => M.M1.Ptype));
else
D := Create_Temp_Ptr (M.M1.Ptype, M.M1.Lv);
return Mnode'(M1 => (State => Mstate_Dp,
- Comp => M.M1.Comp,
+ Is_Composite => M.M1.Is_Composite,
K => K, T => M.M1.T, Dp => D,
Vtype => M.M1.Vtype, Ptype => M.M1.Ptype));
end if;
@@ -1141,7 +1142,7 @@ package body Trans is
E : O_Enode;
begin
-- M must be scalar or access.
- if M.M1.Comp then
+ if M.M1.Is_Composite then
raise Internal_Error;
end if;
case M.M1.State is
@@ -1161,7 +1162,7 @@ package body Trans is
D := Create_Temp_Init (M.M1.Vtype, E);
return Mnode'(M1 => (State => Mstate_Dv,
- Comp => M.M1.Comp,
+ Is_Composite => M.M1.Is_Composite,
K => M.M1.K, T => M.M1.T, Dv => D,
Vtype => M.M1.Vtype, Ptype => M.M1.Ptype));
end Stabilize_Value;
@@ -1377,7 +1378,7 @@ package body Trans is
return Mnode is
begin
return Mnode'(M1 => (State => Mstate_E,
- Comp => T.Type_Mode in Type_Mode_Fat,
+ Is_Composite => T.Type_Mode in Type_Mode_Fat,
K => Kind, T => T, E => E,
Vtype => T.Ortho_Type (Kind),
Ptype => T.Ortho_Ptr_Type (Kind)));
@@ -1387,21 +1388,22 @@ package body Trans is
return Mnode is
begin
return Mnode'(M1 => (State => Mstate_Lv,
- Comp => T.Type_Mode in Type_Mode_Fat,
+ Is_Composite => T.Type_Mode in Type_Mode_Fat,
K => Kind, T => T, Lv => L,
Vtype => T.Ortho_Type (Kind),
Ptype => T.Ortho_Ptr_Type (Kind)));
end Lv2M;
function Lv2M (L : O_Lnode;
+ T : Type_Info_Acc;
+ Kind : Object_Kind_Type;
Comp : Boolean;
Vtype : O_Tnode;
- Ptype : O_Tnode;
- T : Type_Info_Acc; Kind : Object_Kind_Type)
+ Ptype : O_Tnode)
return Mnode is
begin
return Mnode'(M1 => (State => Mstate_Lv,
- Comp => Comp,
+ Is_Composite => Comp,
K => Kind, T => T, Lv => L,
Vtype => Vtype, Ptype => Ptype));
end Lv2M;
@@ -1410,7 +1412,7 @@ package body Trans is
return Mnode is
begin
return Mnode'(M1 => (State => Mstate_Lp,
- Comp => T.Type_Mode in Type_Mode_Fat,
+ Is_Composite => T.Type_Mode in Type_Mode_Fat,
K => Kind, T => T, Lp => L,
Vtype => T.Ortho_Type (Kind),
Ptype => T.Ortho_Ptr_Type (Kind)));
@@ -1424,7 +1426,7 @@ package body Trans is
return Mnode is
begin
return Mnode'(M1 => (State => Mstate_Lp,
- Comp => T.Type_Mode in Type_Mode_Fat,
+ Is_Composite => T.Type_Mode in Type_Mode_Fat,
K => Kind, T => T, Lp => L,
Vtype => Vtype, Ptype => Ptype));
end Lp2M;
@@ -1437,7 +1439,7 @@ package body Trans is
return Mnode is
begin
return Mnode'(M1 => (State => Mstate_Lv,
- Comp => T.Type_Mode in Type_Mode_Fat,
+ Is_Composite => T.Type_Mode in Type_Mode_Fat,
K => Kind, T => T, Lv => L,
Vtype => Vtype, Ptype => Ptype));
end Lv2M;
@@ -1448,7 +1450,7 @@ package body Trans is
return Mnode is
begin
return Mnode'(M1 => (State => Mstate_Dv,
- Comp => T.Type_Mode in Type_Mode_Fat,
+ Is_Composite => T.Type_Mode in Type_Mode_Fat,
K => Kind, T => T, Dv => D,
Vtype => T.Ortho_Type (Kind),
Ptype => T.Ortho_Ptr_Type (Kind)));
@@ -1462,7 +1464,7 @@ package body Trans is
return Mnode is
begin
return Mnode'(M1 => (State => Mstate_Dv,
- Comp => T.Type_Mode in Type_Mode_Fat,
+ Is_Composite => T.Type_Mode in Type_Mode_Fat,
K => Kind, T => T, Dv => D,
Vtype => Vtype,
Ptype => Ptype));
@@ -1476,7 +1478,7 @@ package body Trans is
return Mnode is
begin
return Mnode'(M1 => (State => Mstate_Dp,
- Comp => T.Type_Mode in Type_Mode_Fat,
+ Is_Composite => T.Type_Mode in Type_Mode_Fat,
K => Kind, T => T, Dp => D,
Vtype => Vtype, Ptype => Ptype));
end Dp2M;
@@ -1487,7 +1489,7 @@ package body Trans is
return Mnode is
begin
return Mnode'(M1 => (State => Mstate_Dp,
- Comp => T.Type_Mode in Type_Mode_Fat,
+ Is_Composite => T.Type_Mode in Type_Mode_Fat,
K => Kind, T => T, Dp => D,
Vtype => T.Ortho_Type (Kind),
Ptype => T.Ortho_Ptr_Type (Kind)));
@@ -1576,7 +1578,7 @@ package body Trans is
begin
T := Get_Info (Atype);
return Mnode'(M1 => (State => Mstate_Null,
- Comp => T.Type_Mode in Type_Mode_Fat,
+ Is_Composite => T.Type_Mode in Type_Mode_Fat,
K => Kind, T => T,
Vtype => T.Ortho_Type (Kind),
Ptype => T.Ortho_Ptr_Type (Kind)));
@@ -1641,7 +1643,7 @@ package body Trans is
when Mstate_Dv =>
return New_Address (New_Obj (M.M1.Dv), M.M1.Ptype);
when Mstate_E =>
- if M.M1.Comp then
+ if M.M1.Is_Composite then
return M.M1.E;
else
raise Internal_Error;
diff --git a/src/vhdl/translate/trans.ads b/src/vhdl/translate/trans.ads
index 7e4593c..7156a48 100644
--- a/src/vhdl/translate/trans.ads
+++ b/src/vhdl/translate/trans.ads
@@ -168,6 +168,21 @@ package Trans is
type Allocation_Kind is
(Alloc_Stack, Alloc_Return, Alloc_Heap, Alloc_System);
+ -- Return the value of field FIELD of lnode L that is contains
+ -- a pointer to a record.
+ -- This is equivalent to:
+ -- new_value (new_selected_element (new_access_element (new_value (l)),
+ -- field))
+ function New_Value_Selected_Acc_Value (L : O_Lnode; Field : O_Fnode)
+ return O_Enode;
+ function New_Selected_Acc_Value (L : O_Lnode; Field : O_Fnode)
+ return O_Lnode;
+
+ function New_Indexed_Acc_Value (L : O_Lnode; I : O_Enode) return O_Lnode;
+
+ -- Equivalent to new_access_element (new_value (l))
+ function New_Acc_Value (L : O_Lnode) return O_Lnode;
+
package Chap10 is
-- There are three data storage kind: global, local or instance.
-- For example, a constant can have:
@@ -1359,8 +1374,54 @@ package Trans is
subtype Design_File_Info_Acc is Ortho_Info_Acc (Kind_Design_File);
subtype Library_Info_Acc is Ortho_Info_Acc (Kind_Library);
- -- In order to simplify the handling of Enode/Lnode, let's introduce
- -- Mnode (yes, another node).
+ procedure Init_Node_Infos;
+ procedure Update_Node_Infos;
+ procedure Free_Node_Infos;
+
+ procedure Set_Info (Target : Iir; Info : Ortho_Info_Acc);
+
+ procedure Clear_Info (Target : Iir);
+
+ function Get_Info (Target : Iir) return Ortho_Info_Acc;
+ pragma Inline (Get_Info);
+
+ -- Create an ortho_info field of kind KIND for iir node TARGET, and
+ -- return it.
+ function Add_Info (Target : Iir; Kind : Ortho_Info_Kind)
+ return Ortho_Info_Acc;
+
+ procedure Free_Info (Target : Iir);
+
+ procedure Free_Type_Info (Info : in out Type_Info_Acc);
+
+ procedure Set_Ortho_Expr (Target : Iir; Expr : O_Cnode);
+
+ function Get_Ortho_Expr (Target : Iir) return O_Cnode;
+
+ function Get_Ortho_Type (Target : Iir; Is_Sig : Object_Kind_Type)
+ return O_Tnode;
+
+ -- Return true is INFO is a type info for a composite type, ie:
+ -- * a record
+ -- * an array (fat or thin)
+ -- * a fat pointer.
+ function Is_Composite (Info : Type_Info_Acc) return Boolean;
+ pragma Inline (Is_Composite);
+
+ function Is_Complex_Type (Tinfo : Type_Info_Acc) return Boolean;
+ pragma Inline (Is_Complex_Type);
+
+ type Hexstr_Type is array (Integer range 0 .. 15) of Character;
+ N2hex : constant Hexstr_Type := "0123456789abcdef";
+
+ -- In order to unify and have a common handling of Enode/Lnode/Dnode,
+ -- let's introduce Mnode (yes, another node).
+ --
+ -- Mnodes can be converted to Enode/Lnode via the M2xx functions. If
+ -- an Mnode are referenced more than once, they must be stabilized (this
+ -- will create a new variable if needed as Enode and Lnode can be
+ -- referenced only once).
+ --
-- An Mnode is a typed union, containing either an Lnode or a Enode.
-- See Mstate for a description of the union.
-- The real data is contained insisde a record, so that the discriminant
@@ -1399,7 +1460,7 @@ package Trans is
type Mnode1 (State : Mstate := Mstate_Bad) is record
-- True if the object is composite (its value cannot be read directly).
- Comp : Boolean;
+ Is_Composite : Boolean;
-- Additionnal informations about the objects: kind and type.
K : Object_Kind_Type;
@@ -1435,7 +1496,7 @@ package Trans is
-- Null Mnode.
Mnode_Null : constant Mnode := Mnode'(M1 => (State => Mstate_Null,
- Comp => False,
+ Is_Composite => False,
K => Mode_Value,
Ptype => O_Tnode_Null,
Vtype => O_Tnode_Null,
@@ -1466,97 +1527,42 @@ package Trans is
Kind : Object_Kind_Type := Mode_Value)
return Mnode;
- -- Return the value of field FIELD of lnode L that is contains
- -- a pointer to a record.
- -- This is equivalent to:
- -- new_value (new_selected_element (new_access_element (new_value (l)),
- -- field))
- function New_Value_Selected_Acc_Value (L : O_Lnode; Field : O_Fnode)
- return O_Enode;
- function New_Selected_Acc_Value (L : O_Lnode; Field : O_Fnode)
- return O_Lnode;
-
- function New_Indexed_Acc_Value (L : O_Lnode; I : O_Enode) return O_Lnode;
-
- -- Equivalent to new_access_element (new_value (l))
- function New_Acc_Value (L : O_Lnode) return O_Lnode;
-
- procedure Init_Node_Infos;
- procedure Update_Node_Infos;
- procedure Free_Node_Infos;
-
- procedure Set_Info (Target : Iir; Info : Ortho_Info_Acc);
-
- procedure Clear_Info (Target : Iir);
-
- function Get_Info (Target : Iir) return Ortho_Info_Acc;
- pragma Inline (Get_Info);
-
- -- Create an ortho_info field of kind KIND for iir node TARGET, and
- -- return it.
- function Add_Info (Target : Iir; Kind : Ortho_Info_Kind)
- return Ortho_Info_Acc;
-
- procedure Free_Info (Target : Iir);
-
- procedure Free_Type_Info (Info : in out Type_Info_Acc);
-
- procedure Set_Ortho_Expr (Target : Iir; Expr : O_Cnode);
-
- function Get_Ortho_Expr (Target : Iir) return O_Cnode;
-
- function Get_Ortho_Type (Target : Iir; Is_Sig : Object_Kind_Type)
- return O_Tnode;
-
- -- Return true is INFO is a type info for a composite type, ie:
- -- * a record
- -- * an array (fat or thin)
- -- * a fat pointer.
- function Is_Composite (Info : Type_Info_Acc) return Boolean;
- pragma Inline (Is_Composite);
-
- function Is_Complex_Type (Tinfo : Type_Info_Acc) return Boolean;
- pragma Inline (Is_Complex_Type);
-
- type Hexstr_Type is array (Integer range 0 .. 15) of Character;
- N2hex : constant Hexstr_Type := "0123456789abcdef";
-
function Get_Type_Info (M : Mnode) return Type_Info_Acc;
pragma Inline (Get_Type_Info);
function E2M (E : O_Enode; T : Type_Info_Acc; Kind : Object_Kind_Type)
- return Mnode;
+ return Mnode;
function Lv2M (L : O_Lnode; T : Type_Info_Acc; Kind : Object_Kind_Type)
- return Mnode;
+ return Mnode;
+
function Lv2M (L : O_Lnode;
+ T : Type_Info_Acc;
+ Kind : Object_Kind_Type;
Comp : Boolean;
Vtype : O_Tnode;
- Ptype : O_Tnode;
- T : Type_Info_Acc; Kind : Object_Kind_Type)
- return Mnode;
+ Ptype : O_Tnode)
+ return Mnode;
function Lv2M (L : O_Lnode;
T : Type_Info_Acc;
Kind : Object_Kind_Type;
Vtype : O_Tnode;
Ptype : O_Tnode)
- return Mnode;
+ return Mnode;
function Lp2M (L : O_Lnode; T : Type_Info_Acc; Kind : Object_Kind_Type)
- return Mnode;
+ return Mnode;
function Lp2M (L : O_Lnode;
T : Type_Info_Acc;
Kind : Object_Kind_Type;
Vtype : O_Tnode;
Ptype : O_Tnode)
- return Mnode;
+ return Mnode;
- function Dv2M (D : O_Dnode;
- T : Type_Info_Acc;
- Kind : Object_Kind_Type)
- return Mnode;
+ function Dv2M (D : O_Dnode; T : Type_Info_Acc; Kind : Object_Kind_Type)
+ return Mnode;
function Dv2M (D : O_Dnode;
T : Type_Info_Acc;
@@ -1572,10 +1578,8 @@ package Trans is
Ptype : O_Tnode)
return Mnode;
- function Dp2M (D : O_Dnode;
- T : Type_Info_Acc;
- Kind : Object_Kind_Type)
- return Mnode;
+ function Dp2M (D : O_Dnode; T : Type_Info_Acc; Kind : Object_Kind_Type)
+ return Mnode;
function M2Lv (M : Mnode) return O_Lnode;
@@ -1630,8 +1634,20 @@ package Trans is
-- Generate code to exit from loop LABEL iff COND is true.
procedure Gen_Exit_When (Label : O_Snode; Cond : O_Enode);
- -- Create a region for temporary variables.
+ -- Create a region for temporary variables. The region is only created
+ -- on demand (at the first Create_Temp*), so you must be careful not
+ -- to nest with control statement. For example, the following
+ -- sequence is not correct:
+ -- Open_Temp
+ -- Start_If_Stmt
+ -- ... Create_Temp ...
+ -- Finish_If_Stmt
+ -- Close_Temp
+ -- Because the first Create_Temp is within the if statement, the
+ -- declare block will be created within the if statement, and must
+ -- have been closed before the end of the if statement.
procedure Open_Temp;
+
-- Create a temporary variable.
function Create_Temp (Atype : O_Tnode) return O_Dnode;
-- Create a temporary variable of ATYPE and initialize it with VALUE.
@@ -1648,6 +1664,7 @@ package Trans is
-- Add ATYPE in the chain of types to be destroyed at the end of the
-- temp scope.
procedure Add_Transient_Type_In_Temp (Atype : Iir);
+
-- Close the temporary region.
procedure Close_Temp;