Example #1
0
        public void Compile()
        {
            fixupBranches.Clear();
            fixupLabels.Clear();
            labels.Clear();

//      List<Instruction> instrList = new List<Instruction>();
//      foreach (Instruction instr in body.Instructions)
//        instrList.Add(instr);

            body.Instructions.Clear();

            Visit(ast);

            if (body.Instructions[body.Instructions.Count - 1].OpCode != OpCodes.Ret)
            {
                cil.EmitInstruction(OpCodes.Ret);
            }

            foreach (KeyValuePair <Instruction, string> pair in fixupLabels)
            {
                pair.Key.Operand = body.Instructions[labels[pair.Value]];
            }

            foreach (KeyValuePair <Instruction, int> pair in fixupBranches)
            {
                pair.Key.Operand = body.Instructions[pair.Value];
            }

//      foreach (Instruction instr in instrList)
//        cil.Append(instr);
        }