mirror of
https://github.com/izzy2lost/Diddy-Kong-Racing.git
synced 2026-06-19 01:16:26 -07:00
Fixed mips2c issues hopefully.
This commit is contained in:
+34
-12
@@ -235,7 +235,9 @@ definesRegex = r"(^#\s*define.*\\(?:\n.*\\)*\n.*$)|(^#(?!include)(?!undef).*$)"
|
||||
def collect_directives(filename, filetext, data):
|
||||
defs = regex_get_matches(filetext, definesRegex)
|
||||
for direct in defs:
|
||||
data.append(direct.group(0))
|
||||
if direct.group(1) is None:
|
||||
data['singleline'].append(direct.group(0))
|
||||
data['all'].append(direct.group(0))
|
||||
|
||||
# Return the end position of a string
|
||||
def find_end(text, findStr):
|
||||
@@ -313,7 +315,10 @@ def collect(filenames):
|
||||
'functions': {},
|
||||
'variables': {},
|
||||
'types': {}, # typedefs, structs, unions, enums
|
||||
'directives': [] # Should ignore `#include`
|
||||
'directives': {
|
||||
'singleline': [],
|
||||
'all': []
|
||||
}
|
||||
}
|
||||
|
||||
mapText = load_map()
|
||||
@@ -382,12 +387,9 @@ def write_output_functions(funcs):
|
||||
return out + '\n'
|
||||
|
||||
# Writes all the preprocessor directives to the output file
|
||||
def write_output_directives(directivesArray):
|
||||
out = ''
|
||||
out += '#define NULL (void*)0\n' # Hack, since cleanup() will remove the original NULL definition.
|
||||
for direct in directivesArray:
|
||||
out += direct + '\n'
|
||||
return out + '\n'
|
||||
def write_output_directives(directives):
|
||||
directives['singleline'].append('#define NULL (void*)0\n') # Hack, since cleanup() will remove the original NULL definition.
|
||||
return [ '\n'.join(directives['singleline']) + '\n', '\n'.join(directives['all']) + '\n' ]
|
||||
|
||||
# Writes a variable to the output file
|
||||
def write_output_variable(key, variables, varKeys, doneKeys):
|
||||
@@ -402,7 +404,7 @@ def write_output_variable(key, variables, varKeys, doneKeys):
|
||||
continue
|
||||
if key2 in text:
|
||||
out += write_output_variable(key2, variables, varKeys, doneKeys)
|
||||
out += text + '\n'
|
||||
out += text.replace('UNUSED', '') + '\n'
|
||||
doneKeys[key] = 1
|
||||
return out
|
||||
|
||||
@@ -417,16 +419,36 @@ def write_output_variables(variables):
|
||||
out += write_output_variable(key, variables, varKeys, doneKeys)
|
||||
return out + '\n'
|
||||
|
||||
# Preprocess everything, since mips2c doesn't like the preprocessor.
|
||||
def preprocess_all(directivesText):
|
||||
open("__temp.c", "w").write(directivesText)
|
||||
cpp_command = ["gcc", "-E", "-P", "-undef", "-D_LANGUAGE_C", "-D__sgi", "-DNON_MATCHING", "-D_Static_assert(x, y)=", "-D__attribute__(x)=", "__temp.c"]
|
||||
out = subprocess.check_output(cpp_command, cwd=root_dir, encoding="utf-8")
|
||||
os.remove("__temp.c")
|
||||
return out
|
||||
|
||||
# Preprocess everything but the #defines.
|
||||
def preprocess_directives(directivesText):
|
||||
open("__temp.c", "w").write(directivesText)
|
||||
cpp_command = ["gcc", "-E", "-P", "-fdirectives-only", "-undef", "-D_LANGUAGE_C", "-D__sgi", "-DNON_MATCHING", "-D_Static_assert(x, y)=", "-D__attribute__(x)=", "__temp.c"]
|
||||
out = subprocess.check_output(cpp_command, cwd=root_dir, encoding="utf-8")
|
||||
os.remove("__temp.c")
|
||||
return out
|
||||
|
||||
# Creates the output file text.
|
||||
def write_output(data):
|
||||
out = '/*** DKR decomp context file (Automatically generated by m2ctx.py [' + date.today().strftime("%Y/%m/%d") + ']) ***/\n\n'
|
||||
out += write_output_directives(data['directives'])
|
||||
header = '/*** DKR decomp context file (Automatically generated by m2ctx.py [' + date.today().strftime("%Y/%m/%d") + ']) ***/\n\n'
|
||||
out = ''
|
||||
directives = write_output_directives(data['directives'])
|
||||
out += directives[0] # Only add single-line directives at first for preprocessing.
|
||||
out += write_output_types(data['types'])
|
||||
out += write_output_variables(data['variables'])
|
||||
out += write_output_functions(data['functions'])
|
||||
out = fix_enums(out) # Fixes trailing commas in enums, which gets rid of a warning.
|
||||
out = cleanup(out) # Removes useless stuff
|
||||
return out
|
||||
out = preprocess_all(out) # Preprocesses everything, removing all the directives.
|
||||
out = preprocess_directives(directives[1]) + out # Add the defines back in.
|
||||
return header + out
|
||||
|
||||
# Uses the `find` program to return the filenames in the specified folders.
|
||||
def find_files():
|
||||
|
||||
Reference in New Issue
Block a user