xref: /haiku/src/system/libroot/stubbed/generate_stubs.py (revision 87e8603d9f4cecce2250564deb85bc2ef5c23bfa)
1b2883f6aSOliver Tappe#! /usr/bin/env python
2b2883f6aSOliver Tappe
3b2883f6aSOliver Tappeimport sys;
4b2883f6aSOliver Tappe
5b2883f6aSOliver TappedataSymbolsByAddress = {}
6*445257ffSOliver TappedataSymbols = []
7b2883f6aSOliver TappeversionedDataSymbolsByName = {}
8b2883f6aSOliver TappefunctionSymbolsByAddress = {}
9*445257ffSOliver TappefunctionSymbols = []
10b2883f6aSOliver TappeversionedFunctionSymbolsByName = {}
11b2883f6aSOliver Tappe
12b2883f6aSOliver Tappefor line in sys.stdin.readlines():
13b2883f6aSOliver Tappe	if line[0] != '0':
14b2883f6aSOliver Tappe		# ignore lines without an address
15b2883f6aSOliver Tappe		continue
16b2883f6aSOliver Tappe
17b2883f6aSOliver Tappe	(address, type, symbol) = line.split()
18b2883f6aSOliver Tappe
19b2883f6aSOliver Tappe	# select interesting types of symbols
20*445257ffSOliver Tappe	if type not in 'BCDGRSTuVvWw':
21b2883f6aSOliver Tappe		continue
22b2883f6aSOliver Tappe
23b2883f6aSOliver Tappe	# drop symbols from legacy compiler that contain a dot (those produce
24b2883f6aSOliver Tappe	# syntax errors)
25b2883f6aSOliver Tappe	if '.' in symbol:
26b2883f6aSOliver Tappe		continue
27b2883f6aSOliver Tappe
28b2883f6aSOliver Tappe	if type in 'BD':
29b2883f6aSOliver Tappe		if '@' in symbol:
30b2883f6aSOliver Tappe			versionedDataSymbolsByName[symbol] = address
31b2883f6aSOliver Tappe		else:
32*445257ffSOliver Tappe			if type not in 'VW':
33b2883f6aSOliver Tappe				dataSymbolsByAddress[address] = symbol
34*445257ffSOliver Tappe			dataSymbols.append(symbol)
35b2883f6aSOliver Tappe	else:
36b2883f6aSOliver Tappe		if '@' in symbol:
37b2883f6aSOliver Tappe			versionedFunctionSymbolsByName[symbol] = address
38b2883f6aSOliver Tappe		else:
39*445257ffSOliver Tappe			if type not in 'VW':
40b2883f6aSOliver Tappe				functionSymbolsByAddress[address] = symbol
41*445257ffSOliver Tappe			functionSymbols.append(symbol)
42b2883f6aSOliver Tappe
43b2883f6aSOliver Tappe# add data symbols
44*445257ffSOliver Tappefor dataSymbol in sorted(dataSymbols):
45b2883f6aSOliver Tappe	print 'int %s;' % dataSymbol
46b2883f6aSOliver Tappe
47b2883f6aSOliver Tappeprint
48b2883f6aSOliver Tappe
49b2883f6aSOliver Tappe# add function symbols
50*445257ffSOliver Tappefor functionSymbol in sorted(functionSymbols):
51b2883f6aSOliver Tappe	print 'void %s() {}' % functionSymbol
52b2883f6aSOliver Tappe
53b2883f6aSOliver Tappeprint
54b2883f6aSOliver Tappeprint "#include <symbol_versioning.h>"
55b2883f6aSOliver Tappeprint
56b2883f6aSOliver Tappe
57b2883f6aSOliver Tappe# add symbol versioning information for data symbols
58b2883f6aSOliver Tappefor symbol in sorted(versionedDataSymbolsByName.keys()):
59b2883f6aSOliver Tappe	address = versionedDataSymbolsByName[symbol]
60b2883f6aSOliver Tappe	targetSymbol = dataSymbolsByAddress[address]
61b2883f6aSOliver Tappe	(symbolName, unused, versionTag) = symbol.partition('LIBROOT_')
62b2883f6aSOliver Tappe	print 'DEFINE_LIBROOT_KERNEL_SYMBOL_VERSION("%s", "%s", "%s");'	\
63b2883f6aSOliver Tappe		% (targetSymbol, symbolName, versionTag)
64b2883f6aSOliver Tappe
65b2883f6aSOliver Tappe# add symbol versioning information for function symbols
66b2883f6aSOliver Tappefor symbol in sorted(versionedFunctionSymbolsByName.keys()):
67b2883f6aSOliver Tappe	address = versionedFunctionSymbolsByName[symbol]
68b2883f6aSOliver Tappe	targetSymbol = functionSymbolsByAddress[address]
69b2883f6aSOliver Tappe	(symbolName, unused, versionTag) = symbol.partition('LIBROOT_')
70b2883f6aSOliver Tappe	print 'DEFINE_LIBROOT_KERNEL_SYMBOL_VERSION("%s", "%s", "%s");'	\
71b2883f6aSOliver Tappe		% (targetSymbol, symbolName, versionTag)
72