---------------------------------------------------------------------------- -- get_entities (get_entities.adb) -- -- Copyright (C) 2013, Brian Drummond -- -- This file is part of the ghdl-updates project. -- -- get_entities is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 2 of the License, or -- (at your option) any later version. -- -- get_entities is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with get_entities. If not, see . ---------------------------------------------------------------------------- with Ada.Text_Io; use Ada.Text_IO; with Ada.Characters.Handling; with Ada.Strings.Fixed; with Ada.Strings.Maps; with Ada.Strings.Unbounded; with Ada.Directories; with Ada.Command_Line; procedure get_entities is function Valid_Test(Name : in String) return boolean is use Ada.Directories; use Ada.Characters.Handling; begin return Extension(To_Lower(Name)) = "vhd" or Extension(To_Lower(Name)) = "vhdl"; end Valid_Test; procedure Get_Top_Entities(Test_Name : in String) is use Ada.Text_Io; use Ada.Strings.Fixed; use Ada.Characters.Handling; use Ada.Strings.Unbounded; File : File_Type; function Get_End(Line : in String) return Natural is Comment : natural := Index(Line,"--"); begin if Comment = 0 then return Line'last; else return Comment - 1; end if; end Get_End; type State_Type is (Idle, Have_Entity, Have_Name, In_Entity); State : State_Type; Top_Level_Entity : Boolean; Name : Unbounded_String; Last_Entity : Unbounded_String; begin -- Return the name of all top-level entities in the file. -- Report on stderr, a malformed one -- "malformed" means not conforming to the expectations of this simple parser. -- A top level entity has the form -- Entity is -- -- end {entity} Open(File, In_File, Test_Name); State := Idle; loop declare -- strip name of blanks etc... CharSet : constant Ada.Strings.Maps.Character_Ranges := (('A','Z'), ('a','z'), ('0','9'), ('_','_')); function Token(Source, Name : String; From : positive := 1) return natural is use Ada.Strings.Maps; Pos : natural := Index(Source, Name, From => From); begin -- Look in Source for Name, either surrounded by whitespace or at the start or end of a line if Pos = 0 or Pos = 1 or Pos + Name'Length > Source'Length then return Pos; elsif not is_in (Source(Pos - 1), To_Set(CharSet)) and not is_in (Source(Pos + Name'Length), To_Set(CharSet)) then return Pos; else return 0; end if; end Token; function Strip_Quoted(Raw : String) return String is temp : String(Raw'range); t : natural := Raw'first; copy : Boolean := true; begin -- Eliminate quoted text for i in Raw'range loop if copy then if Raw(i) = '"' then copy := not copy; else temp(t) := Raw(i); t := t + 1; end if; else if Raw(i) = '"' then copy := not copy; end if; end if; end loop; if t > Raw'last then t := Raw'last; end if; return temp(Raw'first .. t); end Strip_Quoted; Line : String := Get_Line (File); -- line based to strip off comments EndLine : natural := G
//==========================================
// Function : Code Gray counter.
// Coder    : Alex Claros F.
// Date     : 15/May/2005.
//=======================================

module GrayCounter
   #(parameter   COUNTER_WIDTH = 4)
   
    (output reg  [COUNTER_WIDTH-1:0]    GrayCount_out,  //'Gray' code count output.
    
     input wire                         Enable_in,  //Count enable.
     input wire                         Clear_in,   //Count reset.
    
     input wire                         Clk);

    /////////Internal connections & variables///////
    reg    [COUNTER_WIDTH-1:0]         BinaryCount;

    /////////Code///////////////////////
    
    always @ (posedge Clk)
        if (Clear_in) begin
            BinaryCount   <= {COUNTER_WIDTH{1'b 0}} + 1;  //Gray count begins @ '1' with
            GrayCount_out <= {COUNTER_WIDTH{1'b 0}};      // first 'Enable_in'.
        end
        else if (Enable_in) begin
            BinaryCount   <= BinaryCount + 1;
            GrayCount_out <= {BinaryCount[COUNTER_WIDTH-1],
                              BinaryCount[COUNTER_WIDTH-2:0] ^ BinaryCount[COUNTER_WIDTH-1:1]};
        end
    
endmodule