aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2019-11-13 18:36:09 +0100
committerTristan Gingold <tgingold@free.fr>2019-11-13 18:36:09 +0100
commit29693dc550ad3f33e8fba23256640e849818b749 (patch)
tree00b7019a1a1784e75a8fb06b4722ce3949cb23f1
parentbd26e10bc1d31cf0a781371710ef3be46bb23a4c (diff)
downloadghdl-29693dc550ad3f33e8fba23256640e849818b749.tar.gz
ghdl-29693dc550ad3f33e8fba23256640e849818b749.tar.bz2
ghdl-29693dc550ad3f33e8fba23256640e849818b749.zip
synth: introduce synth-static_oper.
-rw-r--r--src/synth/synth-ieee-std_logic_1164.ads54
-rw-r--r--src/synth/synth-ieee.ads23
-rw-r--r--src/synth/synth-oper.adb141
-rw-r--r--src/synth/synth-static_oper.adb159
-rw-r--r--src/synth/synth-static_oper.ads31
-rw-r--r--src/synth/synth-stmts.adb10
-rw-r--r--src/synth/synth-values.adb5
7 files changed, 304 insertions, 119 deletions
diff --git a/src/synth/synth-ieee-std_logic_1164.ads b/src/synth/synth-ieee-std_logic_1164.ads
new file mode 100644
index 000000000..36ef3bc34
--- /dev/null
+++ b/src/synth/synth-ieee-std_logic_1164.ads
@@ -0,0 +1,54 @@
+-- std_logic_1164
+-- Copyright (C) 2019 Tristan Gingold
+--
+-- This file is part of GHDL.
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 2 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program; if not, write to the Free Software
+-- Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+-- MA 02110-1301, USA.
+
+package Synth.Ieee.Std_Logic_1164 is
+ -- From openieee.
+
+ -- Unresolved logic state.
+ type Std_Ulogic is
+ (
+ 'U', -- Uninitialized, this is also the default value.
+ 'X', -- Unknown / conflict value (forcing level).
+ '0', -- 0 (forcing level).
+ '1', -- 1 (forcing level).
+ 'Z', -- High impedance.
+ 'W', -- Unknown / conflict (weak level).
+ 'L', -- 0 (weak level).
+ 'H', -- 1 (weak level).
+ '-' -- Don't care.
+ );
+
+ -- type Table_1d is array (Std_Ulogic) of Std_Ulogic;
+ type Table_2d is array (Std_Ulogic, Std_Ulogic) of Std_Ulogic;
+
+ And_Table : constant Table_2d :=
+ -- UX01ZWLH-
+ ("UU0UUU0UU", -- U
+ "UX0XXX0XX", -- X
+ "000000000", -- 0
+ "UX01XX01X", -- 1
+ "UX0XXX0XX", -- Z
+ "UX0XXX0XX", -- W
+ "000000000", -- L
+ "UX01XX01X", -- H
+ "UX0XXX0XX" -- -
+ );
+
+end Synth.Ieee.Std_Logic_1164;
diff --git a/src/synth/synth-ieee.ads b/src/synth/synth-ieee.ads
new file mode 100644
index 000000000..de10c9c3d
--- /dev/null
+++ b/src/synth/synth-ieee.ads
@@ -0,0 +1,23 @@
+-- Parent package of ieee operations.
+-- Copyright (C) 2019 Tristan Gingold
+--
+-- This file is part of GHDL.
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 2 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program; if not, write to the Free Software
+-- Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+-- MA 02110-1301, USA.
+
+package Synth.Ieee is
+ pragma Pure (Synth.Ieee);
+end Synth.Ieee;
diff --git a/src/synth/synth-oper.adb b/src/synth/synth-oper.adb
index 1fe4afca6..7e063fdf7 100644
--- a/src/synth/synth-oper.adb
+++ b/src/synth/synth-oper.adb
@@ -38,6 +38,7 @@ with Synth.Stmts; use Synth.Stmts;
with Synth.Expr; use Synth.Expr;
with Synth.Source;
with Synth.Files_Operations;
+with Synth.Static_Oper; use Synth.Static_Oper;
package body Synth.Oper is
-- As log2(3m) is directly referenced, the program must be linked with -lm
@@ -260,6 +261,7 @@ package body Synth.Oper is
is
N : Net;
begin
+ -- FIXME: check same length.
N := Build_Dyadic (Build_Context, Id,
Get_Net (Left), Get_Net (Right));
Set_Location (N, Expr);
@@ -376,6 +378,11 @@ package body Synth.Oper is
Right := Synth_Subtype_Conversion (Right, Right_Typ, False, Expr);
Strip_Const (Right);
+ if Is_Const_Val (Left) and Is_Const_Val (Right) then
+ return Synth_Static_Dyadic_Predefined
+ (Syn_Inst, Imp, Left, Right, Expr);
+ end if;
+
case Def is
when Iir_Predefined_Error =>
return null;
@@ -428,10 +435,6 @@ package body Synth.Oper is
return Synth_Vec_Dyadic (Id_Xnor);
when Iir_Predefined_Enum_Equality =>
- if Is_Const (Left) and then Is_Const (Right) then
- return Create_Value_Discrete
- (Boolean'Pos (Left.Scal = Right.Scal), Boolean_Type);
- end if;
if Left_Typ = Bit_Type
or else Left_Typ = Logic_Type
then
@@ -450,10 +453,6 @@ package body Synth.Oper is
when Iir_Predefined_Array_Equality
| Iir_Predefined_Record_Equality =>
- if Is_Const (Left) and then Is_Const (Right) then
- return Create_Value_Discrete
- (Boolean'Pos (Is_Equal (Left, Right)), Boolean_Type);
- end if;
if not Is_Matching_Bounds (Left.Typ, Right.Typ) then
Warning_Msg_Synth
(+Expr,
@@ -463,10 +462,6 @@ package body Synth.Oper is
return Synth_Compare (Id_Eq);
when Iir_Predefined_Array_Inequality
| Iir_Predefined_Record_Inequality =>
- if Is_Const (Left) and then Is_Const (Right) then
- return Create_Value_Discrete
- (Boolean'Pos (not Is_Equal (Left, Right)), Boolean_Type);
- end if;
if not Is_Matching_Bounds (Left.Typ, Right.Typ) then
Warning_Msg_Synth
(+Expr,
@@ -726,124 +721,40 @@ package body Synth.Oper is
end;
end if;
when Iir_Predefined_Integer_Plus =>
- if Is_Const_Val (Left) and then Is_Const_Val (Right) then
- return Create_Value_Discrete
- (Get_Const_Discrete (Left) + Get_Const_Discrete (Right),
- Get_Value_Type (Syn_Inst, Get_Type (Expr)));
- else
- return Synth_Int_Dyadic (Id_Add);
- end if;
+ return Synth_Int_Dyadic (Id_Add);
when Iir_Predefined_Integer_Minus =>
- if Is_Const_Val (Left) and then Is_Const_Val (Right) then
- return Create_Value_Discrete
- (Get_Const_Discrete (Left) - Get_Const_Discrete (Right),
- Get_Value_Type (Syn_Inst, Get_Type (Expr)));
- else
- return Synth_Int_Dyadic (Id_Sub);
- end if;
+ return Synth_Int_Dyadic (Id_Sub);
when Iir_Predefined_Integer_Mul =>
- if Is_Const (Left) and then Is_Const (Right) then
- return Create_Value_Discrete
- (Left.Scal * Right.Scal,
- Get_Value_Type (Syn_Inst, Get_Type (Expr)));
- else
- return Synth_Int_Dyadic (Id_Smul);
- end if;
+ return Synth_Int_Dyadic (Id_Smul);
when Iir_Predefined_Integer_Div =>
- if Is_Const (Left) and then Is_Const (Right) then
- return Create_Value_Discrete
- (Left.Scal / Right.Scal,
- Get_Value_Type (Syn_Inst, Get_Type (Expr)));
- else
- return Synth_Int_Dyadic (Id_Sdiv);
- end if;
+ return Synth_Int_Dyadic (Id_Sdiv);
when Iir_Predefined_Integer_Mod =>
- if Is_Const (Left) and then Is_Const (Right) then
- return Create_Value_Discrete
- (Left.Scal mod Right.Scal,
- Get_Value_Type (Syn_Inst, Get_Type (Expr)));
- else
- return Synth_Int_Dyadic (Id_Smod);
- end if;
+ return Synth_Int_Dyadic (Id_Smod);
when Iir_Predefined_Integer_Rem =>
- if Is_Const (Left) and then Is_Const (Right) then
- return Create_Value_Discrete
- (Left.Scal rem Right.Scal,
- Get_Value_Type (Syn_Inst, Get_Type (Expr)));
- else
- return Synth_Int_Dyadic (Id_Srem);
- end if;
+ return Synth_Int_Dyadic (Id_Srem);
when Iir_Predefined_Integer_Exp =>
- if Is_Const (Left) and then Is_Const (Right) then
- return Create_Value_Discrete
- (Left.Scal ** Natural (Right.Scal),
- Get_Value_Type (Syn_Inst, Get_Type (Expr)));
- else
- Error_Msg_Synth
- (+Expr, "non-constant exponentiation not supported");
- return null;
- end if;
+ Error_Msg_Synth
+ (+Expr, "non-constant exponentiation not supported");
+ return null;
when Iir_Predefined_Integer_Less_Equal =>
- if Is_Const (Left) and then Is_Const (Right) then
- return Create_Value_Discrete
- (Boolean'Pos (Left.Scal <= Right.Scal), Boolean_Type);
- else
- return Synth_Compare (Id_Sle);
- end if;
+ return Synth_Compare (Id_Sle);
when Iir_Predefined_Integer_Less =>
- if Is_Const (Left) and then Is_Const (Right) then
- return Create_Value_Discrete
- (Boolean'Pos (Left.Scal < Right.Scal), Boolean_Type);
- else
- return Synth_Compare (Id_Slt);
- end if;
+ return Synth_Compare (Id_Slt);
when Iir_Predefined_Integer_Greater_Equal =>
- if Is_Const (Left) and then Is_Const (Right) then
- return Create_Value_Discrete
- (Boolean'Pos (Left.Scal >= Right.Scal), Boolean_Type);
- else
- return Synth_Compare (Id_Sge);
- end if;
+ return Synth_Compare (Id_Sge);
when Iir_Predefined_Integer_Greater =>
- if Is_Const (Left) and then Is_Const (Right) then
- return Create_Value_Discrete
- (Boolean'Pos (Left.Scal > Right.Scal), Boolean_Type);
- else
- return Synth_Compare (Id_Sgt);
- end if;
+ return Synth_Compare (Id_Sgt);
when Iir_Predefined_Integer_Equality =>
- if Is_Const (Left) and then Is_Const (Right) then
- return Create_Value_Discrete
- (Boolean'Pos (Left.Scal = Right.Scal), Boolean_Type);
- else
- return Synth_Compare (Id_Eq);
- end if;
+ return Synth_Compare (Id_Eq);
when Iir_Predefined_Integer_Inequality =>
- if Is_Const (Left) and then Is_Const (Right) then
- return Create_Value_Discrete
- (Boolean'Pos (Left.Scal /= Right.Scal), Boolean_Type);
- else
- return Synth_Compare (Id_Ne);
- end if;
+ return Synth_Compare (Id_Ne);
when Iir_Predefined_Physical_Physical_Div =>
- if Is_Const (Left) and then Is_Const (Right) then
- return Create_Value_Discrete
- (Left.Scal / Right.Scal,
- Get_Value_Type (Syn_Inst, Get_Type (Expr)));
- else
- Error_Msg_Synth (+Expr, "non-constant division not supported");
- return null;
- end if;
+ Error_Msg_Synth (+Expr, "non-constant division not supported");
+ return null;
when Iir_Predefined_Floating_Div =>
- if Is_Const (Left) and then Is_Const (Right) then
- return Create_Value_Float
- (Left.Fp / Right.Fp,
- Get_Value_Type (Syn_Inst, Get_Type (Imp)));
- else
- Error_Msg_Synth (+Expr, "non-constant division not supported");
- return null;
- end if;
+ Error_Msg_Synth (+Expr, "non-constant division not supported");
+ return null;
when others =>
Error_Msg_Synth (+Expr, "synth_dyadic_operation: unhandled "
diff --git a/src/synth/synth-static_oper.adb b/src/synth/synth-static_oper.adb
new file mode 100644
index 000000000..efa59989b
--- /dev/null
+++ b/src/synth/synth-static_oper.adb
@@ -0,0 +1,159 @@
+-- Operations synthesis.
+-- Copyright (C) 2019 Tristan Gingold
+--
+-- This file is part of GHDL.
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 2 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program; if not, write to the Free Software
+-- Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+-- MA 02110-1301, USA.
+
+with Types; use Types;
+
+with Synth.Errors; use Synth.Errors;
+with Synth.Source; use Synth.Source;
+with Synth.Expr; use Synth.Expr;
+with Synth.Ieee.Std_Logic_1164;
+
+package body Synth.Static_Oper is
+ -- From openiee:
+
+ function Create_Res_Bound (Prev : Type_Acc) return Type_Acc is
+ begin
+ if Prev.Vbound.Dir = Iir_Downto
+ and then Prev.Vbound.Right = 0
+ then
+ -- Normalized range
+ return Prev;
+ end if;
+
+ return Create_Vec_Type_By_Length (Prev.W, Prev.Vec_El);
+ end Create_Res_Bound;
+
+ function Synth_Vector_And (L, R : Value_Acc; Loc : Syn_Src)
+ return Value_Acc
+ is
+ use Synth.Ieee.Std_Logic_1164;
+ El_Typ : constant Type_Acc := L.Typ.Vec_El;
+ Arr : Value_Array_Acc;
+ begin
+ if L.Arr.Len /= R.Arr.Len then
+ Error_Msg_Synth (+Loc, "length of operands mismatch");
+ return null;
+ end if;
+
+ Arr := Create_Value_Array (L.Arr.Len);
+ for I in Arr.V'Range loop
+ declare
+ Ls : constant Std_Ulogic :=
+ Std_Ulogic'Val (L.Arr.V (I).Scal);
+ Rs : constant Std_Ulogic :=
+ Std_Ulogic'Val (R.Arr.V (I).Scal);
+ V : constant Std_Ulogic := And_Table (Ls, Rs);
+ begin
+ Arr.V (I) := Create_Value_Discrete (Std_Ulogic'Pos (V), El_Typ);
+ end;
+ end loop;
+
+ return Create_Value_Array (Create_Res_Bound (L.Typ), Arr);
+ end Synth_Vector_And;
+
+ function Synth_Static_Dyadic_Predefined (Syn_Inst : Synth_Instance_Acc;
+ Imp : Node;
+ Left : Value_Acc;
+ Right : Value_Acc;
+ Expr : Node) return Value_Acc
+ is
+ Def : constant Iir_Predefined_Functions :=
+ Get_Implicit_Definition (Imp);
+ Res_Typ : constant Type_Acc :=
+ Get_Value_Type (Syn_Inst, Get_Type (Expr));
+ begin
+ case Def is
+ when Iir_Predefined_Error =>
+ return null;
+
+ when Iir_Predefined_Enum_Equality =>
+ return Create_Value_Discrete
+ (Boolean'Pos (Left.Scal = Right.Scal), Boolean_Type);
+
+ when Iir_Predefined_Integer_Plus =>
+ return Create_Value_Discrete
+ (Get_Const_Discrete (Left) + Get_Const_Discrete (Right),
+ Res_Typ);
+ when Iir_Predefined_Integer_Minus =>
+ return Create_Value_Discrete
+ (Get_Const_Discrete (Left) - Get_Const_Discrete (Right),
+ Res_Typ);
+ when Iir_Predefined_Integer_Mul =>
+ return Create_Value_Discrete
+ (Get_Const_Discrete (Left) * Get_Const_Discrete (Right),
+ Res_Typ);
+ when Iir_Predefined_Integer_Div =>
+ return Create_Value_Discrete
+ (Left.Scal / Right.Scal, Res_Typ);
+ when Iir_Predefined_Integer_Mod =>
+ return Create_Value_Discrete
+ (Left.Scal mod Right.Scal, Res_Typ);
+ when Iir_Predefined_Integer_Rem =>
+ return Create_Value_Discrete
+ (Left.Scal rem Right.Scal, Res_Typ);
+ when Iir_Predefined_Integer_Exp =>
+ return Create_Value_Discrete
+ (Left.Scal ** Natural (Right.Scal), Res_Typ);
+ when Iir_Predefined_Integer_Less_Equal =>
+ return Create_Value_Discrete
+ (Boolean'Pos (Left.Scal <= Right.Scal), Boolean_Type);
+ when Iir_Predefined_Integer_Less =>
+ return Create_Value_Discrete
+ (Boolean'Pos (Left.Scal < Right.Scal), Boolean_Type);
+ when Iir_Predefined_Integer_Greater_Equal =>
+ return Create_Value_Discrete
+ (Boolean'Pos (Left.Scal >= Right.Scal), Boolean_Type);
+ when Iir_Predefined_Integer_Greater =>
+ return Create_Value_Discrete
+ (Boolean'Pos (Left.Scal > Right.Scal), Boolean_Type);
+ when Iir_Predefined_Integer_Equality =>
+ return Create_Value_Discrete
+ (Boolean'Pos (Left.Scal = Right.Scal), Boolean_Type);
+ when Iir_Predefined_Integer_Inequality =>
+ return Create_Value_Discrete
+ (Boolean'Pos (Left.Scal /= Right.Scal), Boolean_Type);
+ when Iir_Predefined_Physical_Physical_Div =>
+ return Create_Value_Discrete
+ (Left.Scal / Right.Scal, Res_Typ);
+
+ when Iir_Predefined_Floating_Div =>
+ return Create_Value_Float
+ (Left.Fp / Right.Fp, Res_Typ);
+
+ when Iir_Predefined_Array_Equality
+ | Iir_Predefined_Record_Equality =>
+ return Create_Value_Discrete
+ (Boolean'Pos (Is_Equal (Left, Right)), Boolean_Type);
+ when Iir_Predefined_Array_Inequality
+ | Iir_Predefined_Record_Inequality =>
+ return Create_Value_Discrete
+ (Boolean'Pos (not Is_Equal (Left, Right)), Boolean_Type);
+
+ when Iir_Predefined_Ieee_1164_Vector_And =>
+ return Synth_Vector_And (Left, Right, Expr);
+
+ when others =>
+ Error_Msg_Synth
+ (+Expr, "synth_static_dyadic_predefined: unhandled "
+ & Iir_Predefined_Functions'Image (Def));
+ raise Internal_Error;
+ end case;
+ end Synth_Static_Dyadic_Predefined;
+end Synth.Static_Oper;
diff --git a/src/synth/synth-static_oper.ads b/src/synth/synth-static_oper.ads
new file mode 100644
index 000000000..1cf5d9e68
--- /dev/null
+++ b/src/synth/synth-static_oper.ads
@@ -0,0 +1,31 @@
+-- Operations synthesis.
+-- Copyright (C) 2019 Tristan Gingold
+--
+-- This file is part of GHDL.
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 2 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program; if not, write to the Free Software
+-- Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+-- MA 02110-1301, USA.
+
+with Synth.Values; use Synth.Values;
+with Synth.Context; use Synth.Context;
+with Vhdl.Nodes; use Vhdl.Nodes;
+
+package Synth.Static_Oper is
+ function Synth_Static_Dyadic_Predefined (Syn_Inst : Synth_Instance_Acc;
+ Imp : Node;
+ Left : Value_Acc;
+ Right : Value_Acc;
+ Expr : Node) return Value_Acc;
+end Synth.Static_Oper;
diff --git a/src/synth/synth-stmts.adb b/src/synth/synth-stmts.adb
index cd9bee0d7..70c29013c 100644
--- a/src/synth/synth-stmts.adb
+++ b/src/synth/synth-stmts.adb
@@ -451,8 +451,14 @@ package body Synth.Stmts is
Synth_Assign (Target.Obj.W, Target.Targ_Type,
Val, Target.Off, Loc);
else
- pragma Assert (Target.Off = 0);
- Assign_Value (Target.Obj, Val, Loc);
+ if not Is_Const (Val) then
+ -- Maybe the error message is too cryptic ?
+ Error_Msg_Synth
+ (+Loc, "cannot assign a net to a static value");
+ else
+ pragma Assert (Target.Off = 0);
+ Assign_Value (Target.Obj, Val, Loc);
+ end if;
end if;
when Target_Memory =>
declare
diff --git a/src/synth/synth-values.adb b/src/synth/synth-values.adb
index b36e35431..b8bd2cfad 100644
--- a/src/synth/synth-values.adb
+++ b/src/synth/synth-values.adb
@@ -89,9 +89,10 @@ package body Synth.Values is
return False;
when Value_Const =>
return True;
+ when Value_Alias =>
+ return False;
when Value_Instance
- | Value_Subtype
- | Value_Alias =>
+ | Value_Subtype =>
-- Not really a value.
raise Internal_Error;
end case;