The IL instructions for a method
Exemplo n.º 1
0
        internal FMethodVar[] vars; // method variables must be set for loadVar/storeVar

        #endregion Fields

        #region Constructors

        //////////////////////////////////////////////////////////////////////////
        // Constructor
        //////////////////////////////////////////////////////////////////////////
        public FCodeEmit(FTypeEmit parent, FMethod fmethod, CILInstructions code)
            : this(parent, fmethod.m_code, code,
         initRegs(parent.pod,  fmethod.isStatic(), fmethod.m_vars),
         parent.pod.typeRef(fmethod.m_ret))
        {
            this.fmethod    = fmethod;
              this.vars       = fmethod.m_vars;
              this.isStatic   = (fmethod.m_flags & FConst.Static) != 0;
              this.paramCount = fmethod.m_paramCount;
              if (!isStatic) paramCount++;
        }
Exemplo n.º 2
0
 public FCodeEmit(FTypeEmit parent, FBuf fcode, CILInstructions code, Reg[] regs, FTypeRef ret)
 {
     this.pod      = parent.pod;
       this.emitter  = parent.emitter;
       this.parent   = parent;
       this.buf      = fcode.m_buf;
       this.len      = fcode.m_len;
       this.code     = code;
       this.podClass = FanUtil.toDotnetTypeName(pod.m_podName, "$Pod", false);
       this.jumps    = new Jumps(code);
       this.regs     = regs;
       this.ret      = ret;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Create a new code block definition
 /// </summary>
 /// <param name="instructions">The buffer the code block relates to</param>
 internal CodeBlock(CILInstructions instructions)
 {
     cilInstr = instructions;
 }
Exemplo n.º 4
0
 internal uint AddCode(CILInstructions byteCode)
 {
     byteCodes.Add(byteCode);
     uint offset = codeSize;
     codeSize += byteCode.GetCodeSize();
     return offset;
 }
Exemplo n.º 5
0
 internal override sealed void BuildTables(MetaDataOut md)
 {
     md.AddToTable(MDTable.Method,this);
     nameIx = md.AddToStringsHeap(name);
     if (genericParams != null) {
         for (int i=0; i < genericParams.Count; i++) {
             ((GenericParam)genericParams[i]).BuildMDTables(md);
         }
     }
     if (security != null) {
         for (int i=0; i < security.Count; i++) {
             ((DeclSecurity)security[i]).BuildMDTables(md);
         }
     }
     if (pinvokeImpl != null) pinvokeImpl.BuildMDTables(md);
     if (entryPoint) md.SetEntryPoint(this);
     if (locals != null) {
         localSig = new LocalSig(locals);
         localSig.BuildMDTables(md);
     }
     try {
         if (code != null) {
             if (code.IsEmpty()) {
                 code = null;
             } else {
                 code.BuildTables(md);
             }
         }
     } catch (InstructionException ex) {
         throw new Exception(ex.AddMethodName(name));
     }
     parIx = md.TableIndex(MDTable.Param);
     for (int i=0; i < sig.numPars; i++) {
         parList[i].seqNo = (ushort)(i+1);
         parList[i].BuildMDTables(md);
     }
     sig.BuildTables(md);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Create a code buffer for this method to add the IL instructions to
 /// </summary>
 /// <returns>a buffer for this method's IL instructions</returns>
 public CILInstructions CreateCodeBuffer()
 {
     code = new CILInstructions(this);
     return code;
 }
Exemplo n.º 7
0
 private static void loadVar(CILInstructions code, int stackType, int index, int paramCount)
 {
     if (index < paramCount)
       {
     switch (index)
     {
       case 0:  code.Inst(Op.ldarg_0); break;
       case 1:  code.Inst(Op.ldarg_1); break;
       case 2:  code.Inst(Op.ldarg_2); break;
       case 3:  code.Inst(Op.ldarg_3); break;
       default: code.IntInst(IntOp.ldarg, index); break;
     }
       }
       else
       {
     index -= paramCount;
     switch (index)
     {
       case 0:  code.Inst(Op.ldloc_0); break;
       case 1:  code.Inst(Op.ldloc_1); break;
       case 2:  code.Inst(Op.ldloc_2); break;
       case 3:  code.Inst(Op.ldloc_3); break;
       default: code.IntInst(IntOp.ldloc, index); break;
     }
       }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Load variable onto stack using Java type and java index (which might
 /// not map to Fantom index.  Return next available java index
 /// </summary>
 internal static void loadVar(CILInstructions code, int stackType, int index)
 {
     loadVar(code, stackType, index, Int32.MaxValue);
 }
Exemplo n.º 9
0
 public Jumps(CILInstructions code)
 {
     this.code = code;
 }