Skip to content

Commit 4ab46b7

Browse files
Add support for 64-bit scripts;
1 parent dbb814b commit 4ab46b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1123
-404
lines changed

XtractQuery/Logic.Business.Level5ScriptManagement/Logic.Business.Level5ScriptManagement/InternalContract/ILevel5ScriptSyntaxTreeConverter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ namespace Logic.Business.Level5ScriptManagement.InternalContract
1313
[MapException(typeof(Level5SyntaxTreeConverterException))]
1414
public interface ILevel5CodeUnitConverter
1515
{
16-
ScriptFile CreateScriptFile(CodeUnitSyntax tree, ScriptType type);
16+
ScriptFile CreateScriptFile(CodeUnitSyntax tree);
1717
}
1818
}

XtractQuery/Logic.Business.Level5ScriptManagement/Logic.Business.Level5ScriptManagement/Level5CodeUnitConverter.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public Level5CodeUnitConverter(IMethodNameMapper methodNameMapper)
1717
_methodNameMapper = methodNameMapper;
1818
}
1919

20-
public ScriptFile CreateScriptFile(CodeUnitSyntax tree, ScriptType type)
20+
public ScriptFile CreateScriptFile(CodeUnitSyntax tree)
2121
{
2222
var result = new ScriptFile
2323
{
@@ -121,7 +121,7 @@ private void AddPostfixUnaryStatement(ScriptFile result, PostfixUnaryStatementSy
121121
default:
122122
throw CreateException($"Invalid operation {(SyntaxTokenKind)postfixUnaryStatement.Expression.Operation.RawKind} in postfix unary expression.", postfixUnaryStatement.Expression.Location);
123123
}
124-
124+
125125
if (postfixUnaryStatement.Expression.Value is ValueExpressionSyntax { Value: VariableExpressionSyntax variable })
126126
{
127127
int variableSlot = GetVariable(variable);

XtractQuery/Logic.Business.Level5ScriptManagement/Logic.Business.Level5ScriptManagement/Level5ScriptManagementConfigurationValidator.cs

+13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public void Validate(Level5ScriptManagementConfiguration config)
1717

1818
ValidateOperation(config);
1919
ValidateFilePath(config);
20+
ValidatePointerLength(config);
2021
ValidateQueryType(config);
2122
}
2223

@@ -38,6 +39,18 @@ private void ValidateFilePath(Level5ScriptManagementConfiguration config)
3839
throw new Level5ScriptManagementConfigurationValidationException($"File or directory '{Path.GetFullPath(config.FilePath)}' was not found.");
3940
}
4041

42+
private void ValidatePointerLength(Level5ScriptManagementConfiguration config)
43+
{
44+
if (config.Operation != "c")
45+
return;
46+
47+
if (string.IsNullOrWhiteSpace(config.Length))
48+
throw new Level5ScriptManagementConfigurationValidationException("No pointer length was given. Specify a pointer length by using the -l argument.");
49+
50+
if (config.Length != "int" && config.Length != "long")
51+
throw new Level5ScriptManagementConfigurationValidationException($"The pointer length '{config.Length}' is not valid. Use -h to see a list of valid pointer lengths.");
52+
}
53+
4154
private void ValidateQueryType(Level5ScriptManagementConfiguration config)
4255
{
4356
if (config.Operation != "c")

XtractQuery/Logic.Business.Level5ScriptManagement/Logic.Business.Level5ScriptManagement/Level5ScriptManagementWorkflow.cs

+31-13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
7-
using Logic.Business.Level5ScriptManagement.Contract;
1+
using Logic.Business.Level5ScriptManagement.Contract;
82
using Logic.Business.Level5ScriptManagement.InternalContract;
93
using Logic.Domain.CodeAnalysis.Contract.Level5;
104
using Logic.Domain.CodeAnalysis.Contract.Level5.DataClasses;
@@ -168,15 +162,16 @@ private void CreateScript(string filePath)
168162
// Convert to script data
169163
CodeUnitSyntax codeUnit = _scriptParser.ParseCodeUnit(readableScript);
170164

171-
ScriptType type = DetermineScriptType(_config.QueryType);
172-
ScriptFile script = _treeConverter.CreateScriptFile(codeUnit, type);
165+
ScriptFile script = _treeConverter.CreateScriptFile(codeUnit);
166+
script.Length = DeterminePointerLength(_config.Length);
173167

174168
// Write script data
169+
ScriptType type = DetermineScriptType(_config.QueryType);
175170
IScriptWriter scriptWriter = _writerFactory.Create(type);
176171

177172
using Stream newFileStream = File.Create(filePath + ".xq");
178173

179-
scriptWriter.Write(script, newFileStream);
174+
scriptWriter.Write(script, newFileStream, !_config.WithoutCompression);
180175
}
181176

182177
private void DecompressScripts()
@@ -209,15 +204,15 @@ private void DecompressScripts()
209204
private void DecompressScript(string filePath)
210205
{
211206
// Decompress script data
212-
using Stream fileStream = File.OpenRead(_config.FilePath);
207+
using Stream fileStream = File.OpenRead(filePath);
213208

214209
ScriptType type = _typeReader.Peek(fileStream);
215210
IScriptDecompressor decompressor = _decompressorFactory.Create(type);
216211

217212
ScriptContainer container = decompressor.Decompress(fileStream);
218213

219214
// Write script data
220-
using Stream newFileStream = File.Create(_config.FilePath + ".dec");
215+
using Stream newFileStream = File.Create(filePath + ".dec");
221216

222217
IScriptCompressor compressor = _compressorFactory.Create(type);
223218

@@ -264,20 +259,43 @@ private ScriptType DetermineScriptType(string type)
264259
}
265260
}
266261

262+
private PointerLength DeterminePointerLength(string type)
263+
{
264+
switch (type)
265+
{
266+
case "int":
267+
return PointerLength.Int;
268+
269+
case "long":
270+
return PointerLength.Long;
271+
272+
default:
273+
throw new InvalidOperationException($"Unsupported pointer length {type}");
274+
}
275+
}
276+
267277
private void PrintHelp()
268278
{
269279
Console.WriteLine("Following commands exist:");
270280
Console.WriteLine(" -h, --help\t\tShows this help message.");
271281
Console.WriteLine(" -o, --operation\tThe operation to take on the file");
272-
Console.WriteLine(" Valid operations are: e for extraction, c for creation, d for decompression");
273282
Console.WriteLine(" -t, --type\t\tThe type of file given");
274283
Console.WriteLine(" Valid types are: xq32, xseq");
275284
Console.WriteLine(" The type is automatically detected when extracting; This argument will not have any effect on operation 'e'");
285+
Console.WriteLine(" Valid operations are: e for extraction, c for creation, d for decompression");
276286
Console.WriteLine(" -f, --file\t\tThe file to process");
287+
Console.WriteLine(" -n, --no-compression\t[Optional] If the file uses a compression layer");
288+
Console.WriteLine(" This option is automatically detected when extracting; This argument will not have any effect on operation 'e'");
289+
Console.WriteLine(" -l, --length\t\t[Optional]The pointer length given");
290+
Console.WriteLine(" Valid lengths are: int, long");
291+
Console.WriteLine(" Default value is 'int'");
292+
Console.WriteLine(" The length is automatically detected when extracting; This argument will not have any effect on operation 'e'");
277293
Console.WriteLine();
278294
Console.WriteLine("Examples:");
279295
Console.WriteLine($"\tExtract any script to human readable text: {Environment.ProcessPath} -o e -f Path/To/File.xq");
280296
Console.WriteLine($"\tCreate a xq32 script from human readable text: {Environment.ProcessPath} -o c -t xq32 -f Path/To/File.txt");
297+
Console.WriteLine($"\tCreate a xq32 script with long pointers from human readable text: {Environment.ProcessPath} -o c -t xq32 -l long -f Path/To/File.txt");
298+
Console.WriteLine($"\tCreate a xq32 script without a compression layer from human readable text: {Environment.ProcessPath} -o c -t xq32 -n -f Path/To/File.txt");
281299
}
282300

283301
private Exception GetInnermostException(Exception e)

XtractQuery/Logic.Business.Level5ScriptManagement/Logic.Business.Level5ScriptManagement/_Configuration.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
using CrossCutting.Core.Contract.Configuration.DataClasses;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
72

83
namespace Logic.Business.Level5ScriptManagement
94
{
@@ -18,6 +13,12 @@ public class Level5ScriptManagementConfiguration
1813
[ConfigMap("CommandLine", new[] { "t", "type" })]
1914
public virtual string QueryType { get; set; }
2015

16+
[ConfigMap("CommandLine", new[] { "l", "length" })]
17+
public virtual string Length { get; set; } = "int";
18+
19+
[ConfigMap("CommandLine", new[] { "n", "no-compression" })]
20+
public virtual bool WithoutCompression { get; set; } = false;
21+
2122
[ConfigMap("CommandLine", new[] { "f", "file" })]
2223
public virtual string FilePath { get; set; }
2324

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Logic.Domain.Level5.Contract.Script.DataClasses
2+
{
3+
public enum PointerLength
4+
{
5+
Int,
6+
Long
7+
}
8+
}

XtractQuery/Logic.Domain.Level5/Logic.Domain.Level5.Contract/Script/DataClasses/ScriptFile.cs

+2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ public class ScriptFile
1212
public IList<ScriptJump> Jumps { get; set; }
1313
public IList<ScriptInstruction> Instructions { get; set; }
1414
public IList<ScriptArgument> Arguments { get; set; }
15+
16+
public PointerLength Length { get; set; }
1517
}
1618
}

XtractQuery/Logic.Domain.Level5/Logic.Domain.Level5.Contract/Script/DataClasses/ScriptHeader.cs

-13
This file was deleted.

XtractQuery/Logic.Domain.Level5/Logic.Domain.Level5.Contract/Script/DataClasses/ScriptStringTable.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Logic.Domain.Level5.Contract.Script.DataClasses
99
{
1010
public class ScriptStringTable
1111
{
12-
public CompressionType CompressionType { get; set; }
12+
public CompressionType? CompressionType { get; set; }
1313
public Stream Stream { get; set; }
1414
}
1515
}

XtractQuery/Logic.Domain.Level5/Logic.Domain.Level5.Contract/Script/DataClasses/ScriptTable.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Logic.Domain.Level5.Contract.Script.DataClasses
1010
public class ScriptTable
1111
{
1212
public int EntryCount { get; set; }
13-
public CompressionType CompressionType { get; set; }
13+
public CompressionType? CompressionType { get; set; }
1414
public Stream Stream { get; set; }
1515
}
1616
}

XtractQuery/Logic.Domain.Level5/Logic.Domain.Level5.Contract/Script/IScriptCompressor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Logic.Domain.Level5.Contract.Script
1313
[MapException(typeof(ScriptCompressorException))]
1414
public interface IScriptCompressor
1515
{
16-
void Compress(ScriptContainer container, Stream output);
16+
void Compress(ScriptContainer container, Stream output, bool hasCompression);
1717
void Compress(ScriptContainer container, Stream output, CompressionType compressionType);
1818
}
1919
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Logic.Domain.Level5.Contract.Script.DataClasses;
2+
3+
namespace Logic.Domain.Level5.Contract.Script
4+
{
5+
public interface IScriptEntrySizeProvider
6+
{
7+
int GetFunctionEntrySize(PointerLength length);
8+
int GetJumpEntrySize(PointerLength length);
9+
int GetInstructionEntrySize(PointerLength length);
10+
int GetArgumentEntrySize(PointerLength length);
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Logic.Domain.Level5.Contract.Script.DataClasses;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Logic.Domain.Level5.Contract.Script
9+
{
10+
public interface IScriptEntrySizeProviderFactory
11+
{
12+
IScriptEntrySizeProvider Create(ScriptType type);
13+
}
14+
}

XtractQuery/Logic.Domain.Level5/Logic.Domain.Level5.Contract/Script/IScriptReader.cs

-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
using CrossCutting.Core.Contract.Aspects;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
72
using Logic.Domain.Level5.Contract.Script.Exceptions;
83
using Logic.Domain.Level5.Contract.Script.DataClasses;
94

XtractQuery/Logic.Domain.Level5/Logic.Domain.Level5.Contract/Script/IScriptWriter.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ namespace Logic.Domain.Level5.Contract.Script
1313
[MapException(typeof(ScriptWriterException))]
1414
public interface IScriptWriter
1515
{
16-
void Write(ScriptFile script, Stream output);
16+
void Write(ScriptFile script, Stream output, bool hasCompression);
1717
void Write(ScriptFile script, Stream output, CompressionType compressionType);
18-
void Write(ScriptContainer container, Stream output);
18+
void Write(ScriptContainer container, Stream output, bool hasCompression);
1919
void Write(ScriptContainer container, Stream output, CompressionType compressionType);
2020
}
2121
}

XtractQuery/Logic.Domain.Level5/Logic.Domain.Level5.Contract/Script/Xq32/DataClasses/Xq32Function.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
public struct Xq32Function
44
{
5-
public int nameOffset;
5+
public long nameOffset;
66
public uint crc32;
77
public short instructionOffset;
88
public short instructionEndOffset;

XtractQuery/Logic.Domain.Level5/Logic.Domain.Level5.Contract/Script/Xq32/DataClasses/Xq32Jump.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
public struct Xq32Jump
44
{
5-
public int nameOffset;
5+
public long nameOffset;
66
public uint crc32;
77
public int instructionIndex;
88
}

XtractQuery/Logic.Domain.Level5/Logic.Domain.Level5.Contract/Script/Xq32/IXq32ScriptReader.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ namespace Logic.Domain.Level5.Contract.Script.Xq32
88
[MapException(typeof(Xq32ScriptReaderException))]
99
public interface IXq32ScriptReader : IScriptReader
1010
{
11-
IReadOnlyList<Xq32Function> ReadFunctions(Stream functionStream, int entryCount);
12-
IReadOnlyList<Xq32Jump> ReadJumps(Stream jumpStream, int entryCount);
13-
IReadOnlyList<Xq32Instruction> ReadInstructions(Stream instructionStream, int entryCount);
14-
IReadOnlyList<Xq32Argument> ReadArguments(Stream argumentStream, int entryCount);
11+
IReadOnlyList<Xq32Function> ReadFunctions(Stream functionStream, int entryCount, PointerLength length);
12+
IReadOnlyList<Xq32Jump> ReadJumps(Stream jumpStream, int entryCount, PointerLength length);
13+
IReadOnlyList<Xq32Instruction> ReadInstructions(Stream instructionStream, int entryCount, PointerLength length);
14+
IReadOnlyList<Xq32Argument> ReadArguments(Stream argumentStream, int entryCount, PointerLength length);
1515

1616
IList<ScriptFunction> CreateFunctions(IReadOnlyList<Xq32Function> functions, ScriptStringTable? stringTable = null);
1717
IList<ScriptJump> CreateJumps(IReadOnlyList<Xq32Jump> jumps, ScriptStringTable? stringTable = null);
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using CrossCutting.Core.Contract.Aspects;
2+
using Logic.Domain.Level5.Contract.Script.DataClasses;
23
using Logic.Domain.Level5.Contract.Script.Xq32.DataClasses;
34
using Logic.Domain.Level5.Contract.Script.Xq32.Exceptions;
45

@@ -7,9 +8,9 @@ namespace Logic.Domain.Level5.Contract.Script.Xq32
78
[MapException(typeof(Xq32ScriptWriterException))]
89
public interface IXq32ScriptWriter : IScriptWriter
910
{
10-
void WriteFunctions(IReadOnlyList<Xq32Function> functions, Stream output);
11-
void WriteJumps(IReadOnlyList<Xq32Jump> jumps, Stream output);
12-
void WriteInstructions(IReadOnlyList<Xq32Instruction> instructions, Stream output);
13-
void WriteArguments(IReadOnlyList<Xq32Argument> arguments, Stream output);
11+
void WriteFunctions(IReadOnlyList<Xq32Function> functions, Stream output, PointerLength length);
12+
void WriteJumps(IReadOnlyList<Xq32Jump> jumps, Stream output, PointerLength length);
13+
void WriteInstructions(IReadOnlyList<Xq32Instruction> instructions, Stream output, PointerLength length);
14+
void WriteArguments(IReadOnlyList<Xq32Argument> arguments, Stream output, PointerLength length);
1415
}
1516
}

XtractQuery/Logic.Domain.Level5/Logic.Domain.Level5.Contract/Script/Xseq/DataClasses/XseqFunction.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
public struct XseqFunction
44
{
5-
public int nameOffset;
5+
public long nameOffset;
66
public ushort crc16;
77
public short instructionOffset;
88
public short instructionEndOffset;

XtractQuery/Logic.Domain.Level5/Logic.Domain.Level5.Contract/Script/Xseq/DataClasses/XseqJump.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
public struct XseqJump
44
{
5-
public int nameOffset;
5+
public long nameOffset;
66
public ushort crc16;
77
public short instructionIndex;
88
}

XtractQuery/Logic.Domain.Level5/Logic.Domain.Level5.Contract/Script/Xseq/IXseqScriptReader.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ namespace Logic.Domain.Level5.Contract.Script.Xseq
88
[MapException(typeof(XseqScriptReaderException))]
99
public interface IXseqScriptReader : IScriptReader
1010
{
11-
IReadOnlyList<XseqFunction> ReadFunctions(Stream functionStream, int entryCount);
12-
IReadOnlyList<XseqJump> ReadJumps(Stream jumpStream, int entryCount);
13-
IReadOnlyList<XseqInstruction> ReadInstructions(Stream instructionStream, int entryCount);
14-
IReadOnlyList<XseqArgument> ReadArguments(Stream argumentStream, int entryCount);
11+
IReadOnlyList<XseqFunction> ReadFunctions(Stream functionStream, int entryCount, PointerLength length);
12+
IReadOnlyList<XseqJump> ReadJumps(Stream jumpStream, int entryCount, PointerLength length);
13+
IReadOnlyList<XseqInstruction> ReadInstructions(Stream instructionStream, int entryCount, PointerLength length);
14+
IReadOnlyList<XseqArgument> ReadArguments(Stream argumentStream, int entryCount, PointerLength length);
1515

1616
IList<ScriptFunction> CreateFunctions(IReadOnlyList<XseqFunction> functions, ScriptStringTable? stringTable = null);
17-
IList<ScriptJump> ReadJumps(IReadOnlyList<XseqJump> jumps, ScriptStringTable? stringTable = null);
18-
IList<ScriptInstruction> ReadInstructions(IReadOnlyList<XseqInstruction> instructions);
19-
IList<ScriptArgument> ReadArguments(IReadOnlyList<XseqArgument> arguments, ScriptStringTable? stringTable = null);
17+
IList<ScriptJump> CreateJumps(IReadOnlyList<XseqJump> jumps, ScriptStringTable? stringTable = null);
18+
IList<ScriptInstruction> CreateInstructions(IReadOnlyList<XseqInstruction> instructions);
19+
IList<ScriptArgument> CreateArguments(IReadOnlyList<XseqArgument> arguments, ScriptStringTable? stringTable = null);
2020
}
2121
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using CrossCutting.Core.Contract.Aspects;
2+
using Logic.Domain.Level5.Contract.Script.DataClasses;
23
using Logic.Domain.Level5.Contract.Script.Xseq.DataClasses;
34
using Logic.Domain.Level5.Contract.Script.Xseq.Exceptions;
45

@@ -7,9 +8,9 @@ namespace Logic.Domain.Level5.Contract.Script.Xseq
78
[MapException(typeof(XseqScriptWriterException))]
89
public interface IXseqScriptWriter : IScriptWriter
910
{
10-
void WriteFunctions(IReadOnlyList<XseqFunction> functions, Stream output);
11-
void WriteJumps(IReadOnlyList<XseqJump> jumps, Stream output);
12-
void WriteInstructions(IReadOnlyList<XseqInstruction> instructions, Stream output);
13-
void WriteArguments(IReadOnlyList<XseqArgument> arguments, Stream output);
11+
void WriteFunctions(IReadOnlyList<XseqFunction> functions, Stream output, PointerLength length);
12+
void WriteJumps(IReadOnlyList<XseqJump> jumps, Stream output, PointerLength length);
13+
void WriteInstructions(IReadOnlyList<XseqInstruction> instructions, Stream output, PointerLength length);
14+
void WriteArguments(IReadOnlyList<XseqArgument> arguments, Stream output, PointerLength length);
1415
}
1516
}

0 commit comments

Comments
 (0)