public void Generate() { var filename = genTypes.Dirs.GetRustFilename("instruction_internal.rs"); new FileUpdater(TargetLanguage.Rust, "RegToAddrSize", filename).Generate(writer => { var registerType = genTypes[TypeIds.Register]; var icedConstantsName = genTypes.GetConstantsType(TypeIds.IcedConstants).Name(idConverter); var regCountName = idConverter.Constant(IcedConstants.GetEnumCountName(TypeIds.Register)); writer.WriteLine(RustConstants.AttributeNoRustFmt); writer.WriteLine($"static REG_TO_ADDR_SIZE: [u8; {icedConstantsName}::{regCountName}] = ["); using (writer.Indent()) { foreach (var regEnum in registerType.Values) { var reg = (Register)regEnum.Value; var size = GetAddrSize(reg); if (size > byte.MaxValue) { throw new InvalidOperationException(); } writer.WriteLine($"{size}, // {regEnum.Name(idConverter)}"); } } writer.WriteLine("];"); }); }
public void Generate() { var icedConstants = genTypes.GetConstantsType(TypeIds.IcedConstants); var defs = genTypes.GetObject <InstructionDefs>(TypeIds.InstructionDefs).Defs; const string ClassName = "MnemonicUtilsData"; var mnemonicName = genTypes[TypeIds.Mnemonic].Name(idConverter); using (var writer = new FileWriter(TargetLanguage.CSharp, FileUtils.OpenWrite(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, ClassName + ".g.cs")))) { writer.WriteFileHeader(); writer.WriteLine($"namespace {CSharpConstants.IcedNamespace} {{"); using (writer.Indent()) { writer.WriteLine($"static class {ClassName} {{"); using (writer.Indent()) { writer.WriteLine($"internal static readonly ushort[] toMnemonic = new ushort[{icedConstants.Name(idConverter)}.{icedConstants[IcedConstants.GetEnumCountName(TypeIds.Code)].Name(idConverter)}] {{"); using (writer.Indent()) { foreach (var def in defs) { if (def.Mnemonic.Value > ushort.MaxValue) { throw new InvalidOperationException(); } writer.WriteLine($"(ushort){mnemonicName}.{def.Mnemonic.Name(idConverter)},// {def.Code.Name(idConverter)}"); } } writer.WriteLine("};"); } writer.WriteLine("}"); } writer.WriteLine("}"); } }
public void Generate() { var icedConstants = genTypes.GetConstantsType(TypeIds.IcedConstants); var defs = genTypes.GetObject <InstructionDefs>(TypeIds.InstructionDefs).Defs; const string ClassName = "InstructionOpCounts"; using (var writer = new FileWriter(TargetLanguage.CSharp, FileUtils.OpenWrite(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, ClassName + ".g.cs")))) { writer.WriteFileHeader(); writer.WriteLine($"namespace {CSharpConstants.IcedNamespace} {{"); using (writer.Indent()) { writer.WriteLine($"static class {ClassName} {{"); using (writer.Indent()) { writer.WriteLineNoIndent($"#if {CSharpConstants.HasSpanDefine}"); writer.WriteLine($"internal static System.ReadOnlySpan<byte> OpCount => new byte[{icedConstants.Name(idConverter)}.{icedConstants[IcedConstants.GetEnumCountName(TypeIds.Code)].Name(idConverter)}] {{"); writer.WriteLineNoIndent("#else"); writer.WriteLine($"internal static readonly byte[] OpCount = new byte[{icedConstants.Name(idConverter)}.{icedConstants[IcedConstants.GetEnumCountName(TypeIds.Code)].Name(idConverter)}] {{"); writer.WriteLineNoIndent("#endif"); using (writer.Indent()) { foreach (var def in defs) { writer.WriteLine($"{def.OpCount},// {def.Code.Name(idConverter)}"); } } writer.WriteLine("};"); } writer.WriteLine("}"); } writer.WriteLine("}"); } }
public void Generate() { var icedConstants = genTypes.GetConstantsType(TypeIds.IcedConstants); var defs = genTypes.GetObject <InstructionDefs>(TypeIds.InstructionDefs).Defs; const string ClassName = "InstructionMemorySizes"; var memSizeName = genTypes[TypeIds.MemorySize].Name(idConverter); using (var writer = new FileWriter(TargetLanguage.CSharp, FileUtils.OpenWrite(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, ClassName + ".g.cs")))) { writer.WriteFileHeader(); writer.WriteLine($"namespace {CSharpConstants.IcedNamespace} {{"); using (writer.Indent()) { writer.WriteLine($"static class {ClassName} {{"); using (writer.Indent()) { writer.WriteCommentLine("0 = memory size"); writer.WriteCommentLine("1 = broadcast memory size"); writer.WriteLineNoIndent($"#if {CSharpConstants.HasSpanDefine}"); writer.WriteLine($"internal static System.ReadOnlySpan<byte> Sizes => new byte[{icedConstants.Name(idConverter)}.{icedConstants[IcedConstants.GetEnumCountName(TypeIds.Code)].Name(idConverter)} * 2] {{"); writer.WriteLineNoIndent("#else"); writer.WriteLine($"internal static readonly byte[] Sizes = new byte[{icedConstants.Name(idConverter)}.{icedConstants[IcedConstants.GetEnumCountName(TypeIds.Code)].Name(idConverter)} * 2] {{"); writer.WriteLineNoIndent("#endif"); using (writer.Indent()) { foreach (var def in defs) { if (def.Memory.Value > byte.MaxValue) { throw new InvalidOperationException(); } string value; if (def.Memory.Value == 0) { value = "0"; } else { value = $"(byte){memSizeName}.{def.Memory.Name(idConverter)}"; } writer.WriteLine($"{value},// {def.Code.Name(idConverter)}"); } foreach (var def in defs) { if (def.MemoryBroadcast.Value > byte.MaxValue) { throw new InvalidOperationException(); } string value; if (def.MemoryBroadcast.Value == 0) { value = "0"; } else { value = $"(byte){memSizeName}.{def.MemoryBroadcast.Name(idConverter)}"; } writer.WriteLine($"{value},// {def.Code.Name(idConverter)}"); } } writer.WriteLine("};"); } writer.WriteLine("}"); } writer.WriteLine("}"); } }