mirror of
https://github.com/creeperlv/SVM.git
synced 2026-01-11 04:49:53 +00:00
Working on the assembler.
This commit is contained in:
@@ -15,7 +15,7 @@ Match:
|
|||||||
|
|
||||||
D [0-9]
|
D [0-9]
|
||||||
Number {D}+
|
Number {D}+
|
||||||
InstMath math
|
InstMath bmath
|
||||||
InstCvt cvt
|
InstCvt cvt
|
||||||
InstSystem system
|
InstSystem system
|
||||||
InstSys sys
|
InstSys sys
|
||||||
@@ -23,11 +23,11 @@ InstSD sd
|
|||||||
Register \${D}+
|
Register \${D}+
|
||||||
LabelCode \.code\:
|
LabelCode \.code\:
|
||||||
LabelData \.data\:
|
LabelData \.data\:
|
||||||
\.const\:
|
LabelConst \.const\:
|
||||||
string "".*""
|
|
||||||
word \w*
|
word \w*
|
||||||
GenericLabel {word}\:
|
GenericLabel {word}\:
|
||||||
LineEnd \n
|
LineEnd \n
|
||||||
|
string "".*""
|
||||||
|
|
||||||
OpAdd add
|
OpAdd add
|
||||||
OpSub sub
|
OpSub sub
|
||||||
@@ -62,6 +62,10 @@ LabelConstant InternalLbl
|
|||||||
{
|
{
|
||||||
definition.Substitute();
|
definition.Substitute();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Lexer Definition load failed.");
|
||||||
|
}
|
||||||
|
|
||||||
ISA = isaDefinition;
|
ISA = isaDefinition;
|
||||||
}
|
}
|
||||||
@@ -115,10 +119,14 @@ LabelConstant InternalLbl
|
|||||||
{
|
{
|
||||||
return operationResult;
|
return operationResult;
|
||||||
}
|
}
|
||||||
if (!ISA.InstructionDefinitionAliases.TryGetValue(LexDef.LexMatchedItemId, out var instructionDef))
|
if (!ISA.InstructionDefinitionAliases.TryGetValue(LexDef.Content ?? "", out var instructionDef))
|
||||||
{
|
{
|
||||||
|
Console.WriteLine($"Cannot find matching instruction:{LexDef.Content}");
|
||||||
|
operationResult.AddError(new Error());
|
||||||
return operationResult;
|
return operationResult;
|
||||||
}
|
}
|
||||||
|
Console.WriteLine($"Found:{instructionDef.PrimaryInstruction}");
|
||||||
|
intermediateInstruction.inst = instructionDef.PrimaryInstruction;
|
||||||
foreach (var item in instructionDef.ParameterPattern)
|
foreach (var item in instructionDef.ParameterPattern)
|
||||||
{
|
{
|
||||||
var next = Lex(lexer);
|
var next = Lex(lexer);
|
||||||
@@ -140,12 +148,14 @@ LabelConstant InternalLbl
|
|||||||
}
|
}
|
||||||
intermediateInstruction.Parameters.Add(next.Result);
|
intermediateInstruction.Parameters.Add(next.Result);
|
||||||
}
|
}
|
||||||
|
Console.WriteLine($"Parsed:{intermediateInstruction.inst}");
|
||||||
return intermediateInstruction;
|
return intermediateInstruction;
|
||||||
}
|
}
|
||||||
public OperationResult<IntermediateObject> AssembleIntermediateObject(string input, string ID = "main.asm")
|
public OperationResult<IntermediateObject> AssembleIntermediateObject(string input, string ID = "main.asm")
|
||||||
{
|
{
|
||||||
StringLexer lexer = new StringLexer();
|
StringLexer lexer = new StringLexer();
|
||||||
lexer.SetDefinition(definition);
|
lexer.SetDefinition(definition);
|
||||||
|
Console.WriteLine(input);
|
||||||
lexer.Content = input;
|
lexer.Content = input;
|
||||||
lexer.SourceID = ID;
|
lexer.SourceID = ID;
|
||||||
OperationResult<IntermediateObject> operationResult = new OperationResult<IntermediateObject>(new IntermediateObject());
|
OperationResult<IntermediateObject> operationResult = new OperationResult<IntermediateObject>(new IntermediateObject());
|
||||||
@@ -153,6 +163,7 @@ LabelConstant InternalLbl
|
|||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
var lexResult = Lex(lexer);
|
var lexResult = Lex(lexer);
|
||||||
|
Console.WriteLine($"{lexResult.Result?.Content ?? "<null>"}");
|
||||||
if (lexResult.Result == null) break;
|
if (lexResult.Result == null) break;
|
||||||
var r = lexResult.Result;
|
var r = lexResult.Result;
|
||||||
switch (r.LexSegmentId)
|
switch (r.LexSegmentId)
|
||||||
@@ -178,9 +189,10 @@ LabelConstant InternalLbl
|
|||||||
{
|
{
|
||||||
case InternalLabel.Code:
|
case InternalLabel.Code:
|
||||||
{
|
{
|
||||||
|
Console.WriteLine($"Code Seg:{r.Content}");
|
||||||
OperationResult<IntermediateInstruction?> instR = r.LexSegmentId switch
|
OperationResult<IntermediateInstruction?> instR = r.LexSegmentId switch
|
||||||
{
|
{
|
||||||
"GenericLabel" => ParseInstruction(lexer, r, r),
|
"LblG" => ParseInstruction(lexer, r, r),
|
||||||
_ => ParseInstruction(lexer, r, null),
|
_ => ParseInstruction(lexer, r, null),
|
||||||
};
|
};
|
||||||
if (operationResult.CheckAndInheritErrorAndWarnings(instR))
|
if (operationResult.CheckAndInheritErrorAndWarnings(instR))
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ namespace SVM.Assembler.Core
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Console.WriteLine($"Definition of: {pi}");
|
||||||
instDefinition.PrimaryInstruction = pi;
|
instDefinition.PrimaryInstruction = pi;
|
||||||
foreach (XmlNode item in node.ChildNodes)
|
foreach (XmlNode item in node.ChildNodes)
|
||||||
{
|
{
|
||||||
@@ -163,6 +164,11 @@ namespace SVM.Assembler.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
definition.InstructionDefinitions.Add(pi, instDefinition);
|
definition.InstructionDefinitions.Add(pi, instDefinition);
|
||||||
|
foreach (var item in instDefinition.Aliases)
|
||||||
|
{
|
||||||
|
|
||||||
|
definition.InstructionDefinitionAliases.Add(item, instDefinition);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
static bool ParseDefinitions(XmlNode node, ref ISADefinition definition)
|
static bool ParseDefinitions(XmlNode node, ref ISADefinition definition)
|
||||||
|
|||||||
Reference in New Issue
Block a user