summaryrefslogtreecommitdiff
path: root/src/iconc/csym.c
blob: 8e764e3866571d7342acde416e57a8092908a41e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
/*
 * csym.c -- functions for symbol table management.
 */
#include "../h/gsupport.h"
#include "cglobals.h"
#include "ctrans.h"
#include "ctree.h"
#include "ctoken.h"
#include "csym.h"
#include "ccode.h"
#include "cproto.h"

/*
 * Prototypes.
 */

static struct gentry    *alcglob  (struct gentry *blink,
				    char *name,int flag);
static struct fentry    *alcfld   (struct fentry *blink, char *name,
				    struct par_rec *rp);
static struct centry    *alclit	  (struct centry *blink,
				    char *image, int len,int flag);
static struct lentry    *alcloc	  (struct lentry *blink,
				    char *name,int flag);
static struct par_rec   *alcprec  (struct rentry *rec, int offset,
				    struct par_rec *next);
static struct centry    *clookup  (char *image,int flag);
static struct lentry    *dcl_loc  (char *id, int id_type,
                                    struct lentry *next);
static struct lentry    *llookup  (char *id);
static void           opstrinv (struct implement *ip);
static struct gentry    *putglob  (char *id,int id_type);
static struct gentry    *try_gbl  (char *id);

int max_sym = 0;  /* max number of parameter symbols in run-time routines */
int max_prm = 0;  /* max number of parameters for any invocable routine */

/*
 * The operands of the invocable declaration are stored in a list for
 *  later processing.
 */
struct strinv {
   nodeptr op;
   int arity;
   struct strinv *next;
   };
struct strinv *strinvlst = NULL;
int op_tbl_sz;

struct pentry *proc_lst = NULL; /* procedure list */
struct rentry *rec_lst = NULL;  /* record list */


/*
 *instl_p - install procedure or record in global symbol table, returning
 *  the symbol table entry.
 */
struct gentry *instl_p(name, flag)
char *name;
int flag;
   {
   struct gentry *gp;

   flag |= F_Global;
   if ((gp = glookup(name)) == NULL) 
      gp = putglob(name, flag);
   else if ((gp->flag & (~F_Global)) == 0) {
      /* 
       * superfluous global declaration for record or proc
       */
      gp->flag |= flag;
      }
   else			/* the user can't make up his mind */
      tfatal("inconsistent redeclaration", name);
   return gp;
   }

/*
 * install - put an identifier into the global or local symbol table.
 *  The basic idea here is to look in the right table and install
 *  the identifier if it isn't already there.  Some semantic checks
 *  are performed.
 */
void install(name, flag)
char *name;
int flag;
   {
   struct fentry *fp;
   struct gentry *gp;
   struct lentry *lp;
   struct par_rec **rpp;
   struct fldname *fnp;
   int foffset;

   switch (flag) {
      case F_Global:	/* a variable in a global declaration */
         if ((gp = glookup(name)) == NULL)
            putglob(name, flag);
         else
            gp->flag |= flag;
         break;

      case F_Static:	/* static declaration */
         ++proc_lst->nstatic;
         lp = dcl_loc(name, flag, proc_lst->statics);
         proc_lst->statics = lp;
         break;

      case F_Dynamic:	/* local declaration */
         ++proc_lst->ndynam;
         lp = dcl_loc(name, flag, proc_lst->dynams);
         proc_lst->dynams = lp;
         break;

      case F_Argument:	/* formal parameter */
         ++proc_lst->nargs;
         if (proc_lst->nargs > max_prm)
            max_prm = proc_lst->nargs;
         lp = dcl_loc(name, flag, proc_lst->args);
         proc_lst->args = lp;
         break;

      case F_Field: /* field declaration */
         fnp = NewStruct(fldname);
         fnp->name = name;
         fnp->next = rec_lst->fields;
         rec_lst->fields = fnp;
         foffset = rec_lst->nfields++;
         if (foffset > max_prm)
            max_prm = foffset;
         if ((fp = flookup(name)) == NULL) {
            /*
             * first occurrence of this field name.
             */
            fhash[FHasher(name)] = alcfld(fhash[FHasher(name)], name,
               alcprec(rec_lst, foffset, NULL));
            }
         else {
            rpp = &(fp->rlist);
            while (*rpp != NULL && (*rpp)->offset <= foffset &&
               (*rpp)->rec != rec_lst)
               rpp = &((*rpp)->next);
            if (*rpp == NULL || (*rpp)->offset > foffset)
               *rpp = alcprec(rec_lst, foffset, *rpp);
            else
               tfatal("duplicate field name", name);
            }
         break;

      default:
         tsyserr("install: unrecognized symbol table flag.");
      }
   }

/*
 * dcl_loc - handle declaration of a local identifier.
 */
static struct lentry *dcl_loc(name, flag, next)
char *name;
int flag;
struct lentry *next;
   {
   register struct lentry *lp;

   if ((lp = llookup(name)) == NULL) {
      lp = putloc(name,flag);
      lp->next = next;
      }
   else if (lp->flag == flag) /* previously declared as same type */
      twarn("redeclared identifier", name);
   else		/* previously declared as different type */
      tfatal("inconsistent redeclaration", name);
   return lp;
   }

/*
 * putloc - make a local symbol table entry and return pointer to it.
 */
struct lentry *putloc(id,id_type)
char *id;
int id_type;
   {
   register struct lentry *ptr;
   register struct lentry **lhash;
   unsigned hashval;

   if ((ptr = llookup(id)) == NULL) {	/* add to head of hash chain */
      lhash = proc_lst->lhash;
      hashval = LHasher(id);
      ptr = alcloc(lhash[hashval], id, id_type);
      lhash[hashval] = ptr;
      ptr->next = NULL;
      }
   return ptr;
   }

/*
 * putglob makes a global symbol table entry and returns a pointer to it.
 */
static struct gentry *putglob(id, id_type)
char *id;
int id_type;
   {
   register struct gentry *ptr;
   register unsigned hashval;

   if ((ptr = glookup(id)) == NULL) {	 /* add to head of hash chain */
      hashval = GHasher(id);
      ptr = alcglob(ghash[hashval], id, id_type);
      ghash[hashval] = ptr;
      }
   return ptr;
   }

/*
 * putlit makes a constant symbol table entry and returns a pointer to it.
 */
struct centry *putlit(image, littype, len)
char *image;
int len, littype;
   {
   register struct centry *ptr;
   register unsigned hashval;

   if ((ptr = clookup(image,littype)) == NULL) { /* add to head of hash chain */
      hashval = CHasher(image);
      ptr = alclit(chash[hashval], image, len, littype);
      chash[hashval] = ptr;
      }
   return ptr;
   }

/*
 * llookup looks up id in local symbol table and returns pointer to
 *  to it if found or NULL if not present.
 */

static struct lentry *llookup(id)
char *id;
   {
   register struct lentry *ptr;

   ptr = proc_lst->lhash[LHasher(id)];
   while (ptr != NULL && ptr->name != id)
      ptr = ptr->blink;
   return ptr;
   }

/*
 * flookup looks up id in flobal symbol table and returns pointer to
 *  to it if found or NULL if not present.
 */
struct fentry *flookup(id)
char *id;
   {
   register struct fentry *ptr;

   ptr = fhash[FHasher(id)];
   while (ptr != NULL && ptr->name != id) {
      ptr = ptr->blink;
      }
   return ptr;
   }

/*
 * glookup looks up id in global symbol table and returns pointer to
 *  to it if found or NULL if not present.
 */
struct gentry *glookup(id)
char *id;
   {
   register struct gentry *ptr;

   ptr = ghash[GHasher(id)];
   while (ptr != NULL && ptr->name != id) {
      ptr = ptr->blink;
      }
   return ptr;
   }

/*
 * clookup looks up id in constant symbol table and returns pointer to
 *  to it if found or NULL if not present.
 */
static struct centry *clookup(image,flag)
char *image;
int flag;
   {
   register struct centry *ptr;

   ptr = chash[CHasher(image)];
   while (ptr != NULL && (ptr->image != image || ptr->flag != flag))
      ptr = ptr->blink;

   return ptr;
   }

#ifdef DeBug
/*
 * symdump - dump symbol tables.
 */
void symdump()
   {
   struct pentry *proc;

   gdump();
   cdump();
   rdump();
   fdump();
   for (proc = proc_lst; proc != NULL; proc = proc->next) {
      fprintf(stderr,"\n");
      fprintf(stderr,"Procedure %s\n", proc->sym_entry->name);
      ldump(proc->lhash);
      }
   }

/*
 * prt_flgs - print flags from a symbol table entry.
 */
static void prt_flgs(flags)
int flags;
   {
   if (flags & F_Global)
      fprintf(stderr, " F_Global");
   if (flags & F_Proc)
      fprintf(stderr, " F_Proc");
   if (flags & F_Record)
      fprintf(stderr, " F_Record");
   if (flags & F_Dynamic)
      fprintf(stderr, " F_Dynamic");
   if (flags & F_Static)
      fprintf(stderr, " F_Static");
   if (flags & F_Builtin)
      fprintf(stderr, " F_Builtin");
   if (flags & F_StrInv)
      fprintf(stderr, " F_StrInv");
   if (flags & F_ImpError)
      fprintf(stderr, " F_ImpError");
   if (flags & F_Argument)
      fprintf(stderr, " F_Argument");
   if (flags & F_IntLit)
      fprintf(stderr, " F_IntLit");
   if (flags & F_RealLit)
      fprintf(stderr, " F_RealLit");
   if (flags & F_StrLit)
      fprintf(stderr, " F_StrLit");
   if (flags & F_CsetLit)
      fprintf(stderr, " F_CsetLit");
   if (flags & F_Field)
      fprintf(stderr, " F_Field");
   fprintf(stderr, "\n");
   }
/*
 * ldump displays local symbol table to stderr.
 */

void ldump(lhash)
struct lentry **lhash;
   {
   register int i;
   register struct lentry *lptr;

   fprintf(stderr,"   Dump of local symbol table\n");
   fprintf(stderr,"     address                 name  globol-ref  flags\n");
   for (i = 0; i < LHSize; i++)
      for (lptr = lhash[i]; lptr != NULL; lptr = lptr->blink) {
         fprintf(stderr,"    %8x %20s    ", lptr, lptr->name);
         if (lptr->flag & F_Global)
            fprintf(stderr, "%8x ", lptr->val.global);
         else
            fprintf(stderr, "       - ");
         prt_flgs(lptr->flag);
         }
   fflush(stderr);
   }

/*
 * gdump displays global symbol table to stderr.
 */

void gdump()
   {
   register int i;
   register struct gentry *gptr;

   fprintf(stderr,"\n");
   fprintf(stderr,"Dump of global symbol table\n");
   fprintf(stderr,"  address                 name  nargs  flags\n");
   for (i = 0; i < GHSize; i++)
      for (gptr = ghash[i]; gptr != NULL; gptr = gptr->blink) {
         fprintf(stderr," %8x %20s   %4d ", gptr,
		gptr->name, gptr->nargs);
         prt_flgs(gptr->flag);
         }
   fflush(stderr);
   }

/*
 * cdump displays constant symbol table to stderr.
 */

void cdump()
   {
   register int i;
   register struct centry *cptr;

   fprintf(stderr,"\n");
   fprintf(stderr,"Dump of constant symbol table\n");
   fprintf(stderr,
      "  address  value                                      flags\n");
   for (i = 0; i < CHSize; i++)
      for (cptr = chash[i]; cptr != NULL; cptr = cptr->blink) {
         fprintf(stderr," %8x  %-40.40s  ", cptr, cptr->image);
         prt_flgs(cptr->flag);
         }
   fflush(stderr);
   }

/*
 * fdump displays field symbol table to stderr.
 */
void fdump()
   {
   int i;
   struct par_rec *prptr;
   struct fentry *fp;

   fprintf(stderr,"\n");
   fprintf(stderr,"Dump of field symbol table\n");
   fprintf(stderr,
      "  address                field  global-ref  offset\n");
   for (i = 0; i < FHSize; i++)
      for (fp = fhash[i]; fp != NULL; fp = fp->blink) {
         fprintf(stderr," %8x %20s\n", fp, fp->name);
         for (prptr = fp->rlist; prptr != NULL; prptr = prptr->next)
            fprintf(stderr,"                                  %8x    %4d\n",
               prptr->sym_entry, prptr->offset);
         }
   fflush(stderr);
   }

/*
 * prt_flds - print a list of fields stored in reverse order.
 */
static void prt_flds(f)
struct fldname *f;
   {
   if (f == NULL)
     return;
   prt_flds(f->next);
   fprintf(stderr, "  %s", f->name);
   }

/*
 * rdump displays list of records and their fields.
 */
void rdump()
   {
   struct rentry *rp;

   fprintf(stderr,"\n");
   fprintf(stderr,"Dump of record list\n");
   fprintf(stderr, " global-ref   fields\n");
   for (rp = rec_lst; rp != NULL; rp = rp->next) {
      fprintf(stderr, "   %8x ", rp->sym_entry);
      prt_flds(rp->fields);
      fprintf(stderr, "\n");
      }
   }
#endif					/* DeBug */

/*
 * alcloc allocates a local symbol table entry, fills in fields with
 *  specified values and returns pointer to new entry.  
 */
static struct lentry *alcloc(blink, name, flag)
struct lentry *blink;
char *name;
int flag;
   {
   register struct lentry *lp;

   lp = NewStruct(lentry);
   lp->blink = blink;
   lp->name = name;
   lp->flag = flag;
   return lp;
   }

/*
 * alcfld allocates a field symbol table entry, fills in the entry with
 *  specified values and returns pointer to new entry.  
 */
static struct fentry *alcfld(blink, name, rp)
struct fentry *blink;
char *name;
struct par_rec *rp;
   {
   register struct fentry *fp;

   fp = NewStruct(fentry);
   fp->blink = blink;
   fp->name = name;
   fp->rlist = rp;
   return fp;
   }

/*
 * alcglob allocates a global symbol table entry, fills in fields with
 *  specified values and returns pointer to new entry.  
 */
static struct gentry *alcglob(blink, name, flag)
struct gentry *blink;
char *name;
int flag;
   {
   register struct gentry *gp;

   gp = NewStruct(gentry);
   gp->blink = blink;
   gp->name = name;
   gp->flag = flag;
   return gp;
   }

/*
 * alclit allocates a constant symbol table entry, fills in fields with
 *  specified values and returns pointer to new entry.  
 */
static struct centry *alclit(blink, image, len, flag)
struct centry *blink;
char *image;
int len, flag;
   {
   register struct centry *cp;

   cp = NewStruct(centry);
   cp->blink = blink;
   cp->image = image;
   cp->length = len;
   cp->flag = flag;
   switch (flag) {
      case F_IntLit:
         cp->u.intgr = iconint(image);
         break;
      case F_CsetLit:
         cp->u.cset = bitvect(image, len);
         break;
      }
   return cp;
   }

/*
 * alcprec allocates an entry for the parent record list for a field.
 */
static struct par_rec *alcprec(rec, offset, next)
struct rentry *rec;
int offset;
struct par_rec *next;
   {
   register struct par_rec *rp;

   rp = NewStruct(par_rec);
   rp->rec= rec;
   rp->offset = offset;
   rp->next = next;
   return rp;
   }

/*
 * resolve - resolve the scope of undeclared identifiers.
 */
void resolve(proc)
struct pentry *proc;
   {
   struct lentry **lhash;
   register struct lentry *lp;
   struct gentry *gp;
   int i;
   char *id;

   lhash = proc->lhash;

   for (i = 0; i < LHSize; ++i) {
      lp = lhash[i];
      while (lp != NULL) {
         id = lp->name;
         if (lp->flag == 0) {				/* undeclared */
            if ((gp = try_gbl(id)) != NULL) {		/* check global */
               lp->flag = F_Global;
               lp->val.global = gp;
               }
            else {					/* implicit local */
               if (uwarn) {
                  fprintf(stderr, "%s undeclared identifier, procedure %s\n",
                     id, proc->name);
                  ++twarns;
                  }
               lp->flag = F_Dynamic;
               lp->next = proc->dynams;
               proc->dynams = lp;
               ++proc->ndynam;
               }
            }
         lp = lp->blink;
         }
      }
   }

/*
 * try_glb - see if the identifier is or should be a global variable.
 */
static struct gentry *try_gbl(id)
char *id;
   {
   struct gentry *gp;
   register struct implement *iptr;
   int nargs;
   int n;

   gp = glookup(id);
   if (gp == NULL) {
      /*
       * See if it is a built-in function.
       */
      iptr = db_ilkup(id, bhash);
      if (iptr == NULL)
         return NULL;
      else {
        if (iptr->in_line == NULL)
           nfatal(NULL, "built-in function not installed", id);
         nargs = iptr->nargs;
         if (nargs > 0 && iptr->arg_flgs[nargs - 1] & VarPrm)
            nargs = -nargs;
         gp = putglob(id, F_Global | F_Builtin);
         gp->val.builtin = iptr;

         n = n_arg_sym(iptr);
         if (n > max_sym)
            max_sym = n;
         }
      }
   return gp;
   }

/*
 * invoc_grp - called when "invocable all" is encountered.
 */
void invoc_grp(grp)
char *grp;
   {
   if (grp == spec_str("all"))
      str_inv = 1; /* enable full string invocation */
   else
      tfatal("invalid operand to invocable", grp);
   }

/*
 * invocbl - indicate that the operator is needed for for string invocation.
 */
void invocbl(op, arity)
nodeptr op;
int arity;
   {
   struct strinv *si;
   
   si = NewStruct(strinv);
   si->op = op;
   si->arity = arity;
   si->next = strinvlst;
   strinvlst = si;  
   }

/*
 * chkstrinv - check to see what is needed for string invocation.
 */
void chkstrinv()
   {
   struct strinv *si;
   struct gentry *gp;
   struct implement *ip;
   char *op_name;
   int arity;
   int i;

   /*
    * A table of procedure blocks for operators is set up for use by
    *  string invocation.
    */
   op_tbl_sz = 0;
   fprintf(codefile, "\nstatic B_IProc(2) init_op_tbl[OpTblSz]");

   if (str_inv) {
      /*
       * All operations must be available for string invocation. Make sure all
       *  built-in functions have either been hidden by global declarations
       *  or are in global variables, make sure no global variables are
       *  optimized away, and make sure all operations are in the table of
       *  operations.
       */
      for (i = 0; i < IHSize; ++i)  /* built-in function table */
         for (ip = bhash[i]; ip != NULL; ip = ip->blink)
            try_gbl(ip->name);
      for (i = 0; i < GHSize; i++)  /* global symbol table */
         for (gp = ghash[i]; gp != NULL; gp = gp->blink)
            gp->flag |= F_StrInv;
      for (i = 0; i < IHSize; ++i)  /* operator table */
         for (ip = ohash[i]; ip != NULL; ip = ip->blink)
            opstrinv(ip);
      }
   else {
      /*
       * selected operations must be available for string invocation.
       */
      for (si = strinvlst; si != NULL; si = si->next) {
         op_name = Str0(si->op);
         if (isalpha(*op_name) || (*op_name == '_')) {
             /*
              * This needs to be something in a global variable: function,
              *  procedure, or constructor.
              */
             gp = try_gbl(op_name);
             if (gp == NULL)
                nfatal(si->op, "not available for string invocation", op_name);
             else
                gp->flag |= F_StrInv;
             }
         else {
             /*
              * must be an operator.
              */
             arity = si->arity;
             i = IHasher(op_name);
             for (ip = ohash[i]; ip != NULL && ip->op != op_name;
                 ip = ip->blink)
                 ;
             if (arity < 0) {
                /*
                 * Operators of all arities with this symbol.
                 */
                while (ip != NULL && ip->op == op_name) {
                   opstrinv(ip);
                   ip = ip->blink;
                   }
                }
             else {
                /*
                 * Operator of a specific arity.
                 */
                while (ip != NULL && ip->nargs != arity)
                   ip = ip->blink;
                if (ip == NULL || ip->op != op_name)
                   nfatal(si->op, "not available for string invocation",
                      op_name);
                else
                   opstrinv(ip);
                }
             }
         }
      }

   /*
    * Add definitions to the header file indicating the size of the operator
    *  table and finish the declaration in the code file.
    */
   if (op_tbl_sz == 0) {
      fprintf(inclfile, "#define OpTblSz 1\n");
      fprintf(inclfile, "int op_tbl_sz = 0;\n");
      fprintf(codefile, ";\n");
      }
   else {
      fprintf(inclfile, "#define OpTblSz %d\n", op_tbl_sz);
      fprintf(inclfile, "int op_tbl_sz = OpTblSz;\n");
      fprintf(codefile, "\n   };\n");
      }
   }

/*
 * opstrinv - set up string invocation for an operator.
 */
static void opstrinv(ip)
struct implement *ip;
   {
   char c1, c2;
   char *name;
   char *op;
   register char *s;
   int nargs;
   int n;

   if (ip == NULL || ip->iconc_flgs & InStrTbl) 
      return;

   /*
    * Keep track of the maximum number of argument symbols in any operation
    *  so type inference can allocate enough storage for the worst case of
    *  general invocation.
    */
   n = n_arg_sym(ip);
   if (n > max_sym)
      max_sym = n;

   name = ip->name;
   c1 = ip->prefix[0];
   c2 = ip->prefix[1];
   op = ip->op;
   nargs = ip->nargs;
   if (ip->arg_flgs[nargs - 1] & VarPrm)
      nargs = -nargs;   /* indicate varargs with negative number of params */

   if (op_tbl_sz++ == 0) {
       fprintf(inclfile, "\n");
       fprintf(codefile, " = {\n");
       }
   else
       fprintf(codefile, ",\n");
   implproto(ip);   /* output prototype */

   /*
    * Output procedure block for this operator into table used by string
    *  invocation.
    */
   fprintf(codefile, "   {T_Proc, 11, O%c%c_%s, %d, -1, 0, 0, {{%d, \"", c1, c2,
      name, nargs, strlen(op));
   for (s = op; *s != '\0'; ++s) {
      if (*s == '\\')
         fprintf(codefile, "\\");
      fprintf(codefile, "%c", *s);
      }
   fprintf(codefile, "\"}}}");
   ip->iconc_flgs |= InStrTbl;
   }

/*
 * n_arg_sym - determine the number of argument symbols (dereferenced
 *  and undereferenced arguments are separate symbols) for an operation
 *  in the data base.
 */
int n_arg_sym(ip)
struct implement *ip;
   {
   int i;
   int num;

   num = 0;
   for (i = 0; i < ip->nargs; ++i) {
      if (ip->arg_flgs[i] & RtParm)
         ++num;
      if (ip->arg_flgs[i] & DrfPrm)
         ++num;
      }
   return num;
   }