Commit 65623b4a authored by cota's avatar cota

Use alt_getopt to parse wbgen2's parameters

In the current command-line parameter parsing scheme, the
argument comes before the positional parameters. This is against
the UNIX tradition of passing the positional parameters first,
and then the arguments.

This patch gets rid of the existing parameter parsing code, using
alt-getopt to do the hard work for us. This gets rid of the unusual
behaviour mentioned above and also makes it easier to add more
commands or synonyms of existing ones.

Note: the help text has been modified to reflect these changes.
See how the help text looks like before and after the patch:

$ wbgen2 version 0.6.0
(c) Tomasz Wlostowski/CERN BE-Co-HT 2010

usage: ./wbgen2 input_file.wb [options]

Options:
-target [classic / pipelined]   - chooses between classic Wishbone bus and HT pipelined Wishbone.
-lang   [vhdl / verilog]        - chooses the HDL language to be generated
-vo     [file.vhdl / file.v]    - generates VHDL/Verilog code for the slave Wishbone core.
-co     [file.h]                - generates C header file containing register definitions and access macros
-consto [constants.v]           - generates Verilog file containing addresses of all registers/rams and writes them to specified file. Useful for writing testbenches.
-doco   [documentation.html]    - generates nice HTML documentation and writes it to specified file.

$ wbgen2 --help
slave Wishbone generator
  wbgen2 [options] input_file.wb
options:
  -C, --co=FILE         Write the slave's generated C header file to FILE
  -D, --doco=FILE       Write the slave's generated HTML documentation to FILE
  -h, --help              Show this help text
  -l, --lang=LANG       Set the output Hardware Description Language (HDL) to LANG
                          Valid values for LANG: {vhdl,verilog}
  -K, --constco=FILE    Populate FILE with Verilog output (mainly constants)
  -v, --version         Show version information
  -V, --vo=FILE         Write the slave's generated HDL code to FILE

wbgen2 (c) Tomasz Wlostowski/CERN BE-CO-HT 2010
Signed-off-by: Emilio G. Cota's avatarEmilio G. Cota <cota@braap.org>

git-svn-id: http://svn.ohwr.org/wishbone-gen@9 4537843c-45c2-4d80-8546-c3283569414f
parent 365bf3ef
...@@ -5,6 +5,8 @@ Option "executable" ...@@ -5,6 +5,8 @@ Option "executable"
Output "wbgen2" Output "wbgen2"
Module "alt_getopt" "modules/alt_getopt.lua"
Main "wbgen_common.lua" Main "wbgen_common.lua"
Main "cgen_common.lua" Main "cgen_common.lua"
Main "cgen_vhdl.lua" Main "cgen_vhdl.lua"
......
...@@ -26,60 +26,82 @@ options.target_interconnect = "wb-classic"; ...@@ -26,60 +26,82 @@ options.target_interconnect = "wb-classic";
options.register_data_output = false; options.register_data_output = false;
options.lang = "vhdl"; options.lang = "vhdl";
require "alt_getopt"
local usage_string = [[slave Wishbone generator
wbgen2 [options] input_file.wb]]
local commands_string = [[options:
-C, --co=FILE Write the slave's generated C header file to FILE
-D, --doco=FILE Write the slave's generated HTML documentation to FILE
-h, --help Show this help text
-l, --lang=LANG Set the output Hardware Description Language (HDL) to LANG
Valid values for LANG: {vhdl,verilog}
-K, --constco=FILE Populate FILE with Verilog output (mainly constants)
-v, --version Show version information
-V, --vo=FILE Write the slave's generated HDL code to FILE
wbgen2 (c) Tomasz Wlostowski/CERN BE-CO-HT 2010]]
function usage()
print(usage_string)
print("Try `wbgen2 -h' for more information")
end
function usage_complete()
print(usage_string)
print(commands_string)
end
function parse_args(arg) function parse_args(arg)
local n=1; local long_opts = {
help = "h",
if(arg[1] == nil) then version = "v",
print("wbgen2 version "..wbgen2_version); co = "C",
print("(c) Tomasz Wlostowski/CERN BE-Co-HT 2010"); doco = "D",
print(""); constco = "K",
print("usage: "..arg[0].." input_file.wb [options]"); lang = "l",
print(""); vo = "V",
print("Options: "); }
print("-target [classic / pipelined] - chooses between classic Wishbone bus and HT pipelined Wishbone."); local optarg
print("-lang [vhdl / verilog] - chooses the HDL language to be generated"); local optind
print("-vo [file.vhdl / file.v] - generates VHDL/Verilog code for the slave Wishbone core.");
print("-co [file.h] - generates C header file containing register definitions and access macros"); optarg,optind = alt_getopt.get_opts (arg, "hvC:D:K:l:V:", long_opts)
print("-consto [constants.v] - generates Verilog file containing addresses of all registers/rams and writes them to specified file. Useful for writing testbenches."); for key,value in pairs (optarg) do
print("-doco [documentation.html] - generates nice HTML documentation and writes it to specified file."); if key == "h" then
usage_complete()
print(""); os.exit(0)
os.exit(0);
end elseif key == "v" then
print("wbgen2 version "..wbgen2_version)
input_wb_file = arg[1]; os.exit(0)
vhdl_gen_reg_constants = false; elseif key == "C" then
vlog_gen_reg_constants = false; options.output_c_header_file = value
n=2; elseif key == "D" then
while(arg[n] ~= nil) do options.output_doc_file = value
local sw = arg[n];
elseif key == "K" then
if (sw == "-vo") then options.output_vlog_constants_file = value
options.output_hdl_file = chk_nil(arg[n+1], "HDL output filename expected");
n=n+2; elseif key == "l" then
elseif (sw == "-co") then options.lang = value
options.output_c_header_file = chk_nil(arg[n+1], "C header output filename expected");
n=n+2;
elseif (sw == "-consto") then
options.output_vlog_constants_file = chk_nil(arg[n+1],"Verilog constants filename expected");
n=n+2;
elseif (sw == "-doco") then
options.output_doc_file = chk_nil(arg[n+1],"Documentation filename expected");
n=n+2;
elseif (sw == "-lang") then
options.lang = chk_nil(arg[n+1],"Target HDL language name expected");
if (options.lang ~= "vhdl" and options.lang ~= "verilog") then if (options.lang ~= "vhdl" and options.lang ~= "verilog") then
die("Unknown HDL: "..options.lang); die("Unknown HDL: "..options.lang);
end end
n=n+2;
else elseif key == "V" then
n=n+1; options.output_hdl_file = value
end end
end end
if(arg[optind] == nil) then
usage()
os.exit(0)
end
input_wb_file = arg[optind];
end end
parse_args(arg); parse_args(arg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment