fbgen.c

来自「c编译器实现」· C语言 代码 · 共 147 行

C
147
字号
/* *  FBCC - A simple C compiler. *  *  Copyright (c) 1996 Fabrice Bellard * *  Contact addresses: *  mail: Fabrice Bellard, 451 chemin du mas de Matour, 34790 Grabels, France *  email: bellard@email.enst.fr *  url: http://www.enst.fr/~bellard * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#include <stdlib.h>#include <stdio.h>#include "fbcc.h"#include <fbvminstr.h>void Gen_Code(int c){	 printf(" %s\n",vm_instr_str[c]);}void Gen_Int(unsigned int c){	 printf(" =%d\n",c);}int label_num;int Gen_NewLabel(void){	 label_num++;	 return label_num;}void Gen_Label(int c){	 printf("@L%d:\n",c);}void Gen_Jmp(int c,int l){	 printf(" %s @L%d\n",vm_instr_str[c],l);}void Gen_LI(int c,int data,SYM *s){	 if (s==NULL) {			printf(" %s %d\n",vm_instr_str[c],data);	 } else if (data==0) {			printf(" %s %s\n",vm_instr_str[c],s->str);	 } else {			printf(" %s %s+%d\n",vm_instr_str[c],s->str,data);	 }}/* * G閚閞ation du code pour les expressions */void Gen_RVal(LIST *e);void Gen_LVal(LIST *e);/* * G閚閞ation du code pour le casting */void Gen_Cast(LIST *expr){	 LIST *e1;	 int t1,t2;	 	 e1=hd_list(tl(tl(expr)));	 t1=hd_tag(hd_list(expr));	 t2=hd_tag(hd_list(e1));	 Gen_RVal(e1);	 	 /* g閚閞ation des instructions de conversion de type */	 	 switch (t1) {		case TYPE_CHAR:		case TYPE_UCHAR:			switch(t2) {			 case TYPE_CHAR:			 case TYPE_UCHAR:				 break;			 default:				 Gen_Code(cvt_b_i);			}			break;		case TYPE_SHORT:		case TYPE_USHORT:			switch(t2) {			 case TYPE_CHAR:				 Gen_Code(cvt_i_b);				 break;			 case TYPE_UCHAR:				 Gen_Code(cvt_i_ub);				 break;			 default:				 Gen_Code(cvt_w_i);			}			break;		case TYPE_INT:		case TYPE_UINT:		case TYPE_ENUM:		case TYPE_POINTER:		case TYPE_ARRAY:		case TYPE_FUNC:			switch(t2) {			 case TYPE_CHAR:				 Gen_Code(cvt_i_b);				 break;			 case TYPE_UCHAR:				 Gen_Code(cvt_i_ub);				 break;			 case TYPE_SHORT:				 Gen_Code(cvt_i_w);				 break;			 case TYPE_USHORT:				 Gen_Code(cvt_i_uw);				 break;			}			break;		case TYPE_VOID:			break;		default:			Error_Internal("Conversion vers un type non impl閙ent

⌨️ 快捷键说明

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