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

Subversion Repositories soc_maker

[/] [soc_maker/] [trunk/] [lib/] [soc_maker/] [hdl_file.rb] - Diff between revs 7 and 9

Only display areas with differences | Details | Blame | View Log

Rev 7 Rev 9
###############################################################
###############################################################
#
#
#  File:      hdl_file.rb
#  File:      hdl_file.rb
#
#
#  Author:    Christian Hättich
#  Author:    Christian Hättich
#
#
#  Project:   System-On-Chip Maker
#  Project:   System-On-Chip Maker
#
#
#  Target:    Linux / Windows / Mac
#  Target:    Linux / Windows / Mac
#
#
#  Language:  ruby
#  Language:  ruby
#
#
#
#
###############################################################
###############################################################
#
#
#
#
#   Copyright (C) 2014  Christian Hättich  - feddischson [ at ] opencores.org
#   Copyright (C) 2014  Christian Hättich  - feddischson [ at ] opencores.org
#
#
#   This program is free software: you can redistribute it and/or modify
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#   (at your option) any later version.
#
#
#   This program is distributed in the hope that it will be useful,
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#   GNU General Public License for more details.
#
#
#   You should have received a copy of the GNU General Public License
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see .
#   along with this program.  If not, see .
#
#
#
#
###############################################################
###############################################################
#
#
#   Description:
#   Description:
#
#
#
#
#     A small classes, used to group information
#     A small classes, used to group information
#     and to verify, auto-correct and auto-complete
#     and to verify, auto-correct and auto-complete
#     this information:
#     this information:
#     The class represents an high-level-description (HDL) file.
#     The class represents an high-level-description (HDL) file.
#     The two supported file-types are *.vhdl and *.v, whose information
#     The two supported file-types are *.vhdl and *.v, whose information
#     is stored in @type ('verilog' or 'vhdl').
#     is stored in @type ('verilog' or 'vhdl').
#     A @path is mandatory and defines, where the file is located.
#     A @path is mandatory and defines, where the file is located.
#     In addition, is is used for auto-detecting the file-type (if not given).
#     In addition, is is used for auto-detecting the file-type (if not given).
#     There are three flags:
#     There are three flags:
#           - use_syn      (use in synthesis)
#           - use_syn      (use in synthesis)
#           - use_sys_sim  (use in system simulation)
#           - use_sys_sim  (use in system simulation)
#           - use_mod_sim  (use in module simulation)
#           - use_mod_sim  (use in module simulation)
#     These flags are not used at the moment and reserved for
#     These flags are not used at the moment and reserved for
#     future implementation.
#     future implementation.
#
#
#
#
###############################################################
###############################################################
module SOCMaker
module SOCMaker
class HDLFile
class HDLFile
  include ERR
  include ERR
  attr_accessor :path
  attr_accessor :path
  attr_accessor :use_syn
  attr_accessor :use_syn
  attr_accessor :use_sys_sim
  attr_accessor :use_sys_sim
  attr_accessor :use_mod_sim
  attr_accessor :use_mod_sim
  attr_accessor :type
  attr_accessor :type
 
 
  def initialize( path, options = {} )
  def initialize( path, optional = {} )
    init_with( { 'path' => path }.merge( options ) )
    init_with( { 'path' => path }.merge( optional ) )
  end
  end
  def encode_with( coder )
  def encode_with( coder )
    %w[ path use_syn use_sys_sim use_mod_sim type ].
    %w[ path use_syn use_sys_sim use_mod_sim type ].
      each { |v| coder[ v ] = instance_variable_get "@#{v}" }
      each { |v| coder[ v ] = instance_variable_get "@#{v}" }
  end
  end
  def init_with( coder )
  def init_with( coder )
    serr_if( !( coder.is_a?( Hash         ) ||
    serr_if( !( coder.is_a?( Hash         ) ||
                coder.is_a?( Psych::Coder ) ),
                coder.is_a?( Psych::Coder ) ),
      'coder is not given as Hash neither as Psych::Coder' )
      'coder is not given as Hash neither as Psych::Coder' )
    # check path
    # check path
    serr_if( coder[ 'path' ] == nil, 'no filepath specified' )
    serr_if( coder[ 'path' ] == nil, 'no filepath specified' )
    @path = coder[ 'path' ]
    @path = coder[ 'path' ]
    verr_if( !@path.is_a?( String ), 'path must be of type string' )
    verr_if( !@path.is_a?( String ), 'path must be of type string' )
    # auto-complete to 'true'
    # auto-complete to 'true'
    @use_syn      = coder[ 'use_syn'     ] || true
    @use_syn      = coder[ 'use_syn'     ] || true
    @use_sys_sim  = coder[ 'use_sys_sim' ] || true
    @use_sys_sim  = coder[ 'use_sys_sim' ] || true
    @use_mod_sim  = coder[ 'use_mod_sim' ] || true
    @use_mod_sim  = coder[ 'use_mod_sim' ] || true
    # ensure, that the thee use... fields are boolean
    # ensure, that the thee use... fields are boolean
    verr_if( !!@use_syn     != @use_syn,     'use_syn field must be true of false'      )
    verr_if( !!@use_syn     != @use_syn,     'use_syn field must be true of false'      )
    verr_if( !!@use_sys_sim != @use_sys_sim, 'use_sys_sim field must be true of false'  )
    verr_if( !!@use_sys_sim != @use_sys_sim, 'use_sys_sim field must be true of false'  )
    verr_if( !!@use_mod_sim != @use_mod_sim, 'use_mod_sim field must be true of false'  )
    verr_if( !!@use_mod_sim != @use_mod_sim, 'use_mod_sim field must be true of false'  )
    # if the file-type is not given, we try to auto-detect it
    # if the file-type is not given, we try to auto-detect it
    #   *.vhd  ->  vhdl
    #   *.vhd  ->  vhdl
    #   *.v    ->  verilog
    #   *.v    ->  verilog
    #   (see conf[ :vhdl_file_regex ] and
    #   (see conf[ :vhdl_file_regex ] and
    #        conf[ :verilog_file_regex ] )
    #        conf[ :verilog_file_regex ] )
    if  coder[ 'type' ] == nil
    if  coder[ 'type' ] == nil
      if @path =~ SOCMaker::conf[ :vhdl_file_regex ]
      if @path =~ SOCMaker::conf[ :vhdl_file_regex ]
        SOCMaker::logger.warn "Auto-detected vhdl file type for #{ @path }"
        SOCMaker::logger.warn "Auto-detected vhdl file type for #{ @path }"
        @type = 'vhdl'
        @type = 'vhdl'
      elsif @path =~ SOCMaker::conf[ :verilog_file_regex ]
      elsif @path =~ SOCMaker::conf[ :verilog_file_regex ]
        SOCMaker::logger.warn "Auto-detected verilog file type for #{ @path }"
        SOCMaker::logger.warn "Auto-detected verilog file type for #{ @path }"
        @type = 'verilog'
        @type = 'verilog'
      else
      else
        verr_if( true, 'Cant auto-detect file type for "' + path + '"' )
        verr_if( true, 'Cant auto-detect file type for "' + path + '"' )
      end
      end
    else
    else
      # if the file-type is given, ensure, that it is either 'vhdl' or 'verilog'
      # if the file-type is given, ensure, that it is either 'vhdl' or 'verilog'
      verr_if( !SOCMaker::conf[ :hdl_type_regex ].match( coder[ 'type' ] ),
      verr_if( !SOCMaker::conf[ :hdl_type_regex ].match( coder[ 'type' ] ),
        "The type must be 'vhdl' or 'verilog'",
        "The type must be 'vhdl' or 'verilog'",
        instance: @path,
        instance: @path,
        field:    'type' )
        field:    'type' )
      @type = coder[ 'type' ]
      @type = coder[ 'type' ]
    end
    end
  end
  end
  def ==(o)
  def ==(o)
    o.class           == self.class         &&
    o.class           == self.class         &&
    o.path            == self.path          &&
    o.path            == self.path          &&
    o.use_syn         == self.use_syn       &&
    o.use_syn         == self.use_syn       &&
    o.use_sys_sim     == self.use_sys_sim   &&
    o.use_sys_sim     == self.use_sys_sim   &&
    o.use_mod_sim     == self.use_mod_sim   &&
    o.use_mod_sim     == self.use_mod_sim   &&
    o.type            == self.type
    o.type            == self.type
  end
  end
end
end
end
end
# vim: noai:ts=2:sw=2
# vim: noai:ts=2:sw=2
 
 

powered by: WebSVN 2.1.0

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