MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / read_obj

Function read_obj

tools/WCS.py:51–81  ·  view source on GitHub ↗

Reads the file tu.o and gets the binding (global or local) for each function :param tu: name of the translation unit (e.g. for main.c, this would be 'main') :param call_graph: a object used to store information about each function, results go here

(tu, call_graph)

Source from the content-addressed store, hash-verified

49
50
51def read_obj(tu, call_graph):
52 """
53 Reads the file tu.o and gets the binding (global or local) for each function
54 :param tu: name of the translation unit (e.g. for main.c, this would be 'main')
55 :param call_graph: a object used to store information about each function, results go here
56 """
57 symbols = read_symbols(tu[0:tu.rindex(".")] + obj_ext)
58
59 for s in symbols:
60
61 if s.type == 'FUNC':
62 if s.binding == 'GLOBAL':
63 # Check for multiple declarations
64 if s.name in call_graph['globals'] or s.name in call_graph['locals']:
65 raise Exception('Multiple declarations of {}'.format(s.name))
66 call_graph['globals'][s.name] = {'tu': tu, 'name': s.name, 'binding': s.binding}
67 elif s.binding == 'LOCAL':
68 # Check for multiple declarations
69 if s.name in call_graph['locals'] and tu in call_graph['locals'][s.name]:
70 raise Exception('Multiple declarations of {}'.format(s.name))
71
72 if s.name not in call_graph['locals']:
73 call_graph['locals'][s.name] = {}
74
75 call_graph['locals'][s.name][tu] = {'tu': tu, 'name': s.name, 'binding': s.binding}
76 elif s.binding == 'WEAK':
77 if s.name in call_graph['weak']:
78 raise Exception('Multiple declarations of {}'.format(s.name))
79 call_graph['weak'][s.name] = {'tu': tu, 'name': s.name, 'binding': s.binding}
80 else:
81 raise Exception('Error Unknown Binding "{}" for symbol: {}'.format(s.binding, s.name))
82
83
84def find_fxn(tu, fxn, call_graph):

Callers 1

mainFunction · 0.85

Calls 1

read_symbolsFunction · 0.85

Tested by

no test coverage detected