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 9

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 9 feddischso
  def initialize( path, file_dst, optional = {} )
64 3 feddischso
    init_with( { 'path' => path,
65 9 feddischso
                 'file_dst' => file_dst }.merge( optional ) )
66 3 feddischso
  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
 
115
 
116
  def ==(o)
117
    o.class == self.class               &&
118
      o.parameters == self.parameters   &&
119
      o.file_dst   == self.file_dst     &&
120
      o.path       == self.path
121
  end
122
 
123
 
124
 
125
end
126
class SParameterEntry < Parameter
127
  attr_accessor :token
128
 
129 9 feddischso
  def initialize( type, token, optional = {} )
130 3 feddischso
    init_with( { 'type' => type,
131 9 feddischso
                 'token' => token }.merge( optional ) )
132 3 feddischso
 
133
  end
134
  def encode_with( coder )
135
    super coder
136
    coder[ 'token' ] = @token
137
  end
138
  def init_with( coder )
139
    super coder
140
 
141
    serr_if( coder[ 'token' ] == nil,
142
      'no token specified',
143
      field: token)
144
    @token = coder[ 'token' ]
145
    verr_if( !@token.is_a?( String ), 'token is not a string' )
146
    verr_if( @token.size == 0, 'token has zero size' )
147
  end
148
 
149
  def ==(o)
150
    o.class == self.class   &&
151
    o.token  == self.token  &&
152
    super( o )
153
  end
154
 
155
 
156
end
157
end
158
 
159
 
160
# 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.