summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Gingold2014-12-16 11:43:55 +0100
committerTristan Gingold2014-12-16 11:43:55 +0100
commit7536206f05e52657f972cfbb35bed45615048b69 (patch)
tree1db5e5973254cf55410acf39d79ada515047871c
parent2e968e60ccadeebd1186dca7286d34bbf76d7296 (diff)
downloadghdl-7536206f05e52657f972cfbb35bed45615048b69.tar.gz
ghdl-7536206f05e52657f972cfbb35bed45615048b69.tar.bz2
ghdl-7536206f05e52657f972cfbb35bed45615048b69.zip
Recognize some ieee.std_logic_1164 functions.
-rw-r--r--src/vhdl/evaluation.adb2
-rw-r--r--src/vhdl/ieee-std_logic_1164.adb149
-rw-r--r--src/vhdl/iirs.ads24
-rw-r--r--src/vhdl/translate/trans-chap7.adb2
4 files changed, 174 insertions, 3 deletions
diff --git a/src/vhdl/evaluation.adb b/src/vhdl/evaluation.adb
index 5387e6f..3bff387 100644
--- a/src/vhdl/evaluation.adb
+++ b/src/vhdl/evaluation.adb
@@ -1402,7 +1402,7 @@ package body Evaluation is
-- TODO
raise Internal_Error;
- when Iir_Predefined_None =>
+ when Iir_Predefined_Explicit =>
raise Internal_Error;
end case;
exception
diff --git a/src/vhdl/ieee-std_logic_1164.adb b/src/vhdl/ieee-std_logic_1164.adb
index b0c355b..8780bf9 100644
--- a/src/vhdl/ieee-std_logic_1164.adb
+++ b/src/vhdl/ieee-std_logic_1164.adb
@@ -36,6 +36,101 @@ package body Ieee.Std_Logic_1164 is
return Res;
end Skip_Implicit;
+ function Is_Scalar_Parameter (Inter : Iir) return Boolean is
+ begin
+ return Get_Base_Type (Get_Type (Inter)) = Std_Ulogic_Type;
+ end Is_Scalar_Parameter;
+
+ function Is_Vector_Parameter (Inter : Iir) return Boolean
+ is
+ Base_Type : constant Iir := Get_Base_Type (Get_Type (Inter));
+ begin
+ return Base_Type = Std_Ulogic_Vector_Type
+ or Base_Type = Std_Logic_Vector_Type;
+ end Is_Vector_Parameter;
+
+ -- Return True iff the profile of FUNC is: (l, r : std_ulogic)
+ function Is_Scalar_Scalar_Function (Func : Iir) return Boolean
+ is
+ Inter : constant Iir := Get_Interface_Declaration_Chain (Func);
+ Inter2 : Iir;
+ begin
+ if Get_Implicit_Definition (Func) /= Iir_Predefined_None then
+ return False;
+ end if;
+ if Inter = Null_Iir or else not Is_Scalar_Parameter (Inter) then
+ return False;
+ end if;
+ Inter2 := Get_Chain (Inter);
+ if Inter2 = Null_Iir or else not Is_Scalar_Parameter (Inter2) then
+ return False;
+ end if;
+ if Get_Chain (Inter2) /= Null_Iir then
+ return False;
+ end if;
+
+ return True;
+ end Is_Scalar_Scalar_Function;
+
+ -- Return True iff the profile of FUNC is: (l : std_ulogic)
+ function Is_Scalar_Function (Func : Iir) return Boolean
+ is
+ Inter : constant Iir := Get_Interface_Declaration_Chain (Func);
+ begin
+ if Get_Implicit_Definition (Func) /= Iir_Predefined_None then
+ return False;
+ end if;
+ if Inter = Null_Iir or else not Is_Scalar_Parameter (Inter) then
+ return False;
+ end if;
+ if Get_Chain (Inter) /= Null_Iir then
+ return False;
+ end if;
+
+ return True;
+ end Is_Scalar_Function;
+
+ -- Return True iff the profile of FUNC is: (l, r : std_[u]logic_vector)
+ function Is_Vector_Vector_Function (Func : Iir) return Boolean
+ is
+ Inter : constant Iir := Get_Interface_Declaration_Chain (Func);
+ Inter2 : Iir;
+ begin
+ if Get_Implicit_Definition (Func) /= Iir_Predefined_None then
+ return False;
+ end if;
+ if Inter = Null_Iir or else not Is_Vector_Parameter (Inter) then
+ return False;
+ end if;
+ Inter2 := Get_Chain (Inter);
+ if Inter2 = Null_Iir or else not Is_Vector_Parameter (Inter2) then
+ return False;
+ end if;
+ if Get_Chain (Inter2) /= Null_Iir then
+ return False;
+ end if;
+
+ return True;
+ end Is_Vector_Vector_Function;
+
+ -- Return True iff the profile of FUNC is: (l : std_[u]logic_vector)
+ function Is_Vector_Function (Func : Iir) return Boolean
+ is
+ Inter : constant Iir := Get_Interface_Declaration_Chain (Func);
+ begin
+ if Get_Implicit_Definition (Func) /= Iir_Predefined_None then
+ return False;
+ end if;
+ if Inter = Null_Iir or else not Is_Vector_Parameter (Inter) then
+ return False;
+ end if;
+ if Get_Chain (Inter) /= Null_Iir then
+ return False;
+ end if;
+
+ return True;
+ end Is_Vector_Function;
+
procedure Extract_Declarations (Pkg : Iir_Package_Declaration)
is
Error : exception;
@@ -137,6 +232,60 @@ package body Ieee.Std_Logic_1164 is
Rising_Edge := Decl;
elsif Get_Identifier (Decl) = Name_Falling_Edge then
Falling_Edge := Decl;
+ elsif Is_Scalar_Scalar_Function (Decl) then
+ declare
+ Predefined : Iir_Predefined_Functions;
+ begin
+ case Get_Identifier (Decl) is
+ when Name_And =>
+ Predefined := Iir_Predefined_Ieee_1164_Scalar_And;
+ when Name_Nand =>
+ Predefined := Iir_Predefined_Ieee_1164_Scalar_Nand;
+ when Name_Or =>
+ Predefined := Iir_Predefined_Ieee_1164_Scalar_Or;
+ when Name_Nor =>
+ Predefined := Iir_Predefined_Ieee_1164_Scalar_Nor;
+ when Name_Xor =>
+ Predefined := Iir_Predefined_Ieee_1164_Scalar_Xor;
+ when Name_Xnor =>
+ Predefined := Iir_Predefined_Ieee_1164_Scalar_Xnor;
+ when others =>
+ Predefined := Iir_Predefined_None;
+ end case;
+ Set_Implicit_Definition (Decl, Predefined);
+ end;
+ elsif Is_Scalar_Function (Decl)
+ and then Get_Identifier (Decl) = Name_Not
+ then
+ Set_Implicit_Definition
+ (Decl, Iir_Predefined_Ieee_1164_Scalar_Not);
+ elsif Is_Vector_Vector_Function (Decl) then
+ declare
+ Predefined : Iir_Predefined_Functions;
+ begin
+ case Get_Identifier (Decl) is
+ when Name_And =>
+ Predefined := Iir_Predefined_Ieee_1164_Vector_And;
+ when Name_Nand =>
+ Predefined := Iir_Predefined_Ieee_1164_Vector_Nand;
+ when Name_Or =>
+ Predefined := Iir_Predefined_Ieee_1164_Vector_Or;
+ when Name_Nor =>
+ Predefined := Iir_Predefined_Ieee_1164_Vector_Nor;
+ when Name_Xor =>
+ Predefined := Iir_Predefined_Ieee_1164_Vector_Xor;
+ when Name_Xnor =>
+ Predefined := Iir_Predefined_Ieee_1164_Vector_Xnor;
+ when others =>
+ Predefined := Iir_Predefined_None;
+ end case;
+ Set_Implicit_Definition (Decl, Predefined);
+ end;
+ elsif Is_Vector_Function (Decl)
+ and then Get_Identifier (Decl) = Name_Not
+ then
+ Set_Implicit_Definition
+ (Decl, Iir_Predefined_Ieee_1164_Vector_Not);
end if;
end if;
end loop;
diff --git a/src/vhdl/iirs.ads b/src/vhdl/iirs.ads
index 9e84c50..207dab7 100644
--- a/src/vhdl/iirs.ads
+++ b/src/vhdl/iirs.ads
@@ -1198,6 +1198,7 @@ package Iirs is
--
-- Get/Set_Chain (Field2)
--
+ -- For string, the identifier is the corresponding reserved word.
-- Get/Set_Identifier (Field3)
--
-- Get/Set_Subprogram_Hash (Field4)
@@ -3921,7 +3922,28 @@ package Iirs is
Iir_Predefined_Now_Function,
-- A not predefined and not known function. User function.
- Iir_Predefined_None
+ Iir_Predefined_None,
+
+ -- Defined in package ieee.std_logic_1164
+
+ -- Std_Ulogic operations.
+ Iir_Predefined_Ieee_1164_Scalar_And,
+ Iir_Predefined_Ieee_1164_Scalar_Nand,
+ Iir_Predefined_Ieee_1164_Scalar_Or,
+ Iir_Predefined_Ieee_1164_Scalar_Nor,
+ Iir_Predefined_Ieee_1164_Scalar_Xor,
+ Iir_Predefined_Ieee_1164_Scalar_Xnor,
+ Iir_Predefined_Ieee_1164_Scalar_Not,
+
+ -- Std_Logic_Vector or Std_Ulogic_Vector operations.
+ -- Length of the result is the length of the left operand.
+ Iir_Predefined_Ieee_1164_Vector_And,
+ Iir_Predefined_Ieee_1164_Vector_Nand,
+ Iir_Predefined_Ieee_1164_Vector_Or,
+ Iir_Predefined_Ieee_1164_Vector_Nor,
+ Iir_Predefined_Ieee_1164_Vector_Xor,
+ Iir_Predefined_Ieee_1164_Vector_Xnor,
+ Iir_Predefined_Ieee_1164_Vector_Not
);
-- Return TRUE iff FUNC is a short-cut predefined function.
diff --git a/src/vhdl/translate/trans-chap7.adb b/src/vhdl/translate/trans-chap7.adb
index bcee126..ef0e53a 100644
--- a/src/vhdl/translate/trans-chap7.adb
+++ b/src/vhdl/translate/trans-chap7.adb
@@ -5589,7 +5589,7 @@ package body Trans.Chap7 is
case Kind is
when Iir_Predefined_Error
- | Iir_Predefined_None =>
+ | Iir_Predefined_Explicit =>
raise Internal_Error;
when Iir_Predefined_Boolean_And
| Iir_Predefined_Boolean_Or