Beispiel #1
0
        /// <summary>
        /// Emits the artifacts for multiple compilation units with the same compilation mode and target runtime
        /// </summary>
        /// <param name="units">The compilation units</param>
        protected void ExecuteDoEmitSameModeSameTarget(List <Unit> units)
        {
            EmitterBase emitter = null;

            switch (GetTargetRuntimeFor(units[0].Grammar))
            {
            case Runtime.Net:
                emitter = new EmitterForNet(reporter, units);
                break;

            case Runtime.Java:
                emitter = new EmitterForJava(reporter, units);
                break;

            case Runtime.Rust:
                emitter = new EmitterForRust(reporter, units, outputTargetRust);
                break;
            }
            bool success = emitter.Emit();

            if (!success)
            {
                reporter.Error("Failed to emit some output");
            }
        }
        protected override void generate(EmitterBase emitter)
        {
            var namespaces = _declaringAssembly.GetNamespaces(_compositionAttribute.Element as CodeElement);


            var initializerMethodInfo = new TypeMethodInfo(_compositionPoint.DeclaringType, ParsingActivation.InlineMethodName,
                                                           TypeDescriptor.Void, ParameterTypeInfo.NoParams, false, TypeDescriptor.NoDescriptors);

            var code = new StringBuilder();

            code.AppendLine("{");
            for (var i = 0; i < _compositionPoint.Parameters.Length; ++i)
            {
                var parameter = _compositionPoint.Parameters[i];
                var argument  = _compositionAttribute.GetArgument(i);

                if (argument == null)
                {
                    argument = "null";
                }

                code.AppendLine(" var arg" + i + " = " + argument + ";");
            }
            code.AppendLine("}");

            var activation = new ParsingActivation(code.ToString(), initializerMethodInfo, new string[0], namespaces);

            _declaringAssembly.ParsingProvider(activation, emitter);
        }
Beispiel #3
0
        /// <summary>
        /// Transcript given instructions in context of given method.
        /// Transcription is processed by given emitter.
        /// </summary>
        /// <param name="method">Context method of transcription</param>
        /// <param name="instructions">Transcripted instructions</param>
        /// <param name="emitter">Emitter where transcription is emitted</param>
        internal static void Transcript(TypeMethodInfo method, IEnumerable <CILInstruction> instructions, EmitterBase emitter)
        {
            E           = emitter;
            Method      = method;
            LocalTmpVar = E.GetTemporaryVariable("local");

            //prepare labels table
            Labels.Clear();
            foreach (var instruction in instructions)
            {
                var labelName = string.Format("L_0x{0:x4}", instruction.Address);
                Labels.Add(instruction.Address, E.CreateLabel(labelName));
            }

            foreach (var instruction in instructions)
            {
                Instruction = instruction;
                E.SetLabel(Labels[instruction.Address]);

                var block = E.StartNewInfoBlock();
                block.Comment = "\n---" + Instruction.ToString();

                Action transcriptor;
                if (_transcriptors.TryGetValue(Name, out transcriptor))
                {
                    transcriptor();
                }
                else
                {
                    unknownInstruction();
                }
            }
        }
 protected override void generate(EmitterBase emitter)
 {
     foreach (var action in _emitActions)
     {
         action(emitter);
     }
 }
        private void emitDirector(EmitterBase emitter)
        {
            //emitujeme instrukci pro uložení jména
            //assembly do proměnné
            emitter.AssignLiteral("result", _name);

            //instrukce pro vrácení uložené hodnoty
            emitter.Return("result");
        }
Beispiel #6
0
        /// <inheritdoc />
        protected override void generate(EmitterBase emitter)
        {
            if (Activation == null)
            {
                throw new NotSupportedException("Cannot parse abstract method: " + Activation.Method.MethodID);
            }

            _parsingProvider(Activation, emitter);
        }
Beispiel #7
0
        /// <inheritdoc />
        public override void ParsingProvider(ParsingActivation activation, EmitterBase emitter)
        {
            var w = Stopwatch.StartNew();

            var source = Compiler.GenerateInstructions(activation, emitter, TypeServices);

            var methodID = activation.Method == null ? new MethodID("$inline", false) : activation.Method.MethodID;

            VS.Log.Message("Parsing time for {0} {1}ms", methodID, w.ElapsedMilliseconds);
        }
Beispiel #8
0
        protected override void generate(EmitterBase emitter)
        {
            if (_method == null)
            {
                //nothing to emit
                return;
            }

            var method = new CILMethod(_method, _info);

            Compiler.GenerateInstructions(method, _info, emitter, _services);
        }
Beispiel #9
0
        /// <inheritdoc />
        protected override void generate(EmitterBase emitter)
        {
            //first and only argument is parametric
            var resolvedArguments = CILAssembly.ResolveCustomAttributeArgument(_attribute.ConstructorArguments[0]) as object[];

            for (var i = 0; i < resolvedArguments.Length; ++i)
            {
                var argumentStorage = "arg" + i;
                var argumentValue   = resolvedArguments[i];

                emitter.AssignLiteral(argumentStorage, argumentValue);
            }
        }
    static void UpdateBaseComponent(SpriteToParticles StP, EmitterBase eb)
    {
        StP.spriteRenderer  = eb.spriteRenderer;
        StP.particlesSystem = eb.particlesSystem;

        StP.PlayOnAwake          = eb.PlayOnAwake;
        StP.EmissionRate         = eb.EmissionRate;
        StP.UsePixelSourceColor  = eb.UsePixelSourceColor;
        StP.UseEmissionFromColor = eb.UseEmissionFromColor;

        StP.EmitFromColor  = eb.EmitFromColor;
        StP.RedTolerance   = eb.RedTolerance;
        StP.GreenTolerance = eb.GreenTolerance;
        StP.BlueTolerance  = eb.BlueTolerance;

        StP.useSpritesSharingPool = eb.useSpritesSharingCache;
    }
        /// <summary>
        /// Initializes a new instance of the <see cref="CompilationContext"/> class.
        /// </summary>
        /// <param name="emitter">The emitter.</param>
        /// <param name="source">The source.</param>
        /// <param name="services">The services.</param>
        /// <exception cref="System.ArgumentNullException">
        /// emitter
        /// or
        /// source
        /// or
        /// services
        /// </exception>
        internal CompilationContext(EmitterBase emitter, Source source, TypeServices services)
        {
            if (emitter == null)
            {
                throw new ArgumentNullException("emitter");
            }

            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (services == null)
            {
                throw new ArgumentNullException("services");
            }

            Emitter  = emitter;
            Source   = source;
            Services = services;
        }
 /// <summary>
 /// Generate instructions through given emitter.
 /// <remarks>Throwing any exception will immediately stops analyzing.</remarks>.
 /// </summary>
 /// <param name="emitter">The emitter which will be used for instruction generation.</param>
 protected override void generate(EmitterBase emitter)
 {
     _director(emitter);
 }
Beispiel #13
0
        protected override void generate(EmitterBase emitter)
        {
            var activation = new ParsingActivation(SourceCode, Method, _genericParameters);

            Source = Compiler.GenerateInstructions(activation, emitter, _services);
        }
Beispiel #14
0
 /// <summary>
 /// Provider of method parsing for assembly.
 /// </summary>
 /// <param name="activation">Activation for assembly parser.</param>
 /// <param name="emitter">Emitter where parsed instructions are emitted.</param>
 public abstract void ParsingProvider(ParsingActivation activation, EmitterBase emitter);
Beispiel #15
0
 protected override void generate(EmitterBase emitter)
 {
     Compiler.GenerateInstructions(Source, Info, emitter, _services);
 }
Beispiel #16
0
        /// <summary>
        /// Generates the instructions of given method.
        /// </summary>
        /// <param name="method">The method.</param>
        /// <param name="info">The method information.</param>
        /// <param name="emitter">The emitter where instructions will be generated.</param>
        /// <param name="services">The services from <see cref="MEFEditor.TypeSystem"/>.</param>
        public static void GenerateInstructions(CILMethod method, TypeMethodInfo info, EmitterBase emitter, TypeServices services)
        {
            Console.WriteLine(method.ToString());

            var compiler = new Compiler(method, info, emitter, services);

            compiler.generateInstructions();

            //Console.WriteLine(emitter.GetEmittedInstructions().Code);
        }
Beispiel #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Compiler"/> class.
 /// </summary>
 /// <param name="method">The method.</param>
 /// <param name="methodInfo">The method information.</param>
 /// <param name="emitter">The emitter.</param>
 /// <param name="services">The services.</param>
 private Compiler(CILMethod method, TypeMethodInfo methodInfo, EmitterBase emitter, TypeServices services)
 {
     _method     = method;
     _methodInfo = methodInfo;
     E           = emitter;
 }
Beispiel #18
0
 protected override void generate(EmitterBase emitter)
 {
     emitter.DirectInvoke(set);
 }