本文整理汇总了C#中CodeGeneration.CGenState.CGenForceStackSizeTo方法的典型用法代码示例。如果您正苦于以下问题:C# CGenState.CGenForceStackSizeTo方法的具体用法?C# CGenState.CGenForceStackSizeTo怎么用?C# CGenState.CGenForceStackSizeTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeGeneration.CGenState
的用法示例。
在下文中一共展示了CGenState.CGenForceStackSizeTo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CGenStmt
public override void CGenStmt(Env env, CGenState state) {
if (this.ExprOpt.IsSome) {
Int32 stack_size = state.StackSize;
this.ExprOpt.Value.CGenValue(state);
state.CGenForceStackSizeTo(stack_size);
}
}
示例2: CGenDecln
//.........这里部分代码省略.........
last = offset + expr.Type.SizeOf;
});
} else {
// Global without initialization.
switch (this.scs) {
case StorageClass.AUTO:
// .comm name,size,align
break;
case StorageClass.EXTERN:
break;
case StorageClass.STATIC:
// .local name
// .comm name,size,align
state.LOCAL(this.name);
break;
case StorageClass.TYPEDEF:
// Ignore.
return;
default:
throw new InvalidProgramException();
}
if (this.type.Kind != ExprTypeKind.FUNCTION) {
state.COMM(this.name, this.type.SizeOf, ExprType.ALIGN_LONG);
}
}
state.NEWLINE();
} else {
// stack object
state.CGenExpandStackTo(env.StackSize, ToString());
Int32 stack_size = env.StackSize;
// pos should be equal to stack_size, but whatever...
Int32 pos = env.Find(this.name).Value.Offset;
if (this.initr.IsNone) {
return;
}
Initr initr = this.initr.Value;
initr.Iterate(this.type, (Int32 offset, Expr expr) => {
Reg ret = expr.CGenValue(state);
switch (expr.Type.Kind) {
case ExprTypeKind.CHAR:
case ExprTypeKind.UCHAR:
state.MOVB(Reg.EAX, pos + offset, Reg.EBP);
break;
case ExprTypeKind.SHORT:
case ExprTypeKind.USHORT:
state.MOVW(Reg.EAX, pos + offset, Reg.EBP);
break;
case ExprTypeKind.DOUBLE:
state.FSTPL(pos + offset, Reg.EBP);
break;
case ExprTypeKind.FLOAT:
state.FSTPS(pos + offset, Reg.EBP);
break;
case ExprTypeKind.LONG:
case ExprTypeKind.ULONG:
case ExprTypeKind.POINTER:
state.MOVL(Reg.EAX, pos + offset, Reg.EBP);
break;
case ExprTypeKind.STRUCT_OR_UNION:
state.MOVL(Reg.EAX, Reg.ESI);
state.LEA(pos + offset, Reg.EBP, Reg.EDI);
state.MOVL(expr.Type.SizeOf, Reg.ECX);
state.CGenMemCpy();
break;
case ExprTypeKind.ARRAY:
case ExprTypeKind.FUNCTION:
throw new InvalidProgramException($"How could a {expr.Type.Kind} be in a init list?");
default:
throw new InvalidProgramException();
}
state.CGenForceStackSizeTo(stack_size);
});
} // stack object
}
示例3: CGenValue
//.........这里部分代码省略.........
// add an extra argument and move all other arguments upwards.
pack_size += ExprType.SIZEOF_POINTER;
offsets = offsets.Select(_ => _ + ExprType.SIZEOF_POINTER).ToList();
}
// Allocate space for arguments.
// If returning struct, the extra pointer is included.
state.COMMENT($"Arguments take {pack_size} bytes.");
state.CGenExpandStackBy(pack_size);
state.NEWLINE();
// Store the address as the first argument.
if (this.Type is StructOrUnionType) {
state.COMMENT("Putting extra argument for struct return address.");
state.MOVL(Reg.EAX, 0, Reg.ESP);
state.NEWLINE();
}
// This is the stack size before calling the function.
Int32 header_base = -state.StackSize;
// Push the arguments onto the stack in reverse order
for (Int32 i = this.Args.Count; i-- > 0;) {
Expr arg = this.Args[i];
Int32 pos = header_base + offsets[i];
state.COMMENT($"Argument {i} is at {pos}");
Reg ret = arg.CGenValue(state);
switch (arg.Type.Kind) {
case ExprTypeKind.ARRAY:
case ExprTypeKind.CHAR:
case ExprTypeKind.UCHAR:
case ExprTypeKind.SHORT:
case ExprTypeKind.USHORT:
case ExprTypeKind.LONG:
case ExprTypeKind.ULONG:
case ExprTypeKind.POINTER:
if (ret != Reg.EAX) {
throw new InvalidProgramException();
}
state.MOVL(Reg.EAX, pos, Reg.EBP);
break;
case ExprTypeKind.DOUBLE:
if (ret != Reg.ST0) {
throw new InvalidProgramException();
}
state.FSTPL(pos, Reg.EBP);
break;
case ExprTypeKind.FLOAT:
if (ret != Reg.ST0) {
throw new InvalidProgramException();
}
state.FSTPL(pos, Reg.EBP);
break;
case ExprTypeKind.STRUCT_OR_UNION:
if (ret != Reg.EAX) {
throw new InvalidProgramException();
}
state.MOVL(Reg.EAX, Reg.ESI);
state.LEA(pos, Reg.EBP, Reg.EDI);
state.MOVL(arg.Type.SizeOf, Reg.ECX);
state.CGenMemCpy();
break;
default:
throw new InvalidProgramException();
}
state.NEWLINE();
}
// When evaluating arguments, the stack might be changed.
// We must restore the stack.
state.CGenForceStackSizeTo(-header_base);
// Get function address
if (this.Func.Type is FunctionType) {
this.Func.CGenAddress(state);
} else if (this.Func.Type is PointerType) {
this.Func.CGenValue(state);
} else {
throw new InvalidProgramException();
}
state.CALL("*%eax");
state.COMMENT("Function returned.");
state.NEWLINE();
if (this.Type.Kind == ExprTypeKind.FLOAT || this.Type.Kind == ExprTypeKind.DOUBLE) {
return Reg.ST0;
}
return Reg.EAX;
}
示例4: CGenExprStmt
public Reg CGenExprStmt(Env env, Expr expr, CGenState state) {
Int32 stack_size = state.StackSize;
Reg ret = expr.CGenValue(state);
state.CGenForceStackSizeTo(stack_size);
return ret;
}