Skip to content

Commit 75c9076

Browse files
authored
clps2c-compiler: init at 1.0.1 (#339716)
2 parents 654de93 + 1c18250 commit 75c9076

File tree

9 files changed

+363
-0
lines changed

9 files changed

+363
-0
lines changed

pkgs/by-name/cl/clps2c-compiler/deps.nix

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
keystone,
3+
fetchFromGitHub,
4+
buildDotnetModule,
5+
dotnetCorePackages,
6+
lib,
7+
}:
8+
let
9+
version = "1.0.1";
10+
pname = "CLPS2C-Compiler";
11+
owner = "NiV-L-A";
12+
keystone-rev = "MIPS-0.9.2";
13+
keystone-sha256 = "sha256-xLkO06ZgnmAavJMP1kjDwXT1hc5eSDXv+4MUkOz6xeo=";
14+
keystone-src = (
15+
fetchFromGitHub {
16+
name = "keystone";
17+
inherit owner;
18+
repo = "keystone";
19+
rev = keystone-rev;
20+
sha256 = keystone-sha256;
21+
}
22+
);
23+
keystone-override = keystone.overrideAttrs (old: {
24+
src = keystone-src;
25+
});
26+
in
27+
buildDotnetModule rec {
28+
inherit version pname;
29+
30+
srcs = [
31+
(fetchFromGitHub {
32+
name = pname;
33+
inherit owner;
34+
repo = pname;
35+
rev = "CLPS2C-Compiler-${version}";
36+
sha256 = "sha256-4gLdrIxyw9BFSxF+EXZqTgUf9Kik6oK7eO9HBUzk4QM=";
37+
})
38+
keystone-src
39+
];
40+
41+
sourceRoot = ".";
42+
43+
patches = [
44+
./patches/dont_trim_leading_newline.patch
45+
./patches/build_fixes.patch
46+
./patches/remove_platformtarget.patch
47+
./patches/use_compiled_keystone.patch
48+
./patches/set_langversion.patch
49+
./patches/set_runtimeidentifiers.patch
50+
./patches/keystone_set_targetframework.patch
51+
];
52+
53+
dotnet-sdk = dotnetCorePackages.sdk_8_0;
54+
dotnet-runtime = dotnetCorePackages.runtime_8_0;
55+
56+
dotnetFlags = [
57+
"-p:TargetFramework=net8.0"
58+
];
59+
60+
nugetDeps = ./deps.nix;
61+
62+
runtimeDeps = [
63+
keystone-override
64+
];
65+
66+
projectFile = "CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj";
67+
68+
meta = {
69+
homepage = "https://github.com/NiV-L-A/CLPS2C-Compiler";
70+
description = "Compiler for CLPS2C, a domain-specific language built specifically for writing PS2 cheat codes";
71+
mainProgram = "CLPS2C-Compiler";
72+
maintainers = [ lib.maintainers.gigahawk ];
73+
license = lib.licenses.gpl3Only;
74+
};
75+
}
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
diff --git a/CLPS2C-Compiler/Program.cs b/CLPS2C-Compiler/Program.cs
2+
index 6991896..a086433 100644
3+
--- a/CLPS2C-Compiler/CLPS2C-Compiler/Program.cs
4+
+++ b/CLPS2C-Compiler/CLPS2C-Compiler/Program.cs
5+
@@ -1166,7 +1166,7 @@ namespace CLPS2C_Compiler
6+
string Value_1 = "";
7+
string Value_2 = "";
8+
// Handle a bit differently in case there's a label at the start
9+
- if (command.Type.EndsWith(':'))
10+
+ if (command.Type.EndsWith(":"))
11+
{
12+
OpCode = command.Data[0].ToUpper();
13+
Register = command.Data[1];
14+
@@ -1201,7 +1201,7 @@ namespace CLPS2C_Compiler
15+
}
16+
17+
Output = $"lui {Register},0x{Value_1}; {OpCode} {Register},{Value_2}({Register})";
18+
- if (command.Type.EndsWith(':'))
19+
+ if (command.Type.EndsWith(":"))
20+
{
21+
Output = $"{command.FullLine.Substring(0, command.FullLine.IndexOf(':'))}: {Output}";
22+
}
23+
@@ -1589,7 +1589,7 @@ namespace CLPS2C_Compiler
24+
25+
while (IfIndex != -1)
26+
{
27+
- int ExtraIfCount = commands[IfIndex].FullLine.Split("&&", StringSplitOptions.None).Length - 1;
28+
+ int ExtraIfCount = commands[IfIndex].FullLine.Split(new string[] { "&&" }, StringSplitOptions.None).Length - 1;
29+
for (int i = 0; i < ExtraIfCount; i++)
30+
{
31+
// Add more IF commands
32+
@@ -1807,7 +1807,7 @@ namespace CLPS2C_Compiler
33+
for (int j = 0; j < commands[i].Data.Count; j++)
34+
{
35+
string Target = commands[i].Data[j];
36+
- if (Target.StartsWith('+') || Target.StartsWith(','))
37+
+ if (Target.StartsWith("+") || Target.StartsWith(","))
38+
{
39+
Target = Target.Substring(1).TrimStart();
40+
}
41+
@@ -1815,14 +1815,14 @@ namespace CLPS2C_Compiler
42+
if (IsVarDeclared(Target, listSets))
43+
{
44+
List<string> ListValues = GetSetValueFromTarget(Target, commands[i].ID, listSets);
45+
- if (commands[i].Data[j].StartsWith('+') || commands[i].Data[j].StartsWith(','))
46+
+ if (commands[i].Data[j].StartsWith("+") || commands[i].Data[j].StartsWith(","))
47+
{
48+
ListValues[0] = commands[i].Data[j][0] + ListValues[0];
49+
}
50+
51+
for (int k = 1; k < ListValues.Count; k++)
52+
{
53+
- if (ListValues[k].StartsWith('+') || ListValues[k].StartsWith(','))
54+
+ if (ListValues[k].StartsWith("+") || ListValues[k].StartsWith(","))
55+
{
56+
ListValues[k] = ListValues[k][0] + ListValues[k].Substring(1).TrimStart();
57+
}
58+
@@ -1834,7 +1834,7 @@ namespace CLPS2C_Compiler
59+
continue;
60+
}
61+
62+
- if (commands[i].Data[j].StartsWith('+') || commands[i].Data[j].StartsWith(','))
63+
+ if (commands[i].Data[j].StartsWith("+") || commands[i].Data[j].StartsWith(","))
64+
{
65+
commands[i].Data[j] = commands[i].Data[j][0] + Target;
66+
}
67+
@@ -1912,7 +1912,7 @@ namespace CLPS2C_Compiler
68+
69+
for (i = i + 1; i < command.Data.Count; i++)
70+
{
71+
- if (!command.Data[i].StartsWith('+'))
72+
+ if (!command.Data[i].StartsWith("+"))
73+
{
74+
break;
75+
}
76+
@@ -1940,12 +1940,12 @@ namespace CLPS2C_Compiler
77+
78+
for (i = i + 1; i < command.Data.Count; i++)
79+
{
80+
- if (command.Data[i].StartsWith(','))
81+
+ if (command.Data[i].StartsWith(","))
82+
{
83+
ListOffs.Add(TmpAddress.ToString("X8"));
84+
TmpAddress = 0;
85+
}
86+
- else if (!command.Data[i].StartsWith('+'))
87+
+ else if (!command.Data[i].StartsWith("+"))
88+
{
89+
ListOffs.Add(TmpAddress.ToString("X8"));
90+
TmpAddress = 0;
91+
@@ -1980,7 +1980,7 @@ namespace CLPS2C_Compiler
92+
93+
for (i = i + 1; i < command.Data.Count; i++)
94+
{
95+
- if (!command.Data[i].StartsWith('+'))
96+
+ if (!command.Data[i].StartsWith("+"))
97+
{
98+
break;
99+
}
100+
@@ -2008,7 +2008,7 @@ namespace CLPS2C_Compiler
101+
102+
for (i = i + 1; i < command.Data.Count; i++)
103+
{
104+
- if (!command.Data[i].StartsWith('+'))
105+
+ if (!command.Data[i].StartsWith("+"))
106+
{
107+
break;
108+
}
109+
@@ -2040,7 +2040,7 @@ namespace CLPS2C_Compiler
110+
{
111+
string Value = "";
112+
uint Sum = 0;
113+
- if (command.Data[i].StartsWith('"'))
114+
+ if (command.Data[i].StartsWith("\""))
115+
{
116+
// string
117+
Value = command.Data[i];
118+
@@ -2059,7 +2059,7 @@ namespace CLPS2C_Compiler
119+
for (i = i + 1; i < command.Data.Count; i++)
120+
{
121+
string Element = command.Data[i];
122+
- if (!Element.StartsWith('+') || Element == "+")
123+
+ if (!Element.StartsWith("+") || Element == "+")
124+
{
125+
// without +, or just '+'
126+
SetError(ERROR.WRONG_SYNTAX, command);
127+
@@ -2072,7 +2072,7 @@ namespace CLPS2C_Compiler
128+
// string
129+
if (Sum > 0)
130+
{
131+
- if (Value.EndsWith('"'))
132+
+ if (Value.EndsWith("\""))
133+
{
134+
Value = Value.TrimEnd('"') + Sum.ToString() + '"';
135+
}
136+
@@ -2089,7 +2089,7 @@ namespace CLPS2C_Compiler
137+
return "";
138+
}
139+
string Tmp = GetSubstringInQuotes(Element, false);
140+
- if (Value.EndsWith('"'))
141+
+ if (Value.EndsWith("\""))
142+
{
143+
Value = Value.TrimEnd('"') + Tmp + '"';
144+
}
145+
@@ -2112,7 +2112,7 @@ namespace CLPS2C_Compiler
146+
147+
if (Sum > 0)
148+
{
149+
- if (Value.EndsWith('"'))
150+
+ if (Value.EndsWith("\""))
151+
{
152+
Value = Value.TrimEnd('"') + Sum.ToString() + '"';
153+
}
154+
diff --git a/CLPS2C-Compiler/Util.cs b/CLPS2C-Compiler/Util.cs
155+
index 4560c73..7f82ae6 100644
156+
--- a/CLPS2C-Compiler/CLPS2C-Compiler/Util.cs
157+
+++ b/CLPS2C-Compiler/CLPS2C-Compiler/Util.cs
158+
@@ -48,7 +48,7 @@ namespace CLPS2C_Compiler
159+
// ([^ \t\n\r\f\v(+,]+) - Any other word. This is \S, and '(', '+', ','
160+
MatchCollection Matches = Regex.Matches(line, @"(\(.*\))|(""(?:\\.|[^""])*""?)|(\+\s*((""(?:\\.|[^""])*""?)|([^+""]+?))?(?=\+|$| |,))|(,(""?)([^,""]+?)\8(?=,|$| |\+))|([^ \t\n\r\f\v(+,]+)");
161+
Type = Matches[0].Value.ToUpper();
162+
- Data = Matches.Skip(1).Take(Matches.Count - 1).Select(item => item.Value).ToList(); // Data has every word except first
163+
+ Data = Matches.Cast<Match>().Skip(1).Take(Matches.Count - 1).Select(item => item.Value).ToList(); // Data has every word except first
164+
}
165+
166+
public void AppendToTraceback(string file, string fullLine, int lineIdx)
167+
@@ -165,7 +165,7 @@ namespace CLPS2C_Compiler
168+
else
169+
{
170+
// It's a comment, count new lines
171+
- int newLinesCount = match.Value.Split(Program._newLine).Length - 1;
172+
+ int newLinesCount = match.Value.Split(new string[] { Program._newLine }, StringSplitOptions.None).Length - 1;
173+
return string.Concat(Enumerable.Repeat(Program._newLine, newLinesCount));
174+
}
175+
});
176+
@@ -486,7 +486,7 @@ namespace CLPS2C_Compiler
177+
for (int i = 0; i < Output.Count; i++)
178+
{
179+
string Element = Output[i];
180+
- if (Element.StartsWith('+'))
181+
+ if (Element.StartsWith("+"))
182+
{
183+
Element = Element.Substring(1).TrimStart();
184+
}
185+
@@ -496,7 +496,7 @@ namespace CLPS2C_Compiler
186+
List<string> RecursiveValues = GetSetValueFromTarget(Element, SetID, listSets);
187+
if (RecursiveValues.Count != 0)
188+
{
189+
- if (Output[i].StartsWith('+'))
190+
+ if (Output[i].StartsWith("+"))
191+
{
192+
RecursiveValues[0] = "+" + RecursiveValues[0];
193+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
diff --git a/CLPS2C-Compiler/Program.cs b/CLPS2C-Compiler/Program.cs
2+
index 6991896..fe8cd5f 100644
3+
--- a/CLPS2C-Compiler/CLPS2C-Compiler/Program.cs
4+
+++ b/CLPS2C-Compiler/CLPS2C-Compiler/Program.cs
5+
@@ -90,10 +90,6 @@ namespace CLPS2C_Compiler
6+
}
7+
else if (OutputLines.Count != 0)
8+
{
9+
- if (OutputLines[0].StartsWith(_newLine))
10+
- {
11+
- OutputLines[0] = OutputLines[0].Substring(2);
12+
- }
13+
Output += string.Join("", OutputLines);
14+
15+
// Convert to PNACH Format
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/bindings/csharp/Keystone.Net/Keystone.Net.csproj b/bindings/csharp/Keystone.Net/Keystone.Net.csproj
2+
index 04801b4..4c6fe15 100644
3+
--- a/keystone/bindings/csharp/Keystone.Net/Keystone.Net.csproj
4+
+++ b/keystone/bindings/csharp/Keystone.Net/Keystone.Net.csproj
5+
@@ -1,7 +1,7 @@
6+
<Project Sdk="Microsoft.NET.Sdk">
7+
8+
<PropertyGroup>
9+
- <TargetFramework>netstandard2.0</TargetFramework>
10+
+ <TargetFramework>net8.0</TargetFramework>
11+
<RootNamespace>Keystone</RootNamespace>
12+
13+
<Version>1.1.0</Version>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/CLPS2C-Compiler/CLPS2C-Compiler.csproj b/CLPS2C-Compiler/CLPS2C-Compiler.csproj
2+
index 867533e..80f7923 100644
3+
--- a/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj
4+
+++ b/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj
5+
@@ -6,7 +6,6 @@
6+
<RootNamespace>CLPS2C_Compiler</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
- <PlatformTarget>x86</PlatformTarget>
10+
<ApplicationIcon>256x256.ico</ApplicationIcon>
11+
<Version>1.0.1</Version>
12+
</PropertyGroup>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/CLPS2C-Compiler/CLPS2C-Compiler.csproj b/CLPS2C-Compiler/CLPS2C-Compiler.csproj
2+
index 867533e..34b30a4 100644
3+
--- a/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj
4+
+++ b/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj
5+
@@ -5,6 +5,7 @@
6+
<TargetFramework>net8.0</TargetFramework>
7+
<RootNamespace>CLPS2C_Compiler</RootNamespace>
8+
<ImplicitUsings>enable</ImplicitUsings>
9+
+ <LangVersion>10.0</LangVersion>
10+
<Nullable>enable</Nullable>
11+
<PlatformTarget>x86</PlatformTarget>
12+
<ApplicationIcon>256x256.ico</ApplicationIcon>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/CLPS2C-Compiler/CLPS2C-Compiler.csproj b/CLPS2C-Compiler/CLPS2C-Compiler.csproj
2+
index 867533e..ab44095 100644
3+
--- a/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj
4+
+++ b/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj
5+
@@ -3,6 +3,7 @@
6+
<PropertyGroup>
7+
<OutputType>Exe</OutputType>
8+
<TargetFramework>net8.0</TargetFramework>
9+
+ <RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64</RuntimeIdentifiers>
10+
<RootNamespace>CLPS2C_Compiler</RootNamespace>
11+
<ImplicitUsings>enable</ImplicitUsings>
12+
<Nullable>enable</Nullable>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
diff --git a/CLPS2C-Compiler/CLPS2C-Compiler.csproj b/CLPS2C-Compiler/CLPS2C-Compiler.csproj
2+
index 867533e..17a3aca 100644
3+
--- a/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj
4+
+++ b/CLPS2C-Compiler/CLPS2C-Compiler/CLPS2C-Compiler.csproj
5+
@@ -28,16 +29,7 @@
6+
</ItemGroup>
7+
8+
<ItemGroup>
9+
- <Reference Include="Keystone.Net">
10+
- <HintPath>Keystone.Net.dll</HintPath>
11+
- <Private>True</Private>
12+
- </Reference>
13+
- </ItemGroup>
14+
-
15+
- <ItemGroup>
16+
- <None Update="keystone.dll">
17+
- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
18+
- </None>
19+
+ <ProjectReference Include="..\..\keystone\bindings\csharp\Keystone.Net\Keystone.Net.csproj"/>
20+
</ItemGroup>

0 commit comments

Comments
 (0)