mirror of https://github.com/Desuuuu/klipper.git
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):
|
||||
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)
|
||||
|
||||
|
||||
######################################################################
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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:
|
||||
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 };
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue