Class: SOCMaker::Cli

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/soc_maker/cli.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initializeCli

Constructor of this CLI: it sets up a abbreviation map and a list of available commands. Moreover, it initializes readline.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# 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

Instance Method Details

#process_cmd(c) ⇒ Object

Method to processes a single command



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# 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

#runObject

Method to start processing the commands. Readline us used to receive input data. Each line to passed to process_cmd.



133
134
135
136
137
138
139
140
141
# File 'lib/soc_maker/cli.rb', line 133

def run

  ##
  # process user commands
  #
  while buf = Readline.readline( "> ", true )
    process_cmd buf
  end
end