当前位置: 首页>>代码示例>>C#>>正文


C# PEAPI.CreateCodeBuffer方法代码示例

本文整理汇总了C#中PEAPI.CreateCodeBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# PEAPI.CreateCodeBuffer方法的具体用法?C# PEAPI.CreateCodeBuffer怎么用?C# PEAPI.CreateCodeBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PEAPI的用法示例。


在下文中一共展示了PEAPI.CreateCodeBuffer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteCode


//.........这里部分代码省略.........
                        if (max_stack < 0)
                                max_stack = 8;
                        methoddef.SetMaxStack (max_stack);

                        if (pinvoke_info) {
                                methoddef.AddPInvokeInfo (pinvoke_mod.ModuleRef,
                                                (pinvoke_name != null ? pinvoke_name : name), pinvoke_attr);
                        }

                        if ((impl_attr & PEAPI.ImplAttr.Runtime) == PEAPI.ImplAttr.Runtime) {
                                if (inst_list.Count > 0)
                                        Report.Error (start, String.Format ("Method cannot have body if it is non-IL runtime-supplied, '{0}'", 
                                                                FullName));
                        } else {
                                if (((impl_attr & PEAPI.ImplAttr.Native) != 0) ||
                                        ((impl_attr & PEAPI.ImplAttr.Unmanaged) != 0))
                                        Report.Error (start, String.Format ("Cannot compile native/unmanaged method, '{0}'", 
                                                                FullName));
                        }

                        if (inst_list.Count > 0) {
                                /* Has body */
                                if ((impl_attr & PEAPI.ImplAttr.InternalCall) != 0)
                                        Report.Error (start, String.Format ("Method cannot have body if it is an internal call, '{0}'", 
                                                                FullName));

                                if (pinvoke_info)
                                        Report.Error (start, String.Format ("Method cannot have body if it is pinvoke, '{0}'",
                                                                FullName));
                        } else {
                                if (pinvoke_info ||
                                        ((impl_attr & PEAPI.ImplAttr.Runtime) != 0) ||
                                        ((impl_attr & PEAPI.ImplAttr.InternalCall) != 0))
                                        /* No body required */
                                        return;

                                Report.Warning (start, "Method has no body, 'ret' emitted.");
                                AddInstr (new SimpInstr (PEAPI.Op.ret, start));
                        }

                        PEAPI.CILInstructions cil = methoddef.CreateCodeBuffer ();
                        /// Create all the labels
                        /// TODO: Most labels don't actually need to be created so we could
                        /// probably only create the ones that need to be
                        LabelInfo[] label_info = new LabelInfo[label_table.Count + label_list.Count];
                        label_table.Values.CopyTo (label_info, 0);
                        label_list.CopyTo (label_info, label_table.Count);
                        int previous_pos = -1;
                        LabelInfo previous_label = null;
                        Array.Sort (label_info);

                        foreach (LabelInfo label in label_info) {
                                if (label.UseOffset) {
                                        label.Define (new PEAPI.CILLabel (label.Offset, true));
                                        continue;
                                }
                                if (label.Pos == previous_pos)
                                        label.Label = previous_label.Label;
                                else
                                        label.Define (cil.NewLabel ());

                                previous_label = label;
                                previous_pos = label.Pos;
                        }

                        // Set all the label refs
                        foreach (LabelInfo label in labelref_table.Values) {
                                LabelInfo def = (LabelInfo) label_table[label.Name];
                                if (def == null) {
                                        Report.Error ("Undefined Label:  " + label);
                                        return;
                                }
                                label.Label = def.Label;
                        }

                        int label_pos = 0;
                        int next_label_pos = (label_info.Length > 0 ? label_info[0].Pos : -1);

                        for (int i=0; i<inst_list.Count; i++) {
                                IInstr instr = (IInstr) inst_list[i];
                                if (next_label_pos == i) {
                                        cil.CodeLabel (label_info[label_pos].Label);
                                        if (label_pos < label_info.Length) {
                                                while (next_label_pos == i && ++label_pos < label_info.Length) {
                                                        if (label_info[label_pos].UseOffset)
                                                                cil.CodeLabel (label_info[label_pos].Label);
                                                       next_label_pos = label_info[label_pos].Pos;
                                                }
                                        }
                                        if (label_pos >= label_info.Length)
                                                next_label_pos = -1;
                                }
				if (source != null)
					source.MarkLocation (instr.Location.line, cil.Offset);
                                instr.Emit (code_gen, this, cil);
                        }

			if (source != null)
				source.MarkLocation (source.EndLine, cil.Offset);
                }
开发者ID:Profit0004,项目名称:mono,代码行数:101,代码来源:MethodDef.cs


注:本文中的PEAPI.CreateCodeBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。