private void DefineStructureType( IType type, int line, int offset, int flags, CollectionMetadata structureType, CollectionMetadata members) { structureType.Add( string.Format( @"0x13\00{0}\00{1}\00{2}\00{3}\00{4}\00{5}\000", type.Name, line, type.GetTypeSize(this.llvmWriter, true) * 8, LlvmWriter.PointerSize * 8, offset, flags), this.file, null, null, members, null, null, this.structuresByName ? type.FullName : null); if (this.structuresByName) { this.retainedTypes.Add(structureType); } }
public CollectionMetadata DefineMember(IField field, bool create = false, CollectionMetadata structureType = null) { var line = 0; var size = field.FieldType.GetTypeSize(true) * 8; var align = LlvmWriter.PointerSize * 8; var offset = !field.IsStatic ? field.GetFieldOffset() * 8 : 0; // static var flags = field.IsStatic ? 4096 : 0; CollectionMetadata memberMetadata; if (!create && this.typeMembersMetadataCache.TryGetValue(field, out memberMetadata)) { return(memberMetadata); } var fieldMetadata = new CollectionMetadata(this.indexedMetadata); var typeMember = fieldMetadata.Add( string.Format(@"0xd\00{0}\00{1}\00{2}\00{3}\00{4}\00{5}", field.Name, line, size, align, offset, flags), this.file, this.structuresByName || structureType == null ? (object)this.DefineType(field.DeclaringType) : (object)structureType, this.DefineType(field.FieldType)); if (this.structuresByName) { typeMember.Add((object)null); } typeMembersMetadataCache[field] = typeMember; return(typeMember); }
private CollectionMetadata DefineMembers(IType type, CollectionMetadata structureType) { var members = new CollectionMetadata(this.indexedMetadata); foreach (var field in IlReader.Fields(type, this.llvmWriter)) { members.Add(this.DefineMember(field, true, structureType)); } return(members); }
public DebugInfoSourceMethodBuilder( DebugInfoGenerator debugInfoGenerator, ISourceMethod method, CollectionMetadata file, CollectionMetadata subprograms) { this.debugInfoGenerator = debugInfoGenerator; CollectionMetadata functionVariables; subprograms.Add(this.function = debugInfoGenerator.DefineMethod(method, file, out functionVariables)); }
public DebugInfoSourceMethodBuilder(DebugInfoGenerator debugInfoGenerator, ISourceMethod method, CollectionMetadata file, CollectionMetadata subprograms) { this.debugInfoGenerator = debugInfoGenerator; CollectionMetadata subroutineTypes; CollectionMetadata functionVariables; subprograms.Add(this.function = debugInfoGenerator.DefineMethod(method, file, out functionVariables)); this.functionVariables = functionVariables; }
// TODO: make it flexible private CollectionMetadata DefineArrayMembers(IType type, CollectionMetadata structureType) { Debug.Assert(type != null && type.IsArray); var members = new CollectionMetadata(this.indexedMetadata); var elementsCount = 10; CollectionMetadata countMember = null; if (!type.IsMultiArray) { var countOffset = type.GetFieldByName("length", this.llvmWriter).GetFieldOffset(this.llvmWriter); countMember = this.DefineMember( "length", this.llvmWriter.System.System_Int32, countOffset * 8, type, true, structureType); members.Add(countMember); } var dataOffset = type.GetFieldByName("data", this.llvmWriter).GetFieldOffset(this.llvmWriter); members.Add( this.DefineMember( "data", type, dataOffset * 8, type, true, structureType, this.DefineCArrayType(type.GetElementType(), 0, 0, elementsCount, countMember), 0)); return(members); }
public CollectionMetadata DefineMember( string fieldName, IType fieldType, int offset, IType fieldDeclaringType, bool create = false, CollectionMetadata structureType = null, object definedMedataType = null, int count = 1) { var line = 0; var size = fieldType.GetTypeSize(this.llvmWriter, true) * 8 * count; var align = LlvmWriter.PointerSize * 8; // static var flags = 0; var key = string.Concat(fieldType, offset); CollectionMetadata memberMetadata; if (!create && this.typeMembersByOffsetMetadataCache.TryGetValue(key, out memberMetadata)) { return(memberMetadata); } var fieldMetadata = new CollectionMetadata(this.indexedMetadata); var typeMember = fieldMetadata.Add( string.Format(@"0xd\00{0}\00{1}\00{2}\00{3}\00{4}\00{5}", fieldName, line, size, align, offset, flags), this.file, this.structuresByName || structureType == null ? this.FindStructure(fieldDeclaringType) : (object)structureType, definedMedataType); if (this.structuresByName) { typeMember.Add((object)null); } this.typeMembersByOffsetMetadataCache[key] = typeMember; return(typeMember); }
public CollectionMetadata DefineMethod( ISourceMethod method, CollectionMetadata file, out CollectionMetadata functionVariables) { // Flags 256 - definition (as main()), 259 - public (member of a class) var flag = 256; // Line number of the opening '{' of the function var scopeLine = method.LineNumber; // find method definition this.methodDefinition = this.llvmWriter.MethodsByToken[method.Token]; var methodReferenceType = this.llvmWriter.WriteToString( () => this.llvmWriter.WriteMethodPointerType(this.llvmWriter.Output, this.methodDefinition)); var methodDefinitionName = this.llvmWriter.WriteToString( () => this.llvmWriter.WriteMethodDefinitionName(this.llvmWriter.Output, this.methodDefinition)); CollectionMetadata subroutineTypes; CollectionMetadata parametersTypes; // add compile unit template var methodMetadataDefinition = new CollectionMetadata(this.indexedMetadata).Add( string.Format( @"0x2e\00{0}\00{1}\00{2}\00{3}\000\001\000\000\00{4}\000\00{5}", method.Name, method.DisplayName, method.LinkageName, method.LineNumber, flag, scopeLine), // Source directory (including trailing slash) & file pair file, // Reference to context descriptor this.fileType, // Subroutine types subroutineTypes = new CollectionMetadata(this.indexedMetadata), // indicates which base type contains the vtable pointer for the derived class null, // function method reference ex. "i32 ()* @main" new PlainTextMetadata(string.Concat(methodReferenceType, " ", methodDefinitionName)), // Lists function template parameters null, // Function declaration descriptor null, // List of function variables functionVariables = new CollectionMetadata(this.indexedMetadata)); // add subrouting type subroutineTypes.Add( @"0x15\00\000\000\000\000\000\000", null, null, null, parametersTypes = new CollectionMetadata(this.indexedMetadata), null, null, null); this.currentFunction = methodMetadataDefinition; // add return type parametersTypes.Add( !this.methodDefinition.ReturnType.IsVoid() && !this.methodDefinition.ReturnType.IsStructureType() ? this.DefineType(this.methodDefinition.ReturnType) : null); foreach (var parameter in this.methodDefinition.GetParameters()) { parametersTypes.Add(this.DefineType(parameter.ParameterType)); } return(methodMetadataDefinition); }