Skip to content

Commit 8a226a3

Browse files
committed
Other: Shrinker.Transpile - Shrinker.Cmd now exclusively transpiles.
1 parent 106f7b6 commit 8a226a3

File tree

6 files changed

+65
-136
lines changed

6 files changed

+65
-136
lines changed

ShaderShrinker/Shrinker.Cmd/Program.cs

Lines changed: 0 additions & 130 deletions
This file was deleted.

ShaderShrinker/Shrinker.Cmd/CmdOptions.cs renamed to ShaderShrinker/Shrinker.Transpile/CmdOptions.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@
1616

1717
#pragma warning disable CS8618
1818

19-
namespace Shrinker.Cmd;
19+
namespace Shrinker.Transpile;
2020

2121
// ReSharper disable once ClassNeverInstantiated.Global
2222
public class CmdOptions
2323
{
2424
[Option('o', "output", Default = "", HelpText = "Transpile GLSL->CSharp file path.")]
2525
public string CSharpOutputPath { get; set; }
26-
27-
[Option('d', "diff", Default = false, HelpText = "Launch external diffing tool.")]
28-
public bool Diff { get; set; }
2926
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System.Reflection;
2+
using System.Text;
3+
using CommandLine;
4+
using Shrinker.Parser;
5+
using TextCopy;
6+
7+
namespace Shrinker.Transpile
8+
{
9+
// todo - add command line args.
10+
internal static class Program
11+
{
12+
private static void Main(string[] args)
13+
{
14+
CommandLine.Parser.Default.ParseArguments<CmdOptions>(args).WithParsed(Shrink);
15+
}
16+
17+
private static void Shrink(CmdOptions args)
18+
{
19+
var glsl = ClipboardService.GetText();
20+
if (string.IsNullOrEmpty(glsl))
21+
{
22+
Console.WriteLine("Error - Clipboard is empty.");
23+
return;
24+
}
25+
26+
var lexer = new Lexer.Lexer();
27+
if (!lexer.Load(glsl))
28+
{
29+
Console.WriteLine("Error - Unable to process the GLSL.");
30+
return;
31+
}
32+
33+
var parser = new Parser.Parser(lexer);
34+
try
35+
{
36+
Console.WriteLine("Parsing...");
37+
var rootNode = parser.Parse();
38+
39+
Console.WriteLine("Simplifying...");
40+
var options = CustomOptions.TranspileOptions();
41+
rootNode.Simplify(options);
42+
43+
Console.WriteLine("Creating CSharp...");
44+
var newGlsl = rootNode.ToCode(options);
45+
46+
const string ResourceName = "Shrinker.Transpile.Templates.GLSLProg.template";
47+
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(ResourceName);
48+
if (stream == null)
49+
throw new InvalidOperationException($"Missing C# resource template: {ResourceName}");
50+
51+
Console.WriteLine($"Writing {args.CSharpOutputPath}...");
52+
using var reader = new StreamReader(stream);
53+
var text = new StringBuilder(reader.ReadToEnd());
54+
text.Replace("{code}", newGlsl);
55+
File.WriteAllText(args.CSharpOutputPath, text.ToString());
56+
}
57+
catch (Exception ex)
58+
{
59+
Console.WriteLine($" Error - {ex.Message}");
60+
}
61+
}
62+
}
63+
}

ShaderShrinker/Shrinker.Cmd/Shrinker.Cmd.csproj renamed to ShaderShrinker/Shrinker.Transpile/Shrinker.Transpile.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
<ItemGroup>
1212
<PackageReference Include="CommandLineParser" Version="2.9.1" />
13-
<PackageReference Include="DiffEngine" Version="12.3.1" />
1413
<PackageReference Include="TextCopy" Version="6.2.1" />
1514
</ItemGroup>
1615

ShaderShrinker/Shrinker.Cmd/Templates/GLSLProg.template renamed to ShaderShrinker/Shrinker.Transpile/Templates/GLSLProg.template

File renamed without changes.

ShaderShrinker/Shrinker.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shrinker.Lexer", "Shrinker.
99
EndProject
1010
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shrinker.Parser", "Shrinker.Parser\Shrinker.Parser.csproj", "{4B02CF1B-391C-42C8-84B1-2CA6E5B8F504}"
1111
EndProject
12-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shrinker.Cmd", "Shrinker.Cmd\Shrinker.Cmd.csproj", "{6C0A1B07-B195-4A07-921C-F6D962870309}"
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shrinker.Transpile", "Shrinker.Transpile\Shrinker.Transpile.csproj", "{6C0A1B07-B195-4A07-921C-F6D962870309}"
1313
EndProject
1414
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GLSLRenderer", "..\GLSLRenderer\GLSLRenderer.csproj", "{D5026CC4-1CF2-40C3-A185-37EA571A671D}"
1515
EndProject

0 commit comments

Comments
 (0)