Subversion Repositories Kolibri OS

Rev

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

Rev 9401 Rev 9402
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
5
import pickle
-
 
6
import hashlib
-
 
7
import difflib
Line 6... Line 8...
6
 
8
 
7
# fasm keywords
9
# fasm keywords
8
keywords = [
10
keywords = [
9
    "align", "equ", "org", "while", "load", "store", "times", "repeat", 
11
    "align", "equ", "org", "while", "load", "store", "times", "repeat", 
Line 320... Line 322...
320
 
322
 
321
class AsmReader(AsmReaderFetchingIdentifiers):
323
class AsmReader(AsmReaderFetchingIdentifiers):
322
	def __init__(self, file):
324
	def __init__(self, file):
Line -... Line 325...
-
 
325
		super().__init__(file)
-
 
326
 
-
 
327
def append_file(full_path, contents):
-
 
328
	if debug_mode:
-
 
329
		if full_path not in output_files:
-
 
330
			output_files[full_path] = ""
-
 
331
		output_files[full_path] += contents
-
 
332
	else:
-
 
333
		f = open(full_path, "a")
-
 
334
		f.write(contents)
323
		super().__init__(file)
335
		f.close()
324
 
336
 
325
class AsmElement:
337
class AsmElement:
Line 326... Line 338...
326
	def __init__(self, location, name, comment):
338
	def __init__(self, location, name, comment):
Line 371... Line 383...
371
			if os.path.isfile(full_path):
383
			if os.path.isfile(full_path):
372
				os.remove(full_path)
384
				os.remove(full_path)
373
			created_files.append(full_path)
385
			created_files.append(full_path)
374
		# Create directories need for the file
386
		# Create directories need for the file
375
		os.makedirs(os.path.dirname(full_path), exist_ok=True)
387
		os.makedirs(os.path.dirname(full_path), exist_ok=True)
376
		f = open(full_path, "a")
-
 
377
		contents = ''.join([i if ord(i) < 128 else '?' for i in contents])
388
		contents = ''.join([i if ord(i) < 128 else '?' for i in contents])
-
 
389
 
378
		f.write(contents)
390
		append_file(full_path, contents)
379
		f.close()
-
 
Line 380... Line 391...
380
 
391
 
381
class AsmVariable(AsmElement):
392
class AsmVariable(AsmElement):
382
	def __init__(self, location, name, comment, type, init):
393
	def __init__(self, location, name, comment, type, init):
383
		super().__init__(location, name, comment)
394
		super().__init__(location, name, comment)
Line 1007... Line 1018...
1007
	parser.add_argument("--clean", help="Remove generated files", action="store_true")
1018
	parser.add_argument("--clean", help="Remove generated files", action="store_true")
1008
	parser.add_argument("--dump", help="Dump all defined symbols", action="store_true")
1019
	parser.add_argument("--dump", help="Dump all defined symbols", action="store_true")
1009
	parser.add_argument("--stats", help="Print symbol stats", action="store_true")
1020
	parser.add_argument("--stats", help="Print symbol stats", action="store_true")
1010
	parser.add_argument("--nowarn", help="Do not write warnings file", action="store_true")
1021
	parser.add_argument("--nowarn", help="Do not write warnings file", action="store_true")
1011
	parser.add_argument("--noemit", help="Do not emit doxygen files (for testing)", action="store_true")
1022
	parser.add_argument("--noemit", help="Do not emit doxygen files (for testing)", action="store_true")
-
 
1023
	parser.add_argument("--debug", help="Show hashes of files (for testing)", action="store_true")
1012
	args = parser.parse_args()
1024
	args = parser.parse_args()
1013
	doxygen_src_path = args.o if args.o else 'docs/doxygen'
1025
	doxygen_src_path = args.o if args.o else 'docs/doxygen'
1014
	clean_generated_stuff = args.clean
1026
	clean_generated_stuff = args.clean
1015
	dump_symbols = args.dump
1027
	dump_symbols = args.dump
1016
	print_stats = args.stats
1028
	print_stats = args.stats
1017
	enable_warnings = not args.nowarn
1029
	enable_warnings = not args.nowarn
1018
	noemit = args.noemit
1030
	noemit = args.noemit
-
 
1031
	debug_mode = args.debug
Line 1019... Line 1032...
1019
 
1032
 
1020
	# Variables, functions, labels, macros, structure types
1033
	# Variables, functions, labels, macros, structure types
1021
	elements = []
-
 
1022
 
1034
	elements = []
1023
	created_files = []
-
 
1024
 
1035
	created_files = []
-
 
1036
	kernel_files = []
Line 1025... Line 1037...
1025
	kernel_files = []
1037
	output_files = {} # If --debug then all the files are written here
1026
 
1038
 
1027
	# Load remembered list of symbols
1039
	# Load remembered list of symbols
1028
	if os.path.isfile('asmxygen.elements.pickle'):
1040
	if os.path.isfile('asmxygen.elements.pickle'):
Line 1090... Line 1102...
1090
		print(f'Parsed union type count: {uni_count}')
1102
		print(f'Parsed union type count: {uni_count}')
1091
		print(f'Parsed structure type count: {str_count}')
1103
		print(f'Parsed structure type count: {str_count}')
Line 1092... Line 1104...
1092
 
1104
 
1093
	if enable_warnings:
1105
	if enable_warnings:
-
 
1106
		open('asmxygen.txt', "w", encoding = "utf-8").write(warnings)
-
 
1107
 
-
 
1108
	if debug_mode:
-
 
1109
		hash_per_file = ""
-
 
1110
		for file in output_files:
-
 
1111
			h = hashlib.sha1(bytes(output_files[file], "ascii")).hexdigest()
-
 
1112
			hash_per_file += f"{file}: {h}\n"
-
 
1113
		if not os.path.exists("asmxygen_hash_per_file.txt"):
-
 
1114
			open("asmxygen_hash_per_file.txt", "w").write(hash_per_file)
-
 
1115
			print("NEW")
-
 
1116
		else:
-
 
1117
			reference_hash_per_file = open("asmxygen_hash_per_file.txt").read()
-
 
1118
			if reference_hash_per_file != hash_per_file:
-
 
1119
				print(''.join(difflib.ndiff(reference_hash_per_file, hash_per_file)))
-
 
1120
			else: