Skip to content

Commit

Permalink
Output function referenced variables
Browse files Browse the repository at this point in the history
  • Loading branch information
RA-Kooi committed Jan 28, 2022
1 parent eab7668 commit f90ea94
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions DwarfOne2C/CWriter/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ private static List<string> GenerateFunction(
part1,
current.name);

bool firstLocal = true;

if(current.firstChild >= 0)
{
bool firstLocal = true;
bool hasParams = false;

int i = 0;
Expand Down Expand Up @@ -86,23 +87,48 @@ private static List<string> GenerateFunction(
}
}

// We had a local variable;
if(!firstLocal)
{
code.Add(tabs + "}");
}
else
// We didn't have a local variable;
if(firstLocal)
{
if(hasParams)
line = line.Remove(line.Length - 2, 2);

line += ")" + part2 + ";";
code.Add(line);
line += ")" + part2;
}
}
else
{
line += ")" + part2 + ";";
line += ")" + part2;
}

if(current.references.Count > 0)
{
if(firstLocal)
{
code.Add(line);
code.Add("{");
}

foreach(int reference in current.references)
{
Tag referenced = allTags[IDToIndex[reference]];
string name = referenced.name != null
? referenced.name
: $"unknown_0x{reference:X}";

line = $"{tabs}\t// References: {name}";

if(referenced.location != -1)
line += $" (0x{referenced.location:X})";

code.Add(line);
}

code.Add("}");
}
else if(firstLocal)
{
line += ';';
code.Add(line);
}

Expand Down

0 comments on commit f90ea94

Please sign in to comment.