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