本文整理汇总了C#中Mono.CSharp.EmitContext.DefineLabel方法的典型用法代码示例。如果您正苦于以下问题:C# EmitContext.DefineLabel方法的具体用法?C# EmitContext.DefineLabel怎么用?C# EmitContext.DefineLabel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CSharp.EmitContext
的用法示例。
在下文中一共展示了EmitContext.DefineLabel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitFinallyBody
protected override void EmitFinallyBody (EmitContext ec)
{
Label call_dispose = ec.DefineLabel ();
if (dispose != null) {
local_copy.Emit (ec, false);
ec.Emit (OpCodes.Isinst, dispose.Type);
dispose.Store (ec);
}
base.EmitFinallyBody (ec);
if (dispose != null) {
ec.MarkLabel (call_dispose);
dispose.Release (ec);
}
}
示例2: EmitDispose
public void EmitDispose(EmitContext ec)
{
Label end = ec.DefineLabel ();
Label [] labels = null;
int n_resume_points = resume_points == null ? 0 : resume_points.Count;
for (int i = 0; i < n_resume_points; ++i) {
ResumableStatement s = (ResumableStatement) resume_points [i];
Label ret = s.PrepareForDispose (ec, end);
if (ret.Equals (end) && labels == null)
continue;
if (labels == null) {
labels = new Label [resume_points.Count + 1];
for (int j = 0; j <= i; ++j)
labels [j] = end;
}
labels [i+1] = ret;
}
if (labels != null) {
current_pc = ec.GetTemporaryLocal (TypeManager.uint32_type);
ec.Emit (OpCodes.Ldarg_0);
ec.Emit (OpCodes.Ldfld, IteratorHost.PC.Spec);
ec.Emit (OpCodes.Stloc, current_pc);
}
ec.Emit (OpCodes.Ldarg_0);
ec.EmitInt ((int) State.After);
ec.Emit (OpCodes.Stfld, IteratorHost.PC.Spec);
if (labels != null) {
//SymbolWriter.StartIteratorDispatcher (ec.ig);
ec.Emit (OpCodes.Ldloc, current_pc);
ec.Emit (OpCodes.Switch, labels);
//SymbolWriter.EndIteratorDispatcher (ec.ig);
foreach (ResumableStatement s in resume_points)
s.EmitForDispose (ec, this, end, true);
}
ec.MarkLabel (end);
}
示例3: DoEmit
protected override void DoEmit(EmitContext ec)
{
Label label_init = ec.DefineLabel ();
ec.Emit (OpCodes.Ldarg_0);
ec.Emit (OpCodes.Ldflda, host.PC.Spec);
ec.EmitInt ((int) Iterator.State.Start);
ec.EmitInt ((int) Iterator.State.Uninitialized);
ec.Emit (OpCodes.Call, TypeManager.int_interlocked_compare_exchange);
ec.EmitInt ((int) Iterator.State.Uninitialized);
ec.Emit (OpCodes.Bne_Un_S, label_init);
ec.Emit (OpCodes.Ldarg_0);
ec.Emit (OpCodes.Ret);
ec.MarkLabel (label_init);
new_storey.Emit (ec);
ec.Emit (OpCodes.Ret);
}
示例4: Emit
public override void Emit (EmitContext ec)
{
Label l_initialized = ec.DefineLabel ();
if (mg_cache != null) {
ec.Emit (OpCodes.Ldsfld, mg_cache.Spec);
ec.Emit (OpCodes.Brtrue_S, l_initialized);
}
base.Emit (ec);
if (mg_cache != null) {
ec.Emit (OpCodes.Stsfld, mg_cache.Spec);
ec.MarkLabel (l_initialized);
ec.Emit (OpCodes.Ldsfld, mg_cache.Spec);
}
}
示例5: EmitStatement
public override void EmitStatement (EmitContext ec)
{
if (conditionalAccessReceiver) {
ec.ConditionalAccess = new ConditionalAccessContext (type, ec.DefineLabel ()) {
Statement = true
};
}
var call = new CallEmitter ();
call.InstanceExpression = InstanceExpr;
call.EmitStatement (ec, method, arguments, loc);
if (conditionalAccessReceiver)
ec.CloseConditionalAccess (null);
}
示例6: LabelTarget
public Label LabelTarget (EmitContext ec)
{
if (defined)
return label;
label = ec.DefineLabel ();
defined = true;
return label;
}
示例7: EmitCall
//.........这里部分代码省略.........
}
} else {
d = null;
}
var site_type_decl = new GenericTypeExpr (module.PredefinedTypes.CallSiteGeneric.TypeSpec, new TypeArguments (del_type), loc);
var field = site_container.CreateCallSiteField (site_type_decl, loc);
if (field == null)
return;
if (del_type_instance_access == null) {
var dt = d.CurrentType.DeclaringType.MakeGenericType (module, context_mvars.Types);
del_type_instance_access = new TypeExpression (MemberCache.GetMember (dt, d.CurrentType), loc);
}
var instanceAccessExprType = new GenericTypeExpr (module.PredefinedTypes.CallSiteGeneric.TypeSpec,
new TypeArguments (del_type_instance_access), loc);
if (instanceAccessExprType.ResolveAsType (ec.MemberContext) == null)
return;
bool inflate_using_mvar = context_mvars != null && ec.IsAnonymousStoreyMutateRequired;
TypeSpec gt;
if (inflate_using_mvar || context_mvars == null) {
gt = site_container.CurrentType;
} else {
gt = site_container.CurrentType.MakeGenericType (module, context_mvars.Types);
}
// When site container already exists the inflated version has to be
// updated manually to contain newly created field
if (gt is InflatedTypeSpec && site_container.AnonymousMethodsCounter > 1) {
var tparams = gt.MemberDefinition.TypeParametersCount > 0 ? gt.MemberDefinition.TypeParameters : TypeParameterSpec.EmptyTypes;
var inflator = new TypeParameterInflator (module, gt, tparams, gt.TypeArguments);
gt.MemberCache.AddMember (field.InflateMember (inflator));
}
FieldExpr site_field_expr = new FieldExpr (MemberCache.GetMember (gt, field), loc);
BlockContext bc = new BlockContext (ec.MemberContext, null, ec.BuiltinTypes.Void);
Arguments args = new Arguments (1);
args.Add (new Argument (binder));
StatementExpression s = new StatementExpression (new SimpleAssign (site_field_expr, new Invocation (new MemberAccess (instanceAccessExprType, "Create"), args)));
using (ec.With (BuilderContext.Options.OmitDebugInfo, true)) {
var conditionalAccessReceiver = IsConditionalAccessReceiver;
var ca = ec.ConditionalAccess;
if (conditionalAccessReceiver) {
ec.ConditionalAccess = new ConditionalAccessContext (type, ec.DefineLabel ()) {
Statement = isStatement
};
//
// Emit conditional access expressions before dynamic call
// is initialized. It pushes site_field_expr on stack before
// the actual instance argument is emited which would cause
// jump from non-empty stack.
//
EmitConditionalAccess (ec);
}
if (s.Resolve (bc)) {
Statement init = new If (new Binary (Binary.Operator.Equality, site_field_expr, new NullLiteral (loc)), s, loc);
init.Emit (ec);
}
args = new Arguments (1 + dyn_args_count);
args.Add (new Argument (site_field_expr));
if (arguments != null) {
int arg_pos = 1;
foreach (Argument a in arguments) {
if (a is NamedArgument) {
// Name is not valid in this context
args.Add (new Argument (a.Expr, a.ArgType));
} else {
args.Add (a);
}
if (inflate_using_mvar && a.Type != targs[arg_pos].Type)
a.Expr.Type = targs[arg_pos].Type;
++arg_pos;
}
}
var target = new DelegateInvocation (new MemberAccess (site_field_expr, "Target", loc).Resolve (bc), args, false, loc).Resolve (bc);
if (target != null) {
target.Emit (ec);
}
if (conditionalAccessReceiver) {
ec.CloseConditionalAccess (!isStatement && type.IsNullableType ? type : null);
ec.ConditionalAccess = ca;
}
}
}
示例8: TableSwitchEmit
/// <summary>
/// This method emits code for a lookup-based switch statement (non-string)
/// Basically it groups the cases into blocks that are at least half full,
/// and then spits out individual lookup opcodes for each block.
/// It emits the longest blocks first, and short blocks are just
/// handled with direct compares.
/// </summary>
/// <param name="ec"></param>
/// <param name="val"></param>
/// <returns></returns>
void TableSwitchEmit (EmitContext ec, Expression val)
{
int element_count = Elements.Count;
object [] element_keys = new object [element_count];
Elements.Keys.CopyTo (element_keys, 0);
Array.Sort (element_keys);
// initialize the block list with one element per key
var key_blocks = new List<KeyBlock> (element_count);
foreach (object key in element_keys)
key_blocks.Add (new KeyBlock (System.Convert.ToInt64 (key)));
KeyBlock current_kb;
// iteratively merge the blocks while they are at least half full
// there's probably a really cool way to do this with a tree...
while (key_blocks.Count > 1)
{
var key_blocks_new = new List<KeyBlock> ();
current_kb = (KeyBlock) key_blocks [0];
for (int ikb = 1; ikb < key_blocks.Count; ikb++)
{
KeyBlock kb = (KeyBlock) key_blocks [ikb];
if ((current_kb.Size + kb.Size) * 2 >= KeyBlock.TotalLength (current_kb, kb))
{
// merge blocks
current_kb.last = kb.last;
current_kb.Size += kb.Size;
}
else
{
// start a new block
key_blocks_new.Add (current_kb);
current_kb = kb;
}
}
key_blocks_new.Add (current_kb);
if (key_blocks.Count == key_blocks_new.Count)
break;
key_blocks = key_blocks_new;
}
// initialize the key lists
foreach (KeyBlock kb in key_blocks)
kb.element_keys = new List<object> ();
// fill the key lists
int iBlockCurr = 0;
if (key_blocks.Count > 0) {
current_kb = (KeyBlock) key_blocks [0];
foreach (object key in element_keys)
{
bool next_block = (key is UInt64) ? (ulong) key > (ulong) current_kb.last :
System.Convert.ToInt64 (key) > current_kb.last;
if (next_block)
current_kb = (KeyBlock) key_blocks [++iBlockCurr];
current_kb.element_keys.Add (key);
}
}
// sort the blocks so we can tackle the largest ones first
key_blocks.Sort ();
// okay now we can start...
Label lbl_end = ec.DefineLabel (); // at the end ;-)
Label lbl_default = default_target;
Type type_keys = null;
if (element_keys.Length > 0)
type_keys = element_keys [0].GetType (); // used for conversions
TypeSpec compare_type;
if (TypeManager.IsEnumType (SwitchType))
compare_type = EnumSpec.GetUnderlyingType (SwitchType);
else
compare_type = SwitchType;
for (int iBlock = key_blocks.Count - 1; iBlock >= 0; --iBlock)
{
KeyBlock kb = ((KeyBlock) key_blocks [iBlock]);
lbl_default = (iBlock == 0) ? default_target : ec.DefineLabel ();
if (kb.Length <= 2)
{
foreach (object key in kb.element_keys) {
SwitchLabel sl = (SwitchLabel) Elements [key];
if (key is int && (int) key == 0) {
val.EmitBranchable (ec, sl.GetILLabel (ec), false);
} else {
val.Emit (ec);
EmitObjectInteger (ec, key);
//.........这里部分代码省略.........
示例9: DoEmitStringSwitch
void DoEmitStringSwitch (LocalTemporary value, EmitContext ec)
{
Label l_initialized = ec.DefineLabel ();
//
// Skip initialization when value is null
//
value.EmitBranchable (ec, null_target, false);
//
// Check if string dictionary is initialized and initialize
//
switch_cache_field.EmitBranchable (ec, l_initialized, true);
string_dictionary.EmitStatement (ec);
ec.MarkLabel (l_initialized);
LocalTemporary string_switch_variable = new LocalTemporary (TypeManager.int32_type);
ResolveContext rc = new ResolveContext (ec.MemberContext);
if (TypeManager.generic_ienumerable_type != null) {
Arguments get_value_args = new Arguments (2);
get_value_args.Add (new Argument (value));
get_value_args.Add (new Argument (string_switch_variable, Argument.AType.Out));
Expression get_item = new Invocation (new MemberAccess (switch_cache_field, "TryGetValue", loc), get_value_args).Resolve (rc);
if (get_item == null)
return;
//
// A value was not found, go to default case
//
get_item.EmitBranchable (ec, default_target, false);
} else {
Arguments get_value_args = new Arguments (1);
get_value_args.Add (new Argument (value));
Expression get_item = new ElementAccess (switch_cache_field, get_value_args, loc).Resolve (rc);
if (get_item == null)
return;
LocalTemporary get_item_object = new LocalTemporary (TypeManager.object_type);
get_item_object.EmitAssign (ec, get_item, true, false);
ec.Emit (OpCodes.Brfalse, default_target);
ExpressionStatement get_item_int = (ExpressionStatement) new SimpleAssign (string_switch_variable,
new Cast (new TypeExpression (TypeManager.int32_type, loc), get_item_object, loc)).Resolve (rc);
get_item_int.EmitStatement (ec);
get_item_object.Release (ec);
}
TableSwitchEmit (ec, string_switch_variable);
string_switch_variable.Release (ec);
}
示例10: GetILLabelCode
public Label GetILLabelCode (EmitContext ec)
{
if (!il_label_code_set){
il_label_code = ec.DefineLabel ();
il_label_code_set = true;
}
return il_label_code;
}
示例11: DoEmit
protected override void DoEmit (EmitContext ec)
{
Label loop = ec.DefineLabel ();
Label old_begin = ec.LoopBegin;
Label old_end = ec.LoopEnd;
ec.LoopBegin = ec.DefineLabel ();
ec.LoopEnd = ec.DefineLabel ();
ec.MarkLabel (loop);
EmbeddedStatement.Emit (ec);
ec.MarkLabel (ec.LoopBegin);
//
// Dead code elimination
//
if (expr is Constant){
bool res = !((Constant) expr).IsDefaultValue;
expr.EmitSideEffect (ec);
if (res)
ec.Emit (OpCodes.Br, loop);
} else
expr.EmitBranchable (ec, loop, true);
ec.MarkLabel (ec.LoopEnd);
ec.LoopBegin = old_begin;
ec.LoopEnd = old_end;
}
示例12: GetILLabel
public Label GetILLabel (EmitContext ec)
{
if (!il_label_set){
il_label = ec.DefineLabel ();
il_label_set = true;
}
return il_label;
}
示例13: Emit
public override void Emit (EmitContext ec)
{
if (Report.Errors > 0)
return;
#if PRODUCTION
try {
#endif
if (ec.HasReturnLabel)
ec.ReturnLabel = ec.DefineLabel ();
base.Emit (ec);
ec.Mark (EndLocation);
if (ec.HasReturnLabel)
ec.MarkLabel (ec.ReturnLabel);
if (ec.return_value != null) {
ec.Emit (OpCodes.Ldloc, ec.return_value);
ec.Emit (OpCodes.Ret);
} else {
//
// If `HasReturnLabel' is set, then we already emitted a
// jump to the end of the method, so we must emit a `ret'
// there.
//
// Unfortunately, System.Reflection.Emit automatically emits
// a leave to the end of a finally block. This is a problem
// if no code is following the try/finally block since we may
// jump to a point after the end of the method.
// As a workaround, we're always creating a return label in
// this case.
//
if (ec.HasReturnLabel || !unreachable) {
if (ec.ReturnType != TypeManager.void_type)
ec.Emit (OpCodes.Ldloc, ec.TemporaryReturn ());
ec.Emit (OpCodes.Ret);
}
}
#if PRODUCTION
} catch (Exception e){
Console.WriteLine ("Exception caught by the compiler while emitting:");
Console.WriteLine (" Block that caused the problem begin at: " + block.loc);
Console.WriteLine (e.GetType ().FullName + ": " + e.Message);
throw;
}
#endif
}
示例14: PrepareForEmit
public Label PrepareForEmit (EmitContext ec)
{
if (!prepared) {
prepared = true;
resume_point = ec.DefineLabel ();
}
return resume_point;
}
示例15: EmitConditionalAccess
protected void EmitConditionalAccess (EmitContext ec)
{
var a_expr = arguments [0].Expr;
var des = a_expr as DynamicExpressionStatement;
if (des != null) {
des.EmitConditionalAccess (ec);
}
if (HasConditionalAccess ()) {
var NullOperatorLabel = ec.DefineLabel ();
if (ExpressionAnalyzer.IsInexpensiveLoad (a_expr)) {
a_expr.Emit (ec);
} else {
var lt = new LocalTemporary (a_expr.Type);
lt.EmitAssign (ec, a_expr, true, false);
Arguments [0].Expr = lt;
}
ec.Emit (OpCodes.Brtrue_S, NullOperatorLabel);
if (!ec.ConditionalAccess.Statement) {
if (ec.ConditionalAccess.Type.IsNullableType)
Nullable.LiftedNull.Create (ec.ConditionalAccess.Type, Location.Null).Emit (ec);
else
ec.EmitNull ();
}
ec.Emit (OpCodes.Br, ec.ConditionalAccess.EndLabel);
ec.MarkLabel (NullOperatorLabel);
return;
}
if (a_expr.HasConditionalAccess ()) {
var lt = new LocalTemporary (a_expr.Type);
lt.EmitAssign (ec, a_expr, false, false);
Arguments [0].Expr = lt;
}
}