Skip to content

Commit

Permalink
clps2c-compiler: init at 1.0.1 (#339716)
Browse files Browse the repository at this point in the history
  • Loading branch information
corngood authored Nov 5, 2024
2 parents 654de93 + 1c18250 commit 75c9076
Show file tree
Hide file tree
Showing 9 changed files with 363 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkgs/by-name/cl/clps2c-compiler/deps.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions pkgs/by-name/cl/clps2c-compiler/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
keystone,
fetchFromGitHub,
buildDotnetModule,
dotnetCorePackages,
lib,
}:
let
version = "1.0.1";
pname = "CLPS2C-Compiler";
owner = "NiV-L-A";
keystone-rev = "MIPS-0.9.2";
keystone-sha256 = "sha256-xLkO06ZgnmAavJMP1kjDwXT1hc5eSDXv+4MUkOz6xeo=";
keystone-src = (
fetchFromGitHub {
name = "keystone";
inherit owner;
repo = "keystone";
rev = keystone-rev;
sha256 = keystone-sha256;
}
);
keystone-override = keystone.overrideAttrs (old: {
src = keystone-src;
});
in
buildDotnetModule rec {
inherit version pname;

srcs = [
(fetchFromGitHub {
name = pname;
inherit owner;
repo = pname;
rev = "CLPS2C-Compiler-${version}";
sha256 = "sha256-4gLdrIxyw9BFSxF+EXZqTgUf9Kik6oK7eO9HBUzk4QM=";
})
keystone-src
];

sourceRoot = ".";

patches = [
./patches/dont_trim_leading_newline.patch
./patches/build_fixes.patch
./patches/remove_platformtarget.patch
./patches/use_compiled_keystone.patch
./patches/set_langversion.patch
./patches/set_runtimeidentifiers.patch
./patches/keystone_set_targetframework.patch
];

dotnet-sdk = dotnetCorePackages.sdk_8_0;
dotnet-runtime = dotnetCorePackages.runtime_8_0;

dotnetFlags = [
"-p:TargetFramework=net8.0"
];

nugetDeps = ./deps.nix;

runtimeDeps = [
keystone-override
];

projectFile = "CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj";

meta = {
homepage = "https://github.com/NiV-L-A/CLPS2C-Compiler";
description = "Compiler for CLPS2C, a domain-specific language built specifically for writing PS2 cheat codes";
mainProgram = "CLPS2C-Compiler";
maintainers = [ lib.maintainers.gigahawk ];
license = lib.licenses.gpl3Only;
};
}
193 changes: 193 additions & 0 deletions pkgs/by-name/cl/clps2c-compiler/patches/build_fixes.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
diff --git a/CLPS2C-Compiler/Program.cs b/CLPS2C-Compiler/Program.cs
index 6991896..a086433 100644
--- a/CLPS2C-Compiler/CLPS2C-Compiler/Program.cs
+++ b/CLPS2C-Compiler/CLPS2C-Compiler/Program.cs
@@ -1166,7 +1166,7 @@ namespace CLPS2C_Compiler
string Value_1 = "";
string Value_2 = "";
// Handle a bit differently in case there's a label at the start
- if (command.Type.EndsWith(':'))
+ if (command.Type.EndsWith(":"))
{
OpCode = command.Data[0].ToUpper();
Register = command.Data[1];
@@ -1201,7 +1201,7 @@ namespace CLPS2C_Compiler
}

Output = $"lui {Register},0x{Value_1}; {OpCode} {Register},{Value_2}({Register})";
- if (command.Type.EndsWith(':'))
+ if (command.Type.EndsWith(":"))
{
Output = $"{command.FullLine.Substring(0, command.FullLine.IndexOf(':'))}: {Output}";
}
@@ -1589,7 +1589,7 @@ namespace CLPS2C_Compiler

while (IfIndex != -1)
{
- int ExtraIfCount = commands[IfIndex].FullLine.Split("&&", StringSplitOptions.None).Length - 1;
+ int ExtraIfCount = commands[IfIndex].FullLine.Split(new string[] { "&&" }, StringSplitOptions.None).Length - 1;
for (int i = 0; i < ExtraIfCount; i++)
{
// Add more IF commands
@@ -1807,7 +1807,7 @@ namespace CLPS2C_Compiler
for (int j = 0; j < commands[i].Data.Count; j++)
{
string Target = commands[i].Data[j];
- if (Target.StartsWith('+') || Target.StartsWith(','))
+ if (Target.StartsWith("+") || Target.StartsWith(","))
{
Target = Target.Substring(1).TrimStart();
}
@@ -1815,14 +1815,14 @@ namespace CLPS2C_Compiler
if (IsVarDeclared(Target, listSets))
{
List<string> ListValues = GetSetValueFromTarget(Target, commands[i].ID, listSets);
- if (commands[i].Data[j].StartsWith('+') || commands[i].Data[j].StartsWith(','))
+ if (commands[i].Data[j].StartsWith("+") || commands[i].Data[j].StartsWith(","))
{
ListValues[0] = commands[i].Data[j][0] + ListValues[0];
}

for (int k = 1; k < ListValues.Count; k++)
{
- if (ListValues[k].StartsWith('+') || ListValues[k].StartsWith(','))
+ if (ListValues[k].StartsWith("+") || ListValues[k].StartsWith(","))
{
ListValues[k] = ListValues[k][0] + ListValues[k].Substring(1).TrimStart();
}
@@ -1834,7 +1834,7 @@ namespace CLPS2C_Compiler
continue;
}

- if (commands[i].Data[j].StartsWith('+') || commands[i].Data[j].StartsWith(','))
+ if (commands[i].Data[j].StartsWith("+") || commands[i].Data[j].StartsWith(","))
{
commands[i].Data[j] = commands[i].Data[j][0] + Target;
}
@@ -1912,7 +1912,7 @@ namespace CLPS2C_Compiler

for (i = i + 1; i < command.Data.Count; i++)
{
- if (!command.Data[i].StartsWith('+'))
+ if (!command.Data[i].StartsWith("+"))
{
break;
}
@@ -1940,12 +1940,12 @@ namespace CLPS2C_Compiler

for (i = i + 1; i < command.Data.Count; i++)
{
- if (command.Data[i].StartsWith(','))
+ if (command.Data[i].StartsWith(","))
{
ListOffs.Add(TmpAddress.ToString("X8"));
TmpAddress = 0;
}
- else if (!command.Data[i].StartsWith('+'))
+ else if (!command.Data[i].StartsWith("+"))
{
ListOffs.Add(TmpAddress.ToString("X8"));
TmpAddress = 0;
@@ -1980,7 +1980,7 @@ namespace CLPS2C_Compiler

for (i = i + 1; i < command.Data.Count; i++)
{
- if (!command.Data[i].StartsWith('+'))
+ if (!command.Data[i].StartsWith("+"))
{
break;
}
@@ -2008,7 +2008,7 @@ namespace CLPS2C_Compiler

for (i = i + 1; i < command.Data.Count; i++)
{
- if (!command.Data[i].StartsWith('+'))
+ if (!command.Data[i].StartsWith("+"))
{
break;
}
@@ -2040,7 +2040,7 @@ namespace CLPS2C_Compiler
{
string Value = "";
uint Sum = 0;
- if (command.Data[i].StartsWith('"'))
+ if (command.Data[i].StartsWith("\""))
{
// string
Value = command.Data[i];
@@ -2059,7 +2059,7 @@ namespace CLPS2C_Compiler
for (i = i + 1; i < command.Data.Count; i++)
{
string Element = command.Data[i];
- if (!Element.StartsWith('+') || Element == "+")
+ if (!Element.StartsWith("+") || Element == "+")
{
// without +, or just '+'
SetError(ERROR.WRONG_SYNTAX, command);
@@ -2072,7 +2072,7 @@ namespace CLPS2C_Compiler
// string
if (Sum > 0)
{
- if (Value.EndsWith('"'))
+ if (Value.EndsWith("\""))
{
Value = Value.TrimEnd('"') + Sum.ToString() + '"';
}
@@ -2089,7 +2089,7 @@ namespace CLPS2C_Compiler
return "";
}
string Tmp = GetSubstringInQuotes(Element, false);
- if (Value.EndsWith('"'))
+ if (Value.EndsWith("\""))
{
Value = Value.TrimEnd('"') + Tmp + '"';
}
@@ -2112,7 +2112,7 @@ namespace CLPS2C_Compiler

if (Sum > 0)
{
- if (Value.EndsWith('"'))
+ if (Value.EndsWith("\""))
{
Value = Value.TrimEnd('"') + Sum.ToString() + '"';
}
diff --git a/CLPS2C-Compiler/Util.cs b/CLPS2C-Compiler/Util.cs
index 4560c73..7f82ae6 100644
--- a/CLPS2C-Compiler/CLPS2C-Compiler/Util.cs
+++ b/CLPS2C-Compiler/CLPS2C-Compiler/Util.cs
@@ -48,7 +48,7 @@ namespace CLPS2C_Compiler
// ([^ \t\n\r\f\v(+,]+) - Any other word. This is \S, and '(', '+', ','
MatchCollection Matches = Regex.Matches(line, @"(\(.*\))|(""(?:\\.|[^""])*""?)|(\+\s*((""(?:\\.|[^""])*""?)|([^+""]+?))?(?=\+|$| |,))|(,(""?)([^,""]+?)\8(?=,|$| |\+))|([^ \t\n\r\f\v(+,]+)");
Type = Matches[0].Value.ToUpper();
- Data = Matches.Skip(1).Take(Matches.Count - 1).Select(item => item.Value).ToList(); // Data has every word except first
+ Data = Matches.Cast<Match>().Skip(1).Take(Matches.Count - 1).Select(item => item.Value).ToList(); // Data has every word except first
}

public void AppendToTraceback(string file, string fullLine, int lineIdx)
@@ -165,7 +165,7 @@ namespace CLPS2C_Compiler
else
{
// It's a comment, count new lines
- int newLinesCount = match.Value.Split(Program._newLine).Length - 1;
+ int newLinesCount = match.Value.Split(new string[] { Program._newLine }, StringSplitOptions.None).Length - 1;
return string.Concat(Enumerable.Repeat(Program._newLine, newLinesCount));
}
});
@@ -486,7 +486,7 @@ namespace CLPS2C_Compiler
for (int i = 0; i < Output.Count; i++)
{
string Element = Output[i];
- if (Element.StartsWith('+'))
+ if (Element.StartsWith("+"))
{
Element = Element.Substring(1).TrimStart();
}
@@ -496,7 +496,7 @@ namespace CLPS2C_Compiler
List<string> RecursiveValues = GetSetValueFromTarget(Element, SetID, listSets);
if (RecursiveValues.Count != 0)
{
- if (Output[i].StartsWith('+'))
+ if (Output[i].StartsWith("+"))
{
RecursiveValues[0] = "+" + RecursiveValues[0];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/CLPS2C-Compiler/Program.cs b/CLPS2C-Compiler/Program.cs
index 6991896..fe8cd5f 100644
--- a/CLPS2C-Compiler/CLPS2C-Compiler/Program.cs
+++ b/CLPS2C-Compiler/CLPS2C-Compiler/Program.cs
@@ -90,10 +90,6 @@ namespace CLPS2C_Compiler
}
else if (OutputLines.Count != 0)
{
- if (OutputLines[0].StartsWith(_newLine))
- {
- OutputLines[0] = OutputLines[0].Substring(2);
- }
Output += string.Join("", OutputLines);

// Convert to PNACH Format
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/bindings/csharp/Keystone.Net/Keystone.Net.csproj b/bindings/csharp/Keystone.Net/Keystone.Net.csproj
index 04801b4..4c6fe15 100644
--- a/keystone/bindings/csharp/Keystone.Net/Keystone.Net.csproj
+++ b/keystone/bindings/csharp/Keystone.Net/Keystone.Net.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
- <TargetFramework>netstandard2.0</TargetFramework>
+ <TargetFramework>net8.0</TargetFramework>
<RootNamespace>Keystone</RootNamespace>

<Version>1.1.0</Version>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/CLPS2C-Compiler/CLPS2C-Compiler.csproj b/CLPS2C-Compiler/CLPS2C-Compiler.csproj
index 867533e..80f7923 100644
--- a/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj
+++ b/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj
@@ -6,7 +6,6 @@
<RootNamespace>CLPS2C_Compiler</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
- <PlatformTarget>x86</PlatformTarget>
<ApplicationIcon>256x256.ico</ApplicationIcon>
<Version>1.0.1</Version>
</PropertyGroup>
12 changes: 12 additions & 0 deletions pkgs/by-name/cl/clps2c-compiler/patches/set_langversion.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/CLPS2C-Compiler/CLPS2C-Compiler.csproj b/CLPS2C-Compiler/CLPS2C-Compiler.csproj
index 867533e..34b30a4 100644
--- a/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj
+++ b/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj
@@ -5,6 +5,7 @@
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>CLPS2C_Compiler</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
+ <LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<PlatformTarget>x86</PlatformTarget>
<ApplicationIcon>256x256.ico</ApplicationIcon>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/CLPS2C-Compiler/CLPS2C-Compiler.csproj b/CLPS2C-Compiler/CLPS2C-Compiler.csproj
index 867533e..ab44095 100644
--- a/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj
+++ b/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj
@@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
+ <RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64</RuntimeIdentifiers>
<RootNamespace>CLPS2C_Compiler</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/CLPS2C-Compiler/CLPS2C-Compiler.csproj b/CLPS2C-Compiler/CLPS2C-Compiler.csproj
index 867533e..17a3aca 100644
--- a/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj
+++ b/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj
@@ -28,16 +29,7 @@
</ItemGroup>

<ItemGroup>
- <Reference Include="Keystone.Net">
- <HintPath>Keystone.Net.dll</HintPath>
- <Private>True</Private>
- </Reference>
- </ItemGroup>
-
- <ItemGroup>
- <None Update="keystone.dll">
- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </None>
+ <ProjectReference Include="..\..\keystone\bindings\csharp\Keystone.Net\Keystone.Net.csproj"/>
</ItemGroup>

0 comments on commit 75c9076

Please sign in to comment.