Advertisement
iDestyKK

csem_stuff

Nov 21st, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. /*
  2.  * fhead - beginning of function body
  3.  */
  4. void fhead(struct id_entry *p) {
  5.     printf("func %s\n", p->i_name);
  6.     unsigned int i;
  7.     for (i = 0; i < formalnum; i++) {
  8.         if (formaltypes[i] == 'f') {
  9.             printf("formal 8\n");
  10.         } else if (formaltypes[i] == 'i') {
  11.             printf("formal 4\n");
  12.         } else {
  13.             yyerror("formal type somehow stored incorrectly");
  14.         }
  15.     }
  16.     for (i = 0; i < localnum; i++) {
  17.         if (localtypes[i] == 'f') {
  18.             printf("localloc %d\n", 8 * localwidths[i]);
  19.         } else if (localtypes[i] == 'i') {
  20.             printf("localloc %d\n", 4 * localwidths[i]);
  21.         } else {
  22.             yyerror("formal type somehow stored incorrectly");
  23.         }
  24.     }
  25. }
  26.  
  27. /*
  28.  * fname - function declaration
  29.  */
  30. struct id_entry *fname(int t, char *id) {
  31.     struct id_entry *p;
  32.  
  33.     if ((p = lookup(id, 0)) == NULL) {
  34.         p = install(id, 0);
  35.     } else if (p->i_defined) {
  36.         yyerror("procedure previously declared");
  37.     } else if (p->i_type != t) {
  38.         yyerror("function declaration types do not match");
  39.     }
  40.  
  41.     p->i_type = t;
  42.     p->i_scope = GLOBAL;
  43.     p->i_defined = 1;
  44.     enterblock();
  45.     formalnum = 0;
  46.     localnum = 0;
  47.  
  48.     return p;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement