本文整理汇总了C#中Pchp.CodeAnalysis.CodeGen.CodeGenerator.EmitPop方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerator.EmitPop方法的具体用法?C# CodeGenerator.EmitPop怎么用?C# CodeGenerator.EmitPop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pchp.CodeAnalysis.CodeGen.CodeGenerator
的用法示例。
在下文中一共展示了CodeGenerator.EmitPop方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Emit
internal override void Emit(CodeGenerator cg)
{
cg.EmitSequencePoint(this.PhpSyntax);
var rtype = cg.Routine.ReturnType;
var rvoid = rtype.SpecialType == SpecialType.System_Void;
//
if (this.Returned == null)
{
if (rvoid)
{
// <void>
}
else
{
// <default>
cg.EmitLoadDefault(rtype, cg.Routine.ResultTypeMask);
}
}
else
{
if (rvoid)
{
// <expr>;
cg.EmitPop(this.Returned.Emit(cg));
}
else
{
// return (T)<expr>;
cg.EmitConvert(this.Returned, rtype);
}
}
// .ret
cg.EmitRet(rtype);
}
示例2: EmitStrictEquality
internal static TypeSymbol EmitStrictEquality(CodeGenerator cg, TypeSymbol xtype, BoundExpression right)
{
TypeSymbol ytype;
switch (xtype.SpecialType)
{
case SpecialType.System_Boolean:
ytype = cg.Emit(right);
if (ytype.SpecialType == SpecialType.System_Boolean)
{
// bool == bool
cg.Builder.EmitOpCode(ILOpCode.Ceq);
return cg.CoreTypes.Boolean;
}
else if (
ytype.SpecialType == SpecialType.System_Double ||
ytype.SpecialType == SpecialType.System_Int32 ||
ytype.SpecialType == SpecialType.System_Int64 ||
ytype.SpecialType == SpecialType.System_String ||
ytype.IsOfType(cg.CoreTypes.IPhpArray) ||
ytype == cg.CoreTypes.PhpString ||
ytype == cg.CoreTypes.Object)
{
// bool == something else => false
cg.EmitPop(ytype);
cg.EmitPop(xtype);
cg.Builder.EmitBoolConstant(false);
return cg.CoreTypes.Boolean;
}
else
{
// bool == PhpValue
cg.EmitConvertToPhpValue(ytype, 0);
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Operators.StrictCeq_bool_PhpValue)
.Expect(SpecialType.System_Boolean);
}
case SpecialType.System_Int32:
cg.Builder.EmitOpCode(ILOpCode.Conv_i8); // i4 -> i8
goto case SpecialType.System_Int64;
case SpecialType.System_Int64:
ytype = cg.Emit(right);
if (ytype.SpecialType == SpecialType.System_Int32)
{
cg.Builder.EmitOpCode(ILOpCode.Conv_i8); // i4 -> i8
ytype = cg.CoreTypes.Long;
}
if (ytype.SpecialType == SpecialType.System_Int64)
{
// i8 == i8
cg.Builder.EmitOpCode(ILOpCode.Ceq);
return cg.CoreTypes.Boolean;
}
else if (
ytype.SpecialType == SpecialType.System_Boolean ||
ytype.SpecialType == SpecialType.System_String ||
ytype.SpecialType == SpecialType.System_Double ||
ytype.IsOfType(cg.CoreTypes.IPhpArray) ||
ytype == cg.CoreTypes.Object ||
ytype == cg.CoreTypes.PhpString)
{
// i8 == something else => false
cg.EmitPop(ytype);
cg.EmitPop(xtype);
cg.Builder.EmitBoolConstant(false);
return cg.CoreTypes.Boolean;
}
else
{
// i8 == PhpValue
cg.EmitConvertToPhpValue(ytype, 0);
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Operators.StrictCeq_long_PhpValue)
.Expect(SpecialType.System_Boolean);
}
case SpecialType.System_Double:
ytype = cg.Emit(right);
if (ytype.SpecialType == SpecialType.System_Double)
{
// r8 == r8
cg.Builder.EmitOpCode(ILOpCode.Ceq);
return cg.CoreTypes.Boolean;
}
else if (
ytype.SpecialType == SpecialType.System_Boolean ||
ytype.SpecialType == SpecialType.System_String ||
ytype.SpecialType == SpecialType.System_Int64 ||
ytype.SpecialType == SpecialType.System_Int32 ||
ytype.IsOfType(cg.CoreTypes.IPhpArray) ||
ytype == cg.CoreTypes.Object ||
ytype == cg.CoreTypes.PhpString)
{
// r8 == something else => false
cg.EmitPop(ytype);
cg.EmitPop(xtype);
cg.Builder.EmitBoolConstant(false);
return cg.CoreTypes.Boolean;
}
//.........这里部分代码省略.........
示例3: Emit
//.........这里部分代码省略.........
#endregion
#region Boolean and Bitwise Operations
case Operations.And:
returned_type = EmitBinaryBooleanOperation(cg, true);
break;
case Operations.Or:
returned_type = EmitBinaryBooleanOperation(cg, false);
break;
case Operations.Xor:
returned_type = EmitBinaryXor(cg);
break;
case Operations.BitAnd:
returned_type = EmitBitAnd(cg, Left, Right);
break;
case Operations.BitOr:
returned_type = EmitBitOr(cg, Left, Right);
break;
case Operations.BitXor:
//returned_typecode = EmitBitOperation(node, codeGenerator, Operators.BitOp.Xor);
//break;
throw new NotImplementedException();
#endregion
#region Comparing Operations
case Operations.Equal:
returned_type = EmitEquality(cg);
break;
case Operations.NotEqual:
EmitEquality(cg);
cg.EmitLogicNegation();
returned_type = cg.CoreTypes.Boolean;
break;
case Operations.GreaterThan:
returned_type = EmitLtGt(cg, false);
break;
case Operations.LessThan:
returned_type = EmitLtGt(cg, true);
break;
case Operations.GreaterThanOrEqual:
// template: !(LessThan)
returned_type = EmitLtGt(cg, true);
cg.EmitLogicNegation();
break;
case Operations.LessThanOrEqual:
// template: !(GreaterThan)
returned_type = EmitLtGt(cg, false);
cg.EmitLogicNegation();
break;
case Operations.Identical:
// Left === Right
returned_type = EmitStrictEquality(cg);
break;
case Operations.NotIdentical:
// ! (Left === Right)
returned_type = EmitStrictEquality(cg);
cg.EmitLogicNegation();
break;
#endregion
default:
throw ExceptionUtilities.Unreachable;
}
//
switch (Access.Flags)
{
case AccessMask.Read:
// Result is read, do nothing.
Debug.Assert(returned_type.SpecialType != SpecialType.System_Void);
break;
case AccessMask.None:
// Result is not read, pop the result
cg.EmitPop(returned_type);
returned_type = cg.CoreTypes.Void;
break;
}
//
return returned_type;
}
示例4: EmitPhpCtor
void EmitPhpCtor(MethodSymbol ctor, Emit.PEModuleBuilder module)
{
if (ctor == null) return; // static class
Debug.Assert(ctor.MethodKind == MethodKind.Constructor);
module.SetMethodBody(ctor, MethodGenerator.GenerateMethodBody(module, ctor, il =>
{
Debug.Assert(SpecialParameterSymbol.IsContextParameter(ctor.Parameters[0]));
var cg = new CodeGenerator(il, module, DiagnosticBag.GetInstance(), OptimizationLevel.Release, false, this, new ParamPlace(ctor.Parameters[0]), new ArgPlace(this, 0));
// call .phpnew
var phpnew = this.InitializeInstanceMethod;
cg.EmitPop(cg.EmitThisCall(phpnew, ctor));
// call __construct
var phpctor = this.ResolvePhpCtor(true);
cg.EmitPop(cg.EmitThisCall(phpctor, ctor));
Debug.Assert(ctor.ReturnsVoid);
cg.EmitRet(ctor.ReturnType);
}, null, DiagnosticBag.GetInstance(), false));
}
示例5: EmitPhpNew
void EmitPhpNew(SynthesizedPhpNewMethodSymbol phpnew, Emit.PEModuleBuilder module)
{
if (phpnew == null) return; // static class
module.SetMethodBody(phpnew, MethodGenerator.GenerateMethodBody(module, phpnew, (Action<Microsoft.CodeAnalysis.CodeGen.ILBuilder>)(il =>
{
Debug.Assert(SpecialParameterSymbol.IsContextParameter(phpnew.Parameters[0]));
var cg = new CodeGenerator(il, module, DiagnosticBag.GetInstance(), OptimizationLevel.Release, false, this, new ParamPlace(phpnew.Parameters[0]), new ArgPlace(this, 0));
// initialize <ctx> field,
// if field is declared within this type
var ctxField = this.ContextStore;
if (ctxField != null && object.ReferenceEquals((object)ctxField.ContainingType, this))
{
var ctxFieldPlace = new FieldPlace(cg.ThisPlaceOpt, (IFieldSymbol)ctxField);
// Debug.Assert(<ctx> != null)
cg.EmitDebugAssertNotNull(cg.ContextPlaceOpt, "Context cannot be null.");
// <this>.<ctx> = <ctx>
ctxFieldPlace.EmitStorePrepare(il);
cg.EmitLoadContext();
ctxFieldPlace.EmitStore(il);
}
// initialize class fields
foreach (var fld in this.GetFieldsToEmit().OfType<SourceFieldSymbol>().Where(fld => !fld.RequiresHolder && !fld.IsStatic && !fld.IsConst))
{
fld.EmitInit(cg);
}
// base..phpnew ?? base..ctor
var basenew = phpnew.BasePhpNew;
Debug.Assert(basenew != null);
cg.EmitPop(cg.EmitThisCall(basenew, phpnew));
Debug.Assert(phpnew.ReturnsVoid);
cg.EmitRet(phpnew.ReturnType);
}), null, DiagnosticBag.GetInstance(), false));
}
示例6: Generate
internal override void Generate(CodeGenerator cg)
{
// four cases:
// 1. just single or none case label that can be replaced with single IF
// 2. switch over integers, using native CIL switch
// 3. switch over strings, using C# static Dictionary and CIL switch
// 4. PHP style switch which is just a bunch of IFs
if (this.CaseBlocks.Length == 0 || this.CaseBlocks[0].IsDefault)
{
Debug.Assert(this.CaseBlocks.Length <= 1);
// no SWITCH or IF needed
cg.EmitPop(this.SwitchValue.WithAccess(BoundAccess.None).Emit(cg)); // None Access, also using BoundExpression.Emit directly to avoid CodeGenerator type specialization which is not needed
if (this.CaseBlocks.Length == 1)
{
cg.GenerateScope(this.CaseBlocks[0], NextBlock.Ordinal);
}
}
else
{
// CIL Switch:
bool allconsts = this.CaseBlocks.All(c => c.IsDefault || c.CaseValue.ConstantValue.HasValue);
bool allconstints = allconsts && this.CaseBlocks.All(c => c.IsDefault || IsInt32(c.CaseValue.ConstantValue.Value));
//bool allconststrings = allconsts && this.CaseBlocks.All(c => c.IsDefault || IsString(c.CaseValue.ConstantValue.Value));
var default_block = this.DefaultBlock;
// <switch_loc> = <SwitchValue>;
TypeSymbol switch_type;
LocalDefinition switch_loc;
// Switch Header
if (allconstints)
{
switch_type = cg.CoreTypes.Int32;
cg.EmitSequencePoint(this.SwitchValue.PhpSyntax);
cg.EmitConvert(this.SwitchValue, switch_type);
switch_loc = cg.GetTemporaryLocal(switch_type);
cg.Builder.EmitLocalStore(switch_loc);
// switch (labels)
cg.Builder.EmitIntegerSwitchJumpTable(GetSwitchCaseLabels(CaseBlocks), default_block ?? NextBlock, switch_loc, switch_type.PrimitiveTypeCode);
}
//else if (allconststrings)
//{
//}
else
{
// legacy jump table
// IF (case_i) GOTO label_i;
cg.EmitSequencePoint(this.SwitchValue.PhpSyntax);
switch_type = cg.Emit(this.SwitchValue);
switch_loc = cg.GetTemporaryLocal(switch_type);
cg.Builder.EmitLocalStore(switch_loc);
//
for (int i = 0; i < this.CaseBlocks.Length; i++)
{
var this_block = this.CaseBlocks[i];
if (this_block.CaseValue != null)
{
// <CaseValue>:
cg.EmitSequencePoint(this_block.CaseValue.PhpSyntax);
// if (<switch_loc> == c.CaseValue) goto this_block;
cg.Builder.EmitLocalLoad(switch_loc);
BoundBinaryEx.EmitEquality(cg, switch_type, this_block.CaseValue);
cg.Builder.EmitBranch(ILOpCode.Brtrue, this_block);
}
}
// default:
cg.Builder.EmitBranch(ILOpCode.Br, default_block ?? NextBlock);
}
// FREE <switch_loc>
cg.ReturnTemporaryLocal(switch_loc);
// Switch Body
this.CaseBlocks.ForEach((i, this_block) =>
{
var next_case = (i + 1 < this.CaseBlocks.Length) ? this.CaseBlocks[i + 1] : null;
// {
cg.GenerateScope(this_block, (next_case ?? NextBlock).Ordinal);
// }
});
}
//
cg.Scope.ContinueWith(NextBlock);
}
示例7: EmitLoadFieldInstance
/// <summary>
/// Emits instance of the field containing class.
/// </summary>
protected virtual void EmitLoadFieldInstance(CodeGenerator cg, InstanceCacheHolder instanceOpt)
{
// instance
var instancetype = InstanceCacheHolder.EmitInstance(instanceOpt, cg, Instance);
//
if (Field.IsStatic && Instance != null)
cg.EmitPop(instancetype);
else if (!Field.IsStatic && Instance == null)
throw new NotImplementedException();
}
示例8: EmitTmpRet
/// <summary>
/// Stores value from top of the evaluation stack to a temporary variable which will be returned from the exit block.
/// </summary>
internal void EmitTmpRet(CodeGenerator cg, Symbols.TypeSymbol stack)
{
// lazy initialize
if (_retlbl == null)
{
_retlbl = new object();
}
if (_rettmp == null)
{
var rtype = cg.Routine.ReturnType;
if (rtype.SpecialType != SpecialType.System_Void)
{
_rettmp = cg.GetTemporaryLocal(rtype);
}
}
// <rettmp> = <stack>;
if (_rettmp != null)
{
cg.EmitConvert(stack, 0, (Symbols.TypeSymbol)_rettmp.Type);
cg.Builder.EmitLocalStore(_rettmp);
cg.Builder.EmitBranch(ILOpCode.Br, _retlbl);
}
else
{
cg.EmitPop(stack);
}
}