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

Subversion Repositories soc_maker

[/] [soc_maker/] [trunk/] [lib/] [soc_maker/] [sparameter.rb] - Blame information for rev 3

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

Line No. Rev Author Line
1 3 feddischso
###############################################################
2
#
3
#  File:      sparameter.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
#     A small classes, used to group information
38
#     and to verify, auto-correct and auto-complete
39
#     this information:
40
#     This class represents a static parameter, which is
41
#     only defined once within a system. Usually, these
42
#     static parameters are mapped into a vhdl package or
43
#     verilog include file.
44
#     The following fields are defined:
45
#        - path (of the file, which is used as input)
46
#        - file_dst (output file destination)
47
#        - parameters (hash of SParameterEntry values)
48
#     At the moment, the token within the value of the parameter-hash
49
#     is used as regular expression to replace this token
50
#     in the input file by the key of the parameter-hash, and
51
#     write the result to the destination file.
52
#
53
###############################################################
54
 
55
 
56
module SOCMaker
57
class SParameter
58
  include ERR
59
  attr_accessor :path
60
  attr_accessor :file_dst
61
  attr_accessor :parameters
62
 
63
  def initialize( path, file_dst, options = {} )
64
    init_with( { 'path' => path,
65
                 'file_dst' => file_dst }.merge( options ) )
66
  end
67
  def encode_with( coder )
68
    %w[ path file_dst parameters ].
69
          each { |v| coder[ v ] = instance_variable_get "@#{v}" }
70
  end
71
  def init_with( coder )
72
 
73
    # path
74
    serr_if( coder[ 'path' ] == nil,
75
      'no file path specified for static parameter',
76
      field: 'path'  )
77
    @path = coder[ 'path' ]
78
    verr_if( !@path.is_a?( String ),
79
      'file path specified for static parameter is not of type string',
80
      field: 'path'  )
81
    verr_if( @path.size == 0,
82
      'file path specified for static parameter has zero length',
83
      field: 'path'  )
84
 
85
 
86
    # file_dst (file-destination)
87
    serr_if( coder[ 'file_dst' ] == nil,
88
      'no destination file directory given for static parameter',
89
      instance: @path,
90
      field:    'file_dst' )
91
    @file_dst = coder[ 'file_dst' ]
92
    verr_if( !@file_dst.is_a?( String ),
93
      'destination file directory given for static parameter is not of type string',
94
      instance: @path,
95
      field:    'file_dst' )
96
    verr_if( @file_dst.size == 0,
97
      'file path specified for static parameter has zero length',
98
      field: 'path'  )
99
 
100
 
101
    @parameters = coder[ 'parameters' ] || {}
102
    @parameters.each do |name, param|
103
      serr_if( param == nil,
104
            'Static parameter entry not defined',
105
            instance:   name.to_s )
106
 
107
      serr_if( !param.is_a?( SOCMaker::SParameterEntry ),
108
            'Static parameter entry not SOCMaker::SParameterEntry (use SOCM_SENTRY)',
109
            instance: name.to_s )
110
    end
111
 
112
  end
113
 
114
  def verify
115
    @parameters.each do |name, param|
116
      param.verify
117
    end
118
  end
119
 
120
 
121
  def ==(o)
122
    o.class == self.class               &&
123
      o.parameters == self.parameters   &&
124
      o.file_dst   == self.file_dst     &&
125
      o.path       == self.path
126
  end
127
 
128
 
129
 
130
end
131
class SParameterEntry < Parameter
132
  attr_accessor :token
133
 
134
  def initialize( type, token, options = {} )
135
    init_with( { 'type' => type,
136
                 'token' => token }.merge( options ) )
137
 
138
  end
139
  def encode_with( coder )
140
    super coder
141
    coder[ 'token' ] = @token
142
  end
143
  def init_with( coder )
144
    super coder
145
 
146
    serr_if( coder[ 'token' ] == nil,
147
      'no token specified',
148
      field: token)
149
    @token = coder[ 'token' ]
150
    verr_if( !@token.is_a?( String ), 'token is not a string' )
151
    verr_if( @token.size == 0, 'token has zero size' )
152
  end
153
  def verify
154
    super
155
  end
156
 
157
  def ==(o)
158
    o.class == self.class   &&
159
    o.token  == self.token  &&
160
    super( o )
161
  end
162
 
163
 
164
end
165
end
166
 
167
 
168
# 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.