Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
FunctionListGenerator: Fixed bool return type, float/double return ty…
…pe, function pointer args in usercall functions (I hope).
  • Loading branch information
MainMemory committed Mar 18, 2016
1 parent bcaa50b commit c28659d
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions FunctionListGenerator/Program.cs
Expand Up @@ -13,6 +13,14 @@ static class Program
static readonly Regex argument = new Regex(@"(?<name>[^<@]+)(?:@<(?<register>[^>]+)>)?", RegexOptions.CultureInvariant);
static readonly Regex functionptr = new Regex(@"\((?:__cdecl|__stdcall|__fastcall|__thiscall)? \*(?<name>[A-Za-z_][A-Za-z_0-9]*)\)", RegexOptions.CultureInvariant);

static readonly Dictionary<string, string> boolregs = new Dictionary<string, string>()
{
{ "eax", "al" },
{ "ebx", "bl" },
{ "ecx", "cl" },
{ "edx", "dl" }
};

static void Main(string[] args)
{
string filename;
Expand Down Expand Up @@ -79,10 +87,28 @@ static void Main(string[] args)
string returnreg = match.Groups["returnreg"].Value;
string callconv = match.Groups["callconv"].Value;
string arguments = match.Groups["arguments"].Value;
List<string> arglist = new List<string>();
int c = 0;
while (true)
{
if (arguments[c] == ' ')
c++;
int comma = arguments.IndexOf(',', c);
if (comma == -1)
{
arglist.Add(arguments.Substring(c));
break;
}
int paren = arguments.IndexOf('(', c);
if (paren > -1 && paren < comma)
comma = arguments.IndexOf(')', arguments.IndexOf('(', paren + 1)) + 1;
arglist.Add(arguments.Substring(c, comma - c));
c = comma + 1;
}
List<string> argnames = new List<string>();
List<string> argdecls = new List<string>();
List<string> argregs = new List<string>();
foreach (string arg in arguments.Split(','))
foreach (string arg in arglist)
{
match = argument.Match(arg);
string argdecl = match.Groups[1].Value.Trim();
Expand Down Expand Up @@ -111,7 +137,11 @@ static void Main(string[] args)
int stackcnt = argregs.Count((item) => string.IsNullOrEmpty(item));
if (stackcnt > 0)
writer.WriteLine("\t\tadd esp, {0}", stackcnt * 4);
if (returntype != "void")
if (returntype == "bool")
writer.WriteLine("\t\tmov result, {0}", boolregs[returnreg]);
else if (returnreg == "st0")
writer.WriteLine("\t\tfstp result");
else if (returntype != "void")
writer.WriteLine("\t\tmov result, {0}", returnreg);
writer.WriteLine("\t}");
if (returntype != "void")
Expand Down

0 comments on commit c28659d

Please sign in to comment.