Exemplo n.º 1
0
        Statement CreateBuildError(Source src, bool isError, AstExpression value = null)
        {
            var type = "build_" + (isError
                                    ? "error"
                                    : "warning");

            if (!IsFunctionScope)
            {
                return(Error(src, ErrorCode.E0000, type.Quote() + " can only be used in methods"));
            }

            var message = value != null
                    ? Compiler.CompileConstant(value, Namescope, Essentials.String).Value as string ??
                          "<invalid>"
                    : Function.Quote() + " does not support this build target";

            if (isError)
            {
                /*if (!Compiler.Backend.IsDefault)
                 *  Log.Error(s.Source, ErrorCode.E0000, message);*/
                return(new Throw(src,
                                 ILFactory.NewObject(src, Essentials.Exception,
                                                     new Constant(src, Essentials.String, type + ": " + message))));
            }

            if (!Compiler.Backend.IsDefault)
            {
                Log.Warning(src, ErrorCode.W0000, type + ": " + message);
            }
            return(new NoOp(src, message));
        }
Exemplo n.º 2
0
        public Compiler(Log log, Backend backend, SourcePackage package, CompilerOptions options)
            : base(log)
        {
            // This is a block of dependency injection to initialize the Compiler
            var il         = new Namespace();
            var extensions = new ExtensionRoot();

            Backend = backend;
            var disk = Disk = new Disk(log, true);

            Shell = new Shell(log);
            var essentials   = Essentials = new Essentials();
            var resolver     = NameResolver = new NameResolver(this);
            var ilf          = ILFactory = new ILFactory(backend, il, essentials, resolver, this);
            var data         = Data = new BuildData(il, extensions, ilf);
            var environment  = Environment = new BuildEnvironment(backend, package, options, extensions, ilf, this);
            var input        = Input = new SourceReader(log, package, environment);
            var blockBuilder = BlockBuilder = new BlockBuilder(backend, il, ilf, resolver, this);
            var typeBuilder  = TypeBuilder = new TypeBuilder(environment, ilf, resolver, this);
            var bundle       = BundleBuilder = new BundleBuilder(backend, environment, ilf, this);

            AstProcessor = new AstProcessor(il, blockBuilder, typeBuilder, resolver, environment);
            UxlProcessor = new UxlProcessor(disk, backend.Name, il, extensions, environment, ilf);
            Plugins      = new PluginCache(log, bundle, ilf, environment);
            var pass = Pass = new CompilerPass(disk, data, environment, ilf, backend, input.Package, typeBuilder, resolver);

            Utilities      = new Utilities(il, pass);
            ILVerifier     = new ILVerifier(pass);
            ConstantFolder = new ConstantFolder(pass);
            ILStripper     = new ILStripper(pass);
        }
        public Expression CompileImplicitCast(Source src, string expectedType, Expression value)
        {
            var result = TryCompileImplicitCast(src, ILFactory.GetType(src, expectedType), value, true);

            ImplicitCastStack.RemoveLast();
            return(result);
        }
Exemplo n.º 4
0
        public TestSetupTransform(CompilerPass parent)
            : base(parent)
        {
            if (Environment.Options.TestOptions == null)
            {
                throw new InvalidOperationException("Internal error, could not get test options");
            }

            _testOptions         = Environment.Options.TestOptions.Value;
            _testAttributeType   = ILFactory.GetType("Uno.Testing.TestAttribute");
            _ignoreAttributeType = ILFactory.GetType("Uno.Testing.IgnoreAttribute");

            if (_testAttributeType is InvalidType)
            {
                throw new InvalidOperationException("Did you forget to reference the Uno.Testing package?");
            }

            _actionType    = (DelegateType)ILFactory.GetType("Uno.Action");
            _testSetupType = ILFactory.GetType("Uno.Testing.TestSetup");

            _appClass = Essentials.Application;

            _source           = Package.Source;
            _testRegistryType = ILFactory.GetType("Uno.Testing.Registry");
            _mainClass        = new ClassType(_source, Data.IL, null, Modifiers.Generated | Modifiers.Public, "MainClass");
            _mainClass.SetBase(_appClass);
            _mainConstructor = new Constructor(_source, _mainClass, null, Modifiers.Public, ParameterList.Empty);
            _mainClass.Constructors.Add(_mainConstructor);

            _testSetupField = new Field(_source, _mainClass, "_testSetup", null, Modifiers.Private, FieldModifiers.ReadOnly, _testSetupType);
            _mainClass.Fields.Add(_testSetupField);

            Data.IL.Types.Add(_mainClass);
        }
Exemplo n.º 5
0
        internal BuildEnvironment(
            Backend backend,
            SourcePackage project,
            CompilerOptions options,
            ExtensionRoot extensions,
            ILFactory ilf,
            Compiler compiler)
            : base(compiler)
        {
            if (string.IsNullOrEmpty(options.Configuration))
            {
                options.Configuration = "Debug";
            }
            if (string.IsNullOrEmpty(options.BuildTarget))
            {
                throw new ArgumentNullException(nameof(options.BuildTarget));
            }
            if (string.IsNullOrEmpty(options.OutputDirectory))
            {
                throw new ArgumentNullException(nameof(options.OutputDirectory));
            }

            Extensions      = extensions;
            Options         = options;
            BundleDirectory = Path.Combine(project.CacheDirectory, "bundle");
            CacheDirectory  = Path.Combine(project.CacheDirectory, options.BuildTarget, options.Configuration);
            Essentials      = ilf.Essentials;
            MacroExpander   = new MacroExpander(backend, this, extensions, ilf, compiler);
            Compiler        = compiler;

            Set("Target", options.BuildTarget);
            Set("Configuration", options.Configuration);
            Set("OutputDirectory", OutputDirectory = ExpandSingleLine(options.OutputDirectory).UnixToNative());
        }
Exemplo n.º 6
0
        Field GetField(Draw draw)
        {
            var prog = GetProgram(draw);
            var key  = Type + ":" + prog;

            Field result;

            if (!_fields.TryGetValue(key, out result))
            {
                var src        = draw.Source;
                var initMethod = Type.TryGetMethod("init_DrawCalls", false);

                if (initMethod == null)
                {
                    throw new SourceException(src, "No 'init_DrawCalls()' method was found in " + Type.Quote());
                }

                var dc = ILFactory.NewObject(src, "Uno.Graphics.OpenGL.GLDrawCall", prog);
                result = new Field(src, Type, "_draw_" + draw.State.Path.Suffix, null, Modifiers.Private | Modifiers.Generated, 0, dc.ReturnType);
                initMethod.Body.Statements.Add(new StoreField(src, new This(src, Type), result, dc));
                Type.Fields.Add(result);
                _fields.Add(key, result);
            }

            return(result);
        }
Exemplo n.º 7
0
        Expression ProcessVertexBuffer(StageValue vertexBuffer)
        {
            Expression result;

            if (!VertexBuffers.TryGetValue(vertexBuffer.Value.ToString(), out result))
            {
                var src  = vertexBuffer.Value.Source;
                var type = ILFactory.GetType(src, "Uno.Graphics.VertexBuffer");

                if (vertexBuffer.Value.ReturnType.Equals(type))
                {
                    result = ProcessStage(vertexBuffer, MetaStage.Volatile, MetaStage.Volatile).Value;
                    VertexBuffers.Add(vertexBuffer.Value.ToString(), result);
                    return(result);
                }

                var loc = LocationStack.Last();
                var mp  = GetProperty(loc);

                var name  = CreateFieldName(mp, loc);
                var owner = Path.DrawBlock.Method.DeclaringType;

                var field = new Field(src, owner, name, null, Modifiers.Private | Modifiers.Generated, 0, type);
                owner.Fields.Add(field);

                result = new LoadField(src, new This(src, owner), field);
                VertexBuffers.Add(vertexBuffer.Value.ToString(), result);

                if (vertexBuffer.MinStage > MetaStage.Volatile)
                {
                    Log.Error(src, ErrorCode.E5025, "Vertex buffer cannot be accessed from " + vertexBuffer.MinStage + " stage");
                    return(result);
                }
                else if (vertexBuffer.MinStage == MetaStage.Volatile)
                {
                    InitScope.Statements.Add(
                        new StoreField(src, new This(src, owner), field,
                                       ILFactory.NewObject(src, "Uno.Graphics.VertexBuffer",
                                                           ILFactory.GetExpression(src, "Uno.Graphics.BufferUsage.Dynamic"))));

                    FrameScope.Statements.Add(
                        ILFactory.CallMethod(src, new LoadField(src, new This(src, owner), field), "Update",
                                             vertexBuffer.Value));
                }
                else
                {
                    InitScope.Statements.Add(
                        new StoreField(src, new This(src, owner), field,
                                       ILFactory.NewObject(src, "Uno.Graphics.VertexBuffer",
                                                           vertexBuffer.Value,
                                                           ILFactory.GetExpression(src, "Uno.Graphics.BufferUsage.Immutable"))));
                }

                FreeScope.Statements.Add(
                    ILFactory.CallMethod(src, new LoadField(src, new This(src, owner), field), "Dispose"));
            }

            return(result);
        }
Exemplo n.º 8
0
 Expression CreateByteArray(Expression buf)
 {
     return(ILFactory.CallMethod(
                buf.ReturnType.Equals(ILFactory.GetType(buf.Source, "Uno.Buffer")) ?
                buf :
                ILFactory.CallMethod(buf.Source, "Uno.Runtime.Implementation.Internal.BufferConverters", "ToBuffer", buf),
                "GetBytes"));
 }
Exemplo n.º 9
0
        private static FixedList <DeclarationIL> BuildIL(Package package)
        {
            var ilFactory          = new ILFactory();
            var declarationBuilder = new DeclarationBuilder(ilFactory);

            declarationBuilder.Build(package.AllDeclarations, package.SymbolTree);
            return(declarationBuilder.AllDeclarations.ToFixedList());
        }
Exemplo n.º 10
0
 private Expression RegisterTest(TestMethod testMethod, Expression registryArgument, NewDelegate invokeDelegate)
 {
     var testNameExpr = new Constant(_source, Essentials.String, testMethod.Name);
     var ignoreExpr = new Constant(_source, Essentials.Bool, testMethod.Ignored);
     var ignoreReasonExpr = new Constant(_source, Essentials.String, testMethod.IgnoreReason);
     return ILFactory.CallMethod(_source, registryArgument, "Add", invokeDelegate,
                                 testNameExpr, ignoreExpr, ignoreReasonExpr);
 }
Exemplo n.º 11
0
 public GLGenerator(GLBackend backend, IBundle bundle)
     : base(backend)
 {
     _backend     = backend;
     _bundle      = bundle;
     _obfuscator  = new ShaderObfuscator(backend);
     _stringArray = (RefArrayType)ILFactory.GetType("string[]");
     _dumpShaders = Environment.IsDefined("DUMP_SHADERS");
 }
Exemplo n.º 12
0
 public override void Configure()
 {
     _outputDir = Environment.Combine(
         Environment.ExpandSingleLine("@(AssemblyDirectory || '.')")).TrimPath();
     _linker = new CilLinker(Log, Essentials);
     Scheduler.AddTransform(new CilTransform(this));
     EnableReflection   = Environment.IsDefined("REFLECTION");
     TypeAliasAttribute = EnableReflection
                         ? ILFactory.GetType("Uno.Reflection.TypeAliasAttribute")
                         : DataType.Invalid;
 }
Exemplo n.º 13
0
 FunctionCompiler(Compiler compiler)
     : base(compiler)
 {
     Environment  = compiler.Environment;
     Essentials   = compiler.Essentials;
     ILFactory    = compiler.ILFactory;
     ILVerifier   = compiler.ILVerifier;
     TypeBuilder  = compiler.TypeBuilder;
     NameResolver = compiler.NameResolver;
     Compiler     = compiler;
 }
Exemplo n.º 14
0
 public TypeBuilder(
     BuildEnvironment env,
     ILFactory ilf,
     NameResolver resolver,
     Compiler compiler)
     : base(compiler)
 {
     _env      = env;
     _ilf      = ilf;
     _resolver = resolver;
     _compiler = compiler;
 }
Exemplo n.º 15
0
 internal BuildData(
     Namespace il,
     ExtensionRoot extensions,
     ILFactory ilf)
     : base(ilf)
 {
     _ilf        = ilf;
     IL          = il;
     Extensions  = extensions;
     MainClass   = DataType.Invalid;
     StartupCode = new Scope();
 }
Exemplo n.º 16
0
 void EnsureInitialized()
 {
     if (!_initialized)
     {
         ExpandInterceptor    = new ExpandInterceptor(InterceptEntity);
         BoxedJavaObject      = ILFactory.GetType("Java.Object");
         _initialized         = true;
         Convert              = new Converters.Converter(BoxedJavaObject, Essentials, ILFactory, Helpers);
         BlockHost            = new Entrypoints(Environment, Disk, ILFactory, Convert);
         UnoToJavaBoxingClass = ILFactory.GetType("Uno.Compiler.ExportTargetInterop.Foreign.Android.JavaUnoObject");
     }
 }
Exemplo n.º 17
0
 public CompilerPass(CompilerPass parent)
     : base(parent)
 {
     Backend      = parent.Backend;
     Package      = parent.Package;
     TypeBuilder  = parent.TypeBuilder;
     Data         = parent.Data;
     Environment  = parent.Environment;
     Essentials   = parent.Essentials;
     ILFactory    = parent.ILFactory;
     NameResolver = parent.NameResolver;
 }
Exemplo n.º 18
0
 public BundleBuilder(
     Backend backend,
     BuildEnvironment env,
     ILFactory ilf,
     Compiler compiler)
     : base(compiler)
 {
     _backend  = backend;
     _env      = env;
     _ilf      = ilf;
     _compiler = compiler;
 }
Exemplo n.º 19
0
 void EnsureInitialized(Source source, Function f)
 {
     Helpers.CacheContext(f, source);
     if (!_initialized)
     {
         _initialized   = true;
         _objCObject    = ILFactory.GetType("global::ObjC.Object");
         _objCID        = ILFactory.GetType("global::ObjC.ID");
         _intPtr        = ILFactory.GetType("global::Uno.IntPtr");
         _getHandle     = (Method)ILFactory.GetEntity("global::ObjC.Object.GetHandle(" + Helpers.FullGlobalName(_objCObject) + ")");
         _newObjCObject = (Method)ILFactory.GetEntity(Helpers.FullGlobalName(_objCObject) + ".Create(" + Helpers.FullGlobalName(_objCID) + ")");
     }
 }
Exemplo n.º 20
0
 public BlockBuilder(
     Backend backend,
     Namespace il,
     ILFactory ilf,
     NameResolver resolver,
     Compiler compiler)
     : base(compiler)
 {
     _backend  = backend;
     _il       = il;
     _ilf      = ilf;
     _resolver = resolver;
     _compiler = compiler;
 }
Exemplo n.º 21
0
        protected override Statement TransformDraw(Draw draw)
        {
            var src   = draw.Source;
            var scope = new Scope(src);
            var field = GetField(draw);
            var obj   = new LoadField(src, new This(src, field.DeclaringType).Address, field).Address;
            var index = 0;

            foreach (var t in TerminalFields)
            {
                if (t.Value != draw.State.Terminals[t.Key].ToString())
                {
                    scope.Statements.Add(ILFactory.SetProperty(src, obj, t.Key, draw.State.Terminals[t.Key]));
                }
            }

            foreach (var v in draw.State.RuntimeConstants)
            {
                scope.Statements.Add(CallConst(src, obj, v, index++));
            }

            scope.Statements.Add(ILFactory.CallMethod(src, obj, "Use"));

            foreach (var v in draw.State.VertexAttributes)
            {
                scope.Statements.Add(CallAttrib(src, obj, v, index++));
            }
            foreach (var v in draw.State.Uniforms)
            {
                scope.Statements.Add(CallUniform(src, obj, v, index++));
            }
            foreach (var v in draw.State.PixelSamplers)
            {
                scope.Statements.Add(CallSampler(src, obj, v, index++));
            }

            scope.Statements.Add(draw.State.OptionalIndices == null
                ? ILFactory.CallMethod(src, obj,
                                       "DrawArrays",
                                       draw.State.Terminals["VertexCount"])
                : ILFactory.CallMethod(src, obj,
                                       "Draw",
                                       draw.State.Terminals["VertexCount"],
                                       draw.State.OptionalIndices.IndexType,
                                       draw.State.OptionalIndices.Buffer));

            return(draw.State.Terminals.ContainsKey("CullDrawable")
                ? (Statement) new IfElse(src, ILFactory.CallOperator(src, Essentials.Bool, "!", draw.State.Terminals["CullDrawable"]), scope)
                : scope);
        }
Exemplo n.º 22
0
        public ILFactory CreateLFactory()
        {
            ILFactory factory = null;

            try
            {
                factory = new LFactory();
            }
            catch (Exception exception)
            {
                this.Log.Error("Exception message: " + exception.Message + " and stacktrace " + exception.StackTrace);
            }

            return(factory);
        }
Exemplo n.º 23
0
 public UxlProcessor(
     Disk disk,
     string backendName,
     Namespace il,
     ExtensionRoot root,
     BuildEnvironment env,
     ILFactory ilf)
     : base(disk)
 {
     _disk = disk;
     _il   = il;
     _root = root;
     _env  = env;
     _ilf  = ilf;
     Enum.TryParse(backendName, true, out _backendType);
 }
Exemplo n.º 24
0
        public ILFactory CreateLFactory()
        {
            ILFactory factory = null;

            try
            {
                factory = new LFactory();
            }
            catch (Exception exception)
            {
                this.Log.Error(
                    exception.Message,
                    exception);
            }

            return(factory);
        }
Exemplo n.º 25
0
        private void OnTwinMethod(ref Method method)
        {
            Method twin;

            if (!_twinMethods.TryGetValue(method, out twin))
            {
                if (method.HasAttribute(Essentials.DotNetOverrideAttribute) &&
                    method.DeclaringType.HasAttribute(Essentials.DotNetTypeAttribute))
                {
                    if (method.IsGenericParameterization)
                    {
                        var def = method.GenericDefinition;
                        OnTwinMethod(ref def);
                        twin = ILFactory.Parameterize(method.Source, def, method.GenericArguments);
                    }
                    else
                    {
                        var twinClass = GetOrCreateTwinClass(method.DeclaringType);

                        if (method.IsGenericDefinition)
                        {
                            var generic = new ClassType(method.Source, twinClass, method.DocComment, Modifiers.Private | Modifiers.Static | Modifiers.Generated, method.UnoName);
                            generic.MakeGenericDefinition(method.GenericParameters);
                            twin = new Method(method.Source, twinClass, method.DocComment, method.Modifiers, method.Name, generic, method.ReturnType, method.Parameters, method.Body);
                            generic.Methods.Add(twin);
                        }
                        else
                        {
                            twin = new Method(method.Source, twinClass, method.DocComment, method.Modifiers, method.Name, method.ReturnType, method.Parameters, method.Body);
                        }

                        twin.Stats |= method.Stats & EntityStats.ImplicitReturn;
                        twin.SetPrototype(method);
                        twinClass.Methods.Add(twin);
                    }
                }

                _twinMethods.Add(method, twin);
            }

            if (twin != null)
            {
                method = twin;
            }
        }
Exemplo n.º 26
0
 public override void Configure()
 {
     SourceDirectory = Environment.GetOutputPath("SourceDirectory");
     HeaderDirectory = Environment.GetOutputPath("HeaderDirectory");
     Types.Add(Essentials.Bool, "bool");
     Types.Add(Essentials.Byte, "uint8_t");
     Types.Add(Essentials.Char, "char16_t");
     Types.Add(Essentials.Double, "double");
     Types.Add(Essentials.Float, "float");
     Types.Add(Essentials.Int, "int");
     Types.Add(Essentials.Long, "int64_t");
     Types.Add(Essentials.SByte, "int8_t");
     Types.Add(Essentials.Short, "int16_t");
     Types.Add(Essentials.UInt, "unsigned int");
     Types.Add(Essentials.ULong, "uint64_t");
     Types.Add(Essentials.UShort, "uint16_t");
     Types.Add(ILFactory.GetType("global::Uno.IntPtr"), "void*");
 }
Exemplo n.º 27
0
        public override void End(ref Statement e)
        {
            if (e.Tag is InvalidExpression)
            {
                e = new NoOp(e.Source);
            }

            switch (e.StatementType)
            {
            case StatementType.DrawDispose:
            {
                if (!Backend.CanExportDontExports)
                {
                    e = ILFactory.CallMethod(e.Source, new This(e.Source, Type).Address, "free_DrawCalls");
                }
                break;
            }
            }
        }
Exemplo n.º 28
0
 public ShaderGenerator(Compiler compiler, Drawable path, Scope initScope, Scope freeScope, Scope drawScope)
     : base(compiler)
 {
     Backend     = compiler.Backend;
     IL          = compiler.Data.IL;
     Environment = compiler.Environment;
     Essentials  = compiler.Essentials;
     ILFactory   = compiler.ILFactory;
     Compiler    = compiler;
     DrawState   = path.DrawState;
     Path        = path;
     InitScope   = initScope;
     FreeScope   = freeScope;
     FrameScope  = drawScope;
     VertexScope = DrawState.VertexShader.Entrypoint.Body;
     PixelScope  = DrawState.PixelShader.Entrypoint.Body;
     InitStart   = InitScope.Statements.Count;
     FrameStart  = FrameScope.Statements.Count;
 }
Exemplo n.º 29
0
        private void RegisterTestMethods()
        {
            var registryObject   = ILFactory.NewObject(_source, _testRegistryType);
            var registryVariable = new Variable(_source, _mainConstructor, "registry", _testRegistryType, VariableType.Default, registryObject);
            var body             = new Scope(_source);

            body.Statements.Add(new CallConstructor(_source, _appClass.Constructors[0]));
            body.Statements.Add(new VariableDeclaration(registryVariable));

            var methods = _methods;

            if (_testOptions.Filter != null)
            {
                var regex = new Regex(_testOptions.Filter, RegexOptions.CultureInvariant);
                methods = methods.Where(m => regex.IsMatch(m.FullName)).ToList();
            }

            methods.Sort((a, b) => string.Compare(a.FullName, b.FullName, StringComparison.InvariantCultureIgnoreCase));

            var ret = new List <TestMethod>();

            foreach (var method in methods)
            {
                var testMethod      = CreateTestMethod(method);
                var invokerMethod   = CreateInvoker(method);
                var invokerInstance = InstantiateTestFixture(invokerMethod);
                var testExpression  = RegisterTest(testMethod,
                                                   new LoadLocal(_source, registryVariable),
                                                   new NewDelegate(_source, _actionType,
                                                                   invokerInstance, invokerMethod));

                body.Statements.Add(testExpression);
                ret.Add(testMethod);
            }

            var registryExpr          = new LoadLocal(_source, registryVariable);
            var testSetupConstruction = ILFactory.NewObject(_source, _testSetupType, registryExpr);

            body.Statements.Add(new StoreField(_source, new This(_source, _mainClass), _testSetupField, testSetupConstruction));

            _mainConstructor.SetBody(body);
        }
Exemplo n.º 30
0
 void EnsureInitialized()
 {
     if (!_initialized)
     {
         _initialized = true;
         IdentityTypes.Add(Essentials.Bool, "bool");
         IdentityTypes.Add(Essentials.Byte, "uint8_t");
         IdentityTypes.Add(Essentials.Char, "char16_t");
         IdentityTypes.Add(Essentials.Double, "double");
         IdentityTypes.Add(Essentials.Float, "float");
         IdentityTypes.Add(Essentials.Int, "int");
         IdentityTypes.Add(Essentials.Long, "int64_t");
         IdentityTypes.Add(Essentials.SByte, "int8_t");
         IdentityTypes.Add(Essentials.Short, "int16_t");
         IdentityTypes.Add(Essentials.UInt, "unsigned int");
         IdentityTypes.Add(Essentials.ULong, "uint64_t");
         IdentityTypes.Add(Essentials.UShort, "uint16_t");
         IdentityTypes.Add(ILFactory.GetType("global::Uno.IntPtr"), "void*");
     }
 }