From d4bed025ed6de39e517422b076b5af9d7b31abb7 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 26 May 2017 13:20:20 -0400 Subject: [PATCH] command: Store the command parsing information directly in array Instead of defining an array of pointers, just define the array directly. Signed-off-by: Kevin O'Connor --- scripts/buildcommands.py | 18 ++++++------------ scripts/checkstack.py | 25 +++++++++++++++++-------- src/command.c | 11 +++-------- src/command.h | 2 +- 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/scripts/buildcommands.py b/scripts/buildcommands.py index 3935fa63..cb19c475 100644 --- a/scripts/buildcommands.py +++ b/scripts/buildcommands.py @@ -151,37 +151,31 @@ def build_param_types(all_param_types): def build_commands(cmd_by_id, messages_by_name, all_param_types): max_cmd_msgid = max(cmd_by_id.keys()) index = [] - parsers = [] externs = {} for msgid in range(max_cmd_msgid+1): if msgid not in cmd_by_id: - index.append(" 0,") + index.append(" {\n},") continue funcname, flags, msgname = cmd_by_id[msgid] msg = messages_by_name[msgname] externs[funcname] = 1 - parsername = 'parser_%s' % (funcname,) - index.append(" &%s," % (parsername,)) parser = msgproto.MessageFormat(msgid, msg) parsercode = build_parser(parser, 1, all_param_types) - parsers.append("const struct command_parser %s PROGMEM = {" - " %s\n .flags=%s,\n .func=%s\n};" % ( - parsername, parsercode, flags, funcname)) - index = "\n".join(index) + index.append(" {%s\n .flags=%s,\n .func=%s\n}," % ( + parsercode, flags, funcname)) + index = "".join(index).strip() externs = "\n".join(["extern void "+funcname+"(uint32_t*);" for funcname in sorted(externs)]) fmt = """ %s -%s - -const struct command_parser * const command_index[] PROGMEM = { +const struct command_parser command_index[] PROGMEM = { %s }; const uint8_t command_index_size PROGMEM = ARRAY_SIZE(command_index); """ - return fmt % (externs, '\n'.join(parsers), index) + return fmt % (externs, index) ###################################################################### diff --git a/scripts/checkstack.py b/scripts/checkstack.py index 34314218..e4cf45cc 100755 --- a/scripts/checkstack.py +++ b/scripts/checkstack.py @@ -135,8 +135,7 @@ def main(): continue m = re_asm.match(line) if m is None: - if funcaddr not in datalines: - datalines[funcaddr] = line.split() + datalines.setdefault(funcaddr, []).append(line) #print("other", repr(line)) continue insn = m.group('insn') @@ -192,14 +191,24 @@ def main(): funcnameroot = info.funcname.split('.')[0] funcsbyname[funcnameroot] = info cmdfunc = funcsbyname.get('sched_main') + command_index = funcsbyname.get('command_index') + if command_index is not None and cmdfunc is not None: + for line in datalines[command_index.funcaddr]: + parts = line.split() + if len(parts) < 9: + continue + calladdr = int(parts[8]+parts[7], 16) * 2 + numparams = int(parts[2], 16) + stackusage = cmdfunc.basic_stack_usage + 2 + numparams * 4 + cmdfunc.noteCall(0, calladdr, stackusage) + if len(parts) < 17: + continue + calladdr = int(parts[16]+parts[15], 16) * 2 + numparams = int(parts[10], 16) + stackusage = cmdfunc.basic_stack_usage + 2 + numparams * 4 + cmdfunc.noteCall(0, calladdr, stackusage) eventfunc = funcsbyname.get('__vector_13', funcsbyname.get('__vector_17')) for funcnameroot, info in funcsbyname.items(): - if funcnameroot.startswith('parser_'): - f = funcsbyname.get(funcnameroot[7:]) - if f is not None: - numparams = int(datalines[info.funcaddr][2], 16) - stackusage = cmdfunc.basic_stack_usage + 2 + numparams * 4 - cmdfunc.noteCall(0, f.funcaddr, stackusage) if funcnameroot.endswith('_event') and eventfunc is not None: eventfunc.noteCall(0, info.funcaddr, eventfunc.basic_stack_usage + 2) diff --git a/src/command.c b/src/command.c index 2a248f16..ae2b10fe 100644 --- a/src/command.c +++ b/src/command.c @@ -213,14 +213,9 @@ DECL_SHUTDOWN(sendf_shutdown); static const struct command_parser * command_get_handler(uint8_t cmdid) { - if (cmdid >= READP(command_index_size)) - goto error; - const struct command_parser *cp = READP(command_index[cmdid]); - if (!cp) - goto error; - return cp; -error: - shutdown("Invalid command"); + if (!cmdid || cmdid >= READP(command_index_size)) + shutdown("Invalid command"); + return &command_index[cmdid]; } enum { CF_NEED_SYNC=1<<0, CF_NEED_VALID=1<<1 }; diff --git a/src/command.h b/src/command.h index 609becd9..5bd6faf4 100644 --- a/src/command.h +++ b/src/command.h @@ -50,7 +50,7 @@ enum { PT_uint32, PT_int32, PT_uint16, PT_int16, PT_byte, PT_string, PT_progmem_buffer, PT_buffer, }; -extern const struct command_parser * const command_index[]; +extern const struct command_parser command_index[]; extern const uint8_t command_index_size; extern const uint8_t command_identify_data[]; extern const uint32_t command_identify_size;