From 48546422b50cdc7847e537fa8aca249d9cbe3677 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Fri, 28 Jun 2019 18:30:30 +0200 Subject: vhdl: recognize some functions of math_real. --- src/vhdl/vhdl-ieee-math_real.adb | 58 ++++++++++++++++++++++++++++++++++++++++ src/vhdl/vhdl-ieee-math_real.ads | 24 +++++++++++++++++ src/vhdl/vhdl-ieee.adb | 3 +-- src/vhdl/vhdl-nodes.ads | 6 ++++- src/vhdl/vhdl-post_sems.adb | 3 +++ 5 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 src/vhdl/vhdl-ieee-math_real.adb create mode 100644 src/vhdl/vhdl-ieee-math_real.ads diff --git a/src/vhdl/vhdl-ieee-math_real.adb b/src/vhdl/vhdl-ieee-math_real.adb new file mode 100644 index 000000000..d62e4c246 --- /dev/null +++ b/src/vhdl/vhdl-ieee-math_real.adb @@ -0,0 +1,58 @@ +-- Nodes recognizer for ieee.math_real. +-- Copyright (C) 2019 Tristan Gingold +-- +-- GHDL 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, or (at your option) any later +-- version. +-- +-- GHDL 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 GHDL; see the file COPYING. If not, write to the Free +-- Software Foundation, 59 Temple Place - Suite 330, Boston, MA +-- 02111-1307, USA. + +with Std_Names; use Std_Names; + +package body Vhdl.Ieee.Math_Real is + procedure Extract_Declarations (Pkg : Iir_Package_Declaration) + is + Decl : Iir; + Predef : Iir_Predefined_Functions; + begin + Math_Real_Pkg := Pkg; + + Decl := Get_Declaration_Chain (Pkg); + + -- Skip a potential copyright constant. + Decl := Skip_Copyright_Notice (Decl); + + -- Skip any declarations but functions. + loop + Decl := Get_Chain (Decl); + exit when Decl = Null_Iir; + + case Get_Kind (Decl) is + when Iir_Kind_Function_Declaration => + Predef := Iir_Predefined_None; + case Get_Identifier (Decl) is + when Name_Ceil => + Predef := Iir_Predefined_Ieee_Math_Real_Ceil; + when Name_Log2 => + Predef := Iir_Predefined_Ieee_Math_Real_Log2; + when others => + null; + end case; + Set_Implicit_Definition (Decl, Predef); + when Iir_Kind_Constant_Declaration => + null; + when others => + null; + end case; + end loop; + end Extract_Declarations; +end Vhdl.Ieee.Math_Real; diff --git a/src/vhdl/vhdl-ieee-math_real.ads b/src/vhdl/vhdl-ieee-math_real.ads new file mode 100644 index 000000000..7ba1e33e8 --- /dev/null +++ b/src/vhdl/vhdl-ieee-math_real.ads @@ -0,0 +1,24 @@ +-- Nodes recognizer for ieee.math_real. +-- Copyright (C) 2019 Tristan Gingold +-- +-- GHDL 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, or (at your option) any later +-- version. +-- +-- GHDL 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 GHDL; see the file COPYING. If not, write to the Free +-- Software Foundation, 59 Temple Place - Suite 330, Boston, MA +-- 02111-1307, USA. + +package Vhdl.Ieee.Math_Real is + Math_Real_Pkg : Iir_Package_Declaration := Null_Iir; + + -- Extract declarations from PKG (ieee.math_real). + procedure Extract_Declarations (Pkg : Iir_Package_Declaration); +end Vhdl.Ieee.Math_Real; diff --git a/src/vhdl/vhdl-ieee.adb b/src/vhdl/vhdl-ieee.adb index 69d5196f0..9e861f378 100644 --- a/src/vhdl/vhdl-ieee.adb +++ b/src/vhdl/vhdl-ieee.adb @@ -20,8 +20,7 @@ with Vhdl.Utils; use Vhdl.Utils; with Vhdl.Std_Package; package body Vhdl.Ieee is - function Skip_Copyright_Notice (Decl : Iir) return Iir - is + function Skip_Copyright_Notice (Decl : Iir) return Iir is begin if Decl /= Null_Iir and then Get_Kind (Decl) = Iir_Kind_Constant_Declaration diff --git a/src/vhdl/vhdl-nodes.ads b/src/vhdl/vhdl-nodes.ads index 807069d2e..aa151c4d8 100644 --- a/src/vhdl/vhdl-nodes.ads +++ b/src/vhdl/vhdl-nodes.ads @@ -4873,7 +4873,11 @@ package Vhdl.Nodes is -- Unary functions for numeric_std Iir_Predefined_Ieee_Numeric_Std_Neg_Uns, - Iir_Predefined_Ieee_Numeric_Std_Neg_Sgn + Iir_Predefined_Ieee_Numeric_Std_Neg_Sgn, + + -- Math_Real + Iir_Predefined_Ieee_Math_Real_Ceil, + Iir_Predefined_Ieee_Math_Real_Log2 ); -- Return TRUE iff FUNC is a short-cut predefined function. diff --git a/src/vhdl/vhdl-post_sems.adb b/src/vhdl/vhdl-post_sems.adb index 4a8c96697..bcee6c47b 100644 --- a/src/vhdl/vhdl-post_sems.adb +++ b/src/vhdl/vhdl-post_sems.adb @@ -21,6 +21,7 @@ with Vhdl.Sem_Specs; with Vhdl.Ieee.Std_Logic_1164; with Vhdl.Ieee.Vital_Timing; with Vhdl.Ieee.Numeric; +with Vhdl.Ieee.Math_Real; with Flags; use Flags; package body Vhdl.Post_Sems is @@ -56,6 +57,8 @@ package body Vhdl.Post_Sems is Vhdl.Ieee.Vital_Timing.Extract_Declarations (Lib_Unit); when Name_Numeric_Std => Vhdl.Ieee.Numeric.Extract_Std_Declarations (Lib_Unit); + when Name_Math_Real => + Vhdl.Ieee.Math_Real.Extract_Declarations (Lib_Unit); when others => null; end case; -- cgit v1.2.3