URL
https://opencores.org/ocsvn/soc_maker/soc_maker/trunk
Subversion Repositories soc_maker
[/] [soc_maker/] [trunk/] [lib/] [soc_maker/] [cli.rb] - Rev 7
Go to most recent revision | Compare with Previous | Blame | View Log
#!/usr/bin/env ruby################################################################# File: soc_maker_cli.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/>.################################################################### Description:## Command-line interface for accessing the SOC-Maker functionallity## The following commands are available:# - new -> create a new soc file# - open -> open soc file# - list -> list library# - add -> add core to soc# - parameter -> set/get parameter# - sparameter -> set/get static parameter# - connect -> connect cores# - delete -> delete core or connection# - save -> save soc# - generate -> generate soc# - quit -> quit this CLI# - exit -> same than quit# - help -> print some help## Please use the help command to get more information about# each command and its parameters.## This CLI is a wrapper around SOCMaker::SOCDef.########### TODO: add commands for# - selecting the coder# (at the moment, only VHDL is supported)## - refreshing the lib#################################################################require 'readline'require 'optparse'module SOCMakerclass Cliprivate_class_method :newdef Cli.instance@@inst = new if @@inst == nilreturn @@instendFMSG = ' -> failed '########################################### command implementations:# -> a usage string and# a function for every command### New#NEW_USAGE =" > new <<name>> <<version>> <<toplevel>> # opens a system-on-chip file- <<name>> : the SOC name- <<version>> : the SOC version- <<toplevel>> : the toplevel name"def do_new( args )if args.size != 3puts "three arguments are required:\nusage:\n#{NEW_USAGE}"else@soc = SOCMaker::SOCDef.new( args[0], args[1], args[2] )SOCMaker::lib.add_core( @soc )@soc_inst = SOCMaker::CoreInst.new( "#{args[0]}#{args[1]}" )#puts FMSG if @soc.load_soc( args[ 0 ] ) == nilendend## Open#OPEN_USAGE =" > open <<file>> # opens a system-on-chip file- <<file>> : system-on-chip definition in in YAML format"def do_open( args )if args.size != 1puts "only one argument is required:\nusage:\n#{OPEN_USAGE}"elseputs "loading #{args[0]}"@soc = SOCMaker::from_f( args[0] )SOCMaker::lib.add_core( @soc )@soc_inst = SOCMaker::CoreInst.new( "#{@soc.name}#{@soc.version}" )#puts FMSG if @soc.load_soc( args[ 0 ] ) == nilendend## List#LIST_USAGE =" > list # prints list of cores and interfaces,which are in the library"def do_list( args )puts SOCMaker::libend## Add#ADD_USAGE =" > add <<core>> <<version>> <<name>># adds a ip-core from the library to the SOC- <<core>> : name of the IP core- <<version>> : version of the IP core- <<name>> : instanciation name"def do_add( args )if args.size != 3puts "three arguments are required:\nusage:\n#{ADD_USAGE}"elseputs FMSG if @soc.add_core( args[ 0 ], args[ 1 ], args[ 2 ] ) == nilendend## Set/Get Parameter#PARAMETER_USAGE =" > prameter <<instance>> <<parameter>> <<value>># modifies a parameter of an instance- <<instance>> : the instance name of the core- <<parameter>> : the instance parameter name- <<value>> : the value which is set (optional). The currentvalue is printed, if omitted"def do_parameter( args )if args.size == 2puts FMSG if @soc.get_param( args[ 0 ], args[ 1 ] ) == nilelsif args.size == 3puts FMSG if @soc.set_param( args[ 0 ], args[ 1 ], args[ 2 ] ) == nilelseputs "two or three arguments required:\nusage:\n#{PARAMETER_USAGE}"endend## Set/Get Static Parameter#SPARAMETER_USAGE =" > sprameter <<core>> <<parameter>> <<value>># modifies the static parameter of a core- <<core>> : the name of the core- <<parameter>> : the static parameter name- <<value>> : the value which is set (optional). The currentvalue is printed, if omitted"def do_sparameter( args )if args.size == 2puts FMSG if @soc.get_sparam( args[ 0 ], args[ 1 ] ) == nilelsif args.size == 3puts FMSG if @soc.set_sparam( args[ 0 ], args[ 1 ], args[ 2 ] ) == nilelseputs "two or three arguments required:\nusage:\n#{SPARAMETER_USAGE}"endend## Connect#CONNECT_USAGE =" > connect <<core1>> <<ifc1>> <<core2>> <<ifc2>> <<name>># connects two cores- <<core1>> : instance name of the first core- <<core2>> : instance name of the second core- <<ifc1>> : interface name of the first core- <<ifc2>> : interface name of the second core- <<name>> : connection name"def do_connect( args )if args.size != 5puts "five arguments are required:\nusage:\n#{CONNECT_USAGE}"elseputs FMSG if @soc.add_connection( args[ 0 ], args[ 1 ], args[ 2 ], args[ 3 ], args[ 4 ] )endend## Delete#DELETE_USAGE =" > delete <<core/connection>># removes a core or a connection- <<core/conection> : the core or connection, which is removed"def do_delete( args )if args.size != 1puts "five arguments are required:\nusage:\n#{DELETE_USAGE}"elseputs FMSG if @soc.rm( args[ 0 ] ) == nilendend## Save#SAVE_USAGE =" > save <<file>> # saves system-on-chip definition in YAML format to file- <<file>> : optional destination file, when omitted: theoriginal file-path is used"def do_save( args )if args.size > 1puts "zero or one argument is required:\nusage:\n#{SAVE_USAGE}"elsep argsputs FMSG if @soc.save_yaml( args ) == nilendend## Generate#GENERATE_USAGE =" > generate # generates a synthesizable system-on-chip implementation"def do_generate( args )if args.size != 0puts "no arguments are required:\nusage:\n#{GENERATE_USAGE}"else@soc_inst.gen_toplevel@soc.copy_filesendendPRINT_USAGE =" > print # prints SOC information"def do_print( args )if args.size != 0puts "no arguments are required:\nusage:\n#{PRINT_USAGE}"elseputs @socendend## Quit#QUIT_USAGE =" > quit # the same than exit"def do_quit( args )do_exit( args )end## Exit#EXIT_USAGE =" > exit # exits this tool"def do_exit( args )puts "... bye bye!"exit 0end## Help#HELP_USAGE =" > help # prints some help information"def do_help( args )puts "The following commands are available:\n\n"@commands.each { |c| eval "puts #{c.upcase}_USAGE" }endSET_USAGE =" > set # not implemented yet"def do_set( args )puts "NOT IMPLEMENTED, YET"endGET_USAGE =" > get # not implemented yet"def do_get( args )puts "NOT IMPLEMENTED, YET"end# end command implementations##################################@soc = nil@soc_inst = nildef initialize# appreviation map@appr_map = { 'n' => "new",'o' => "open",'q' => "quit",'h' => "help",'l' => "list",'a' => "add",'g' => "generate",'s' => "save",'p' => "parameter",'d' => "delete",'c' => "connect",'i' => "print",'x' => "exit"}# all available commands@commands = %w[ new open list add parameter sparameterdelete connect save help quit exitgenerate print set get ]comp = proc { |s| (@commands + Dir.entries( Dir.pwd )).grep( /^#{Regexp.escape(s)}/ ) }Readline.completion_append_character = " "Readline.completion_proc = compenddef run### process user commands#while buf = Readline.readline( "> ", true )process_cmd bufendenddef process_cmd( c )# remove the comments and split each linematch = SOCMaker::conf[ :COMMENT_REGEX ].match( c )cmd_arr = match[1].split( ' ' )# process the command, if there is oneif cmd_arr.size > 0cmd = ""if cmd_arr[ 0 ].size == 1 and @appr_map[ cmd_arr[ 0 ] ] != nilcmd = @appr_map[ cmd_arr[ 0 ] ]elsecmd = cmd_arr[ 0 ]endif @commands.include?( cmd )cmd_str = "do_#{cmd}( cmd_arr[ 1..-1] )"puts "evaluating >>#{cmd_str}<< "eval( cmd_str )#TODO this is for linux onlyelsif system( "which #{cmd} > /dev/null 2>&1" )system( c )elseputs "Command #{cmd} not available"end#begin#rescue# puts "evaluating >>#{cmd_str}<< failed"#endendend@@inst = nilendend# vim: noai:ts=2:sw=2
Go to most recent revision | Compare with Previous | Blame | View Log
