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:
52
src/SVM.Assembler.Core/Assembler.cs
Normal file
52
src/SVM.Assembler.Core/Assembler.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using LibCLCC.NET.Lexer;
|
||||
using System;
|
||||
|
||||
namespace SVM.Assembler.Core
|
||||
{
|
||||
public class Assembler
|
||||
{
|
||||
public const string LexDefinition =
|
||||
@"
|
||||
Match:
|
||||
|
||||
D [0-9]
|
||||
Number {D}+
|
||||
InstMath math
|
||||
InstCvt cvt
|
||||
InstSystem system
|
||||
InstSys sys
|
||||
InstSD sd
|
||||
Register \${D}+
|
||||
LabelCode \.code\:
|
||||
LabelData \.data\:
|
||||
string "".*""
|
||||
LineEnd \n
|
||||
|
||||
OpAdd add
|
||||
OpSub sub
|
||||
OpMul mul
|
||||
OpDiv div
|
||||
|
||||
Id:
|
||||
|
||||
InstMath inst
|
||||
InstCvt inst
|
||||
InstSystem inst
|
||||
InstSys inst
|
||||
InstSD sd
|
||||
string String
|
||||
Number Number
|
||||
Register Register
|
||||
OpAdd BOp
|
||||
OpSub BOp
|
||||
OpMul BOp
|
||||
OpDiv BOp
|
||||
LineEnd LE
|
||||
";
|
||||
LexerDefinition? definition;
|
||||
public Assembler()
|
||||
{
|
||||
LexerDefinition.TryParse(LexDefinition, out definition);
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/SVM.Assembler.Core/SVM.Assembler.Core.csproj
Normal file
8
src/SVM.Assembler.Core/SVM.Assembler.Core.csproj
Normal file
@@ -0,0 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -31,7 +31,7 @@ namespace SVM.Core.Data
|
||||
{
|
||||
return new CompactByte(Value / R.Value);
|
||||
}
|
||||
public SCVMSimpleResult<CompactByte> AddOF(CompactByte R)
|
||||
public SVMSimpleResult<CompactByte> AddOF(CompactByte R)
|
||||
{
|
||||
CompactByte result = default;
|
||||
bool IsOF = false;
|
||||
@@ -50,10 +50,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactByte>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactByte>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactByte> SubOF(CompactByte R)
|
||||
public SVMSimpleResult<CompactByte> SubOF(CompactByte R)
|
||||
{
|
||||
CompactByte result = default;
|
||||
bool IsOF = false;
|
||||
@@ -72,10 +72,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactByte>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactByte>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactByte> DivOF(CompactByte R)
|
||||
public SVMSimpleResult<CompactByte> DivOF(CompactByte R)
|
||||
{
|
||||
CompactByte result = default;
|
||||
bool IsOF = false;
|
||||
@@ -94,10 +94,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactByte>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactByte>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactByte> MulOF(CompactByte R)
|
||||
public SVMSimpleResult<CompactByte> MulOF(CompactByte R)
|
||||
{
|
||||
CompactByte result = default;
|
||||
bool IsOF = false;
|
||||
@@ -116,7 +116,7 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactByte>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactByte>(IsOF, result);
|
||||
}
|
||||
|
||||
public bool LT(CompactByte R)
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace SVM.Core.Data
|
||||
return new CompactDouble(Value / R.Value);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactDouble> AddOF(CompactDouble R)
|
||||
public SVMSimpleResult<CompactDouble> AddOF(CompactDouble R)
|
||||
{
|
||||
CompactDouble result = default;
|
||||
bool IsOF = false;
|
||||
@@ -49,10 +49,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactDouble>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactDouble>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactDouble> SubOF(CompactDouble R)
|
||||
public SVMSimpleResult<CompactDouble> SubOF(CompactDouble R)
|
||||
{
|
||||
CompactDouble result = default;
|
||||
bool IsOF = false;
|
||||
@@ -71,10 +71,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactDouble>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactDouble>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactDouble> DivOF(CompactDouble R)
|
||||
public SVMSimpleResult<CompactDouble> DivOF(CompactDouble R)
|
||||
{
|
||||
CompactDouble result = default;
|
||||
bool IsOF = false;
|
||||
@@ -93,10 +93,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactDouble>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactDouble>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactDouble> MulOF(CompactDouble R)
|
||||
public SVMSimpleResult<CompactDouble> MulOF(CompactDouble R)
|
||||
{
|
||||
CompactDouble result = default;
|
||||
bool IsOF = false;
|
||||
@@ -115,7 +115,7 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactDouble>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactDouble>(IsOF, result);
|
||||
}
|
||||
|
||||
public bool LT(CompactDouble R)
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace SVM.Core.Data
|
||||
return new CompactInt(Value / R.Value);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactInt> AddOF(CompactInt R)
|
||||
public SVMSimpleResult<CompactInt> AddOF(CompactInt R)
|
||||
{
|
||||
CompactInt result = default;
|
||||
bool IsOF = false;
|
||||
@@ -50,10 +50,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactInt>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactInt>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactInt> SubOF(CompactInt R)
|
||||
public SVMSimpleResult<CompactInt> SubOF(CompactInt R)
|
||||
{
|
||||
CompactInt result = default;
|
||||
bool IsOF = false;
|
||||
@@ -72,10 +72,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactInt>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactInt>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactInt> DivOF(CompactInt R)
|
||||
public SVMSimpleResult<CompactInt> DivOF(CompactInt R)
|
||||
{
|
||||
CompactInt result = default;
|
||||
bool IsOF = false;
|
||||
@@ -94,10 +94,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactInt>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactInt>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactInt> MulOF(CompactInt R)
|
||||
public SVMSimpleResult<CompactInt> MulOF(CompactInt R)
|
||||
{
|
||||
CompactInt result = default;
|
||||
bool IsOF = false;
|
||||
@@ -116,7 +116,7 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactInt>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactInt>(IsOF, result);
|
||||
}
|
||||
|
||||
public bool LT(CompactInt R)
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace SVM.Core.Data
|
||||
{
|
||||
return new CompactLong(Value / R.Value);
|
||||
}
|
||||
public SCVMSimpleResult<CompactLong> AddOF(CompactLong R)
|
||||
public SVMSimpleResult<CompactLong> AddOF(CompactLong R)
|
||||
{
|
||||
CompactLong result = default;
|
||||
bool IsOF = false;
|
||||
@@ -48,10 +48,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactLong>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactLong>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactLong> SubOF(CompactLong R)
|
||||
public SVMSimpleResult<CompactLong> SubOF(CompactLong R)
|
||||
{
|
||||
CompactLong result = default;
|
||||
bool IsOF = false;
|
||||
@@ -70,10 +70,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactLong>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactLong>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactLong> DivOF(CompactLong R)
|
||||
public SVMSimpleResult<CompactLong> DivOF(CompactLong R)
|
||||
{
|
||||
CompactLong result = default;
|
||||
bool IsOF = false;
|
||||
@@ -92,10 +92,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactLong>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactLong>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactLong> MulOF(CompactLong R)
|
||||
public SVMSimpleResult<CompactLong> MulOF(CompactLong R)
|
||||
{
|
||||
CompactLong result = default;
|
||||
bool IsOF = false;
|
||||
@@ -114,7 +114,7 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactLong>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactLong>(IsOF, result);
|
||||
}
|
||||
|
||||
public bool LT(CompactLong R)
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace SVM.Core.Data
|
||||
{
|
||||
return new CompactSByte(Value / R.Value);
|
||||
}
|
||||
public SCVMSimpleResult<CompactSByte> AddOF(CompactSByte R)
|
||||
public SVMSimpleResult<CompactSByte> AddOF(CompactSByte R)
|
||||
{
|
||||
CompactSByte result = default;
|
||||
bool IsOF = false;
|
||||
@@ -49,10 +49,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactSByte>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactSByte>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactSByte> SubOF(CompactSByte R)
|
||||
public SVMSimpleResult<CompactSByte> SubOF(CompactSByte R)
|
||||
{
|
||||
CompactSByte result = default;
|
||||
bool IsOF = false;
|
||||
@@ -71,10 +71,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactSByte>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactSByte>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactSByte> DivOF(CompactSByte R)
|
||||
public SVMSimpleResult<CompactSByte> DivOF(CompactSByte R)
|
||||
{
|
||||
CompactSByte result = default;
|
||||
bool IsOF = false;
|
||||
@@ -93,10 +93,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactSByte>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactSByte>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactSByte> MulOF(CompactSByte R)
|
||||
public SVMSimpleResult<CompactSByte> MulOF(CompactSByte R)
|
||||
{
|
||||
CompactSByte result = default;
|
||||
bool IsOF = false;
|
||||
@@ -115,7 +115,7 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactSByte>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactSByte>(IsOF, result);
|
||||
}
|
||||
|
||||
public bool LT(CompactSByte R)
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace SVM.Core.Data
|
||||
{
|
||||
return new CompactShort(Value / R.Value);
|
||||
}
|
||||
public SCVMSimpleResult<CompactShort> AddOF(CompactShort R)
|
||||
public SVMSimpleResult<CompactShort> AddOF(CompactShort R)
|
||||
{
|
||||
CompactShort result = default;
|
||||
bool IsOF = false;
|
||||
@@ -49,10 +49,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactShort>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactShort>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactShort> SubOF(CompactShort R)
|
||||
public SVMSimpleResult<CompactShort> SubOF(CompactShort R)
|
||||
{
|
||||
CompactShort result = default;
|
||||
bool IsOF = false;
|
||||
@@ -71,10 +71,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactShort>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactShort>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactShort> DivOF(CompactShort R)
|
||||
public SVMSimpleResult<CompactShort> DivOF(CompactShort R)
|
||||
{
|
||||
CompactShort result = default;
|
||||
bool IsOF = false;
|
||||
@@ -93,10 +93,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactShort>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactShort>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactShort> MulOF(CompactShort R)
|
||||
public SVMSimpleResult<CompactShort> MulOF(CompactShort R)
|
||||
{
|
||||
CompactShort result = default;
|
||||
bool IsOF = false;
|
||||
@@ -115,7 +115,7 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactShort>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactShort>(IsOF, result);
|
||||
}
|
||||
|
||||
public bool LT(CompactShort R)
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace SVM.Core.Data
|
||||
{
|
||||
return new CompactSingle(Value / R.Value);
|
||||
}
|
||||
public SCVMSimpleResult<CompactSingle> AddOF(CompactSingle R)
|
||||
public SVMSimpleResult<CompactSingle> AddOF(CompactSingle R)
|
||||
{
|
||||
CompactSingle result = default;
|
||||
bool IsOF = false;
|
||||
@@ -48,10 +48,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactSingle>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactSingle>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactSingle> SubOF(CompactSingle R)
|
||||
public SVMSimpleResult<CompactSingle> SubOF(CompactSingle R)
|
||||
{
|
||||
CompactSingle result = default;
|
||||
bool IsOF = false;
|
||||
@@ -70,10 +70,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactSingle>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactSingle>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactSingle> DivOF(CompactSingle R)
|
||||
public SVMSimpleResult<CompactSingle> DivOF(CompactSingle R)
|
||||
{
|
||||
CompactSingle result = default;
|
||||
bool IsOF = false;
|
||||
@@ -92,10 +92,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactSingle>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactSingle>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactSingle> MulOF(CompactSingle R)
|
||||
public SVMSimpleResult<CompactSingle> MulOF(CompactSingle R)
|
||||
{
|
||||
CompactSingle result = default;
|
||||
bool IsOF = false;
|
||||
@@ -114,7 +114,7 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactSingle>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactSingle>(IsOF, result);
|
||||
}
|
||||
|
||||
public bool LT(CompactSingle R)
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace SVM.Core.Data
|
||||
{
|
||||
return new CompactUInt(Value / R.Value);
|
||||
}
|
||||
public SCVMSimpleResult<CompactUInt> AddOF(CompactUInt R)
|
||||
public SVMSimpleResult<CompactUInt> AddOF(CompactUInt R)
|
||||
{
|
||||
CompactUInt result = default;
|
||||
bool IsOF = false;
|
||||
@@ -48,10 +48,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactUInt>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactUInt>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactUInt> SubOF(CompactUInt R)
|
||||
public SVMSimpleResult<CompactUInt> SubOF(CompactUInt R)
|
||||
{
|
||||
CompactUInt result = default;
|
||||
bool IsOF = false;
|
||||
@@ -70,10 +70,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactUInt>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactUInt>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactUInt> DivOF(CompactUInt R)
|
||||
public SVMSimpleResult<CompactUInt> DivOF(CompactUInt R)
|
||||
{
|
||||
CompactUInt result = default;
|
||||
bool IsOF = false;
|
||||
@@ -92,10 +92,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactUInt>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactUInt>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactUInt> MulOF(CompactUInt R)
|
||||
public SVMSimpleResult<CompactUInt> MulOF(CompactUInt R)
|
||||
{
|
||||
CompactUInt result = default;
|
||||
bool IsOF = false;
|
||||
@@ -114,7 +114,7 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactUInt>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactUInt>(IsOF, result);
|
||||
}
|
||||
|
||||
public bool LT(CompactUInt R)
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace SVM.Core.Data
|
||||
{
|
||||
return new CompactULong(Value / R.Value);
|
||||
}
|
||||
public SCVMSimpleResult<CompactULong> AddOF(CompactULong R)
|
||||
public SVMSimpleResult<CompactULong> AddOF(CompactULong R)
|
||||
{
|
||||
CompactULong result = default;
|
||||
bool IsOF = false;
|
||||
@@ -48,10 +48,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactULong>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactULong>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactULong> SubOF(CompactULong R)
|
||||
public SVMSimpleResult<CompactULong> SubOF(CompactULong R)
|
||||
{
|
||||
CompactULong result = default;
|
||||
bool IsOF = false;
|
||||
@@ -70,10 +70,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactULong>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactULong>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactULong> DivOF(CompactULong R)
|
||||
public SVMSimpleResult<CompactULong> DivOF(CompactULong R)
|
||||
{
|
||||
CompactULong result = default;
|
||||
bool IsOF = false;
|
||||
@@ -92,10 +92,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactULong>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactULong>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactULong> MulOF(CompactULong R)
|
||||
public SVMSimpleResult<CompactULong> MulOF(CompactULong R)
|
||||
{
|
||||
CompactULong result = default;
|
||||
bool IsOF = false;
|
||||
@@ -114,7 +114,7 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactULong>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactULong>(IsOF, result);
|
||||
}
|
||||
|
||||
public bool LT(CompactULong R)
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace SVM.Core.Data
|
||||
{
|
||||
return new CompactUShort(Value / R.Value);
|
||||
}
|
||||
public SCVMSimpleResult<CompactUShort> AddOF(CompactUShort R)
|
||||
public SVMSimpleResult<CompactUShort> AddOF(CompactUShort R)
|
||||
{
|
||||
CompactUShort result = default;
|
||||
bool IsOF = false;
|
||||
@@ -49,10 +49,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactUShort>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactUShort>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactUShort> SubOF(CompactUShort R)
|
||||
public SVMSimpleResult<CompactUShort> SubOF(CompactUShort R)
|
||||
{
|
||||
CompactUShort result = default;
|
||||
bool IsOF = false;
|
||||
@@ -71,10 +71,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactUShort>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactUShort>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactUShort> DivOF(CompactUShort R)
|
||||
public SVMSimpleResult<CompactUShort> DivOF(CompactUShort R)
|
||||
{
|
||||
CompactUShort result = default;
|
||||
bool IsOF = false;
|
||||
@@ -93,10 +93,10 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactUShort>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactUShort>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactUShort> MulOF(CompactUShort R)
|
||||
public SVMSimpleResult<CompactUShort> MulOF(CompactUShort R)
|
||||
{
|
||||
CompactUShort result = default;
|
||||
bool IsOF = false;
|
||||
@@ -115,7 +115,7 @@ namespace SVM.Core.Data
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactUShort>(IsOF, result);
|
||||
return new SVMSimpleResult<CompactUShort>(IsOF, result);
|
||||
}
|
||||
|
||||
public bool LT(CompactUShort R)
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Text;
|
||||
|
||||
namespace SVM.Core.Data
|
||||
{
|
||||
public interface INumbericData<T> : IPointerWritable where T : unmanaged
|
||||
public interface INumbericData<T> : IPointerWritable, ICastable where T : unmanaged
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
T Add(T R);
|
||||
@@ -19,13 +19,13 @@ namespace SVM.Core.Data
|
||||
T Mod(T R);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
SCVMSimpleResult<T> AddOF(T R);
|
||||
SVMSimpleResult<T> AddOF(T R);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
SCVMSimpleResult<T> SubOF(T R);
|
||||
SVMSimpleResult<T> SubOF(T R);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
SCVMSimpleResult<T> DivOF(T R);
|
||||
SVMSimpleResult<T> DivOF(T R);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
SCVMSimpleResult<T> MulOF(T R);
|
||||
SVMSimpleResult<T> MulOF(T R);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
bool LT(T R);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -38,6 +38,9 @@ namespace SVM.Core.Data
|
||||
bool EQ(T R);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
bool NE(T R);
|
||||
}
|
||||
public interface ICastable
|
||||
{
|
||||
INumbericData<CompactByte> Cast_Byte();
|
||||
INumbericData<CompactSByte> Cast_SByte();
|
||||
INumbericData<CompactShort> Cast_Short();
|
||||
@@ -49,17 +52,18 @@ namespace SVM.Core.Data
|
||||
INumbericData<CompactDouble> Cast_Double();
|
||||
INumbericData<CompactSingle> Cast_Float();
|
||||
}
|
||||
|
||||
public unsafe interface IPointerWritable
|
||||
{
|
||||
public void Write(byte* targetPtr);
|
||||
public int SizeOf();
|
||||
}
|
||||
public struct SCVMSimpleResult<T> where T : unmanaged
|
||||
public struct SVMSimpleResult<T> where T : unmanaged
|
||||
{
|
||||
public bool IsSuccess;
|
||||
public T Value;
|
||||
|
||||
public SCVMSimpleResult(bool isSuccess, T value)
|
||||
public SVMSimpleResult(bool isSuccess, T value)
|
||||
{
|
||||
IsSuccess = isSuccess;
|
||||
Value = value;
|
||||
|
||||
@@ -7,9 +7,9 @@ namespace SVM.Core
|
||||
{
|
||||
public Dictionary<string, uint> Functions = new Dictionary<string, uint>();
|
||||
}
|
||||
public class RuntimeBinary
|
||||
public unsafe class RuntimeBinary
|
||||
{
|
||||
public uint offset;
|
||||
public SVMProgram* program;
|
||||
public SimpleVirtualMachine? BindedMachine;
|
||||
public DebugSymbol? Symbol;
|
||||
public bool Invoke(string funcName)
|
||||
|
||||
@@ -27,6 +27,11 @@ namespace SVM.Core
|
||||
if (RegisterID == 0) return default;
|
||||
return Data.GetDataWithOffsetInBytes<T>(RegisterID * sizeof(Int64));
|
||||
}
|
||||
public unsafe byte* GetPtr(int RegisterID)
|
||||
{
|
||||
if (RegisterID == 0) return null;
|
||||
return ((byte*)Data) + RegisterID * sizeof(long);
|
||||
}
|
||||
public unsafe void SetData<T>(int offset, T d) where T : unmanaged
|
||||
{
|
||||
if (offset == 0) return;
|
||||
|
||||
@@ -72,7 +72,13 @@
|
||||
}
|
||||
public enum ConditionFlag
|
||||
{
|
||||
Cmp,
|
||||
/// <summary>
|
||||
/// Compare Flag
|
||||
/// </summary>
|
||||
CF,
|
||||
/// <summary>
|
||||
/// Overflow Flag
|
||||
/// </summary>
|
||||
Of,
|
||||
}
|
||||
public enum SIMDOperator : byte
|
||||
|
||||
53
src/SVM.Core/SVMProgram.cs
Normal file
53
src/SVM.Core/SVMProgram.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using SVM.Core.Utils;
|
||||
using System;
|
||||
using System.IO;
|
||||
using static SVM.Core.stdc.stdlib;
|
||||
namespace SVM.Core
|
||||
{
|
||||
public unsafe struct SVMProgram : IDisposable
|
||||
{
|
||||
public UInt64 InstructionCount;
|
||||
public UInt64 DataSize;
|
||||
public SVMInstruction* instructions;
|
||||
public byte* data;
|
||||
public static SVMProgram* LoadFromStream(Stream stream)
|
||||
{
|
||||
if (!stream.TryReadData(out uint dataSectionLength))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (!stream.TryReadData(out uint codeCount))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var dataPtr = malloc(dataSectionLength);
|
||||
Span<byte> dataBuffer = new Span<byte>((byte*)dataPtr, (int)dataSectionLength);
|
||||
if (stream.Read(dataBuffer) != dataSectionLength)
|
||||
{
|
||||
free(dataPtr);
|
||||
return null;
|
||||
}
|
||||
var codeLen = codeCount * sizeof(SVMInstruction);
|
||||
var codePtr = malloc((uint)codeLen);
|
||||
Span<byte> codeBuffer = new Span<byte>((byte*)codePtr, (int)codeLen);
|
||||
if (stream.Read(codeBuffer) != codeLen)
|
||||
{
|
||||
free(dataPtr);
|
||||
free(codePtr);
|
||||
return null;
|
||||
}
|
||||
var program = (SVMProgram*)malloc(sizeof(SVMProgram));
|
||||
program->data = (byte*)dataPtr;
|
||||
program->DataSize = dataSectionLength;
|
||||
program->instructions = (SVMInstruction*)codePtr;
|
||||
program->InstructionCount = codeCount;
|
||||
return program;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
free((IntPtr)data);
|
||||
free((IntPtr)instructions);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
using SVM.Core.FuncImpl;
|
||||
using SVM.Core.Data;
|
||||
using SVM.Core.FuncImpl;
|
||||
using SVM.Core.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using static SVM.Core.stdc.stdlib;
|
||||
namespace SVM.Core
|
||||
@@ -105,6 +105,9 @@ namespace SVM.Core
|
||||
case SVMInstDef.UMath:
|
||||
break;
|
||||
case SVMInstDef.Cvt:
|
||||
{
|
||||
Convert(Instruction);
|
||||
}
|
||||
break;
|
||||
case SVMInstDef.Cmp:
|
||||
break;
|
||||
@@ -148,6 +151,86 @@ namespace SVM.Core
|
||||
PC++;
|
||||
registers.SetData<ulong>((int)PCOffset, PC);
|
||||
}
|
||||
|
||||
private void Convert(SVMInstruction Instruction)
|
||||
{
|
||||
var SType = Instruction.GetData<SVMNativeTypes>(1);
|
||||
var TType = Instruction.GetData<SVMNativeTypes>(2);
|
||||
var L = Instruction.GetData<byte>(3);
|
||||
var T = Instruction.GetData<byte>(4);
|
||||
ICastable castable;
|
||||
switch (SType)
|
||||
{
|
||||
case SVMNativeTypes.Int8:
|
||||
castable = registers.GetData<CompactSByte>(L);
|
||||
break;
|
||||
case SVMNativeTypes.Int16:
|
||||
castable = registers.GetData<CompactShort>(L);
|
||||
break;
|
||||
case SVMNativeTypes.Int32:
|
||||
castable = registers.GetData<CompactInt>(L);
|
||||
break;
|
||||
case SVMNativeTypes.Int64:
|
||||
castable = registers.GetData<CompactLong>(L);
|
||||
break;
|
||||
case SVMNativeTypes.UInt8:
|
||||
castable = registers.GetData<CompactByte>(L);
|
||||
break;
|
||||
case SVMNativeTypes.UInt16:
|
||||
castable = registers.GetData<CompactUShort>(L);
|
||||
break;
|
||||
case SVMNativeTypes.UInt32:
|
||||
castable = registers.GetData<CompactUInt>(L);
|
||||
break;
|
||||
case SVMNativeTypes.UInt64:
|
||||
castable = registers.GetData<CompactULong>(L);
|
||||
break;
|
||||
case SVMNativeTypes.Float:
|
||||
castable = registers.GetData<CompactSingle>(L);
|
||||
break;
|
||||
case SVMNativeTypes.Double:
|
||||
castable = registers.GetData<CompactDouble>(L);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
switch (TType)
|
||||
{
|
||||
case SVMNativeTypes.Int8:
|
||||
castable.Cast_SByte().Write(registers.GetPtr(T));
|
||||
break;
|
||||
case SVMNativeTypes.Int16:
|
||||
castable.Cast_Short().Write(registers.GetPtr(T));
|
||||
break;
|
||||
case SVMNativeTypes.Int32:
|
||||
castable.Cast_Int().Write(registers.GetPtr(T));
|
||||
break;
|
||||
case SVMNativeTypes.Int64:
|
||||
castable.Cast_Long().Write(registers.GetPtr(T));
|
||||
break;
|
||||
case SVMNativeTypes.UInt8:
|
||||
castable.Cast_Byte().Write(registers.GetPtr(T));
|
||||
break;
|
||||
case SVMNativeTypes.UInt16:
|
||||
castable.Cast_UShort().Write(registers.GetPtr(T));
|
||||
break;
|
||||
case SVMNativeTypes.UInt32:
|
||||
castable.Cast_UInt().Write(registers.GetPtr(T));
|
||||
break;
|
||||
case SVMNativeTypes.UInt64:
|
||||
castable.Cast_ULong().Write(registers.GetPtr(T));
|
||||
break;
|
||||
case SVMNativeTypes.Float:
|
||||
castable.Cast_Float().Write(registers.GetPtr(T));
|
||||
break;
|
||||
case SVMNativeTypes.Double:
|
||||
castable.Cast_Double().Write(registers.GetPtr(T));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public IntPtr GetPointer(ulong PC)
|
||||
{
|
||||
return GetPointer(new SVMPointer() { offset = (uint)PC, index = 0 });
|
||||
@@ -229,24 +312,12 @@ namespace SVM.Core
|
||||
/// </summary>
|
||||
public uint EIDRegisterID;
|
||||
}
|
||||
public unsafe struct SVMProgram
|
||||
{
|
||||
public UInt64 InstructionCount;
|
||||
public UInt64 DataSize;
|
||||
public SVMInstruction* instructions;
|
||||
public byte* data;
|
||||
public static SVMProgram* LoadFromStream(Stream stream)
|
||||
{
|
||||
var program = (SVMProgram*)malloc(sizeof(SVMProgram));
|
||||
|
||||
return program;
|
||||
}
|
||||
}
|
||||
public delegate void FuncCall(SimpleVirtualMachine machine);
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct MState
|
||||
{
|
||||
public byte OF;
|
||||
public byte CF;
|
||||
}
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct MemoryBlock : IDisposable
|
||||
|
||||
25
src/SVM.Core/Utils/StreamUtils.cs
Normal file
25
src/SVM.Core/Utils/StreamUtils.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace SVM.Core.Utils
|
||||
{
|
||||
public static class StreamUtils
|
||||
{
|
||||
public unsafe static bool TryReadData<T>(this Stream stream, out T data) where T : unmanaged
|
||||
{
|
||||
int len = sizeof(T);
|
||||
var dataPtr = stackalloc byte[len];
|
||||
Span<byte> buffer = new Span<byte>(dataPtr, len);
|
||||
var count = stream.Read(buffer);
|
||||
if (count != len)
|
||||
{
|
||||
data = default;
|
||||
return false;
|
||||
}
|
||||
data = ((T*)dataPtr)[0];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user