commit the "code generator" that was used to assist in creating r4203. it's not much, and is probably quite useless. but if you must pry, try readme.txt

This commit is contained in:
goyuken 2012-12-24 18:20:30 +00:00
parent 5e3d6555b0
commit fb2a80b7d9
11 changed files with 11506 additions and 0 deletions

View File

@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
namespace Generex
{
public class Decoder
{
TextReader core;
public List<List<string>> impls = new List<List<string>>();
List<string> ops = new List<string>();
public Decoder(TextReader core, TextReader ops)
{
this.core = core;
string s;
while ((s = ops.ReadLine()) != null)
{
this.ops.Add(s);
}
}
void ProcMethod(string openline, int opsindex, string submeth)
{
List<string> impl = new List<string>();
impl.Add("// " + openline);
string replacant = null;
if (submeth != null)
{
var r = new Regex(@">\(([^\)]*)");
var m = r.Match(openline);
if (m.Success)
{
replacant = m.Groups[1].Value;
}
else
{
throw new Exception(string.Format("no find in \"{0}\"", openline));
}
}
for (int i = opsindex; i < ops.Count; i++)
{
if (string.IsNullOrWhiteSpace(ops[i]))
break;
if (submeth != null && ops[i].Contains("call"))
{
var s = ops[i].Replace("call", submeth);
// also have to replace 'r' tokens
//Console.WriteLine("\"{0}\"{1}\"", s, replacant);
impl.Add(s);
}
else
impl.Add(ops[i]);
}
impls.Add(impl);
}
public void Scan()
{
string s;
while ((s = core.ReadLine()) != null)
{
var r = new Regex(@": return ([^<\(]*)");
var m = r.Match(s);
if (!m.Success)
continue;
var methname = m.Groups[1].Value;
r = new Regex(@"<&SMPcore::([^>]*)");
m = r.Match(s);
string submeth = m.Success ? m.Groups[1].Value : null;
// find method
string findu = "void SMPcore::" + methname;
int i;
for (i = 0; i < ops.Count; i++)
{
if (ops[i].Contains(findu))
{
ProcMethod(s, i, submeth);
break;
}
}
if (i == ops.Count)
throw new Exception(string.Format("Couldn't find! \"{0}\"", findu));
}
}
}
}

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{CC4ABECE-2F0B-4649-88FC-62F6B2AFBA59}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Generex</RootNamespace>
<AssemblyName>Generex</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Decoder.cs" />
<Compile Include="ListerTheTormentor.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Generex", "Generex.csproj", "{CC4ABECE-2F0B-4649-88FC-62F6B2AFBA59}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CC4ABECE-2F0B-4649-88FC-62F6B2AFBA59}.Debug|x86.ActiveCfg = Debug|x86
{CC4ABECE-2F0B-4649-88FC-62F6B2AFBA59}.Debug|x86.Build.0 = Debug|x86
{CC4ABECE-2F0B-4649-88FC-62F6B2AFBA59}.Release|x86.ActiveCfg = Release|x86
{CC4ABECE-2F0B-4649-88FC-62F6B2AFBA59}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,111 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Generex
{
public class Lister
{
List<string> lines = new List<string>();
Dictionary<string, int> uops = new Dictionary<string, int>();
int nextindex = 1;
int nextmulti = 0;
StringWriter output = new StringWriter();
public Lister(TextReader src)
{
string s;
while ((s = src.ReadLine()) != null)
lines.Add(s);
}
int GetIndex(string uop)
{
uop = uop.Trim();
int ret;
if (uops.TryGetValue(uop, out ret))
return ret;
else
{
uops.Add(uop, nextindex++);
return nextindex - 1;
}
}
void ReadOpcode(ref int idx)
{
if (lines[idx] != "//##IMPL")
throw new Exception("missing IMPL tag");
idx++;
output.WriteLine(lines[idx++]);
output.WriteLine("// " + lines[idx++]);
output.WriteLine("{");
while (lines[idx].Length > 1)
{
var s = lines[idx].Trim();
if (s == "//[[") // special multiline hack
{
idx++;
while ((s = lines[idx].Trim()) != "//]]")
{
output.WriteLine(" //{0}", s);
idx++;
}
string f = string.Format("//!!MULTI{0}", nextmulti++);
int j = GetIndex(f);
output.WriteLine(" {0}, // {1}", j, f);
idx++;
}
else
{
int j = GetIndex(s);
output.WriteLine(" {0}, // {1}", j, s);
idx++;
}
}
output.WriteLine(" {0}, // //!!NEXT", GetIndex("//!!NEXT"));
output.WriteLine("},");
idx++;
}
public void Scan()
{
for (int idx = 0; idx < lines.Count; ReadOpcode(ref idx))
{
}
}
void PrintUops()
{
Console.WriteLine("{");
Console.WriteLine(" switch (uop)");
Console.WriteLine(" {");
foreach (var kv in uops)
{
Console.WriteLine(" case {0}:", kv.Value);
Console.WriteLine(" {0}", kv.Key);
Console.WriteLine(" break;");
}
Console.WriteLine(" }");
Console.WriteLine("}");
}
public void PrintStuff()
{
Console.WriteLine(output.ToString());
for (int i = 0; i < 8; i++)
Console.WriteLine();
PrintUops();
}
}
}

View File

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Generex
{
class Program
{
// contains case list
const string corecpp = @"..\..\..\..\bsnes\snes\smp\core\core.cpp";
const string opcodescpp = @"..\..\..\..\bsnes\snes\smp\core\opcodes.cpp";
const string fixedcpp = @".\fixed.cpp";
static void Main(string[] args)
{
try
{
// GENEREX PHASE 1
/*
TextReader core = new StreamReader(corecpp);
TextReader ops = new StreamReader(opcodescpp);
Decoder d = new Decoder(core, ops);
d.Scan();
foreach (var s in d.impls)
{
Console.WriteLine("//##IMPL");
foreach (var ss in s)
Console.WriteLine(ss);
}
*/
// GENERX PHASE 2
TextReader fixedt = new StreamReader(fixedcpp);
Lister l = new Lister(fixedt);
l.Scan();
l.PrintStuff();
}
catch (Exception e)
{
Console.Error.WriteLine("EXCEPTION KILLED ME");
Console.Error.WriteLine(e.ToString());
}
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Generex")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Generex")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("6c415bcd-4fe8-4df8-9bfd-41f0ea31aeed")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,13 @@
this code was used to aid in the creation of r4203. it's not really production quality, and two generate steps are involved with manual
editing inbetween each.
rough outline of functionality:
1. in Program.cs, uncomment "PHASE 1" and comment "PHASE 2".
run the program and redirect stdout to "out.cpp"
2. edit "out.cpp" to produce "fixed.cpp". as fixed.cpp is included
in the svn commit, i won't provide any other details.
3. in Program.cs, uncomment "PHASE 2" and comment "PHASE 1".
run the program and redirect stdout. to "uop.cpp"
4. fix up "uop.cpp" by hand, and integrate it into the bsnes source tree.