X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=sim%2Fucsim%2Fcmd.src%2Fcmdset.cc;h=8f3523bb3b03c6371bedff9f8ff61edd82b65e46;hb=90f4aedaef8a2310573eef905f95c671f84e5cde;hp=c985354b7cbbbf3fd26a13f5f7175881d5a61fc2;hpb=98671430502e22f7cc8764845254afc2d725131b;p=fw%2Fsdcc diff --git a/sim/ucsim/cmd.src/cmdset.cc b/sim/ucsim/cmd.src/cmdset.cc index c985354b..8f3523bb 100644 --- a/sim/ucsim/cmd.src/cmdset.cc +++ b/sim/ucsim/cmd.src/cmdset.cc @@ -27,6 +27,9 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "ddconfig.h" +#include "cmdlexcl.h" +#include "cmdpars.h" + // prj #include "i_string.h" #include "utils.h" @@ -47,51 +50,51 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA //int //cl_run_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_SIM(cl_run_cmd) { class cl_brk *b; t_addr start, end; class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; if (params[0]) if (!(params[0]->get_address(sim->uc, &start))) { - con->dd_printf("Error: wrong start address\n"); - return(DD_FALSE); + con->dd_printf("Error: wrong start address\n"); + return(DD_FALSE); } if (params[1]) if (!(params[1]->get_address(sim->uc, &end))) { - con->dd_printf("Error: wromg end address\n"); - return(DD_FALSE); + con->dd_printf("Error: wromg end address\n"); + return(DD_FALSE); } if (params[0]) { if (!sim->uc->inst_at(start)) - con->dd_printf("Warning: maybe not instruction at 0x%06lx\n", start); + con->dd_printf("Warning: maybe not instruction at 0x%06lx\n", start); sim->uc->PC= start; if (params[1]) - { - if (start == end) - { - con->dd_printf("Addresses must be different.\n"); - return(DD_FALSE); - } - if ((b= sim->uc->fbrk_at(end))) - { - } - else - { - b= new cl_fetch_brk(sim->uc->mem(MEM_ROM), - sim->uc->make_new_brknr(), end, - brkDYNAMIC, 1); - sim->uc->fbrk->add_bp(b); - } - } + { + if (start == end) + { + con->dd_printf("Addresses must be different.\n"); + return(DD_FALSE); + } + if ((b= sim->uc->fbrk_at(end))) + { + } + else + { + b= new cl_fetch_brk(sim->uc->address_space(MEM_ROM_ID), + sim->uc->make_new_brknr(), end, + brkDYNAMIC, 1); + sim->uc->fbrk->add_bp(b); + } + } } con->dd_printf("Simulation started, PC=0x%06x\n", sim->uc->PC); if (sim->uc->fbrk_at(sim->uc->PC)) @@ -109,7 +112,7 @@ COMMAND_DO_WORK_SIM(cl_run_cmd) //int //cl_stop_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_SIM(cl_stop_cmd) { sim->stop(resUSER); @@ -125,7 +128,7 @@ COMMAND_DO_WORK_SIM(cl_stop_cmd) //int //cl_step_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_step_cmd) { //printf("step %x\n",uc->PC); @@ -143,7 +146,7 @@ COMMAND_DO_WORK_UC(cl_step_cmd) //int //cl_next_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_SIM(cl_next_cmd) { class cl_brk *b; @@ -157,7 +160,7 @@ COMMAND_DO_WORK_SIM(cl_next_cmd) int i= 0; de= &(sim->uc->dis_tbl()[i]); while ((code & de->mask) != de->code && - de->mnemonic) + de->mnemonic) { i++; de= &(sim->uc->dis_tbl()[i]); @@ -171,25 +174,26 @@ COMMAND_DO_WORK_SIM(cl_next_cmd) { next= sim->uc->PC + inst_len; if (!sim->uc->fbrk_at(next)) - { - b= new cl_fetch_brk(sim->uc->mem(MEM_ROM), - sim->uc->make_new_brknr(), - next, brkDYNAMIC, 1); + { + b= new cl_fetch_brk(sim->uc->address_space(MEM_ROM_ID), + sim->uc->make_new_brknr(), + next, brkDYNAMIC, 1); - b->init(); -// sim->uc->fbrk->add_bp(b); + b->init(); +// sim->uc->fbrk->add_bp(b); - sim->uc->fbrk->add(b); - b->activate(); - } + sim->uc->fbrk->add(b); + b->activate(); + } if (sim->uc->fbrk_at(sim->uc->PC)) - sim->uc->do_inst(1); + sim->uc->do_inst(1); sim->start(con); //sim->uc->do_inst(-1); } - else + else { sim->uc->do_inst(1); - sim->uc->print_regs(con); + sim->uc->print_regs(con); + } return(DD_FALSE); } @@ -201,77 +205,173 @@ COMMAND_DO_WORK_SIM(cl_next_cmd) //int //cl_help_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_APP(cl_help_cmd) { class cl_sim *sim; - class cl_commander *cmd; + class cl_commander_base *commander; class cl_cmdset *cmdset= 0; - class cl_cmd *c; int i; class cl_cmd_arg *parm= cmdline->param(0); sim= app->get_sim(); - if ((cmd= app->get_commander()) != 0) - cmdset= cmd->cmdset; + if ((commander= app->get_commander()) != 0) + cmdset= commander->cmdset; if (!cmdset) return(DD_FALSE); if (!parm) { for (i= 0; i < cmdset->count; i++) { - c= (class cl_cmd *)(cmdset->at(i)); - if (c->short_help) - con->dd_printf("%s\n", c->short_help); - else - con->dd_printf("%s\n", (char*)(c->names->at(0))); + class cl_cmd *c= (class cl_cmd *)(cmdset->at(i)); + if (c->short_help) + con->dd_printf("%s\n", c->short_help); + else + con->dd_printf("%s\n", (char*)(c->names->at(0))); } } - else if (cmdline->syntax_match(/*sim*/0, STRING)) { - int matches= 0; + else + { + matches= 0; + do_set(cmdline, 0, cmdset, con); + if (matches == 1 && + cmd_found) + { + int names; + con->dd_printf("Names of command:"); + for (names= 0; names < cmd_found->names->count; names++) + con->dd_printf(" %s", (char*)(cmd_found->names->at(names))); + con->dd_printf("\n"); + class cl_cmdset *subset= cmd_found->get_subcommands(); + if (subset) + { + con->dd_printf("\"%s\" must be followed by the name of a " + "subcommand\nList of subcommands:\n", + (char*)(cmd_found->names->at(0))); + for (i= 0; i < subset->count; i++) + { + class cl_cmd *c= + dynamic_cast(subset->object_at(i)); + con->dd_printf("%s\n", c->short_help); + } + } + if (cmd_found->long_help) + con->dd_printf("%s\n", cmd_found->long_help); + } + if (!matches || + !cmd_found) + con->dd_printf("No such command.\n"); + //return(DD_FALSE); + /* + int pari; + for (pari= 0; pari < cmdline->nuof_params(); pari++) + { + class cl_cmd_arg *act_param; + act_param= (class cl_cmd_arg *)(cmdline->param(pari)); + for (i= 0; i < cmdset->count; i++) + { + class cl_cmd *c= (class cl_cmd *)(cmdset->at(i)); + if (!c->name_match(act_param->s_value, DD_FALSE)) + continue; + if (c->short_help) + con->dd_printf("%s\n", c->short_help); + else + con->dd_printf("%s\n", (char*)(c->names->at(0))); + if (pari < cmdline->nuof_params()-1) + continue; + cmdset= c->get_subcommands(); + if (!cmdset) + return(DD_FALSE); + } + } + return(DD_FALSE); + */ + } + return(DD_FALSE); + /* + if (cmdline->syntax_match(0, STRING)) { + matches= 0; for (i= 0; i < cmdset->count; i++) { - c= (class cl_cmd *)(cmdset->at(i)); - if (c->name_match(parm->value.string.string, DD_FALSE)) - matches++; + c= (class cl_cmd *)(cmdset->at(i)); + if (c->name_match(parm->value.string.string, DD_FALSE)) + matches++; } if (!matches) con->dd_printf("No such command\n"); else if (matches > 1) for (i= 0; i < cmdset->count; i++) - { - c= (class cl_cmd *)(cmdset->at(i)); - if (!c->name_match(parm->value.string.string, DD_FALSE)) - continue; - if (c->short_help) - con->dd_printf("%s\n", c->short_help); - else - con->dd_printf("%s\n", (char*)(c->names->at(0))); - } + { + c= (class cl_cmd *)(cmdset->at(i)); + if (!c->name_match(parm->value.string.string, DD_FALSE)) + continue; + if (c->short_help) + con->dd_printf("%s\n", c->short_help); + else + con->dd_printf("%s\n", (char*)(c->names->at(0))); + } else for (i= 0; i < cmdset->count; i++) - { - c= (class cl_cmd *)(cmdset->at(i)); - if (!c->name_match(parm->value.string.string, DD_FALSE)) - continue; - if (c->short_help) - con->dd_printf("%s\n", c->short_help); - else - con->dd_printf("%s\n", (char*)(c->names->at(0))); - int names; - con->dd_printf("Names of command:"); - for (names= 0; names < c->names->count; names++) - con->dd_printf(" %s", (char*)(c->names->at(names))); - con->dd_printf("\n"); - if (c->long_help) - con->dd_printf("%s\n", c->long_help); - else - con->dd_printf("%s\n", (char*)(c->names->at(0))); - } + { + c= (class cl_cmd *)(cmdset->at(i)); + if (!c->name_match(parm->value.string.string, DD_FALSE)) + continue; + if (c->short_help) + con->dd_printf("%s\n", c->short_help); + else + con->dd_printf("%s\n", (char*)(c->names->at(0))); + int names; + con->dd_printf("Names of command:"); + for (names= 0; names < c->names->count; names++) + con->dd_printf(" %s", (char*)(c->names->at(names))); + con->dd_printf("\n"); + if (c->long_help) + con->dd_printf("%s\n", c->long_help); + else + con->dd_printf("%s\n", (char*)(c->names->at(0))); + } } else con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax"); return(0); + */ +} + +bool +cl_help_cmd::do_set(class cl_cmdline *cmdline, int pari, + class cl_cmdset *cmdset, + class cl_console_base *con) +{ + int i; + for (i= 0; i < cmdset->count; i++) + { + class cl_cmd *cmd= dynamic_cast(cmdset->object_at(i)); + if (!cmd) + continue; + if (pari >= cmdline->nuof_params()) + return(DD_FALSE); + class cl_cmd_arg *param= cmdline->param(pari); + if (!param) + return(DD_FALSE); + class cl_cmdset *next_set= cmd->get_subcommands(); + if (cmd->name_match(param->s_value, DD_FALSE)) + { + if (pari+1 >= cmdline->nuof_params()) + { + matches++; + cmd_found= cmd; + if (cmd->short_help) + con->dd_printf("%s\n", cmd->short_help); + else + con->dd_printf("%s\n", (char*)(cmd->names->at(0))); + //continue; + } + else + if (next_set) + do_set(cmdline, pari+1, next_set, con); + } + } + return(DD_TRUE); } @@ -282,7 +382,7 @@ COMMAND_DO_WORK_APP(cl_help_cmd) //int //cl_quit_cmd::do_work(class cl_sim *sim, -// class cl_cmdline */*cmdline*/, class cl_console */*con*/) +// class cl_cmdline */*cmdline*/, class cl_console_base */*con*/) COMMAND_DO_WORK(cl_quit_cmd) { return(1); @@ -296,7 +396,7 @@ COMMAND_DO_WORK(cl_quit_cmd) //int //cl_kill_cmd::do_work(class cl_sim *sim, -// class cl_cmdline */*cmdline*/, class cl_console */*con*/) +// class cl_cmdline */*cmdline*/, class cl_console_base */*con*/) COMMAND_DO_WORK_APP(cl_kill_cmd) { app->going= 0; @@ -306,4 +406,58 @@ COMMAND_DO_WORK_APP(cl_kill_cmd) } +/* + * EXEC file + */ + +COMMAND_DO_WORK_APP(cl_exec_cmd) +{ + class cl_cmd_arg *parm= cmdline->param(0); + char *fn= 0; + + if (cmdline->syntax_match(0, STRING)) { + fn= parm->value.string.string; + } + else + con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n"); + + class cl_commander_base *c= app->get_commander(); + class cl_console_base *cons= con->clone_for_exec(fn); + if (cons) + { + cons->flags|= CONS_NOWELCOME; + c->add_console(cons); + } + + return(DD_FALSE); +} + + +/* + * expression expression + */ + +COMMAND_DO_WORK_APP(cl_expression_cmd) +{ + //con->dd_printf("\"%s\"\n", cmdline->cmd); + char *s= cmdline->cmd; + if (!s || + !*s) + return(DD_FALSE); + int i= strspn(s, " \t\v\n"); + s+= i; + //con->dd_printf("\"%s\"\n", s); + i= strspn(s, "abcdefghijklmnopqrstuvwxyz"); + s+= i; + //con->dd_printf("\"%s\"\n", s); + class YY_cl_ucsim_parser_CLASS *pars; + class cl_ucsim_lexer *lexer; + lexer= new cl_ucsim_lexer(s); + pars= new YY_cl_ucsim_parser_CLASS(lexer); + pars->yyparse(); + delete pars; + return(DD_FALSE); +} + + /* End of cmd.src/cmdset.cc */