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

Subversion Repositories soc_maker

[/] [soc_maker/] [trunk/] [lib/] [soc_maker/] [conf.rb] - Blame information for rev 7

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 feddischso
###############################################################
2
#
3
#  File:      conf.rb
4
#
5
#  Author:    Christian Hättich
6
#
7
#  Project:   System-On-Chip Maker
8
#
9
#  Target:    Linux / Windows / Mac
10
#
11
#  Language:  ruby
12
#
13
#
14
###############################################################
15
#
16
#
17
#   Copyright (C) 2014  Christian Hättich  - feddischson [ at ] opencores.org
18
#
19
#   This program is free software: you can redistribute it and/or modify
20
#   it under the terms of the GNU General Public License as published by
21
#   the Free Software Foundation, either version 3 of the License, or
22
#   (at your option) any later version.
23
#
24
#   This program is distributed in the hope that it will be useful,
25
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
26
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
#   GNU General Public License for more details.
28
#
29
#   You should have received a copy of the GNU General Public License
30
#   along with this program.  If not, see .
31
#
32
#
33
###############################################################
34
#
35
#   Description:
36
#
37
#     This class holds all the configuration and is
38
#     realized as singleton.
39
#     The instance can be accessed via Conf::instance
40
#     The configuration is splitted into two parts:
41
#       @data     -> user-configurable
42
#       @data_ro  -> read-only
43
#
44
#
45
#
46
######
47
#
48
# TODO
49
#     - functionallity to modify @data
50
#
51
###############################################################
52
 
53
 
54
module SOCMaker
55
class Conf
56
  include YAML_EXT
57
  include ERR
58
 
59
  private_class_method :new
60
  def Conf.instance
61
      @@inst = new if @@inst == nil
62
      return @@inst
63
  end
64
 
65
  def initialize( options = {} )
66
 
67
 
68
      init_with( options.merge( { 'data' => {
69
        # the name of this application/tool
70
        :app_name         => 'SOC-Maker',
71
 
72
        # the name of the tool's commandline interface
73
        :app_cli_name     => 'SOC-Maker CLI',
74
 
75
        # array of core search paths
76
        :cores_search_path => [ './' ],
77
 
78
        # VHDL include directive
79
        :vhdl_include     => "library ieee;\nuse ieee.std_logic_1164.ALL;",
80
 
81
        # build directory, where the whole synthese and build process
82
        # happens
83
        :build_dir        =>  'build',
84
 
85
        # the folder inside build_dir, where all the vhdl source is placed
86
        :hdl_dir          =>  'hdl',
87
 
88
        # synthesis directory inside build_dir
89
        :syn_dir          =>  'syn',
90
 
91
        # simulation directory inside build_dir
92
        :sim_dir          =>  'sim'
93
 
94
        } } ) )
95
  end
96
  def encoder_with( coder )
97
    coder[ 'data' ] = @data
98
  end
99
  def init_with( coder )
100
 
101
    serr_if( coder[ 'data' ] == nil,
102
      "No configuration data provided",
103
      field: 'data' )
104
    @data = coder[ 'data' ]
105
 
106
    %w[ app_name vhdl_include
107
        build_dir hdl_dir
108
        syn_dir sim_dir ].each do |d|
109
      serr_if( @data[ d.to_sym ] == nil,
110
        "Data field '#{d}' is not provided",
111
        field: 'data' )
112
 
113
      verr_if( !@data[ d.to_sym ].is_a?( String ),
114
        "Data field '#{d}' is not of type String",
115
        field: 'data' )
116
 
117
      verr_if( @data[ d.to_sym ].size == 0,
118
        "Data field '#{d}' is not of type String",
119
        field: 'data' )
120
    end
121
 
122
 
123
    @data_ro = {
124
 
125
      :yaml_classes     => [ SOCMaker::CoreDef, SOCMaker::SOCDef, SOCMaker::IfcSpc, SOCMaker::LibInc, SOCMaker::Conf ],
126
 
127
      # Regular expression, which is evaluatted to detect values like
128
      #    eval function_name
129
      # The function_name is used for further processing
130
      :eval_regex       =>  /eval +([a-zA-Z_1-9]+)/,
131
 
132
      # Regular expression to check, if it is VHDL or verilog
133
      :hdl_type_regex   => /(\bvhdl\b)|(\bverilog\b)/,
134
 
135
      #
136
      # Regular expression for vhdl file detection
137
      #
138
      :vhdl_file_regex    =>  /\A\S+\.vhd\Z/,
139
 
140
      #
141
      # Regular expression for verilog file detection
142
      #
143
      :verilog_file_regex =>  /\A\S+\.v\Z/,
144
 
145
 
146
      #
147
      # Regular expression to match names starting with non-number
148
      #
149
      :length_regex     =>  /\A[^0-9]+.*\Z/,
150
 
151
      #
152
      # Regular expression to match a component's name (core-name or SOC-name)
153
      #
154
      :name_regex       =>  /^[a-zA-Z]+[a-zA-Z0-9_\-]*$/,
155
 
156
 
157
      :YPP_LUT          => {
158
                /\bSOCM_CONF\b/     =>  '--- !ruby/object:SOCMaker::Conf',
159
                /\bSOCM_CORE\b/     =>  '--- !ruby/object:SOCMaker::CoreDef',
160
                /\bSOCM_SOC\b/      =>  '--- !ruby/object:SOCMaker::SOCDef',
161
                /\bSOCM_IFC_SPC\b/  =>  '--- !ruby/object:SOCMaker::IfcSpc',
162
                /\bSOCM_INCLUDE\b/  =>  '--- !ruby/object:SOCMaker::LibInc',
163
                /\bSOCM_INST\b/     =>  '!ruby/object:SOCMaker::CoreInst',
164
                /\bSOCM_IFC\b/      =>  '!ruby/object:SOCMaker::IfcDef',
165
                /\bSOCM_PORT\b/     =>  '!ruby/object:SOCMaker::IfcPort',
166
                /\bSOCM_HDL_FILE\b/ =>  '!ruby/object:SOCMaker::HDLFile',
167
                /\bSOCM_PARAM\b/    =>  '!ruby/object:SOCMaker::Parameter',
168
                /\bSOCM_SPARAM\b/   =>  '!ruby/object:SOCMaker::SParameter',
169
                /\bSOCM_SENTRY\b/   =>  '!ruby/object:SOCMaker::SParameterEntry'
170
              },
171
      #
172
      # $1 provides the white spaces
173
      # $2 the name
174
      #
175
      :YPP_INV_REGEX      => /(\s)*-{0,3}\s*!ruby\/object:SOCMaker::([a-zA-Z]+)/,
176
 
177
      :YPP_INV_LUT        => {
178
                'Conf'            => 'SOCM_CONF',
179
                'CoreDef'         => 'SOCM_CORE',
180
                'SOCDef'          => 'SOCM_SOC',
181
                'CoreInst'        => 'SOCM_INST',
182
                'IfcSpc'          => 'SOCM_IFC_SPC',
183
                'IfcDef'          => 'SOCM_IFC',
184
                'IfcPort'         => 'SOCM_PORT',
185
                'HDLFile'         => 'SOCM_HDL_FILE',
186
                'Parameter'       => 'SOCM_PARAM',
187
                'SParameter'      => 'SOCM_SPARAM',
188
                'SParameterEntry' => 'SOCM_SENTRY',
189
                'LibInc'          => 'SOCM_INCLUDE'
190
              },
191
 
192
      # used to split yaml files
193
      #
194
      :YPP_SPLIT_REGEX    => /^\s*---\s*!ruby\/(object|object):SOCMaker/,
195
 
196
 
197
      :COMMENT_REGEX      => /([^#]*)(#.*)?/,
198
 
199
      :EMPTY_CMD_REGEX    => /(\s*)(.*)/,
200
 
201
      :LIC =>
202
"""
203
Copyright (C) 2014  Christian Haettich  - feddischson [ at ] opencores.org
204
 
205
This program is free software: you can redistribute it and/or modify
206
it under the terms of the GNU General Public License as published by
207
the Free Software Foundation, either version 3 of the License, or
208
(at your option) any later version.
209
 
210
This program is distributed in the hope that it will be useful,
211
but WITHOUT ANY WARRANTY; without even the implied warranty of
212
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
213
GNU General Public License for more details.
214
 
215
You should have received a copy of the GNU General Public License
216
along with this program.  If not, see .
217
"""
218
 
219
 
220
    }
221
  end
222
 
223
  def [](y)
224
    @data.merge( @data_ro )[y]
225
  end
226
 
227
  def []=(y, value)
228
    @data[y] = value
229
  end
230
  @@inst = nil
231
 
232
 
233
end
234
 
235
end
236
 
237
 
238
# 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.