Esempio n. 1
0
        public virtual void Emit(IlBuilder builder)
        {
            builder.EmitString(".method");
            foreach (string flag in Flags)
            {
                builder.EmitString(" " + flag);
            }
            builder.EmitLine($" {ReturnType.Name} {Name}({ArgList}) cil managed");
            builder.EmitLine("{");

            if (!IsAbstract && Instructions.Count > 0)
            {
                builder.Output.AddIndentation();

                //TODO: Allow for selection of entrypoint
                if (Name == "Main")
                {
                    builder.EmitLine(".entrypoint");
                }

                int startLoc = builder.Output.ReserveLocation();

                if (Locals.Count > 0)
                {
                    string types = "";
                    foreach (var t in Locals)
                    {
                        types += t.Type.Name + ",";
                    }
                    builder.EmitLine(".locals init (" + types[..^ 1] + ")");
Esempio n. 2
0
        public virtual void Emit(IlBuilder builder)
        {
            if (Label == "")
            {
                return;
            }

            builder.Output.ReduceIndentationForLine();
            builder.EmitString(Label + ": ");
        }
Esempio n. 3
0
        public override void Emit(IlBuilder builder)
        {
            base.Emit(builder);

            bool or = _op.Type == Operator.OperatorType.Or;

            string label1 = Owner.LabelManager.NextLabel;
            string label2 = Owner.LabelManager.NextLabel;

            builder.PushValue(_op1);
            builder.EmitOpCode(or ? OpCodes.Brtrue : OpCodes.Brfalse, label1);

            builder.PushValue(_op2);
            builder.EmitOpCode(OpCodes.Br, label2);

            builder.Output.ReduceIndentationForLine();
            builder.EmitString(label1 + ": ");
            builder.PushValue(new CodeValue(CodeType.Int32, or ? 1 : 0));

            builder.Output.ReduceIndentationForLine();
            builder.EmitString(label2 + ": ");
            builder.EmitOpCode(OpCodes.Nop);
        }
Esempio n. 4
0
        public override void Emit(IlBuilder builder)
        {
            base.Emit(builder);


            string label1 = Owner.LabelManager.NextLabel;
            string label2 = Owner.LabelManager.NextLabel;

            builder.PushValue(_exp);

            builder.EmitOpCode(OpCodes.Brfalse, label1);

            builder.PushValue(_op1);
            builder.EmitOpCode(OpCodes.Br, label2);

            builder.Output.ReduceIndentationForLine();
            builder.EmitString(label1 + ": ");
            builder.PushValue(_op2);

            builder.Output.ReduceIndentationForLine();
            builder.EmitString(label2 + ": ");
            builder.EmitOpCode(OpCodes.Nop);
        }