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;
        }
Exemplo n.º 2
0
        private void DefineStructureType(IType type, int line, int offset, int flags, CollectionMetadata structureType)
        {
            structureType.Add(
                    string.Format(
                        @"0x13\00{0}\00{1}\00{2}\00{3}\00{4}\00{5}\000", type.Name, line, type.GetTypeSize(true) * 8, LlvmWriter.PointerSize * 8, offset, flags),
                    this.file,
                    null,
                    null,
                // members
                    this.DefineMembers(type, structureType),
                    null,
                    null,
                    this.structuresByName ? type.FullName : null);

            if (structuresByName)
            {
                this.retainedTypes.Add(structureType);
            }
        }
Exemplo n.º 3
0
        private CollectionMetadata DefineMembers(IType type, CollectionMetadata structureType)
        {
            var members = new CollectionMetadata(this.indexedMetadata);
            foreach (var field in IlReader.Fields(type))
            {
                members.Add(this.DefineMember(field, true, structureType));
            }

            return members;
        }
Exemplo n.º 4
0
        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.writer.MethodsByToken[method.Token];

            var methodReferenceType = this.writer.WriteToString(() => this.writer.WriteMethodPointerType(this.writer.Output, this.methodDefinition));
            var methodDefinitionName = this.writer.WriteToString(() => this.writer.WriteMethodDefinitionName(this.writer.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;
        }
Exemplo n.º 5
0
        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;
        }