本文整理汇总了C#中AssemblyCompiler类的典型用法代码示例。如果您正苦于以下问题:C# AssemblyCompiler类的具体用法?C# AssemblyCompiler怎么用?C# AssemblyCompiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AssemblyCompiler类属于命名空间,在下文中一共展示了AssemblyCompiler类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Create
/// <summary>
/// Create annotations for all included attributes
/// </summary>
public static void Create(AssemblyCompiler compiler, ICustomAttributeProvider attributeProvider,
IAnnotationProvider annotationProvider, DexTargetPackage targetPackage, bool customAttributesOnly = false)
{
if (!attributeProvider.HasCustomAttributes)
return;
var annotations = new List<Annotation>();
foreach (var attr in attributeProvider.CustomAttributes)
{
var attributeType = attr.AttributeType.Resolve();
if (!attributeType.HasIgnoreAttribute())
{
Create(compiler, attr, attributeType, annotations, targetPackage);
}
}
if (annotations.Count > 0)
{
// Create 1 IAttributes annotation
var attrsAnnotation = new Annotation { Visibility = AnnotationVisibility.Runtime };
attrsAnnotation.Type = compiler.GetDot42InternalType("IAttributes").GetClassReference(targetPackage);
attrsAnnotation.Arguments.Add(new AnnotationArgument("Attributes", annotations.ToArray()));
annotationProvider.Annotations.Add(attrsAnnotation);
}
if (!customAttributesOnly)
{
// Add annotations specified using AnnotationAttribute
foreach (var attr in attributeProvider.CustomAttributes.Where(IsAnnotationAttribute))
{
var annotationType = (TypeReference) attr.ConstructorArguments[0].Value;
var annotationClass = annotationType.GetClassReference(targetPackage, compiler.Module);
annotationProvider.Annotations.Add(new Annotation(annotationClass, AnnotationVisibility.Runtime));
}
}
}
开发者ID:jakesays,项目名称:dot42,代码行数:36,代码来源:AnnotationBuilder.cs
示例2: Generate
private Assembly Generate()
{
var assemblyPath = Path.GetDirectoryName(this.assembly.Location);
var trees = new ConcurrentBag<SyntaxTree>();
var allowUnsafe = false;
Parallel.ForEach(assembly.GetExportedTypes()
.Where(_ => string.IsNullOrWhiteSpace(_.Validate(this.options.Serialization, new AssemblyNameGenerator(_))) && !typeof(Array).IsAssignableFrom(_) &&
!typeof(Enum).IsAssignableFrom(_) && !typeof(ValueType).IsAssignableFrom(_) &&
!typeof(Delegate).IsAssignableFrom(_)), _ =>
{
var builder = new AssemblyBuilder(_,
new ReadOnlyDictionary<int, ReadOnlyCollection<HandlerInformation>>(
new Dictionary<int, ReadOnlyCollection<HandlerInformation>>()),
new SortedSet<string>(), this.options);
builder.Build();
trees.Add(builder.Tree);
allowUnsafe |= builder.IsUnsafe;
});
var referencedAssemblies = this.assembly.GetReferencedAssemblies().Select(_ => Assembly.Load(_)).ToList();
referencedAssemblies.Add(this.assembly);
var compiler = new AssemblyCompiler(trees, this.options.Optimization,
new AssemblyNameGenerator(this.assembly).AssemblyName,
referencedAssemblies.AsReadOnly(), currentDirectory, allowUnsafe, this.options.AllowWarnings);
compiler.Compile();
return compiler.Result;
}
开发者ID:JamesBender,项目名称:Rocks,代码行数:29,代码来源:RockAssembly.cs
示例3: Convert
/// <summary>
/// Optimize expressions
/// </summary>
public static void Convert(AstNode ast, AssemblyCompiler compiler)
{
// Optimize enum2int(ldsfld(enum-const))
foreach (var node in ast.GetExpressions())
{
switch (node.Code)
{
case AstCode.Enum_to_int:
case AstCode.Enum_to_long:
{
var arg = node.Arguments[0];
XFieldReference fieldRef;
if (arg.Match(AstCode.Ldsfld, out fieldRef))
{
XFieldDefinition field;
object value;
if (fieldRef.TryResolve(out field) && field.IsStatic && field.DeclaringType.IsEnum && field.TryGetEnumValue(out value))
{
// Replace with ldc_ix
var wide = (node.Code == AstCode.Enum_to_long);
node.SetCode(wide ? AstCode.Ldc_I8 : AstCode.Ldc_I4);
node.Operand = wide ? (object)XConvert.ToLong(value) : XConvert.ToInt(value);
node.Arguments.Clear();
}
}
}
break;
}
}
}
开发者ID:rfcclub,项目名称:dot42,代码行数:33,代码来源:EnumOptimizer.cs
示例4: Create
/// <summary>
/// Create a type builder for the given type.
/// </summary>
internal static IClassBuilder[] Create(ReachableContext context, AssemblyCompiler compiler, TypeDefinition typeDef)
{
if (typeDef.FullName == "<Module>")
return new IClassBuilder[] { new SkipClassBuilder() };
if (typeDef.IsDelegate())
return new IClassBuilder[] {new DelegateClassBuilder(context, compiler, typeDef) };
if (typeDef.IsAttribute())
return new IClassBuilder[] {new AttributeClassBuilder(context, compiler, typeDef) };
if (typeDef.IsAnnotation())
return new IClassBuilder[] {new AnnotationClassBuilder(context, compiler, typeDef) };
if (typeDef.HasDexImportAttribute())
return new IClassBuilder[] {new DexImportClassBuilder(context, compiler, typeDef) };
if (typeDef.HasJavaImportAttribute())
return new IClassBuilder[] {CreateJavaImportBuilder(context, compiler, typeDef)};
if (typeDef.IsEnum)
{
if (typeDef.UsedInNullableT)
{
var nullableBaseClassBuilder = new NullableEnumBaseClassBuilder(context, compiler, typeDef);
IClassBuilder builder = new EnumClassBuilder(context, compiler, typeDef, nullableBaseClassBuilder);
return new[] { builder, nullableBaseClassBuilder };
}
return new IClassBuilder[] { new EnumClassBuilder(context, compiler, typeDef, null) };
}
else
{
IClassBuilder builder = new StandardClassBuilder(context, compiler, typeDef);
if (typeDef.UsedInNullableT)
return new[] { builder, new NullableBaseClassBuilder(context, compiler, typeDef) };
return new[] { builder };
}
}
开发者ID:rfcclub,项目名称:dot42,代码行数:35,代码来源:ClassBuilder.cs
示例5: Convert
/// <summary>
/// Optimize expressions
/// </summary>
public static void Convert(AstNode ast, AssemblyCompiler compiler)
{
// Convert IntPtr.Zero
foreach (var node in ast.GetExpressions(AstCode.Ldsfld))
{
var field = (XFieldReference)node.Operand;
if (field.DeclaringType.IsIntPtr() && (field.Name == "Zero"))
{
node.Code = AstCode.Ldnull;
node.Operand = null;
node.Arguments.Clear();
node.SetType(compiler.Module.TypeSystem.Object);
}
}
// Convert box(IntPtr)
foreach (var node in ast.GetExpressions(AstCode.Box))
{
var type = (XTypeReference)node.Operand;
if (type.IsIntPtr())
{
node.CopyFrom(node.Arguments[0]);
}
}
}
开发者ID:Xtremrules,项目名称:dot42,代码行数:28,代码来源:IntPtrConverter.cs
示例6: CreateOptimizedAst
/// <summary>
/// Convert the given method into optimized Ast format.
/// </summary>
internal protected static AstNode CreateOptimizedAst(AssemblyCompiler compiler, MethodSource source,
bool generateSetNextInstructionCode,
StopAstConversion debugStop = StopAstConversion.None,
AstOptimizationStep debugStopOptimizing = AstOptimizationStep.None
)
{
// Build AST
DecompilerContext context;
AstBlock ast;
if (source.IsDotNet)
{
context = new DecompilerContext(source.Method);
var astBuilder = new IL2Ast.AstBuilder(source.ILMethod, true, context);
var children = astBuilder.Build();
ast = new AstBlock(children.Select(x => x.SourceLocation).FirstOrDefault(), children);
if ((source.ILMethod.IsConstructor) && (source.Method.DeclaringType.Fields.Any(x => x.FieldType.IsEnum() || x.Name.EndsWith(NameConstants.Atomic.FieldUpdaterPostfix))))
{
// Ensure all fields are initialized
AddFieldInitializationCode(compiler, source, ast);
}
if (source.Method.NeedsGenericInstanceTypeParameter && (source.Name == ".ctor"))
{
// Add code to save the generic instance type parameter into the generic instance field.
AddGenericInstanceFieldInitializationCode(source, ast, compiler.Module.TypeSystem);
}
}
else if (source.IsJava)
{
var astBuilder = new Java2Ast.AstBuilder(compiler.Module, source.JavaMethod, source.Method.DeclaringType, true);
context = new DecompilerContext(source.Method);
ast = astBuilder.Build();
}
else if (source.IsAst)
{
context = new DecompilerContext(source.Method);
ast = source.Ast;
}
else
{
throw new NotSupportedException("Unknown source");
}
if (debugStop == StopAstConversion.AfterILConversion) return ast;
// Optimize AST
var astOptimizer = new AstOptimizer(context, ast);
astOptimizer.Optimize(debugStopOptimizing);
if (debugStop == StopAstConversion.AfterOptimizing) return ast;
// Optimize AST towards the target
TargetConverters.Convert(context, ast, source, compiler, debugStop);
if(generateSetNextInstructionCode)
SetNextInstructionGenerator.Convert(ast, source, compiler);
// Return return
return ast;
}
开发者ID:Xtremrules,项目名称:dot42,代码行数:62,代码来源:MethodBodyCompiler.cs
示例7: ConvertCastclass
/// <summary>
/// Convert node with code Cast.
/// </summary>
private static void ConvertCastclass(AssemblyCompiler compiler, AstExpression node, XTypeSystem typeSystem)
{
var type = (XTypeReference) node.Operand;
if (type.IsSystemArray())
{
// Call cast method
var arrayHelper = compiler.GetDot42InternalType(InternalConstants.CompilerHelperName).Resolve();
var castToArray = arrayHelper.Methods.First(x => x.Name == "CastToArray");
var castToArrayExpr = new AstExpression(node.SourceLocation, AstCode.Call, castToArray, node.Arguments).SetType(type);
node.CopyFrom(castToArrayExpr);
return;
}
string castMethod = null;
if (type.IsSystemCollectionsIEnumerable())
{
castMethod = "CastToEnumerable";
}
else if (type.IsSystemCollectionsICollection())
{
castMethod = "CastToCollection";
}
else if (type.IsSystemCollectionsIList())
{
castMethod = "CastToList";
}
else if (type.IsSystemIFormattable())
{
castMethod = "CastToFormattable";
}
if (castMethod != null)
{
// Call cast method
var arrayHelper = compiler.GetDot42InternalType(InternalConstants.CompilerHelperName).Resolve();
var castToArray = arrayHelper.Methods.First(x => x.Name == castMethod);
// Call "(x instanceof T) ? (T)x : asMethod(x)"
// "instanceof x"
var instanceofExpr = new AstExpression(node.SourceLocation, AstCode.SimpleInstanceOf, type, node.Arguments[0]).SetType(typeSystem.Bool);
// CastX(x)
var castXExpr = new AstExpression(node.SourceLocation, AstCode.Call, castToArray, node.Arguments[0]).SetType(typeSystem.Object);
// T(x)
var txExpr = new AstExpression(node.SourceLocation, AstCode.SimpleCastclass, type, node.Arguments[0]).SetType(type);
// Combine
var conditional = new AstExpression(node.SourceLocation, AstCode.Conditional, type, instanceofExpr, txExpr, castXExpr).SetType(type);
node.CopyFrom(conditional);
return;
}
// Normal castclass
node.Code = AstCode.SimpleCastclass;
}
开发者ID:rfcclub,项目名称:dot42,代码行数:61,代码来源:CastConverter.cs
示例8: InvalidOperationException
void IAssemblyCompilerStage.Setup(AssemblyCompiler compiler)
{
base.Setup(compiler);
scheduler = compiler.Pipeline.FindFirst<ICompilationSchedulerStage>();
if (scheduler == null)
throw new InvalidOperationException(@"No compilation scheduler found in the assembly compiler pipeline.");
}
开发者ID:grover,项目名称:MOSA-Project,代码行数:9,代码来源:AssemblyMemberCompilationSchedulerStage.cs
示例9: AddGenericDefinitionAnnotationIfGeneric
/// <summary>
/// Create a IGnericDefinition annotation and attaches it to the given provider.
/// TODO: this might better belong somewhere else.
/// </summary>
public static void AddGenericDefinitionAnnotationIfGeneric(this IAnnotationProvider provider, XTypeReference xtype, AssemblyCompiler compiler, DexTargetPackage targetPackage, bool forceTypeDefinition=false)
{
if (!xtype.IsGenericInstance && !xtype.IsGenericParameter)
return;
Annotation annotation = GetGenericDefinitionAnnotationForType(xtype, forceTypeDefinition, compiler, targetPackage);
if(annotation != null)
provider.Annotations.Add(annotation);
}
开发者ID:jakesays,项目名称:dot42,代码行数:13,代码来源:DexAnnotations.cs
示例10: CreateMapping
/// <summary>
/// Initializes a mapping.
/// </summary>
public static AttributeAnnotationMapping CreateMapping(
ISourceLocation sequencePoint,
AssemblyCompiler compiler,
DexTargetPackage targetPackage,
TypeDefinition attributeType,
ClassDefinition attributeClass)
{
return new AttributeAnnotationMapping(attributeType, attributeClass);
}
开发者ID:Xtremrules,项目名称:dot42,代码行数:12,代码来源:AttributeAnnotationInstanceBuilder.cs
示例11: DelegateType
/// <summary>
/// Default ctor
/// </summary>
public DelegateType(AssemblyCompiler compiler, XTypeDefinition delegateType, ClassDefinition interfaceClass, Dex target, NameConverter nsConverter)
{
this.compiler = compiler;
this.delegateType = delegateType;
this.interfaceClass = interfaceClass;
// Build invoke prototype
invokeMethod = delegateType.Methods.First(x => x.EqualsName("Invoke"));
}
开发者ID:Xtremrules,项目名称:dot42,代码行数:12,代码来源:DelegateType.cs
示例12: Convert
public static void Convert(AstNode ast, MethodSource currentMethod, AssemblyCompiler compiler)
{
foreach (var block in ast.GetSelfAndChildrenRecursive<AstBlock>())
{
for (int i = 0; i < block.Body.Count; ++i)
{
var expr = block.Body[i] as AstExpression;
if(expr == null)
continue;
var interlockedPairs = expr.GetExpressionPairs(p =>
p.Code == AstCode.Call
&& ((XMethodReference) p.Operand).DeclaringType.FullName == "System.Threading.Interlocked")
.ToList();
if(interlockedPairs.Count == 0)
continue;
if (interlockedPairs.Count > 1)
throw new CompilerException("The Interlocked converter can not handle more than one interlocked call per statement. Try splittig the statement up.");
var interlockedCall = interlockedPairs.First().Expression;
// first parameter should be a reference to a field,
// (but be lenient if we don't find what we expect)
var targetExpr = interlockedCall.Arguments[0];
XFieldReference field = null;
if (targetExpr.InferredType.IsByReference)
{
field = targetExpr.Operand as XFieldReference;
if (field != null)
{
// check if we have an atomic updater
var updater = field.DeclaringType.Resolve().Fields
.FirstOrDefault(f => f.Name == field.Name + NameConstants.Atomic.FieldUpdaterPostfix);
if (updater != null)
{
var method = (XMethodReference) interlockedCall.Operand;
var methodName = method.Name.Split('$')[0]; // retrieve original name.
if (InterlockedUsingUpdater(interlockedCall, methodName, field, updater, targetExpr, interlockedPairs.First().Parent, compiler))
continue;
}
}
}
FailsafeInterlockedUsingLocking(field, expr, targetExpr, block, i, compiler, currentMethod);
}
}
}
开发者ID:Xtremrules,项目名称:dot42,代码行数:56,代码来源:InterlockedConverter.cs
示例13: CreateJavaImportBuilder
/// <summary>
/// Create a type builder for the given type with JavaImport attribute.
/// </summary>
internal static IClassBuilder CreateJavaImportBuilder(ReachableContext context, AssemblyCompiler compiler, TypeDefinition typeDef)
{
var javaImportAttr = typeDef.GetJavaImportAttribute(true);
var className = (string)javaImportAttr.ConstructorArguments[0].Value;
ClassFile classFile;
if (!compiler.ClassLoader.TryLoadClass(className, out classFile))
throw new ClassNotFoundException(className);
context.RecordReachableType(classFile);
return new SkipClassBuilder();
}
开发者ID:rfcclub,项目名称:dot42,代码行数:13,代码来源:ClassBuilder.cs
示例14: Convert
public static void Convert(AstNode ast, MethodSource currentMethod, AssemblyCompiler compiler)
{
// only work on MoveNext of IAsyncStateMachine implementations.
if (currentMethod.Name != "MoveNext" && currentMethod.Name != "IAsyncStateMachine_MoveNext")
return;
var declaringType = currentMethod.Method.DeclaringType.Resolve();
if (declaringType.Interfaces.All(i => i.FullName != "System.Runtime.CompilerServices.IAsyncStateMachine"))
return;
foreach(var block in ast.GetSelfAndChildrenRecursive<AstBlock>())
FixBlock(block);
}
开发者ID:Xtremrules,项目名称:dot42,代码行数:12,代码来源:FixAsyncStateMachine.cs
示例15: Create
/// <summary>
/// Default ctor
/// </summary>
public static FieldBuilder Create(AssemblyCompiler compiler, FieldDefinition field)
{
if (field.IsAndroidExtension())
return new DexImportFieldBuilder(compiler, field);
if (field.DeclaringType.IsEnum)
{
if (!field.IsStatic)
throw new ArgumentException("value field should not be implemented this way");
return new EnumFieldBuilder(compiler, field);
}
return new FieldBuilder(compiler, field);
}
开发者ID:rfcclub,项目名称:dot42,代码行数:15,代码来源:FieldBuilder.cs
示例16: Create
/// <summary>
/// Default ctor
/// </summary>
public static MethodBuilder Create(AssemblyCompiler compiler, MethodDefinition method)
{
string dllName;
if (method.IsAndroidExtension())
{
return new DexImportMethodBuilder(compiler, method);
}
if (method.TryGetDllImportName(out dllName))
{
return new DllImportMethodBuilder(compiler, method, dllName);
}
return new MethodBuilder(compiler, method);
}
开发者ID:rfcclub,项目名称:dot42,代码行数:16,代码来源:MethodBuilder.cs
示例17: BuildPrototype
/// <summary>
/// Create a prototype for the given methods signature
/// </summary>
internal static Prototype BuildPrototype(AssemblyCompiler compiler, DexTargetPackage targetPackage, ClassDefinition declaringClass, MethodDefinition method)
{
var result = new Prototype();
var module = compiler.Module;
result.ReturnType = method.ReturnType.GetReference(XTypeUsageFlags.ReturnType, targetPackage, module);
var paramIndex = 0;
foreach (var p in method.Parameters)
{
var dparameter = new Parameter(p.GetReference(XTypeUsageFlags.ParameterType, targetPackage, module), "p" + paramIndex++);
result.Parameters.Add(dparameter);
}
return result;
}
开发者ID:rfcclub,项目名称:dot42,代码行数:16,代码来源:PrototypeBuilder.cs
示例18: CreateOptimizedAst
/// <summary>
/// Convert the given method into optimized Ast format.
/// </summary>
protected static AstNode CreateOptimizedAst(AssemblyCompiler compiler, MethodSource source)
{
// Build AST
DecompilerContext context;
AstBlock ast;
if (source.IsDotNet)
{
context = new DecompilerContext(source.Method);
var astBuilder = new IL2Ast.AstBuilder(source.ILMethod, true, context);
var children = astBuilder.Build();
ast = new AstBlock(children.Select(x => x.SourceLocation).FirstOrDefault(), children);
if ((source.ILMethod.IsConstructor) && (source.Method.DeclaringType.Fields.Any(x => x.FieldType.IsEnum())))
{
// Ensure all fields are initialized
AddFieldInitializationCode(source, ast);
}
if (source.Method.NeedsGenericInstanceTypeParameter && (source.Name == ".ctor"))
{
// Add code to safe the generic instance type parameter into the generic instance field.
AddGenericInstanceFieldInitializationCode(ast);
}
}
else if (source.IsJava)
{
var astBuilder = new Java2Ast.AstBuilder(compiler.Module, source.JavaMethod, source.Method.DeclaringType, true);
context = new DecompilerContext(source.Method);
ast = astBuilder.Build();
}
else if (source.IsAst)
{
context = new DecompilerContext(source.Method);
ast = source.Ast;
}
else
{
throw new NotSupportedException("Unknown source");
}
// Optimize AST
var astOptimizer = new AstOptimizer(context, ast);
astOptimizer.Optimize();
// Optimize AST towards the target
TargetConverters.Convert(context, ast, source, compiler);
// Return return
return ast;
}
开发者ID:rfcclub,项目名称:dot42,代码行数:51,代码来源:MethodBodyCompiler.cs
示例19: CreateAssemblyTypes
public static void CreateAssemblyTypes(AssemblyCompiler compiler, DexTargetPackage targetPackage,
IEnumerable<TypeDefinition> reachableTypes)
{
var xAssemblyTypes = compiler.GetDot42InternalType("AssemblyTypes");
var assemblyTypes = (ClassDefinition)xAssemblyTypes.GetClassReference(targetPackage);
var entryAssembly = assemblyTypes.Fields.First(f => f.Name == "EntryAssembly");
var iAssemblyTypes = compiler.GetDot42InternalType("IAssemblyTypes").GetClassReference(targetPackage);
entryAssembly.Value = compiler.Assemblies.First().Name.Name;
List<object> values = new List<object>();
string prevAssemblyName = null;
foreach (var type in reachableTypes.OrderBy(t => t.Module.Assembly.Name.Name)
.ThenBy(t => t.Namespace)
.ThenBy(t => t.Name))
{
var assemblyName = type.module.Assembly.Name.Name;
if (assemblyName == "dot42")
{
// group all android types into virtual "android" assembly,
// so that MvvmCross can find all view-types.
// -- is this a hack?
if (type.Namespace.StartsWith("Android"))
assemblyName = "android";
else // ignore other types, these will get the "default" assembly.
continue;
}
if (prevAssemblyName != assemblyName)
{
values.Add("!" + assemblyName); // we need some identification of assemblies.
prevAssemblyName = assemblyName;
}
// TODO: With compilationmode=all reachable types contains <Module>
// this should be excluded earlier.
if (type.FullName == "<Module>")
continue;
var tRef = type.GetReference(targetPackage, compiler.Module) as ClassReference;
if(tRef != null) values.Add(tRef.Fullname);
}
var anno = new Annotation(iAssemblyTypes, AnnotationVisibility.Runtime,
new AnnotationArgument("AssemblyTypeList", values.ToArray()));
((IAnnotationProvider)assemblyTypes).Annotations.Add(anno);
}
开发者ID:Xtremrules,项目名称:dot42,代码行数:48,代码来源:AssemblyTypesBuilder.cs
示例20: DelegateInstanceTypeBuilder
/// <summary>
/// Create the current type as class definition.
/// </summary>
internal DelegateInstanceTypeBuilder(
ISourceLocation sequencePoint,
AssemblyCompiler compiler, DexTargetPackage targetPackage,
ClassDefinition delegateClass,
XMethodDefinition invokeMethod, Prototype invokePrototype,
XMethodDefinition calledMethod)
{
this.sequencePoint = sequencePoint;
this.compiler = compiler;
this.targetPackage = targetPackage;
this.delegateClass = delegateClass;
this.invokeMethod = invokeMethod;
this.invokePrototype = invokePrototype;
this.calledMethod = calledMethod;
this.multicastDelegateClass = compiler.GetDot42InternalType("System", "MulticastDelegate").GetClassReference(targetPackage);
}
开发者ID:Xtremrules,项目名称:dot42,代码行数:19,代码来源:DelegateInstanceTypeBuilder.cs
注:本文中的AssemblyCompiler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论