class SOCMaker::Conf

This class holds all the configuration and is realized as singleton. The instance can be accessed via Conf.instance The configuration is splitted into two parts:

Examples:

c = Conf.instance
c[ :app_nam ]   # SOC-Maker
c[ :build_dir ] # build

Public Class Methods

instance() click to toggle source

Method to access the singleton instance: Within the first call, this method tries to load the config from the file. If the file doesn exist, a new instance is created.

return

the config instance

# File lib/soc_maker/conf.rb, line 76
def Conf.instance
  if @@inst == nil
    if File.file?( @@conf_file_path )
      @@inst = YAML::load_file( @@conf_file_path )
    else
      @@inst = new 
    end
  end
  return @@inst
end
new( ) click to toggle source

Private constructor: it initializes all data

# File lib/soc_maker/conf.rb, line 97
def initialize( )


    init_with( { 'data' => {

      # array of core search paths
      :cores_search_path => [ './' ],

      # VHDL include directive
      :vhdl_include     => "library ieee;\nuse ieee.std_logic_1164.ALL;",

      # build directory, where the whole synthese and build process
      # happens
      :build_dir        =>  'build',

      # the folder inside build_dir, where all the vhdl source is placed
      :hdl_dir          =>  'hdl',

      # synthesis directory inside build_dir
      :syn_dir          =>  'syn',

      # simulation directory inside build_dir
      :sim_dir          =>  'sim'

      } } )
end
write() click to toggle source

Method to write the config to the file system

# File lib/soc_maker/conf.rb, line 90
def Conf.write
  File.open( 'socm_conf.yaml', 'w' ) { |f| f.write( @@inst.to_yaml  ) }
end

Public Instance Methods

[](y) click to toggle source

Read access via array operator: config from @data and @data_ro can be accessed.

# File lib/soc_maker/conf.rb, line 287
def [](y)
  @data.merge( @data_ro )[y]
end
[]=(y, value) click to toggle source

Write access via array operator: config from @data can be accessed, @data_ro not.

# File lib/soc_maker/conf.rb, line 295
def []=(y, value)
  @data[y] = value if @data.has_key?( y )
end
encode_with( coder ) click to toggle source

Encoder function (to yaml)

coder

An instance of the Psych::Coder to encode this class to a YAML file

# File lib/soc_maker/conf.rb, line 129
def encode_with( coder )
  puts "ENCODE_WITH CALLED"
  init_error_if !coder.is_a?( Psych::Coder ), 
              'coder is not given as Psych::Coder'
  coder[ 'data' ] = @data
end
init_with( coder ) click to toggle source

Initialization function (from yaml)

coder

An instance of the Psych::Coder to init this class from a YAML file

# File lib/soc_maker/conf.rb, line 142
  def init_with( coder )

    init_error_if !( coder.is_a?( Hash ) || coder.is_a?( Psych::Coder ) ), 
                'coder is not given as Hash neither as Psych::Coder'

    init_error "No configuration data provided",
      field: 'data' if coder[ 'data' ] == nil

    @data = coder[ 'data' ]

    %w[ vhdl_include 
        build_dir hdl_dir
        syn_dir sim_dir ].each do |d|
      raise InitError.new( 
        "Data field '#{d}' is not provided",
        field: 'data' ) if @data[ d.to_sym ] == nil

      raise InitError.new( 
        "Data field '#{d}' is not of type String",
        field: 'data' ) if !@data[ d.to_sym ].is_a?( String )

      raise InitError.new( 
        "Data field '#{d}' is not of type String",
        field: 'data' ) if @data[ d.to_sym ].size == 0
    end


    @data_ro = { 

      # the name of this application/tool
      :app_name         => 'SOC-Maker',

      # the name of the tool's commandline interface
      :app_cli_name     => 'SOC-Maker CLI',


      # All classes, which can be loaded by this software
      :yaml_classes     => [  SOCMaker::CoreDef, 
                              SOCMaker::SOCDef, 
                              SOCMaker::IfcSpc, 
                              SOCMaker::LibInc, 
                              SOCMaker::Conf, 
                              SOCMaker::CoreInst ],

      # Regular expression, which is evaluatted to detect values like
      #    eval function_name
      # The function_name is used for further processing
      :eval_regex       =>  /eval +([a-zA-Z_1-9]+)/,

      # Regular expression to check, if it is VHDL or verilog
      :hdl_type_regex   => /(\bvhdl\b)|(\bverilog\b)/,

      #
      # Regular expression for vhdl file detection
      #
      :vhdl_file_regex    =>  /\A\S+\.vhd\Z/,

      #
      # Regular expression for verilog file detection
      #
      :verilog_file_regex =>  /\A\S+\.v\Z/,


      #
      # Regular expression to match names starting with non-number
      #
      :length_regex     =>  /\A[^0-9]+.*\Z/,

      #
      # Regular expression to match a component's name (core-name or SOC-name)
      # (Obsolete)
      #
      :name_regex       =>  /^[a-zA-Z]+[a-zA-Z0-9_\-]*$/,


      :YPP_LUT          => {
                /\bSOCM_CONF\b/     =>  '--- !ruby/object:SOCMaker::Conf',
                /\bSOCM_CORE\b/     =>  '--- !ruby/object:SOCMaker::CoreDef',
                /\bSOCM_SOC\b/      =>  '--- !ruby/object:SOCMaker::SOCDef',
                /\bSOCM_IFC_SPC\b/  =>  '--- !ruby/object:SOCMaker::IfcSpc',
                /\bSOCM_INCLUDE\b/  =>  '--- !ruby/object:SOCMaker::LibInc',
                /\bSOCM_INST\b/     =>  '!ruby/object:SOCMaker::CoreInst',
                /\bSOCM_IFC\b/      =>  '!ruby/object:SOCMaker::IfcDef',
                /\bSOCM_PORT\b/     =>  '!ruby/object:SOCMaker::IfcPort',
                /\bSOCM_HDL_FILE\b/ =>  '!ruby/object:SOCMaker::HDLFile',
                /\bSOCM_PARAM\b/    =>  '!ruby/object:SOCMaker::Parameter',
                /\bSOCM_SPARAM\b/   =>  '!ruby/object:SOCMaker::SParameter',
                /\bSOCM_SENTRY\b/   =>  '!ruby/object:SOCMaker::SParameterEntry'
              },
      #
      # $1 provides the white spaces
      # $2 the name
      #
      :YPP_INV_REGEX      => /(\s)*-{0,3}\s*!ruby\/object:SOCMaker::([a-zA-Z]+)/,  

      :YPP_INV_LUT        => {
                'Conf'            => 'SOCM_CONF',
                'CoreDef'         => 'SOCM_CORE',
                'SOCDef'          => 'SOCM_SOC',
                'CoreInst'        => 'SOCM_INST',
                'IfcSpc'          => 'SOCM_IFC_SPC',
                'IfcDef'          => 'SOCM_IFC',
                'IfcPort'         => 'SOCM_PORT',
                'HDLFile'         => 'SOCM_HDL_FILE',
                'Parameter'       => 'SOCM_PARAM',
                'SParameter'      => 'SOCM_SPARAM',
                'SParameterEntry' => 'SOCM_SENTRY',
                'LibInc'          => 'SOCM_INCLUDE'
              },

      # used to split yaml files
      #
      :YPP_SPLIT_REGEX    => /^\s*---\s*!ruby\/(object|object):SOCMaker/,


      :COMMENT_REGEX      => /([^#]*)(#.*)?/,

      :EMPTY_CMD_REGEX    => /(\s*)(.*)/,

      :LIC =>        
"""
Copyright (C) 2014  Christian Haettich  - feddischson [ at ] opencores.org

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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
"""


    }
  end