Refactors Program.cs to assembler.cs. Adds command line compilation arguments, adds colored and structured display.
This commit is contained in:
parent
cbc817bd36
commit
fec40a26c3
6 changed files with 58 additions and 115 deletions
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
</startup>
|
||||
</configuration>
|
7
prototypes/supervm-asm/Makefile
Normal file
7
prototypes/supervm-asm/Makefile
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
CSC = mcs
|
||||
|
||||
all: assembler.exe
|
||||
|
||||
assembler.exe: assembler.cs
|
||||
$(CSC) -out:$@ -target:exe $^
|
|
@ -1,36 +0,0 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die einer Assembly zugeordnet sind.
|
||||
[assembly: AssemblyTitle("supervm-asm")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("supervm-asm")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
|
||||
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
|
||||
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
||||
[assembly: Guid("7b2cb53a-d2ef-4aef-b354-fcf28c581280")]
|
||||
|
||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
//
|
||||
// Hauptversion
|
||||
// Nebenversion
|
||||
// Buildnummer
|
||||
// Revision
|
||||
//
|
||||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||
// übernehmen, indem Sie "*" eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
1
prototypes/supervm-asm/assembler
Normal file
1
prototypes/supervm-asm/assembler
Normal file
|
@ -0,0 +1 @@
|
|||
#!/usr/bin/mono assembler.exe
|
|
@ -16,15 +16,57 @@ namespace supervm_asm
|
|||
{
|
||||
// MnemonicParser.GenerateFromDocumentation(@"D:\felix\projects\DasOS\prototypes\supervm\instructions.md");
|
||||
|
||||
var code = Assembler.Assemble(File.ReadAllText("testcode.asm"));
|
||||
|
||||
for (int i = 0; i < code.Length; i++)
|
||||
foreach(var file in args.Where(a => !a.StartsWith("-") && Path.GetExtension(a) == ".asm"))
|
||||
{
|
||||
Console.Write("; {0:X3} ", i);
|
||||
Console.Write(Convert.ToString((long)code[i], 2).PadLeft(64, '0'));
|
||||
Console.WriteLine();
|
||||
var output = Path.ChangeExtension(file, ".bin");
|
||||
var code = Assembler.Assemble(File.ReadAllText("testcode.asm"));
|
||||
|
||||
Console.WriteLine("{0}:", output);
|
||||
for (int i = 0; i < code.Length; i++)
|
||||
{
|
||||
Console.Write("; {0:X3} ", i);
|
||||
PrintInstruction(code[i]);
|
||||
}
|
||||
using(var fs = File.Open(output, FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
for(int i = 0; i < code.Length; i++)
|
||||
{
|
||||
var bits = BitConverter.GetBytes(code[i]);
|
||||
if(BitConverter.IsLittleEndian)
|
||||
{
|
||||
bits = bits.Reverse().ToArray();
|
||||
}
|
||||
fs.Write(bits, 0, bits.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void PrintInstruction(ulong instr)
|
||||
{
|
||||
var str = Convert.ToString((long)instr, 2).PadLeft(64, '0');
|
||||
|
||||
var portions = new []
|
||||
{
|
||||
new { Start = 0, Length = 32, Color = ConsoleColor.Red },
|
||||
new { Start = 32, Length = 2, Color = ConsoleColor.Blue },
|
||||
new { Start = 34, Length = 1, Color = ConsoleColor.Green },
|
||||
new { Start = 35, Length = 16, Color = ConsoleColor.Magenta },
|
||||
new { Start = 51, Length = 8, Color = ConsoleColor.Yellow },
|
||||
new { Start = 59, Length = 1, Color = ConsoleColor.DarkCyan },
|
||||
new { Start = 60, Length = 2, Color = ConsoleColor.Cyan },
|
||||
new { Start = 62, Length = 2, Color = ConsoleColor.DarkBlue },
|
||||
};
|
||||
|
||||
var fg = Console.ForegroundColor;
|
||||
foreach(var portion in portions)
|
||||
{
|
||||
Console.ForegroundColor = portion.Color;
|
||||
Console.Write("{0} ", str.Substring(portion.Start, portion.Length));
|
||||
}
|
||||
Console.ForegroundColor = fg;
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Assembler
|
||||
|
@ -123,10 +165,10 @@ namespace supervm_asm
|
|||
switch (annotation)
|
||||
{
|
||||
case "f:yes":
|
||||
instruction.ModifyFlags = false;
|
||||
instruction.ModifyFlags = true;
|
||||
break;
|
||||
case "f:no":
|
||||
instruction.ModifyFlags = true;
|
||||
instruction.ModifyFlags = false;
|
||||
break;
|
||||
case "r:discard":
|
||||
instruction.Output = OutputType.Discard;
|
|
@ -1,65 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{7B2CB53A-D2EF-4AEF-B354-FCF28C581280}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>supervm_asm</RootNamespace>
|
||||
<AssemblyName>supervm-asm</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="testcode.asm">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
Loading…
Reference in a new issue