public override void CGenStmt(Env env, CGenState state) {
ExprType ret_type = env.GetCurrentFunction().ReturnType;
Int32 stack_size = state.StackSize;
if (this.ExprOpt.IsSome) {
// Evaluate the Value.
this.ExprOpt.Value.CGenValue(state);
// If the function returns a struct, copy it to the address given by 8(%ebp).
if (this.ExprOpt.Value.Type is StructOrUnionType) {
state.MOVL(Reg.EAX, Reg.ESI);
state.MOVL(2 * ExprType.SIZEOF_POINTER, Reg.EBP, Reg.EDI);
state.MOVL(this.ExprOpt.Value.Type.SizeOf, Reg.ECX);
state.CGenMemCpy();
state.MOVL(2 * ExprType.SIZEOF_POINTER, Reg.EBP, Reg.EAX);
}
// Restore stack size.
state.CGenForceStackSizeTo(stack_size);
}
// Jump to end of the function.
state.JMP(state.ReturnLabel);
}
}