Subversion Repositories Kolibri OS

Rev

Rev 8825 | Rev 8835 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8825 Rev 8834
Line -... Line 1...
-
 
1
import re
1
import os
2
import os
2
from glob import glob
-
 
3
 
-
 
4
"""
-
 
5
# Collect all .inc files
-
 
6
kernel_files = [y for x in os.walk(".") for y in glob(os.path.join(x[0], '*.inc'))]
-
 
7
 
-
 
8
to_remove = []
-
 
9
for i in range(len(kernel_files)):
-
 
10
	inc = kernel_files[i]
-
 
11
	# Remove files that aren't a part of the kernel
-
 
12
	if "bootloader" in inc or "sec_loader" in inc:
-
 
13
		to_remove.append(i)
-
 
14
 
-
 
15
for i in range(len(to_remove) - 1, -1, -1):
-
 
16
	kernel_files.pop(to_remove[i])
-
 
17
 
-
 
18
# Add main kernel file
-
 
19
kernel_files.append("kernel.asm")
-
 
20
 
-
 
21
# Add main kernel file
-
 
22
# TODO: Rename the file so it won't be an exception
-
 
23
kernel_files.append("fs/xfs.asm")
-
 
24
"""
-
 
Line 25... Line 3...
25
 
3
 
-
 
4
# Parameters
-
 
5
doxygen_src_path = 'docs/doxygen'
-
 
6
link_root = "http://websvn.kolibrios.org/filedetails.php?repname=Kolibri+OS&path=/kernel/trunk"
-
 
7
clean_generated_stuff = True # Remove generated doxygen files if True
-
 
8
dump_symbols = False
Line 26... Line 9...
26
import re
9
print_stats = False
27
 
10
 
28
# kernel_structure["filename"] = {
11
# kernel_structure["filename"] = {
29
#   [ [],    # [0] Variables - [ line, name ]
12
#   [ [],    # [0] Variables - [ line, name ]
Line 61... Line 44...
61
			continue
44
			continue
Line 62... Line 45...
62
 
45
 
63
		match = macro_pattern.findall(line)
46
		match = macro_pattern.findall(line)
64
		if len(match) > 0:
47
		if len(match) > 0:
65
			macro_name = match[0]
-
 
66
			#print(f"Macro '{macro_name}' at {line_idx + 1}")
48
			macro_name = match[0]
67
			kernel_structure[asm_file_name][MACROS].append([ line_idx + 1, macro_name ])
49
			kernel_structure[asm_file_name][MACROS].append([ line_idx + 1, macro_name ])
68
			end_of_macro = False
50
			end_of_macro = False
69
			while not end_of_macro:
51
			while not end_of_macro:
70
				line = lines[line_idx]
52
				line = lines[line_idx]
Line 77... Line 59...
77
			continue
59
			continue
Line 78... Line 60...
78
 
60
 
79
		match = proc_pattern.findall(line)
61
		match = proc_pattern.findall(line)
80
		if len(match) > 0:
62
		if len(match) > 0:
81
			proc_name = match[0]
-
 
82
			#print(f"Procedure '{proc_name}' at {line_idx + 1}")
63
			proc_name = match[0]
83
			kernel_structure[asm_file_name][PROCEDURES].append([ line_idx + 1, proc_name ])
64
			kernel_structure[asm_file_name][PROCEDURES].append([ line_idx + 1, proc_name ])
84
			line_idx += 1
65
			line_idx += 1
Line 85... Line 66...
85
			continue
66
			continue
86
 
67
 
87
		match = label_pattern.findall(line)
68
		match = label_pattern.findall(line)
88
		if len(match) > 0:
69
		if len(match) > 0:
89
			label_name = match[0]
70
			label_name = match[0]
90
			# Don't count local labels
-
 
91
			if label_name[0] != '.':
71
			# Don't count local labels
92
				#print(f"Label '{label_name}' at {line_idx + 1}")
72
			if label_name[0] != '.':
93
				kernel_structure[asm_file_name][LABELS].append([ line_idx + 1, label_name ])
73
				kernel_structure[asm_file_name][LABELS].append([ line_idx + 1, label_name ])
Line 94... Line 74...
94
				line_idx += 1
74
				line_idx += 1
95
				continue
75
				continue
96
 
76
 
97
		match = struct_pattern.findall(line)
-
 
98
		if len(match) > 0:
77
		match = struct_pattern.findall(line)
99
			struct_name = match[0]
78
		if len(match) > 0:
100
			#print(f"Structure '{struct_name}' at {line_idx + 1}")
79
			struct_name = match[0]
101
			kernel_structure[asm_file_name][STRUCTURES].append([ line_idx + 1, struct_name ])
80
			kernel_structure[asm_file_name][STRUCTURES].append([ line_idx + 1, struct_name ])
102
			end_of_struct = False
81
			end_of_struct = False
Line 107... Line 86...
107
				line_idx += 1
86
				line_idx += 1
108
			continue
87
			continue
Line 109... Line 88...
109
 
88
 
Line 110... Line 89...
110
		line_idx += 1
89
		line_idx += 1
111
 
90
 
112
def get_includes(handled_files, asm_file_name, subdir = "."):
91
def handle_file(handled_files, asm_file_name, subdir = "."):
113
	print(f"Handling {asm_file_name}")
92
	print(f"Handling {asm_file_name}")
114
	handled_files.append(asm_file_name)
93
	handled_files.append(asm_file_name)
115
	try:
94
	try:
Line 124... Line 103...
124
	for include in includes:
103
	for include in includes:
125
		include = include.replace('\\', '/');
104
		include = include.replace('\\', '/');
126
		full_path = subdir + '/' + include;
105
		full_path = subdir + '/' + include;
127
		if full_path not in handled_files:
106
		if full_path not in handled_files:
128
			new_subdir = full_path.rsplit('/', 1)[0]
107
			new_subdir = full_path.rsplit('/', 1)[0]
129
			get_includes(handled_files, full_path, new_subdir)
108
			handle_file(handled_files, full_path, new_subdir)
130
	return handled_files
109
	return handled_files
Line 131... Line 110...
131
 
110
 
Line 132... Line 111...
132
kernel_files = []
111
kernel_files = []
Line -... Line 112...
-
 
112
 
133
 
113
handle_file(kernel_files, "./kernel.asm");
134
get_includes(kernel_files, "./kernel.asm");
114
 
135
 
115
if dump_symbols:
136
for source in kernel_structure:
116
	for source in kernel_structure:
137
	print(f"File: {source}")
117
		print(f"File: {source}")
Line 154... Line 134...
154
	if len(kernel_structure[source][STRUCTURES]) > 0:
134
		if len(kernel_structure[source][STRUCTURES]) > 0:
155
		print(" Structures:")
135
			print(" Structures:")
156
		for struct in kernel_structure[source][STRUCTURES]:
136
			for struct in kernel_structure[source][STRUCTURES]:
157
			print(f"  {struct[0]}: {struct[1]}")
137
				print(f"  {struct[0]}: {struct[1]}")
Line -... Line 138...
-
 
138
 
158
 
139
if print_stats:
159
# Collect stats
140
	# Collect stats
160
var_count = 0
141
	var_count = 0
161
proc_count = 0
142
	proc_count = 0
162
label_count = 0
143
	label_count = 0
Line 174... Line 155...
174
print(f"Procedures count: {proc_count}")
155
	print(f"Procedures count: {proc_count}")
175
print(f"Global labels count: {label_count}")
156
	print(f"Global labels count: {label_count}")
176
print(f"Macroses count: {macro_count}")
157
	print(f"Macroses count: {macro_count}")
177
print(f"Structures count: {struct_count}")
158
	print(f"Structures count: {struct_count}")
Line -... Line 159...
-
 
159
 
-
 
160
print(f"Writing doumented sources to {doxygen_src_path}")
-
 
161
 
-
 
162
created_files = []
-
 
163
 
-
 
164
def write_variable(source, line, name, type = "int", brief = "Undocumented",
-
 
165
	               init = None):
-
 
166
	source = source.replace("./", "")
-
 
167
	full_path = doxygen_src_path + '/' + source
178
 
168
	# Remove the file on first access if it was created by previous generation
-
 
169
	if full_path not in created_files:
-
 
170
		if os.path.isfile(full_path):
-
 
171
			os.remove(full_path)
-
 
172
		created_files.append(full_path)
-
 
173
	# Only remove the file on 'clean_generated_stuff' flag (removed above, just return)
-
 
174
	if clean_generated_stuff: return
-
 
175
	# Create directories need for the file
-
 
176
	os.makedirs(os.path.dirname(full_path), exist_ok=True)
-
 
177
	name = name.replace(".", "_")
-
 
178
	f = open(full_path, "a")
-
 
179
	f.write(f"/**\n")
-
 
180
	f.write(f" * @brief {brief}\n")
-
 
181
	f.write(f" * @par Initial value\n")
-
 
182
	f.write(f" * {init}\n")
-
 
183
	f.write(f" * @par Source\n")
179
#for kernel_file in kernel_files:
184
	f.write(f" * {source}:{line}\n")
-
 
185
	f.write(f" */\n")
-
 
186
	if init == None:
-
 
187
		set_init = ""
-
 
188
	else:
-
 
189
		set_init = f" = {init}"
-
 
190
	f.write(f"{type} {name}{set_init};\n\n")
-
 
191
	f.close()
-
 
192
 
-
 
193
i = 1
-
 
194
for source in kernel_structure:
-
 
195
	# Print progress: current/total
-
 
196
	print(f"{i}/{len(kernel_structure)} Writing {source}")
-
 
197
	# Write variables doxygen of the source file
-
 
198
	if len(kernel_structure[source][VARIABLES]) > 0:
-
 
199
		for variable in kernel_structure[source][VARIABLES]:
-
 
200
			write_variable(source, variable[0], variable[1])