Skip to content

Commit

Permalink
Run dotnet-format for ThunkGenerator (#77715)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo authored Nov 1, 2022
1 parent 705babd commit 7ba371c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

namespace Thunkerator
{
public class InstructionSetGenerator
{
class InstructionSetInfo
sealed class InstructionSetInfo
{
public string Architecture { get; }
public string ManagedName { get; }
Expand Down Expand Up @@ -58,9 +58,9 @@ public string PublicName
}
}

record InstructionSetGroup(string Names, string Archs, string Sets);
sealed record InstructionSetGroup(string Names, string Archs, string Sets);

class InstructionSetImplication
sealed class InstructionSetImplication
{
public string Architecture { get; }
public string JitName { get; }
Expand All @@ -85,13 +85,13 @@ public InstructionSetImplication(string architecture, InstructionSetImplication
List<InstructionSetImplication> _implications = new List<InstructionSetImplication>();
List<InstructionSetGroup> _instructionSetsGroups = new List<InstructionSetGroup>();
Dictionary<string, HashSet<string>> _64bitVariants = new Dictionary<string, HashSet<string>>();
SortedDictionary<string,int> _r2rNamesByName = new SortedDictionary<string,int>();
SortedDictionary<int,string> _r2rNamesByNumber = new SortedDictionary<int,string>();
SortedDictionary<string, int> _r2rNamesByName = new SortedDictionary<string, int>();
SortedDictionary<int, string> _r2rNamesByNumber = new SortedDictionary<int, string>();
SortedSet<string> _architectures = new SortedSet<string>();
Dictionary<string,List<string>> _architectureJitNames = new Dictionary<string,List<string>>();
Dictionary<string,List<string>> _architectureVectorInstructionSetJitNames = new Dictionary<string,List<string>>();
Dictionary<string, List<string>> _architectureJitNames = new Dictionary<string, List<string>>();
Dictionary<string, List<string>> _architectureVectorInstructionSetJitNames = new Dictionary<string, List<string>>();
HashSet<string> _64BitArchitectures = new HashSet<string>();
Dictionary<string,string> _64BitVariantArchitectureJitNameSuffix = new Dictionary<string,string>();
Dictionary<string, string> _64BitVariantArchitectureJitNameSuffix = new Dictionary<string, string>();
// This represents the number of flags fields we currently track
const int FlagsFieldCount = 1;

Expand All @@ -112,7 +112,7 @@ void ValidateArchitectureEncountered(string arch)
throw new Exception("Architecture not defined");
}

private string ArchToIfDefArch(string arch)
private static string ArchToIfDefArch(string arch)
{
if (arch == "X64")
return "AMD64";
Expand Down Expand Up @@ -147,7 +147,7 @@ public bool ParseInput(TextReader tr)
{
command[i] = command[i].Trim();
}
switch(command[0])
switch (command[0])
{
case "definearch":
if (command.Length != 4)
Expand All @@ -168,7 +168,7 @@ public bool ParseInput(TextReader tr)
throw new Exception("Incorrect number of args for instructionset");
ValidateArchitectureEncountered(command[1]);
_architectureJitNames[command[1]].Add(command[5]);
_instructionSets.Add(new InstructionSetInfo(command[1],command[2],command[3],command[4],command[5],command[6]));
_instructionSets.Add(new InstructionSetInfo(command[1], command[2], command[3], command[4], command[5], command[6]));
break;
case "vectorinstructionset":
if (command.Length != 3)
Expand All @@ -187,7 +187,7 @@ public bool ParseInput(TextReader tr)
if (command.Length != 4)
throw new Exception("Incorrect number of args for instructionset");
ValidateArchitectureEncountered(command[1]);
_implications.Add(new InstructionSetImplication(command[1],command[2], command[3]));
_implications.Add(new InstructionSetImplication(command[1], command[2], command[3]));
break;
case "instructionsetgroup":
if (command.Length != 4)
Expand Down Expand Up @@ -1026,7 +1026,7 @@ inline CORINFO_InstructionSet InstructionSetFromR2RInstructionSet(ReadyToRunInst
string r2rEnumerationValue;
if (String.IsNullOrEmpty(instructionSet.R2rName))
continue;

r2rEnumerationValue = $"READYTORUN_INSTRUCTION_{instructionSet.R2rName}";

tr.WriteLine($" case {r2rEnumerationValue}: return InstructionSet_{instructionSet.JitName};");
Expand Down
68 changes: 34 additions & 34 deletions src/coreclr/tools/Common/JitInterface/ThunkGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

namespace Thunkerator
{
Expand All @@ -34,7 +34,7 @@ public static string Canonicalize(this string current)
}
}

class TypeReplacement
sealed class TypeReplacement
{
public TypeReplacement(string line)
{
Expand Down Expand Up @@ -100,7 +100,7 @@ public string UnmanagedTypeName
}
}

class Parameter
sealed class Parameter
{
public Parameter(string name, TypeReplacement type)
{
Expand All @@ -114,7 +114,7 @@ public Parameter(string name, TypeReplacement type)
public readonly TypeReplacement Type;
}

class FunctionDecl
sealed class FunctionDecl
{
public FunctionDecl(string line, Dictionary<string, TypeReplacement> ThunkReturnTypes, Dictionary<string, TypeReplacement> ThunkTypes)
{
Expand All @@ -139,7 +139,7 @@ public FunctionDecl(string line, Dictionary<string, TypeReplacement> ThunkReturn
}

string parameterList = line.Substring(indexOfOpenParen + 1, indexOfCloseParen - indexOfOpenParen - 1).Canonicalize();
string[] parametersString = parameterList.Length == 0 ? new string[0] : parameterList.Split(',');
string[] parametersString = parameterList.Length == 0 ? Array.Empty<string>() : parameterList.Split(',');
List<Parameter> parameters = new List<Parameter>();

foreach (string parameterString in parametersString)
Expand All @@ -161,10 +161,10 @@ public FunctionDecl(string line, Dictionary<string, TypeReplacement> ThunkReturn
public readonly string FunctionName;
public readonly TypeReplacement ReturnType;
public readonly Parameter[] Parameters;
public readonly bool ManualNativeWrapper = false;
public readonly bool ManualNativeWrapper;
}

class Program
static class Program
{
enum ParseMode
{
Expand Down Expand Up @@ -406,13 +406,13 @@ class JitInterfaceWrapper : public ICorJitInfo
");

API_Wrapper_Generic_Core(tw, functionData,
funcNameFunc: (FunctionDecl decl)=>$"{decl.FunctionName }",
beforeCallFunc:(FunctionDecl)=>" CorInfoExceptionClass* pException = nullptr;",
afterCallFunc: (FunctionDecl decl) => " if (pException != nullptr) throw pException;",
wrappedObjectName: "_callbacks",
useNativeType2: false,
addVirtualPrefix: true,
API_Wrapper_Generic_Core(tw, functionData,
funcNameFunc: (FunctionDecl decl) => $"{decl.FunctionName}",
beforeCallFunc: (FunctionDecl) => " CorInfoExceptionClass* pException = nullptr;",
afterCallFunc: (FunctionDecl decl) => " if (pException != nullptr) throw pException;",
wrappedObjectName: "_callbacks",
useNativeType2: false,
addVirtualPrefix: true,
skipManualWrapper: true);

tw.WriteLine("};");
Expand All @@ -432,7 +432,7 @@ static void WriteAPI_Names(TextWriter tw, IEnumerable<FunctionDecl> functionData
");
}

static void API_Wrapper_Generic_Core(TextWriter tw, IEnumerable<FunctionDecl> functionData, Func<FunctionDecl, string> funcNameFunc, Func<FunctionDecl, string> beforeCallFunc, Func<FunctionDecl,string> afterCallFunc, string wrappedObjectName, bool useNativeType2, bool addVirtualPrefix, bool skipManualWrapper)
static void API_Wrapper_Generic_Core(TextWriter tw, IEnumerable<FunctionDecl> functionData, Func<FunctionDecl, string> funcNameFunc, Func<FunctionDecl, string> beforeCallFunc, Func<FunctionDecl, string> afterCallFunc, string wrappedObjectName, bool useNativeType2, bool addVirtualPrefix, bool skipManualWrapper)
{
foreach (FunctionDecl decl in functionData)
{
Expand Down Expand Up @@ -516,35 +516,35 @@ string GetNativeType(TypeReplacement typeReplacement)
}
}

static void API_Wrapper_Generic(TextWriter tw, IEnumerable<FunctionDecl> functionData, string header, string footer, string cppType, Func<FunctionDecl, string> beforeCallFunc, Func<FunctionDecl,string> afterCallFunc, string wrappedObjectName)
static void API_Wrapper_Generic(TextWriter tw, IEnumerable<FunctionDecl> functionData, string header, string footer, string cppType, Func<FunctionDecl, string> beforeCallFunc, Func<FunctionDecl, string> afterCallFunc, string wrappedObjectName)
{
WriteAutogeneratedHeader(tw);
tw.Write(header);

API_Wrapper_Generic_Core(tw, functionData, funcNameFunc: (FunctionDecl decl)=>$"{cppType}::{ decl.FunctionName }", beforeCallFunc:beforeCallFunc, afterCallFunc: afterCallFunc, wrappedObjectName: wrappedObjectName, useNativeType2: true, addVirtualPrefix: false, skipManualWrapper: false);
API_Wrapper_Generic_Core(tw, functionData, funcNameFunc: (FunctionDecl decl) => $"{cppType}::{decl.FunctionName}", beforeCallFunc: beforeCallFunc, afterCallFunc: afterCallFunc, wrappedObjectName: wrappedObjectName, useNativeType2: true, addVirtualPrefix: false, skipManualWrapper: false);

tw.Write(footer);
}

static void API_Wrapper(TextWriter tw, IEnumerable<FunctionDecl> functionData)
{
API_Wrapper_Generic(tw, functionData,
header:@"
API_Wrapper_Generic(tw, functionData,
header: @"
#define API_ENTER(name) wrapComp->CLR_API_Enter(API_##name);
#define API_LEAVE(name) wrapComp->CLR_API_Leave(API_##name);
/**********************************************************************************/
// clang-format off
/**********************************************************************************/
",
",
footer: @"
/**********************************************************************************/
// clang-format on
/**********************************************************************************/
",
cppType: "WrapICorJitInfo",
beforeCallFunc: (FunctionDecl decl)=> $" API_ENTER({decl.FunctionName});",
afterCallFunc: (FunctionDecl decl)=> $" API_LEAVE({decl.FunctionName});",
beforeCallFunc: (FunctionDecl decl) => $" API_ENTER({decl.FunctionName});",
afterCallFunc: (FunctionDecl decl) => $" API_LEAVE({decl.FunctionName});",
wrappedObjectName: "wrapHnd");
}

Expand All @@ -571,7 +571,7 @@ static void SPMI_ICorJitInfoImpl(TextWriter tw, IEnumerable<FunctionDecl> functi

foreach (FunctionDecl decl in functionData)
{
tw.Write($"{Environment.NewLine}{decl.ReturnType.NativeTypeName2} { decl.FunctionName}(");
tw.Write($"{Environment.NewLine}{decl.ReturnType.NativeTypeName2} {decl.FunctionName}(");
bool isFirst = true;
foreach (Parameter param in decl.Parameters)
{
Expand All @@ -597,37 +597,37 @@ static void SPMI_ICorJitInfoImpl(TextWriter tw, IEnumerable<FunctionDecl> functi

static void SPMI_ShimCounter_ICorJitInfo(TextWriter tw, IEnumerable<FunctionDecl> functionData)
{
API_Wrapper_Generic(tw, functionData,
header:@"
API_Wrapper_Generic(tw, functionData,
header: @"
#include ""standardpch.h""
#include ""icorjitinfo.h""
#include ""superpmi-shim-counter.h""
#include ""icorjitcompiler.h""
#include ""spmiutil.h""
",
",
footer: Environment.NewLine,
cppType: "interceptor_ICJI",
beforeCallFunc: (FunctionDecl decl)=> $" mcs->AddCall(\"{decl.FunctionName}\");",
afterCallFunc: (FunctionDecl decl)=> null,
beforeCallFunc: (FunctionDecl decl) => $" mcs->AddCall(\"{decl.FunctionName}\");",
afterCallFunc: (FunctionDecl decl) => null,
wrappedObjectName: "original_ICorJitInfo");
}

static void SPMI_ShimSimple_ICorJitInfo(TextWriter tw, IEnumerable<FunctionDecl> functionData)
{
API_Wrapper_Generic(tw, functionData,
header:@"
API_Wrapper_Generic(tw, functionData,
header: @"
#include ""standardpch.h""
#include ""icorjitinfo.h""
#include ""superpmi-shim-simple.h""
#include ""icorjitcompiler.h""
#include ""spmiutil.h""
",
",
footer: Environment.NewLine,
cppType: "interceptor_ICJI",
beforeCallFunc: (FunctionDecl decl)=> null,
afterCallFunc: (FunctionDecl decl)=> null,
beforeCallFunc: (FunctionDecl decl) => null,
afterCallFunc: (FunctionDecl decl) => null,
wrappedObjectName: "original_ICorJitInfo");
}

Expand Down

0 comments on commit 7ba371c

Please sign in to comment.