コード例 #1
0
ファイル: assem.c プロジェクト: JackWyj/Tiger
/* first param is string created by this function by reading 'assem' string
 * and replacing `d `s and `j stuff.
 * Last param is function to use to determine what to do with each temp.
 */
static void format(char *result, string assem, Temp_tempList dst, Temp_tempList src, AS_targets jumps, Temp_map m)
{  
	char *p;
	int i = 0; /* offset to result string */

	for (p = assem; p && *p != '\0'; p++) {
		if (*p == '`') {
			switch(*(++p)) {
				case 's':
				{
				int n = *(++p) - '0';
				string s = Temp_look(m, nthTemp(src,n));
				strcpy(result+i, s);
				i += strlen(s);
				}
				break;
				case 'd': 
				{
				int n = *(++p) - '0';
				string s = Temp_look(m, nthTemp(dst,n));
				strcpy(result+i, s);
				i += strlen(s);
				}
				break;
				case 'j': assert(jumps); 
				{
				int n = *(++p) - '0';
				string s = Temp_labelstring(nthLabel(jumps->labels,n));
				strcpy(result+i, s);
				i += strlen(s);
				}
				break;
				default: assert(0);
			} 
		} else {
			result[i] = *p; 
			i++; 
		}
	}
	result[i] = '\0';
}
コード例 #2
0
ファイル: assem.c プロジェクト: 0xcc/tiger-compiler-C
/* first param is string created by this function by reading 'assem' string
 * and replacing `d `s and `j stuff.
 * Last param is function to use to determine what to do with each temp.
 */
void AS_format(char *result, string assem, 
		   Temp_tempList dst, Temp_tempList src,
		   AS_targets jumps, Temp_map m)
{
  char *p;
  int i = 0; /* offset to result string */
  for(p = assem; p && *p != '\0'; p++)
    if (*p == '`')
      switch(*(++p)) {
      case 's': {int n = atoi(++p);
//printf("mark start\n");
//printf("n = %d\n", n);
//if(nthTemp(src,n)==NULL){printf("But it is NULL!\n");}fflush(stdout);
		 string s = Temp_look(m, nthTemp(src,n));
//printf("mark end\n");fflush(stdout);
		 strcpy(result+i, s);
		 i += strlen(s);
	       }
	break;
      case 'd': {int n = atoi(++p);
		 string s = Temp_look(m, nthTemp(dst,n));
		 strcpy(result+i, s);
		 i += strlen(s);
	       }
	break;
      case 'j': assert(jumps); 
	       {int n = atoi(++p);
		 string s = Temp_labelstring(nthLabel(jumps->labels,n));
		 strcpy(result+i, s);
		 i += strlen(s);
	       }
	break;
      case '`': result[i] = '`'; i++; 
	break;
      default: assert(0);
      }
    else {result[i] = *p; i++; }
  result[i] = '\0';
}
コード例 #3
0
ファイル: assem.c プロジェクト: 0xcc/tiger-compiler-C
static Temp_label nthLabel(Temp_labelList list, int i) {
  assert(list);
  if (i==0) return list->head;
  else return nthLabel(list->tail,i-1);
}