代码拉取完成,页面将自动刷新
#include "chibi.h"
// Returns the contents of a given file.
static char *read_file(char *path) {
// Open and read the file.
FILE *fp = fopen(path, "r");
if (!fp)
error("cannot open %s: %s", path, strerror(errno));
int filemax = 10 * 1024 * 1024;
char *buf = malloc(filemax);
int size = fread(buf, 1, filemax - 2, fp);
if (!feof(fp))
error("%s: file too large");
// Make sure that the string ends with "\n\0".
if (size == 0 || buf[size - 1] != '\n')
buf[size++] = '\n';
buf[size] = '\0';
return buf;
}
int main(int argc, char **argv) {
if (argc != 2)
error("%s: invalid number of arguments", argv[0]);
// Tokenize and parse.
filename = argv[1];
user_input = read_file(argv[1]);
token = tokenize();
Program *prog = program();
// Assign offsets to local variables.
for (Function *fn = prog->fns; fn; fn = fn->next) {
int offset = fn->has_varargs ? 56 : 0;
for (VarList *vl = fn->locals; vl; vl = vl->next) {
Var *var = vl->var;
offset = align_to(offset, var->ty->align);
offset += var->ty->size;
var->offset = offset;
}
fn->stack_size = align_to(offset, 8);
}
// Traverse the AST to emit assembly.
codegen(prog);
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。