diff --git a/find_func_def.py b/find_func_def.py new file mode 100644 index 0000000..addacd3 --- /dev/null +++ b/find_func_def.py @@ -0,0 +1,1012 @@ +import os +import sys +import shutil +import dataclasses + + + + +TOKEN_IF = 256, +TOKEN_BREAK = 257, +TOKEN_WHILE=258, +TOKEN_SWITCH=259, +TOKEN_CASE=260, +TOKEN_DO=261, +TOKEN_CHAR=262, +TOKEN_INT=263, +TOKEN_VOID=264, +TOKEN_SYMBOL = 265 , +TOKEN_NUM = 266 ,# 数字 +TOKEN_INC = 267,# 自增 +TOKEN_DEC = 268,# 自减 +TOKEN_EQ = 269,# 相等 +TOKEN_NEQ = 270,# 不相等 +TOKEN_LSH = 271,# 左移 +TOKEN_RSH = 272,# 右移 +TOKEN_LEQ = 273,# 小于等于 +TOKEN_GEQ = 274,# 大于等于 +TOKEN_ELSE = 275, +TOKEN_CONTINUE = 276 , +TOKEN_CONST = 277 , +TOKEN_STATIC = 278 , +TOKEN_UNSIGNED = 279 , +TOKEN_TYPEDEF = 280 , +TOKEN_STRUCT = 281 , +TOKEN_ENUM = 282 , +TOKEN_UNION = 283, +TOKEN_STRING = 284, +TOKEN_DEFAULT = 285, +TOKEN_RETURN = 286, +TOKEN_ASSIG_ADD = 287 +TOKEN_ASSIG_SUB = 288 +TOKEN_ASSIG_MUL = 289 +TOKEN_ASSIG_DIV = 290 +TOKEN_ASSIG_LSH = 291 +TOKEN_ASSIG_RSH = 292 +TOKEN_EXTERN = 293 +TOKEN_FLOAT = 294 +TOKEN_DOUBLE = 295 +TOKEN_SHORT = 296 +TOKEN_LONG = 297 +TOKEN_POINTER = 298 + + +def TOKEN(t:str): + return t.encode("utf-8")[0] + +_KeyWordTable={ + "if":TOKEN_IF, + "else":TOKEN_ELSE, + "break":TOKEN_BREAK, + "while":TOKEN_WHILE, + "switch":TOKEN_SWITCH, + "case":TOKEN_CASE, + "do":TOKEN_DO, + "char":TOKEN_CHAR, + "int":TOKEN_INT, + "void":TOKEN_VOID, + "continue":TOKEN_CONTINUE, + "const":TOKEN_CONST, + "static":TOKEN_STATIC, + "unisgned":TOKEN_UNSIGNED, + "typedef":TOKEN_TYPEDEF, + "struct":TOKEN_STRUCT, + "enum":TOKEN_ENUM, + "union":TOKEN_UNION, + "default":TOKEN_DEFAULT, + "return":TOKEN_RETURN, + "extern":TOKEN_EXTERN, + "float":TOKEN_FLOAT, + "double":TOKEN_DOUBLE, + "short":TOKEN_SHORT, + "long":TOKEN_LONG, +} + +_MarkTable={ + "<<":TOKEN_LSH, + ">>":TOKEN_RSH, + "<=":TOKEN_LEQ, + ">=":TOKEN_GEQ, + "!=":TOKEN_NEQ, + "==":TOKEN_EQ, + "++":TOKEN_INC, + "--":TOKEN_DEC, + "->":TOKEN_POINTER, + "+=":TOKEN_ASSIG_ADD, + "-=":TOKEN_ASSIG_SUB, + "*=":TOKEN_ASSIG_MUL, + "<<=":TOKEN_ASSIG_LSH, + ">>=":TOKEN_ASSIG_RSH, + "=":TOKEN("="), + "!":TOKEN("!"), + "<":TOKEN("<"), + ">":TOKEN(">"), + "+":TOKEN("+"), + "-":TOKEN("-"), + +} + + + +# 是否是数字加字母 +def isalnum(num:int): + return bytes([num]).isalnum() + +# 是否是数字加字母或下划线 +def isalnum_(num:int): + return bytes([num]).isalnum() or num==TOKEN("_") + +# 是否是字母 +def isalpha(num:int): + return bytes([num]).isalpha() + +# 是否是字母或下划线 +def isalpha_(num:int): + return bytes([num]).isalpha() or num==TOKEN("_") + +# 是否是数字 +def isdigit(num:int): + return bytes([num]).isdigit() + +# 是否是数字或小数点 +def isdigitdot(num:int): + return bytes([num]).isdigit() or num==TOKEN(".") + +# 是否是空白字符 包括换行符 +def isspace(num:int): + return bytes([num]).isspace() + +# 是否是给定字符串之一 +def isinstr(num:int,t:str): + c=bytes([num]) + return c in t.encode("utf-8") + +# 是否是操作符 +def isoperator(num:int): + return isinstr(num,"<>!+-=") + +@dataclasses.dataclass +class lex_token: + name:str + buff:bytearray + token:int + line:int + pos:int + + +class lex_class(object): + def __init__(self,text:bytes) -> None: + self.text=text + self.index=-1 + self.line=1 + self.pos=-1 + self.token_list:list[lex_token]=[] + self.token_buff=bytearray() + def save_char(self,c:int): + self.token_buff.append(c&0xff) + def save_token(self,token:lex_token): + self.token_list.append(token) + self.token_buff=bytearray() + def _get_char(self): + if(self.index=len(self.text) + def save_one_char_token(self,c:int): + token=lex_token(bytes([c]).decode("utf-8"),bytes([c]),c,self.line,self.pos) + self.save_token(token) + def read_name_and_save(self,c:int): + token=lex_token("symbol",bytearray(),TOKEN_SYMBOL,self.line,self.pos) + self.save_char(c) + while True: + c=self.get_next_char() + if(isalnum_(c)): + self.save_char(c) + else: + break + name=self.token_buff.decode("utf-8") + if(name in _KeyWordTable): + token.token=_KeyWordTable[name] + token.name=name + token.buff=self.token_buff + self.save_token(token) + return c + def read_operator_and_save(self,c:int): + token=lex_token("operator",bytearray(),TOKEN_SYMBOL,self.line,self.pos) + self.save_char(c) + while True: + c=self.get_next_char() + if(isoperator(c)): + self.save_char(c) + else: + break + name=self.token_buff.decode("utf-8") + if(name in _MarkTable): + token.token=_MarkTable[name] + token.name=name + token.buff=self.token_buff + self.save_token(token) + else: + # raise Exception(f"不存在的操作符 {name} ") + print(f"不存在的操作符 {name} ") + return c + def read_num_and_save(self,c:int): + token=lex_token("number",bytearray(),TOKEN_NUM,self.line,self.pos) + self.save_char(c) + while True: + c=self.get_next_char() + if(isdigitdot(c)): + self.save_char(c) + else: + break + if(self.token_buff.count(b'.')>1): + raise Exception("数字不能包含多个点号") + token.buff=self.token_buff + self.save_token(token) + return c + _escape_table={'0':0,'a':7,'b':8,'t':9,'n':10,'v':11,'f':12,'r':13,'"':34,'\'':39,'?':63,'\\':92} + def read_str_and_save(self,c:int): + c=self.get_next_char() + while c!=b'\"'[0]: + if(c==TOKEN('\\')):# \ + c=self.get_next_char() + s=str(bytearray([c]),encoding='utf-8') + # if(c in self._escape_table.keys()): + self.save_char(self._escape_table.get(c,0)) + else: + self.save_char(c) + c=self.get_next_char() + self.save_token(lex_token("string",self.token_buff,TOKEN_STRING,self.line,self.pos)) + return self.get_next_char() + def read_char_and_save(self,c:int): + c=self.get_next_char() + while c!=b'\''[0]: + if(c==TOKEN('\\')):# \ + c=self.get_next_char() + s=str(bytearray([c]),encoding='utf-8') + # if(c in self._escape_table.keys()): + self.save_char(self._escape_table.get(c,0)) + else: + self.save_char(c) + c=self.get_next_char() + self.save_token(lex_token("string",self.token_buff,TOKEN_STRING,self.line,self.pos)) + return self.get_next_char() + +def lex(text:bytes): + lex_obj = lex_class(text) + c=lex_obj.get_next_char() + line_old=0 + pos_old=0 + while not lex_obj.is_end(): + line_old=lex_obj.line + pos_old=lex_obj.pos + if isalpha_(c): + c=lex_obj.read_name_and_save(c) + elif isinstr(c,"{}[]()~,;:*"): + lex_obj.save_one_char_token(c) + c=lex_obj.get_next_char() + elif isdigit(c): + c=lex_obj.read_num_and_save(c) + elif isspace(c): + c=lex_obj.get_next_char() + elif isoperator(c): + c=lex_obj.read_operator_and_save(c) + elif isinstr(c,"\""): + c=lex_obj.read_str_and_save(c) + elif isinstr(c,"\'"): + c=lex_obj.read_char_and_save(c) + elif isinstr(c,"\\"): + c=lex_obj.get_next_char() + if(c!=TOKEN("\r") and c!=TOKEN("\n")): + raise Exception(f"符号 '\\' 必须在行末, line:{lex_obj.line} pos:{lex_obj.pos}") + elif isinstr(c,"#"): # 宏定义 + c_old=c + while (c!=TOKEN("\n") and c!=-1): + c=lex_obj.get_next_char() + if(c_old==TOKEN('/') and c==TOKEN('*')):# 适配宏后面有注释的情况 + while not (c_old==TOKEN("*") and c==TOKEN("/")): + c_old=c + c=lex_obj.get_next_char() + if(c_old==TOKEN('\\') and c==TOKEN('\n')):# 适配多行 + c=lex_obj.get_next_char() + c_old=c + elif isinstr(c,"/"): + c=lex_obj.get_next_char() + if(c==TOKEN("/")): + while (c!=TOKEN("\n") and c!=-1): + c=lex_obj.get_next_char() + elif(c==TOKEN("*")): + c_old=lex_obj.get_next_char() + c=lex_obj.get_next_char() + while not (c_old==TOKEN("*") and c==TOKEN("/")): + c_old=c + c=lex_obj.get_next_char() + c=lex_obj.get_next_char() + elif(c==TOKEN("=")): + lex_obj.save_token(lex_token("/=",b"/=",TOKEN_ASSIG_DIV,lex_obj.line,lex_obj.pos)) + c=lex_obj.get_next_char() + else: + lex_obj.save_one_char_token(TOKEN("/")) + else: + # raise Exception(f"未知的字符 {bytes([c])}, line:{lex_obj.line} pos:{lex_obj.pos}") + c=lex_obj.get_next_char() + # if(line_old==lex_obj.line and pos_old==lex_obj.pos): + # print(f"pointer not move.") + # print(line_old,pos_old) + # for item in lex_obj.token_list: + # print(f"{item}") + return lex_obj.token_list + + + +@dataclasses.dataclass +class node: + name:list=dataclasses.field(default_factory=list) + type:str="base" + token_list:list=dataclasses.field(default_factory=list) + child:list=dataclasses.field(default_factory=list) + def complite(self): + print(f"complite {self.type}") +# 文件节点 +@dataclasses.dataclass +class node_file(node): + type:str="file" +# 变量定义节点 +@dataclasses.dataclass +class node_variable_def(node): + type:str="variable_def" + +# 结构体声明节点 +@dataclasses.dataclass +class node_struct_decl(node): + type:str="struct_decl" + +# 结构体定义节点 +@dataclasses.dataclass +class node_struct_def(node): + type:str="struct_def" + +# 联合体声明节点 +@dataclasses.dataclass +class node_union_decl(node): + type:str="union_decl" + +# 联合体定义节点 +@dataclasses.dataclass +class node_union_def(node): + type:str="union_def" + +# 枚举声明节点 +@dataclasses.dataclass +class node_enum_decl(node): + type:str="enum_decl" + +# 枚举定义节点 +@dataclasses.dataclass +class node_enum_def(node): + type:str="enum_def" + +# 函数声明节点 +@dataclasses.dataclass +class node_func_decl(node): + type:str="func_decl" + +#typedef 节点 +@dataclasses.dataclass +class node_typedef(node): + type:str="typedef" + +# 函数定义节点 +@dataclasses.dataclass +class node_func_def(node): + type:str="func_def" + +# switch节点 +@dataclasses.dataclass +class node_switch(node): + type:str="switch" + +# case节点 +@dataclasses.dataclass +class node_case(node): + type:str="case" + +# default +@dataclasses.dataclass +class node_default(node): + type:str="default" + +# break节点 +@dataclasses.dataclass +class node_break(node): + type:str="break" + +# return节点 +@dataclasses.dataclass +class node_return(node): + type:str="return" + +# 函数调用节点 +@dataclasses.dataclass +class node_call(node): + type:str="call" + +# 变量操作节点 +@dataclasses.dataclass +class node_opt(node): + type:str="opt_var" + +# 符号节点 +@dataclasses.dataclass +class node_symbol(node): + type:str="symbol" + +# string节点 +@dataclasses.dataclass +class node_string(node): + type:str="string" + +# int节点 +@dataclasses.dataclass +class node_int(node): + type:str="int" + + + +# 找到闭合的括号 +def find_close(token_list:list,token:tuple): + if token_list[0].token!=token[0]: + return 0 + num=0 + for index,item in enumerate(token_list): + if(item.token==token[0]): + num+=1 + elif(item.token==token[1]): + num-=1 + if(num==0): + return index + raise Exception(f"没有找到闭合的符号 {token_list[0]} {token[1]}") + +# 找到指定token的index +def find_token(token_list:list,token:int): + num=0 + for index,item in enumerate(token_list): + if(item.token!=token): + num+=1 + else: + return num + return num + + +# 找到一个完整的语句 +def find_sentence(token_list:list,sep:list=[TOKEN(";"),TOKEN(":")]): + bracket_flag=False + index=0 + if(len(token_list)==1): + return token_list + while index0): + bracket_flag=True + index+=bracket_index + elif(token_list[index].token==TOKEN("{")): + bracket_index=find_close(token_list[index:],(TOKEN("{"),TOKEN("}"))) + if(bracket_index>0): + index+=bracket_index + if(bracket_flag==True): + return token_list[:index+1] + elif(token_list[index].token in sep): + return token_list[:index+1] + index+=1 + raise Exception(f"没有找到完整的语句 sep={sep} token={token_list[0]}") + + + + + + + + + + + + + +def dist_node_type_struct(token_list:list): + if(token_list[0].token==TOKEN_STRUCT): + if(token_list[1].token==TOKEN_SYMBOL): + if(len(token_list)==2): + return node_struct_decl(name=token_list[1].buff.decode("utf-8"),token_list=token_list,child=[]) + elif(token_list[2].token==TOKEN("{")): + # if not token_list[-1].token==TOKEN("}"): + # raise Exception("没有出现预期的符号 '}'") + # v_list:list[node_variable_def]=[] + # token_list_local=token_list[3:-1] + # while len(token_list_local)>0: + # sentence=find_sentence(token_list_local) + # v_list.append(dist_node_type(token_list=sentence)) + # token_list_local=token_list_local[len(sentence):] + return node_struct_def(name=token_list[1].buff.decode("utf-8"),token_list=token_list,child=[]) + else: + return node_struct_decl(name=token_list[1].buff.decode("utf-8"),token_list=token_list,child=[]) + if(find_token(token_list,TOKEN('('))0: + # sentence=find_sentence(token_list_local) + # v_list.append(dist_node_type(token_list=sentence)) + # token_list_local=token_list_local[len(sentence):] + return node_union_def(name=token_list[1].buff.decode("utf-8"),token_list=token_list,child=[]) + if(find_token(token_list,TOKEN('('))1): + # raise Exception(f"意外的token {token_list[0]}") + return node_typedef(name=name,token_list=token_list_local,child=[]) + raise Exception(f"语法错误 {token_list[0]}") + + + +# 找到子节点 +def find_child(token_list:list,seq:list=[TOKEN(";"),TOKEN(":")]): + child=[] + for i in range(len(token_list)): + if(token_list[i].token==TOKEN("{")): + token_list_local=token_list[i+1:-1] + break + while len(token_list_local)>0: + sentence=find_sentence(token_list_local,seq) + node_d=dist_node_type(sentence) + child.append(node_d) + token_list_local=token_list_local[len(sentence):] + return child + + +def dist_node_type_funcdef(token_list:list): + for i in range(len(token_list)): + if(token_list[i].token==TOKEN('(')): + name=token_list[i-1].buff.decode("utf-8") + break + # return node_func_def(name=[name],token_list=token_list,child=find_child(token_list)) + return node_func_def(name=[name],token_list=token_list,child=[]) + +def dist_node_type_funcdecl(token_list:list): + for i in range(len(token_list)): + if(token_list[i].token==TOKEN_SYMBOL): + name=token_list[i].buff.decode("utf-8") + return node_func_decl(name=[name],token_list=token_list,child=[]) + raise Exception(f"函数声明格式错误 {token_list[0]}") + + +# 第一个token是symbol的处理 +def dist_node_type_symbol(token_list:list): + # 变量赋值或函数调用 + if(len(token_list)==1): + return node_symbol(name=token_list[0].buff.decode("utf-8"),token_list=token_list) + if(token_list[1].token == TOKEN("(")): + child=find_child(token_list=token_list[2:-1]) + return node_call("call",token_list=token_list,child=child) + elif(token_list[1].token in [ + TOKEN("="),TOKEN_ASSIG_ADD,TOKEN_ASSIG_DIV,TOKEN_ASSIG_LSH, + TOKEN_ASSIG_MUL,TOKEN_ASSIG_RSH,TOKEN_ASSIG_SUB]): + name=token_list[1].name + child=[node_symbol(name=token_list[0].buff.decode("utf-8"),token_list=token_list[:1]), + dist_node_type(token_list=token_list[2:])] + return node_opt(name=name,token_list=token_list,child=child) + else: + # 没有赋值属性的操作 + name=token_list[1].name + return node_opt(name=name,token_list=token_list,child=[]) + + + + + + + + + + + + + + +# 判断一个语句的类型 +def dist_node_type(token_list:list): + if(token_list[0].token==TOKEN_EXTERN): + token_list=token_list[1:] + if(token_list[-1].token==TOKEN(";")): + token_list=token_list[:-1] + if(token_list[0].token==TOKEN_STRUCT): + return dist_node_type_struct(token_list=token_list) + if(token_list[0].token==TOKEN_UNION): + return dist_node_type_union(token_list=token_list) + if(token_list[0].token==TOKEN_ENUM): + return dist_node_type_enum(token_list=token_list) + if(token_list[0].token==TOKEN_TYPEDEF): + return dist_node_type_typedef(token_list=token_list) + # if(token_list[0].token==TOKEN_SWITCH): + # child=find_child(token_list) + # return node_switch(name="",token_list=token_list,child=child) + # if(token_list[0].token==TOKEN_CASE): + # name=token_list[1].buff.decode("utf-8") + # return node_case(name=name,token_list=token_list,child=[]) + # if(token_list[0].token==TOKEN_DEFAULT): + # return node_default(name="",token_list=token_list,child=[]) + # if(token_list[0].token==TOKEN_BREAK): + # return node_break(name="",token_list=token_list,child=[]) + # if(token_list[0].token==TOKEN_RETURN): + # if(len(token_list)>1): + # child=[dist_node_type(token_list[1:])] + # else: + # child=[] + # return node_return(name="",token_list=token_list,child=child) + if(token_list[0].token==TOKEN_STRING): + name=token_list[0].buff.decode("utf-8") + return node_string(name=name,token_list=token_list,child=[]) + if(token_list[0].token==TOKEN_NUM): + name=token_list[0].buff.decode("utf-8") + return node_int(name=name,token_list=token_list,child=[]) + + if(token_list[-1].token==TOKEN(")")): + # 函数声明 + return dist_node_type_funcdecl(token_list) + elif(token_list[-1].token==TOKEN("}")): + if(find_token(token_list,TOKEN('('))0: + for item in n.child: + print_node(item,deep+1) + +def find_func_def_in_file(n:node,deep:int,func_name_list:list): + ack=False + if(n.type=='func_def') and (n.name[0] in func_name_list): + print(f"{n.type} {n.name}") + return True + # n.complite() + if (not n.child is None) and len(n.child)>0: + for item in n.child: + ack=find_func_def_in_file(item,deep+1,func_name_list) + if(ack): + return ack + return False + +def check_func_def(file_name:str,func_name_list:list): + with open(file_name,mode='rb') as f: + # print("start read") + token_list=lex(f.read()) + # print("end read") + file=node_file(name=file_name,token_list=token_list) + while len(token_list)>0: + sentence=find_sentence(token_list) + node_d=dist_node_type(sentence) + file.child.append(node_d) + # print('找到一个语句:') + # for item in sentence: + # print(f"\t{item}") + token_list=token_list[len(sentence):] + # print_node(file,0) + return find_func_def_in_file(file,0,func_name_list) + + +# 找到定义函数的文件 +def find_func_def(file_list:list,func_name_list:str): + ret_list=[] + err_list=[] + for item in file_list: + print(f"check {item}") + try: + ack=check_func_def(item,func_name_list) + if(ack): + ret_list.append(item) + except Exception as e: + print(e) + err_list.append(item) + return ret_list,err_list + +# 找到指定后缀的文件 +def find_type(path:str,fix:str): + dlist=os.listdir(path) + file_list=[] + for i in dlist: + ps=os.path.join(path, i) + if os.path.isdir(ps): + file_list+=find_type(ps,fix) + pass + else: + if(ps[-len(fix):]==fix): + file_list.append(ps) + return file_list + + + + + +_out_text=''' +.output/plc/sbl/obj/src/common.o: In function `do_help': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:243: undefined reference to `os_mem_cmp' +.output/plc/sbl/obj/src/common.o: In function `find_cmd': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:243: undefined reference to `iot_strcmp' +.output/plc/sbl/obj/src/common.o: In function `sbl_param_generate': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:243: undefined reference to `iot_strlen' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:243: undefined reference to `os_mem_set' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:243: undefined reference to `os_mem_cpy' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:243: undefined reference to `iot_strlen' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:243: undefined reference to `os_mem_cpy' +.output/plc/sbl/obj/src/common.o: In function `sbl_param_get_value': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:243: undefined reference to `iot_strlen' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:243: undefined reference to `os_mem_cmp' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:243: undefined reference to `iot_strlen' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:243: undefined reference to `os_mem_cpy' +.output/plc/sbl/obj/src/common.o: In function `sbl_param_set_value': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:255: undefined reference to `iot_strlen' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:257: undefined reference to `os_mem_cmp' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:252: undefined reference to `iot_strlen' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:259: undefined reference to `os_mem_cpy' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:264: undefined reference to `os_mem_cpy' +.output/plc/sbl/obj/src/common.o: In function `sbl_param_load': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:493: undefined reference to `flash_get_dev_base' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:490: undefined reference to `iot_layout_get_part_offset' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:285: undefined reference to `os_mem_cpy' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:287: undefined reference to `os_mem_set' +.output/plc/sbl/obj/src/common.o: In function `sbl_param_save_list': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:300: undefined reference to `iot_layout_get_part_offset' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:309: undefined reference to `flash_write' +.output/plc/sbl/obj/src/common.o: In function `sbl_mem_display': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:346: undefined reference to `os_mem_set' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:382: undefined reference to `os_mem_set' +.output/plc/sbl/obj/src/common.o: In function `do_print': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:599: undefined reference to `iot_layout_get_index' +.output/plc/sbl/obj/src/common.o: In function `run_boot_delay': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:780: undefined reference to `iot_strlen' +.output/plc/sbl/obj/src/common.o: In function `sbl_main_loop': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1020: undefined reference to `iot_strlen' +.output/plc/sbl/obj/src/common.o: In function `readline': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:835: undefined reference to `iot_strcpy' +.output/plc/sbl/obj/src/common.o: In function `sbl_main_loop': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1024: undefined reference to `iot_strlen' +.output/plc/sbl/obj/src/common.o: In function `readline': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:860: undefined reference to `iot_strcpy' +.output/plc/sbl/obj/src/common.o: In function `run_command': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:983: undefined reference to `os_mem_cpy' +.output/plc/sbl/obj/src/common.o: In function `sbl_get_start_part': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1067: undefined reference to `os_mem_cpy' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1075: undefined reference to `os_mem_cpy' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1086: undefined reference to `os_mem_cpy' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1093: undefined reference to `os_mem_cpy' +.output/plc/sbl/obj/src/common.o:/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1103: more undefined references to `os_mem_cpy' follow +.output/plc/sbl/obj/src/common.o: In function `sbl_get_start_part': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1112: undefined reference to `os_mem_cmp' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1118: undefined reference to `os_mem_cpy' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1144: undefined reference to `os_mem_cpy' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1149: undefined reference to `os_mem_cpy' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1154: undefined reference to `os_mem_cpy' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1163: undefined reference to `os_mem_cpy' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1167: undefined reference to `os_mem_cmp' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1168: undefined reference to `os_mem_cmp' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1170: undefined reference to `os_mem_cmp' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1174: undefined reference to `os_mem_cpy' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1183: undefined reference to `os_mem_cpy' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1202: undefined reference to `os_mem_cpy' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1202: undefined reference to `os_mem_cmp' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1224: undefined reference to `os_mem_cmp' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1123: undefined reference to `os_mem_cmp' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1126: undefined reference to `os_mem_cpy' +.output/plc/sbl/obj/src/common.o: In function `parse_param': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1229: undefined reference to `os_mem_cmp' +.output/plc/sbl/obj/src/common.o: In function `do_bootm': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:1248: undefined reference to `os_mem_cmp' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:676: undefined reference to `os_mem_cmp' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/common.c:683: undefined reference to `os_mem_cmp' +.output/plc/sbl/obj/src/boot.o: In function `display_banner': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/boot.c:41: undefined reference to `flash_get_dev_size' +.output/plc/sbl/obj/src/boot.o: In function `start_boot': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/boot.c:52: undefined reference to `iot_layout_init_index' +.output/plc/sbl/obj/src/sbl_printf.o: In function `sbl_uart_printf': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/sbl_printf.c:40: undefined reference to `uart_e_ctrl' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/sbl_printf.c:40: undefined reference to `uart_e_ctrl' +.output/plc/sbl/obj/src/sbl_printf.o: In function `sbl_fifo_flush': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/sbl_printf.c:33: undefined reference to `uart_e_ctrl' +.output/plc/sbl/obj/src/sbl_printf.o: In function `getc': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/sbl_printf.c:61: undefined reference to `uart_e_ctrl' +.output/plc/sbl/obj/src/hw4/sbl_boot.o: In function `sbl_boot_hw_init': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:106: undefined reference to `efuse_init' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:107: undefined reference to `efuse_get_ft_pass_flag' +.output/plc/sbl/obj/src/hw4/sbl_boot.o: In function `sbl_calib_code_load': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:70: undefined reference to `efuse_get_d_bg_vbg_cntl' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:71: undefined reference to `efuse_get_d_bg_iccal' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:72: undefined reference to `efuse_get_dcdc_trim' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:73: undefined reference to `efuse_get_flash_ldo_out_trim' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:74: undefined reference to `efuse_get_d_mdll_ldo_vref_trim' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:78: undefined reference to `ana_vbg_trim_code_set' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:79: undefined reference to `ana_iccal_trim_code_set' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:82: undefined reference to `ana_dcdc_vref_code_set' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:91: undefined reference to `ana_mdll_ldo_trim_code_set' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:94: undefined reference to `ana_ldo_trim_code_set' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:98: undefined reference to `ahb_emc_disable' +.output/plc/sbl/obj/src/hw4/sbl_boot.o: In function `sbl_boot_hw_init': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:110: undefined reference to `ahb_emc_enable' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:111: undefined reference to `clk_system_clock_tree_config' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:114: undefined reference to `flash_init' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:119: undefined reference to `ahb_cache_disable' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:130: undefined reference to `ahb_cache_enable' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:131: undefined reference to `ahb_cache_fill_valid_space' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:132: undefined reference to `ahb_cache_enable' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:138: undefined reference to `ahb_cache_set_buffer_mode' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:139: undefined reference to `ahb_cache_disable' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:143: undefined reference to `ahb_cache_enable' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:144: undefined reference to `ahb_cache_fill_valid_space' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:145: undefined reference to `ahb_cache_enable' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:151: undefined reference to `ahb_cache_set_buffer_mode' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:152: undefined reference to `ahb_cache_enable' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:156: undefined reference to `ahb_cache_set_buffer_mode' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:160: undefined reference to `ana_dcdc_vref_code_set' +.output/plc/sbl/obj/src/hw4/sbl_boot.o: In function `sbl_calib_code_load': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:86: undefined reference to `ana_dcdc_vref_code_set' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:86: undefined reference to `apb_wdg_enable' +.output/plc/sbl/obj/src/hw4/sbl_boot.o: In function `sbl_wdg_ena': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:171: undefined reference to `wdg_set_cmp' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:172: undefined reference to `wdg_set_timeout_cmp' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:178: undefined reference to `wdg_set_cpurst_cmp' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:179: undefined reference to `wdg_set_fullrst_cmp' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:179: undefined reference to `wdg_cnt_enable' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:181: undefined reference to `wdg_enable' +.output/plc/sbl/obj/src/hw4/sbl_boot.o: In function `sbl_wdg_disable': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:183: undefined reference to `wdg_cnt_disable' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:194: undefined reference to `wdg_disable' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:195: undefined reference to `wdg_cnt_disable' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:197: undefined reference to `wdg_disable' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:198: undefined reference to `wdg_cnt_disable' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:200: undefined reference to `wdg_disable' +.output/plc/sbl/obj/src/hw4/sbl_boot.o: In function `sbl_scratch_reg_set': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:210: undefined reference to `scratch_p_set_wdg_reset' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:211: undefined reference to `scratch_p_set_wdg_reset' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:212: undefined reference to `scratch_p_get_wdg_reset' +.output/plc/sbl/obj/src/hw4/sbl_boot.o: In function `sbl_check_reset_by_wdg': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:225: undefined reference to `scratch_p_get_wdg_reset' +.output/plc/sbl/obj/src/hw4/sbl_boot.o: In function `get_fw_addr_info': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:339: undefined reference to `iot_layout_get_part_offset' +.output/plc/sbl/obj/src/hw4/sbl_boot.o: In function `image_check': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:293: undefined reference to `ahb_cache_clear' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:294: undefined reference to `os_mem_cpy' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:306: undefined reference to `iot_getcrc32' +.output/plc/sbl/obj/src/hw4/sbl_boot.o: In function `get_fw_addr_info': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:383: undefined reference to `iot_layout_get_part_offset' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:349: undefined reference to `iot_layout_get_part_offset' +.output/plc/sbl/obj/src/hw4/sbl_boot.o: In function `sbl_load_next_firmware': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:448: undefined reference to `iot_layout_get_part_offset' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:476: undefined reference to `iot_layout_get_part_offset' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:478: undefined reference to `iot_layout_get_part_offset' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:479: undefined reference to `iot_layout_get_part_size' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:480: undefined reference to `flash_addr_mapping' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:483: undefined reference to `os_mem_cmp' +.output/plc/sbl/obj/src/hw4/sbl_boot.o: In function `sbl_decompress_image': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:414: undefined reference to `iot_getcrc32' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/src/hw4/sbl_boot.c:421: undefined reference to `system_set_fw_boot_param' +.output/plc/sbl/obj/lzma/LzmaTools.o: In function `outputCallback': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/lzma/LzmaTools.c:113: undefined reference to `ahb_cache_space_dis_for_flash_write' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/lzma/LzmaTools.c:127: undefined reference to `flash_write' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/lzma/LzmaTools.c:127: undefined reference to `ahb_cache_space_ena_for_flash_write' +.output/plc/sbl/obj/lzma/LzmaTools.o: In function `flash_erase_blocks': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/lzma/LzmaTools.c:73: undefined reference to `ahb_cache_space_dis_for_flash_write' +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/lzma/LzmaTools.c:77: undefined reference to `ahb_cache_space_ena_for_flash_write' +.output/plc/sbl/obj/lzma/LzmaTools.o: In function `Decode2': +/home/ran.chuan@htzd.com/work/kunlun/iotelic/kunlun/Mainline/sbl/lzma/LzmaTools.c:184: undefined reference to `flash_erase' + +'''.split('\n') + + + + + + + +# 参数是扫描的目录列表 +if __name__=="__main__": + file_list=[] + for item in sys.argv[1:]: + file_list+=find_type(item,'.c') + func_list=[] + for item in _out_text: + key_str='undefined reference to `' + index=item.find(key_str) + if(index<0): + continue + index+=len(key_str) + func=item[index:-1] + if not (func in func_list): + func_list.append(func) + print(func_list) + # find_func_def(['driver/src/hw3/efuse.c'],['efuse_get_d_bg_vbg_cntl']) + ret_list,err_list=find_func_def(file_list,func_list) + print("已找到的文件") + for item in ret_list: + print(item) + print("分析失败的文件") + for item in err_list: + print(item) \ No newline at end of file