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 <kevin@koconnor.net>
This commit is contained in:
parent
a82e949c00
commit
d4bed025ed
|
@ -151,37 +151,31 @@ def build_param_types(all_param_types):
|
||||||
def build_commands(cmd_by_id, messages_by_name, all_param_types):
|
def build_commands(cmd_by_id, messages_by_name, all_param_types):
|
||||||
max_cmd_msgid = max(cmd_by_id.keys())
|
max_cmd_msgid = max(cmd_by_id.keys())
|
||||||
index = []
|
index = []
|
||||||
parsers = []
|
|
||||||
externs = {}
|
externs = {}
|
||||||
for msgid in range(max_cmd_msgid+1):
|
for msgid in range(max_cmd_msgid+1):
|
||||||
if msgid not in cmd_by_id:
|
if msgid not in cmd_by_id:
|
||||||
index.append(" 0,")
|
index.append(" {\n},")
|
||||||
continue
|
continue
|
||||||
funcname, flags, msgname = cmd_by_id[msgid]
|
funcname, flags, msgname = cmd_by_id[msgid]
|
||||||
msg = messages_by_name[msgname]
|
msg = messages_by_name[msgname]
|
||||||
externs[funcname] = 1
|
externs[funcname] = 1
|
||||||
parsername = 'parser_%s' % (funcname,)
|
|
||||||
index.append(" &%s," % (parsername,))
|
|
||||||
parser = msgproto.MessageFormat(msgid, msg)
|
parser = msgproto.MessageFormat(msgid, msg)
|
||||||
parsercode = build_parser(parser, 1, all_param_types)
|
parsercode = build_parser(parser, 1, all_param_types)
|
||||||
parsers.append("const struct command_parser %s PROGMEM = {"
|
index.append(" {%s\n .flags=%s,\n .func=%s\n}," % (
|
||||||
" %s\n .flags=%s,\n .func=%s\n};" % (
|
parsercode, flags, funcname))
|
||||||
parsername, parsercode, flags, funcname))
|
index = "".join(index).strip()
|
||||||
index = "\n".join(index)
|
|
||||||
externs = "\n".join(["extern void "+funcname+"(uint32_t*);"
|
externs = "\n".join(["extern void "+funcname+"(uint32_t*);"
|
||||||
for funcname in sorted(externs)])
|
for funcname in sorted(externs)])
|
||||||
fmt = """
|
fmt = """
|
||||||
%s
|
%s
|
||||||
|
|
||||||
%s
|
const struct command_parser command_index[] PROGMEM = {
|
||||||
|
|
||||||
const struct command_parser * const command_index[] PROGMEM = {
|
|
||||||
%s
|
%s
|
||||||
};
|
};
|
||||||
|
|
||||||
const uint8_t command_index_size PROGMEM = ARRAY_SIZE(command_index);
|
const uint8_t command_index_size PROGMEM = ARRAY_SIZE(command_index);
|
||||||
"""
|
"""
|
||||||
return fmt % (externs, '\n'.join(parsers), index)
|
return fmt % (externs, index)
|
||||||
|
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
|
@ -135,8 +135,7 @@ def main():
|
||||||
continue
|
continue
|
||||||
m = re_asm.match(line)
|
m = re_asm.match(line)
|
||||||
if m is None:
|
if m is None:
|
||||||
if funcaddr not in datalines:
|
datalines.setdefault(funcaddr, []).append(line)
|
||||||
datalines[funcaddr] = line.split()
|
|
||||||
#print("other", repr(line))
|
#print("other", repr(line))
|
||||||
continue
|
continue
|
||||||
insn = m.group('insn')
|
insn = m.group('insn')
|
||||||
|
@ -192,14 +191,24 @@ def main():
|
||||||
funcnameroot = info.funcname.split('.')[0]
|
funcnameroot = info.funcname.split('.')[0]
|
||||||
funcsbyname[funcnameroot] = info
|
funcsbyname[funcnameroot] = info
|
||||||
cmdfunc = funcsbyname.get('sched_main')
|
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'))
|
eventfunc = funcsbyname.get('__vector_13', funcsbyname.get('__vector_17'))
|
||||||
for funcnameroot, info in funcsbyname.items():
|
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:
|
if funcnameroot.endswith('_event') and eventfunc is not None:
|
||||||
eventfunc.noteCall(0, info.funcaddr, eventfunc.basic_stack_usage + 2)
|
eventfunc.noteCall(0, info.funcaddr, eventfunc.basic_stack_usage + 2)
|
||||||
|
|
||||||
|
|
|
@ -213,14 +213,9 @@ DECL_SHUTDOWN(sendf_shutdown);
|
||||||
static const struct command_parser *
|
static const struct command_parser *
|
||||||
command_get_handler(uint8_t cmdid)
|
command_get_handler(uint8_t cmdid)
|
||||||
{
|
{
|
||||||
if (cmdid >= READP(command_index_size))
|
if (!cmdid || cmdid >= READP(command_index_size))
|
||||||
goto error;
|
shutdown("Invalid command");
|
||||||
const struct command_parser *cp = READP(command_index[cmdid]);
|
return &command_index[cmdid];
|
||||||
if (!cp)
|
|
||||||
goto error;
|
|
||||||
return cp;
|
|
||||||
error:
|
|
||||||
shutdown("Invalid command");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum { CF_NEED_SYNC=1<<0, CF_NEED_VALID=1<<1 };
|
enum { CF_NEED_SYNC=1<<0, CF_NEED_VALID=1<<1 };
|
||||||
|
|
|
@ -50,7 +50,7 @@ enum {
|
||||||
PT_uint32, PT_int32, PT_uint16, PT_int16, PT_byte,
|
PT_uint32, PT_int32, PT_uint16, PT_int16, PT_byte,
|
||||||
PT_string, PT_progmem_buffer, PT_buffer,
|
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_index_size;
|
||||||
extern const uint8_t command_identify_data[];
|
extern const uint8_t command_identify_data[];
|
||||||
extern const uint32_t command_identify_size;
|
extern const uint32_t command_identify_size;
|
||||||
|
|
Loading…
Reference in New Issue