1 /* @(#)rpc_parse.c 1.1 87/11/04 3.9 RPCSRC */
3 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
4 * unrestricted use provided that this legend is included on all tape
5 * media and as a part of the software program in whole or part. Users
6 * may copy or modify Sun RPC without charge, but are not authorized
7 * to license or distribute it to anyone else except as part of a product or
8 * program developed by the user.
10 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
11 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
12 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 * Sun RPC is provided with no support and without any obligation on the
15 * part of Sun Microsystems, Inc. to assist in its use, correction,
16 * modification or enhancement.
18 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
19 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
20 * OR ANY PART THEREOF.
22 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
23 * or profits or other special, indirect and consequential damages, even if
24 * Sun has been advised of the possibility of such damages.
26 * Sun Microsystems, Inc.
28 * Mountain View, California 94043
32 * rpc_parse.c, Parser for the RPC protocol compiler
33 * Copyright (C) 1987 Sun Microsystems, Inc.
35 #include <afsconfig.h>
36 #include <afs/param.h>
43 #include "rpc_parse.h"
46 list *proc_defined[MAX_PACKAGES], *special_defined, *typedef_defined,
47 *uniondef_defined, *complex_defined;
48 char *SplitStart = NULL;
49 char *SplitEnd = NULL;
50 char *MasterPrefix = NULL;
51 char *ServerPrefix = "";
52 char *PackagePrefix[MAX_PACKAGES];
53 char *PackageStatIndex[MAX_PACKAGES];
54 int no_of_stat_funcs = 0; /*
55 * current function number in client interface
58 int no_of_stat_funcs_header[MAX_PACKAGES]; /*
59 * Total number of functions in client
62 int no_of_opcodes[MAX_PACKAGES], master_no_of_opcodes = 0;
63 int lowest_opcode[MAX_PACKAGES], master_lowest_opcode = 99999;
64 int highest_opcode[MAX_PACKAGES], master_highest_opcode = 0;
65 int master_opcodenumber = 99999;
66 int opcodesnotallowed[MAX_PACKAGES];
67 int combinepackages = 0;
68 int PackageIndex = -1;
69 int PerProcCounter = 0;
74 * Character arrays to keep list of function names as we process the file
77 char function_list[MAX_PACKAGES]
78 [MAX_FUNCTIONS_PER_PACKAGE]
79 [MAX_FUNCTION_NAME_LEN];
80 int function_list_index;
82 /* static prototypes */
83 static void isdefined(definition * defp);
84 static void def_struct(definition * defp);
85 static void def_program(definition * defp);
86 static void def_enum(definition * defp);
87 static void def_const(definition * defp);
88 static void def_union(definition * defp);
89 static void def_typedef(definition * defp);
90 static void get_declaration(declaration * dec, defkind dkind);
91 static void get_type(char **prefixp, char **typep, defkind dkind);
92 static void unsigned_dec(char **typep);
93 static void def_package(definition * defp);
94 static void def_prefix(definition * defp);
95 static void def_statindex(definition * defp);
96 static void def_startingopcode(definition * defp);
97 static void def_split(definition * defp);
98 static void customize_struct(definition * defp);
99 static char *structname(char *name);
100 static void def_special(declaration * dec, definition * defp);
101 static void check_proc(definition * defp, token * tokp, int noname);
102 static int InvalidConstant(char *name);
103 static int opcodenum_is_defined(int opcode_num);
104 static void analyze_ProcParams(definition * defp, token * tokp);
105 static void generate_code(definition * defp, int proc_split_flag,
107 static void handle_split_proc(definition * defp, int multi_flag);
108 static void do_split(definition * defp, int direction, int *numofparams,
109 defkind param_kind, int restore_flag);
110 static void hdle_param_tok(definition * defp, declaration * dec, token * tokp,
112 static void get1_param_type(definition * defp, declaration * dec,
114 static void get_param_type(definition * defp, declaration * dec,
115 char **param_type, char **typename);
117 static void hndle_param_tail(definition * defp, declaration * dec,
118 token * tokp, char *typename);
120 static void cs_Proc_CodeGeneration(definition * defp, int split_flag,
122 static void cs_ProcName_setup(definition * defp, char *procheader,
124 static void cs_ProcParams_setup(definition * defp, int split_flag);
125 static void cs_ProcMarshallInParams_setup(definition * defp, int split_flag);
126 static void cs_ProcSendPacket_setup(definition * defp, int split_flag);
127 static void cs_ProcUnmarshallOutParams_setup(definition * defp);
128 static void cs_ProcTail_setup(definition * defp, int split_flag);
129 static void ucs_ProcName_setup(definition * defp, char *procheader,
131 static void ucs_ProcParams_setup(definition * defp, int split_flag);
132 static void ucs_ProcTail_setup(definition * defp, int split_flag);
133 static void ss_Proc_CodeGeneration(definition * defp);
134 static void ss_ProcName_setup(definition * defp);
135 static void ss_ProcParams_setup(definition * defp);
136 static void ss_ProcSpecial_setup(definition * defp);
137 static void ss_ProcUnmarshallInParams_setup(definition * defp);
138 static void ss_ProcCallRealProc_setup(definition * defp);
139 static void ss_ProcMarshallOutParams_setup(definition * defp);
140 static void ss_ProcTail_setup(definition * defp);
141 static int opcode_holes_exist(void);
142 static void er_ProcDeclExterns_setup(void);
143 static void er_ProcProcsArray_setup(void);
144 static void er_ProcMainBody_setup(void);
145 static void er_HeadofOldStyleProc_setup(void);
146 static void er_HeadofOldStyleProc_setup2(void);
147 static void er_BodyofOldStyleProc_setup(void);
148 static void er_BodyofOldStyleProc_setup2(void);
149 static void proc_er_case(definition * defp);
150 static void er_TailofOldStyleProc_setup(void);
151 static void er_TailofOldStyleProc_setup2(void);
156 * return the next definition you see
164 defp = ALLOC(definition);
165 memset(defp, 0, sizeof(definition));
201 def_special(&dec, defp);
204 case TOK_STARTINGOPCODE:
205 def_startingopcode(defp);
210 customize_struct(defp);
212 case TOK_SPLITPREFIX:
217 if (tok.kind == TOK_LPAREN) {
219 check_proc(defp, &tok, 1);
221 check_proc(defp, &tok, 0);
224 check_proc(defp, &tok, 0);
228 check_proc(defp, &tok, 1);
231 error("definition keyword expected");
233 if (!IsRxgenToken(&tok)) {
234 scan(TOK_SEMICOLON, &tok);
242 isdefined(definition * defp)
244 STOREVAL(&defined, defp);
249 def_struct(definition * defp)
257 defp->def_kind = DEF_STRUCT;
259 scan(TOK_IDENT, &tok);
260 defp->def_name = tok.str;
261 scan(TOK_LBRACE, &tok);
262 tailp = &defp->def.st.decls;
264 get_declaration(&dec, DEF_STRUCT);
265 /* If a structure contains an array, then we're going
266 * to need to be clever about freeing it */
267 if (dec.rel == REL_ARRAY) {
270 decls = ALLOC(decl_list);
273 tailp = &decls->next;
274 scan(TOK_SEMICOLON, &tok);
276 } while (tok.kind != TOK_RBRACE);
281 STOREVAL(&complex_defined, defp);
285 def_program(definition * defp)
289 version_list **vtailp;
293 defp->def_kind = DEF_PROGRAM;
294 scan(TOK_IDENT, &tok);
295 defp->def_name = tok.str;
296 scan(TOK_LBRACE, &tok);
297 vtailp = &defp->def.pr.versions;
298 scan(TOK_VERSION, &tok);
300 scan(TOK_IDENT, &tok);
301 vlist = ALLOC(version_list);
302 vlist->vers_name = tok.str;
303 scan(TOK_LBRACE, &tok);
304 ptailp = &vlist->procs;
306 plist = ALLOC(proc_list);
307 get_type(&plist->res_prefix, &plist->res_type, DEF_PROGRAM);
308 if (streq(plist->res_type, "opaque")) {
309 error("illegal result type");
311 scan(TOK_IDENT, &tok);
312 plist->proc_name = tok.str;
313 scan(TOK_LPAREN, &tok);
314 get_type(&plist->arg_prefix, &plist->arg_type, DEF_PROGRAM);
315 if (streq(plist->arg_type, "opaque")) {
316 error("illegal argument type");
318 scan(TOK_RPAREN, &tok);
319 scan(TOK_EQUAL, &tok);
321 scan(TOK_SEMICOLON, &tok);
322 plist->proc_num = tok.str;
324 ptailp = &plist->next;
326 } while (tok.kind != TOK_RBRACE);
328 vtailp = &vlist->next;
329 scan(TOK_RBRACE, &tok);
330 scan(TOK_EQUAL, &tok);
332 vlist->vers_num = tok.str;
333 scan(TOK_SEMICOLON, &tok);
334 scan2(TOK_VERSION, TOK_RBRACE, &tok);
335 } while (tok.kind == TOK_VERSION);
336 scan(TOK_EQUAL, &tok);
338 defp->def.pr.prog_num = tok.str;
343 def_enum(definition * defp)
347 enumval_list **tailp;
349 defp->def_kind = DEF_ENUM;
350 scan(TOK_IDENT, &tok);
351 defp->def_name = tok.str;
352 scan(TOK_LBRACE, &tok);
353 tailp = &defp->def.en.vals;
355 scan(TOK_IDENT, &tok);
356 elist = ALLOC(enumval_list);
357 elist->name = tok.str;
358 elist->assignment = NULL;
359 scan3(TOK_COMMA, TOK_RBRACE, TOK_EQUAL, &tok);
360 if (tok.kind == TOK_EQUAL) {
362 elist->assignment = tok.str;
363 scan2(TOK_COMMA, TOK_RBRACE, &tok);
366 tailp = &elist->next;
367 } while (tok.kind != TOK_RBRACE);
372 def_const(definition * defp)
376 defp->def_kind = DEF_CONST;
377 scan(TOK_IDENT, &tok);
378 defp->def_name = tok.str;
379 scan(TOK_EQUAL, &tok);
380 scan2(TOK_IDENT, TOK_STRCONST, &tok);
381 defp->def.co = tok.str;
385 def_union(definition * defp)
392 defp->def_kind = DEF_UNION;
393 scan(TOK_IDENT, &tok);
394 defp->def_name = tok.str;
395 scan(TOK_SWITCH, &tok);
396 scan(TOK_LPAREN, &tok);
397 get_declaration(&dec, DEF_UNION);
398 defp->def.un.enum_decl = dec;
399 tailp = &defp->def.un.cases;
400 scan(TOK_RPAREN, &tok);
401 scan(TOK_LBRACE, &tok);
402 scan(TOK_CASE, &tok);
403 while (tok.kind == TOK_CASE) {
404 scan(TOK_IDENT, &tok);
405 cases = ALLOC(case_list);
406 cases->case_name = tok.str;
407 scan(TOK_COLON, &tok);
408 get_declaration(&dec, DEF_UNION);
409 cases->case_decl = dec;
411 tailp = &cases->next;
412 scan(TOK_SEMICOLON, &tok);
413 scan3(TOK_CASE, TOK_DEFAULT, TOK_RBRACE, &tok);
416 if (tok.kind == TOK_DEFAULT) {
417 scan(TOK_COLON, &tok);
418 get_declaration(&dec, DEF_UNION);
419 defp->def.un.default_decl = ALLOC(declaration);
420 *defp->def.un.default_decl = dec;
421 scan(TOK_SEMICOLON, &tok);
422 scan(TOK_RBRACE, &tok);
424 defp->def.un.default_decl = NULL;
430 def_typedef(definition * defp)
434 memset(&dec, 0, sizeof(dec));
436 defp->def_kind = DEF_TYPEDEF;
437 get_declaration(&dec, DEF_TYPEDEF);
438 defp->def_name = dec.name;
439 defp->def.ty.old_prefix = dec.prefix;
440 defp->def.ty.old_type = dec.type;
441 defp->def.ty.rel = dec.rel;
442 defp->def.ty.array_max = dec.array_max;
447 get_declaration(declaration * dec, defkind dkind)
451 get_type(&dec->prefix, &dec->type, dkind);
452 dec->rel = REL_ALIAS;
453 if (streq(dec->type, "void")) {
456 scan2(TOK_STAR, TOK_IDENT, &tok);
457 if (tok.kind == TOK_STAR) {
458 dec->rel = REL_POINTER;
459 scan(TOK_IDENT, &tok);
462 if (peekscan(TOK_LBRACKET, &tok)) {
463 if (dec->rel == REL_POINTER) {
464 error("no array-of-pointer declarations -- use typedef");
466 dec->rel = REL_VECTOR;
468 dec->array_max = tok.str;
469 scan(TOK_RBRACKET, &tok);
470 } else if (peekscan(TOK_LANGLE, &tok)) {
471 if (dec->rel == REL_POINTER) {
472 error("no array-of-pointer declarations -- use typedef");
474 dec->rel = REL_ARRAY;
475 if (peekscan(TOK_RANGLE, &tok)) {
476 dec->array_max = "~0u"; /* unspecified size, use max */
479 dec->array_max = tok.str;
480 scan(TOK_RANGLE, &tok);
483 if (streq(dec->type, "opaque")) {
484 if (dec->rel != REL_ARRAY && dec->rel != REL_VECTOR) {
485 error("array declaration expected");
487 } else if (streq(dec->type, "string")) {
488 if (dec->rel != REL_ARRAY) {
489 error(" variable-length array declaration expected");
496 get_type(char **prefixp, char **typep, defkind dkind)
510 scan(TOK_IDENT, &tok);
518 (void)peekscan(TOK_INT, &tok);
521 *typep = "afs_int32";
522 (void)peekscan(TOK_INT, &tok);
525 if (dkind != DEF_UNION && dkind != DEF_PROGRAM) {
526 error("voids allowed only inside union and program definitions");
541 error("expected type specifier");
547 unsigned_dec(char **typep)
560 (void)peekscan(TOK_INT, &tok);
564 *typep = "afs_uint32";
565 (void)peekscan(TOK_INT, &tok);
579 def_package(definition * defp)
583 defp->def_kind = DEF_PACKAGE;
584 scan(TOK_IDENT, &tok);
585 defp->def_name = tok.str;
586 no_of_stat_funcs = 0;
589 if (PackageIndex >= MAX_PACKAGES)
590 error("Exceeded upper limit of package statements\n");
592 function_list_index = 0;
593 PackagePrefix[PackageIndex] = tok.str;
594 if (MasterPrefix == NULL)
595 MasterPrefix = tok.str;
596 no_of_opcodes[PackageIndex] = highest_opcode[PackageIndex] =
597 opcodesnotallowed[PackageIndex] = 0;
598 lowest_opcode[PackageIndex] = 99999;
599 proc_defined[PackageIndex] = NULL;
600 PackageStatIndex[PackageIndex] = NULL;
604 def_prefix(definition * defp)
608 defp->def_kind = DEF_PREFIX;
609 scan(TOK_IDENT, &tok);
610 defp->def_name = tok.str;
611 ServerPrefix = tok.str;
615 def_statindex(definition * defp)
620 defp->def_kind = DEF_CONST;
622 if (PackageIndex < 0)
623 error("'statindex' command must follow 'package' command!\n");
624 if (PackageStatIndex[PackageIndex])
625 error("Cannot have more then one 'statindex' per package!\n");
626 if (InvalidConstant(tok.str))
627 error("Index in 'statindex' command must be a constant!");
629 alloc(strlen(PackagePrefix[PackageIndex]) + strlen("STATINDEX") + 1);
630 strcpy(name, PackagePrefix[PackageIndex]);
631 strcat(name, "STATINDEX");
632 defp->def_name = name;
633 defp->def.co = tok.str;
634 PackageStatIndex[PackageIndex] = name;
635 StatIndex = atoi(tok.str);
639 def_startingopcode(definition * defp)
643 defp->def_kind = DEF_STARTINGOPCODE;
644 scan(TOK_IDENT, &tok);
645 defp->def_name = tok.str;
646 if (InvalidConstant(defp->def_name))
647 error("Opcode in 'startingopcode' command must be a constant!");
648 lowest_opcode[PackageIndex] = master_lowest_opcode = atoi(tok.str);
649 if (lowest_opcode[PackageIndex] < 0
650 || lowest_opcode[PackageIndex] > 99999)
652 ("startingopcode number is out of bounds (must be >= 0 < 100000)");
653 master_opcodenumber = lowest_opcode[PackageIndex];
654 opcodesnotallowed[PackageIndex] = 1;
658 def_split(definition * defp)
662 defp->def_kind = DEF_SPLITPREFIX;
667 scan(TOK_EQUAL, &tok);
668 scan(TOK_IDENT, &tok);
669 SplitStart = tok.str;
672 scan(TOK_EQUAL, &tok);
673 scan(TOK_IDENT, &tok);
679 error("syntax error in the 'splitprefix' line");
681 } while (tok.kind != TOK_SEMICOLON);
682 if (!SplitStart && !SplitEnd)
683 error("At least one param should be passed to 'splitprefix' cmd");
688 customize_struct(definition * defp)
692 definition *defp1 = ALLOC(definition);
693 spec_list *specs, **tailp;
695 defp->def_kind = DEF_CUSTOMIZED;
696 defp1->def_kind = DEF_SPECIAL;
697 tailp = &defp1->def.sd.specs;
698 for (listp = defp->def.st.decls; listp; listp = listp->next) {
700 if (streq(dec->type, "string") || (dec->rel == REL_POINTER)) {
701 specs = ALLOC(spec_list);
702 specs->sdef.string_name = dec->name;
703 specs->sdef.string_value = defp->def_name;
705 tailp = &specs->next;
709 STOREVAL(&special_defined, defp1);
713 structname(char *name)
715 static char namecontents[150];
718 strcpy(namecontents, name);
720 if (!strncmp(pnt, "struct", 6))
722 while (isspace(*pnt))
725 while (*pnt != ' ' && *pnt != '\0')
733 def_special(declaration * dec, definition * defp)
736 spec_list *specs, **tailp;
739 defp->def_kind = DEF_SPECIAL;
740 get_type(&dec->prefix, &dec->type, DEF_SPECIAL);
741 dec->rel = REL_POINTER;
742 scan(TOK_IDENT, &tok);
743 tailp = &defp->def.sd.specs;
745 specs = ALLOC(spec_list);
746 specs->sdef.string_name = tok.str;
747 get_param_type(defp, dec, &specs->sdef.string_value, &typename);
749 tailp = &specs->next;
750 scan2(TOK_COMMA, TOK_SEMICOLON, &tok);
751 if (tok.kind == TOK_SEMICOLON)
754 } while (tok.kind == TOK_IDENT);
756 STOREVAL(&special_defined, defp);
760 proc1_list *Proc_list, **Proc_listp;
763 check_proc(definition * defp, token * tokp, int noname)
769 if (PackageIndex < 0)
770 error("Procedure must be in a package!\n");
772 tokp->kind = TOK_PROC;
773 defp->def_kind = DEF_PROC;
775 defp->pc.proc_name = "";
777 defp->pc.proc_name = tokp->str;
779 defp->pc.proc_prefix = alloc(strlen(PackagePrefix[PackageIndex]) + 1);
780 strcpy(defp->pc.proc_prefix, PackagePrefix[PackageIndex]);
781 scan2(TOK_LPAREN, TOK_IDENT, &tok);
782 defp->pc.proc_serverstub = NULL;
783 if (tok.kind == TOK_IDENT) {
784 defp->pc.proc_serverstub = tok.str;
785 scan(TOK_LPAREN, &tok);
787 analyze_ProcParams(defp, &tok);
788 defp->pc.proc_opcodenum = -1;
789 scan4(TOK_SPLIT, TOK_MULTI, TOK_EQUAL, TOK_SEMICOLON, &tok);
790 if (tok.kind == TOK_MULTI) {
792 defp->pc.multi_flag = 1;
793 scan2(TOK_EQUAL, TOK_SEMICOLON, &tok);
795 defp->pc.multi_flag = 0;
797 if (tok.kind == TOK_SPLIT) {
799 defp->pc.split_flag = 1;
800 scan2(TOK_EQUAL, TOK_SEMICOLON, &tok);
802 defp->pc.split_flag = 0;
804 if (tok.kind == TOK_EQUAL) {
805 if (opcodesnotallowed[PackageIndex])
806 error("Opcode assignment isn't allowed here!");
808 if (InvalidConstant(tok.str))
809 error("Illegal Opcode assignment (Must be a constant opcode!)");
810 if (opcodenum_is_defined(atoi(tok.str)))
811 error("The opcode number is already used by a previous proc");
812 defp->pc.proc_opcodename = tok.str;
813 defp->pc.proc_opcodenum = atoi(tok.str);
814 if (defp->pc.proc_opcodenum < lowest_opcode[PackageIndex])
815 lowest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
816 if (defp->pc.proc_opcodenum < master_lowest_opcode)
817 master_lowest_opcode = defp->pc.proc_opcodenum;
818 if (defp->pc.proc_opcodenum > highest_opcode[PackageIndex])
819 highest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
820 if (defp->pc.proc_opcodenum > master_highest_opcode)
821 master_highest_opcode = defp->pc.proc_opcodenum;
822 scan(TOK_SEMICOLON, &tok);
824 if (master_opcodenumber == 99999)
825 master_opcodenumber = 0;
826 defp->pc.proc_opcodenum = master_opcodenumber++;
827 if (defp->pc.proc_opcodenum < lowest_opcode[PackageIndex])
828 lowest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
829 if (defp->pc.proc_opcodenum > highest_opcode[PackageIndex])
830 highest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
831 if (defp->pc.proc_opcodenum > master_highest_opcode)
832 master_highest_opcode = defp->pc.proc_opcodenum;
833 opcodesnotallowed[PackageIndex] = 1; /* force it */
835 no_of_opcodes[PackageIndex]++, master_no_of_opcodes++;
837 generate_code(defp, 0, 1);
838 if (Cflag || cflag) {
839 generate_code(defp, 1, 1);
841 generate_multi_macros(defp);
843 generate_code(defp, proc_split, 0);
846 if (function_list_index >= MAX_FUNCTIONS_PER_INTERFACE) {
847 error("too many functions in interface, "
848 "increase MAX_FUNCTIONS_PER_INTERFACE");
850 sprintf(function_list[PackageIndex][function_list_index], "%s%s%s",
851 prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
853 function_list_index++;
854 defp->statindex = no_of_stat_funcs;
855 no_of_stat_funcs_header[PackageIndex]++;
861 #define LEGALNUMS "0123456789"
863 InvalidConstant(char *name)
869 slen = (int)strlen(name);
870 return (slen != strspn(name, map));
874 opcodenum_is_defined(int opcode_num)
879 for (listp = proc_defined[PackageIndex]; listp != NULL;
880 listp = listp->next) {
881 defp = (definition *) listp->val;
882 if (opcode_num == defp->pc.proc_opcodenum)
890 analyze_ProcParams(definition * defp, token * tokp)
893 decl_list *decls, **tailp;
895 Proc_listp = &defp->pc.plists;
896 tailp = &defp->def.st.decls;
899 Proc_list = ALLOC(proc1_list);
900 memset(Proc_list, 0, sizeof(proc1_list));
901 Proc_list->pl.param_flag = 0;
902 switch (tokp->kind) {
904 hdle_param_tok(defp, &dec, tokp, DEF_INPARAM);
907 hdle_param_tok(defp, &dec, tokp, DEF_OUTPARAM);
910 hdle_param_tok(defp, &dec, tokp, DEF_INOUTPARAM);
916 hdle_param_tok(defp, &dec, tokp, DEF_NULL);
919 *Proc_listp = Proc_list;
920 Proc_listp = &Proc_list->next;
921 decls = ALLOC(decl_list);
922 memset(decls, 0, sizeof(decl_list));
923 if (tokp->kind != TOK_RPAREN)
926 tailp = &decls->next;
927 } while (tokp->kind != TOK_RPAREN);
933 generate_code(definition * defp, int proc_split_flag, int multi_flag)
936 handle_split_proc(defp, multi_flag);
938 if (Cflag || cflag) {
939 cs_Proc_CodeGeneration(defp, 0, "");
942 ss_Proc_CodeGeneration(defp);
944 if (Sflag || (cflag && xflag && !proc_split_flag) || hflag)
945 STOREVAL(&proc_defined[PackageIndex], defp);
950 handle_split_proc(definition * defp, int multi_flag)
952 char *startname = SplitStart, *endname = SplitEnd;
959 if (Cflag || cflag) {
961 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 0);
963 cs_Proc_CodeGeneration(defp, 1, startname);
965 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 1);
966 do_split(defp, IN, &numofparams, DEF_INPARAM, 0);
968 cs_Proc_CodeGeneration(defp, (multi_flag ? 3 : 2), endname);
970 do_split(defp, IN, &numofparams, DEF_INPARAM, 1);
974 ss_Proc_CodeGeneration(defp);
979 do_split(definition * defp, int direction, int *numofparams,
980 defkind param_kind, int restore_flag)
985 defp->pc.paramtypes[direction] = *numofparams;
986 for (plist = defp->pc.plists; plist; plist = plist->next) {
987 if (plist->component_kind == DEF_NULL
988 && plist->pl.param_kind == param_kind)
989 plist->component_kind = DEF_PARAM;
992 *numofparams = defp->pc.paramtypes[direction];
993 defp->pc.paramtypes[direction] = 0;
994 for (plist = defp->pc.plists; plist; plist = plist->next) {
995 if (plist->component_kind == DEF_PARAM
996 && plist->pl.param_kind == param_kind)
997 plist->component_kind = DEF_NULL;
1004 hdle_param_tok(definition * defp, declaration * dec, token * tokp,
1007 static defkind last_param_kind = DEF_NULL;
1009 if (par_kind == DEF_NULL)
1010 Proc_list->pl.param_kind = last_param_kind;
1012 Proc_list->pl.param_kind = par_kind;
1013 last_param_kind = Proc_list->pl.param_kind;
1014 defp->pc.paramtypes[(int)last_param_kind]++;
1015 Proc_list->component_kind = DEF_PARAM;
1016 Proc_list->code = alloc(250);
1017 Proc_list->scode = alloc(250);
1018 get_declaration(dec, DEF_PARAM);
1019 Proc_list->pl.param_name = dec->name;
1020 get1_param_type(defp, dec, &Proc_list->pl.param_type);
1022 scan2(TOK_COMMA, TOK_RPAREN, tokp);
1023 if (tokp->kind == TOK_COMMA)
1029 get1_param_type(definition * defp, declaration * dec, char **param_type)
1031 char typecontents[100];
1033 if (streq(dec->type, "string")) {
1034 *param_type = "char *";
1037 strcpy(typecontents, dec->prefix);
1038 strcat(typecontents, " ");
1039 strcat(typecontents, dec->type);
1040 strcat(typecontents, " *");
1041 } else if (dec->rel == REL_POINTER) {
1042 strcpy(typecontents, dec->type);
1043 strcat(typecontents, " *");
1045 strcpy(typecontents, dec->type);
1046 *param_type = alloc(100);
1047 strcpy(*param_type, typecontents);
1053 get_param_type(definition * defp, declaration * dec, char **param_type,
1056 char typecontents[100];
1058 if (streq(dec->type, "string")) {
1059 *typename = "wrapstring";
1060 *param_type = "char *";
1062 *typename = dec->type;
1064 strcpy(typecontents, dec->prefix);
1065 strcat(typecontents, " ");
1066 strcat(typecontents, dec->type);
1067 strcat(typecontents, " *");
1068 dec->rel = REL_POINTER;
1069 } else if (dec->rel == REL_POINTER) {
1070 strcpy(typecontents, dec->type);
1071 strcat(typecontents, " *");
1073 strcpy(typecontents, dec->type);
1074 *param_type = alloc(100);
1075 strcpy(*param_type, typecontents);
1082 hndle_param_tail(definition * defp, declaration * dec, token * tokp,
1087 if (dec->rel == REL_POINTER)
1088 Proc_list->pl.param_flag |= INDIRECT_PARAM;
1090 Proc_list->pl.param_flag &= ~INDIRECT_PARAM;
1092 if (!(Proc_list->pl.param_flag & INDIRECT_PARAM))
1095 sprintf(Proc_list->code, "xdr_%s(&z_xdrs, %s%s)", typename, amp,
1096 Proc_list->pl.param_name);
1097 sprintf(Proc_list->scode, "xdr_%s(z_xdrs, &%s)", typename,
1098 Proc_list->pl.param_name);
1099 scan2(TOK_COMMA, TOK_RPAREN, tokp);
1100 if (tokp->kind == TOK_COMMA)
1107 cs_Proc_CodeGeneration(definition * defp, int split_flag, char *procheader)
1110 cs_ProcName_setup(defp, procheader, split_flag);
1112 cs_ProcParams_setup(defp, split_flag);
1113 cs_ProcMarshallInParams_setup(defp, split_flag);
1114 if (split_flag != 1) {
1115 cs_ProcSendPacket_setup(defp, split_flag);
1116 cs_ProcUnmarshallOutParams_setup(defp);
1118 cs_ProcTail_setup(defp, split_flag);
1121 if (!kflag && !split_flag && uflag) {
1122 ucs_ProcName_setup(defp, "ubik_", split_flag);
1124 ucs_ProcParams_setup(defp, split_flag);
1125 ucs_ProcTail_setup(defp, split_flag);
1131 cs_ProcName_setup(definition * defp, char *procheader, int split_flag)
1138 first_arg = "struct rx_call *z_call";
1140 first_arg = "struct rx_connection *z_conn";
1144 first_arg = "z_call";
1146 first_arg = "z_conn";
1151 f_print(fout, "int %s%s%s%s(%s", procheader, prefix,
1152 PackagePrefix[PackageIndex], defp->pc.proc_name, first_arg);
1154 if ((strlen(procheader) + strlen(prefix) +
1155 strlen(PackagePrefix[PackageIndex]) + strlen(defp->pc.proc_name)) >=
1156 MAX_FUNCTION_NAME_LEN) {
1157 error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
1160 for (plist = defp->pc.plists; plist; plist = plist->next) {
1161 if (plist->component_kind == DEF_PARAM) {
1164 if (plist->pl.param_kind == DEF_INPARAM &&
1165 strcmp(plist->pl.param_type, "char *") == 0) {
1166 f_print(fout, "const ");
1168 if (plist->pl.param_flag & OUT_STRING) {
1169 f_print(fout, "%s *%s", plist->pl.param_type,
1170 plist->pl.param_name);
1172 f_print(fout, "%s %s", plist->pl.param_type,
1173 plist->pl.param_name);
1176 f_print(fout, " %s", plist->pl.param_name);
1177 plist->pl.param_flag &= ~PROCESSED_PARAM;
1181 f_print(fout, ")\n");
1186 cs_ProcParams_setup(definition * defp, int split_flag)
1188 proc1_list *plist, *plist1;
1194 f_print(fout, "\tstruct rx_connection *z_conn;\n");
1196 f_print(fout, "\tstruct rx_call *z_call;\n");
1198 for (plist = defp->pc.plists; plist; plist = plist->next) {
1199 if (plist->component_kind == DEF_PARAM
1200 && !(plist->pl.param_flag & PROCESSED_PARAM)) {
1201 if (plist->pl.param_flag & OUT_STRING) {
1202 f_print(fout, "\t%s *%s", plist->pl.param_type,
1203 plist->pl.param_name);
1205 f_print(fout, "\t%s %s", plist->pl.param_type,
1206 plist->pl.param_name);
1208 plist->pl.param_flag |= PROCESSED_PARAM;
1209 for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
1210 if ((plist1->component_kind == DEF_PARAM)
1211 && streq(plist->pl.param_type, plist1->pl.param_type)
1212 && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
1214 char *pntr = strchr(plist1->pl.param_type, '*');
1217 if (plist1->pl.param_flag & OUT_STRING) {
1218 f_print(fout, ", *%s%s", star, plist1->pl.param_name);
1220 f_print(fout, ", %s%s", star, plist1->pl.param_name);
1222 plist1->pl.param_flag |= PROCESSED_PARAM;
1225 f_print(fout, ";\n");
1232 cs_ProcMarshallInParams_setup(definition * defp, int split_flag)
1234 int noofparams, i = 0;
1238 defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT] +
1239 defp->pc.paramtypes[OUT];
1241 f_print(fout, "{\n");
1243 f_print(fout, "\tstruct rx_call *z_call = rx_NewCall(z_conn);\n");
1244 if ((!split_flag) || (split_flag == 1)) {
1245 if (opcodesnotallowed[PackageIndex]) {
1246 f_print(fout, "\tstatic int z_op = %d;\n",
1247 defp->pc.proc_opcodenum);
1249 f_print(fout, "\tstatic int z_op = %s;\n",
1250 defp->pc.proc_opcodename);
1253 f_print(fout, "\tint z_result;\n");
1254 if (!(split_flag > 1) || (noofallparams != 0)) {
1255 f_print(fout, "\tXDR z_xdrs;\n");
1258 if ((!split_flag) || (split_flag == 1)) {
1259 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_ENCODE);\n");
1260 f_print(fout, "\n\t/* Marshal the arguments */\n");
1261 f_print(fout, "\tif ((!xdr_int(&z_xdrs, &z_op))");
1262 noofparams = defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT];
1263 for (plist = defp->pc.plists, dl = defp->def.st.decls; plist;
1264 plist = plist->next, dl = dl->next) {
1265 if (plist->component_kind == DEF_PARAM
1266 && (plist->pl.param_kind == DEF_INPARAM
1267 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1268 f_print(fout, "\n\t || (!%s)", plist->code);
1269 if (++i == noofparams) {
1271 ") {\n\t\tz_result = RXGEN_CC_MARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1278 ") {\n\t\tz_result = RXGEN_CC_MARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1286 cs_ProcSendPacket_setup(definition * defp, int split_flag)
1288 int noofoutparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1290 if (noofoutparams) {
1291 f_print(fout, "\t/* Un-marshal the reply arguments */\n");
1293 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
1295 f_print(fout, "\tz_xdrs.x_op = XDR_DECODE;\n");
1302 cs_ProcUnmarshallOutParams_setup(definition * defp)
1308 noofparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1310 for (plist = defp->pc.plists, dl = defp->def.st.decls, i = 0; plist;
1311 plist = plist->next, dl = dl->next) {
1312 if (plist->component_kind == DEF_PARAM
1313 && (plist->pl.param_kind == DEF_OUTPARAM
1314 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1316 f_print(fout, "\tif ((!%s)", plist->code);
1318 f_print(fout, "\n\t || (!%s)", plist->code);
1320 if (++i == noofparams) {
1322 ") {\n\t\tz_result = RXGEN_CC_UNMARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1331 cs_ProcTail_setup(definition * defp, int split_flag)
1333 f_print(fout, "\tz_result = RXGEN_SUCCESS;\n");
1334 if (defp->can_fail) {
1335 f_print(fout, "fail:\n");
1338 f_print(fout, "\tz_result = rx_EndCall(z_call, z_result);\n");
1340 if (xflag && split_flag != 1) {
1341 f_print(fout, "\tif (rx_enable_stats) {\n");
1342 if (PackageStatIndex[PackageIndex]) {
1344 "\t rx_RecordCallStatistics(z_call, %s,\n",
1345 PackageStatIndex[PackageIndex]);
1348 "\t rx_RecordCallStatistics(z_call, \n"
1349 "\t\t(((afs_uint32)(ntohs(rx_ServiceIdOf(rx_ConnectionOf(z_call))) << 16)) |\n"
1350 "\t\t((afs_uint32)ntohs(rx_PortOf(rx_PeerOf(rx_ConnectionOf(z_call)))))),\n");
1352 f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, 1);\n",
1353 no_of_stat_funcs, PackagePrefix[PackageIndex]);
1354 f_print(fout, "\t}\n\n");
1356 f_print(fout, "\treturn z_result;\n}\n\n");
1361 ss_Proc_CodeGeneration(definition * defp)
1364 ss_ProcName_setup(defp);
1366 ss_ProcParams_setup(defp);
1367 ss_ProcSpecial_setup(defp);
1368 ss_ProcUnmarshallInParams_setup(defp);
1369 ss_ProcCallRealProc_setup(defp);
1370 ss_ProcMarshallOutParams_setup(defp);
1371 ss_ProcTail_setup(defp);
1377 ss_ProcName_setup(definition * defp)
1381 if ((strlen(prefix) + strlen(PackagePrefix[PackageIndex]) +
1382 strlen(defp->pc.proc_name)) >= MAX_FUNCTION_NAME_LEN) {
1383 error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
1387 f_print(fout, "static afs_int32 _%s%s%s(", prefix,
1388 PackagePrefix[PackageIndex], defp->pc.proc_name);
1389 f_print(fout, "struct rx_call *z_call, XDR *z_xdrs)\n{\n");
1390 f_print(fout, "\t" "afs_int32 z_result;\n");
1392 for (plist = defp->pc.plists; plist; plist = plist->next)
1393 if (plist->component_kind == DEF_PARAM) {
1394 plist->pl.param_flag &= ~(PROCESSED_PARAM);
1395 plist->pl.string_name = NULL;
1402 ss_ProcParams_setup(definition * defp)
1404 proc1_list *plist, *plist1;
1408 for (plist = defp->pc.plists; plist; plist = plist->next) {
1409 if ((plist->component_kind == DEF_PARAM)
1410 && !(plist->pl.param_flag & PROCESSED_PARAM)) {
1411 if (plist->pl.param_flag & INDIRECT_PARAM) {
1412 char pres = '\0', *pntr = strchr(plist->pl.param_type, '*');
1418 f_print(fout, "\t%s %s", plist->pl.param_type,
1419 plist->pl.param_name);
1422 } else if (strchr(plist->pl.param_type, '*') == 0) {
1423 f_print(fout, "\t%s %s", plist->pl.param_type,
1424 plist->pl.param_name);
1426 plist->pl.param_flag |= FREETHIS_PARAM;
1427 f_print(fout, "\t%s %s=(%s)0", plist->pl.param_type,
1428 plist->pl.param_name, plist->pl.param_type);
1430 plist->pl.param_flag |= PROCESSED_PARAM;
1431 for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
1432 if ((plist1->component_kind == DEF_PARAM)
1433 && streq(plist->pl.param_type, plist1->pl.param_type)
1434 && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
1435 if (plist1->pl.param_flag & INDIRECT_PARAM) {
1436 f_print(fout, ", %s", plist1->pl.param_name);
1437 } else if (strchr(plist1->pl.param_type, '*') == 0) {
1438 f_print(fout, ", %s", plist1->pl.param_name);
1440 plist1->pl.param_flag |= FREETHIS_PARAM;
1441 f_print(fout, ", *%s=(%s)0", plist1->pl.param_name,
1442 plist1->pl.param_type);
1444 plist1->pl.param_flag |= PROCESSED_PARAM;
1447 f_print(fout, ";\n");
1450 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1451 defp1 = (definition *) listp->val;
1452 for (plist = defp->pc.plists; plist; plist = plist->next) {
1453 if (plist->component_kind == DEF_PARAM
1454 && (plist->pl.param_kind == DEF_OUTPARAM
1455 || plist->pl.param_kind == DEF_INOUTPARAM)
1456 && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1457 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1458 switch (defp1->pc.rel) {
1468 fprintf(fout, "\n");
1473 ss_ProcSpecial_setup(definition * defp)
1479 for (listp = special_defined; listp != NULL; listp = listp->next) {
1480 defp1 = (definition *) listp->val;
1482 for (plist = defp->pc.plists; plist; plist = plist->next) {
1483 if (plist->component_kind == DEF_PARAM
1484 && (plist->pl.param_kind == DEF_INPARAM
1485 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1486 spec_list *spec = defp1->def.sd.specs;
1488 strcpy(string, structname(spec->sdef.string_value));
1489 if (streq(string, structname(plist->pl.param_type))) {
1490 plist->pl.string_name = spec->sdef.string_name;
1491 plist->pl.param_flag |= FREETHIS_PARAM;
1492 fprintf(fout, "\n\t%s.%s = 0;", plist->pl.param_name,
1493 spec->sdef.string_name);
1498 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1499 defp1 = (definition *) listp->val;
1500 for (plist = defp->pc.plists; plist; plist = plist->next) {
1501 if (plist->component_kind == DEF_PARAM) {
1502 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1503 plist->pl.param_flag |= FREETHIS_PARAM;
1504 switch (defp1->pc.rel) {
1506 plist->pl.string_name = alloc(40);
1508 f_print(fout, "\n\t%s.val = 0;",
1509 plist->pl.param_name);
1510 f_print(fout, "\n\t%s.len = 0;",
1511 plist->pl.param_name);
1512 s_print(plist->pl.string_name, "val");
1514 f_print(fout, "\n\t%s.%s_val = 0;",
1515 plist->pl.param_name, defp1->def_name);
1516 f_print(fout, "\n\t%s.%s_len = 0;",
1517 plist->pl.param_name, defp1->def_name);
1518 s_print(plist->pl.string_name, "%s_val",
1523 f_print(fout, "\n\t%s = 0;", plist->pl.param_name);
1524 plist->pl.string_name = NULL;
1533 for (listp = complex_defined; listp != NULL; listp = listp->next) {
1534 defp1 = (definition *) listp->val;
1535 for (plist = defp->pc.plists; plist; plist = plist->next) {
1536 if (plist->component_kind == DEF_PARAM) {
1537 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1538 plist->pl.param_flag |= FREETHIS_PARAM;
1539 fprintf(fout, "\n\tmemset(&%s, 0, sizeof(%s));",
1540 plist->pl.param_name, defp1->def_name);
1546 f_print(fout, "\n");
1551 ss_ProcUnmarshallInParams_setup(definition * defp)
1553 int noofparams, noofoutparams, i;
1556 noofparams = defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT];
1557 noofoutparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1558 for (plist = defp->pc.plists, i = 0; plist; plist = plist->next) {
1559 if (plist->component_kind == DEF_PARAM
1560 && (plist->pl.param_kind == DEF_INPARAM
1561 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1563 f_print(fout, "\n\tif ((!%s)",
1564 (plist->scode ? plist->scode : plist->code));
1566 f_print(fout, "\n\t || (!%s)",
1567 (plist->scode ? plist->scode : plist->code));
1569 if (++i == noofparams) {
1570 if (!noofoutparams) {
1571 f_print(fout, ") {\n");
1573 f_print(fout, ") {\n");
1576 "\t\tz_result = RXGEN_SS_UNMARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1585 ss_ProcCallRealProc_setup(definition * defp)
1590 f_print(fout, "\tz_result = %s%s%s%s(z_call", prefix, ServerPrefix,
1591 PackagePrefix[PackageIndex], defp->pc.proc_name);
1592 for (plist = defp->pc.plists; plist; plist = plist->next) {
1593 if (plist->component_kind == DEF_PARAM) {
1594 if (plist->pl.param_flag & INDIRECT_PARAM) {
1595 f_print(fout, ", &%s", plist->pl.param_name);
1597 if (plist->pl.param_flag & OUT_STRING) {
1598 f_print(fout, ", &%s", plist->pl.param_name);
1600 f_print(fout, ", %s", plist->pl.param_name);
1605 f_print(fout, ");\n");
1607 f_print(fout, "\tif (z_result)\n\t\treturn z_result;\n");
1613 ss_ProcMarshallOutParams_setup(definition * defp)
1618 noofparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1620 f_print(fout, "\tz_xdrs->x_op = XDR_ENCODE;\n");
1622 for (plist = defp->pc.plists, i = 0; plist; plist = plist->next) {
1623 if (plist->component_kind == DEF_PARAM
1624 && (plist->pl.param_kind == DEF_OUTPARAM
1625 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1627 f_print(fout, "\tif ((!%s)",
1628 (plist->scode ? plist->scode : plist->code));
1630 f_print(fout, "\n\t || (!%s)",
1631 (plist->scode ? plist->scode : plist->code));
1633 if (++i == noofparams) {
1634 f_print(fout, ")\n\t\tz_result = RXGEN_SS_MARSHAL;\n");
1642 ss_ProcTail_frees(char *xdrfunc, int *somefrees) {
1644 f_print(fout, "\tz_xdrs->x_op = XDR_FREE;\n");
1645 f_print(fout, "\tif ((!%s)", xdrfunc);
1648 f_print(fout, "\n\t || (!%s)", xdrfunc);
1654 ss_ProcTail_setup(definition * defp)
1661 if (defp->can_fail) {
1662 f_print(fout, "fail:\n");
1665 for (plist = defp->pc.plists; plist; plist = plist->next) {
1666 if (plist->component_kind == DEF_PARAM
1667 && (plist->pl.param_flag & FREETHIS_PARAM))
1668 ss_ProcTail_frees(plist->scode, &somefrees);
1671 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1672 defp1 = (definition *) listp->val;
1673 for (plist = defp->pc.plists; plist; plist = plist->next) {
1674 if (plist->component_kind == DEF_PARAM
1675 && (plist->pl.param_kind == DEF_OUTPARAM
1676 || plist->pl.param_kind == DEF_INOUTPARAM)
1677 && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1678 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1679 switch (defp1->pc.rel) {
1682 ss_ProcTail_frees(plist->scode, &somefrees);
1692 for (listp = uniondef_defined; listp != NULL; listp = listp->next) {
1693 defp1 = (definition *) listp->val;
1694 for (plist = defp->pc.plists; plist; plist = plist->next) {
1695 if (plist->component_kind == DEF_PARAM
1696 && (plist->pl.param_kind == DEF_OUTPARAM
1697 || plist->pl.param_kind == DEF_INOUTPARAM)
1698 && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1699 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1700 if (plist->pl.param_flag & INDIRECT_PARAM) {
1701 ss_ProcTail_frees(plist->scode, &somefrees);
1709 f_print(fout, ")\n");
1710 f_print(fout, "\t\tz_result = RXGEN_SS_XDRFREE;\n\n");
1714 f_print(fout, "\tif (rx_enable_stats) {\n");
1715 f_print(fout, "\t rx_RecordCallStatistics(z_call,");
1716 if (PackageStatIndex[PackageIndex]) {
1717 f_print(fout, " %s,\n", PackageStatIndex[PackageIndex]);
1720 "\n\t\t(((afs_uint32)(ntohs(rx_ServiceIdOf(rx_ConnectionOf(z_call))) << 16)) |\n"
1721 "\t\t((afs_uint32)ntohs(rx_ServiceOf(rx_ConnectionOf(z_call))->servicePort))),\n");
1723 f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, 0);\n",
1724 no_of_stat_funcs, PackagePrefix[PackageIndex]);
1725 f_print(fout, "\t}\n\n");
1728 f_print(fout, "\treturn z_result;\n");
1729 f_print(fout, "}\n\n");
1734 ucs_ProcName_setup(definition * defp, char *procheader, int split_flag)
1740 f_print(fout, "int %s%s%s%s(struct ubik_client *aclient, afs_int32 aflags",
1741 procheader, prefix, PackagePrefix[PackageIndex],
1742 defp->pc.proc_name);
1744 f_print(fout, "int %s%s%s%s(aclient, aflags", procheader, prefix,
1745 PackagePrefix[PackageIndex], defp->pc.proc_name);
1748 if ((strlen(procheader) + strlen(prefix) +
1749 strlen(PackagePrefix[PackageIndex]) + strlen(defp->pc.proc_name)) >=
1750 MAX_FUNCTION_NAME_LEN) {
1751 error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
1754 for (plist = defp->pc.plists; plist; plist = plist->next) {
1755 if (plist->component_kind == DEF_PARAM) {
1758 if (plist->pl.param_kind == DEF_INPARAM &&
1759 strcmp(plist->pl.param_type, "char *") == 0) {
1760 f_print(fout, "const ");
1762 if (plist->pl.param_flag & OUT_STRING) {
1763 f_print(fout, "%s *%s", plist->pl.param_type,
1764 plist->pl.param_name);
1766 f_print(fout, "%s %s", plist->pl.param_type,
1767 plist->pl.param_name);
1770 plist->pl.param_flag &= ~PROCESSED_PARAM;
1771 f_print(fout, " %s", plist->pl.param_name);
1775 f_print(fout, ")\n");
1781 ucs_ProcParams_setup(definition * defp, int split_flag)
1783 proc1_list *plist, *plist1;
1788 f_print(fout, "\tstruct ubik_client *aclient;\n\tafs_int32 aflags;\n");
1789 for (plist = defp->pc.plists; plist; plist = plist->next) {
1790 if (plist->component_kind == DEF_PARAM
1791 && !(plist->pl.param_flag & PROCESSED_PARAM)) {
1792 if (plist->pl.param_flag & OUT_STRING) {
1793 f_print(fout, "\t%s *%s", plist->pl.param_type,
1794 plist->pl.param_name);
1796 f_print(fout, "\t%s %s", plist->pl.param_type,
1797 plist->pl.param_name);
1799 plist->pl.param_flag |= PROCESSED_PARAM;
1800 for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
1801 if ((plist1->component_kind == DEF_PARAM)
1802 && streq(plist->pl.param_type, plist1->pl.param_type)
1803 && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
1805 char *pntr = strchr(plist1->pl.param_type, '*');
1808 if (plist1->pl.param_flag & OUT_STRING) {
1809 f_print(fout, ", *%s%s", star, plist1->pl.param_name);
1811 f_print(fout, ", %s%s", star, plist1->pl.param_name);
1813 plist1->pl.param_flag |= PROCESSED_PARAM;
1816 f_print(fout, ";\n");
1822 ucs_ProcTail_setup(definition * defp, int split_flag)
1826 f_print(fout, "{\tafs_int32 rcode, code, newHost, thisHost, i, _ucount;\n");
1827 f_print(fout, "\tint chaseCount, pass, needsync;\n");
1828 #if 0 /* goes with block below */
1829 f_print(fout, "\tint j, inlist;\n");
1831 f_print(fout, "\tstruct rx_connection *tc;\n");
1832 f_print(fout, "\tstruct rx_peer *rxp;\n");
1833 f_print(fout, "\tshort origLevel;\n\n");
1834 f_print(fout, "\tif (!aclient)\n");
1835 f_print(fout, "\t\treturn UNOENT;\n");
1836 f_print(fout, "\tLOCK_UBIK_CLIENT(aclient);\n\n");
1837 f_print(fout, "\t restart:\n");
1838 f_print(fout, "\torigLevel = aclient->initializationState;\n");
1839 f_print(fout, "\trcode = UNOSERVERS;\n");
1840 f_print(fout, "\tchaseCount = needsync = 0;\n\n");
1841 #if 0 /* We should do some sort of caching algorithm for this, but I need to think about it - shadow 26 jun 06 */
1842 f_print(fout, "\tinlist = 0;\n");
1843 f_print(fout, "\tLOCK_UCLNT_CACHE;\n");
1844 f_print(fout, "\tfor (j = 0; ((j < SYNCCOUNT) && calls_needsync[j]); j++) {\n");
1845 f_print(fout, "\t\tif (calls_needsync[j] == (int *)%s%s%s) {\n", prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
1846 f_print(fout, "\t\t\tinlist = needsync = 1;\n");
1847 f_print(fout, "\t\t\tbreak;\n");
1848 f_print(fout, "\t\t}\n");
1849 f_print(fout, "\t}\n");
1850 f_print(fout, "\tUNLOCK_UCLNT_CACHE;\n");
1852 f_print(fout, "\t/* \n\t* First pass, we try all servers that are up.\n\t* Second pass, we try all servers.\n\t*/\n");
1853 f_print(fout, "\tfor (pass = 0; pass < 2; pass++) { /*p */\n");
1854 f_print(fout, "\t\t/* For each entry in our servers list */\n");
1855 f_print(fout, "\t\tfor (_ucount = 0;; _ucount++) { /*s */\n\n");
1856 f_print(fout, "\t\tif (needsync) {\n");
1857 f_print(fout, "\t\t\t/* Need a sync site. Lets try to quickly find it */\n");
1858 f_print(fout, "\t\t\tif (aclient->syncSite) {\n");
1859 f_print(fout, "\t\t\t\tnewHost = aclient->syncSite; /* already in network order */\n");
1860 f_print(fout, "\t\t\t\taclient->syncSite = 0; /* Will reset if it works */\n");
1861 f_print(fout, "\t\t\t} else if (aclient->conns[3]) {\n");
1862 f_print(fout, "\t\t\t\t/* If there are fewer than four db servers in a cell,\n");
1863 f_print(fout, "\t\t\t\t* there's no point in making the GetSyncSite call.\n");
1864 f_print(fout, "\t\t\t\t* At best, it's a wash. At worst, it results in more\n");
1865 f_print(fout, "\t\t\t\t* RPCs than you would otherwise make.\n");
1866 f_print(fout, "\t\t\t\t*/\n");
1867 f_print(fout, "\t\t\t\ttc = aclient->conns[_ucount];\n");
1868 f_print(fout, "\t\t\t\tif (tc && rx_ConnError(tc)) {\n");
1869 f_print(fout, "\t\t\t\t\taclient->conns[_ucount] = tc = ubik_RefreshConn(tc);\n");
1870 f_print(fout, "\t\t\t\t}\n");
1871 f_print(fout, "\t\t\t\tif (!tc)\n");
1872 f_print(fout, "\t\t\t\t\tbreak;\n");
1873 f_print(fout, "\t\t\t\tcode = VOTE_GetSyncSite(tc, &newHost);\n");
1874 f_print(fout, "\t\t\t\tif (aclient->initializationState != origLevel)\n");
1875 f_print(fout, "\t\t\t\t\tgoto restart; /* somebody did a ubik_ClientInit */\n");
1876 f_print(fout, "\t\t\t\tif (code)\n");
1877 f_print(fout, "\t\t\t\t\tnewHost = 0;\n");
1878 f_print(fout, "\t\t\t\tnewHost = htonl(newHost); /* convert to network order */\n");
1879 f_print(fout, "\t\t\t} else {\n");
1880 f_print(fout, "\t\t\t\tnewHost = 0;\n");
1881 f_print(fout, "\t\t\t}\n");
1882 f_print(fout, "\t\t\tif (newHost) {\n");
1883 f_print(fout, "\t\t\t\t/* position count at the appropriate slot in the client\n");
1884 f_print(fout, "\t\t\t\t* structure and retry. If we can't find in slot, we'll\n");
1885 f_print(fout, "\t\t\t\t* just continue through the whole list \n");
1886 f_print(fout, "\t\t\t\t*/\n");
1887 f_print(fout, "\t\t\t\tfor (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {\n");
1888 f_print(fout, "\t\t\t\t\trxp = rx_PeerOf(aclient->conns[i]);\n");
1889 f_print(fout, "\t\t\t\t\tthisHost = rx_HostOf(rxp);\n");
1890 f_print(fout, "\t\t\t\t\tif (!thisHost)\n");
1891 f_print(fout, "\t\t\t\t\t\tbreak;\n");
1892 f_print(fout, "\t\t\t\t\tif (thisHost == newHost) {\n");
1893 f_print(fout, "\t\t\t\t\t\tif (chaseCount++ > 2)\n");
1894 f_print(fout, "\t\t\t\t\t\t\tbreak; /* avoid loop asking */\n");
1895 f_print(fout, "\t\t\t\t\t\t_ucount = i; /* this index is the sync site */\n");
1896 f_print(fout, "\t\t\t\t\t\tbreak;\n");
1897 f_print(fout, "\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n");
1898 f_print(fout, "\t\t/*needsync */\n");
1899 f_print(fout, "\t\ttc = aclient->conns[_ucount];\n");
1900 f_print(fout, "\t\tif (tc && rx_ConnError(tc)) {\n");
1901 f_print(fout, "\t\t\taclient->conns[_ucount] = tc = ubik_RefreshConn(tc);\n");
1902 f_print(fout, "\t\t}\n");
1903 f_print(fout, "\t\tif (!tc)\n");
1904 f_print(fout, "\t\t\tbreak;\n\n");
1905 f_print(fout, "\t\tif ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {\n");
1906 f_print(fout, "\t\t\tcontinue; /* this guy's down */\n");
1907 f_print(fout, "\t\t}\n");
1909 f_print(fout, "\t\trcode = %s%s%s(tc\n", prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
1910 for (plist = defp->pc.plists; plist; plist = plist->next) {
1911 if (plist->component_kind == DEF_PARAM) {
1912 plist->pl.param_flag &= ~PROCESSED_PARAM;
1913 f_print(fout, ", %s", plist->pl.param_name);
1916 f_print(fout, ");\n");
1917 f_print(fout, "\t\tif (aclient->initializationState != origLevel) {\n");
1918 f_print(fout, "\t\t\t/* somebody did a ubik_ClientInit */\n");
1919 f_print(fout, "\t\t\tif (rcode)\n");
1920 f_print(fout, "\t\t\t\tgoto restart; /* call failed */\n");
1921 f_print(fout, "\t\t\telse\n");
1922 f_print(fout, "\t\t\t\tgoto done; /* call suceeded */\n");
1923 f_print(fout, "\t\t}\n");
1924 f_print(fout, "\t\tif (rcode < 0) { /* network errors */\n");
1925 f_print(fout, "\t\t\taclient->states[_ucount] |= CFLastFailed; /* Mark server down */\n");
1926 f_print(fout, "\t\t} else if (rcode == UNOTSYNC) {\n");
1927 f_print(fout, "\t\t\tneedsync = 1;\n");
1928 f_print(fout, "\t\t} else if (rcode != UNOQUORUM) {\n");
1929 f_print(fout, "\t\t\t/* either misc ubik code, or misc appl code, or success. */\n");
1930 f_print(fout, "\t\t\taclient->states[_ucount] &= ~CFLastFailed; /* mark server up*/\n");
1931 f_print(fout, "\t\t\tgoto done; /* all done */\n");
1932 f_print(fout, "\t\t}\n");
1933 f_print(fout, "\t\t} /*s */\n");
1934 f_print(fout, "\t} /*p */\n\n");
1935 f_print(fout, "\tdone:\n");
1936 f_print(fout, "\tif (needsync) {\n");
1938 #if 0 /* We should do some sort of caching algorithm for this, but I need to think about it - shadow 26 jun 06 */
1939 f_print(fout, "\t\tif (!inlist) { /* Remember proc call that needs sync site */\n");
1940 f_print(fout, "\t\t\tLOCK_UCLNT_CACHE;\n");
1941 f_print(fout, "\t\t\tcalls_needsync[synccount % SYNCCOUNT] = (int *)%s%s%s;\n", prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
1942 f_print(fout, "\t\t\tsynccount++;\n");
1943 f_print(fout, "\t\t\tUNLOCK_UCLNT_CACHE;\n");
1944 f_print(fout, "\t\t\tinlist = 1;\n");
1945 f_print(fout, "\t\t}\n");
1947 f_print(fout, "\t\tif (!rcode) { /* Remember the sync site - cmd successful */\n");
1948 f_print(fout, "\t\t\trxp = rx_PeerOf(aclient->conns[_ucount]);\n");
1949 f_print(fout, "\t\t\taclient->syncSite = rx_HostOf(rxp);\n");
1950 f_print(fout, "\t\t}\n");
1951 f_print(fout, "\t}\n");
1952 f_print(fout, "\tUNLOCK_UBIK_CLIENT(aclient);\n");
1953 f_print(fout, "\treturn rcode;\n}\n\n");
1958 opcode_holes_exist(void)
1962 for (i = lowest_opcode[PackageIndex]; i < highest_opcode[PackageIndex];
1964 if (!opcodenum_is_defined(i))
1972 er_Proc_CodeGeneration(void)
1976 temp = PackageIndex;
1977 if (!combinepackages)
1979 for (; PackageIndex <= temp; PackageIndex++) {
1980 if (proc_defined[PackageIndex] == NULL)
1982 if (combinepackages || opcode_holes_exist()) {
1983 er_HeadofOldStyleProc_setup();
1984 er_BodyofOldStyleProc_setup();
1985 er_TailofOldStyleProc_setup();
1986 er_HeadofOldStyleProc_setup2();
1987 er_BodyofOldStyleProc_setup2();
1988 er_TailofOldStyleProc_setup2();
1990 er_ProcDeclExterns_setup();
1991 er_ProcProcsArray_setup();
1992 er_ProcMainBody_setup();
1995 PackageIndex = temp;
2000 er_ProcDeclExterns_setup(void)
2008 f_print(fout, "\n");
2009 for (listp = proc_defined[PackageIndex]; listp != NULL;
2010 listp = listp->next) {
2011 defp = (definition *) listp->val;
2012 if (defp->pc.proc_serverstub) {
2013 f_print(fout, "afs_int32 %s();\n", defp->pc.proc_serverstub);
2020 er_ProcProcsArray_setup(void)
2025 if ((listp = proc_defined[PackageIndex])) {
2026 defp = (definition *) listp->val;
2028 f_print(fout, "\nstatic char *opnames%d[] = {\"%s%s\"",
2029 PackageIndex, defp->pc.proc_prefix, defp->pc.proc_name);
2032 if (defp->pc.proc_serverstub) {
2033 f_print(fout, "\nstatic afs_int32 (*StubProcsArray%d[])() = {%s",
2034 PackageIndex, defp->pc.proc_serverstub);
2037 "\nstatic afs_int32 (*StubProcsArray%d[])(struct rx_call *z_call, XDR *z_xdrs) = {_%s%s%s",
2038 PackageIndex, prefix, defp->pc.proc_prefix,
2039 ((definition *) listp->val)->pc.proc_name);
2042 listp = listp->next;
2044 for (; listp != NULL; listp = listp->next) {
2045 defp = (definition *) listp->val;
2047 f_print(fout, ", \"%s%s\"",defp->pc.proc_prefix,defp->pc.proc_name);
2050 if (defp->pc.proc_serverstub) {
2051 f_print(fout, ",%s", defp->pc.proc_serverstub);
2053 f_print(fout, ", _%s%s%s", prefix, defp->pc.proc_prefix,
2054 defp->pc.proc_name);
2058 f_print(fout, "};\n\n");
2063 er_ProcMainBody_setup(void)
2066 f_print(fout, "char *%sTranslateOpCode(int op)\n{\n",
2067 PackagePrefix[PackageIndex]);
2068 f_print(fout, "\tif (op < %sLOWEST_OPCODE || op > %sHIGHEST_OPCODE)\n\t\treturn NULL;\n",
2069 PackagePrefix[PackageIndex], PackagePrefix[PackageIndex]);
2070 f_print(fout, "\treturn opnames%d[op - %sLOWEST_OPCODE];\n}\n",
2071 PackageIndex, PackagePrefix[PackageIndex]);
2072 f_print(fout, "struct %sstats *%sOpCodeStats(int op)\n{\n",
2073 PackagePrefix[PackageIndex], PackagePrefix[PackageIndex]);
2074 f_print(fout, "\tif (op < %sLOWEST_OPCODE || op > %sHIGHEST_OPCODE)\n\t\treturn NULL;\n",
2075 PackagePrefix[PackageIndex], PackagePrefix[PackageIndex]);
2076 f_print(fout, "\treturn NULL;/*%d %s*/\n}\n",
2077 PackageIndex, PackagePrefix[PackageIndex]);
2081 f_print(fout, "int %s%sExecuteRequest(struct rx_call *z_call)\n",
2082 prefix, PackagePrefix[PackageIndex]);
2083 f_print(fout, "{\n\tint op;\n");
2084 f_print(fout, "\tXDR z_xdrs;\n");
2085 f_print(fout, "\t" "afs_int32 z_result;\n\n");
2086 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
2088 "\tif (!xdr_int(&z_xdrs, &op))\n\t\tz_result = RXGEN_DECODE;\n");
2090 "\telse if (op < %sLOWEST_OPCODE || op > %sHIGHEST_OPCODE)\n\t\tz_result = RXGEN_OPCODE;\n",
2091 PackagePrefix[PackageIndex], PackagePrefix[PackageIndex]);
2093 "\telse\n\t\tz_result = (*StubProcsArray%d[op - %sLOWEST_OPCODE])(z_call, &z_xdrs);\n",
2094 PackageIndex, PackagePrefix[PackageIndex]);
2095 f_print(fout, "\treturn hton_syserr_conv(z_result);\n}\n");
2099 er_HeadofOldStyleProc_setup2(void)
2102 f_print(fout, "int %sOpCodeIndex(int op)\n{\n", (combinepackages ? MasterPrefix : PackagePrefix[PackageIndex]));
2103 f_print(fout, "\tswitch (op) {\n");
2108 er_HeadofOldStyleProc_setup(void)
2111 f_print(fout, "char *%sTranslateOpCode(int op)\n{\n",
2112 (combinepackages ? MasterPrefix : PackagePrefix[PackageIndex]));
2116 "\nint %s%sExecuteRequest (struct rx_call *z_call)\n",
2118 (combinepackages ? MasterPrefix : PackagePrefix[PackageIndex]));
2119 f_print(fout, "{\n");
2120 f_print(fout, "\tint op;\n");
2121 f_print(fout, "\tXDR z_xdrs;\n");
2122 f_print(fout, "\t" "afs_int32 z_result;\n\n");
2123 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
2124 f_print(fout, "\tz_result = RXGEN_DECODE;\n");
2125 f_print(fout, "\tif (!xdr_int(&z_xdrs, &op)) goto fail;\n");
2127 f_print(fout, "\tswitch (op) {\n");
2131 er_BodyofOldStyleProc_setup(void)
2135 if (combinepackages) {
2136 int temp = PackageIndex;
2137 for (PackageIndex = 0; PackageIndex <= temp; PackageIndex++) {
2138 for (listp = proc_defined[PackageIndex]; listp != NULL;
2139 listp = listp->next)
2140 proc_er_case((definition *) listp->val);
2142 PackageIndex = temp;
2144 for (listp = proc_defined[PackageIndex]; listp != NULL;
2145 listp = listp->next)
2146 proc_er_case((definition *) listp->val);
2152 proc_er_case(definition * defp)
2155 f_print(fout, "\t\tcase %d:", defp->pc.proc_opcodenum);
2156 f_print(fout, "\treturn \"%s%s\";\n",
2157 defp->pc.proc_prefix, defp->pc.proc_name);
2160 if (opcodesnotallowed[PackageIndex]) {
2161 f_print(fout, "\t\tcase %d:\n", defp->pc.proc_opcodenum);
2163 f_print(fout, "\t\tcase %s:\n", defp->pc.proc_opcodename);
2165 if (defp->pc.proc_serverstub) {
2166 f_print(fout, "\t\t\tz_result = %s(z_call, &z_xdrs);\n",
2167 defp->pc.proc_serverstub);
2169 f_print(fout, "\t\t\tz_result = _%s%s%s(z_call, &z_xdrs);\n", prefix,
2170 defp->pc.proc_prefix, defp->pc.proc_name);
2172 f_print(fout, "\t\t\tbreak;\n");
2176 proc_op_case(definition * defp)
2178 f_print(fout, "\t\tcase %d:", defp->pc.proc_opcodenum);
2179 f_print(fout, "\treturn %d;\n",
2184 er_BodyofOldStyleProc_setup2(void)
2190 if (combinepackages) {
2191 int temp = PackageIndex;
2192 for (PackageIndex = 0; PackageIndex <= temp; PackageIndex++) {
2193 for (listp = proc_defined[PackageIndex]; listp != NULL;
2194 listp = listp->next)
2195 proc_op_case((definition *) listp->val);
2197 PackageIndex = temp;
2199 for (listp = proc_defined[PackageIndex]; listp != NULL;
2200 listp = listp->next)
2201 proc_op_case((definition *) listp->val);
2206 er_TailofOldStyleProc_setup2(void)
2209 f_print(fout, "\t\tdefault:\n");
2210 f_print(fout, "\t\t\treturn -1;\n\t}\n}\n");
2215 er_TailofOldStyleProc_setup(void)
2217 f_print(fout, "\t\tdefault:\n");
2219 f_print(fout, "\t\t\treturn NULL;\n\t}\n}\n");
2222 f_print(fout, "\t\t\tz_result = RXGEN_OPCODE;\n");
2223 f_print(fout, "\t\t\tbreak;\n\t}\n");
2224 f_print(fout, "fail:\n");
2225 f_print(fout, "\treturn z_result;\n}\n");
2229 h_ProcMainBody_setup(void)
2231 f_print(fout,"\nextern int %s%sExecuteRequest(struct rx_call *);\n",
2232 prefix, PackagePrefix[PackageIndex]);
2236 h_HeadofOldStyleProc_setup(void)
2238 char *pprefix = (combinepackages ? MasterPrefix :
2239 PackagePrefix[PackageIndex]);
2240 f_print(fout,"\nstruct %sstats{\n\tint statsver;\n};", pprefix);
2241 f_print(fout,"\nextern int %s%sExecuteRequest(struct rx_call *);\n",
2243 f_print(fout,"\nextern int %sOpCodeIndex(int op);\n", PackagePrefix[PackageIndex]);
2247 h_Proc_CodeGeneration(void)
2251 temp = PackageIndex;
2252 if (!combinepackages)
2254 for (; PackageIndex <= temp; PackageIndex++) {
2255 if (combinepackages || opcode_holes_exist()) {
2256 h_HeadofOldStyleProc_setup();
2258 h_ProcMainBody_setup();
2261 PackageIndex = temp;
2265 proc_h_case(definition * defp)
2267 f_print(fout, "#define opcode_%s%s \t((afs_uint64)((%uLL << 32) + %sOpCodeIndex(%u)))\n",
2268 defp->pc.proc_prefix, defp->pc.proc_name, StatIndex,
2269 defp->pc.proc_prefix, defp->pc.proc_opcodenum);
2273 h_opcode_stats_pkg(char *pprefix, int lowest, int highest, int nops,
2274 int statfuncs, char *ptype, list *proclist)
2282 "\n/* Opcode-related useful stats for %spackage: %s */\n",
2284 f_print(fout, "#define %sLOWEST_OPCODE %d\n", pprefix, lowest);
2285 f_print(fout, "#define %sHIGHEST_OPCODE %d\n", pprefix, highest);
2286 f_print(fout, "#define %sNUMBER_OPCODES %d\n\n", pprefix, nops);
2288 for (listp = proclist; listp != NULL;
2289 listp = listp->next)
2290 proc_h_case((definition *) listp->val);
2293 f_print(fout, "#define %sNO_OF_STAT_FUNCS\t%d\n\n",
2294 pprefix, statfuncs);
2295 f_print(fout, "AFS_RXGEN_EXPORT\n");
2296 f_print(fout, "extern const char *%sfunction_names[];\n\n",
2302 h_opcode_stats(void)
2304 if (combinepackages) {
2305 h_opcode_stats_pkg(MasterPrefix, master_lowest_opcode, master_highest_opcode, master_no_of_opcodes, no_of_stat_funcs_header[0], "Master ", proc_defined[0]);
2308 for (i = 0; i <= PackageIndex; i++) {
2309 h_opcode_stats_pkg(PackagePrefix[i], lowest_opcode[i], highest_opcode[i], no_of_opcodes[i], no_of_stat_funcs_header[i], "", proc_defined[i]);
2316 generate_multi_macros(definition * defp)
2318 char *startname = SplitStart, *endname = SplitEnd;
2327 f_print(fout, "\n#include <rx/rx_multi.h>");
2329 f_print(fout, "\n#define multi_%s%s(", PackagePrefix[PackageIndex],
2330 defp->pc.proc_name);
2331 for (plist = defp->pc.plists; plist; plist = plist->next) {
2332 if (plist->component_kind == DEF_PARAM) {
2335 f_print(fout, "%s", plist->pl.param_name);
2337 f_print(fout, ", %s", plist->pl.param_name);
2341 f_print(fout, ") \\\n");
2343 startname = "Start";
2346 f_print(fout, "\tmulti_Body(%s%s%s(multi_call", startname,
2347 PackagePrefix[PackageIndex], defp->pc.proc_name);
2348 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 0);
2349 for (plist = defp->pc.plists; plist; plist = plist->next) {
2350 if (plist->component_kind == DEF_PARAM)
2351 f_print(fout, ", %s", plist->pl.param_name);
2353 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 1);
2354 f_print(fout, "), %s%s%s(multi_call", endname,
2355 PackagePrefix[PackageIndex], defp->pc.proc_name);
2356 do_split(defp, IN, &numofparams, DEF_INPARAM, 0);
2357 for (plist = defp->pc.plists; plist; plist = plist->next) {
2358 if (plist->component_kind == DEF_PARAM) {
2359 f_print(fout, ", %s", plist->pl.param_name);
2362 do_split(defp, IN, &numofparams, DEF_INPARAM, 1);
2363 f_print(fout, "))\n\n");
2368 IsRxgenToken(token * tokp)
2370 if (tokp->kind == TOK_PACKAGE || tokp->kind == TOK_PREFIX
2371 || tokp->kind == TOK_SPECIAL || tokp->kind == TOK_STARTINGOPCODE
2372 || tokp->kind == TOK_SPLITPREFIX || tokp->kind == TOK_PROC
2373 || tokp->kind == TOK_STATINDEX)
2379 IsRxgenDefinition(definition * def)
2381 if (def->def_kind == DEF_PACKAGE || def->def_kind == DEF_PREFIX
2382 || def->def_kind == DEF_SPECIAL || def->def_kind == DEF_STARTINGOPCODE
2383 || def->def_kind == DEF_SPLITPREFIX || def->def_kind == DEF_PROC)