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] + ")");
public virtual void Emit(IlBuilder builder) { if (Label == "") { return; } builder.Output.ReduceIndentationForLine(); builder.EmitString(Label + ": "); }
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); }
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); }