systemfun.cpp

来自「c语言的简化编译器」· C++ 代码 · 共 72 行

CPP
72
字号

#include "stdafx.h"

#include <string.h>
#include "symbol.h"
#include "memory.h"
#include "error.h"

SYMBOL *s_SysFun;
char *codeSignature(DECL *f, TYPE *t);
FUNCTION *funCinit;

/* 手工生成系统函数的符号表 */
void generateSymbol_SysFun()
{	
	SYMBOL *s;
	FUNCTION *f;
	DECL *d, *d1;
	TYPE *t, *t1;	

	t1 = makeTYPEvoid();
	d = NULL;
	f = makeFUNCTION("cinit", t1, d, NULL);
	f->formals = d;
	f->signature = codeSignature(f->formals,f->type);
	funCinit = f;
	s = NEW(SYMBOL);
	s->name = "cinit";
	s->kind = functionSym;
	s->val.functionS = f;
	s->next = s_SysFun;
	s_SysFun = s;

	t = makeTYPEstring();
	t1 = makeTYPEvoid();
	d = makeDECLformal(t, "name");
	f = makeFUNCTION("printf", t1, d, NULL);
	f->formals = d;
	f->signature = codeSignature(f->formals,f->type);
	s = NEW(SYMBOL);
	s->name = "printf";
	s->kind = functionSym;
	s->val.functionS = f;
	s->next = s_SysFun;
	s_SysFun = s;


	t = makeTYPEint();
	d = makeDECLformal(t, "a");
	d1 = makeDECLformal(t, "b");
	f = makeFUNCTION("printf", t, d, NULL);
	f->formals = d;
	d->next = d1;
	f->signature = codeSignature(f->formals,f->type);
	s = NEW(SYMBOL);
	s->name = "getsum";
	s->kind = functionSym;
	s->val.functionS = f;
	s->next = s_SysFun;
	s_SysFun = s;
}

SYMBOL *getSymbol_SysFun(char *name)
{
	SYMBOL *s;
	for (s = s_SysFun; s; s = s->next) {
		if (strcmp(s->name,name)==0) 
			return s;
	}
	return NULL;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?