OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [gcc/] [testsuite/] [ada/] [acats/] [support/] [enumchek.ada] - Blame information for rev 826

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 294 jeremybenn
-- THIS GENERIC PROCEDURE IS INTENDED FOR USE IN CONJUNCTION WITH THE ACVC
2
-- CHAPTER 13 C TESTS. IT IS INSTANTIATED WITH TWO TYPES. THE FIRST IS AN
3
-- ENUMERATION TYPE FOR WHICH AN ENUMERATION CLAUSE HAS BEEN GIVEN, AND THE
4
-- SECOND IS AN INTEGER TYPE WHOSE 'SIZE IS THE SAME AS THE 'SIZE OF THIS
5
-- ENUMERATION TYPE.
6
 
7
-- THE PROCEDURE ENUM_CHECK IS THEN CALLED WITH THREE ARGUMENTS. THE FIRST IS
8
-- AN ENUMERATION LITERAL FROM THE ENUMERATION TYPE, THE SECOND IS AN INTEGER
9
-- LITERAL WHICH IS THE VALUE OF THE EXPECTED REPRESENTATION (TAKEN FROM THE
10
-- ENUMERATION REPRESENTATION CLAUSE), AND THE THIRD IS A STRING DESCRIBING OR
11
-- NAMING THE TYPE (USED IN A CALL TO FAILED IF THE REPRESENTATION CHECK FAILS).
12
 
13
-- THE CHECK IS TO CONVERT THE ENUMERATION VALUE TO A BOOLEAN ARRAY WITH A
14
-- LENGTH CORRESONDING TO THE 'SIZE OF THE ENUMERATION TYPE. AN INTEGER TYPE
15
-- IS THEN CREATED WITH THIS SAME 'SIZE, AND THE REQUIRED REPRESENTATION VALUE
16
-- IS CONVERTED FROM THIS TYPE TO A BOOLEAN ARRAY WITH THE SAME LENGTH. THE
17
-- TWO BOOLEAN ARRAYS ARE THEN COMPARED AND SHOULD BE EQUAL. THE CONVERSIONS
18
-- ARE PERFORMED USING APPROPRIATE INSTANTIATIONS OF UNCHECKED_CONVERSION.
19
 
20
-- AUTHOR: ROBERT B. K. DEWAR, UNCOPYRIGHTED, PUBLIC DOMAIN USE AUTHORIZED
21
 
22
GENERIC
23
 
24
   TYPE ENUM_TYPE IS PRIVATE;
25
   TYPE INT_TYPE IS RANGE <>;
26
 
27
PROCEDURE ENUM_CHECK (TEST_VALUE : ENUM_TYPE;
28
                      REP_VALUE  : INT_TYPE;
29
                      TYPE_ID    : STRING);
30
 
31
 
32
WITH UNCHECKED_CONVERSION;
33
WITH REPORT; USE REPORT;
34
 
35
PROCEDURE ENUM_CHECK (TEST_VALUE : ENUM_TYPE;
36
                      REP_VALUE  : INT_TYPE;
37
                      TYPE_ID    : STRING) IS
38
 
39
   TYPE BIT_ARRAY_TYPE IS ARRAY (1 .. ENUM_TYPE'SIZE) OF BOOLEAN;
40
   PRAGMA PACK (BIT_ARRAY_TYPE);
41
 
42
   FUNCTION TO_BITS IS NEW UNCHECKED_CONVERSION (ENUM_TYPE, BIT_ARRAY_TYPE);
43
   FUNCTION TO_BITS IS NEW UNCHECKED_CONVERSION (INT_TYPE, BIT_ARRAY_TYPE);
44
 
45
   BIT_ARRAY_1 : BIT_ARRAY_TYPE;
46
   BIT_ARRAY_2 : BIT_ARRAY_TYPE;
47
 
48
   INT_VALUE : INT_TYPE := INT_TYPE (REP_VALUE);
49
 
50
BEGIN
51
 
52
   -- VERIFY CORRECT CALL (THIS IS A SANITY CHECK ON THE TEST ITSELF)
53
 
54
   IF ENUM_TYPE'SIZE /= INT_TYPE'SIZE THEN
55
      FAILED ("ERROR IN ENUM_CHECK CALL: SIZES DO NOT MATCH");
56
   END IF;
57
 
58
   BIT_ARRAY_1 := TO_BITS (TEST_VALUE);
59
   BIT_ARRAY_2 := TO_BITS (INT_VALUE);
60
 
61
   IF BIT_ARRAY_1 /= BIT_ARRAY_2 THEN
62
      FAILED ("CHECK ON REPRESENTATION OF TYPE " & TYPE_ID & " FAILED.");
63
   END IF;
64
 
65
END ENUM_CHECK;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.