Library of reusable VHDL components
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5043 lines
204 KiB

  1. --
  2. -- File Name: CoveragePkg.vhd
  3. -- Design Unit Name: CoveragePkg
  4. -- Revision: STANDARD VERSION
  5. --
  6. -- Maintainer: Jim Lewis email: jim@synthworks.com
  7. -- Contributor(s):
  8. -- Jim Lewis SynthWorks
  9. -- Matthias Alles Creonic. Inspired GetMinBinVal, GetMinPoint, GetCov
  10. -- Jerry Kaczynski Aldec. Inspired GetBin function
  11. -- Sebastian Dunst Inspired GetBinName function
  12. -- ... Aldec Worked on VendorCov functional coverage interface
  13. --
  14. -- Package Defines
  15. -- Functional coverage modeling utilities and data structure
  16. --
  17. -- Developed by/for:
  18. -- SynthWorks Design Inc.
  19. -- VHDL Training Classes
  20. -- 11898 SW 128th Ave. Tigard, Or 97223
  21. -- http://www.SynthWorks.com
  22. --
  23. -- Latest standard version available at:
  24. -- http://www.SynthWorks.com/downloads
  25. --
  26. -- Revision History: For more details, see CoveragePkg_release_notes.pdf
  27. -- Date Version Description
  28. -- 06/2010: 0.1 Initial revision
  29. -- 09/2010 Release in SynthWorks' VHDL Testbenches and Verification classes
  30. -- 02/2011: 1.0 Changed CoverBinType to facilitage long term support of cross coverage
  31. -- 02/2011: 1.1 Added GetMinCov, GetMaxCov, CountCovHoles, GetCovHole
  32. -- 04/2011: 2.0 Added protected type based data structure: CovPType
  33. -- 06/2011: 2.1 Removed signal based coverage modeling
  34. -- 07/2011: 2.2 Added randomization with coverage goals (AtLeast), weight, and percentage thresholds
  35. -- 11/2011: 2.2a Changed constants ALL_RANGE, ZERO_BIN, and ONE_BIN to have a 1 index
  36. -- 12/2011: 2.2b Fixed minor inconsistencies on interface declarations.
  37. -- 01/2012: 2.3 Added Function GetBin from Jerry K. Made write for RangeArrayType visible
  38. -- 01/2012: 2.4 Added Merging of bins
  39. -- 04/2013: 2013.04 Thresholding, CovTarget, Merging off by default,
  40. -- 5/2013 2013.05 Release with updated RandomPkg. Minimal changes.
  41. -- 1/2014 2014.01 Merging of Cov Models, LastIndex
  42. -- 7/2014 2014.07 Bin Naming (for requirements tracking), WriteBin with Pass/Fail, GenBin[integer_vector]
  43. -- 12/2014 2014.07a Fix memory leak in deallocate. Removed initialied pointers which can lead to leaks.
  44. -- 01/2015 2015.01 Use AlertLogPkg to count assertions and filter log messages
  45. -- 06/2015 2015.06 AddCross[CovMatrix?Type], Mirroring for WriteBin
  46. -- 01/2016 2016.01 Fixes for pure functions. Added bounds checking on ICover
  47. -- 03/2016 2016.03 Added GetBinName(Index) to retrieve a bin's name
  48. -- 11/2016 2016.11 Added VendorCovApiPkg and calls to bind it in.
  49. -- 05/2017 2017.05 Updated WriteBin name printing
  50. -- ClearCov (deprecates SetCovZero)
  51. --
  52. --
  53. -- Development Notes:
  54. -- The coverage procedures are named ICover to avoid conflicts with
  55. -- future language changes which may add cover as a keyword
  56. -- Procedure WriteBin writes each CovBin on a separate line, as such
  57. -- it was inappropriate to overload either textio write or to_string
  58. -- In the notes VHDL-2008 notes refers to
  59. -- composites with unconstrained elements
  60. --
  61. --
  62. -- Copyright (c) 2010 - 2017 by SynthWorks Design Inc. All rights reserved.
  63. --
  64. -- Verbatim copies of this source file may be used and
  65. -- distributed without restriction.
  66. --
  67. -- This source file is free software; you can redistribute it
  68. -- and/or modify it under the terms of the ARTISTIC License
  69. -- as published by The Perl Foundation; either version 2.0 of
  70. -- the License, or (at your option) any later version.
  71. --
  72. -- This source is distributed in the hope that it will be
  73. -- useful, but WITHOUT ANY WARRANTY; without even the implied
  74. -- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  75. -- PURPOSE. See the Artistic License for details.
  76. --
  77. -- You should have received a copy of the license with this source.
  78. -- If not download it from,
  79. -- http://www.perlfoundation.org/artistic_license_2_0
  80. --
  81. -- Credits:
  82. -- CovBinBaseType is inspired by a structure proposed in the
  83. -- paper "Functional Coverage - without SystemVerilog!"
  84. -- by Alan Fitch and Doug Smith. Presented at DVCon 2010
  85. -- However the approach in their paper uses entities and
  86. -- architectures where this approach relies on functions
  87. -- and procedures, so the usage models differ greatly however.
  88. --
  89. library ieee ;
  90. use ieee.std_logic_1164.all ;
  91. use ieee.numeric_std.all ;
  92. use ieee.math_real.all ;
  93. use std.textio.all ;
  94. -- comment out following 2 lines with VHDL-2008. Leave in for VHDL-2002
  95. -- library ieee_proposed ; -- remove with VHDL-2008
  96. -- use ieee_proposed.standard_additions.all ; -- remove with VHDL-2008
  97. use work.TextUtilPkg.all ;
  98. use work.TranscriptPkg.all ;
  99. use work.AlertLogPkg.all ;
  100. use work.RandomBasePkg.all ;
  101. use work.RandomPkg.all ;
  102. use work.NamePkg.all ;
  103. use work.MessagePkg.all ;
  104. use work.OsvvmGlobalPkg.all ;
  105. use work.VendorCovApiPkg.all ;
  106. package CoveragePkg is
  107. -- CovPType allocates bins that are multiples of MIN_NUM_BINS
  108. constant MIN_NUM_BINS : integer := 2**7 ; -- power of 2
  109. type RangeType is record
  110. min : integer ;
  111. max : integer ;
  112. end record ;
  113. type RangeArrayType is array (integer range <>) of RangeType ;
  114. constant ALL_RANGE : RangeArrayType := (1=>(Integer'left, Integer'right)) ;
  115. procedure write ( file f : text ; BinVal : RangeArrayType ) ;
  116. procedure write ( variable buf : inout line ; constant BinVal : in RangeArrayType) ;
  117. -- CovBinBaseType.action values.
  118. -- Note that coverage counting depends on these values
  119. constant COV_COUNT : integer := 1 ;
  120. constant COV_IGNORE : integer := 0 ;
  121. constant COV_ILLEGAL : integer := -1 ;
  122. -- type OsvvmOptionsType is (OPT_DEFAULT, FALSE, TRUE) ;
  123. alias CovOptionsType is work.OsvvmGlobalPkg.OsvvmOptionsType ;
  124. constant COV_OPT_INIT_PARM_DETECT : CovOptionsType := work.OsvvmGlobalPkg.OPT_INIT_PARM_DETECT ;
  125. -- For backward compatibility. Don't add to other packages.
  126. alias DISABLED is work.OsvvmGlobalPkg.DISABLED [return work.OsvvmGlobalPkg.OsvvmOptionsType ];
  127. alias ENABLED is work.OsvvmGlobalPkg.ENABLED [return work.OsvvmGlobalPkg.OsvvmOptionsType ];
  128. -- Deprecated
  129. -- Used for easy manual entry. Order: min, max, action
  130. -- Intentionally did not use a record to allow other input
  131. -- formats in the future with VHDL-2008 unconstrained arrays
  132. -- of unconstrained elements
  133. -- type CovBinManualType is array (natural range <>) of integer_vector(0 to 2) ;
  134. type CovBinBaseType is record
  135. BinVal : RangeArrayType(1 to 1) ;
  136. Action : integer ;
  137. Count : integer ;
  138. AtLeast : integer ;
  139. Weight : integer ;
  140. end record ;
  141. type CovBinType is array (natural range <>) of CovBinBaseType ;
  142. constant ALL_BIN : CovBinType := (0 => ( BinVal => ALL_RANGE, Action => COV_COUNT, Count => 0, AtLeast => 1, Weight => 1 )) ;
  143. constant ALL_COUNT : CovBinType := (0 => ( BinVal => ALL_RANGE, Action => COV_COUNT, Count => 0, AtLeast => 1, Weight => 1 )) ;
  144. constant ALL_ILLEGAL : CovBinType := (0 => ( BinVal => ALL_RANGE, Action => COV_ILLEGAL, Count => 0, AtLeast => 0, Weight => 0 )) ;
  145. constant ALL_IGNORE : CovBinType := (0 => ( BinVal => ALL_RANGE, Action => COV_IGNORE, Count => 0, AtLeast => 0, Weight => 0 )) ;
  146. constant ZERO_BIN : CovBinType := (0 => ( BinVal => (1=>(0,0)), Action => COV_COUNT, Count => 0, AtLeast => 1, Weight => 1 )) ;
  147. constant ONE_BIN : CovBinType := (0 => ( BinVal => (1=>(1,1)), Action => COV_COUNT, Count => 0, AtLeast => 1, Weight => 1 )) ;
  148. constant NULL_BIN : CovBinType(work.RandomPkg.NULL_RANGE_TYPE) := (others => ( BinVal => ALL_RANGE, Action => integer'high, Count => 0, AtLeast => integer'high, Weight => integer'high )) ;
  149. type CountModeType is (COUNT_FIRST, COUNT_ALL) ;
  150. type IllegalModeType is (ILLEGAL_ON, ILLEGAL_FAILURE, ILLEGAL_OFF) ;
  151. type WeightModeType is (AT_LEAST, WEIGHT, REMAIN, REMAIN_EXP, REMAIN_SCALED, REMAIN_WEIGHT ) ;
  152. -- In VHDL-2008 CovMatrix?BaseType and CovMatrix?Type will be subsumed
  153. -- by CovBinBaseType and CovBinType with RangeArrayType as an unconstrained array.
  154. type CovMatrix2BaseType is record
  155. BinVal : RangeArrayType(1 to 2) ;
  156. Action : integer ;
  157. Count : integer ;
  158. AtLeast : integer ;
  159. Weight : integer ;
  160. end record ;
  161. type CovMatrix2Type is array (natural range <>) of CovMatrix2BaseType ;
  162. type CovMatrix3BaseType is record
  163. BinVal : RangeArrayType(1 to 3) ;
  164. Action : integer ;
  165. Count : integer ;
  166. AtLeast : integer ;
  167. Weight : integer ;
  168. end record ;
  169. type CovMatrix3Type is array (natural range <>) of CovMatrix3BaseType ;
  170. type CovMatrix4BaseType is record
  171. BinVal : RangeArrayType(1 to 4) ;
  172. Action : integer ;
  173. Count : integer ;
  174. AtLeast : integer ;
  175. Weight : integer ;
  176. end record ;
  177. type CovMatrix4Type is array (natural range <>) of CovMatrix4BaseType ;
  178. type CovMatrix5BaseType is record
  179. BinVal : RangeArrayType(1 to 5) ;
  180. Action : integer ;
  181. Count : integer ;
  182. AtLeast : integer ;
  183. Weight : integer ;
  184. end record ;
  185. type CovMatrix5Type is array (natural range <>) of CovMatrix5BaseType ;
  186. type CovMatrix6BaseType is record
  187. BinVal : RangeArrayType(1 to 6) ;
  188. Action : integer ;
  189. Count : integer ;
  190. AtLeast : integer ;
  191. Weight : integer ;
  192. end record ;
  193. type CovMatrix6Type is array (natural range <>) of CovMatrix6BaseType ;
  194. type CovMatrix7BaseType is record
  195. BinVal : RangeArrayType(1 to 7) ;
  196. Action : integer ;
  197. Count : integer ;
  198. AtLeast : integer ;
  199. Weight : integer ;
  200. end record ;
  201. type CovMatrix7Type is array (natural range <>) of CovMatrix7BaseType ;
  202. type CovMatrix8BaseType is record
  203. BinVal : RangeArrayType(1 to 8) ;
  204. Action : integer ;
  205. Count : integer ;
  206. AtLeast : integer ;
  207. Weight : integer ;
  208. end record ;
  209. type CovMatrix8Type is array (natural range <>) of CovMatrix8BaseType ;
  210. type CovMatrix9BaseType is record
  211. BinVal : RangeArrayType(1 to 9) ;
  212. Action : integer ;
  213. Count : integer ;
  214. AtLeast : integer ;
  215. Weight : integer ;
  216. end record ;
  217. type CovMatrix9Type is array (natural range <>) of CovMatrix9BaseType ;
  218. ------------------------------------------------------------ VendorCov
  219. -- VendorCov Conversion for Vendor supported functional coverage modeling
  220. function ToVendorCovBinVal (BinVal : RangeArrayType) return VendorCovRangeArrayType ;
  221. ------------------------------------------------------------
  222. function ToMinPoint (A : RangeArrayType) return integer ;
  223. function ToMinPoint (A : RangeArrayType) return integer_vector ;
  224. -- BinVal to Minimum Point
  225. ------------------------------------------------------------
  226. procedure ToRandPoint(
  227. -- BinVal to Random Point
  228. -- better as a function, however, inout not supported on functions
  229. ------------------------------------------------------------
  230. variable RV : inout RandomPType ;
  231. constant BinVal : in RangeArrayType ;
  232. variable result : out integer
  233. ) ;
  234. ------------------------------------------------------------
  235. procedure ToRandPoint(
  236. -- BinVal to Random Point
  237. ------------------------------------------------------------
  238. variable RV : inout RandomPType ;
  239. constant BinVal : in RangeArrayType ;
  240. variable result : out integer_vector
  241. ) ;
  242. ------------------------------------------------------------------------------------------
  243. -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CovPType XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  244. -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CovPType XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  245. -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CovPType XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  246. ------------------------------------------------------------------------------------------
  247. type CovPType is protected
  248. procedure FileOpenWriteBin (FileName : string; OpenKind : File_Open_Kind ) ;
  249. procedure FileCloseWriteBin ;
  250. procedure SetAlertLogID (A : AlertLogIDType) ;
  251. procedure SetAlertLogID(Name : string ; ParentID : AlertLogIDType := ALERTLOG_BASE_ID ; CreateHierarchy : Boolean := TRUE) ;
  252. impure function GetAlertLogID return AlertLogIDType ;
  253. -- procedure FileOpenWriteCovDb (FileName : string; OpenKind : File_Open_Kind ) ;
  254. -- procedure FileCloseWriteCovDb ;
  255. procedure SetIllegalMode (A : IllegalModeType) ;
  256. procedure SetWeightMode (A : WeightModeType; Scale : real := 1.0) ;
  257. procedure SetName (Name : String) ;
  258. impure function SetName (Name : String) return string ;
  259. impure function GetName return String ;
  260. impure function GetCovModelName return String ;
  261. procedure SetMessage (Message : String) ;
  262. procedure DeallocateName ; -- clear name
  263. procedure DeallocateMessage ; -- clear message
  264. procedure SetThresholding(A : boolean := TRUE ) ; -- 2.5
  265. procedure SetCovThreshold (Percent : real) ;
  266. procedure SetCovTarget (Percent : real) ; -- 2.5
  267. impure function GetCovTarget return real ; -- 2.5
  268. procedure SetMerging(A : boolean := TRUE ) ; -- 2.5
  269. procedure SetCountMode (A : CountModeType) ;
  270. procedure InitSeed (S : string ) ;
  271. impure function InitSeed (S : string ) return string ;
  272. procedure InitSeed (I : integer ) ;
  273. procedure SetSeed (RandomSeedIn : RandomSeedType ) ;
  274. impure function GetSeed return RandomSeedType ;
  275. ------------------------------------------------------------
  276. procedure SetReportOptions (
  277. WritePassFail : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  278. WriteBinInfo : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  279. WriteCount : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  280. WriteAnyIllegal : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  281. WritePrefix : string := OSVVM_STRING_INIT_PARM_DETECT ;
  282. PassName : string := OSVVM_STRING_INIT_PARM_DETECT ;
  283. FailName : string := OSVVM_STRING_INIT_PARM_DETECT
  284. ) ;
  285. procedure SetBinSize (NewNumBins : integer) ;
  286. ------------------------------------------------------------
  287. procedure AddBins (
  288. ------------------------------------------------------------
  289. Name : String ;
  290. AtLeast : integer ;
  291. Weight : integer ;
  292. CovBin : CovBinType
  293. ) ;
  294. procedure AddBins ( Name : String ; AtLeast : integer ; CovBin : CovBinType ) ;
  295. procedure AddBins ( Name : String ; CovBin : CovBinType) ;
  296. procedure AddBins ( AtLeast : integer ; Weight : integer ; CovBin : CovBinType ) ;
  297. procedure AddBins ( AtLeast : integer ; CovBin : CovBinType ) ;
  298. procedure AddBins ( CovBin : CovBinType ) ;
  299. ------------------------------------------------------------
  300. procedure AddCross(
  301. ------------------------------------------------------------
  302. Name : string ;
  303. AtLeast : integer ;
  304. Weight : integer ;
  305. Bin1, Bin2 : CovBinType ;
  306. Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11, Bin12, Bin13,
  307. Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  308. ) ;
  309. ------------------------------------------------------------
  310. procedure AddCross(
  311. Name : string ;
  312. AtLeast : integer ;
  313. Bin1, Bin2 : CovBinType ;
  314. Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11, Bin12, Bin13,
  315. Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  316. ) ;
  317. ------------------------------------------------------------
  318. procedure AddCross(
  319. Name : string ;
  320. Bin1, Bin2 : CovBinType ;
  321. Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11, Bin12, Bin13,
  322. Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  323. ) ;
  324. ------------------------------------------------------------
  325. procedure AddCross(
  326. AtLeast : integer ;
  327. Weight : integer ;
  328. Bin1, Bin2 : CovBinType ;
  329. Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11, Bin12, Bin13,
  330. Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  331. ) ;
  332. ------------------------------------------------------------
  333. procedure AddCross(
  334. AtLeast : integer ;
  335. Bin1, Bin2 : CovBinType ;
  336. Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11, Bin12, Bin13,
  337. Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  338. ) ;
  339. ------------------------------------------------------------
  340. procedure AddCross(
  341. Bin1, Bin2 : CovBinType ;
  342. Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11, Bin12, Bin13,
  343. Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  344. ) ;
  345. procedure Deallocate ;
  346. procedure ICoverLast ;
  347. procedure ICover( CovPoint : integer) ;
  348. procedure ICover( CovPoint : integer_vector) ;
  349. procedure ClearCov ;
  350. procedure SetCovZero ;
  351. impure function IsInitialized return boolean ;
  352. impure function GetNumBins return integer ;
  353. impure function GetMinIndex return integer ;
  354. impure function GetMinCov return real ; -- PercentCov
  355. impure function GetMinCount return integer ; -- Count
  356. impure function GetMaxIndex return integer ;
  357. impure function GetMaxCov return real ; -- PercentCov
  358. impure function GetMaxCount return integer ; -- Count
  359. impure function CountCovHoles ( PercentCov : real ) return integer ;
  360. impure function CountCovHoles return integer ;
  361. impure function IsCovered return boolean ;
  362. impure function IsCovered ( PercentCov : real ) return boolean ;
  363. impure function GetCov ( PercentCov : real ) return real ;
  364. impure function GetCov return real ; -- PercentCov of entire model/all bins
  365. impure function GetItemCount return integer ;
  366. impure function GetTotalCovGoal ( PercentCov : real ) return integer ;
  367. impure function GetTotalCovGoal return integer ;
  368. impure function GetLastIndex return integer ;
  369. -- Return BinVal
  370. impure function GetBinVal ( BinIndex : integer ) return RangeArrayType ;
  371. impure function GetLastBinVal return RangeArrayType ;
  372. impure function RandCovBinVal ( PercentCov : real ) return RangeArrayType ;
  373. impure function RandCovBinVal return RangeArrayType ;
  374. impure function GetMinBinVal return RangeArrayType ;
  375. impure function GetMaxBinVal return RangeArrayType ;
  376. impure function GetHoleBinVal ( ReqHoleNum : integer ; PercentCov : real ) return RangeArrayType ;
  377. impure function GetHoleBinVal ( PercentCov : real ) return RangeArrayType ;
  378. impure function GetHoleBinVal ( ReqHoleNum : integer := 1 ) return RangeArrayType ;
  379. -- Return Points
  380. impure function RandCovPoint return integer ;
  381. impure function RandCovPoint ( PercentCov : real ) return integer ;
  382. impure function RandCovPoint return integer_vector ;
  383. impure function RandCovPoint ( PercentCov : real ) return integer_vector ;
  384. impure function GetPoint ( BinIndex : integer ) return integer ;
  385. impure function GetPoint ( BinIndex : integer ) return integer_vector ;
  386. impure function GetMinPoint return integer ;
  387. impure function GetMinPoint return integer_vector ;
  388. impure function GetMaxPoint return integer ;
  389. impure function GetMaxPoint return integer_vector ;
  390. -- GetBin returns an internal value of the coverage data structure
  391. -- The return value may change as the package evolves
  392. -- Use it only for debugging.
  393. -- GetBinInfo is a for development only.
  394. impure function GetBinInfo ( BinIndex : integer ) return CovBinBaseType ;
  395. impure function GetBinValLength return integer ;
  396. impure function GetBin ( BinIndex : integer ) return CovBinBaseType ;
  397. impure function GetBin ( BinIndex : integer ) return CovMatrix2BaseType ;
  398. impure function GetBin ( BinIndex : integer ) return CovMatrix3BaseType ;
  399. impure function GetBin ( BinIndex : integer ) return CovMatrix4BaseType ;
  400. impure function GetBin ( BinIndex : integer ) return CovMatrix5BaseType ;
  401. impure function GetBin ( BinIndex : integer ) return CovMatrix6BaseType ;
  402. impure function GetBin ( BinIndex : integer ) return CovMatrix7BaseType ;
  403. impure function GetBin ( BinIndex : integer ) return CovMatrix8BaseType ;
  404. impure function GetBin ( BinIndex : integer ) return CovMatrix9BaseType ;
  405. impure function GetBinName ( BinIndex : integer; DefaultName : string := "" ) return string ;
  406. ------------------------------------------------------------
  407. procedure WriteBin (
  408. WritePassFail : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  409. WriteBinInfo : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  410. WriteCount : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  411. WriteAnyIllegal : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  412. WritePrefix : string := OSVVM_STRING_INIT_PARM_DETECT ;
  413. PassName : string := OSVVM_STRING_INIT_PARM_DETECT ;
  414. FailName : string := OSVVM_STRING_INIT_PARM_DETECT
  415. ) ;
  416. ------------------------------------------------------------
  417. procedure WriteBin ( -- With LogLevel
  418. LogLevel : LogType ;
  419. WritePassFail : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  420. WriteBinInfo : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  421. WriteCount : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  422. WriteAnyIllegal : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  423. WritePrefix : string := OSVVM_STRING_INIT_PARM_DETECT ;
  424. PassName : string := OSVVM_STRING_INIT_PARM_DETECT ;
  425. FailName : string := OSVVM_STRING_INIT_PARM_DETECT
  426. ) ;
  427. ------------------------------------------------------------
  428. procedure WriteBin (
  429. FileName : string;
  430. OpenKind : File_Open_Kind := APPEND_MODE ;
  431. WritePassFail : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  432. WriteBinInfo : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  433. WriteCount : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  434. WriteAnyIllegal : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  435. WritePrefix : string := OSVVM_STRING_INIT_PARM_DETECT ;
  436. PassName : string := OSVVM_STRING_INIT_PARM_DETECT ;
  437. FailName : string := OSVVM_STRING_INIT_PARM_DETECT
  438. ) ;
  439. ------------------------------------------------------------
  440. procedure WriteBin ( -- With LogLevel
  441. LogLevel : LogType ;
  442. FileName : string;
  443. OpenKind : File_Open_Kind := APPEND_MODE ;
  444. WritePassFail : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  445. WriteBinInfo : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  446. WriteCount : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  447. WriteAnyIllegal : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  448. WritePrefix : string := OSVVM_STRING_INIT_PARM_DETECT ;
  449. PassName : string := OSVVM_STRING_INIT_PARM_DETECT ;
  450. FailName : string := OSVVM_STRING_INIT_PARM_DETECT
  451. ) ;
  452. procedure WriteCovHoles ( LogLevel : LogType := ALWAYS ) ;
  453. procedure WriteCovHoles ( PercentCov : real ) ;
  454. procedure WriteCovHoles ( LogLevel : LogType ; PercentCov : real ) ;
  455. procedure WriteCovHoles ( FileName : string; OpenKind : File_Open_Kind := APPEND_MODE ) ;
  456. procedure WriteCovHoles ( LogLevel : LogType ; FileName : string; OpenKind : File_Open_Kind := APPEND_MODE ) ;
  457. procedure WriteCovHoles ( FileName : string; PercentCov : real ; OpenKind : File_Open_Kind := APPEND_MODE ) ;
  458. procedure WriteCovHoles ( LogLevel : LogType ; FileName : string; PercentCov : real ; OpenKind : File_Open_Kind := APPEND_MODE ) ;
  459. procedure DumpBin (LogLevel : LogType := DEBUG) ; -- Development only
  460. procedure ReadCovDb (FileName : string; Merge : boolean := FALSE) ;
  461. procedure WriteCovDb (FileName : string; OpenKind : File_Open_Kind := WRITE_MODE ) ;
  462. impure function GetErrorCount return integer ;
  463. -- These support usage of cross coverage constants
  464. -- Also support the older AddBins(GenCross(...)) methodology
  465. -- which has been replaced by AddCross
  466. procedure AddCross (CovBin : CovMatrix2Type ; Name : String := "") ;
  467. procedure AddCross (CovBin : CovMatrix3Type ; Name : String := "") ;
  468. procedure AddCross (CovBin : CovMatrix4Type ; Name : String := "") ;
  469. procedure AddCross (CovBin : CovMatrix5Type ; Name : String := "") ;
  470. procedure AddCross (CovBin : CovMatrix6Type ; Name : String := "") ;
  471. procedure AddCross (CovBin : CovMatrix7Type ; Name : String := "") ;
  472. procedure AddCross (CovBin : CovMatrix8Type ; Name : String := "") ;
  473. procedure AddCross (CovBin : CovMatrix9Type ; Name : String := "") ;
  474. ------------------------------------------------------------
  475. -- Remaining are Deprecated
  476. --
  477. -- Deprecated. Replaced by SetName with multi-line support
  478. procedure SetItemName (ItemNameIn : String) ; -- deprecated
  479. -- Deprecated. Consistency across packages
  480. impure function CovBinErrCnt return integer ;
  481. -- Deprecated. Due to name changes to promote greater consistency
  482. -- Maintained for backward compatibility.
  483. -- RandCovHole replaced by RandCovBinVal
  484. impure function RandCovHole ( PercentCov : real ) return RangeArrayType ; -- Deprecated
  485. impure function RandCovHole return RangeArrayType ; -- Deprecated
  486. -- GetCovHole replaced by GetHoleBinVal
  487. impure function GetCovHole ( ReqHoleNum : integer ; PercentCov : real ) return RangeArrayType ;
  488. impure function GetCovHole ( PercentCov : real ) return RangeArrayType ;
  489. impure function GetCovHole ( ReqHoleNum : integer := 1 ) return RangeArrayType ;
  490. -- Deprecated/ Subsumed by versions with PercentCov Parameter
  491. -- Maintained for backward compatibility only and
  492. -- may be removed in the future.
  493. impure function GetMinCov return integer ;
  494. impure function GetMaxCov return integer ;
  495. impure function CountCovHoles ( AtLeast : integer ) return integer ;
  496. impure function IsCovered ( AtLeast : integer ) return boolean ;
  497. impure function RandCovBinVal ( AtLeast : integer ) return RangeArrayType ;
  498. impure function RandCovHole ( AtLeast : integer ) return RangeArrayType ; -- Deprecated
  499. impure function RandCovPoint (AtLeast : integer ) return integer ;
  500. impure function RandCovPoint (AtLeast : integer ) return integer_vector ;
  501. impure function GetHoleBinVal ( ReqHoleNum : integer ; AtLeast : integer ) return RangeArrayType ;
  502. impure function GetCovHole ( ReqHoleNum : integer ; AtLeast : integer ) return RangeArrayType ;
  503. procedure WriteCovHoles ( AtLeast : integer ) ;
  504. procedure WriteCovHoles ( LogLevel : LogType ; AtLeast : integer ) ;
  505. procedure WriteCovHoles ( FileName : string; AtLeast : integer ; OpenKind : File_Open_Kind := APPEND_MODE ) ;
  506. procedure WriteCovHoles ( LogLevel : LogType ; FileName : string; AtLeast : integer ; OpenKind : File_Open_Kind := APPEND_MODE ) ;
  507. -- Replaced by a more appropriately named AddCross
  508. procedure AddBins (CovBin : CovMatrix2Type ; Name : String := "") ;
  509. procedure AddBins (CovBin : CovMatrix3Type ; Name : String := "") ;
  510. procedure AddBins (CovBin : CovMatrix4Type ; Name : String := "") ;
  511. procedure AddBins (CovBin : CovMatrix5Type ; Name : String := "") ;
  512. procedure AddBins (CovBin : CovMatrix6Type ; Name : String := "") ;
  513. procedure AddBins (CovBin : CovMatrix7Type ; Name : String := "") ;
  514. procedure AddBins (CovBin : CovMatrix8Type ; Name : String := "") ;
  515. procedure AddBins (CovBin : CovMatrix9Type ; Name : String := "") ;
  516. end protected CovPType ;
  517. ------------------------------------------------------------------------------------------
  518. -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CovPType XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  519. -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CovPType XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  520. ------------------------------------------------------------------------------------------
  521. ------------------------------------------------------------
  522. -- Experimental. Intended primarily for development.
  523. procedure CompareBins (
  524. ------------------------------------------------------------
  525. variable Bin1 : inout CovPType ;
  526. variable Bin2 : inout CovPType ;
  527. variable ErrorCount : inout integer
  528. ) ;
  529. ------------------------------------------------------------
  530. -- Experimental. Intended primarily for development.
  531. procedure CompareBins (
  532. ------------------------------------------------------------
  533. variable Bin1 : inout CovPType ;
  534. variable Bin2 : inout CovPType
  535. ) ;
  536. --
  537. -- Support for AddBins and AddCross
  538. --
  539. ------------------------------------------------------------
  540. function GenBin(
  541. ------------------------------------------------------------
  542. AtLeast : integer ;
  543. Weight : integer ;
  544. Min, Max : integer ;
  545. NumBin : integer
  546. ) return CovBinType ;
  547. -- Each item in range in a separate CovBin
  548. function GenBin(AtLeast : integer ; Min, Max, NumBin : integer ) return CovBinType ;
  549. function GenBin(Min, Max, NumBin : integer ) return CovBinType ;
  550. function GenBin(Min, Max : integer) return CovBinType ;
  551. function GenBin(A : integer) return CovBinType ;
  552. ------------------------------------------------------------
  553. function GenBin(
  554. ------------------------------------------------------------
  555. AtLeast : integer ;
  556. Weight : integer ;
  557. A : integer_vector
  558. ) return CovBinType ;
  559. function GenBin ( AtLeast : integer ; A : integer_vector ) return CovBinType ;
  560. function GenBin ( A : integer_vector ) return CovBinType ;
  561. ------------------------------------------------------------
  562. function IllegalBin ( Min, Max, NumBin : integer ) return CovBinType ;
  563. ------------------------------------------------------------
  564. -- All items in range in a single CovBin
  565. function IllegalBin ( Min, Max : integer ) return CovBinType ;
  566. function IllegalBin ( A : integer ) return CovBinType ;
  567. -- IgnoreBin should never have an AtLeast parameter
  568. ------------------------------------------------------------
  569. function IgnoreBin (Min, Max, NumBin : integer) return CovBinType ;
  570. ------------------------------------------------------------
  571. function IgnoreBin (Min, Max : integer) return CovBinType ; -- All items in range in a single CovBin
  572. function IgnoreBin (A : integer) return CovBinType ;
  573. -- With VHDL-2008, there will be one GenCross that returns CovBinType
  574. -- and has inputs initialized to NULL_BIN - see AddCross
  575. ------------------------------------------------------------
  576. function GenCross( -- 2
  577. -- Cross existing bins
  578. -- Use AddCross for adding values directly to coverage database
  579. -- Use GenCross for constants
  580. ------------------------------------------------------------
  581. AtLeast : integer ;
  582. Weight : integer ;
  583. Bin1, Bin2 : CovBinType
  584. ) return CovMatrix2Type ;
  585. function GenCross(AtLeast : integer ; Bin1, Bin2 : CovBinType) return CovMatrix2Type ;
  586. function GenCross(Bin1, Bin2 : CovBinType) return CovMatrix2Type ;
  587. ------------------------------------------------------------
  588. function GenCross( -- 3
  589. ------------------------------------------------------------
  590. AtLeast : integer ;
  591. Weight : integer ;
  592. Bin1, Bin2, Bin3 : CovBinType
  593. ) return CovMatrix3Type ;
  594. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3 : CovBinType ) return CovMatrix3Type ;
  595. function GenCross( Bin1, Bin2, Bin3 : CovBinType ) return CovMatrix3Type ;
  596. ------------------------------------------------------------
  597. function GenCross( -- 4
  598. ------------------------------------------------------------
  599. AtLeast : integer ;
  600. Weight : integer ;
  601. Bin1, Bin2, Bin3, Bin4 : CovBinType
  602. ) return CovMatrix4Type ;
  603. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4 : CovBinType ) return CovMatrix4Type ;
  604. function GenCross( Bin1, Bin2, Bin3, Bin4 : CovBinType ) return CovMatrix4Type ;
  605. ------------------------------------------------------------
  606. function GenCross( -- 5
  607. ------------------------------------------------------------
  608. AtLeast : integer ;
  609. Weight : integer ;
  610. Bin1, Bin2, Bin3, Bin4, Bin5 : CovBinType
  611. ) return CovMatrix5Type ;
  612. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4, Bin5 : CovBinType ) return CovMatrix5Type ;
  613. function GenCross( Bin1, Bin2, Bin3, Bin4, Bin5 : CovBinType ) return CovMatrix5Type ;
  614. ------------------------------------------------------------
  615. function GenCross( -- 6
  616. ------------------------------------------------------------
  617. AtLeast : integer ;
  618. Weight : integer ;
  619. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6 : CovBinType
  620. ) return CovMatrix6Type ;
  621. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4, Bin5, Bin6 : CovBinType ) return CovMatrix6Type ;
  622. function GenCross( Bin1, Bin2, Bin3, Bin4, Bin5, Bin6 : CovBinType ) return CovMatrix6Type ;
  623. ------------------------------------------------------------
  624. function GenCross( -- 7
  625. ------------------------------------------------------------
  626. AtLeast : integer ;
  627. Weight : integer ;
  628. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7 : CovBinType
  629. ) return CovMatrix7Type ;
  630. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7 : CovBinType ) return CovMatrix7Type ;
  631. function GenCross( Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7 : CovBinType ) return CovMatrix7Type ;
  632. ------------------------------------------------------------
  633. function GenCross( -- 8
  634. ------------------------------------------------------------
  635. AtLeast : integer ;
  636. Weight : integer ;
  637. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8 : CovBinType
  638. ) return CovMatrix8Type ;
  639. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8 : CovBinType ) return CovMatrix8Type ;
  640. function GenCross( Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8 : CovBinType ) return CovMatrix8Type ;
  641. ------------------------------------------------------------
  642. function GenCross( -- 9
  643. ------------------------------------------------------------
  644. AtLeast : integer ;
  645. Weight : integer ;
  646. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9 : CovBinType
  647. ) return CovMatrix9Type ;
  648. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9 : CovBinType ) return CovMatrix9Type ;
  649. function GenCross( Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9 : CovBinType ) return CovMatrix9Type ;
  650. ------------------------------------------------------------
  651. -- Utilities. Remove if added to std.standard
  652. function to_integer ( B : boolean ) return integer ;
  653. function to_integer ( SL : std_logic ) return integer ;
  654. function to_integer_vector ( BV : boolean_vector ) return integer_vector ;
  655. function to_integer_vector ( SLV : std_logic_vector ) return integer_vector ;
  656. ------------------------------------------------------------
  657. ------------------------------------------------------------
  658. -- Deprecated: These are not part of the coverage model
  659. procedure increment( signal Count : inout integer ) ;
  660. procedure increment( signal Count : inout integer ; enable : boolean ) ;
  661. procedure increment( signal Count : inout integer ; enable : std_ulogic ) ;
  662. end package CoveragePkg ;
  663. --- ///////////////////////////////////////////////////////////////////////////
  664. --- ///////////////////////////////////////////////////////////////////////////
  665. --- ///////////////////////////////////////////////////////////////////////////
  666. package body CoveragePkg is
  667. ------------------------------------------------------------
  668. function inside (
  669. -- package local
  670. ------------------------------------------------------------
  671. CovPoint : integer_vector ;
  672. BinVal : RangeArrayType
  673. ) return boolean is
  674. alias iCovPoint : integer_vector(BinVal'range) is CovPoint ;
  675. begin
  676. for i in BinVal'range loop
  677. if not (iCovPoint(i) >= BinVal(i).min and iCovPoint(i) <= BinVal(i).max) then
  678. return FALSE ;
  679. end if ;
  680. end loop ;
  681. return TRUE ;
  682. end function inside ;
  683. ------------------------------------------------------------
  684. function inside (
  685. -- package local, used by InsertBin
  686. -- True when BinVal1 is inside BinVal2
  687. ------------------------------------------------------------
  688. BinVal1 : RangeArrayType ;
  689. BinVal2 : RangeArrayType
  690. ) return boolean is
  691. alias iBinVal2 : RangeArrayType(BinVal1'range) is BinVal2 ;
  692. begin
  693. for i in BinVal1'range loop
  694. if not (BinVal1(i).min >= iBinVal2(i).min and BinVal1(i).max <= iBinVal2(i).max) then
  695. return FALSE ;
  696. end if ;
  697. end loop ;
  698. return TRUE ;
  699. end function inside ;
  700. ------------------------------------------------------------
  701. procedure write (
  702. variable buf : inout line ;
  703. CovPoint : integer_vector
  704. ) is
  705. -- package local. called by ICover
  706. ------------------------------------------------------------
  707. alias iCovPoint : integer_vector(1 to CovPoint'length) is CovPoint ;
  708. begin
  709. write(buf, "(" & integer'image(iCovPoint(1)) ) ;
  710. for i in 2 to iCovPoint'right loop
  711. write(buf, "," & integer'image(iCovPoint(i)) ) ;
  712. end loop ;
  713. swrite(buf, ")") ;
  714. end procedure write ;
  715. ------------------------------------------------------------
  716. procedure write ( file f : text ; BinVal : RangeArrayType ) is
  717. -- called by WriteBin and WriteCovHoles
  718. ------------------------------------------------------------
  719. begin
  720. for i in BinVal'range loop
  721. if BinVal(i).min = BinVal(i).max then
  722. write(f, "(" & integer'image(BinVal(i).min) & ") " ) ;
  723. elsif (BinVal(i).min = integer'left) and (BinVal(i).max = integer'right) then
  724. write(f, "(ALL) " ) ;
  725. else
  726. write(f, "(" & integer'image(BinVal(i).min) & " to " &
  727. integer'image(BinVal(i).max) & ") " ) ;
  728. end if ;
  729. end loop ;
  730. end procedure write ;
  731. ------------------------------------------------------------
  732. procedure write (
  733. -- called by WriteBin and WriteCovHoles
  734. ------------------------------------------------------------
  735. variable buf : inout line ;
  736. constant BinVal : in RangeArrayType
  737. ) is
  738. ------------------------------------------------------------
  739. begin
  740. for i in BinVal'range loop
  741. if BinVal(i).min = BinVal(i).max then
  742. write(buf, "(" & integer'image(BinVal(i).min) & ") " ) ;
  743. elsif (BinVal(i).min = integer'left) and (BinVal(i).max = integer'right) then
  744. swrite(buf, "(ALL) " ) ;
  745. else
  746. write(buf, "(" & integer'image(BinVal(i).min) & " to " &
  747. integer'image(BinVal(i).max) & ") " ) ;
  748. end if ;
  749. end loop ;
  750. end procedure write ;
  751. ------------------------------------------------------------
  752. procedure WriteBinVal (
  753. -- package local for now
  754. ------------------------------------------------------------
  755. variable buf : inout line ;
  756. constant BinVal : in RangeArrayType
  757. ) is
  758. begin
  759. for i in BinVal'range loop
  760. write(buf, BinVal(i).min) ;
  761. write(buf, ' ') ;
  762. write(buf, BinVal(i).max) ;
  763. write(buf, ' ') ;
  764. end loop ;
  765. end procedure WriteBinVal ;
  766. ------------------------------------------------------------
  767. -- package local for now
  768. procedure read (
  769. -- if public, also create one that does not use valid flag
  770. ------------------------------------------------------------
  771. variable buf : inout line ;
  772. variable BinVal : out RangeArrayType ;
  773. variable Valid : out boolean
  774. ) is
  775. variable ReadValid : boolean ;
  776. begin
  777. for i in BinVal'range loop
  778. read(buf, BinVal(i).min, ReadValid) ;
  779. exit when not ReadValid ;
  780. read(buf, BinVal(i).max, ReadValid) ;
  781. exit when not ReadValid ;
  782. end loop ;
  783. Valid := ReadValid ;
  784. end procedure read ;
  785. -- ------------------------------------------------------------
  786. function BinLengths (
  787. -- package local, used by AddCross, GenCross
  788. -- ------------------------------------------------------------
  789. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11,
  790. Bin12, Bin13, Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  791. ) return integer_vector is
  792. variable result : integer_vector(1 to 20) := (others => 0 ) ;
  793. variable i : integer := result'left ;
  794. variable Len : integer ;
  795. begin
  796. loop
  797. case i is
  798. when 1 => Len := Bin1'length ;
  799. when 2 => Len := Bin2'length ;
  800. when 3 => Len := Bin3'length ;
  801. when 4 => Len := Bin4'length ;
  802. when 5 => Len := Bin5'length ;
  803. when 6 => Len := Bin6'length ;
  804. when 7 => Len := Bin7'length ;
  805. when 8 => Len := Bin8'length ;
  806. when 9 => Len := Bin9'length ;
  807. when 10 => Len := Bin10'length ;
  808. when 11 => Len := Bin11'length ;
  809. when 12 => Len := Bin12'length ;
  810. when 13 => Len := Bin13'length ;
  811. when 14 => Len := Bin14'length ;
  812. when 15 => Len := Bin15'length ;
  813. when 16 => Len := Bin16'length ;
  814. when 17 => Len := Bin17'length ;
  815. when 18 => Len := Bin18'length ;
  816. when 19 => Len := Bin19'length ;
  817. when 20 => Len := Bin20'length ;
  818. when others => Len := 0 ;
  819. end case ;
  820. result(i) := Len ;
  821. exit when Len = 0 ;
  822. i := i + 1 ;
  823. exit when i = 21 ;
  824. end loop ;
  825. return result(1 to (i-1)) ;
  826. end function BinLengths ;
  827. -- ------------------------------------------------------------
  828. function CalcNumCrossBins ( BinLens : integer_vector ) return integer is
  829. -- package local, used by AddCross
  830. -- ------------------------------------------------------------
  831. variable result : integer := 1 ;
  832. begin
  833. for i in BinLens'range loop
  834. result := result * BinLens(i) ;
  835. end loop ;
  836. return result ;
  837. end function CalcNumCrossBins ;
  838. -- ------------------------------------------------------------
  839. procedure IncBinIndex (
  840. -- package local, used by AddCross
  841. -- ------------------------------------------------------------
  842. variable BinIndex : inout integer_vector ;
  843. constant BinLens : in integer_vector
  844. ) is
  845. alias aBinIndex : integer_vector(1 to BinIndex'length) is BinIndex ;
  846. alias aBinLens : integer_vector(aBinIndex'range) is BinLens ;
  847. begin
  848. -- increment right most one, then if overflow, increment next
  849. -- assumes bins numbered from 1 to N. - assured by ConcatenateBins
  850. for i in aBinIndex'reverse_range loop
  851. aBinIndex(i) := aBinIndex(i) + 1 ;
  852. exit when aBinIndex(i) <= aBinLens(i) ;
  853. aBinIndex(i) := 1 ;
  854. end loop ;
  855. end procedure IncBinIndex ;
  856. -- ------------------------------------------------------------
  857. function ConcatenateBins (
  858. -- package local, used by AddCross and GenCross
  859. -- ------------------------------------------------------------
  860. BinIndex : integer_vector ;
  861. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11,
  862. Bin12, Bin13, Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  863. ) return CovBinType is
  864. alias aBin1 : CovBinType (1 to Bin1'length) is Bin1 ;
  865. alias aBin2 : CovBinType (1 to Bin2'length) is Bin2 ;
  866. alias aBin3 : CovBinType (1 to Bin3'length) is Bin3 ;
  867. alias aBin4 : CovBinType (1 to Bin4'length) is Bin4 ;
  868. alias aBin5 : CovBinType (1 to Bin5'length) is Bin5 ;
  869. alias aBin6 : CovBinType (1 to Bin6'length) is Bin6 ;
  870. alias aBin7 : CovBinType (1 to Bin7'length) is Bin7 ;
  871. alias aBin8 : CovBinType (1 to Bin8'length) is Bin8 ;
  872. alias aBin9 : CovBinType (1 to Bin9'length) is Bin9 ;
  873. alias aBin10 : CovBinType (1 to Bin10'length) is Bin10 ;
  874. alias aBin11 : CovBinType (1 to Bin11'length) is Bin11 ;
  875. alias aBin12 : CovBinType (1 to Bin12'length) is Bin12 ;
  876. alias aBin13 : CovBinType (1 to Bin13'length) is Bin13 ;
  877. alias aBin14 : CovBinType (1 to Bin14'length) is Bin14 ;
  878. alias aBin15 : CovBinType (1 to Bin15'length) is Bin15 ;
  879. alias aBin16 : CovBinType (1 to Bin16'length) is Bin16 ;
  880. alias aBin17 : CovBinType (1 to Bin17'length) is Bin17 ;
  881. alias aBin18 : CovBinType (1 to Bin18'length) is Bin18 ;
  882. alias aBin19 : CovBinType (1 to Bin19'length) is Bin19 ;
  883. alias aBin20 : CovBinType (1 to Bin20'length) is Bin20 ;
  884. alias aBinIndex : integer_vector(1 to BinIndex'length) is BinIndex ;
  885. variable result : CovBinType(aBinIndex'range) ;
  886. begin
  887. for i in aBinIndex'range loop
  888. case i is
  889. when 1 => result(i) := aBin1(aBinIndex(i)) ;
  890. when 2 => result(i) := aBin2(aBinIndex(i)) ;
  891. when 3 => result(i) := aBin3(aBinIndex(i)) ;
  892. when 4 => result(i) := aBin4(aBinIndex(i)) ;
  893. when 5 => result(i) := aBin5(aBinIndex(i)) ;
  894. when 6 => result(i) := aBin6(aBinIndex(i)) ;
  895. when 7 => result(i) := aBin7(aBinIndex(i)) ;
  896. when 8 => result(i) := aBin8(aBinIndex(i)) ;
  897. when 9 => result(i) := aBin9(aBinIndex(i)) ;
  898. when 10 => result(i) := aBin10(aBinIndex(i)) ;
  899. when 11 => result(i) := aBin11(aBinIndex(i)) ;
  900. when 12 => result(i) := aBin12(aBinIndex(i)) ;
  901. when 13 => result(i) := aBin13(aBinIndex(i)) ;
  902. when 14 => result(i) := aBin14(aBinIndex(i)) ;
  903. when 15 => result(i) := aBin15(aBinIndex(i)) ;
  904. when 16 => result(i) := aBin16(aBinIndex(i)) ;
  905. when 17 => result(i) := aBin17(aBinIndex(i)) ;
  906. when 18 => result(i) := aBin18(aBinIndex(i)) ;
  907. when 19 => result(i) := aBin19(aBinIndex(i)) ;
  908. when 20 => result(i) := aBin20(aBinIndex(i)) ;
  909. when others =>
  910. -- pure functions cannot use alert and/or print
  911. report "CoveragePkg.AddCross: More than 20 bins not supported"
  912. severity FAILURE ;
  913. end case ;
  914. end loop ;
  915. return result ;
  916. end function ConcatenateBins ;
  917. ------------------------------------------------------------
  918. function MergeState( CrossBins : CovBinType) return integer is
  919. -- package local, Used by AddCross, GenCross
  920. ------------------------------------------------------------
  921. variable resultState : integer ;
  922. begin
  923. resultState := COV_COUNT ;
  924. for i in CrossBins'range loop
  925. if CrossBins(i).action = COV_ILLEGAL then
  926. return COV_ILLEGAL ;
  927. end if ;
  928. if CrossBins(i).action = COV_IGNORE then
  929. resultState := COV_IGNORE ;
  930. end if ;
  931. end loop ;
  932. return resultState ;
  933. end function MergeState ;
  934. ------------------------------------------------------------
  935. function MergeBinVal( CrossBins : CovBinType) return RangeArrayType is
  936. -- package local, Used by AddCross, GenCross
  937. ------------------------------------------------------------
  938. alias aCrossBins : CovBinType(1 to CrossBins'length) is CrossBins ;
  939. variable BinVal : RangeArrayType(aCrossBins'range) ;
  940. begin
  941. for i in aCrossBins'range loop
  942. BinVal(i to i) := aCrossBins(i).BinVal ;
  943. end loop ;
  944. return BinVal ;
  945. end function MergeBinVal ;
  946. ------------------------------------------------------------
  947. function MergeAtLeast(
  948. -- package local, Used by AddCross, GenCross
  949. ------------------------------------------------------------
  950. Action : in integer ;
  951. AtLeast : in integer ;
  952. CrossBins : in CovBinType
  953. ) return integer is
  954. variable Result : integer := AtLeast ;
  955. begin
  956. if Action /= COV_COUNT then
  957. return 0 ;
  958. end if ;
  959. for i in CrossBins'range loop
  960. if CrossBins(i).Action = Action then
  961. Result := maximum (Result, CrossBins(i).AtLeast) ;
  962. end if ;
  963. end loop ;
  964. return result ;
  965. end function MergeAtLeast ;
  966. ------------------------------------------------------------
  967. function MergeWeight(
  968. -- package local, Used by AddCross, GenCross
  969. ------------------------------------------------------------
  970. Action : in integer ;
  971. Weight : in integer ;
  972. CrossBins : in CovBinType
  973. ) return integer is
  974. variable Result : integer := Weight ;
  975. begin
  976. if Action /= COV_COUNT then
  977. return 0 ;
  978. end if ;
  979. for i in CrossBins'range loop
  980. if CrossBins(i).Action = Action then
  981. Result := maximum (Result, CrossBins(i).Weight) ;
  982. end if ;
  983. end loop ;
  984. return result ;
  985. end function MergeWeight ;
  986. ------------------------------------------------------------ VendorCov
  987. -- VendorCov Conversion for Vendor supported functional coverage modeling
  988. function ToVendorCovBinVal (BinVal : RangeArrayType) return VendorCovRangeArrayType is
  989. ------------------------------------------------------------
  990. variable VendorCovBinVal : VendorCovRangeArrayType(BinVal'range);
  991. begin -- VendorCov
  992. for ArrIdx in BinVal'LEFT to BinVal'RIGHT loop -- VendorCov
  993. VendorCovBinVal(ArrIdx) := (min => BinVal(ArrIdx).min, -- VendorCov
  994. max => BinVal(ArrIdx).max) ; -- VendorCov
  995. end loop; -- VendorCov
  996. return VendorCovBinVal ;
  997. end function ToVendorCovBinVal ;
  998. ------------------------------------------------------------
  999. function ToMinPoint (A : RangeArrayType) return integer is
  1000. -- Used in testing
  1001. ------------------------------------------------------------
  1002. begin
  1003. return A(A'left).min ;
  1004. end function ToMinPoint ;
  1005. ------------------------------------------------------------
  1006. function ToMinPoint (A : RangeArrayType) return integer_vector is
  1007. -- Used in testing
  1008. ------------------------------------------------------------
  1009. variable result : integer_vector(A'range) ;
  1010. begin
  1011. for i in A'range loop
  1012. result(i) := A(i).min ;
  1013. end loop ;
  1014. return result ;
  1015. end function ToMinPoint ;
  1016. ------------------------------------------------------------
  1017. procedure ToRandPoint(
  1018. ------------------------------------------------------------
  1019. variable RV : inout RandomPType ;
  1020. constant BinVal : in RangeArrayType ;
  1021. variable result : out integer
  1022. ) is
  1023. begin
  1024. result := RV.RandInt(BinVal(BinVal'left).min, BinVal(BinVal'left).max) ;
  1025. end procedure ToRandPoint ;
  1026. ------------------------------------------------------------
  1027. procedure ToRandPoint(
  1028. ------------------------------------------------------------
  1029. variable RV : inout RandomPType ;
  1030. constant BinVal : in RangeArrayType ;
  1031. variable result : out integer_vector
  1032. ) is
  1033. variable VectorVal : integer_vector(BinVal'range) ;
  1034. begin
  1035. for i in BinVal'range loop
  1036. VectorVal(i) := RV.RandInt(BinVal(i).min, BinVal(i).max) ;
  1037. end loop ;
  1038. result := VectorVal ;
  1039. end procedure ToRandPoint ;
  1040. ------------------------------------------------------------
  1041. -- Local. Get first word from a string
  1042. function GetWord (Message : string) return string is
  1043. ------------------------------------------------------------
  1044. alias aMessage : string( 1 to Message'length) is Message ;
  1045. begin
  1046. for i in aMessage'range loop
  1047. if aMessage(i) = ' ' or aMessage(i) = HT then
  1048. return aMessage(1 to i-1) ;
  1049. end if ;
  1050. end loop ;
  1051. return aMessage ;
  1052. end function GetWord ;
  1053. ------------------------------------------------------------
  1054. -- Local -- long term move to MessagePkg? Used by WriteCovDb
  1055. procedure WriteMessage ( file f : text ; variable Message : inout MessagePType ) is
  1056. ------------------------------------------------------------
  1057. variable buf : line ;
  1058. begin
  1059. for i in 1 to Message.GetCount loop
  1060. write(buf, string'(Message.Get(i))) ;
  1061. writeline(f, buf) ;
  1062. end loop ;
  1063. end procedure WriteMessage ;
  1064. ------------------------------------------------------------------------------------------
  1065. -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CovPType XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  1066. -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CovPType XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  1067. -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CovPType XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  1068. ------------------------------------------------------------------------------------------
  1069. type CovPType is protected body
  1070. -- Name Data Structure
  1071. variable CovNameVar : NamePType ;
  1072. variable CovMessageVar : MessagePType ;
  1073. -- Handle into Vendor Data Structure -- VendorCov
  1074. variable VendorCovHandleVar : VendorCovHandleType := 0 ; -- VendorCov
  1075. -- CoverageBin Data Structures
  1076. type RangeArrayPtrType is access RangeArrayType ;
  1077. type CovBinBaseTempType is record
  1078. BinVal : RangeArrayPtrType ;
  1079. Action : integer ;
  1080. Count : integer ;
  1081. AtLeast : integer ;
  1082. Weight : integer ;
  1083. PercentCov : real ;
  1084. OrderCount : integer ;
  1085. Name : line ;
  1086. end record CovBinBaseTempType ;
  1087. type CovBinTempType is array (natural range <>) of CovBinBaseTempType ;
  1088. type CovBinPtrType is access CovBinTempType ;
  1089. variable CovBinPtr : CovBinPtrType ;
  1090. variable NumBins : integer := 0 ;
  1091. variable BinValLength : integer := 1 ;
  1092. variable OrderCount : integer := 0 ; -- for statistics
  1093. variable ItemCount : integer := 0 ; -- Count of randomizations
  1094. variable LastIndex : integer := 1 ; -- Index of last randomization
  1095. -- Internal Modes and Names
  1096. variable IllegalMode : IllegalModeType := ILLEGAL_ON ;
  1097. variable IllegalModeLevel : AlertType := ERROR ;
  1098. variable WeightMode : WeightModeType := AT_LEAST ;
  1099. variable WeightScale : real := 1.0 ;
  1100. variable ThresholdingEnable : boolean := FALSE ; -- thresholding disabled by default
  1101. variable CovThreshold : real := 45.0 ;
  1102. variable CovTarget : real := 100.0 ;
  1103. variable MergingEnable : boolean := FALSE ; -- merging disabled by default
  1104. variable CountMode : CountModeType := COUNT_FIRST ;
  1105. -- Randomization Variable
  1106. variable RV : RandomPType ;
  1107. variable RvSeedInit : boolean := FALSE ;
  1108. file WriteBinFile : text ;
  1109. variable WriteBinFileInit : boolean := FALSE ;
  1110. variable UsingLocalFile : boolean := FALSE ;
  1111. variable AlertLogIDVar : AlertLogIDType := OSVVM_ALERTLOG_ID ;
  1112. -- file WriteCovDbFile : text ;
  1113. -- variable WriteCovDbFileInit : boolean := FALSE ;
  1114. -- Local WriteBin and WriteCovHoles formatting settings, defaults determined by CoverageGlobals
  1115. variable WritePassFailVar : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  1116. variable WriteBinInfoVar : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  1117. variable WriteCountVar : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  1118. variable WriteAnyIllegalVar : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  1119. variable WritePrefixVar : NamePType ;
  1120. variable PassNameVar : NamePType ;
  1121. variable FailNameVar : NamePType ;
  1122. ------------------------------------------------------------
  1123. procedure FileOpenWriteBin (FileName : string; OpenKind : File_Open_Kind ) is
  1124. ------------------------------------------------------------
  1125. begin
  1126. WriteBinFileInit := TRUE ;
  1127. file_open( WriteBinFile , FileName , OpenKind );
  1128. end procedure FileOpenWriteBin ;
  1129. ------------------------------------------------------------
  1130. procedure FileCloseWriteBin is
  1131. ------------------------------------------------------------
  1132. begin
  1133. WriteBinFileInit := FALSE ;
  1134. file_close( WriteBinFile) ;
  1135. end procedure FileCloseWriteBin ;
  1136. ------------------------------------------------------------
  1137. procedure SetAlertLogID (A : AlertLogIDType) is
  1138. ------------------------------------------------------------
  1139. begin
  1140. AlertLogIDVar := A ;
  1141. end procedure SetAlertLogID ;
  1142. ------------------------------------------------------------
  1143. procedure SetAlertLogID(Name : string ; ParentID : AlertLogIDType := ALERTLOG_BASE_ID ; CreateHierarchy : Boolean := TRUE) is
  1144. ------------------------------------------------------------
  1145. begin
  1146. AlertLogIDVar := GetAlertLogID(Name, ParentID, CreateHierarchy) ;
  1147. if not RvSeedInit then -- Init seed if not initialized
  1148. RV.InitSeed(Name) ;
  1149. RvSeedInit := TRUE ;
  1150. end if ;
  1151. end procedure SetAlertLogID ;
  1152. ------------------------------------------------------------
  1153. impure function GetAlertLogID return AlertLogIDType is
  1154. ------------------------------------------------------------
  1155. begin
  1156. return AlertLogIDVar ;
  1157. end function GetAlertLogID ;
  1158. -- ------------------------------------------------------------
  1159. -- procedure FileOpen (FileName : string; OpenKind : File_Open_Kind ) is
  1160. -- ------------------------------------------------------------
  1161. -- begin
  1162. -- WriteCovDbFileInit := TRUE ;
  1163. -- file_open( WriteCovDbFile , FileName , OpenKind );
  1164. -- end procedure FileOpenWriteCovDb ;
  1165. --
  1166. -- ------------------------------------------------------------
  1167. -- procedure FileCloseWriteCovDb is
  1168. -- ------------------------------------------------------------
  1169. -- begin
  1170. -- WriteCovDbFileInit := FALSE ;
  1171. -- file_close( WriteCovDbFile );
  1172. -- end procedure FileCloseWriteCovDb ;
  1173. ------------------------------------------------------------
  1174. procedure SetName (Name : String) is
  1175. ------------------------------------------------------------
  1176. begin
  1177. CovNameVar.Set(Name) ;
  1178. -- Update if name updated after model created -- VendorCov
  1179. if IsInitialized then -- VendorCov
  1180. VendorCovSetName(VendorCovHandleVar, Name) ; -- VendorCov
  1181. end if ; -- VendorCov
  1182. if not RvSeedInit then -- Init seed if not initialized
  1183. RV.InitSeed(Name) ;
  1184. RvSeedInit := TRUE ;
  1185. end if ;
  1186. end procedure SetName ;
  1187. ------------------------------------------------------------
  1188. impure function SetName (Name : String) return string is
  1189. ------------------------------------------------------------
  1190. begin
  1191. SetName(Name) ; -- call procedure above
  1192. return Name ;
  1193. end function SetName ;
  1194. ------------------------------------------------------------
  1195. impure function GetName return String is
  1196. ------------------------------------------------------------
  1197. begin
  1198. return CovNameVar.Get("") ;
  1199. end function GetName ;
  1200. ------------------------------------------------------------
  1201. impure function GetCovModelName return String is
  1202. ------------------------------------------------------------
  1203. begin
  1204. if CovNameVar.IsSet then
  1205. -- return Name if set
  1206. return CovNameVar.Get ;
  1207. elsif AlertLogIDVar /= OSVVM_ALERTLOG_ID then
  1208. -- otherwise return AlertLogName if it is set
  1209. return GetAlertLogName(AlertLogIDVar) ;
  1210. elsif CovMessageVar.IsSet then
  1211. -- otherwise Get the first word of the Message if it is set
  1212. return GetWord(string'(CovMessageVar.Get(1))) ;
  1213. else
  1214. return "" ;
  1215. end if ;
  1216. end function GetCovModelName ;
  1217. ------------------------------------------------------------
  1218. impure function GetNamePlus(prefix, suffix : string) return String is
  1219. ------------------------------------------------------------
  1220. begin
  1221. if CovNameVar.IsSet then
  1222. -- return Name if set
  1223. return prefix & CovNameVar.Get & suffix ;
  1224. elsif AlertLogIDVar = OSVVM_ALERTLOG_ID and CovMessageVar.IsSet then
  1225. -- If AlertLogID not set, then use Message
  1226. return prefix & GetWord(string'(CovMessageVar.Get(1))) & suffix ;
  1227. else
  1228. return "" ;
  1229. end if ;
  1230. end function GetNamePlus ;
  1231. ------------------------------------------------------------
  1232. procedure SetMessage (Message : String) is
  1233. ------------------------------------------------------------
  1234. begin
  1235. CovMessageVar.Set(Message) ;
  1236. -- VendorCov update if name updated after model created
  1237. if IsInitialized then -- VendorCov
  1238. -- Refine this? If CovNameVar or AlertLogIDName is set, -- VendorCov
  1239. -- it may be set to the same name again. -- VendorCov
  1240. VendorCovSetName(VendorCovHandleVar, GetCovModelName) ; -- VendorCov
  1241. end if ; -- VendorCov
  1242. if not RvSeedInit then -- Init seed if not initialized
  1243. RV.InitSeed(Message) ;
  1244. RvSeedInit := TRUE ;
  1245. end if ;
  1246. end procedure SetMessage ;
  1247. ------------------------------------------------------------
  1248. procedure SetIllegalMode (A : IllegalModeType) is
  1249. ------------------------------------------------------------
  1250. begin
  1251. IllegalMode := A ;
  1252. if IllegalMode = ILLEGAL_FAILURE then
  1253. IllegalModeLevel := FAILURE ;
  1254. else
  1255. IllegalModeLevel := ERROR ;
  1256. end if ;
  1257. end procedure SetIllegalMode ;
  1258. ------------------------------------------------------------
  1259. procedure SetWeightMode (A : WeightModeType; Scale : real := 1.0) is
  1260. ------------------------------------------------------------
  1261. variable buf : line ;
  1262. begin
  1263. WeightMode := A ;
  1264. WeightScale := Scale ;
  1265. if (WeightMode = REMAIN_EXP) and (WeightScale > 2.0) then
  1266. Alert(AlertLogIDVar, GetNamePlus(prefix => "in ", suffix => ", ") & "CoveragePkg.SetWeightMode:" &
  1267. " WeightScale > 2.0 and large Counts can cause RandCovPoint to fail due to integer values out of range", WARNING) ;
  1268. end if ;
  1269. if (WeightScale < 1.0) and (WeightMode = REMAIN_WEIGHT or WeightMode = REMAIN_SCALED) then
  1270. Alert(AlertLogIDVar, GetNamePlus(prefix => "in ", suffix => ", ") & "CoveragePkg.SetWeightMode:" &
  1271. " WeightScale must be > 1.0 when WeightMode = REMAIN_WEIGHT or WeightMode = REMAIN_SCALED", FAILURE) ;
  1272. WeightScale := 1.0 ;
  1273. end if;
  1274. if WeightScale <= 0.0 then
  1275. Alert(AlertLogIDVar, GetNamePlus(prefix => "in ", suffix => ", ") & "CoveragePkg.SetWeightMode:" &
  1276. " WeightScale must be > 0.0", FAILURE) ;
  1277. WeightScale := 1.0 ;
  1278. end if;
  1279. end procedure SetWeightMode ;
  1280. ------------------------------------------------------------
  1281. -- pt local for now -- file formal parameter not allowed with a public method
  1282. procedure WriteBinName ( file f : text ; S : string ; Prefix : string := "%% " ) is
  1283. ------------------------------------------------------------
  1284. variable MessageCount : integer ;
  1285. variable MessageIndex : integer := 1 ;
  1286. variable buf : line ;
  1287. begin
  1288. MessageCount := CovMessageVar.GetCount ;
  1289. if MessageCount = 0 then
  1290. write(buf, Prefix & S & GetCovModelName) ; -- Print name when no message
  1291. writeline(f, buf) ;
  1292. else
  1293. if CovNameVar.IsSet then
  1294. -- Print Name if set
  1295. write(buf, Prefix & S & CovNameVar.Get) ;
  1296. elsif AlertLogIDVar /= OSVVM_ALERTLOG_ID then
  1297. -- otherwise Print AlertLogName if it is set
  1298. write(buf, Prefix & S & string'(GetAlertLogName(AlertLogIDVar))) ;
  1299. else
  1300. -- otherwise print the first line of the message
  1301. MessageIndex := 2 ;
  1302. write(buf, Prefix & S & string'(CovMessageVar.Get(1))) ;
  1303. end if ;
  1304. writeline(f, buf) ;
  1305. for i in MessageIndex to MessageCount loop
  1306. write(buf, Prefix & string'(CovMessageVar.Get(i))) ;
  1307. writeline(f, buf) ;
  1308. end loop ;
  1309. end if ;
  1310. end procedure WriteBinName ;
  1311. ------------------------------------------------------------
  1312. procedure DeallocateMessage is
  1313. ------------------------------------------------------------
  1314. begin
  1315. CovMessageVar.Deallocate ;
  1316. end procedure DeallocateMessage ;
  1317. ------------------------------------------------------------
  1318. procedure DeallocateName is
  1319. ------------------------------------------------------------
  1320. begin
  1321. CovNameVar.Clear ;
  1322. end procedure DeallocateName ;
  1323. ------------------------------------------------------------
  1324. procedure SetThresholding (A : boolean := TRUE ) is
  1325. ------------------------------------------------------------
  1326. begin
  1327. ThresholdingEnable := A ;
  1328. end procedure SetThresholding ;
  1329. ------------------------------------------------------------
  1330. procedure SetCovThreshold (Percent : real) is
  1331. ------------------------------------------------------------
  1332. begin
  1333. ThresholdingEnable := TRUE ;
  1334. if Percent >= 0.0 then
  1335. CovThreshold := Percent + 0.0001 ; -- used in less than
  1336. else
  1337. CovThreshold := 0.0001 ; -- used in less than
  1338. Alert(AlertLogIDVar, GetNamePlus(prefix => "in ", suffix => ", ") & "CoveragePkg.SetCovThreshold:" &
  1339. " Invalid Threshold Value " & real'image(Percent), FAILURE) ;
  1340. end if ;
  1341. end procedure SetCovThreshold ;
  1342. ------------------------------------------------------------
  1343. procedure SetCovTarget (Percent : real) is
  1344. ------------------------------------------------------------
  1345. begin
  1346. CovTarget := Percent ;
  1347. end procedure SetCovTarget ;
  1348. ------------------------------------------------------------
  1349. impure function GetCovTarget return real is
  1350. ------------------------------------------------------------
  1351. begin
  1352. return CovTarget ;
  1353. end function GetCovTarget ;
  1354. ------------------------------------------------------------
  1355. procedure SetMerging (A : boolean := TRUE ) is
  1356. ------------------------------------------------------------
  1357. begin
  1358. MergingEnable := A ;
  1359. end procedure SetMerging ;
  1360. ------------------------------------------------------------
  1361. procedure SetCountMode (A : CountModeType) is
  1362. ------------------------------------------------------------
  1363. begin
  1364. CountMode := A ;
  1365. end procedure SetCountMode ;
  1366. ------------------------------------------------------------
  1367. procedure InitSeed (S : string ) is
  1368. ------------------------------------------------------------
  1369. begin
  1370. RV.InitSeed(S) ;
  1371. RvSeedInit := TRUE ;
  1372. end procedure InitSeed ;
  1373. ------------------------------------------------------------
  1374. impure function InitSeed (S : string ) return string is
  1375. ------------------------------------------------------------
  1376. begin
  1377. RV.InitSeed(S) ;
  1378. RvSeedInit := TRUE ;
  1379. return S ;
  1380. end function InitSeed ;
  1381. ------------------------------------------------------------
  1382. procedure InitSeed (I : integer ) is
  1383. ------------------------------------------------------------
  1384. begin
  1385. RV.InitSeed(I) ;
  1386. RvSeedInit := TRUE ;
  1387. end procedure InitSeed ;
  1388. ------------------------------------------------------------
  1389. procedure SetSeed (RandomSeedIn : RandomSeedType ) is
  1390. ------------------------------------------------------------
  1391. begin
  1392. RV.SetSeed(RandomSeedIn) ;
  1393. RvSeedInit := TRUE ;
  1394. end procedure SetSeed ;
  1395. ------------------------------------------------------------
  1396. impure function GetSeed return RandomSeedType is
  1397. ------------------------------------------------------------
  1398. begin
  1399. return RV.GetSeed ;
  1400. end function GetSeed ;
  1401. ------------------------------------------------------------
  1402. procedure SetReportOptions (
  1403. ------------------------------------------------------------
  1404. WritePassFail : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  1405. WriteBinInfo : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  1406. WriteCount : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  1407. WriteAnyIllegal : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  1408. WritePrefix : string := OSVVM_STRING_INIT_PARM_DETECT ;
  1409. PassName : string := OSVVM_STRING_INIT_PARM_DETECT ;
  1410. FailName : string := OSVVM_STRING_INIT_PARM_DETECT
  1411. ) is
  1412. begin
  1413. if WritePassFail /= COV_OPT_INIT_PARM_DETECT then
  1414. WritePassFailVar := WritePassFail ;
  1415. end if ;
  1416. if WriteBinInfo /= COV_OPT_INIT_PARM_DETECT then
  1417. WriteBinInfoVar := WriteBinInfo ;
  1418. end if ;
  1419. if WriteCount /= COV_OPT_INIT_PARM_DETECT then
  1420. WriteCountVar := WriteCount ;
  1421. end if ;
  1422. if WriteAnyIllegal /= COV_OPT_INIT_PARM_DETECT then
  1423. WriteAnyIllegalVar := WriteAnyIllegal ;
  1424. end if ;
  1425. if WritePrefix /= OSVVM_STRING_INIT_PARM_DETECT then
  1426. WritePrefixVar.Set(WritePrefix) ;
  1427. end if ;
  1428. if PassName /= OSVVM_STRING_INIT_PARM_DETECT then
  1429. PassNameVar.Set(PassName) ;
  1430. end if ;
  1431. if FailName /= OSVVM_STRING_INIT_PARM_DETECT then
  1432. FailNameVar.Set(FailName) ;
  1433. end if ;
  1434. end procedure SetReportOptions ;
  1435. ------------------------------------------------------------
  1436. procedure SetBinSize (NewNumBins : integer) is
  1437. -- Sets a CovBin to a particular size
  1438. -- Use for small bins to save space or large bins to
  1439. -- suppress the resize and copy as a CovBin autosizes.
  1440. ------------------------------------------------------------
  1441. variable oldCovBinPtr : CovBinPtrType ;
  1442. begin
  1443. if CovBinPtr = NULL then
  1444. CovBinPtr := new CovBinTempType(1 to NewNumBins) ;
  1445. elsif NewNumBins > CovBinPtr'length then
  1446. -- make message bigger
  1447. oldCovBinPtr := CovBinPtr ;
  1448. CovBinPtr := new CovBinTempType(1 to NewNumBins) ;
  1449. CovBinPtr.all(1 to NumBins) := oldCovBinPtr.all(1 to NumBins) ;
  1450. deallocate(oldCovBinPtr) ;
  1451. end if ;
  1452. end procedure SetBinSize ;
  1453. ------------------------------------------------------------
  1454. -- pt local
  1455. procedure CheckBinValLength( CurBinValLength : integer ; Caller : string ) is
  1456. begin
  1457. if NumBins = 0 then
  1458. BinValLength := CurBinValLength ; -- number of points in cross
  1459. else
  1460. AlertIf(AlertLogIDVar, BinValLength /= CurBinValLength, GetNamePlus(prefix => "in ", suffix => ", ") & "CoveragePkg." & Caller & ":" &
  1461. " Cross coverage bins of different dimensions prohibited", FAILURE) ;
  1462. end if;
  1463. end procedure CheckBinValLength ;
  1464. ------------------------------------------------------------
  1465. -- pt local
  1466. impure function NormalizeNumBins( ReqNumBins : integer ) return integer is
  1467. variable NormNumBins : integer := MIN_NUM_BINS ;
  1468. begin
  1469. while NormNumBins < ReqNumBins loop
  1470. NormNumBins := NormNumBins + MIN_NUM_BINS ;
  1471. end loop ;
  1472. return NormNumBins ;
  1473. end function NormalizeNumBins ;
  1474. ------------------------------------------------------------
  1475. -- pt local
  1476. procedure GrowBins (ReqNumBins : integer) is
  1477. variable oldCovBinPtr : CovBinPtrType ;
  1478. variable NewNumBins : integer ;
  1479. begin
  1480. NewNumBins := NumBins + ReqNumBins ;
  1481. if CovBinPtr = NULL then
  1482. CovBinPtr := new CovBinTempType(1 to NormalizeNumBins(NewNumBins)) ;
  1483. elsif NewNumBins > CovBinPtr'length then
  1484. -- make message bigger
  1485. oldCovBinPtr := CovBinPtr ;
  1486. CovBinPtr := new CovBinTempType(1 to NormalizeNumBins(NewNumBins)) ;
  1487. CovBinPtr.all(1 to NumBins) := oldCovBinPtr.all(1 to NumBins) ;
  1488. deallocate(oldCovBinPtr) ;
  1489. end if ;
  1490. end procedure GrowBins ;
  1491. ------------------------------------------------------------
  1492. -- pt local, called by InsertBin
  1493. -- Finds index of bin if it is inside an existing bins
  1494. procedure FindBinInside(
  1495. BinVal : RangeArrayType ;
  1496. Position : out integer ;
  1497. FoundInside : out boolean
  1498. ) is
  1499. begin
  1500. Position := NumBins + 1 ;
  1501. FoundInside := FALSE ;
  1502. FindLoop : for i in NumBins downto 1 loop
  1503. -- skip this CovBin if CovPoint is not in it
  1504. next FindLoop when not inside(BinVal, CovBinPtr(i).BinVal.all) ;
  1505. Position := i ;
  1506. FoundInside := TRUE ;
  1507. exit ;
  1508. end loop ;
  1509. end procedure FindBinInside ;
  1510. ------------------------------------------------------------
  1511. -- pt local
  1512. -- Inserts values into a new bin.
  1513. -- Called by InsertBin
  1514. procedure InsertNewBin(
  1515. BinVal : RangeArrayType ;
  1516. Action : integer ;
  1517. Count : integer ;
  1518. AtLeast : integer ;
  1519. Weight : integer ;
  1520. Name : string ;
  1521. PercentCov : real := 0.0
  1522. ) is
  1523. begin
  1524. if (not IsInitialized) then -- VendorCov
  1525. if (BinVal'length > 1) then -- Cross Bin -- VendorCov
  1526. VendorCovHandleVar := VendorCovCrossCreate(GetCovModelName) ; -- VendorCov
  1527. else -- VendorCov
  1528. VendorCovHandleVar := VendorCovPointCreate(GetCovModelName); -- VendorCov
  1529. end if; -- VendorCov
  1530. end if; -- VendorCov
  1531. VendorCovBinAdd(VendorCovHandleVar, ToVendorCovBinVal(BinVal), Action, AtLeast, Name) ; -- VendorCov
  1532. NumBins := NumBins + 1 ;
  1533. CovBinPtr.all(NumBins).BinVal := new RangeArrayType'(BinVal) ;
  1534. CovBinPtr.all(NumBins).Action := Action ;
  1535. CovBinPtr.all(NumBins).Count := Count ;
  1536. CovBinPtr.all(NumBins).AtLeast := AtLeast ;
  1537. CovBinPtr.all(NumBins).Weight := Weight ;
  1538. CovBinPtr.all(NumBins).Name := new String'(Name) ;
  1539. CovBinPtr.all(NumBins).PercentCov := PercentCov ;
  1540. CovBinPtr.all(NumBins).OrderCount := 0 ; --- Metrics for evaluating randomization order Temp
  1541. end procedure InsertNewBin ;
  1542. ------------------------------------------------------------
  1543. -- pt local
  1544. -- Inserts values into a new bin.
  1545. -- Called by InsertBin
  1546. procedure MergeBin (
  1547. Position : Natural ;
  1548. Count : integer ;
  1549. AtLeast : integer ;
  1550. Weight : integer
  1551. ) is
  1552. begin
  1553. CovBinPtr.all(Position).Count := CovBinPtr.all(Position).Count + Count ;
  1554. CovBinPtr.all(Position).AtLeast := CovBinPtr.all(Position).AtLeast + AtLeast ;
  1555. CovBinPtr.all(Position).Weight := CovBinPtr.all(Position).Weight + Weight ;
  1556. CovBinPtr.all(Position).PercentCov :=
  1557. real(CovBinPtr.all(Position).Count)*100.0/maximum(real(CovBinPtr.all(Position).AtLeast), 1.0) ;
  1558. end procedure MergeBin ;
  1559. ------------------------------------------------------------
  1560. -- pt local
  1561. -- All insertion comes here
  1562. -- Enforces the general insertion use model:
  1563. -- Earlier bins supercede later bins - except with COUNT_ALL
  1564. -- Add Illegal and Ignore bins first to remove regions of larger count bins
  1565. -- Later ignore bins can be used to miss an illegal catch-all
  1566. -- Add Illegal bins last as a catch-all to find things that missed other bins
  1567. procedure InsertBin(
  1568. BinVal : RangeArrayType ;
  1569. Action : integer ;
  1570. Count : integer ;
  1571. AtLeast : integer ;
  1572. Weight : integer ;
  1573. Name : string ;
  1574. PercentCov : real := 0.0
  1575. ) is
  1576. variable Position : integer ;
  1577. variable FoundInside : boolean ;
  1578. begin
  1579. if not MergingEnable then
  1580. InsertNewBin(BinVal, Action, Count, AtLeast, Weight, Name, PercentCov) ;
  1581. else -- handle merging
  1582. -- future optimization, FindBinInside only checks against Ignore and Illegal bins
  1583. FindBinInside(BinVal, Position, FoundInside) ;
  1584. if not FoundInside then
  1585. InsertNewBin(BinVal, Action, Count, AtLeast, Weight, Name, PercentCov) ;
  1586. elsif Action = COV_COUNT then
  1587. -- when check only ignore and illegal bins, only action is to drop
  1588. if CovBinPtr.all(Position).Action /= COV_COUNT then
  1589. null ; -- drop count bin when it is inside a Illegal or Ignore bin
  1590. elsif CovBinPtr.all(Position).BinVal.all = BinVal and CovBinPtr.all(Position).Name.all = Name then
  1591. -- Bins match, so merge the count values
  1592. MergeBin (Position, Count, AtLeast, Weight) ;
  1593. else
  1594. -- Bins overlap, but do not match, insert new bin
  1595. InsertNewBin(BinVal, Action, Count, AtLeast, Weight, Name, PercentCov) ;
  1596. end if;
  1597. elsif Action = COV_IGNORE then
  1598. -- when check only ignore and illegal bins, only action is to report error
  1599. if CovBinPtr.all(Position).Action = COV_COUNT then
  1600. InsertNewBin(BinVal, Action, Count, AtLeast, Weight, Name, PercentCov) ;
  1601. else
  1602. Alert(AlertLogIDVar, GetNamePlus(prefix => "in ", suffix => ", ") & "CoveragePkg.InsertBin (AddBins/AddCross):" &
  1603. " ignore bin dropped. It is a subset of prior bin", ERROR) ;
  1604. end if;
  1605. elsif Action = COV_ILLEGAL then
  1606. -- when check only ignore and illegal bins, only action is to report error
  1607. if CovBinPtr.all(Position).Action = COV_COUNT then
  1608. InsertNewBin(BinVal, Action, Count, AtLeast, Weight, Name, PercentCov) ;
  1609. else
  1610. Alert(AlertLogIDVar, GetNamePlus(prefix => "in ", suffix => ", ") & "CoveragePkg.InsertBin (AddBins/AddCross):" &
  1611. " illegal bin dropped. It is a subset of prior bin", ERROR) ;
  1612. end if;
  1613. end if ;
  1614. end if ; -- merging enabled
  1615. end procedure InsertBin ;
  1616. ------------------------------------------------------------
  1617. procedure AddBins (
  1618. ------------------------------------------------------------
  1619. Name : String ;
  1620. AtLeast : integer ;
  1621. Weight : integer ;
  1622. CovBin : CovBinType
  1623. ) is
  1624. variable calcAtLeast : integer ;
  1625. variable calcWeight : integer ;
  1626. begin
  1627. CheckBinValLength( 1, "AddBins") ;
  1628. GrowBins(CovBin'length) ;
  1629. for i in CovBin'range loop
  1630. if CovBin(i).Action = COV_COUNT then
  1631. calcAtLeast := maximum(AtLeast, CovBin(i).AtLeast) ;
  1632. calcWeight := maximum(Weight, CovBin(i).Weight) ;
  1633. else
  1634. calcAtLeast := 0 ;
  1635. calcWeight := 0 ;
  1636. end if ;
  1637. InsertBin(
  1638. BinVal => CovBin(i).BinVal,
  1639. Action => CovBin(i).Action,
  1640. Count => CovBin(i).Count,
  1641. AtLeast => calcAtLeast,
  1642. Weight => calcWeight,
  1643. Name => Name
  1644. ) ;
  1645. end loop ;
  1646. end procedure AddBins ;
  1647. ------------------------------------------------------------
  1648. procedure AddBins ( Name : String ; AtLeast : integer ; CovBin : CovBinType ) is
  1649. ------------------------------------------------------------
  1650. begin
  1651. AddBins(Name, AtLeast, 0, CovBin) ;
  1652. end procedure AddBins ;
  1653. ------------------------------------------------------------
  1654. procedure AddBins (Name : String ; CovBin : CovBinType) is
  1655. ------------------------------------------------------------
  1656. begin
  1657. AddBins(Name, 0, 0, CovBin) ;
  1658. end procedure AddBins ;
  1659. ------------------------------------------------------------
  1660. procedure AddBins ( AtLeast : integer ; Weight : integer ; CovBin : CovBinType ) is
  1661. ------------------------------------------------------------
  1662. begin
  1663. AddBins("", AtLeast, Weight, CovBin) ;
  1664. end procedure AddBins ;
  1665. ------------------------------------------------------------
  1666. procedure AddBins ( AtLeast : integer ; CovBin : CovBinType ) is
  1667. ------------------------------------------------------------
  1668. begin
  1669. AddBins("", AtLeast, 0, CovBin) ;
  1670. end procedure AddBins ;
  1671. ------------------------------------------------------------
  1672. procedure AddBins ( CovBin : CovBinType ) is
  1673. ------------------------------------------------------------
  1674. begin
  1675. AddBins("", 0, 0, CovBin) ;
  1676. end procedure AddBins ;
  1677. ------------------------------------------------------------
  1678. procedure AddCross(
  1679. ------------------------------------------------------------
  1680. Name : string ;
  1681. AtLeast : integer ;
  1682. Weight : integer ;
  1683. Bin1, Bin2 : CovBinType ;
  1684. Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11, Bin12, Bin13,
  1685. Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  1686. ) is
  1687. constant BIN_LENS : integer_vector :=
  1688. BinLengths(
  1689. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11,
  1690. Bin12, Bin13, Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20
  1691. ) ;
  1692. constant NUM_NEW_BINS : integer := CalcNumCrossBins(BIN_LENS) ;
  1693. variable BinIndex : integer_vector(1 to BIN_LENS'length) := (others => 1) ;
  1694. variable CrossBins : CovBinType(BinIndex'range) ;
  1695. variable calcAction, calcCount, calcAtLeast, calcWeight : integer ;
  1696. variable calcBinVal : RangeArrayType(BinIndex'range) ;
  1697. begin
  1698. CheckBinValLength( BIN_LENS'length, "AddCross") ;
  1699. GrowBins(NUM_NEW_BINS) ;
  1700. calcCount := 0 ;
  1701. for MatrixIndex in 1 to NUM_NEW_BINS loop
  1702. CrossBins := ConcatenateBins(BinIndex,
  1703. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11,
  1704. Bin12, Bin13, Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20
  1705. ) ;
  1706. calcAction := MergeState(CrossBins) ;
  1707. calcBinVal := MergeBinVal(CrossBins) ;
  1708. calcAtLeast := MergeAtLeast( calcAction, AtLeast, CrossBins) ;
  1709. calcWeight := MergeWeight ( calcAction, Weight, CrossBins) ;
  1710. InsertBin(calcBinVal, calcAction, calcCount, calcAtLeast, calcWeight, Name) ;
  1711. IncBinIndex( BinIndex, BIN_LENS) ; -- increment right most one, then if overflow, increment next
  1712. end loop ;
  1713. end procedure AddCross ;
  1714. ------------------------------------------------------------
  1715. procedure AddCross(
  1716. ------------------------------------------------------------
  1717. Name : string ;
  1718. AtLeast : integer ;
  1719. Bin1, Bin2 : CovBinType ;
  1720. Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11, Bin12, Bin13,
  1721. Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  1722. ) is
  1723. begin
  1724. AddCross(Name, AtLeast, 0,
  1725. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11,
  1726. Bin12, Bin13, Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20
  1727. ) ;
  1728. end procedure AddCross ;
  1729. ------------------------------------------------------------
  1730. procedure AddCross(
  1731. ------------------------------------------------------------
  1732. Name : string ;
  1733. Bin1, Bin2 : CovBinType ;
  1734. Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11, Bin12, Bin13,
  1735. Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  1736. ) is
  1737. begin
  1738. AddCross(Name, 0, 0,
  1739. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11,
  1740. Bin12, Bin13, Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20
  1741. ) ;
  1742. end procedure AddCross ;
  1743. ------------------------------------------------------------
  1744. procedure AddCross(
  1745. ------------------------------------------------------------
  1746. AtLeast : integer ;
  1747. Weight : integer ;
  1748. Bin1, Bin2 : CovBinType ;
  1749. Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11, Bin12, Bin13,
  1750. Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  1751. ) is
  1752. begin
  1753. AddCross("", AtLeast, Weight,
  1754. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11,
  1755. Bin12, Bin13, Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20
  1756. ) ;
  1757. end procedure AddCross ;
  1758. ------------------------------------------------------------
  1759. procedure AddCross(
  1760. ------------------------------------------------------------
  1761. AtLeast : integer ;
  1762. Bin1, Bin2 : CovBinType ;
  1763. Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11, Bin12, Bin13,
  1764. Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  1765. ) is
  1766. begin
  1767. AddCross("", AtLeast, 0,
  1768. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11,
  1769. Bin12, Bin13, Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20
  1770. ) ;
  1771. end procedure AddCross ;
  1772. ------------------------------------------------------------
  1773. procedure AddCross(
  1774. ------------------------------------------------------------
  1775. Bin1, Bin2 : CovBinType ;
  1776. Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11, Bin12, Bin13,
  1777. Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  1778. ) is
  1779. begin
  1780. AddCross("", 0, 0,
  1781. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11,
  1782. Bin12, Bin13, Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20
  1783. ) ;
  1784. end procedure AddCross ;
  1785. ------------------------------------------------------------
  1786. procedure Deallocate is
  1787. ------------------------------------------------------------
  1788. begin
  1789. for i in 1 to NumBins loop
  1790. deallocate(CovBinPtr(i).BinVal) ;
  1791. deallocate(CovBinPtr(i).Name) ;
  1792. end loop ;
  1793. deallocate(CovBinPtr) ;
  1794. DeallocateName ;
  1795. DeallocateMessage ;
  1796. -- Restore internal variables to their default values
  1797. NumBins := 0 ;
  1798. OrderCount := 0 ;
  1799. BinValLength := 1 ;
  1800. IllegalMode := ILLEGAL_ON ;
  1801. WeightMode := AT_LEAST ;
  1802. WeightScale := 1.0 ;
  1803. ThresholdingEnable := FALSE ;
  1804. CovThreshold := 45.0 ;
  1805. CovTarget := 100.0 ;
  1806. MergingEnable := FALSE ;
  1807. CountMode := COUNT_FIRST ;
  1808. AlertLogIDVar := OSVVM_ALERTLOG_ID ;
  1809. -- RvSeedInit := FALSE ;
  1810. WritePassFailVar := COV_OPT_INIT_PARM_DETECT ;
  1811. WriteBinInfoVar := COV_OPT_INIT_PARM_DETECT ;
  1812. WriteCountVar := COV_OPT_INIT_PARM_DETECT ;
  1813. WriteAnyIllegalVar := COV_OPT_INIT_PARM_DETECT ;
  1814. WritePrefixVar.deallocate ;
  1815. PassNameVar.deallocate ;
  1816. FailNameVar.deallocate ;
  1817. end procedure deallocate ;
  1818. ------------------------------------------------------------
  1819. -- Local
  1820. procedure ICoverIndex( Index : integer ; CovPoint : integer_vector ) is
  1821. ------------------------------------------------------------
  1822. variable buf : line ;
  1823. begin
  1824. -- Update Count, PercentCov
  1825. CovBinPtr(Index).Count := CovBinPtr(Index).Count + CovBinPtr(Index).action ;
  1826. VendorCovBinInc(VendorCovHandleVar, Index); -- VendorCov
  1827. CovBinPtr(Index).PercentCov := real(CovBinPtr(Index).Count)*100.0/maximum(real(CovBinPtr(Index).AtLeast), 1.0) ;
  1828. -- OrderCount handling - Statistics
  1829. OrderCount := OrderCount + 1 ;
  1830. CovBinPtr(Index).OrderCount := OrderCount + CovBinPtr(Index).OrderCount ;
  1831. if CovBinPtr(Index).action = COV_ILLEGAL then
  1832. if IllegalMode /= ILLEGAL_OFF then
  1833. if CovPoint = NULL_INTV then
  1834. alert(AlertLogIDVar, GetNamePlus(prefix => "in ", suffix => ", ") & "CoveragePkg.ICoverLast:" &
  1835. " Value randomized is in an illegal bin.", IllegalModeLevel) ;
  1836. else
  1837. write(buf, CovPoint) ;
  1838. alert(AlertLogIDVar, GetNamePlus(prefix => "in ", suffix => ", ") & "CoveragePkg.ICover:" &
  1839. " Value " & buf.all & " is in an illegal bin.", IllegalModeLevel) ;
  1840. deallocate(buf) ;
  1841. end if ;
  1842. else
  1843. IncAlertCount(AlertLogIDVar, ERROR) ; -- silent alert.
  1844. end if ;
  1845. end if ;
  1846. end procedure ICoverIndex ;
  1847. ------------------------------------------------------------
  1848. procedure ICoverLast is
  1849. ------------------------------------------------------------
  1850. begin
  1851. ICoverIndex(LastIndex, NULL_INTV) ;
  1852. end procedure ICoverLast ;
  1853. ------------------------------------------------------------
  1854. procedure ICover ( CovPoint : integer) is
  1855. ------------------------------------------------------------
  1856. begin
  1857. ICover((1=> CovPoint)) ;
  1858. end procedure ICover ;
  1859. ------------------------------------------------------------
  1860. procedure ICover( CovPoint : integer_vector) is
  1861. ------------------------------------------------------------
  1862. begin
  1863. if CovPoint'length /= BinValLength then
  1864. Alert(AlertLogIDVar, GetNamePlus(prefix => "in ", suffix => ", ") & "CoveragePkg." &
  1865. " ICover: CovPoint length = " & to_string(CovPoint'length) &
  1866. " does not match Coverage Bin dimensions = " & to_string(BinValLength), FAILURE) ;
  1867. elsif CountMode = COUNT_FIRST and inside(CovPoint, CovBinPtr(LastIndex).BinVal.all) then
  1868. ICoverIndex(LastIndex, CovPoint) ;
  1869. else
  1870. CovLoop : for i in 1 to NumBins loop
  1871. -- skip this CovBin if CovPoint is not in it
  1872. next CovLoop when not inside(CovPoint, CovBinPtr(i).BinVal.all) ;
  1873. -- Mark Covered
  1874. ICoverIndex(i, CovPoint) ;
  1875. exit CovLoop when CountMode = COUNT_FIRST ; -- only find first one
  1876. end loop CovLoop ;
  1877. end if ;
  1878. end procedure ICover ;
  1879. ------------------------------------------------------------
  1880. procedure ClearCov is
  1881. ------------------------------------------------------------
  1882. begin
  1883. for i in 1 to NumBins loop
  1884. CovBinPtr(i).Count := 0 ;
  1885. CovBinPtr(i).PercentCov := 0.0 ;
  1886. CovBinPtr(i).OrderCount := 0 ;
  1887. end loop ;
  1888. OrderCount := 0 ;
  1889. end procedure ClearCov ;
  1890. ------------------------------------------------------------
  1891. -- deprecated
  1892. procedure SetCovZero is
  1893. ------------------------------------------------------------
  1894. begin
  1895. ClearCov ;
  1896. end procedure SetCovZero ;
  1897. ------------------------------------------------------------
  1898. impure function IsInitialized return boolean is
  1899. ------------------------------------------------------------
  1900. begin
  1901. return NumBins > 0 ;
  1902. end function IsInitialized ;
  1903. ------------------------------------------------------------
  1904. impure function GetNumBins return integer is
  1905. ------------------------------------------------------------
  1906. begin
  1907. return NumBins ;
  1908. end function GetNumBins ;
  1909. ------------------------------------------------------------
  1910. impure function GetMinIndex return integer is
  1911. ------------------------------------------------------------
  1912. variable MinCov : real := real'right ; -- big number
  1913. variable MinIndex : integer := NumBins ;
  1914. begin
  1915. CovLoop : for i in 1 to NumBins loop
  1916. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).PercentCov < MinCov then
  1917. MinCov := CovBinPtr(i).PercentCov ;
  1918. MinIndex := i ;
  1919. end if ;
  1920. end loop CovLoop ;
  1921. return MinIndex ;
  1922. end function GetMinIndex ;
  1923. ------------------------------------------------------------
  1924. impure function GetMinCov return real is
  1925. ------------------------------------------------------------
  1926. variable MinCov : real := real'right ; -- big number
  1927. begin
  1928. CovLoop : for i in 1 to NumBins loop
  1929. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).PercentCov < MinCov then
  1930. MinCov := CovBinPtr(i).PercentCov ;
  1931. end if ;
  1932. end loop CovLoop ;
  1933. return MinCov ;
  1934. end function GetMinCov ;
  1935. ------------------------------------------------------------
  1936. impure function GetMinCount return integer is
  1937. ------------------------------------------------------------
  1938. variable MinCount : integer := integer'right ; -- big number
  1939. begin
  1940. CovLoop : for i in 1 to NumBins loop
  1941. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).Count < MinCount then
  1942. MinCount := CovBinPtr(i).Count ;
  1943. end if ;
  1944. end loop CovLoop ;
  1945. return MinCount ;
  1946. end function GetMinCount ;
  1947. ------------------------------------------------------------
  1948. impure function GetMaxIndex return integer is
  1949. ------------------------------------------------------------
  1950. variable MaxCov : real := 0.0 ;
  1951. variable MaxIndex : integer := NumBins ;
  1952. begin
  1953. CovLoop : for i in 1 to NumBins loop
  1954. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).PercentCov > MaxCov then
  1955. MaxCov := CovBinPtr(i).PercentCov ;
  1956. MaxIndex := i ;
  1957. end if ;
  1958. end loop CovLoop ;
  1959. return MaxIndex ;
  1960. end function GetMaxIndex ;
  1961. ------------------------------------------------------------
  1962. impure function GetMaxCov return real is
  1963. ------------------------------------------------------------
  1964. variable MaxCov : real := 0.0 ;
  1965. begin
  1966. CovLoop : for i in 1 to NumBins loop
  1967. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).PercentCov > MaxCov then
  1968. MaxCov := CovBinPtr(i).PercentCov ;
  1969. end if ;
  1970. end loop CovLoop ;
  1971. return MaxCov ;
  1972. end function GetMaxCov ;
  1973. ------------------------------------------------------------
  1974. impure function GetMaxCount return integer is
  1975. ------------------------------------------------------------
  1976. variable MaxCount : integer := 0 ;
  1977. begin
  1978. CovLoop : for i in 1 to NumBins loop
  1979. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).Count > MaxCount then
  1980. MaxCount := CovBinPtr(i).Count ;
  1981. end if ;
  1982. end loop CovLoop ;
  1983. return MaxCount ;
  1984. end function GetMaxCount ;
  1985. ------------------------------------------------------------
  1986. impure function CountCovHoles ( PercentCov : real ) return integer is
  1987. ------------------------------------------------------------
  1988. variable HoleCount : integer := 0 ;
  1989. begin
  1990. CovLoop : for i in 1 to NumBins loop
  1991. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).PercentCov < PercentCov then
  1992. HoleCount := HoleCount + 1 ;
  1993. end if ;
  1994. end loop CovLoop ;
  1995. return HoleCount ;
  1996. end function CountCovHoles ;
  1997. ------------------------------------------------------------
  1998. impure function CountCovHoles return integer is
  1999. ------------------------------------------------------------
  2000. begin
  2001. return CountCovHoles(CovTarget) ;
  2002. end function CountCovHoles ;
  2003. ------------------------------------------------------------
  2004. impure function IsCovered ( PercentCov : real ) return boolean is
  2005. ------------------------------------------------------------
  2006. begin
  2007. -- AlertIf(NumBins < 1, OSVVM_ALERTLOG_ID, "CoveragePkg.IsCovered: Empty Coverage Model", failure) ;
  2008. return CountCovHoles(PercentCov) = 0 ;
  2009. end function IsCovered ;
  2010. ------------------------------------------------------------
  2011. impure function IsCovered return boolean is
  2012. ------------------------------------------------------------
  2013. begin
  2014. -- AlertIf(NumBins < 1, OSVVM_ALERTLOG_ID, "CoveragePkg.IsCovered: Empty Coverage Model", failure) ;
  2015. return CountCovHoles(CovTarget) = 0 ;
  2016. end function IsCovered ;
  2017. ------------------------------------------------------------
  2018. impure function GetCov ( PercentCov : real ) return real is
  2019. ------------------------------------------------------------
  2020. variable TotalCovGoal, TotalCovCount, ScaledCovGoal : integer := 0 ;
  2021. begin
  2022. BinLoop : for i in 1 to NumBins loop
  2023. if CovBinPtr(i).action = COV_COUNT then
  2024. ScaledCovGoal := integer(ceil(PercentCov * real(CovBinPtr(i).AtLeast)/100.0)) ;
  2025. TotalCovGoal := TotalCovGoal + ScaledCovGoal ;
  2026. if CovBinPtr(i).Count <= ScaledCovGoal then
  2027. TotalCovCount := TotalCovCount + CovBinPtr(i).Count ;
  2028. else
  2029. -- do not count the extra values that exceed their cov goal
  2030. TotalCovCount := TotalCovCount + ScaledCovGoal ;
  2031. end if ;
  2032. end if ;
  2033. end loop BinLoop ;
  2034. return 100.0 * real(TotalCovCount) / real(TotalCovGoal) ;
  2035. end function GetCov ;
  2036. ------------------------------------------------------------
  2037. impure function GetCov return real is
  2038. ------------------------------------------------------------
  2039. variable TotalCovGoal, TotalCovCount : integer := 0 ;
  2040. begin
  2041. return GetCov( CovTarget ) ;
  2042. end function GetCov ;
  2043. ------------------------------------------------------------
  2044. impure function GetItemCount return integer is
  2045. ------------------------------------------------------------
  2046. begin
  2047. return ItemCount ;
  2048. end function GetItemCount ;
  2049. ------------------------------------------------------------
  2050. impure function GetTotalCovGoal ( PercentCov : real ) return integer is
  2051. ------------------------------------------------------------
  2052. variable TotalCovGoal, ScaledCovGoal : integer := 0 ;
  2053. begin
  2054. BinLoop : for i in 1 to NumBins loop
  2055. if CovBinPtr(i).action = COV_COUNT then
  2056. ScaledCovGoal := integer(ceil(PercentCov * real(CovBinPtr(i).AtLeast)/100.0)) ;
  2057. TotalCovGoal := TotalCovGoal + ScaledCovGoal ;
  2058. end if ;
  2059. end loop BinLoop ;
  2060. return TotalCovGoal ;
  2061. end function GetTotalCovGoal ;
  2062. ------------------------------------------------------------
  2063. impure function GetTotalCovGoal return integer is
  2064. ------------------------------------------------------------
  2065. begin
  2066. return GetTotalCovGoal(CovTarget) ;
  2067. end function GetTotalCovGoal ;
  2068. ------------------------------------------------------------
  2069. impure function GetLastIndex return integer is
  2070. ------------------------------------------------------------
  2071. begin
  2072. return LastIndex ;
  2073. end function GetLastIndex ;
  2074. ------------------------------------------------------------
  2075. impure function GetHoleBinVal ( ReqHoleNum : integer ; PercentCov : real ) return RangeArrayType is
  2076. ------------------------------------------------------------
  2077. variable HoleCount : integer := 0 ;
  2078. variable buf : line ;
  2079. begin
  2080. CovLoop : for i in 1 to NumBins loop
  2081. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).PercentCov < PercentCov then
  2082. HoleCount := HoleCount + 1 ;
  2083. if HoleCount = ReqHoleNum then
  2084. return CovBinPtr(i).BinVal.all ;
  2085. end if ;
  2086. end if ;
  2087. end loop CovLoop ;
  2088. Alert(AlertLogIDVar, GetNamePlus(prefix => "in ", suffix => ", ") & "CoveragePkg.GetHoleBinVal:" &
  2089. " did not find a coverage hole. HoleCount = " & integer'image(HoleCount) &
  2090. " ReqHoleNum = " & integer'image(ReqHoleNum), ERROR
  2091. ) ;
  2092. return CovBinPtr(NumBins).BinVal.all ;
  2093. end function GetHoleBinVal ;
  2094. ------------------------------------------------------------
  2095. impure function GetHoleBinVal ( PercentCov : real ) return RangeArrayType is
  2096. ------------------------------------------------------------
  2097. begin
  2098. return GetHoleBinVal(1, PercentCov) ;
  2099. end function GetHoleBinVal ;
  2100. ------------------------------------------------------------
  2101. impure function GetHoleBinVal ( ReqHoleNum : integer := 1 ) return RangeArrayType is
  2102. ------------------------------------------------------------
  2103. begin
  2104. return GetHoleBinVal(ReqHoleNum, CovTarget) ;
  2105. end function GetHoleBinVal ;
  2106. ------------------------------------------------------------
  2107. impure function CalcWeight ( BinIndex : integer ; MaxCovPercent : real ) return integer is
  2108. -- pt local
  2109. ------------------------------------------------------------
  2110. begin
  2111. case WeightMode is
  2112. when AT_LEAST => -- AtLeast
  2113. return CovBinPtr(BinIndex).AtLeast ;
  2114. when WEIGHT => -- Weight
  2115. return CovBinPtr(BinIndex).Weight ;
  2116. when REMAIN => -- (Adjust * AtLeast) - Count
  2117. return integer( Ceil( MaxCovPercent * real(CovBinPtr(BinIndex).AtLeast)/100.0)) -
  2118. CovBinPtr(BinIndex).Count ;
  2119. when REMAIN_EXP => -- Weight * (REMAIN **WeightScale)
  2120. -- Experimental may be removed
  2121. -- CAUTION: for large numbers and/or WeightScale > 2.0, result can be > 2**31 (max integer value)
  2122. -- both Weight and WeightScale default to 1
  2123. return CovBinPtr(BinIndex).Weight *
  2124. integer( Ceil (
  2125. ( (MaxCovPercent * real(CovBinPtr(BinIndex).AtLeast)/100.0) -
  2126. real(CovBinPtr(BinIndex).Count) ) ** WeightScale ) );
  2127. when REMAIN_SCALED => -- (WeightScale * Adjust * AtLeast) - Count
  2128. -- Experimental may be removed
  2129. -- Biases remainder toward AT_LEAST value.
  2130. -- WeightScale must be > 1.0
  2131. return integer( Ceil( WeightScale * MaxCovPercent * real(CovBinPtr(BinIndex).AtLeast)/100.0)) -
  2132. CovBinPtr(BinIndex).Count ;
  2133. when REMAIN_WEIGHT => -- Weight * ((WeightScale * Adjust * AtLeast) - Count)
  2134. -- Experimental may be removed
  2135. -- WeightScale must be > 1.0
  2136. return CovBinPtr(BinIndex).Weight * (
  2137. integer( Ceil( WeightScale * MaxCovPercent * real(CovBinPtr(BinIndex).AtLeast)/100.0)) -
  2138. CovBinPtr(BinIndex).Count) ;
  2139. end case ;
  2140. end function CalcWeight ;
  2141. ------------------------------------------------------------
  2142. impure function RandHoleIndex ( CovTargetPercent : real ) return integer is
  2143. -- pt local
  2144. ------------------------------------------------------------
  2145. variable WeightVec : integer_vector(0 to NumBins-1) ; -- Prep for change to DistInt
  2146. variable MaxCovPercent : real ;
  2147. variable MinCovPercent : real ;
  2148. begin
  2149. ItemCount := ItemCount + 1 ;
  2150. MinCovPercent := GetMinCov ;
  2151. if ThresholdingEnable then
  2152. MaxCovPercent := MinCovPercent + CovThreshold ;
  2153. if MinCovPercent < CovTargetPercent then
  2154. -- Clip at CovTargetPercent until reach CovTargetPercent
  2155. MaxCovPercent := minimum(MaxCovPercent, CovTargetPercent);
  2156. end if ;
  2157. else
  2158. if MinCovPercent < CovTargetPercent then
  2159. MaxCovPercent := CovTargetPercent ;
  2160. else
  2161. -- Done, Enable all bins
  2162. MaxCovPercent := GetMaxCov + 1.0 ;
  2163. -- MaxCovPercent := real'right ; -- weight scale issues
  2164. end if ;
  2165. end if ;
  2166. CovLoop : for i in 1 to NumBins loop
  2167. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).PercentCov < MaxCovPercent then
  2168. -- Calculate Weight based on WeightMode
  2169. -- Scale to current percentage goal: MaxCov which can be < or > 100.0
  2170. WeightVec(i-1) := CalcWeight(i, MaxCovPercent) ;
  2171. else
  2172. WeightVec(i-1) := 0 ;
  2173. end if ;
  2174. end loop CovLoop ;
  2175. -- DistInt returns integer range 0 to Numbins-1
  2176. -- Caution: DistInt can fail when sum(WeightVec) > 2**31
  2177. -- See notes in CalcWeight for REMAIN_EXP
  2178. LastIndex := 1 + RV.DistInt( WeightVec ) ; -- return range 1 to NumBins
  2179. return LastIndex ;
  2180. end function RandHoleIndex ;
  2181. ------------------------------------------------------------
  2182. impure function GetBinVal ( BinIndex : integer ) return RangeArrayType is
  2183. ------------------------------------------------------------
  2184. begin
  2185. return CovBinPtr( BinIndex ).BinVal.all ;
  2186. end function GetBinVal ;
  2187. ------------------------------------------------------------
  2188. impure function GetLastBinVal return RangeArrayType is
  2189. ------------------------------------------------------------
  2190. begin
  2191. return CovBinPtr( LastIndex ).BinVal.all ;
  2192. end function GetLastBinVal ;
  2193. ------------------------------------------------------------
  2194. impure function RandCovBinVal ( PercentCov : real ) return RangeArrayType is
  2195. ------------------------------------------------------------
  2196. begin
  2197. return CovBinPtr( RandHoleIndex(PercentCov) ).BinVal.all ; -- GetBinVal
  2198. end function RandCovBinVal ;
  2199. ------------------------------------------------------------
  2200. impure function RandCovBinVal return RangeArrayType is
  2201. ------------------------------------------------------------
  2202. begin
  2203. -- use global coverage target
  2204. return CovBinPtr( RandHoleIndex( CovTarget ) ).BinVal.all ; -- GetBinVal
  2205. end function RandCovBinVal ;
  2206. ------------------------------------------------------------
  2207. impure function GetMinBinVal return RangeArrayType is
  2208. ------------------------------------------------------------
  2209. begin
  2210. -- use global coverage target
  2211. return GetBinVal( GetMinIndex ) ;
  2212. end function GetMinBinVal ;
  2213. ------------------------------------------------------------
  2214. impure function GetMaxBinVal return RangeArrayType is
  2215. ------------------------------------------------------------
  2216. begin
  2217. -- use global coverage target
  2218. return GetBinVal( GetMaxIndex ) ;
  2219. end function GetMaxBinVal ;
  2220. ------------------------------------------------------------
  2221. -- impure function RandCovPoint( BinVal : RangeArrayType ) return integer_vector is
  2222. impure function ToRandPoint( BinVal : RangeArrayType ) return integer_vector is
  2223. -- pt local
  2224. ------------------------------------------------------------
  2225. variable CovPoint : integer_vector(BinVal'range) ;
  2226. variable normCovPoint : integer_vector(1 to BinVal'length) ;
  2227. begin
  2228. for i in BinVal'range loop
  2229. CovPoint(i) := RV.RandInt(BinVal(i).min, BinVal(i).max) ;
  2230. end loop ;
  2231. normCovPoint := CovPoint ;
  2232. return normCovPoint ;
  2233. end function ToRandPoint ;
  2234. ------------------------------------------------------------
  2235. impure function ToRandPoint( BinVal : RangeArrayType ) return integer is
  2236. -- pt local
  2237. ------------------------------------------------------------
  2238. begin
  2239. return RV.RandInt(BinVal(BinVal'left).min, BinVal(BinVal'left).max) ;
  2240. end function ToRandPoint ;
  2241. ------------------------------------------------------------
  2242. impure function RandCovPoint return integer is
  2243. ------------------------------------------------------------
  2244. begin
  2245. return ToRandPoint(RandCovBinVal(CovTarget)) ;
  2246. end function RandCovPoint ;
  2247. ------------------------------------------------------------
  2248. impure function RandCovPoint ( PercentCov : real ) return integer is
  2249. ------------------------------------------------------------
  2250. begin
  2251. return ToRandPoint(RandCovBinVal(PercentCov)) ;
  2252. end function RandCovPoint ;
  2253. ------------------------------------------------------------
  2254. impure function RandCovPoint return integer_vector is
  2255. ------------------------------------------------------------
  2256. begin
  2257. return ToRandPoint(RandCovBinVal(CovTarget)) ;
  2258. end function RandCovPoint ;
  2259. ------------------------------------------------------------
  2260. impure function RandCovPoint ( PercentCov : real ) return integer_vector is
  2261. ------------------------------------------------------------
  2262. begin
  2263. return ToRandPoint(RandCovBinVal(PercentCov)) ;
  2264. end function RandCovPoint ;
  2265. ------------------------------------------------------------
  2266. impure function GetPoint ( BinIndex : integer ) return integer is
  2267. ------------------------------------------------------------
  2268. begin
  2269. return ToRandPoint(GetBinVal(BinIndex)) ;
  2270. end function GetPoint ;
  2271. ------------------------------------------------------------
  2272. impure function GetPoint ( BinIndex : integer ) return integer_vector is
  2273. ------------------------------------------------------------
  2274. begin
  2275. return ToRandPoint(GetBinVal(BinIndex)) ;
  2276. end function GetPoint ;
  2277. ------------------------------------------------------------
  2278. impure function GetMinPoint return integer is
  2279. ------------------------------------------------------------
  2280. begin
  2281. return ToRandPoint(GetBinVal( GetMinIndex )) ;
  2282. end function GetMinPoint ;
  2283. ------------------------------------------------------------
  2284. impure function GetMinPoint return integer_vector is
  2285. ------------------------------------------------------------
  2286. begin
  2287. return ToRandPoint(GetBinVal( GetMinIndex )) ;
  2288. end function GetMinPoint ;
  2289. ------------------------------------------------------------
  2290. impure function GetMaxPoint return integer is
  2291. ------------------------------------------------------------
  2292. begin
  2293. return ToRandPoint(GetBinVal( GetMaxIndex )) ;
  2294. end function GetMaxPoint ;
  2295. ------------------------------------------------------------
  2296. impure function GetMaxPoint return integer_vector is
  2297. ------------------------------------------------------------
  2298. begin
  2299. return ToRandPoint(GetBinVal( GetMaxIndex )) ;
  2300. end function GetMaxPoint ;
  2301. -- ------------------------------------------------------------
  2302. -- Intended as a stand in until we get a more general GetBin
  2303. impure function GetBinInfo ( BinIndex : integer ) return CovBinBaseType is
  2304. -- ------------------------------------------------------------
  2305. variable result : CovBinBaseType ;
  2306. begin
  2307. result.BinVal := ALL_RANGE;
  2308. result.Action := CovBinPtr(BinIndex).Action;
  2309. result.Count := CovBinPtr(BinIndex).Count;
  2310. result.AtLeast := CovBinPtr(BinIndex).AtLeast;
  2311. result.Weight := CovBinPtr(BinIndex).Weight;
  2312. return result ;
  2313. end function GetBinInfo ;
  2314. -- ------------------------------------------------------------
  2315. -- Intended as a stand in until we get a more general GetBin
  2316. impure function GetBinValLength return integer is
  2317. -- ------------------------------------------------------------
  2318. begin
  2319. return BinValLength ;
  2320. end function GetBinValLength ;
  2321. -- Eventually the multiple GetBin functions will be replaced by a
  2322. -- a single GetBin that returns CovBinBaseType with BinVal as an
  2323. -- unconstrained element
  2324. -- ------------------------------------------------------------
  2325. impure function GetBin ( BinIndex : integer ) return CovBinBaseType is
  2326. -- ------------------------------------------------------------
  2327. variable result : CovBinBaseType ;
  2328. begin
  2329. result.BinVal := CovBinPtr(BinIndex).BinVal.all;
  2330. result.Action := CovBinPtr(BinIndex).Action;
  2331. result.Count := CovBinPtr(BinIndex).Count;
  2332. result.AtLeast := CovBinPtr(BinIndex).AtLeast;
  2333. result.Weight := CovBinPtr(BinIndex).Weight;
  2334. return result ;
  2335. end function GetBin ;
  2336. -- ------------------------------------------------------------
  2337. impure function GetBin ( BinIndex : integer ) return CovMatrix2BaseType is
  2338. -- ------------------------------------------------------------
  2339. variable result : CovMatrix2BaseType ;
  2340. begin
  2341. result.BinVal := CovBinPtr(BinIndex).BinVal.all;
  2342. result.Action := CovBinPtr(BinIndex).Action;
  2343. result.Count := CovBinPtr(BinIndex).Count;
  2344. result.AtLeast := CovBinPtr(BinIndex).AtLeast;
  2345. result.Weight := CovBinPtr(BinIndex).Weight;
  2346. return result ;
  2347. end function GetBin ;
  2348. -- ------------------------------------------------------------
  2349. impure function GetBin ( BinIndex : integer ) return CovMatrix3BaseType is
  2350. -- ------------------------------------------------------------
  2351. variable result : CovMatrix3BaseType ;
  2352. begin
  2353. result.BinVal := CovBinPtr(BinIndex).BinVal.all;
  2354. result.Action := CovBinPtr(BinIndex).Action;
  2355. result.Count := CovBinPtr(BinIndex).Count;
  2356. result.AtLeast := CovBinPtr(BinIndex).AtLeast;
  2357. result.Weight := CovBinPtr(BinIndex).Weight;
  2358. return result ;
  2359. end function GetBin ;
  2360. -- ------------------------------------------------------------
  2361. impure function GetBin ( BinIndex : integer ) return CovMatrix4BaseType is
  2362. -- ------------------------------------------------------------
  2363. variable result : CovMatrix4BaseType ;
  2364. begin
  2365. result.BinVal := CovBinPtr(BinIndex).BinVal.all;
  2366. result.Action := CovBinPtr(BinIndex).Action;
  2367. result.Count := CovBinPtr(BinIndex).Count;
  2368. result.AtLeast := CovBinPtr(BinIndex).AtLeast;
  2369. result.Weight := CovBinPtr(BinIndex).Weight;
  2370. return result ;
  2371. end function GetBin ;
  2372. -- ------------------------------------------------------------
  2373. impure function GetBin ( BinIndex : integer ) return CovMatrix5BaseType is
  2374. -- ------------------------------------------------------------
  2375. variable result : CovMatrix5BaseType ;
  2376. begin
  2377. result.BinVal := CovBinPtr(BinIndex).BinVal.all;
  2378. result.Action := CovBinPtr(BinIndex).Action;
  2379. result.Count := CovBinPtr(BinIndex).Count;
  2380. result.AtLeast := CovBinPtr(BinIndex).AtLeast;
  2381. result.Weight := CovBinPtr(BinIndex).Weight;
  2382. return result ;
  2383. end function GetBin ;
  2384. -- ------------------------------------------------------------
  2385. impure function GetBin ( BinIndex : integer ) return CovMatrix6BaseType is
  2386. -- ------------------------------------------------------------
  2387. variable result : CovMatrix6BaseType ;
  2388. begin
  2389. result.BinVal := CovBinPtr(BinIndex).BinVal.all;
  2390. result.Action := CovBinPtr(BinIndex).Action;
  2391. result.Count := CovBinPtr(BinIndex).Count;
  2392. result.AtLeast := CovBinPtr(BinIndex).AtLeast;
  2393. result.Weight := CovBinPtr(BinIndex).Weight;
  2394. return result ;
  2395. end function GetBin ;
  2396. -- ------------------------------------------------------------
  2397. impure function GetBin ( BinIndex : integer ) return CovMatrix7BaseType is
  2398. -- ------------------------------------------------------------
  2399. variable result : CovMatrix7BaseType ;
  2400. begin
  2401. result.BinVal := CovBinPtr(BinIndex).BinVal.all;
  2402. result.Action := CovBinPtr(BinIndex).Action;
  2403. result.Count := CovBinPtr(BinIndex).Count;
  2404. result.AtLeast := CovBinPtr(BinIndex).AtLeast;
  2405. result.Weight := CovBinPtr(BinIndex).Weight;
  2406. return result ;
  2407. end function GetBin ;
  2408. -- ------------------------------------------------------------
  2409. impure function GetBin ( BinIndex : integer ) return CovMatrix8BaseType is
  2410. -- ------------------------------------------------------------
  2411. variable result : CovMatrix8BaseType ;
  2412. begin
  2413. result.BinVal := CovBinPtr(BinIndex).BinVal.all;
  2414. result.Action := CovBinPtr(BinIndex).Action;
  2415. result.Count := CovBinPtr(BinIndex).Count;
  2416. result.AtLeast := CovBinPtr(BinIndex).AtLeast;
  2417. result.Weight := CovBinPtr(BinIndex).Weight;
  2418. return result ;
  2419. end function GetBin ;
  2420. -- ------------------------------------------------------------
  2421. impure function GetBin ( BinIndex : integer ) return CovMatrix9BaseType is
  2422. -- ------------------------------------------------------------
  2423. variable result : CovMatrix9BaseType ;
  2424. begin
  2425. result.BinVal := CovBinPtr(BinIndex).BinVal.all;
  2426. result.Action := CovBinPtr(BinIndex).Action;
  2427. result.Count := CovBinPtr(BinIndex).Count;
  2428. result.AtLeast := CovBinPtr(BinIndex).AtLeast;
  2429. result.Weight := CovBinPtr(BinIndex).Weight;
  2430. return result ;
  2431. end function GetBin ;
  2432. -- ------------------------------------------------------------
  2433. impure function GetBinName ( BinIndex : integer; DefaultName : string := "" ) return string is
  2434. -- ------------------------------------------------------------
  2435. begin
  2436. if CovBinPtr(BinIndex).Name.all /= "" then
  2437. return CovBinPtr(BinIndex).Name.all ;
  2438. else
  2439. return DefaultName ;
  2440. end if;
  2441. end function GetBinName;
  2442. ------------------------------------------------------------
  2443. -- pt local for now -- file formal parameter not allowed with method
  2444. procedure WriteBin (
  2445. file f : text ;
  2446. WritePassFail : CovOptionsType ;
  2447. WriteBinInfo : CovOptionsType ;
  2448. WriteCount : CovOptionsType ;
  2449. WriteAnyIllegal : CovOptionsType ;
  2450. WritePrefix : string ;
  2451. PassName : string ;
  2452. FailName : string
  2453. ) is
  2454. ------------------------------------------------------------
  2455. variable buf : line ;
  2456. begin
  2457. if NumBins < 1 then
  2458. if WriteBinFileInit or UsingLocalFile then
  2459. swrite(buf, WritePrefix & " " & FailName & " ") ;
  2460. swrite(buf, GetNamePlus(prefix => "in ", suffix => ", ") & "CoveragePkg.WriteBin: Coverage model is empty. Nothing to print.") ;
  2461. writeline(f, buf) ;
  2462. end if ;
  2463. Alert(AlertLogIDVar, GetNamePlus(prefix => "in ", suffix => ", ") & "CoveragePkg.WriteBin:" &
  2464. " Coverage model is empty. Nothing to print.", FAILURE) ;
  2465. return ;
  2466. end if ;
  2467. -- Models with Bins
  2468. WriteBinName(f, "WriteBin: ", WritePrefix) ;
  2469. for i in 1 to NumBins loop -- CovBinPtr.all'range
  2470. if CovBinPtr(i).action = COV_COUNT or
  2471. (CovBinPtr(i).action = COV_ILLEGAL and IsEnabled(WriteAnyIllegal)) or
  2472. CovBinPtr(i).count < 0 -- Illegal bin with errors
  2473. then
  2474. -- WriteBin Info
  2475. swrite(buf, WritePrefix) ;
  2476. if CovBinPtr(i).Name.all /= "" then
  2477. swrite(buf, CovBinPtr(i).Name.all & " ") ;
  2478. end if ;
  2479. if IsEnabled(WritePassFail) then
  2480. -- For illegal bins, AtLeast = 0 and count is negative.
  2481. if CovBinPtr(i).count >= CovBinPtr(i).AtLeast then
  2482. swrite(buf, PassName & ' ') ;
  2483. else
  2484. swrite(buf, FailName & ' ') ;
  2485. end if ;
  2486. end if ;
  2487. if IsEnabled(WriteBinInfo) then
  2488. if CovBinPtr(i).action = COV_COUNT then
  2489. swrite(buf, "Bin:") ;
  2490. else
  2491. swrite(buf, "Illegal Bin:") ;
  2492. end if;
  2493. write(buf, CovBinPtr(i).BinVal.all) ;
  2494. end if ;
  2495. if IsEnabled(WriteCount) then
  2496. write(buf, " Count = " & integer'image(abs(CovBinPtr(i).count))) ;
  2497. write(buf, " AtLeast = " & integer'image(CovBinPtr(i).AtLeast)) ;
  2498. if WeightMode = WEIGHT or WeightMode = REMAIN_WEIGHT then
  2499. -- Print Weight only when it is used
  2500. write(buf, " Weight = " & integer'image(CovBinPtr(i).Weight)) ;
  2501. end if ;
  2502. end if ;
  2503. writeline(f, buf) ;
  2504. end if ;
  2505. end loop ;
  2506. swrite(buf, "") ;
  2507. writeline(f, buf) ;
  2508. end procedure WriteBin ;
  2509. ------------------------------------------------------------
  2510. procedure WriteBin (
  2511. ------------------------------------------------------------
  2512. WritePassFail : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  2513. WriteBinInfo : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  2514. WriteCount : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  2515. WriteAnyIllegal : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  2516. WritePrefix : string := OSVVM_STRING_INIT_PARM_DETECT ;
  2517. PassName : string := OSVVM_STRING_INIT_PARM_DETECT ;
  2518. FailName : string := OSVVM_STRING_INIT_PARM_DETECT
  2519. ) is
  2520. constant rWritePassFail : CovOptionsType := ResolveCovWritePassFail(WritePassFail, WritePassFailVar) ;
  2521. constant rWriteBinInfo : CovOptionsType := ResolveCovWriteBinInfo(WriteBinInfo, WriteBinInfoVar ) ;
  2522. constant rWriteCount : CovOptionsType := ResolveCovWriteCount(WriteCount, WriteCountVar ) ;
  2523. constant rWriteAnyIllegal : CovOptionsType := ResolveCovWriteAnyIllegal(WriteAnyIllegal, WriteAnyIllegalVar) ;
  2524. constant rWritePrefix : string := ResolveOsvvmWritePrefix(WritePrefix, WritePrefixVar.GetOpt) ;
  2525. constant rPassName : string := ResolveOsvvmPassName(PassName, PassNameVar.GetOpt ) ;
  2526. constant rFailName : string := ResolveOsvvmFailName(FailName, FailNameVar.GetOpt ) ;
  2527. begin
  2528. if WriteBinFileInit then
  2529. -- Write to Local WriteBinFile - Deprecated, recommend use TranscriptFile instead
  2530. WriteBin (
  2531. f => WriteBinFile,
  2532. WritePassFail => rWritePassFail,
  2533. WriteBinInfo => rWriteBinInfo,
  2534. WriteCount => rWriteCount,
  2535. WriteAnyIllegal => rWriteAnyIllegal,
  2536. WritePrefix => rWritePrefix,
  2537. PassName => rPassName,
  2538. FailName => rFailName
  2539. ) ;
  2540. elsif IsTranscriptEnabled then
  2541. -- Write to TranscriptFile
  2542. WriteBin (
  2543. f => TranscriptFile,
  2544. WritePassFail => rWritePassFail,
  2545. WriteBinInfo => rWriteBinInfo,
  2546. WriteCount => rWriteCount,
  2547. WriteAnyIllegal => rWriteAnyIllegal,
  2548. WritePrefix => rWritePrefix,
  2549. PassName => rPassName,
  2550. FailName => rFailName
  2551. ) ;
  2552. if IsTranscriptMirrored then
  2553. -- Mirrored to OUTPUT
  2554. WriteBin (
  2555. f => OUTPUT,
  2556. WritePassFail => rWritePassFail,
  2557. WriteBinInfo => rWriteBinInfo,
  2558. WriteCount => rWriteCount,
  2559. WriteAnyIllegal => rWriteAnyIllegal,
  2560. WritePrefix => rWritePrefix,
  2561. PassName => rPassName,
  2562. FailName => rFailName
  2563. ) ;
  2564. end if ;
  2565. else
  2566. -- Default Write to OUTPUT
  2567. WriteBin (
  2568. f => OUTPUT,
  2569. WritePassFail => rWritePassFail,
  2570. WriteBinInfo => rWriteBinInfo,
  2571. WriteCount => rWriteCount,
  2572. WriteAnyIllegal => rWriteAnyIllegal,
  2573. WritePrefix => rWritePrefix,
  2574. PassName => rPassName,
  2575. FailName => rFailName
  2576. ) ;
  2577. end if ;
  2578. end procedure WriteBin ;
  2579. ------------------------------------------------------------
  2580. procedure WriteBin ( -- With LogLevel
  2581. ------------------------------------------------------------
  2582. LogLevel : LogType ;
  2583. WritePassFail : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  2584. WriteBinInfo : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  2585. WriteCount : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  2586. WriteAnyIllegal : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  2587. WritePrefix : string := OSVVM_STRING_INIT_PARM_DETECT ;
  2588. PassName : string := OSVVM_STRING_INIT_PARM_DETECT ;
  2589. FailName : string := OSVVM_STRING_INIT_PARM_DETECT
  2590. ) is
  2591. begin
  2592. if IsLogEnabled(AlertLogIDVar, LogLevel) then
  2593. WriteBin (
  2594. WritePassFail => WritePassFail,
  2595. WriteBinInfo => WriteBinInfo,
  2596. WriteCount => WriteCount,
  2597. WriteAnyIllegal => WriteAnyIllegal,
  2598. WritePrefix => WritePrefix,
  2599. PassName => PassName,
  2600. FailName => FailName
  2601. ) ;
  2602. end if ;
  2603. end procedure WriteBin ; -- With LogLevel
  2604. ------------------------------------------------------------
  2605. procedure WriteBin (
  2606. ------------------------------------------------------------
  2607. FileName : string;
  2608. OpenKind : File_Open_Kind := APPEND_MODE ;
  2609. WritePassFail : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  2610. WriteBinInfo : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  2611. WriteCount : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  2612. WriteAnyIllegal : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  2613. WritePrefix : string := OSVVM_STRING_INIT_PARM_DETECT ;
  2614. PassName : string := OSVVM_STRING_INIT_PARM_DETECT ;
  2615. FailName : string := OSVVM_STRING_INIT_PARM_DETECT
  2616. ) is
  2617. file LocalWriteBinFile : text open OpenKind is FileName ;
  2618. constant rWritePassFail : CovOptionsType := ResolveCovWritePassFail(WritePassFail, WritePassFailVar) ;
  2619. constant rWriteBinInfo : CovOptionsType := ResolveCovWriteBinInfo(WriteBinInfo, WriteBinInfoVar ) ;
  2620. constant rWriteCount : CovOptionsType := ResolveCovWriteCount(WriteCount, WriteCountVar ) ;
  2621. constant rWriteAnyIllegal : CovOptionsType := ResolveCovWriteAnyIllegal(WriteAnyIllegal, WriteAnyIllegalVar) ;
  2622. constant rWritePrefix : string := ResolveOsvvmWritePrefix(WritePrefix, WritePrefixVar.GetOpt) ;
  2623. constant rPassName : string := ResolveOsvvmPassName(PassName, PassNameVar.GetOpt ) ;
  2624. constant rFailName : string := ResolveOsvvmFailName(FailName, FailNameVar.GetOpt ) ;
  2625. begin
  2626. UsingLocalFile := TRUE ;
  2627. WriteBin (
  2628. f => LocalWriteBinFile,
  2629. WritePassFail => rWritePassFail,
  2630. WriteBinInfo => rWriteBinInfo,
  2631. WriteCount => rWriteCount,
  2632. WriteAnyIllegal => rWriteAnyIllegal,
  2633. WritePrefix => rWritePrefix,
  2634. PassName => rPassName,
  2635. FailName => rFailName
  2636. );
  2637. UsingLocalFile := FALSE ;
  2638. end procedure WriteBin ;
  2639. ------------------------------------------------------------
  2640. procedure WriteBin ( -- With LogLevel
  2641. ------------------------------------------------------------
  2642. LogLevel : LogType ;
  2643. FileName : string;
  2644. OpenKind : File_Open_Kind := APPEND_MODE ;
  2645. WritePassFail : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  2646. WriteBinInfo : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  2647. WriteCount : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  2648. WriteAnyIllegal : CovOptionsType := COV_OPT_INIT_PARM_DETECT ;
  2649. WritePrefix : string := OSVVM_STRING_INIT_PARM_DETECT ;
  2650. PassName : string := OSVVM_STRING_INIT_PARM_DETECT ;
  2651. FailName : string := OSVVM_STRING_INIT_PARM_DETECT
  2652. ) is
  2653. begin
  2654. if IsLogEnabled(AlertLogIDVar, LogLevel) then
  2655. UsingLocalFile := TRUE ;
  2656. WriteBin (
  2657. FileName => FileName,
  2658. OpenKind => OpenKind,
  2659. WritePassFail => WritePassFail,
  2660. WriteBinInfo => WriteBinInfo,
  2661. WriteCount => WriteCount,
  2662. WriteAnyIllegal => WriteAnyIllegal,
  2663. WritePrefix => WritePrefix,
  2664. PassName => PassName,
  2665. FailName => FailName
  2666. ) ;
  2667. UsingLocalFile := FALSE ;
  2668. end if ;
  2669. end procedure WriteBin ; -- With LogLevel
  2670. ------------------------------------------------------------
  2671. -- Development only
  2672. -- pt local for now -- file formal parameter not allowed with method
  2673. procedure DumpBin ( file f : text ) is
  2674. ------------------------------------------------------------
  2675. variable buf : line ;
  2676. begin
  2677. WriteBinName(f, "DumpBin: ") ;
  2678. -- if NumBins < 1 then
  2679. -- Write(f, "%%FATAL, Coverage Model is empty. Nothing to print." & LF ) ;
  2680. -- end if ;
  2681. for i in 1 to NumBins loop -- CovBinPtr.all'range
  2682. swrite(buf, "%% ") ;
  2683. if CovBinPtr(i).Name.all /= "" then
  2684. swrite(buf, CovBinPtr(i).Name.all & " ") ;
  2685. end if ;
  2686. swrite(buf, "Bin:") ;
  2687. write(buf, CovBinPtr(i).BinVal.all) ;
  2688. case CovBinPtr(i).action is
  2689. when COV_COUNT => swrite(buf, " Count = ") ;
  2690. when COV_IGNORE => swrite(buf, " Ignore = ") ;
  2691. when COV_ILLEGAL => swrite(buf, " Illegal = ") ;
  2692. when others => swrite(buf, " BOGUS BOGUS BOGUS = ") ;
  2693. end case ;
  2694. write(buf, CovBinPtr(i).count) ;
  2695. -- write(f, " Count = " & integer'image(CovBinPtr(i).count)) ;
  2696. write(buf, " AtLeast = " & integer'image(CovBinPtr(i).AtLeast)) ;
  2697. write(buf, " Weight = " & integer'image(CovBinPtr(i).Weight)) ;
  2698. write(buf, " OrderCount = " & integer'image(CovBinPtr(i).OrderCount)) ;
  2699. if CovBinPtr(i).count > 0 then
  2700. write(buf, " Normalized OrderCount = " & integer'image(CovBinPtr(i).OrderCount/CovBinPtr(i).count)) ;
  2701. end if ;
  2702. writeline(f, buf) ;
  2703. end loop ;
  2704. swrite(buf, "") ;
  2705. writeline(f,buf) ;
  2706. end procedure DumpBin ;
  2707. ------------------------------------------------------------
  2708. procedure DumpBin (LogLevel : LogType := DEBUG) is
  2709. ------------------------------------------------------------
  2710. begin
  2711. if IsLogEnabled(AlertLogIDVar, LogLevel) then
  2712. if WriteBinFileInit then
  2713. -- Write to Local WriteBinFile - Deprecated, recommend use TranscriptFile instead
  2714. DumpBin(WriteBinFile) ;
  2715. elsif IsTranscriptEnabled then
  2716. -- Write to TranscriptFile
  2717. DumpBin(TranscriptFile) ;
  2718. if IsTranscriptMirrored then
  2719. -- Mirrored to OUTPUT
  2720. DumpBin(OUTPUT) ;
  2721. end if ;
  2722. else
  2723. -- Default Write to OUTPUT
  2724. DumpBin(OUTPUT) ;
  2725. end if ;
  2726. end if ;
  2727. end procedure DumpBin ;
  2728. ------------------------------------------------------------
  2729. -- pt local
  2730. procedure WriteCovHoles ( file f : text; PercentCov : real := 100.0 ) is
  2731. ------------------------------------------------------------
  2732. variable buf : line ;
  2733. begin
  2734. if NumBins < 1 then
  2735. if WriteBinFileInit or UsingLocalFile then
  2736. -- Duplicate Alert in specified file
  2737. swrite(buf, "%% Alert FAILURE " & GetNamePlus(prefix => "in ", suffix => ", ") & "CoveragePkg.WriteCovHoles:" &
  2738. " coverage model empty. Nothing to print.") ;
  2739. writeline(f, buf) ;
  2740. end if ;
  2741. Alert(AlertLogIDVar, GetNamePlus(prefix => "in ", suffix => ", ") & "CoveragePkg.WriteCovHoles:" &
  2742. " coverage model empty. Nothing to print.", FAILURE) ;
  2743. return ;
  2744. end if ;
  2745. -- Models with Bins
  2746. WriteBinName(f, "WriteCovHoles: ") ;
  2747. CovLoop : for i in 1 to NumBins loop
  2748. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).PercentCov < PercentCov then
  2749. swrite(buf, "%% ") ;
  2750. if CovBinPtr(i).Name.all /= "" then
  2751. swrite(buf, CovBinPtr(i).Name.all & " ") ;
  2752. end if ;
  2753. swrite(buf, "Bin:") ;
  2754. write(buf, CovBinPtr(i).BinVal.all) ;
  2755. write(buf, " Count = " & integer'image(CovBinPtr(i).Count)) ;
  2756. write(buf, " AtLeast = " & integer'image(CovBinPtr(i).AtLeast)) ;
  2757. if WeightMode = WEIGHT or WeightMode = REMAIN_WEIGHT then
  2758. -- Print Weight only when it is used
  2759. write(buf, " Weight = " & integer'image(CovBinPtr(i).Weight)) ;
  2760. end if ;
  2761. writeline(f, buf) ;
  2762. end if ;
  2763. end loop CovLoop ;
  2764. swrite(buf, "") ;
  2765. writeline(f, buf) ;
  2766. end procedure WriteCovHoles ;
  2767. ------------------------------------------------------------
  2768. procedure WriteCovHoles ( PercentCov : real ) is
  2769. ------------------------------------------------------------
  2770. begin
  2771. if WriteBinFileInit then
  2772. -- Write to Local WriteBinFile - Deprecated, recommend use TranscriptFile instead
  2773. WriteCovHoles(WriteBinFile, PercentCov) ;
  2774. elsif IsTranscriptEnabled then
  2775. -- Write to TranscriptFile
  2776. WriteCovHoles(TranscriptFile, PercentCov) ;
  2777. if IsTranscriptMirrored then
  2778. -- Mirrored to OUTPUT
  2779. WriteCovHoles(OUTPUT, PercentCov) ;
  2780. end if ;
  2781. else
  2782. -- Default Write to OUTPUT
  2783. WriteCovHoles(OUTPUT, PercentCov) ;
  2784. end if;
  2785. end procedure WriteCovHoles ;
  2786. ------------------------------------------------------------
  2787. procedure WriteCovHoles ( LogLevel : LogType := ALWAYS ) is
  2788. ------------------------------------------------------------
  2789. begin
  2790. if IsLogEnabled(AlertLogIDVar, LogLevel) then
  2791. WriteCovHoles(CovTarget) ;
  2792. end if;
  2793. end procedure WriteCovHoles ;
  2794. ------------------------------------------------------------
  2795. procedure WriteCovHoles ( LogLevel : LogType ; PercentCov : real ) is
  2796. ------------------------------------------------------------
  2797. begin
  2798. if IsLogEnabled(AlertLogIDVar, LogLevel) then
  2799. WriteCovHoles(PercentCov) ;
  2800. end if;
  2801. end procedure WriteCovHoles ;
  2802. ------------------------------------------------------------
  2803. procedure WriteCovHoles ( FileName : string; OpenKind : File_Open_Kind := APPEND_MODE ) is
  2804. ------------------------------------------------------------
  2805. file CovHoleFile : text open OpenKind is FileName ;
  2806. begin
  2807. UsingLocalFile := TRUE ;
  2808. WriteCovHoles(CovHoleFile, CovTarget) ;
  2809. UsingLocalFile := FALSE ;
  2810. end procedure WriteCovHoles ;
  2811. ------------------------------------------------------------
  2812. procedure WriteCovHoles ( LogLevel : LogType ; FileName : string; OpenKind : File_Open_Kind := APPEND_MODE ) is
  2813. ------------------------------------------------------------
  2814. begin
  2815. if IsLogEnabled(AlertLogIDVar, LogLevel) then
  2816. WriteCovHoles(FileName, OpenKind) ;
  2817. end if;
  2818. end procedure WriteCovHoles ;
  2819. ------------------------------------------------------------
  2820. procedure WriteCovHoles ( FileName : string; PercentCov : real ; OpenKind : File_Open_Kind := APPEND_MODE ) is
  2821. ------------------------------------------------------------
  2822. file CovHoleFile : text open OpenKind is FileName ;
  2823. begin
  2824. UsingLocalFile := TRUE ;
  2825. WriteCovHoles(CovHoleFile, PercentCov) ;
  2826. UsingLocalFile := FALSE ;
  2827. end procedure WriteCovHoles ;
  2828. ------------------------------------------------------------
  2829. procedure WriteCovHoles ( LogLevel : LogType ; FileName : string; PercentCov : real ; OpenKind : File_Open_Kind := APPEND_MODE ) is
  2830. ------------------------------------------------------------
  2831. begin
  2832. if IsLogEnabled(AlertLogIDVar, LogLevel) then
  2833. WriteCovHoles(FileName, PercentCov, OpenKind) ;
  2834. end if;
  2835. end procedure WriteCovHoles ;
  2836. ------------------------------------------------------------
  2837. -- pt local
  2838. impure function FindExactBin (
  2839. -- find an exact match to a bin wrt BinVal, Action, AtLeast, Weight, and Name
  2840. ------------------------------------------------------------
  2841. Merge : boolean ;
  2842. BinVal : RangeArrayType ;
  2843. Action : integer ;
  2844. AtLeast : integer ;
  2845. Weight : integer ;
  2846. Name : string
  2847. ) return integer is
  2848. begin
  2849. if Merge then
  2850. for i in 1 to NumBins loop
  2851. if (BinVal = CovBinPtr(i).BinVal.all) and (Action = CovBinPtr(i).Action) and
  2852. (AtLeast = CovBinPtr(i).AtLeast) and (Weight = CovBinPtr(i).Weight) and
  2853. (Name = CovBinPtr(i).Name.all) then
  2854. return i ;
  2855. end if;
  2856. end loop ;
  2857. end if ;
  2858. return 0 ;
  2859. end function FindExactBin ;
  2860. ------------------------------------------------------------
  2861. -- pt local
  2862. procedure read (
  2863. ------------------------------------------------------------
  2864. buf : inout line ;
  2865. NamePtr : inout line ;
  2866. NameLength : in integer ;
  2867. ReadValid : out boolean
  2868. ) is
  2869. variable Name : string(1 to NameLength) ;
  2870. begin
  2871. if NameLength > 0 then
  2872. read(buf, Name, ReadValid) ;
  2873. NamePtr := new string'(Name) ;
  2874. else
  2875. ReadValid := TRUE ;
  2876. NamePtr := new string'("") ;
  2877. end if ;
  2878. end procedure read ;
  2879. ------------------------------------------------------------
  2880. -- pt local
  2881. procedure ReadCovVars (file CovDbFile : text; Good : out boolean ) is
  2882. ------------------------------------------------------------
  2883. variable buf : line ;
  2884. variable Empty : boolean ;
  2885. variable MultiLineComment : boolean := FALSE ;
  2886. variable ReadValid : boolean ;
  2887. variable GoodLoop1 : boolean ;
  2888. variable iSeed : RandomSeedType ;
  2889. variable iIllegalMode : integer ;
  2890. variable iWeightMode : integer ;
  2891. variable iWeightScale : real ;
  2892. variable iCovThreshold : real ;
  2893. variable iCountMode : integer ;
  2894. variable iNumberOfMessages : integer ;
  2895. variable iThresholdingEnable : boolean ;
  2896. variable iCovTarget : real ;
  2897. variable iMergingEnable : boolean ;
  2898. begin
  2899. -- ReadLoop0 : while not EndFile(CovDbFile) loop
  2900. ReadLoop0 : loop -- allows emulation of "return when"
  2901. -- ReadLine to Get Coverage Model Name, skip blank and comment lines, fails when file empty
  2902. exit when AlertIf(AlertLogIDVar, EndFile(CovDbFile), GetNamePlus(prefix => "in ", suffix => ", ") &
  2903. "CoveragePkg.ReadCovDb: No Coverage Data to read", FAILURE) ;
  2904. ReadLine(CovDbFile, buf) ;
  2905. EmptyOrCommentLine(buf, Empty, MultiLineComment) ;
  2906. next when Empty ;
  2907. if buf.all /= "Coverage_Model_Not_Named" then
  2908. SetName(buf.all) ;
  2909. end if ;
  2910. exit ReadLoop0 ;
  2911. end loop ReadLoop0 ;
  2912. -- ReadLoop1 : while not EndFile(CovDbFile) loop
  2913. ReadLoop1 : loop
  2914. -- ReadLine to Get Variables, skip blank and comment lines, fails when file empty
  2915. exit when AlertIf(AlertLogIDVar, EndFile(CovDbFile), GetNamePlus(prefix => "in ", suffix => ", ") &
  2916. "CoveragePkg.ReadCovDb: Coverage DB File Incomplete", FAILURE) ;
  2917. ReadLine(CovDbFile, buf) ;
  2918. EmptyOrCommentLine(buf, Empty, MultiLineComment) ;
  2919. next when Empty ;
  2920. read(buf, iSeed, ReadValid) ;
  2921. exit when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  2922. "CoveragePkg.ReadCovDb: Failed while reading Seed", FAILURE) ;
  2923. RV.SetSeed( iSeed ) ;
  2924. RvSeedInit := TRUE ;
  2925. read(buf, iCovThreshold, ReadValid) ;
  2926. exit when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  2927. "CoveragePkg.ReadCovDb: Failed while reading CovThreshold", FAILURE) ;
  2928. CovThreshold := iCovThreshold ;
  2929. read(buf, iIllegalMode, ReadValid) ;
  2930. exit when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  2931. "CoveragePkg.ReadCovDb: Failed while reading IllegalMode", FAILURE) ;
  2932. SetIllegalMode(IllegalModeType'val( iIllegalMode )) ;
  2933. read(buf, iWeightMode, ReadValid) ;
  2934. exit when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  2935. "CoveragePkg.ReadCovDb: Failed while reading WeightMode", FAILURE) ;
  2936. WeightMode := WeightModeType'val( iWeightMode ) ;
  2937. read(buf, iWeightScale, ReadValid) ;
  2938. exit when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  2939. "CoveragePkg.ReadCovDb: Failed while reading WeightScale", FAILURE) ;
  2940. WeightScale := iWeightScale ;
  2941. read(buf, iCountMode, ReadValid) ;
  2942. exit when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  2943. "CoveragePkg.ReadCovDb: Failed while reading CountMode", FAILURE) ;
  2944. CountMode := CountModeType'val( iCountMode ) ;
  2945. read(buf, iThresholdingEnable, ReadValid) ;
  2946. exit when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  2947. "CoveragePkg.ReadCovDb: Failed while reading CountMode", FAILURE) ;
  2948. ThresholdingEnable := iThresholdingEnable ;
  2949. read(buf, iCovTarget, ReadValid) ;
  2950. exit when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  2951. "CoveragePkg.ReadCovDb: Failed while reading CountMode", FAILURE) ;
  2952. CovTarget := iCovTarget ;
  2953. read(buf, iMergingEnable, ReadValid) ;
  2954. exit when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  2955. "CoveragePkg.ReadCovDb: Failed while reading CountMode", FAILURE) ;
  2956. MergingEnable := iMergingEnable ;
  2957. exit ReadLoop1 ;
  2958. end loop ReadLoop1 ;
  2959. GoodLoop1 := ReadValid ;
  2960. -- ReadLoop2 : while not EndFile(CovDbFile) loop
  2961. ReadLoop2 : while ReadValid loop
  2962. -- ReadLine to Coverage Model Header WriteBin Message, skip blank and comment lines, fails when file empty
  2963. exit when AlertIf(AlertLogIDVar, EndFile(CovDbFile), GetNamePlus(prefix => "in ", suffix => ", ") &
  2964. "CoveragePkg.ReadCovDb: Coverage DB File Incomplete", FAILURE) ;
  2965. ReadLine(CovDbFile, buf) ;
  2966. EmptyOrCommentLine(buf, Empty, MultiLineComment) ;
  2967. next when Empty ;
  2968. read(buf, iNumberOfMessages, ReadValid) ;
  2969. exit when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  2970. "CoveragePkg.ReadCovDb: Failed while reading NumberOfMessages", FAILURE) ;
  2971. for i in 1 to iNumberOfMessages loop
  2972. exit when AlertIf(AlertLogIDVar, EndFile(CovDbFile), GetNamePlus(prefix => "in ", suffix => ", ") &
  2973. "CoveragePkg.ReadCovDb: End of File while reading Messages", FAILURE) ;
  2974. ReadLine(CovDbFile, buf) ;
  2975. SetMessage(buf.all) ;
  2976. end loop ;
  2977. exit ReadLoop2 ;
  2978. end loop ReadLoop2 ;
  2979. Good := ReadValid and GoodLoop1 ;
  2980. end procedure ReadCovVars ;
  2981. ------------------------------------------------------------
  2982. -- pt local
  2983. procedure ReadCovDbInfo (
  2984. ------------------------------------------------------------
  2985. File CovDbFile : text ;
  2986. variable NumRangeItems : out integer ;
  2987. variable NumLines : out integer ;
  2988. variable Good : out boolean
  2989. ) is
  2990. variable buf : line ;
  2991. variable ReadValid : boolean ;
  2992. variable Empty : boolean ;
  2993. variable MultiLineComment : boolean := FALSE ;
  2994. begin
  2995. ReadLoop : loop
  2996. -- ReadLine to RangeItems NumLines, skip blank and comment lines, fails when file empty
  2997. exit when AlertIf(AlertLogIDVar, EndFile(CovDbFile), GetNamePlus(prefix => "in ", suffix => ", ") &
  2998. "CoveragePkg.ReadCovDb: Coverage DB File Incomplete", FAILURE) ;
  2999. ReadLine(CovDbFile, buf) ;
  3000. EmptyOrCommentLine(buf, Empty, MultiLineComment) ;
  3001. next when Empty ;
  3002. read(buf, NumRangeItems, ReadValid) ;
  3003. exit when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  3004. "CoveragePkg.ReadCovDb: Failed while reading NumRangeItems", FAILURE) ;
  3005. read(buf, NumLines, ReadValid) ;
  3006. exit when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  3007. "CoveragePkg.ReadCovDb: Failed while reading NumLines", FAILURE) ;
  3008. exit ;
  3009. end loop ReadLoop ;
  3010. Good := ReadValid ;
  3011. end procedure ReadCovDbInfo ;
  3012. ------------------------------------------------------------
  3013. -- pt local
  3014. procedure ReadCovDbDataBase (
  3015. ------------------------------------------------------------
  3016. File CovDbFile : text ;
  3017. constant NumRangeItems : in integer ;
  3018. constant NumLines : in integer ;
  3019. constant Merge : in boolean ;
  3020. variable Good : out boolean
  3021. ) is
  3022. variable buf : line ;
  3023. variable Empty : boolean ;
  3024. variable MultiLineComment : boolean := FALSE ;
  3025. variable ReadValid : boolean ;
  3026. -- Format: Action Count min1 max1 min2 max2 ....
  3027. variable Action : integer ;
  3028. variable Count : integer ;
  3029. variable BinVal : RangeArrayType(1 to NumRangeItems) ;
  3030. variable index : integer ;
  3031. variable AtLeast : integer ;
  3032. variable Weight : integer ;
  3033. variable PercentCov : real ;
  3034. variable NameLength : integer ;
  3035. variable SkipBlank : character ;
  3036. variable NamePtr : line ;
  3037. begin
  3038. GrowBins(NumLines) ;
  3039. ReadLoop : for i in 1 to NumLines loop
  3040. GetValidLineLoop: loop
  3041. exit ReadLoop when AlertIf(AlertLogIDVar, EndFile(CovDbFile), GetNamePlus(prefix => "in ", suffix => ", ") &
  3042. "CoveragePkg.ReadCovDb: Did not read specified number of lines", FAILURE) ;
  3043. ReadLine(CovDbFile, buf) ;
  3044. EmptyOrCommentLine(buf, Empty, MultiLineComment) ;
  3045. next GetValidLineLoop when Empty ; -- replace with EmptyLine(buf)
  3046. exit GetValidLineLoop ;
  3047. end loop ;
  3048. read(buf, Action, ReadValid) ;
  3049. exit ReadLoop when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  3050. "CoveragePkg.ReadCovDb: Failed while reading Action", FAILURE) ;
  3051. read(buf, Count, ReadValid) ;
  3052. exit ReadLoop when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  3053. "CoveragePkg.ReadCovDb: Failed while reading Count", FAILURE) ;
  3054. read(buf, AtLeast, ReadValid) ;
  3055. exit ReadLoop when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  3056. "CoveragePkg.ReadCovDb: Failed while reading AtLeast", FAILURE) ;
  3057. read(buf, Weight, ReadValid) ;
  3058. exit ReadLoop when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  3059. "CoveragePkg.ReadCovDb: Failed while reading Weight", FAILURE) ;
  3060. read(buf, PercentCov, ReadValid) ;
  3061. exit ReadLoop when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  3062. "CoveragePkg.ReadCovDb: Failed while reading PercentCov", FAILURE) ;
  3063. read(buf, BinVal, ReadValid) ;
  3064. exit ReadLoop when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  3065. "CoveragePkg.ReadCovDb: Failed while reading BinVal", FAILURE) ;
  3066. read(buf, NameLength, ReadValid) ;
  3067. exit ReadLoop when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  3068. "CoveragePkg.ReadCovDb: Failed while reading Bin Name Length", FAILURE) ;
  3069. read(buf, SkipBlank, ReadValid) ;
  3070. exit ReadLoop when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  3071. "CoveragePkg.ReadCovDb: Failed while reading Bin Name Length", FAILURE) ;
  3072. read(buf, NamePtr, NameLength, ReadValid) ;
  3073. exit ReadLoop when AlertIfNot(AlertLogIDVar, ReadValid, GetNamePlus(prefix => "in ", suffix => ", ") &
  3074. "CoveragePkg.ReadCovDb: Failed while reading Bin Name", FAILURE) ;
  3075. index := FindExactBin(Merge, BinVal, Action, AtLeast, Weight, NamePtr.all) ;
  3076. if index > 0 then
  3077. -- Bin is an exact match so only merge the count values
  3078. CovBinPtr(index).Count := CovBinPtr(index).Count + Count ;
  3079. CovBinPtr(index).PercentCov := real(CovBinPtr(index).Count)*100.0/maximum(real(CovBinPtr(index).AtLeast), 1.0) ;
  3080. else
  3081. InsertNewBin(BinVal, Action, Count, AtLeast, Weight, NamePtr.all, PercentCov) ;
  3082. end if ;
  3083. deallocate(NamePtr) ;
  3084. end loop ReadLoop ;
  3085. Good := ReadValid ;
  3086. end ReadCovDbDataBase ;
  3087. ------------------------------------------------------------
  3088. -- pt local
  3089. procedure ReadCovDb (File CovDbFile : text; Merge : boolean := FALSE) is
  3090. ------------------------------------------------------------
  3091. -- Format: Action Count min1 max1 min2 max2
  3092. -- file CovDbFile : text open READ_MODE is FileName ;
  3093. variable NumRangeItems : integer ;
  3094. variable NumLines : integer ;
  3095. variable ReadValid : boolean ;
  3096. begin
  3097. if not Merge then
  3098. Deallocate ; -- remove any old bins
  3099. end if ;
  3100. ReadLoop : loop
  3101. -- Read coverage private variables to the file
  3102. ReadCovVars(CovDbFile, ReadValid) ;
  3103. exit when not ReadValid ;
  3104. -- Get Coverage dimensions and number of items in file.
  3105. ReadCovDbInfo(CovDbFile, NumRangeItems, NumLines, ReadValid) ;
  3106. exit when not ReadValid ;
  3107. -- Read the file
  3108. ReadCovDbDataBase(CovDbFile, NumRangeItems, NumLines, Merge, ReadValid) ;
  3109. exit ;
  3110. end loop ReadLoop ;
  3111. end ReadCovDb ;
  3112. ------------------------------------------------------------
  3113. procedure ReadCovDb (FileName : string; Merge : boolean := FALSE) is
  3114. ------------------------------------------------------------
  3115. -- Format: Action Count min1 max1 min2 max2
  3116. file CovDbFile : text open READ_MODE is FileName ;
  3117. begin
  3118. ReadCovDb(CovDbFile, Merge) ;
  3119. end procedure ReadCovDb ;
  3120. ------------------------------------------------------------
  3121. -- pt local
  3122. procedure WriteCovDbVars (file CovDbFile : text ) is
  3123. ------------------------------------------------------------
  3124. variable buf : line ;
  3125. begin
  3126. -- write coverage private variables to the file
  3127. swrite(buf, CovNameVar.Get("Coverage_Model_Not_Named")) ;
  3128. writeline(CovDbFile, buf) ;
  3129. write(buf, RV.GetSeed ) ;
  3130. write(buf, ' ') ;
  3131. write(buf, CovThreshold, RIGHT, 0, 5) ;
  3132. write(buf, ' ') ;
  3133. write(buf, IllegalModeType'pos(IllegalMode)) ;
  3134. write(buf, ' ') ;
  3135. write(buf, WeightModeType'pos(WeightMode)) ;
  3136. write(buf, ' ') ;
  3137. write(buf, WeightScale, RIGHT, 0, 6) ;
  3138. write(buf, ' ') ;
  3139. write(buf, CountModeType'pos(CountMode)) ;
  3140. write(buf, ' ') ;
  3141. write(buf, ThresholdingEnable) ; -- boolean
  3142. write(buf, ' ') ;
  3143. write(buf, CovTarget, RIGHT, 0, 6) ; -- Real
  3144. write(buf, ' ') ;
  3145. write(buf, MergingEnable) ; -- boolean
  3146. write(buf, ' ') ;
  3147. writeline(CovDbFile, buf) ;
  3148. write(buf, CovMessageVar.GetCount ) ;
  3149. writeline(CovDbFile, buf) ;
  3150. WriteMessage(CovDbFile, CovMessageVar) ;
  3151. end procedure WriteCovDbVars ;
  3152. ------------------------------------------------------------
  3153. -- pt local
  3154. procedure WriteCovDb (file CovDbFile : text ) is
  3155. ------------------------------------------------------------
  3156. -- Format: Action Count min1 max1 min2 max2
  3157. variable buf : line ;
  3158. begin
  3159. -- write Cover variables to the file
  3160. WriteCovDbVars( CovDbFile ) ;
  3161. -- write NumRangeItems, NumLines
  3162. write(buf, CovBinPtr(1).BinVal'length) ;
  3163. write(buf, ' ') ;
  3164. write(buf, NumBins) ;
  3165. write(buf, ' ') ;
  3166. writeline(CovDbFile, buf) ;
  3167. -- write coverage to a file
  3168. writeloop : for LineCount in 1 to NumBins loop
  3169. write(buf, CovBinPtr(LineCount).Action) ;
  3170. write(buf, ' ') ;
  3171. write(buf, CovBinPtr(LineCount).Count) ;
  3172. write(buf, ' ') ;
  3173. write(buf, CovBinPtr(LineCount).AtLeast) ;
  3174. write(buf, ' ') ;
  3175. write(buf, CovBinPtr(LineCount).Weight) ;
  3176. write(buf, ' ') ;
  3177. write(buf, CovBinPtr(LineCount).PercentCov, RIGHT, 0, 4) ;
  3178. write(buf, ' ') ;
  3179. WriteBinVal(buf, CovBinPtr(LineCount).BinVal.all) ;
  3180. write(buf, ' ') ;
  3181. write(buf, CovBinPtr(LineCount).Name'length) ;
  3182. write(buf, ' ') ;
  3183. write(buf, CovBinPtr(LineCount).Name.all) ;
  3184. writeline(CovDbFile, buf) ;
  3185. end loop WriteLoop ;
  3186. end procedure WriteCovDb ;
  3187. ------------------------------------------------------------
  3188. procedure WriteCovDb (FileName : string; OpenKind : File_Open_Kind := WRITE_MODE ) is
  3189. ------------------------------------------------------------
  3190. -- Format: Action Count min1 max1 min2 max2
  3191. file CovDbFile : text open OpenKind is FileName ;
  3192. begin
  3193. if NumBins >= 1 then
  3194. WriteCovDb(CovDbFile) ;
  3195. else
  3196. Alert(AlertLogIDVar, GetNamePlus(prefix => "in ", suffix => ", ") &
  3197. "CoveragePkg.WriteCovDb: no bins defined ", FAILURE) ;
  3198. end if ;
  3199. end procedure WriteCovDb ;
  3200. -- ------------------------------------------------------------
  3201. -- procedure WriteCovDb is
  3202. -- ------------------------------------------------------------
  3203. -- begin
  3204. -- if WriteCovDbFileInit then
  3205. -- WriteCovDb(WriteCovDbFile) ;
  3206. -- else
  3207. -- report "CoveragePkg: WriteCovDb file not specified" severity failure ;
  3208. -- end if ;
  3209. -- end procedure WriteCovDb ;
  3210. ------------------------------------------------------------
  3211. impure function GetErrorCount return integer is
  3212. ------------------------------------------------------------
  3213. variable ErrorCnt : integer := 0 ;
  3214. begin
  3215. if NumBins < 1 then
  3216. return 1 ; -- return error if model empty
  3217. else
  3218. for i in 1 to NumBins loop
  3219. if CovBinPtr(i).count < 0 then -- illegal CovBin
  3220. ErrorCnt := ErrorCnt + CovBinPtr(i).count ;
  3221. end if ;
  3222. end loop ;
  3223. return - ErrorCnt ;
  3224. end if ;
  3225. end function GetErrorCount ;
  3226. ------------------------------------------------------------
  3227. -- These support usage of cross coverage constants
  3228. -- Also support the older AddBins(GenCross(...)) methodology
  3229. -- which has been replaced by AddCross
  3230. ------------------------------------------------------------
  3231. procedure AddCross (CovBin : CovMatrix2Type ; Name : String := "") is
  3232. ------------------------------------------------------------
  3233. begin
  3234. CheckBinValLength(2, "AddCross") ;
  3235. GrowBins(CovBin'length) ;
  3236. for i in CovBin'range loop
  3237. InsertBin(
  3238. CovBin(i).BinVal, CovBin(i).Action, CovBin(i).Count,
  3239. CovBin(i).AtLeast, CovBin(i).Weight, Name
  3240. ) ;
  3241. end loop ;
  3242. end procedure AddCross ;
  3243. ------------------------------------------------------------
  3244. procedure AddCross (CovBin : CovMatrix3Type ; Name : String := "") is
  3245. ------------------------------------------------------------
  3246. begin
  3247. CheckBinValLength(3, "AddCross") ;
  3248. GrowBins(CovBin'length) ;
  3249. for i in CovBin'range loop
  3250. InsertBin(
  3251. CovBin(i).BinVal, CovBin(i).Action, CovBin(i).Count,
  3252. CovBin(i).AtLeast, CovBin(i).Weight, Name
  3253. ) ;
  3254. end loop ;
  3255. end procedure AddCross ;
  3256. ------------------------------------------------------------
  3257. procedure AddCross (CovBin : CovMatrix4Type ; Name : String := "") is
  3258. ------------------------------------------------------------
  3259. begin
  3260. CheckBinValLength(4, "AddCross") ;
  3261. GrowBins(CovBin'length) ;
  3262. for i in CovBin'range loop
  3263. InsertBin(
  3264. CovBin(i).BinVal, CovBin(i).Action, CovBin(i).Count,
  3265. CovBin(i).AtLeast, CovBin(i).Weight, Name
  3266. ) ;
  3267. end loop ;
  3268. end procedure AddCross ;
  3269. ------------------------------------------------------------
  3270. procedure AddCross (CovBin : CovMatrix5Type ; Name : String := "") is
  3271. ------------------------------------------------------------
  3272. begin
  3273. CheckBinValLength(5, "AddCross") ;
  3274. GrowBins(CovBin'length) ;
  3275. for i in CovBin'range loop
  3276. InsertBin(
  3277. CovBin(i).BinVal, CovBin(i).Action, CovBin(i).Count,
  3278. CovBin(i).AtLeast, CovBin(i).Weight, Name
  3279. ) ;
  3280. end loop ;
  3281. end procedure AddCross ;
  3282. ------------------------------------------------------------
  3283. procedure AddCross (CovBin : CovMatrix6Type ; Name : String := "") is
  3284. ------------------------------------------------------------
  3285. begin
  3286. CheckBinValLength(6, "AddCross") ;
  3287. GrowBins(CovBin'length) ;
  3288. for i in CovBin'range loop
  3289. InsertBin(
  3290. CovBin(i).BinVal, CovBin(i).Action, CovBin(i).Count,
  3291. CovBin(i).AtLeast, CovBin(i).Weight, Name
  3292. ) ;
  3293. end loop ;
  3294. end procedure AddCross ;
  3295. ------------------------------------------------------------
  3296. procedure AddCross (CovBin : CovMatrix7Type ; Name : String := "") is
  3297. ------------------------------------------------------------
  3298. begin
  3299. CheckBinValLength(7, "AddCross") ;
  3300. GrowBins(CovBin'length) ;
  3301. for i in CovBin'range loop
  3302. InsertBin(
  3303. CovBin(i).BinVal, CovBin(i).Action, CovBin(i).Count,
  3304. CovBin(i).AtLeast, CovBin(i).Weight, Name
  3305. ) ;
  3306. end loop ;
  3307. end procedure AddCross ;
  3308. ------------------------------------------------------------
  3309. procedure AddCross (CovBin : CovMatrix8Type ; Name : String := "") is
  3310. ------------------------------------------------------------
  3311. begin
  3312. CheckBinValLength(8, "AddCross") ;
  3313. GrowBins(CovBin'length) ;
  3314. for i in CovBin'range loop
  3315. InsertBin(
  3316. CovBin(i).BinVal, CovBin(i).Action, CovBin(i).Count,
  3317. CovBin(i).AtLeast, CovBin(i).Weight, Name
  3318. ) ;
  3319. end loop ;
  3320. end procedure AddCross ;
  3321. ------------------------------------------------------------
  3322. procedure AddCross (CovBin : CovMatrix9Type ; Name : String := "") is
  3323. ------------------------------------------------------------
  3324. begin
  3325. CheckBinValLength(9, "AddCross") ;
  3326. GrowBins(CovBin'length) ;
  3327. for i in CovBin'range loop
  3328. InsertBin(
  3329. CovBin(i).BinVal, CovBin(i).Action, CovBin(i).Count,
  3330. CovBin(i).AtLeast, CovBin(i).Weight, Name
  3331. ) ;
  3332. end loop ;
  3333. end procedure AddCross ;
  3334. -- ------------------------------------------------------------
  3335. -- ------------------------------------------------------------
  3336. -- Deprecated. Due to name changes to promote greater consistency
  3337. -- Maintained for backward compatibility.
  3338. -- ------------------------------------------------------------
  3339. ------------------------------------------------------------
  3340. impure function CovBinErrCnt return integer is
  3341. -- Deprecated. Name changed to ErrorCount for package to package consistency
  3342. ------------------------------------------------------------
  3343. begin
  3344. return GetErrorCount ;
  3345. end function CovBinErrCnt ;
  3346. ------------------------------------------------------------
  3347. -- Deprecated. Same as RandCovBinVal
  3348. impure function RandCovHole ( PercentCov : real ) return RangeArrayType is
  3349. ------------------------------------------------------------
  3350. begin
  3351. return RandCovBinVal(PercentCov) ;
  3352. end function RandCovHole ;
  3353. ------------------------------------------------------------
  3354. -- Deprecated. Same as RandCovBinVal
  3355. impure function RandCovHole return RangeArrayType is
  3356. ------------------------------------------------------------
  3357. begin
  3358. return RandCovBinVal ;
  3359. end function RandCovHole ;
  3360. -- GetCovHole replaced by GetHoleBinVal
  3361. ------------------------------------------------------------
  3362. -- Deprecated. Same as GetHoleBinVal
  3363. impure function GetCovHole ( ReqHoleNum : integer ; PercentCov : real ) return RangeArrayType is
  3364. ------------------------------------------------------------
  3365. begin
  3366. return GetHoleBinVal(ReqHoleNum, PercentCov) ;
  3367. end function GetCovHole ;
  3368. ------------------------------------------------------------
  3369. -- Deprecated. Same as GetHoleBinVal
  3370. impure function GetCovHole ( PercentCov : real ) return RangeArrayType is
  3371. ------------------------------------------------------------
  3372. begin
  3373. return GetHoleBinVal(PercentCov) ;
  3374. end function GetCovHole ;
  3375. ------------------------------------------------------------
  3376. -- Deprecated. Same as GetHoleBinVal
  3377. impure function GetCovHole ( ReqHoleNum : integer := 1 ) return RangeArrayType is
  3378. ------------------------------------------------------------
  3379. begin
  3380. return GetHoleBinVal(ReqHoleNum) ;
  3381. end function GetCovHole ;
  3382. -- ------------------------------------------------------------
  3383. -- ------------------------------------------------------------
  3384. -- Deprecated / Subsumed by versions with PercentCov Parameter
  3385. -- Maintained for backward compatibility only and
  3386. -- may be removed in the future.
  3387. -- ------------------------------------------------------------
  3388. ------------------------------------------------------------
  3389. -- Deprecated. Replaced by SetMessage with multi-line support
  3390. procedure SetItemName (ItemNameIn : String) is
  3391. ------------------------------------------------------------
  3392. begin
  3393. SetMessage(ItemNameIn) ;
  3394. end procedure SetItemName ;
  3395. ------------------------------------------------------------
  3396. -- Deprecated. Same as GetMinCount
  3397. impure function GetMinCov return integer is
  3398. ------------------------------------------------------------
  3399. begin
  3400. return GetMinCount ;
  3401. end function GetMinCov ;
  3402. ------------------------------------------------------------
  3403. -- Deprecated. Same as GetMaxCount
  3404. impure function GetMaxCov return integer is
  3405. ------------------------------------------------------------
  3406. begin
  3407. return GetMaxCount ;
  3408. end function GetMaxCov ;
  3409. ------------------------------------------------------------
  3410. -- Deprecated. New versions use PercentCov
  3411. impure function CountCovHoles ( AtLeast : integer ) return integer is
  3412. ------------------------------------------------------------
  3413. variable HoleCount : integer := 0 ;
  3414. begin
  3415. CovLoop : for i in 1 to NumBins loop
  3416. -- if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).Count < minimum(AtLeast, CovBinPtr(i).AtLeast) then
  3417. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).Count < AtLeast then
  3418. HoleCount := HoleCount + 1 ;
  3419. end if ;
  3420. end loop CovLoop ;
  3421. return HoleCount ;
  3422. end function CountCovHoles ;
  3423. ------------------------------------------------------------
  3424. -- Deprecated. New versions use PercentCov
  3425. impure function IsCovered ( AtLeast : integer ) return boolean is
  3426. ------------------------------------------------------------
  3427. begin
  3428. return CountCovHoles(AtLeast) = 0 ;
  3429. end function IsCovered ;
  3430. ------------------------------------------------------------
  3431. impure function CalcWeight ( BinIndex : integer ; MaxAtLeast : integer ) return integer is
  3432. -- pt local
  3433. ------------------------------------------------------------
  3434. begin
  3435. case WeightMode is
  3436. when AT_LEAST =>
  3437. return CovBinPtr(BinIndex).AtLeast ;
  3438. when WEIGHT =>
  3439. return CovBinPtr(BinIndex).Weight ;
  3440. when REMAIN =>
  3441. return MaxAtLeast - CovBinPtr(BinIndex).Count ;
  3442. when REMAIN_SCALED =>
  3443. -- Experimental may be removed
  3444. return integer( Ceil( WeightScale * real(MaxAtLeast))) -
  3445. CovBinPtr(BinIndex).Count ;
  3446. when REMAIN_WEIGHT =>
  3447. -- Experimental may be removed
  3448. return CovBinPtr(BinIndex).Weight * (
  3449. integer( Ceil( WeightScale * real(MaxAtLeast))) -
  3450. CovBinPtr(BinIndex).Count ) ;
  3451. when others =>
  3452. Alert(AlertLogIDVar, GetNamePlus(prefix => "in ", suffix => ", ") & "CoveragePkg.CalcWeight:" &
  3453. " Selected Weight Mode not supported with deprecated RandCovPoint(AtLeast), see RandCovPoint(PercentCov)", FAILURE) ;
  3454. return MaxAtLeast - CovBinPtr(BinIndex).Count ;
  3455. end case ;
  3456. end function CalcWeight ;
  3457. ------------------------------------------------------------
  3458. -- Deprecated. New versions use PercentCov
  3459. -- If keep this, need to be able to scale AtLeast Value
  3460. impure function RandHoleIndex ( AtLeast : integer ) return integer is
  3461. -- pt local
  3462. ------------------------------------------------------------
  3463. variable WeightVec : integer_vector(0 to NumBins-1) ; -- Prep for change to DistInt
  3464. variable MinCount, AdjAtLeast, MaxAtLeast : integer ;
  3465. begin
  3466. ItemCount := ItemCount + 1 ;
  3467. MinCount := GetMinCov ;
  3468. -- iAtLeast := integer(ceil(CovTarget * real(AtLeast)/100.0)) ;
  3469. if ThresholdingEnable then
  3470. AdjAtLeast := MinCount + integer(CovThreshold) + 1 ;
  3471. if MinCount < AtLeast then
  3472. -- Clip at AtLeast until reach AtLeast
  3473. AdjAtLeast := minimum(AdjAtLeast, AtLeast) ;
  3474. end if ;
  3475. else
  3476. if MinCount < AtLeast then
  3477. AdjAtLeast := AtLeast ; -- Valid
  3478. else
  3479. -- Done, Enable all bins
  3480. -- AdjAtLeast := integer'right ; -- Get All
  3481. AdjAtLeast := GetMaxCov + 1 ; -- Get All
  3482. end if ;
  3483. end if;
  3484. MaxAtLeast := AdjAtLeast ;
  3485. CovLoop : for i in 1 to NumBins loop
  3486. -- if not ThresholdingEnable then
  3487. -- -- When not thresholding, consider bin Bin.AtLeast
  3488. -- -- iBinAtLeast := integer(ceil(CovTarget * real(CovBinPtr(i).AtLeast)/100.0)) ;
  3489. -- MaxAtLeast := maximum(AdjAtLeast, CovBinPtr(i).AtLeast) ;
  3490. -- end if ;
  3491. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).Count < MaxAtLeast then
  3492. WeightVec(i-1) := CalcWeight(i, MaxAtLeast ) ; -- CovBinPtr(i).Weight ;
  3493. else
  3494. WeightVec(i-1) := 0 ;
  3495. end if ;
  3496. end loop CovLoop ;
  3497. -- DistInt returns integer range 0 to Numbins-1
  3498. LastIndex := 1 + RV.DistInt( WeightVec ) ; -- return range 1 to NumBins
  3499. return LastIndex ;
  3500. end function RandHoleIndex ;
  3501. ------------------------------------------------------------
  3502. -- Deprecated. New versions use PercentCov
  3503. impure function RandCovBinVal (AtLeast : integer ) return RangeArrayType is
  3504. ------------------------------------------------------------
  3505. begin
  3506. return CovBinPtr( RandHoleIndex(AtLeast) ).BinVal.all ; -- GetBinVal
  3507. end function RandCovBinVal ;
  3508. -- Maintained for backward compatibility. Repeated until aliases work for methods
  3509. ------------------------------------------------------------
  3510. -- Deprecated+ New versions use PercentCov. Name change.
  3511. impure function RandCovHole (AtLeast : integer ) return RangeArrayType is
  3512. ------------------------------------------------------------
  3513. begin
  3514. return RandCovBinVal(AtLeast) ; -- GetBinVal
  3515. end function RandCovHole ;
  3516. ------------------------------------------------------------
  3517. -- Deprecated. New versions use PercentCov
  3518. impure function RandCovPoint (AtLeast : integer ) return integer is
  3519. ------------------------------------------------------------
  3520. variable BinVal : RangeArrayType(1 to 1) ;
  3521. begin
  3522. BinVal := RandCovBinVal(AtLeast) ;
  3523. return RV.RandInt(BinVal(1).min, BinVal(1).max) ;
  3524. end function RandCovPoint ;
  3525. ------------------------------------------------------------
  3526. impure function RandCovPoint (AtLeast : integer ) return integer_vector is
  3527. ------------------------------------------------------------
  3528. begin
  3529. return ToRandPoint(RandCovBinVal(AtLeast)) ;
  3530. end function RandCovPoint ;
  3531. ------------------------------------------------------------
  3532. -- Deprecated. New versions use PercentCov
  3533. impure function GetHoleBinVal ( ReqHoleNum : integer ; AtLeast : integer ) return RangeArrayType is
  3534. ------------------------------------------------------------
  3535. variable HoleCount : integer := 0 ;
  3536. variable buf : line ;
  3537. begin
  3538. CovLoop : for i in 1 to NumBins loop
  3539. -- if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).Count < minimum(AtLeast, CovBinPtr(i).AtLeast) then
  3540. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).Count < AtLeast then
  3541. HoleCount := HoleCount + 1 ;
  3542. if HoleCount = ReqHoleNum then
  3543. return CovBinPtr(i).BinVal.all ;
  3544. end if ;
  3545. end if ;
  3546. end loop CovLoop ;
  3547. Alert(AlertLogIDVar, GetNamePlus(prefix => "in ", suffix => ", ") & "CoveragePkg.GetHoleBinVal:" &
  3548. " did not find hole. HoleCount = " & integer'image(HoleCount) &
  3549. "ReqHoleNum = " & integer'image(ReqHoleNum), ERROR
  3550. ) ;
  3551. return CovBinPtr(NumBins).BinVal.all ;
  3552. end function GetHoleBinVal ;
  3553. ------------------------------------------------------------
  3554. -- Deprecated+. New versions use PercentCov. Name Change.
  3555. impure function GetCovHole ( ReqHoleNum : integer ; AtLeast : integer ) return RangeArrayType is
  3556. ------------------------------------------------------------
  3557. begin
  3558. return GetHoleBinVal(ReqHoleNum, AtLeast) ;
  3559. end function GetCovHole ;
  3560. ------------------------------------------------------------
  3561. -- pt local
  3562. -- Deprecated. New versions use PercentCov.
  3563. procedure WriteCovHoles ( file f : text; AtLeast : integer ) is
  3564. ------------------------------------------------------------
  3565. -- variable minAtLeast : integer ;
  3566. variable buf : line ;
  3567. begin
  3568. WriteBinName(f, "WriteCovHoles: ") ;
  3569. if NumBins < 1 then
  3570. if WriteBinFileInit or UsingLocalFile then
  3571. -- Duplicate Alert in specified file
  3572. swrite(buf, "%% Alert FAILURE " & GetNamePlus(prefix => "in ", suffix => ", ") & "CoveragePkg.WriteCovHoles:" &
  3573. " coverage model is empty. Nothing to print.") ;
  3574. writeline(f, buf) ;
  3575. end if ;
  3576. Alert(AlertLogIDVar, GetNamePlus(prefix => "in ", suffix => ", ") & "CoveragePkg.WriteCovHoles:" &
  3577. " coverage model is empty. Nothing to print.", FAILURE) ;
  3578. end if ;
  3579. CovLoop : for i in 1 to NumBins loop
  3580. -- minAtLeast := minimum(AtLeast,CovBinPtr(i).AtLeast) ;
  3581. -- if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).Count < minAtLeast then
  3582. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).Count < AtLeast then
  3583. swrite(buf, "%% Bin:") ;
  3584. write(buf, CovBinPtr(i).BinVal.all) ;
  3585. write(buf, " Count = " & integer'image(CovBinPtr(i).Count)) ;
  3586. write(buf, " AtLeast = " & integer'image(CovBinPtr(i).AtLeast)) ;
  3587. if WeightMode = WEIGHT or WeightMode = REMAIN_WEIGHT then
  3588. -- Print Weight only when it is used
  3589. write(buf, " Weight = " & integer'image(CovBinPtr(i).Weight)) ;
  3590. end if ;
  3591. writeline(f, buf) ;
  3592. end if ;
  3593. end loop CovLoop ;
  3594. swrite(buf, "") ;
  3595. writeline(f, buf) ;
  3596. end procedure WriteCovHoles ;
  3597. ------------------------------------------------------------
  3598. -- Deprecated. New versions use PercentCov.
  3599. procedure WriteCovHoles ( AtLeast : integer ) is
  3600. ------------------------------------------------------------
  3601. begin
  3602. if WriteBinFileInit then
  3603. -- Write to Local WriteBinFile - Deprecated, recommend use TranscriptFile instead
  3604. WriteCovHoles(WriteBinFile, AtLeast) ;
  3605. elsif IsTranscriptEnabled then
  3606. -- Write to TranscriptFile
  3607. WriteCovHoles(TranscriptFile, AtLeast) ;
  3608. if IsTranscriptMirrored then
  3609. -- Mirrored to OUTPUT
  3610. WriteCovHoles(OUTPUT, AtLeast) ;
  3611. end if ;
  3612. else
  3613. -- Default Write to OUTPUT
  3614. WriteCovHoles(OUTPUT, AtLeast) ;
  3615. end if;
  3616. end procedure WriteCovHoles ;
  3617. ------------------------------------------------------------
  3618. -- Deprecated. New versions use PercentCov.
  3619. procedure WriteCovHoles ( LogLevel : LogType ; AtLeast : integer ) is
  3620. ------------------------------------------------------------
  3621. begin
  3622. if IsLogEnabled(AlertLogIDVar, LogLevel) then
  3623. WriteCovHoles(AtLeast) ;
  3624. end if;
  3625. end procedure WriteCovHoles ;
  3626. ------------------------------------------------------------
  3627. -- Deprecated. New versions use PercentCov.
  3628. procedure WriteCovHoles ( FileName : string; AtLeast : integer ; OpenKind : File_Open_Kind := APPEND_MODE ) is
  3629. ------------------------------------------------------------
  3630. file CovHoleFile : text open OpenKind is FileName ;
  3631. begin
  3632. WriteCovHoles(CovHoleFile, AtLeast) ;
  3633. end procedure WriteCovHoles ;
  3634. ------------------------------------------------------------
  3635. -- Deprecated. New versions use PercentCov.
  3636. procedure WriteCovHoles ( LogLevel : LogType ; FileName : string; AtLeast : integer ; OpenKind : File_Open_Kind := APPEND_MODE ) is
  3637. ------------------------------------------------------------
  3638. begin
  3639. if IsLogEnabled(AlertLogIDVar, LogLevel) then
  3640. WriteCovHoles(FileName, AtLeast, OpenKind) ;
  3641. end if;
  3642. end procedure WriteCovHoles ;
  3643. ------------------------------------------------------------
  3644. -- Deprecated. Use AddCross Instead.
  3645. procedure AddBins (CovBin : CovMatrix2Type ; Name : String := "") is
  3646. ------------------------------------------------------------
  3647. begin
  3648. AddCross(CovBin, Name) ;
  3649. end procedure AddBins ;
  3650. ------------------------------------------------------------
  3651. procedure AddBins (CovBin : CovMatrix3Type ; Name : String := "") is
  3652. ------------------------------------------------------------
  3653. begin
  3654. AddCross(CovBin, Name) ;
  3655. end procedure AddBins ;
  3656. ------------------------------------------------------------
  3657. procedure AddBins (CovBin : CovMatrix4Type ; Name : String := "") is
  3658. ------------------------------------------------------------
  3659. begin
  3660. AddCross(CovBin, Name) ;
  3661. end procedure AddBins ;
  3662. ------------------------------------------------------------
  3663. procedure AddBins (CovBin : CovMatrix5Type ; Name : String := "") is
  3664. ------------------------------------------------------------
  3665. begin
  3666. AddCross(CovBin, Name) ;
  3667. end procedure AddBins ;
  3668. ------------------------------------------------------------
  3669. procedure AddBins (CovBin : CovMatrix6Type ; Name : String := "") is
  3670. ------------------------------------------------------------
  3671. begin
  3672. AddCross(CovBin, Name) ;
  3673. end procedure AddBins ;
  3674. ------------------------------------------------------------
  3675. procedure AddBins (CovBin : CovMatrix7Type ; Name : String := "") is
  3676. ------------------------------------------------------------
  3677. begin
  3678. AddCross(CovBin, Name) ;
  3679. end procedure AddBins ;
  3680. ------------------------------------------------------------
  3681. procedure AddBins (CovBin : CovMatrix8Type ; Name : String := "") is
  3682. ------------------------------------------------------------
  3683. begin
  3684. AddCross(CovBin, Name) ;
  3685. end procedure AddBins ;
  3686. ------------------------------------------------------------
  3687. procedure AddBins (CovBin : CovMatrix9Type ; Name : String := "") is
  3688. ------------------------------------------------------------
  3689. begin
  3690. AddCross(CovBin, Name) ;
  3691. end procedure AddBins ;
  3692. end protected body CovPType ;
  3693. ------------------------------------------------------------------------------------------
  3694. -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CovPType XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  3695. -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CovPType XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  3696. ------------------------------------------------------------------------------------------
  3697. ------------------------------------------------------------
  3698. -- Experimental. Intended primarily for development.
  3699. procedure CompareBins (
  3700. ------------------------------------------------------------
  3701. variable Bin1 : inout CovPType ;
  3702. variable Bin2 : inout CovPType ;
  3703. variable ErrorCount : inout integer
  3704. ) is
  3705. variable NumBins1, NumBins2 : integer ;
  3706. variable BinInfo1, BinInfo2 : CovBinBaseType ;
  3707. variable BinVal1, BinVal2 : RangeArrayType(1 to Bin1.GetBinValLength) ;
  3708. variable buf : line ;
  3709. variable iAlertLogID : AlertLogIDType ;
  3710. begin
  3711. iAlertLogID := Bin1.GetAlertLogID ;
  3712. NumBins1 := Bin1.GetNumBins ;
  3713. NumBins2 := Bin2.GetNumBins ;
  3714. if (NumBins1 /= NumBins2) then
  3715. ErrorCount := ErrorCount + 1 ;
  3716. print("CoveragePkg.CompareBins: CoverageModels " & Bin1.GetCovModelName & " and " & Bin2.GetCovModelName &
  3717. " have different bin lengths") ;
  3718. return ;
  3719. end if ;
  3720. for i in 1 to NumBins1 loop
  3721. BinInfo1 := Bin1.GetBinInfo(i) ;
  3722. BinInfo2 := Bin2.GetBinInfo(i) ;
  3723. BinVal1 := Bin1.GetBinVal(i) ;
  3724. BinVal2 := Bin2.GetBinVal(i) ;
  3725. if BinInfo1 /= BinInfo2 or BinVal1 /= BinVal2 then
  3726. write(buf, "%% Bin:" & integer'image(i) & " miscompare." & LF) ;
  3727. -- writeline(OUTPUT, buf) ;
  3728. swrite(buf, "%% Bin1: ") ;
  3729. write(buf, BinVal1) ;
  3730. write(buf, " Action = " & integer'image(BinInfo1.action)) ;
  3731. write(buf, " Count = " & integer'image(BinInfo1.count)) ;
  3732. write(buf, " AtLeast = " & integer'image(BinInfo1.AtLeast)) ;
  3733. write(buf, " Weight = " & integer'image(BinInfo1.Weight) & LF ) ;
  3734. -- writeline(OUTPUT, buf) ;
  3735. swrite(buf, "%% Bin2: ") ;
  3736. write(buf, BinVal2) ;
  3737. write(buf, " Action = " & integer'image(BinInfo2.action)) ;
  3738. write(buf, " Count = " & integer'image(BinInfo2.count)) ;
  3739. write(buf, " AtLeast = " & integer'image(BinInfo2.AtLeast)) ;
  3740. write(buf, " Weight = " & integer'image(BinInfo2.Weight) & LF ) ;
  3741. -- writeline(OUTPUT, buf) ;
  3742. ErrorCount := ErrorCount + 1 ;
  3743. writeline(buf) ;
  3744. -- Alert(iAlertLogID, buf.all, ERROR) ;
  3745. -- deallocate(buf) ;
  3746. end if ;
  3747. end loop ;
  3748. end procedure CompareBins ;
  3749. ------------------------------------------------------------
  3750. -- Experimental. Intended primarily for development.
  3751. procedure CompareBins (
  3752. ------------------------------------------------------------
  3753. variable Bin1 : inout CovPType ;
  3754. variable Bin2 : inout CovPType
  3755. ) is
  3756. variable ErrorCount : integer ;
  3757. variable iAlertLogID : AlertLogIDType ;
  3758. begin
  3759. CompareBins(Bin1, Bin2, ErrorCount) ;
  3760. iAlertLogID := Bin1.GetAlertLogID ;
  3761. AlertIf(ErrorCount /= 0, "CoveragePkg.CompareBins: CoverageModels " & Bin1.GetCovModelName & " and " & Bin2.GetCovModelName & " are not the same.") ;
  3762. end procedure CompareBins ;
  3763. ------------------------------------------------------------
  3764. -- package local, Used by GenBin, IllegalBin, and IgnoreBin
  3765. function MakeBin(
  3766. -- Must be pure to allow initializing coverage models passed as generics.
  3767. -- Impure implies the expression is not globally static.
  3768. ------------------------------------------------------------
  3769. Min, Max : integer ;
  3770. NumBin : integer ;
  3771. AtLeast : integer ;
  3772. Weight : integer ;
  3773. Action : integer
  3774. ) return CovBinType is
  3775. variable iCovBin : CovBinType(1 to NumBin) ;
  3776. variable TotalBins : integer ; -- either real or integer
  3777. variable rMax, rCurMin, rNumItemsInBin, rRemainingBins : real ; -- must be real
  3778. variable iCurMin, iCurMax : integer ;
  3779. begin
  3780. if Min > Max then
  3781. -- Similar to NULL ranges. Only generate report warning.
  3782. report "OSVVM.CoveragePkg.MakeBin (called by GenBin, IllegalBin, or IgnoreBin) MAX > MIN generated NULL_BIN"
  3783. severity WARNING ;
  3784. -- No Alerts. They make this impure.
  3785. -- Alert(OSVVM_ALERTLOG_ID, "CoveragePkg.MakeBin (called by GenBin, IllegalBin, IgnoreBin): Min must be <= Max", WARNING) ;
  3786. return NULL_BIN ;
  3787. elsif NumBin <= 0 then
  3788. -- Similar to NULL ranges. Only generate report warning.
  3789. report "OSVVM.CoveragePkg.MakeBin (called by GenBin, IllegalBin, or IgnoreBin) NumBin <= 0 generated NULL_BIN"
  3790. severity WARNING ;
  3791. -- Alerts make this impure.
  3792. -- Alert(OSVVM_ALERTLOG_ID, "CoveragePkg.MakeBin (called by GenBin, IllegalBin, IgnoreBin): NumBin must be <= 0", WARNING) ;
  3793. return NULL_BIN ;
  3794. elsif NumBin = 1 then
  3795. iCovBin(1) := (
  3796. BinVal => (1 => (Min, Max)),
  3797. Action => Action,
  3798. Count => 0,
  3799. Weight => Weight,
  3800. AtLeast => AtLeast
  3801. ) ;
  3802. return iCovBin ;
  3803. else
  3804. -- Using type real to work around issues with integer sizing
  3805. iCurMin := Min ;
  3806. rCurMin := real(iCurMin) ;
  3807. rMax := real(Max) ;
  3808. rRemainingBins := (minimum( real(NumBin), rMax - rCurMin + 1.0 )) ;
  3809. TotalBins := integer(rRemainingBins) ;
  3810. for i in iCovBin'range loop
  3811. rNumItemsInBin := trunc((rMax - rCurMin + 1.0) / rRemainingBins) ; -- Max - Min can be larger than integer range.
  3812. iCurMax := iCurMin - integer(-rNumItemsInBin + 1.0) ; -- Keep: the "minus negative" works around a simulator bounds issue found in 2015.06
  3813. iCovBin(i) := (
  3814. BinVal => (1 => (iCurMin, iCurMax)),
  3815. Action => Action,
  3816. Count => 0,
  3817. Weight => Weight,
  3818. AtLeast => AtLeast
  3819. ) ;
  3820. rRemainingBins := rRemainingBins - 1.0 ;
  3821. exit when rRemainingBins = 0.0 ;
  3822. iCurMin := iCurMax + 1 ;
  3823. rCurMin := real(iCurMin) ;
  3824. end loop ;
  3825. return iCovBin(1 to TotalBins) ;
  3826. end if ;
  3827. end function MakeBin ;
  3828. ------------------------------------------------------------
  3829. -- package local, Used by GenBin, IllegalBin, and IgnoreBin
  3830. function MakeBin(
  3831. ------------------------------------------------------------
  3832. A : integer_vector ;
  3833. AtLeast : integer ;
  3834. Weight : integer ;
  3835. Action : integer
  3836. ) return CovBinType is
  3837. alias NewA : integer_vector(1 to A'length) is A ;
  3838. variable iCovBin : CovBinType(1 to A'length) ;
  3839. begin
  3840. if A'length <= 0 then
  3841. -- Similar to NULL ranges. Only generate report warning.
  3842. report "OSVVM.CoveragePkg.MakeBin (called by GenBin, IllegalBin, or IgnoreBin) integer_vector length <= 0 generated NULL_BIN"
  3843. severity WARNING ;
  3844. -- Alerts make this impure.
  3845. -- Alert(OSVVM_ALERTLOG_ID, "CoveragePkg.MakeBin (GenBin, IllegalBin, IgnoreBin): integer_vector parameter must have values", WARNING) ;
  3846. return NULL_BIN ;
  3847. else
  3848. for i in NewA'Range loop
  3849. iCovBin(i) := (
  3850. BinVal => (i => (NewA(i), NewA(i)) ),
  3851. Action => Action,
  3852. Count => 0,
  3853. Weight => Weight,
  3854. AtLeast => AtLeast
  3855. ) ;
  3856. end loop ;
  3857. return iCovBin ;
  3858. end if ;
  3859. end function MakeBin ;
  3860. ------------------------------------------------------------
  3861. function GenBin(
  3862. ------------------------------------------------------------
  3863. AtLeast : integer ;
  3864. Weight : integer ;
  3865. Min, Max : integer ;
  3866. NumBin : integer
  3867. ) return CovBinType is
  3868. begin
  3869. return MakeBin(
  3870. Min => Min,
  3871. Max => Max,
  3872. NumBin => NumBin,
  3873. AtLeast => AtLeast,
  3874. Weight => Weight,
  3875. Action => COV_COUNT
  3876. ) ;
  3877. end function GenBin ;
  3878. ------------------------------------------------------------
  3879. function GenBin( AtLeast : integer ; Min, Max, NumBin : integer ) return CovBinType is
  3880. ------------------------------------------------------------
  3881. begin
  3882. return MakeBin(
  3883. Min => Min,
  3884. Max => Max,
  3885. NumBin => NumBin,
  3886. AtLeast => AtLeast,
  3887. Weight => 1,
  3888. Action => COV_COUNT
  3889. ) ;
  3890. end function GenBin ;
  3891. ------------------------------------------------------------
  3892. function GenBin( Min, Max, NumBin : integer ) return CovBinType is
  3893. ------------------------------------------------------------
  3894. begin
  3895. return MakeBin(
  3896. Min => Min,
  3897. Max => Max,
  3898. NumBin => NumBin,
  3899. AtLeast => 1,
  3900. Weight => 1,
  3901. Action => COV_COUNT
  3902. ) ;
  3903. end function GenBin ;
  3904. ------------------------------------------------------------
  3905. function GenBin ( Min, Max : integer) return CovBinType is
  3906. ------------------------------------------------------------
  3907. begin
  3908. -- create a separate CovBin for each value
  3909. -- AtLeast and Weight = 1 (must use longer version to specify)
  3910. return MakeBin(
  3911. Min => Min,
  3912. Max => Max,
  3913. NumBin => Max - Min + 1,
  3914. AtLeast => 1,
  3915. Weight => 1,
  3916. Action => COV_COUNT
  3917. ) ;
  3918. end function GenBin ;
  3919. ------------------------------------------------------------
  3920. function GenBin ( A : integer ) return CovBinType is
  3921. ------------------------------------------------------------
  3922. begin
  3923. -- create a single CovBin for A.
  3924. -- AtLeast and Weight = 1 (must use longer version to specify)
  3925. return MakeBin(
  3926. Min => A,
  3927. Max => A,
  3928. NumBin => 1,
  3929. AtLeast => 1,
  3930. Weight => 1,
  3931. Action => COV_COUNT
  3932. ) ;
  3933. end function GenBin ;
  3934. ------------------------------------------------------------
  3935. function GenBin(
  3936. ------------------------------------------------------------
  3937. AtLeast : integer ;
  3938. Weight : integer ;
  3939. A : integer_vector
  3940. ) return CovBinType is
  3941. begin
  3942. return MakeBin(
  3943. A => A,
  3944. AtLeast => AtLeast,
  3945. Weight => Weight,
  3946. Action => COV_COUNT
  3947. ) ;
  3948. end function GenBin ;
  3949. ------------------------------------------------------------
  3950. function GenBin ( AtLeast : integer ; A : integer_vector ) return CovBinType is
  3951. ------------------------------------------------------------
  3952. begin
  3953. return MakeBin(
  3954. A => A,
  3955. AtLeast => AtLeast,
  3956. Weight => 1,
  3957. Action => COV_COUNT
  3958. ) ;
  3959. end function GenBin ;
  3960. ------------------------------------------------------------
  3961. function GenBin ( A : integer_vector ) return CovBinType is
  3962. ------------------------------------------------------------
  3963. begin
  3964. return MakeBin(
  3965. A => A,
  3966. AtLeast => 1,
  3967. Weight => 1,
  3968. Action => COV_COUNT
  3969. ) ;
  3970. end function GenBin ;
  3971. ------------------------------------------------------------
  3972. function IllegalBin ( Min, Max, NumBin : integer ) return CovBinType is
  3973. ------------------------------------------------------------
  3974. begin
  3975. return MakeBin(
  3976. Min => Min,
  3977. Max => Max,
  3978. NumBin => NumBin,
  3979. AtLeast => 0,
  3980. Weight => 0,
  3981. Action => COV_ILLEGAL
  3982. ) ;
  3983. end function IllegalBin ;
  3984. ------------------------------------------------------------
  3985. function IllegalBin ( Min, Max : integer ) return CovBinType is
  3986. ------------------------------------------------------------
  3987. begin
  3988. -- default, generate one CovBin with the entire range of values
  3989. return MakeBin(
  3990. Min => Min,
  3991. Max => Max,
  3992. NumBin => 1,
  3993. AtLeast => 0,
  3994. Weight => 0,
  3995. Action => COV_ILLEGAL
  3996. ) ;
  3997. end function IllegalBin ;
  3998. ------------------------------------------------------------
  3999. function IllegalBin ( A : integer ) return CovBinType is
  4000. ------------------------------------------------------------
  4001. begin
  4002. return MakeBin(
  4003. Min => A,
  4004. Max => A,
  4005. NumBin => 1,
  4006. AtLeast => 0,
  4007. Weight => 0,
  4008. Action => COV_ILLEGAL
  4009. ) ;
  4010. end function IllegalBin ;
  4011. -- IgnoreBin should never have an AtLeast parameter
  4012. ------------------------------------------------------------
  4013. function IgnoreBin (Min, Max, NumBin : integer) return CovBinType is
  4014. ------------------------------------------------------------
  4015. begin
  4016. return MakeBin(
  4017. Min => Min,
  4018. Max => Max,
  4019. NumBin => NumBin,
  4020. AtLeast => 0,
  4021. Weight => 0,
  4022. Action => COV_IGNORE
  4023. ) ;
  4024. end function IgnoreBin ;
  4025. ------------------------------------------------------------
  4026. function IgnoreBin (Min, Max : integer) return CovBinType is
  4027. ------------------------------------------------------------
  4028. begin
  4029. -- default, generate one CovBin with the entire range of values
  4030. return MakeBin(
  4031. Min => Min,
  4032. Max => Max,
  4033. NumBin => 1,
  4034. AtLeast => 0,
  4035. Weight => 0,
  4036. Action => COV_IGNORE
  4037. ) ;
  4038. end function IgnoreBin ;
  4039. ------------------------------------------------------------
  4040. function IgnoreBin (A : integer) return CovBinType is
  4041. ------------------------------------------------------------
  4042. begin
  4043. return MakeBin(
  4044. Min => A,
  4045. Max => A,
  4046. NumBin => 1,
  4047. AtLeast => 0,
  4048. Weight => 0,
  4049. Action => COV_IGNORE
  4050. ) ;
  4051. end function IgnoreBin ;
  4052. ------------------------------------------------------------
  4053. function GenCross( -- 2
  4054. -- Cross existing bins
  4055. -- Use AddCross for adding values directly to coverage database
  4056. -- Use GenCross for constants
  4057. ------------------------------------------------------------
  4058. AtLeast : integer ;
  4059. Weight : integer ;
  4060. Bin1, Bin2 : CovBinType
  4061. ) return CovMatrix2Type is
  4062. constant BIN_LENS : integer_vector := BinLengths(Bin1, Bin2) ;
  4063. constant NUM_NEW_BINS : integer := CalcNumCrossBins(BIN_LENS) ;
  4064. variable BinIndex : integer_vector(1 to BIN_LENS'length) := (others => 1) ;
  4065. variable CrossBins : CovBinType(BinIndex'range) ;
  4066. variable Action : integer ;
  4067. variable iCovMatrix : CovMatrix2Type(1 to NUM_NEW_BINS) ;
  4068. begin
  4069. for MatrixIndex in iCovMatrix'range loop
  4070. CrossBins := ConcatenateBins(BinIndex, Bin1, Bin2) ;
  4071. Action := MergeState(CrossBins) ;
  4072. iCovMatrix(MatrixIndex).action := Action ;
  4073. iCovMatrix(MatrixIndex).count := 0 ;
  4074. iCovMatrix(MatrixIndex).BinVal := MergeBinVal(CrossBins) ;
  4075. iCovMatrix(MatrixIndex).AtLeast := MergeAtLeast( Action, AtLeast, CrossBins) ;
  4076. iCovMatrix(MatrixIndex).Weight := MergeWeight ( Action, Weight, CrossBins) ;
  4077. IncBinIndex( BinIndex, BIN_LENS ) ; -- increment right most one, then if overflow, increment next
  4078. end loop ;
  4079. return iCovMatrix ;
  4080. end function GenCross ;
  4081. ------------------------------------------------------------
  4082. function GenCross(AtLeast : integer ; Bin1, Bin2 : CovBinType) return CovMatrix2Type is
  4083. -- Cross existing bins -- use AddCross instead
  4084. ------------------------------------------------------------
  4085. begin
  4086. return GenCross(AtLeast, 0, Bin1, Bin2) ;
  4087. end function GenCross ;
  4088. ------------------------------------------------------------
  4089. function GenCross(Bin1, Bin2 : CovBinType) return CovMatrix2Type is
  4090. -- Cross existing bins -- use AddCross instead
  4091. ------------------------------------------------------------
  4092. begin
  4093. return GenCross(0, 0, Bin1, Bin2) ;
  4094. end function GenCross ;
  4095. ------------------------------------------------------------
  4096. function GenCross( -- 3
  4097. ------------------------------------------------------------
  4098. AtLeast : integer ;
  4099. Weight : integer ;
  4100. Bin1, Bin2, Bin3 : CovBinType
  4101. ) return CovMatrix3Type is
  4102. constant BIN_LENS : integer_vector := BinLengths(Bin1, Bin2, Bin3) ;
  4103. constant NUM_NEW_BINS : integer := CalcNumCrossBins(BIN_LENS) ;
  4104. variable BinIndex : integer_vector(1 to BIN_LENS'length) := (others => 1) ;
  4105. variable CrossBins : CovBinType(BinIndex'range) ;
  4106. variable Action : integer ;
  4107. variable iCovMatrix : CovMatrix3Type(1 to NUM_NEW_BINS) ;
  4108. begin
  4109. for MatrixIndex in iCovMatrix'range loop
  4110. CrossBins := ConcatenateBins(BinIndex, Bin1, Bin2, Bin3) ;
  4111. Action := MergeState(CrossBins) ;
  4112. iCovMatrix(MatrixIndex).action := Action ;
  4113. iCovMatrix(MatrixIndex).count := 0 ;
  4114. iCovMatrix(MatrixIndex).BinVal := MergeBinVal(CrossBins) ;
  4115. iCovMatrix(MatrixIndex).AtLeast := MergeAtLeast( Action, AtLeast, CrossBins) ;
  4116. iCovMatrix(MatrixIndex).Weight := MergeWeight ( Action, Weight, CrossBins) ;
  4117. IncBinIndex( BinIndex, BIN_LENS ) ; -- increment right most one, then if overflow, increment next
  4118. end loop ;
  4119. return iCovMatrix ;
  4120. end function GenCross ;
  4121. ------------------------------------------------------------
  4122. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3 : CovBinType ) return CovMatrix3Type is
  4123. ------------------------------------------------------------
  4124. begin
  4125. return GenCross(AtLeast, 0, Bin1, Bin2, Bin3) ;
  4126. end function GenCross ;
  4127. ------------------------------------------------------------
  4128. function GenCross( Bin1, Bin2, Bin3 : CovBinType ) return CovMatrix3Type is
  4129. ------------------------------------------------------------
  4130. begin
  4131. return GenCross(0, 0, Bin1, Bin2, Bin3) ;
  4132. end function GenCross ;
  4133. ------------------------------------------------------------
  4134. function GenCross( -- 4
  4135. ------------------------------------------------------------
  4136. AtLeast : integer ;
  4137. Weight : integer ;
  4138. Bin1, Bin2, Bin3, Bin4 : CovBinType
  4139. ) return CovMatrix4Type is
  4140. constant BIN_LENS : integer_vector := BinLengths(Bin1, Bin2, Bin3, Bin4) ;
  4141. constant NUM_NEW_BINS : integer := CalcNumCrossBins(BIN_LENS) ;
  4142. variable BinIndex : integer_vector(1 to BIN_LENS'length) := (others => 1) ;
  4143. variable CrossBins : CovBinType(BinIndex'range) ;
  4144. variable Action : integer ;
  4145. variable iCovMatrix : CovMatrix4Type(1 to NUM_NEW_BINS) ;
  4146. begin
  4147. for MatrixIndex in iCovMatrix'range loop
  4148. CrossBins := ConcatenateBins(BinIndex, Bin1, Bin2, Bin3, Bin4) ;
  4149. Action := MergeState(CrossBins) ;
  4150. iCovMatrix(MatrixIndex).action := Action ;
  4151. iCovMatrix(MatrixIndex).count := 0 ;
  4152. iCovMatrix(MatrixIndex).BinVal := MergeBinVal(CrossBins) ;
  4153. iCovMatrix(MatrixIndex).AtLeast := MergeAtLeast( Action, AtLeast, CrossBins) ;
  4154. iCovMatrix(MatrixIndex).Weight := MergeWeight ( Action, Weight, CrossBins) ;
  4155. IncBinIndex( BinIndex, BIN_LENS ) ; -- increment right most one, then if overflow, increment next
  4156. end loop ;
  4157. return iCovMatrix ;
  4158. end function GenCross ;
  4159. ------------------------------------------------------------
  4160. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4 : CovBinType ) return CovMatrix4Type is
  4161. ------------------------------------------------------------
  4162. begin
  4163. return GenCross(AtLeast, 0, Bin1, Bin2, Bin3, Bin4) ;
  4164. end function GenCross ;
  4165. ------------------------------------------------------------
  4166. function GenCross( Bin1, Bin2, Bin3, Bin4 : CovBinType ) return CovMatrix4Type is
  4167. ------------------------------------------------------------
  4168. begin
  4169. return GenCross(0, 0, Bin1, Bin2, Bin3, Bin4) ;
  4170. end function GenCross ;
  4171. ------------------------------------------------------------
  4172. function GenCross( -- 5
  4173. ------------------------------------------------------------
  4174. AtLeast : integer ;
  4175. Weight : integer ;
  4176. Bin1, Bin2, Bin3, Bin4, Bin5 : CovBinType
  4177. ) return CovMatrix5Type is
  4178. constant BIN_LENS : integer_vector := BinLengths(Bin1, Bin2, Bin3, Bin4, Bin5) ;
  4179. constant NUM_NEW_BINS : integer := CalcNumCrossBins(BIN_LENS) ;
  4180. variable BinIndex : integer_vector(1 to BIN_LENS'length) := (others => 1) ;
  4181. variable CrossBins : CovBinType(BinIndex'range) ;
  4182. variable Action : integer ;
  4183. variable iCovMatrix : CovMatrix5Type(1 to NUM_NEW_BINS) ;
  4184. begin
  4185. for MatrixIndex in iCovMatrix'range loop
  4186. CrossBins := ConcatenateBins(BinIndex, Bin1, Bin2, Bin3, Bin4, Bin5) ;
  4187. Action := MergeState(CrossBins) ;
  4188. iCovMatrix(MatrixIndex).action := Action ;
  4189. iCovMatrix(MatrixIndex).count := 0 ;
  4190. iCovMatrix(MatrixIndex).BinVal := MergeBinVal(CrossBins) ;
  4191. iCovMatrix(MatrixIndex).AtLeast := MergeAtLeast( Action, AtLeast, CrossBins) ;
  4192. iCovMatrix(MatrixIndex).Weight := MergeWeight ( Action, Weight, CrossBins) ;
  4193. IncBinIndex( BinIndex, BIN_LENS ) ; -- increment right most one, then if overflow, increment next
  4194. end loop ;
  4195. return iCovMatrix ;
  4196. end function GenCross ;
  4197. ------------------------------------------------------------
  4198. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4, Bin5 : CovBinType ) return CovMatrix5Type is
  4199. ------------------------------------------------------------
  4200. begin
  4201. return GenCross(AtLeast, 0, Bin1, Bin2, Bin3, Bin4, Bin5) ;
  4202. end function GenCross ;
  4203. ------------------------------------------------------------
  4204. function GenCross( Bin1, Bin2, Bin3, Bin4, Bin5 : CovBinType ) return CovMatrix5Type is
  4205. ------------------------------------------------------------
  4206. begin
  4207. return GenCross(0, 0, Bin1, Bin2, Bin3, Bin4, Bin5) ;
  4208. end function GenCross ;
  4209. ------------------------------------------------------------
  4210. function GenCross( -- 6
  4211. ------------------------------------------------------------
  4212. AtLeast : integer ;
  4213. Weight : integer ;
  4214. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6 : CovBinType
  4215. ) return CovMatrix6Type is
  4216. constant BIN_LENS : integer_vector := BinLengths(Bin1, Bin2, Bin3, Bin4, Bin5, Bin6) ;
  4217. constant NUM_NEW_BINS : integer := CalcNumCrossBins(BIN_LENS) ;
  4218. variable BinIndex : integer_vector(1 to BIN_LENS'length) := (others => 1) ;
  4219. variable CrossBins : CovBinType(BinIndex'range) ;
  4220. variable Action : integer ;
  4221. variable iCovMatrix : CovMatrix6Type(1 to NUM_NEW_BINS) ;
  4222. begin
  4223. for MatrixIndex in iCovMatrix'range loop
  4224. CrossBins := ConcatenateBins(BinIndex, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6) ;
  4225. Action := MergeState(CrossBins) ;
  4226. iCovMatrix(MatrixIndex).action := Action ;
  4227. iCovMatrix(MatrixIndex).count := 0 ;
  4228. iCovMatrix(MatrixIndex).BinVal := MergeBinVal(CrossBins) ;
  4229. iCovMatrix(MatrixIndex).AtLeast := MergeAtLeast( Action, AtLeast, CrossBins) ;
  4230. iCovMatrix(MatrixIndex).Weight := MergeWeight ( Action, Weight, CrossBins) ;
  4231. IncBinIndex( BinIndex, BIN_LENS ) ; -- increment right most one, then if overflow, increment next
  4232. end loop ;
  4233. return iCovMatrix ;
  4234. end function GenCross ;
  4235. ------------------------------------------------------------
  4236. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4, Bin5, Bin6 : CovBinType ) return CovMatrix6Type is
  4237. ------------------------------------------------------------
  4238. begin
  4239. return GenCross(AtLeast, 0, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6) ;
  4240. end function GenCross ;
  4241. ------------------------------------------------------------
  4242. function GenCross( Bin1, Bin2, Bin3, Bin4, Bin5, Bin6 : CovBinType ) return CovMatrix6Type is
  4243. ------------------------------------------------------------
  4244. begin
  4245. return GenCross(0, 0, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6) ;
  4246. end function GenCross ;
  4247. ------------------------------------------------------------
  4248. function GenCross( -- 7
  4249. ------------------------------------------------------------
  4250. AtLeast : integer ;
  4251. Weight : integer ;
  4252. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7 : CovBinType
  4253. ) return CovMatrix7Type is
  4254. constant BIN_LENS : integer_vector := BinLengths(Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7) ;
  4255. constant NUM_NEW_BINS : integer := CalcNumCrossBins(BIN_LENS) ;
  4256. variable BinIndex : integer_vector(1 to BIN_LENS'length) := (others => 1) ;
  4257. variable CrossBins : CovBinType(BinIndex'range) ;
  4258. variable Action : integer ;
  4259. variable iCovMatrix : CovMatrix7Type(1 to NUM_NEW_BINS) ;
  4260. begin
  4261. for MatrixIndex in iCovMatrix'range loop
  4262. CrossBins := ConcatenateBins(BinIndex, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7) ;
  4263. Action := MergeState(CrossBins) ;
  4264. iCovMatrix(MatrixIndex).action := Action ;
  4265. iCovMatrix(MatrixIndex).count := 0 ;
  4266. iCovMatrix(MatrixIndex).BinVal := MergeBinVal(CrossBins) ;
  4267. iCovMatrix(MatrixIndex).AtLeast := MergeAtLeast( Action, AtLeast, CrossBins) ;
  4268. iCovMatrix(MatrixIndex).Weight := MergeWeight ( Action, Weight, CrossBins) ;
  4269. IncBinIndex( BinIndex, BIN_LENS ) ; -- increment right most one, then if overflow, increment next
  4270. end loop ;
  4271. return iCovMatrix ;
  4272. end function GenCross ;
  4273. ------------------------------------------------------------
  4274. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7 : CovBinType ) return CovMatrix7Type is
  4275. ------------------------------------------------------------
  4276. begin
  4277. return GenCross(AtLeast, 0, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7) ;
  4278. end function GenCross ;
  4279. ------------------------------------------------------------
  4280. function GenCross( Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7 : CovBinType ) return CovMatrix7Type is
  4281. ------------------------------------------------------------
  4282. begin
  4283. return GenCross(0, 0, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7) ;
  4284. end function GenCross ;
  4285. ------------------------------------------------------------
  4286. function GenCross( -- 8
  4287. ------------------------------------------------------------
  4288. AtLeast : integer ;
  4289. Weight : integer ;
  4290. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8 : CovBinType
  4291. ) return CovMatrix8Type is
  4292. constant BIN_LENS : integer_vector := BinLengths(Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8) ;
  4293. constant NUM_NEW_BINS : integer := CalcNumCrossBins(BIN_LENS) ;
  4294. variable BinIndex : integer_vector(1 to BIN_LENS'length) := (others => 1) ;
  4295. variable CrossBins : CovBinType(BinIndex'range) ;
  4296. variable Action : integer ;
  4297. variable iCovMatrix : CovMatrix8Type(1 to NUM_NEW_BINS) ;
  4298. begin
  4299. for MatrixIndex in iCovMatrix'range loop
  4300. CrossBins := ConcatenateBins(BinIndex, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8) ;
  4301. Action := MergeState(CrossBins) ;
  4302. iCovMatrix(MatrixIndex).action := Action ;
  4303. iCovMatrix(MatrixIndex).count := 0 ;
  4304. iCovMatrix(MatrixIndex).BinVal := MergeBinVal(CrossBins) ;
  4305. iCovMatrix(MatrixIndex).AtLeast := MergeAtLeast( Action, AtLeast, CrossBins) ;
  4306. iCovMatrix(MatrixIndex).Weight := MergeWeight ( Action, Weight, CrossBins) ;
  4307. IncBinIndex( BinIndex, BIN_LENS ) ; -- increment right most one, then if overflow, increment next
  4308. end loop ;
  4309. return iCovMatrix ;
  4310. end function GenCross ;
  4311. ------------------------------------------------------------
  4312. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8 : CovBinType ) return CovMatrix8Type is
  4313. ------------------------------------------------------------
  4314. begin
  4315. return GenCross(AtLeast, 0, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8) ;
  4316. end function GenCross ;
  4317. ------------------------------------------------------------
  4318. function GenCross( Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8 : CovBinType ) return CovMatrix8Type is
  4319. ------------------------------------------------------------
  4320. begin
  4321. return GenCross(0, 0, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8) ;
  4322. end function GenCross ;
  4323. ------------------------------------------------------------
  4324. function GenCross( -- 9
  4325. ------------------------------------------------------------
  4326. AtLeast : integer ;
  4327. Weight : integer ;
  4328. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9 : CovBinType
  4329. ) return CovMatrix9Type is
  4330. constant BIN_LENS : integer_vector := BinLengths(Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9) ;
  4331. constant NUM_NEW_BINS : integer := CalcNumCrossBins(BIN_LENS) ;
  4332. variable BinIndex : integer_vector(1 to BIN_LENS'length) := (others => 1) ;
  4333. variable CrossBins : CovBinType(BinIndex'range) ;
  4334. variable Action : integer ;
  4335. variable iCovMatrix : CovMatrix9Type(1 to NUM_NEW_BINS) ;
  4336. begin
  4337. for MatrixIndex in iCovMatrix'range loop
  4338. CrossBins := ConcatenateBins(BinIndex, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9) ;
  4339. Action := MergeState(CrossBins) ;
  4340. iCovMatrix(MatrixIndex).action := Action ;
  4341. iCovMatrix(MatrixIndex).count := 0 ;
  4342. iCovMatrix(MatrixIndex).BinVal := MergeBinVal(CrossBins) ;
  4343. iCovMatrix(MatrixIndex).AtLeast := MergeAtLeast( Action, AtLeast, CrossBins) ;
  4344. iCovMatrix(MatrixIndex).Weight := MergeWeight ( Action, Weight, CrossBins) ;
  4345. IncBinIndex( BinIndex, BIN_LENS ) ; -- increment right most one, then if overflow, increment next
  4346. end loop ;
  4347. return iCovMatrix ;
  4348. end function GenCross ;
  4349. ------------------------------------------------------------
  4350. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9 : CovBinType ) return CovMatrix9Type is
  4351. ------------------------------------------------------------
  4352. begin
  4353. return GenCross(AtLeast, 0, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9) ;
  4354. end function GenCross ;
  4355. ------------------------------------------------------------
  4356. function GenCross( Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9 : CovBinType ) return CovMatrix9Type is
  4357. ------------------------------------------------------------
  4358. begin
  4359. return GenCross(0, 0, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9) ;
  4360. end function GenCross ;
  4361. ------------------------------------------------------------
  4362. function to_integer ( B : boolean ) return integer is
  4363. ------------------------------------------------------------
  4364. begin
  4365. if B then
  4366. return 1 ;
  4367. else
  4368. return 0 ;
  4369. end if ;
  4370. end function to_integer ;
  4371. ------------------------------------------------------------
  4372. function to_integer ( SL : std_logic ) return integer is
  4373. -------------------------------------------------------------
  4374. begin
  4375. case SL is
  4376. when '1' | 'H' => return 1 ;
  4377. when '0' | 'L' => return 0 ;
  4378. when others => return -1 ;
  4379. end case ;
  4380. end function to_integer ;
  4381. ------------------------------------------------------------
  4382. function to_integer_vector ( BV : boolean_vector ) return integer_vector is
  4383. ------------------------------------------------------------
  4384. variable result : integer_vector(BV'range) ;
  4385. begin
  4386. for i in BV'range loop
  4387. result(i) := to_integer(BV(i)) ;
  4388. end loop ;
  4389. return result ;
  4390. end function to_integer_vector ;
  4391. ------------------------------------------------------------
  4392. function to_integer_vector ( SLV : std_logic_vector ) return integer_vector is
  4393. -------------------------------------------------------------
  4394. variable result : integer_vector(SLV'range) ;
  4395. begin
  4396. for i in SLV'range loop
  4397. result(i) := to_integer(SLV(i)) ;
  4398. end loop ;
  4399. return result ;
  4400. end function to_integer_vector ;
  4401. ------------------------------------------------------------
  4402. ------------------------------------------------------------
  4403. -- Deprecated: These are not part of the coverage model
  4404. ------------------------------------------------------------
  4405. procedure increment( signal Count : inout integer ) is
  4406. ------------------------------------------------------------
  4407. begin
  4408. Count <= Count + 1 ;
  4409. end procedure increment ;
  4410. ------------------------------------------------------------
  4411. procedure increment( signal Count : inout integer ; enable : boolean ) is
  4412. ------------------------------------------------------------
  4413. begin
  4414. if enable then
  4415. Count <= Count + 1 ;
  4416. end if ;
  4417. end procedure increment ;
  4418. ------------------------------------------------------------
  4419. procedure increment( signal Count : inout integer ; enable : std_ulogic ) is
  4420. ------------------------------------------------------------
  4421. begin
  4422. if to_x01(enable) = '1' then
  4423. Count <= Count + 1 ;
  4424. end if ;
  4425. end procedure increment ;
  4426. end package body CoveragePkg ;