Ejemplo n.º 1
0
        public void Execute(CompilerTypeContext context)
        {
            var @type = context.Type;

            if (@type.IsValueType)
            {
                return;
            }

            context.OutputFile.WriteLine();
            List <string> labels = new();

            foreach (var m in @type.GetVirtualMethods())
            {
                labels.Add(m.GetLabel());
            }

            string outputLine = $"{context.Type.Name.ToValidName()}_VTable: ";

            if (labels.Count > 0)
            {
                outputLine += $" .word {string.Join(',', labels)}";
            }
            else
            {
                outputLine += $" .byte 0";
            }

            context.OutputFile.WriteLine(outputLine);
        }
Ejemplo n.º 2
0
        public void Execute(CompilerTypeContext context)
        {
            var fields = context.Type.GetFields(BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public);

            foreach (var field in fields.Where(f => !f.IsLiteral).OrderBy(f => f.FieldType.IsReferenceCounted() ? 0 : 1))
            {
                string outputLine = $"{context.Type.Name.ToValidName()}_field_{field.Name.ToValidName()} .byte 0";
                context.OutputFile.WriteLine(outputLine);
            }
        }
Ejemplo n.º 3
0
        public void Execute(CompilerContext context)
        {
            context.Methods = new List <CompilerMethodContext>();
            foreach (var @type in context.Assembly.GetTypes())
            {
                if (@type.IsValueType)
                {
                    continue;
                }
                // context.GlobalOutputFile.WriteLine($".include \".\\\\{type.Name}.asm\"");

                var normalizedName = type.Name.ToValidName();
                var import         = $"\"./{normalizedName}.asm\"";
                context.GlobalOutputFile.WriteLine($".include {import}");
                using (var outputFile = File.CreateText(Path.Combine(context.OutputDirectory, $"{normalizedName}.asm")))
                {
                    var typeContext = new CompilerTypeContext()
                    {
                        CompilerContext = context,
                        Type            = @type,
                        OutputFile      = outputFile
                    };
                    foreach (var pass in _typePasses)
                    {
                        pass.Execute(typeContext);
                    }

                    var methods = @type.GetMethods(BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).OfType <MethodBase>();
                    // var staticconstructors = @type.GetConstructors(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).OfType<MethodBase>();
                    // var constructors = @type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).OfType<MethodBase>();
                    // if (constructors.Count() > 1)
                    //     throw new Exception($"Only 1 constructor supported (at the moment). Type : {@type} ");

                    foreach (var method in methods.Where(m => m.DeclaringType != typeof(object)))
                    {
                        var methodContext = new CompilerMethodContext()
                        {
                            CompilerContext = context,
                            TypeContext     = typeContext,
                            Lines           = new List <ILOperation>(),
                            Method          = method,
                        };
                        context.Methods.Add(methodContext);

                        foreach (var pass in _methodPasses)
                        {
                            pass.Execute(methodContext);
                        }
                    }
                }
            }
        }