class SOCMaker::Cli
Command-line interface for accessing the SOC-Maker functionallity
PLEASE NOTE: this class is outdated and needs some work!!
The following commands are available:
-
new -> create a new soc file
-
open -> open soc file
-
list -> list library
-
add -> add core to the SOC
-
add_interface -> add an interface to the 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
and this class is realized as singleton.
TODO: add commands for
-
selecting the coder (at the moment, only VHDL is supported)
-
refreshing the lib
Constants
- ADD_INTERFACE_USAGE
- ADD_USAGE
Usage message of the 'add' comand
- CONNECT_USAGE
Usage message of the 'connect' comand
- DELETE_USAGE
Usage message of the 'delete' comand
- EXIT_USAGE
Usage message of the 'exit' comand
- FMSG
failed message
- GENERATE_USAGE
Usage message of the 'generate' comand
- GET_USAGE
Usage message of the 'get' comand
- HELP_USAGE
Usage message of the 'help' comand
- LIST_USAGE
Usage message of the 'list' comand
- NEW_USAGE
Usage message of the 'new' comand
- OPEN_USAGE
Usage message of the 'open' comand
- PARAMETER_USAGE
Usage message of the 'parameter' comand
- PRINT_USAGE
Usage message of the 'print' comand
- QUIT_USAGE
Usage message of the 'quit' comand
- SAVE_USAGE
Usage message of the 'save' comand
- SET_USAGE
Usage message of the 'set' comand
- SPARAMETER_USAGE
Usage message of the 'sparameter' comand
Public Class Methods
Constructor of this CLI: it sets up a abbreviation map and a list of available commands. Moreover, it initializes readline.
# File lib/soc_maker/cli.rb, line 100 def initialize # abbreviation 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 add_interface parameter sparameter delete connect save help quit exit generate print set get ] comp = proc { |s| (@commands + Dir.entries( Dir.pwd )).grep( /^#{Regexp.escape(s)}/ ) } Readline.completion_append_character = " " Readline.completion_proc = comp end
Public Instance Methods
Method to processes a single command
# File lib/soc_maker/cli.rb, line 146 def process_cmd( c ) # remove the comments and split each line match = SOCMaker::conf[ :COMMENT_REGEX ].match( c ) cmd_arr = match[1].split( ' ' ) # process the command, if there is one if cmd_arr.size > 0 cmd = "" if cmd_arr[ 0 ].size == 1 and @appr_map[ cmd_arr[ 0 ] ] != nil cmd = @appr_map[ cmd_arr[ 0 ] ] else cmd = cmd_arr[ 0 ] end if @commands.include?( cmd ) cmd_str = "do_#{cmd}( cmd_arr[ 1..-1] )" puts "evaluating >>#{cmd_str}<< " eval( cmd_str ) elsif !Gem.win_platform? && system( "which #{cmd} > /dev/null 2>&1" ) # this is for linux only system( c ) else puts "Command #{cmd} not available" end #begin #rescue # puts "evaluating >>#{cmd_str}<< failed" #end end end
Method to start processing the commands. Readline us used to receive input data. Each line to passed to process_cmd.
# File lib/soc_maker/cli.rb, line 133 def run ## # process user commands # while buf = Readline.readline( "> ", true ) process_cmd buf end end
Private Instance Methods
Implementation of the 'add' command
# File lib/soc_maker/cli.rb, line 266 def do_add( args ) if args.size != 2 puts "two arguments are required:\nusage:\n#{ADD_USAGE}" else @soc.add_core( args[ 0 ].to_sym, args[ 1 ].to_sym ) @soc.consistence_check end end
# File lib/soc_maker/cli.rb, line 286 def do_add_interface( args ) if args.size < 5 || args.size % 2 != 1 puts "five or more (but odd) arguments required:\nusage:\n#{ADD_INTERFACE_USAGE}" else ports = {} args[3..-1].each_slice(2).to_a.each do |entry| ports[ entry[0].to_sym ] = SOCMaker::IfcPort.new( entry[0], entry[1] ) end @soc.add_interface( args[0], args[ 1 ], args[2].to_i, ports ) end end
Implementation of the 'connect' command
# File lib/soc_maker/cli.rb, line 369 def do_connect( args ) if args.size != 5 puts "five arguments are required:\nusage:\n#{CONNECT_USAGE}" else @soc.add_connection( args[ 0 ], args[ 1 ].to_sym, args[ 2 ].to_sym, args[ 3 ].to_sym, args[ 4 ].to_sym ) @soc.consistence_check end end
Implementation of the 'delete' command
# File lib/soc_maker/cli.rb, line 394 def do_delete( args ) if args.size != 1 puts "five arguments are required:\nusage:\n#{DELETE_USAGE}" else @soc.rm( args[ 0 ].to_sym ) @soc.consistence_check end end
Implementation of the 'exit' command
# File lib/soc_maker/cli.rb, line 485 def do_exit( args ) puts "... bye bye!" exit 0 end
Implementation of the 'generate' command
# File lib/soc_maker/cli.rb, line 434 def do_generate( args ) if args.size != 0 puts "no arguments are required:\nusage:\n#{GENERATE_USAGE}" else @soc.consistence_check SOCMaker::deploy_soc( @soc ) end end
Implementation of the 'get' command
# File lib/soc_maker/cli.rb, line 528 def do_get( args ) puts "NOT IMPLEMENTED, YET" end
Implementation of the 'help' command
# File lib/soc_maker/cli.rb, line 500 def do_help( args ) puts "The following commands are available:\n\n" @commands.each { |c| eval "puts #{c.upcase}_USAGE" } end
Implementation of the 'list' command
# File lib/soc_maker/cli.rb, line 249 def do_list( args ) puts SOCMaker::lib end
Implementation of the 'new' command
# File lib/soc_maker/cli.rb, line 206 def do_new( args ) if args.size != 3 puts "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.consistence_check end end
Implementation of the 'open' command
# File lib/soc_maker/cli.rb, line 227 def do_open( args ) if args.size != 1 puts "only one argument is required:\nusage:\n#{OPEN_USAGE}" else puts "loading #{args[0]}" @soc = SOCMaker::from_f( args[0] ) SOCMaker::lib.add_core( @soc ) @soc.consistence_check end end
Implementation of the 'parameter' command
# File lib/soc_maker/cli.rb, line 317 def do_parameter( args ) if args.size == 2 @soc.get_param( args[ 0 ].to_sym, args[ 1 ].to_sym ) elsif args.size == 3 @soc.set_param( args[ 0 ].to_sym, args[ 1 ].to_sym, args[ 2 ] ) @soc.consistence_check else puts "two or three arguments required:\nusage:\n#{PARAMETER_USAGE}" end end
Implementation of the 'print' command
# File lib/soc_maker/cli.rb, line 453 def do_print( args ) if args.size != 0 puts "no arguments are required:\nusage:\n#{PRINT_USAGE}" else puts @soc end end
Implementation of the 'quit' command
# File lib/soc_maker/cli.rb, line 471 def do_quit( args ) do_exit( args ) end
Implementation of the 'save' command
# File lib/soc_maker/cli.rb, line 414 def do_save( args ) if args.size > 1 puts "zero or one argument is required:\nusage:\n#{SAVE_USAGE}" else p args @soc.save_yaml( args ) File.open( args[0], 'w' ) { |f| f.write( SOCMaker::to_yaml_s( @soc ) ) } end end
Implementation of the 'set' command
# File lib/soc_maker/cli.rb, line 515 def do_set( args ) puts "NOT IMPLEMENTED, YET" end
Implementation of the 'sparameter' command
# File lib/soc_maker/cli.rb, line 342 def do_sparameter( args ) if args.size == 2 @soc.get_sparam( args[ 0 ].to_sym, args[ 1 ].to_sym ) elsif args.size == 3 @soc.set_sparam( args[ 0 ].to_sym, args[ 1 ].to_sym, args[ 2 ] ) @soc.consistence_check else puts "two or three arguments required:\nusage:\n#{SPARAMETER_USAGE}" end end