Subversion Repositories Kolibri OS

Rev

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

Rev 8989 Rev 8990
Line 1... Line 1...
1
import re
1
import re
2
import os
2
import os
3
import argparse
3
import argparse
4
import sys
4
import sys
-
 
5
import pickle
Line 5... Line 6...
5
 
6
 
6
# Parameters
7
# Parameters
7
# Path to doxygen folder to make doxygen files in: -o 
8
# Path to doxygen folder to make doxygen files in: -o 
8
doxygen_src_path = 'docs/doxygen'
9
doxygen_src_path = 'docs/doxygen'
Line 1357... Line 1358...
1357
 
1358
 
1358
class AsmElement:
1359
class AsmElement:
1359
	def __init__(self, location, name, comment):
1360
	def __init__(self, location, name, comment):
Line -... Line 1361...
-
 
1361
		global warnings
-
 
1362
 
1360
		global warnings
1363
		# If the element was constructed during this execution then the element is new
1361
 
1364
		self.new = True
1362
		self.location = location
1365
		self.location = location
1363
		self.file = self.location.split(':')[0].replace('\\', '/')
1366
		self.file = self.location.split(':')[0].replace('\\', '/')
1364
		self.line = self.location.split(':')[1]
1367
		self.line = self.location.split(':')[1]
Line 1908... Line 1911...
1908
					# Save the identifier as an equated constant
1911
					# Save the identifier as an equated constant
1909
					id_add_kind(word_one, ID_KIND_EQUATED_CONSTANT)
1912
					id_add_kind(word_one, ID_KIND_EQUATED_CONSTANT)
1910
		r.nextline()
1913
		r.nextline()
Line 1911... Line 1914...
1911
 
1914
 
-
 
1915
def it_neds_to_be_parsed(source_file):
-
 
1916
	# If there's no symbols file saved - parse it anyway
-
 
1917
	# cause we need to create the symbols file and use it
-
 
1918
	# if we gonna generate proper doxygen
-
 
1919
	if not os.path.isfile('asmxygen.elements.pickle'):
1912
def it_neds_to_be_parsed(source_file):
1920
		return True
1913
	dest = doxygen_src_path + '/' + source_file
1921
	dest = doxygen_src_path + '/' + source_file
1914
	# If there's no the doxygen file it should be compiled to
1922
	# If there's no the doxygen file it should be compiled to
1915
	# then yes, we should compile it to doxygen
1923
	# then yes, we should compile it to doxygen
1916
	if not os.path.isfile(dest):
1924
	if not os.path.isfile(dest):
Line 1922... Line 1930...
1922
	if source_change_time > dest_change_file:
1930
	if source_change_time > dest_change_file:
1923
		return True
1931
		return True
1924
	return False
1932
	return False
Line 1925... Line 1933...
1925
 
1933
 
-
 
1934
def handle_file(handled_files, asm_file_name, subdir = "."):
1926
def handle_file(handled_files, asm_file_name, subdir = "."):
1935
	global elements
1927
	# Canonicalize the file path and get it relative to cwd
1936
	# Canonicalize the file path and get it relative to cwd
1928
	cwd = os.path.abspath(os.path.dirname(sys.argv[0]))
1937
	cwd = os.path.abspath(os.path.dirname(sys.argv[0]))
1929
	asm_file_name = os.path.realpath(asm_file_name)
1938
	asm_file_name = os.path.realpath(asm_file_name)
1930
	asm_file_name = asm_file_name[len(cwd) + 1:]
1939
	asm_file_name = asm_file_name[len(cwd) + 1:]
Line 1941... Line 1950...
1941
	if not it_neds_to_be_parsed(asm_file_name):
1950
	if not it_neds_to_be_parsed(asm_file_name):
1942
		print(f"Skipping {asm_file_name} (already newest)")
1951
		print(f"Skipping {asm_file_name} (already newest)")
1943
		should_get_declarations = False
1952
		should_get_declarations = False
1944
	else:
1953
	else:
1945
		print(f"Handling {asm_file_name}")
1954
		print(f"Handling {asm_file_name}")
-
 
1955
		# Remove elements parsed from this file before if any
-
 
1956
		elements_to_remove = [x for x in elements if x.location.split(':')[0] == asm_file_name]
-
 
1957
		elements = [x for x in elements if x.location.split(':')[0] != asm_file_name]
-
 
1958
		# Forget types of identifiers of names of the removed elements
-
 
1959
		for element in elements_to_remove:
-
 
1960
			if type(element) == AsmStruct:
-
 
1961
				id_remove_kind(element.name, ID_KIND_STRUCT_NAME)
-
 
1962
			elif type(element) == AsmMacro:
-
 
1963
				id_remove_kind(element.name, ID_KIND_MACRO_NAME)
1946
	# Read the source
1964
	# Read the source
1947
	asm_file_contents = open(asm_file_name, "r", encoding="utf-8").read()
1965
	asm_file_contents = open(asm_file_name, "r", encoding="utf-8").read()
1948
	# Find includes, fix their paths and handle em recoursively
1966
	# Find includes, fix their paths and handle em recoursively
1949
	includes = re.findall(r'^include (["\'])(.*)\1', asm_file_contents, flags=re.MULTILINE)
1967
	includes = re.findall(r'^include (["\'])(.*)\1', asm_file_contents, flags=re.MULTILINE)
1950
	for include in includes:
1968
	for include in includes:
Line 1959... Line 1977...
1959
	if should_get_declarations and not clean_generated_stuff:
1977
	if should_get_declarations and not clean_generated_stuff:
1960
		get_declarations(asm_file_contents, asm_file_name)
1978
		get_declarations(asm_file_contents, asm_file_name)
Line 1961... Line 1979...
1961
 
1979
 
Line -... Line 1980...
-
 
1980
kernel_files = []
-
 
1981
 
-
 
1982
# Load remembered list of symbols
-
 
1983
if os.path.isfile('asmxygen.elements.pickle'):
-
 
1984
	print('Reading existing dump of symbols')
1962
kernel_files = []
1985
	(elements, id2kind) = pickle.load(open('asmxygen.elements.pickle', 'rb'))
Line 1963... Line 1986...
1963
 
1986
 
1964
handle_file(kernel_files, "./kernel.asm");
1987
handle_file(kernel_files, "./kernel.asm");
1965
 
1988
 
Line 1977... Line 2000...
1977
			print("Done.")
2000
			print("Done.")
1978
elif not noemit:
2001
elif not noemit:
1979
	print(f"Writing doumented sources to {doxygen_src_path}")
2002
	print(f"Writing doumented sources to {doxygen_src_path}")
Line 1980... Line 2003...
1980
 
2003
 
-
 
2004
	i = 0
1981
	i = 0
2005
	new_elements = [x for x in elements if x.new]
1982
	for element in elements:
2006
	for element in new_elements:
1983
		print(f"[{i + 1}/{len(elements)}] Emitting {element.name} from {element.location}")
2007
		print(f"[{i + 1}/{len(new_elements)}] Emitting {element.name} from {element.location}")
1984
		element.emit(doxygen_src_path)
2008
		element.emit(doxygen_src_path)
Line -... Line 2009...
-
 
2009
		i += 1
-
 
2010
 
-
 
2011
	print(f"Writing dump of symbols to asmxygen.elements.pickle")
-
 
2012
 
-
 
2013
	# Now when the new elements already was written, there's no new elements anymore
-
 
2014
	for element in elements:
-
 
2015
		element.new = False
1985
		i += 1
2016
	pickle.dump((elements, id2kind), open('asmxygen.elements.pickle', 'wb'))
1986
 
2017
 
1987
if print_stats:
2018
if print_stats:
1988
	var_count = 0
2019
	var_count = 0
1989
	mac_count = 0
2020
	mac_count = 0