mirror of
https://github.com/creeperlv/SVM.git
synced 2026-01-11 21:09:53 +00:00
Working on the assembler.
This commit is contained in:
@@ -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<IntermediateObject> Assemble(string input, string ID = "main.asm")
|
||||
{
|
||||
StringLexer lexer = new StringLexer();
|
||||
lexer.SetDefinition(definition);
|
||||
lexer.Content = input;
|
||||
lexer.SourceID = ID;
|
||||
OperationResult<IntermediateObject> operationResult = new OperationResult<IntermediateObject>();
|
||||
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<string, string> data = new Dictionary<string, string>();
|
||||
public List<IntermediateInstruction> instructions = new List<IntermediateInstruction>();
|
||||
}
|
||||
[Serializable]
|
||||
public class IntermediateInstruction
|
||||
{
|
||||
public string? Label = null;
|
||||
public PrimaryInstruction inst;
|
||||
public List<LexSegment> Parameters = new List<LexSegment>();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user