Class PCodeSerializer
- Namespace
- Pl0.Core
- Assembly
- Pl0.Core.dll
Serializes and parses P-Code in text form.
public static class PCodeSerializer
- Inheritance
-
PCodeSerializer
- Inherited Members
Fields
DefaultMaximumInstructionCount
private const int DefaultMaximumInstructionCount = 10000
Field Value
MaximumAcceptedInstructionCount
private const int MaximumAcceptedInstructionCount = 100000
Field Value
MaximumLineLength
private const int MaximumLineLength = 4096
Field Value
MaximumTextLength
private const int MaximumTextLength = 1048576
Field Value
Methods
Parse(TextReader, int)
Liest P-Code zeilenweise mit einer festen Befehlsgrenze ein. Parses P-Code line by line with a fixed instruction limit.
public static IReadOnlyList<Instruction> Parse(TextReader reader, int maximumInstructionCount = 10000)
Parameters
readerTextReaderTextquelle. / Text source.
maximumInstructionCountintMaximale Befehlsanzahl. / Maximum instruction count.
Returns
- IReadOnlyList<Instruction>
Die eingelesene Befehlsliste. / The parsed instruction list.
Exceptions
- ArgumentOutOfRangeException
Die Grenze liegt außerhalb des unterstützten Bereichs. / The limit is outside the supported range.
- FormatException
Der Text ist ungültig oder überschreitet eine Grenze. / The text is invalid or exceeds a limit.
Parse(string)
Liest P-Code-Text als Befehlsfolge ein.
Parses P-Code text into instructions.
public static IReadOnlyList<Instruction> Parse(string text)
Parameters
textstringDer Eingabetext mit P-Code. / Input text containing P-Code.
Returns
- IReadOnlyList<Instruction>
Die eingelesene Befehlsliste. / The parsed instruction list.
Exceptions
- FormatException
Eine nicht leere Zeile besitzt kein gültiges Opcode-, Ebenen- oder Argumentformat. / A non-empty line has no valid opcode, level, or argument format.
ParseInt(string, int, string)
Parses an integer value or throws a formatted exception.
private static int ParseInt(string value, int lineNo, string partName)
Parameters
valuestringText to parse.
lineNointLine number for error reporting.
partNamestringName of the parsed part.
Returns
- int
Parsed integer.
ParseOpcode(string, int)
Parses an opcode from mnemonic or numeric form.
private static Opcode ParseOpcode(string value, int lineNo)
Parameters
Returns
- Opcode
The parsed opcode.
ReadBoundedLine(TextReader, int, ref int)
private static string? ReadBoundedLine(TextReader reader, int maximumLength, ref int charactersRead)
Parameters
readerTextReadermaximumLengthintcharactersReadint
Returns
SafeDiagnosticValue(string)
private static string SafeDiagnosticValue(string value)
Parameters
valuestring
Returns
StripComment(string)
Removes // comments from a line.
private static string StripComment(string line)
Parameters
linestringInput line.
Returns
- string
Line content without comments.
ToAsm(IReadOnlyList<Instruction>)
Wandelt Befehle in das mnemonische Assemblerformat um.
Converts instructions to mnemonic assembly format.
public static string ToAsm(IReadOnlyList<Instruction> instructions)
Parameters
instructionsIReadOnlyList<Instruction>Die zu serialisierenden Befehle. / Instructions to serialize.
Returns
- string
Assemblertext mit einem Befehl pro Zeile. / Assembly text with one instruction per line.
Exceptions
- ArgumentOutOfRangeException
Ein Befehl enthält einen nicht unterstützten Opcode. / An instruction contains an unsupported opcode.
ToCod(IReadOnlyList<Instruction>)
Converts instructions to numeric opcode format.
public static string ToCod(IReadOnlyList<Instruction> instructions)
Parameters
instructionsIReadOnlyList<Instruction>Instructions to serialize.
Returns
- string
Numeric opcode text with one instruction per line.
ToMnemonic(Opcode)
Converts an opcode to its mnemonic form.
private static string ToMnemonic(Opcode opcode)
Parameters
opcodeOpcodeOpcode to convert.
Returns
- string
Mnemonic string.