本文整理汇总了C++中status::number_returns方法的典型用法代码示例。如果您正苦于以下问题:C++ status::number_returns方法的具体用法?C++ status::number_returns怎么用?C++ status::number_returns使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类status
的用法示例。
在下文中一共展示了status::number_returns方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: code_gen
void n_func_def::code_gen(status& stat, std::ostream& out)
{
// starting pseudo ops
stat.change_text_data("text", out);
out << "\t.globl\t" << stat.get_function_name() << "\n";
out << "\t.ent\t" << stat.get_function_name() << "\n";
out << "\t.type\t" << stat.get_function_name() << ", @function\n";
out << stat.get_function_name() << ":\n";
// dealing with the stack and frame:
// status contains the function number and number of variables in the function.
// function 0 is global, main will probably be function 1 (not really relevant here)
// we need 8 + (vars*4) space on the stack. All variables assigned 4 bytes for simplicity.
int stack_space = 8 + stat.size_variables();
out << "\taddiu\t" << "$sp,$sp,-" << stack_space << "\n"; // stack grows down...
out << "\tsw\t" << "$fp," << (stack_space - 4) << "($sp)\n"; // store the old fp at the top of the stack
out << "\taddi\t" << "$fp,$sp," << stack_space << "\n"; // set new fp at the top of the stack frame.
if (left != NULL)
left->code_gen(stat, out); // the function body.
out << "\tmove\t$v0,$zero\n"; // return zero by default
if (stat.number_returns() > 0)
out << "r" << stat.get_function_name() << ":\n"; // label to branch to and return
out << "\tlw\t" << "$fp," << (stack_space - 4) << "($sp)\n"; // restore the old fp
out << "\taddiu\t" << "$sp,$sp," << stack_space << "\n"; // move the stack back up.
out << "\tj\t$ra\n"; // return
out << "\tnop\n";
out << "\t.end\t" << stat.get_function_name() << "\n\n";
stat.remove_parameters();
return;
}