diff --git a/src/SVM.Assembler.Core/Assembler.cs b/src/SVM.Assembler.Core/Assembler.cs index a9d0c17..bbc4fd7 100644 --- a/src/SVM.Assembler.Core/Assembler.cs +++ b/src/SVM.Assembler.Core/Assembler.cs @@ -1,5 +1,8 @@ using LibCLCC.NET.Lexer; +using LibCLCC.NET.Operations; +using SVM.Core; using System; +using System.Collections.Generic; namespace SVM.Assembler.Core { @@ -19,7 +22,10 @@ InstSD sd Register \${D}+ LabelCode \.code\: LabelData \.data\: + \.const\: string "".*"" +word \w* +GenericLabel {word}\: LineEnd \n OpAdd add @@ -42,11 +48,54 @@ OpSub BOp OpMul BOp OpDiv BOp LineEnd LE +GenericLabel LblG +LabelCode InternalLbl +LabelData InternalLbl +LabelConstant InternalLbl "; LexerDefinition? definition; public Assembler() { - LexerDefinition.TryParse(LexDefinition, out definition); + if (LexerDefinition.TryParse(LexDefinition, out definition)) + { + definition.Substitute(); + } + } + public OperationResult Assemble(string input, string ID = "main.asm") + { + StringLexer lexer = new StringLexer(); + lexer.SetDefinition(definition); + lexer.Content = input; + lexer.SourceID = ID; + OperationResult operationResult = new OperationResult(); + while (true) + { + var lexResult = lexer.Lex(); + if (lexResult.Result == null) break; + var r = lexResult.Result; + switch (r.LexSegmentId) + { + case "InternalLbl": + break; + default: + break; + } + } + + return operationResult; } } + [Serializable] + public class IntermediateObject + { + public Dictionary data = new Dictionary(); + public List instructions = new List(); + } + [Serializable] + public class IntermediateInstruction + { + public string? Label = null; + public PrimaryInstruction inst; + public List Parameters = new List(); + } } diff --git a/src/SVM.Core/SVMInstDef.cs b/src/SVM.Core/PrimaryInstruction.cs similarity index 97% rename from src/SVM.Core/SVMInstDef.cs rename to src/SVM.Core/PrimaryInstruction.cs index a66407c..32a741e 100644 --- a/src/SVM.Core/SVMInstDef.cs +++ b/src/SVM.Core/PrimaryInstruction.cs @@ -1,6 +1,6 @@ namespace SVM.Core { - public enum SVMInstDef : byte + public enum PrimaryInstruction : byte { // 0 1 2 3 4 5 6 // Math [I]Op [I]Type [R]L [R]R [R]T [I]CheckOF diff --git a/src/SVM.Core/SimpleVirtualMachine.cs b/src/SVM.Core/SimpleVirtualMachine.cs index ff6019d..9325f5b 100644 --- a/src/SVM.Core/SimpleVirtualMachine.cs +++ b/src/SVM.Core/SimpleVirtualMachine.cs @@ -72,7 +72,7 @@ namespace SVM.Core switch (def) { - case SVMInstDef.BMath: + case PrimaryInstruction.BMath: { var Op = Instruction.GetData(1); var NativeType = Instruction.GetData(2); @@ -102,16 +102,16 @@ namespace SVM.Core } } break; - case SVMInstDef.UMath: + case PrimaryInstruction.UMath: break; - case SVMInstDef.Cvt: + case PrimaryInstruction.Cvt: { Convert(Instruction); } break; - case SVMInstDef.Cmp: + case PrimaryInstruction.Cmp: break; - case SVMInstDef.SD: + case PrimaryInstruction.SD: { var Reg = Instruction.GetData(1); PC++; @@ -120,19 +120,19 @@ namespace SVM.Core registers.SetData(Reg, data); } break; - case SVMInstDef.JAL: + case PrimaryInstruction.JAL: break; - case SVMInstDef.JALF: + case PrimaryInstruction.JALF: break; - case SVMInstDef.Load: + case PrimaryInstruction.Load: break; - case SVMInstDef.Save: + case PrimaryInstruction.Save: break; - case SVMInstDef.Call: + case PrimaryInstruction.Call: break; - case SVMInstDef.Return: + case PrimaryInstruction.Return: break; - case SVMInstDef.System: + case PrimaryInstruction.System: if (Config != null) { var target = Instruction.GetData(1); @@ -142,7 +142,7 @@ namespace SVM.Core } } break; - case SVMInstDef.SIMD: + case PrimaryInstruction.SIMD: break; default: break; @@ -351,11 +351,11 @@ namespace SVM.Core return ((T*)(((byte*)dataPtr) + offset))[0]; } } - public SVMInstDef GetDef() + public PrimaryInstruction GetDef() { fixed (ulong* dataPtr = &data) { - return ((SVMInstDef*)dataPtr)[0]; + return ((PrimaryInstruction*)dataPtr)[0]; } } }