mirror of
https://github.com/creeperlv/SVM.git
synced 2026-01-10 20:39:54 +00:00
The assembler is partially working now.
This commit is contained in:
@@ -13,7 +13,7 @@ namespace SVM.Assembler.Core
|
||||
@"
|
||||
Match:
|
||||
|
||||
D [0-9]
|
||||
D \d
|
||||
Number {D}+
|
||||
InstMath bmath
|
||||
InstCvt cvt
|
||||
@@ -24,18 +24,14 @@ Register \${D}+
|
||||
LabelCode \.code\:
|
||||
LabelData \.data\:
|
||||
LabelConst \.const\:
|
||||
word \w*
|
||||
word [\w\d]+
|
||||
GenericLabel {word}\:
|
||||
LineEnd \n
|
||||
string "".*""
|
||||
string ""\"".*\""""
|
||||
|
||||
OpAdd add
|
||||
OpSub sub
|
||||
OpMul mul
|
||||
OpDiv div
|
||||
|
||||
Id:
|
||||
|
||||
word Word
|
||||
InstMath inst
|
||||
InstCvt inst
|
||||
InstSystem inst
|
||||
@@ -64,7 +60,6 @@ LabelConstant InternalLbl
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Lexer Definition load failed.");
|
||||
}
|
||||
|
||||
ISA = isaDefinition;
|
||||
@@ -76,10 +71,13 @@ LabelConstant InternalLbl
|
||||
var r = lexer.Lex();
|
||||
if (r.HasError()) return r;
|
||||
if (r.Result == null) return r;
|
||||
|
||||
if (r.Result.LexSegmentId != null && r.Result.LexMatchedItemId != null)
|
||||
{
|
||||
if (r.Result.LexSegmentId == "LE") continue;
|
||||
return r;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
private OperationResult<(string, string)?> ParseKVPair(ILexer lexer, LexSegment currentSeg)
|
||||
@@ -121,11 +119,9 @@ LabelConstant InternalLbl
|
||||
}
|
||||
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)
|
||||
{
|
||||
@@ -148,14 +144,12 @@ 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());
|
||||
@@ -163,7 +157,6 @@ 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)
|
||||
@@ -189,7 +182,6 @@ LabelConstant InternalLbl
|
||||
{
|
||||
case InternalLabel.Code:
|
||||
{
|
||||
Console.WriteLine($"Code Seg:{r.Content}");
|
||||
OperationResult<IntermediateInstruction?> instR = r.LexSegmentId switch
|
||||
{
|
||||
"LblG" => ParseInstruction(lexer, r, r),
|
||||
|
||||
@@ -108,6 +108,7 @@ namespace SVM.Assembler.Core
|
||||
return false;
|
||||
}
|
||||
}
|
||||
instruction.ParameterPattern.Add(parameter);
|
||||
return true;
|
||||
}
|
||||
static bool ParseDefinition(XmlNode node, ref ISADefinition definition)
|
||||
@@ -120,7 +121,6 @@ namespace SVM.Assembler.Core
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Console.WriteLine($"Definition of: {pi}");
|
||||
instDefinition.PrimaryInstruction = pi;
|
||||
foreach (XmlNode item in node.ChildNodes)
|
||||
{
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace SVM.Assembler.Core
|
||||
SVMNativeTypes.Double => sizeof(double),
|
||||
_ => 0,
|
||||
};
|
||||
Buffer.MemoryCopy(dataStart, inst + Pos * sizeof(byte), size, size);
|
||||
Buffer.MemoryCopy(dataStart, ((byte*)inst) + Pos * sizeof(byte), size, size);
|
||||
}
|
||||
public unsafe static bool ParseAndWriteData(SVMInstruction* inst, SVMNativeTypes nativeType, int Pos, string value)
|
||||
{
|
||||
@@ -291,7 +291,6 @@ namespace SVM.Assembler.Core
|
||||
offset += (uint)data2.Length;
|
||||
Data.Add(data);
|
||||
}
|
||||
Console.WriteLine($"Instruction Count:{Obj.instructions.Count}");
|
||||
foreach (var item in Obj.instructions)
|
||||
{
|
||||
if (definition.InstructionDefinitions.TryGetValue(item.inst, out var def))
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LibCLCC.NET" Version="1.34.35" />
|
||||
<PackageReference Include="LibCLCC.NET" Version="1.35.36" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -18,33 +18,33 @@
|
||||
<Parameters>
|
||||
<InstructionParameter>
|
||||
<MatchingItems>
|
||||
<Item Id="String"/>
|
||||
<Item Id="Word"/>
|
||||
</MatchingItems>
|
||||
<ExpectedValue Type="UInt8" Pos="1" Converter="InternalEnum:bOp" />
|
||||
</InstructionParameter>
|
||||
<InstructionParameter>
|
||||
<MatchingItems>
|
||||
<Item Id="String"/>
|
||||
<Item Id="Word"/>
|
||||
</MatchingItems>
|
||||
<ExpectedValue Type="UInt8" Pos="2" Converter="InternalEnum:NativeType" />
|
||||
</InstructionParameter>
|
||||
<InstructionParameter>
|
||||
<MatchingItems>
|
||||
<Item Id="String"/>
|
||||
<Item Id="Word"/>
|
||||
<Item Id="Register"/>
|
||||
</MatchingItems>
|
||||
<ExpectedValue Type="UInt8" Pos="3" Converter="Register" />
|
||||
</InstructionParameter>
|
||||
<InstructionParameter>
|
||||
<MatchingItems>
|
||||
<Item Id="String"/>
|
||||
<Item Id="Word"/>
|
||||
<Item Id="Register"/>
|
||||
</MatchingItems>
|
||||
<ExpectedValue Type="UInt8" Pos="4" Converter="Register" />
|
||||
</InstructionParameter>
|
||||
<InstructionParameter>
|
||||
<MatchingItems>
|
||||
<Item Id="String"/>
|
||||
<Item Id="Word"/>
|
||||
<Item Id="Register"/>
|
||||
</MatchingItems>
|
||||
<ExpectedValue Type="UInt8" Pos="5" Converter="Register" />
|
||||
|
||||
@@ -40,11 +40,6 @@ namespace SVM.Assembler
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in files)
|
||||
{
|
||||
Console.WriteLine(item);
|
||||
}
|
||||
Assembler.Core.Assembler assembler = new Core.Assembler(def);
|
||||
foreach (var item in files)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user