Class: SOCMaker::Conf

Inherits:
Object
  • Object
show all
Includes:
ERR, YAML_EXT
Defined in:
lib/soc_maker/conf.rb

Overview

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:

  • @data -> user-configurable

  • @data_ro -> read-only

Examples:

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

Constant Summary collapse

@@conf_file_path =

Config file path. This is fixed and can’t be modified.

'socm_conf.yaml'
@@inst =

The singleton instance. It is initialized by the first Conf::instance mehtod call.

nil

Instance Attribute Summary

Attributes included from YAML_EXT

#src_dir

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ERR

#consistence_error, #consistence_error_if, #init_error, #init_error_if, #processing_error, #processing_error_if

Methods included from YAML_EXT

#save_yaml

Constructor Details

#initializeConf

Private constructor: it initializes all data



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# 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

Class Method Details

.instanceObject

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



76
77
78
79
80
81
82
83
84
85
# 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

.writeObject

Method to write the config to the file system



90
91
92
# File 'lib/soc_maker/conf.rb', line 90

def Conf.write
  File.open( 'socm_conf.yaml', 'w' ) { |f| f.write( @@inst.to_yaml  ) }
end

Instance Method Details

#[](y) ⇒ Object

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



287
288
289
# File 'lib/soc_maker/conf.rb', line 287

def [](y)
  @data.merge( @data_ro )[y]
end

#[]=(y, value) ⇒ Object

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



295
296
297
# File 'lib/soc_maker/conf.rb', line 295

def []=(y, value)
  @data[y] = value if @data.has_key?( y )
end

#encode_with(coder) ⇒ Object

Encoder function (to yaml)

coder

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



129
130
131
132
133
134
# 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) ⇒ Object

Initialization function (from yaml)

coder

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



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# 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