From f90ea945af62ee231183b206c59217a80e954209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C3=ABl=20Kooi?= <48814281+RA-Kooi@users.noreply.github.com> Date: Fri, 28 Jan 2022 14:56:04 +0100 Subject: [PATCH] Output function referenced variables --- DwarfOne2C/CWriter/Function.cs | 46 ++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/DwarfOne2C/CWriter/Function.cs b/DwarfOne2C/CWriter/Function.cs index 24680f1..1eaf27a 100644 --- a/DwarfOne2C/CWriter/Function.cs +++ b/DwarfOne2C/CWriter/Function.cs @@ -32,9 +32,10 @@ private static List GenerateFunction( part1, current.name); + bool firstLocal = true; + if(current.firstChild >= 0) { - bool firstLocal = true; bool hasParams = false; int i = 0; @@ -86,23 +87,48 @@ private static List 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); }