with Instrument;
use Instrument;

--------------
-- Clustered Case
--------------

-- This test evaluates the code efficiency of a clustered case
-- statement, i.e., one in which the case alternatives are selected
-- by two groups of consecutive individual choice values from an
-- extensive range of case expression values.

-- The purpose of this test is to offer the compiler a case statement
-- that may be implemented using multiple jump-tables.

-- The global variable is used in the case expression to select one
-- of the alternatives that are included in the case statement.
-- In the test version, each alternative is explicitly specified and
-- comprises a camouflaged assignment to the global variable.
-- The value of the case expression will always cause execution of the
-- first case alternative; however, this condition is carefully protected
-- from detection by the compiler so that no optimization of the case
-- statement is performed.  In the noise version, the case statement
-- is removed to leave an if-then-else construct comprising an
-- equivalent number of assignments so that the code efficiency can be
-- derived.

procedure Cscta1 is

    package New_Procs is new Procs (Integer);
    use New_Procs;

begin

    Start ("CSCTA1", "Case Statement Cluster Test (control)");
    for I in 1 .. 10000 loop

        Let (Global, Ident (1));
        --  case Global is
        --    when 1 =>
        if Global = Ident (1) then
            -- always true
            Let (Global, Ident (1));
        else
            Let (Global, Ident (0));
            --      end if;                                -- included in test version
            --    when 2 =>
            Let (Global, Ident (2));
            --    when 3 =>
            Let (Global, Ident (3));
            --    when 4 =>
            Let (Global, Ident (4));
            --    when 5 =>
            Let (Global, Ident (5));
            --    when 9001 =>
            Let (Global, Ident (9001));
            --    when 9002 =>
            Let (Global, Ident (9002));
            --    when 9003 =>
            Let (Global, Ident (9003));
            --    when 9004 =>
            Let (Global, Ident (9004));
            --    when 9005 =>
            Let (Global, Ident (9005));
            --    when others =>
            null;
        end if;                                -- included in control version
        --  end case;

    end loop;
    Stop;

end Cscta1;