Module: SOCMaker
- Defined in:
- lib/soc_maker/err.rb,
lib/soc_maker.rb,
lib/soc_maker/cli.rb,
lib/soc_maker/lib.rb,
lib/soc_maker/ypp.rb,
lib/soc_maker/conf.rb,
lib/soc_maker/ifc_def.rb,
lib/soc_maker/ifc_spc.rb,
lib/soc_maker/lib_inc.rb,
lib/soc_maker/soc_def.rb,
lib/soc_maker/version.rb,
lib/soc_maker/core_def.rb,
lib/soc_maker/hdl_file.rb,
lib/soc_maker/ifc_port.rb,
lib/soc_maker/core_inst.rb,
lib/soc_maker/hdl_coder.rb,
lib/soc_maker/parameter.rb,
lib/soc_maker/hdl_parser.rb,
lib/soc_maker/sparameter.rb
Overview
File: hdl_coder.rb
Author: Christian Hättich
Project: System-On-Chip Maker
Target: Linux / Windows / Mac
Language: ruby
Copyright (C) 2014 Christian Hättich - 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/>.
Defined Under Namespace
Modules: ERR, YAML_EXT Classes: Cli, Conf, CoreDef, CoreInst, HDLCoder, HDLFile, HDLParser, IfcDef, IfcPort, IfcSpc, Lib, LibInc, Parameter, SOCDef, SParameter, SParameterEntry, VHDLCoder, VHDLParser, VerilogCoder, VerilogParser, YPP
Constant Summary collapse
- LIBPATH =
:stopdoc:
::File.('..', __FILE__) + ::File::SEPARATOR
- PATH =
::File.dirname(LIBPATH) + ::File::SEPARATOR
- VERSION =
The SoC-Maker Version
"0.1.1"
Class Attribute Summary collapse
-
.conf ⇒ Object
The global configuration.
-
.lib ⇒ Object
The global library.
-
.logger ⇒ Object
The global logging instance.
Class Method Summary collapse
-
.check_static_setup(static) ⇒ Object
Ensure, that there are no multiple defined static parameters for a core/soc.
-
.deploy_soc(soc, coder = VHDLCoder.new) ⇒ Object
- Deployes a System-on-Chip: - get all core-ids - get all static parameters - call deploy for each core which causes to copy and generate all HDL files soc
- the System-on-Chip, which is deployed coder
-
the choosen HDL coder.
-
.from_f(path) ⇒ Object
Method to load a yaml-based object(s) from one or multiple files.
-
.from_s(s) ⇒ Object
Funtion to load a object from a YAML string.
-
.libpath(*args) ⇒ Object
Returns the library path for the module.
-
.load(options = {}) ⇒ Object
Global initialization method: this loads the config and refreshes the core library.
-
.path(*args) ⇒ Object
Returns the lpath for the module.
-
.require_all_libs ⇒ Object
load all file for soc_maker.
-
.to_yaml_s(o) ⇒ Object
This method takes an object, converts it to a YAML string and also applies the YPP to replace the YAML object-tags.
Class Attribute Details
.conf ⇒ Object
The global configuration
91 92 93 |
# File 'lib/soc_maker.rb', line 91 def conf @conf end |
.lib ⇒ Object
The global library
94 95 96 |
# File 'lib/soc_maker.rb', line 94 def lib @lib end |
.logger ⇒ Object
The global logging instance
88 89 90 |
# File 'lib/soc_maker.rb', line 88 def logger @logger end |
Class Method Details
.check_static_setup(static) ⇒ Object
Ensure, that there are no multiple defined static parameters for a core/soc.
- static
-
Input hash with the structure { soc_id : { core_id1: { .… }, core_id2: { .… } } }
- return
-
Output hash with the structure { core_id1: { .…}, core_id2: { .… } }
225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/soc_maker.rb', line 225 def check_static_setup( static ) static_tmp = {} static.each do |core_id, static_setup| static_setup.each do |core_id2, value | if static_tmp.has_key?( core_id2 ) raise ConsistenceError.new( "Invalid static setup: #{core_id2} is defined multiple times" ) end static_tmp[ core_id2 ] = value end end return static_tmp end |
.deploy_soc(soc, coder = VHDLCoder.new) ⇒ Object
Deployes a System-on-Chip:
-
get all core-ids
-
get all static parameters
-
call deploy for each core which causes to copy and generate all HDL files
- soc
-
the System-on-Chip, which is deployed
- coder
-
the choosen HDL coder
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/soc_maker.rb', line 202 def deploy_soc( soc, coder = VHDLCoder.new ) SOCMaker::logger.info "Deploying SOC #{soc.name}" soc.consistence_check ids = soc.all_core_id static = soc.all_static_parameters static = check_static_setup( static ) SOCMaker::logger.info "Core Occurrence" SOCMaker::CoreDef.core_cnt( ids ).each do |k,v| SOCMaker::logger.info "#{k}\t#{v}" end ids.uniq.each{ |core| lib.get_core( core ).deploy( coder: coder, static: static ) } end |
.from_f(path) ⇒ Object
Method to load a yaml-based object(s) from one or multiple files. The files are read and concatenated. Path argument can be an array of paths or a file (wildcards are allowed) loading from a YAML file
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/soc_maker.rb', line 169 def from_f( path ) path = Dir[ path ].sort if path.is_a?( String ) SOCMaker::logger.warn( "No file(s) found to load" ) if path.size == 0 yaml_str = "" path.each do |file| SOCMaker::logger.info "reading:" + file yaml_str << File.read( file ) end o = from_s( yaml_str ) o.src_dir = File.dirname( path.first ) return o end |
.from_s(s) ⇒ Object
Funtion to load a object from a YAML string. This includes the YPP, which replaces our custom object tags with yaml object information. Afterwards, the method YAML::load is used to create the object.
In addition, it is possible to provide multiple objects in one string: YPP takes care and splits them into single object strings.
- s
-
the object(s) as yaml string (before processing with YPP)
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/soc_maker.rb', line 133 def from_s( s ) objs = [] SOCMaker::YPP.to_yaml( s ) do |yaml_obj_str| begin YAML::load( yaml_obj_str ) o = YAML::load( yaml_obj_str ) # ensure, that we load only our classes if SOCMaker::conf[ :yaml_classes ].include?( o.class ) #o.verify objs << o else SOCMaker::logger.warn( "Tried to load something, which does not belong to #{SOCMaker::conf[ :app_name ]}" ) end rescue ArgumentError, Psych::SyntaxError => e SOCMaker::logger.error( 'YAML loading failed, invalid YAML syntax?' ) SOCMaker::logger.error( ">>> #{e.to_s} <<<" ) raise ERR::YAMLParseError else end end if block_given? objs.each{ |o| yield(o) } end return ( objs.size >1 ? objs : objs[0] ) end |
.libpath(*args) ⇒ Object
Returns the library path for the module. If any arguments are given, they will be joined to the end of the libray path using File.join
.
272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/soc_maker.rb', line 272 def self.libpath( *args ) rv = args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten) if block_given? begin $LOAD_PATH.unshift LIBPATH rv = yield ensure $LOAD_PATH.shift end end return rv end |
.load(options = {}) ⇒ Object
Global initialization method: this loads the config and refreshes the core library. Typically, this is the first method which is called during initialization.
- options
-
skip_refresh=true/false: can be used to skip refreshing the core library
-
logger_out=<any file stream>: default is STDOUT, can be used to put the log into a file
-
107 108 109 110 111 112 113 114 |
# File 'lib/soc_maker.rb', line 107 def load( ={} ) = { skip_refresh: false, logger_out: STDOUT }.merge( ) @conf = Conf.instance @logger = Logger.new([ :logger_out ] ) @lib = Lib.new() @logger.progname = @conf[ :app_name ] @lib.refresh( [ :libpath ] ) unless [ :skip_refresh ] end |
.path(*args) ⇒ Object
Returns the lpath for the module. If any arguments are given, they will be joined to the end of the path using File.join
.
289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/soc_maker.rb', line 289 def self.path( *args ) rv = args.empty? ? PATH : ::File.join(PATH, args.flatten) if block_given? begin $LOAD_PATH.unshift PATH rv = yield ensure $LOAD_PATH.shift end end return rv end |
.require_all_libs ⇒ Object
load all file for soc_maker
305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/soc_maker.rb', line 305 def self.require_all_libs file = ::File.basename(__FILE__, '.*') dir = ::File.dirname(__FILE__) %w[ err ypp lib_inc version core_def core_inst hdl_file ifc_def ifc_port ifc_spc soc_def parameter sparameter hdl_coder lib cli conf hdl_parser ].each { |rb| require ::File.( ::File.join( dir, file, rb ) ) } end |