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));
200 def_special(&dec, defp);
203 case TOK_STARTINGOPCODE:
204 def_startingopcode(defp);
209 customize_struct(defp);
211 case TOK_SPLITPREFIX:
216 if (tok.kind == TOK_LPAREN) {
218 check_proc(defp, &tok, 1);
220 check_proc(defp, &tok, 0);
223 check_proc(defp, &tok, 0);
227 check_proc(defp, &tok, 1);
230 error("definition keyword expected");
232 if (!IsRxgenToken(&tok)) {
233 scan(TOK_SEMICOLON, &tok);
241 isdefined(definition * defp)
243 STOREVAL(&defined, defp);
248 def_struct(definition * defp)
256 defp->def_kind = DEF_STRUCT;
258 scan(TOK_IDENT, &tok);
259 defp->def_name = tok.str;
260 scan(TOK_LBRACE, &tok);
261 tailp = &defp->def.st.decls;
263 get_declaration(&dec, DEF_STRUCT);
264 /* If a structure contains an array, then we're going
265 * to need to be clever about freeing it */
266 if (dec.rel == REL_ARRAY) {
269 decls = ALLOC(decl_list);
272 tailp = &decls->next;
273 scan(TOK_SEMICOLON, &tok);
275 } while (tok.kind != TOK_RBRACE);
280 STOREVAL(&complex_defined, defp);
284 def_program(definition * defp)
288 version_list **vtailp;
292 defp->def_kind = DEF_PROGRAM;
293 scan(TOK_IDENT, &tok);
294 defp->def_name = tok.str;
295 scan(TOK_LBRACE, &tok);
296 vtailp = &defp->def.pr.versions;
297 scan(TOK_VERSION, &tok);
299 scan(TOK_IDENT, &tok);
300 vlist = ALLOC(version_list);
301 vlist->vers_name = tok.str;
302 scan(TOK_LBRACE, &tok);
303 ptailp = &vlist->procs;
305 plist = ALLOC(proc_list);
306 get_type(&plist->res_prefix, &plist->res_type, DEF_PROGRAM);
307 if (streq(plist->res_type, "opaque")) {
308 error("illegal result type");
310 scan(TOK_IDENT, &tok);
311 plist->proc_name = tok.str;
312 scan(TOK_LPAREN, &tok);
313 get_type(&plist->arg_prefix, &plist->arg_type, DEF_PROGRAM);
314 if (streq(plist->arg_type, "opaque")) {
315 error("illegal argument type");
317 scan(TOK_RPAREN, &tok);
318 scan(TOK_EQUAL, &tok);
320 scan(TOK_SEMICOLON, &tok);
321 plist->proc_num = tok.str;
323 ptailp = &plist->next;
325 } while (tok.kind != TOK_RBRACE);
327 vtailp = &vlist->next;
328 scan(TOK_RBRACE, &tok);
329 scan(TOK_EQUAL, &tok);
331 vlist->vers_num = tok.str;
332 scan(TOK_SEMICOLON, &tok);
333 scan2(TOK_VERSION, TOK_RBRACE, &tok);
334 } while (tok.kind == TOK_VERSION);
335 scan(TOK_EQUAL, &tok);
337 defp->def.pr.prog_num = tok.str;
342 def_enum(definition * defp)
346 enumval_list **tailp;
348 defp->def_kind = DEF_ENUM;
349 scan(TOK_IDENT, &tok);
350 defp->def_name = tok.str;
351 scan(TOK_LBRACE, &tok);
352 tailp = &defp->def.en.vals;
354 scan(TOK_IDENT, &tok);
355 elist = ALLOC(enumval_list);
356 elist->name = tok.str;
357 elist->assignment = NULL;
358 scan3(TOK_COMMA, TOK_RBRACE, TOK_EQUAL, &tok);
359 if (tok.kind == TOK_EQUAL) {
361 elist->assignment = tok.str;
362 scan2(TOK_COMMA, TOK_RBRACE, &tok);
365 tailp = &elist->next;
366 } while (tok.kind != TOK_RBRACE);
371 def_const(definition * defp)
375 defp->def_kind = DEF_CONST;
376 scan(TOK_IDENT, &tok);
377 defp->def_name = tok.str;
378 scan(TOK_EQUAL, &tok);
379 scan2(TOK_IDENT, TOK_STRCONST, &tok);
380 defp->def.co = tok.str;
384 def_union(definition * defp)
391 defp->def_kind = DEF_UNION;
392 scan(TOK_IDENT, &tok);
393 defp->def_name = tok.str;
394 scan(TOK_SWITCH, &tok);
395 scan(TOK_LPAREN, &tok);
396 get_declaration(&dec, DEF_UNION);
397 defp->def.un.enum_decl = dec;
398 tailp = &defp->def.un.cases;
399 scan(TOK_RPAREN, &tok);
400 scan(TOK_LBRACE, &tok);
401 scan(TOK_CASE, &tok);
402 while (tok.kind == TOK_CASE) {
403 scan(TOK_IDENT, &tok);
404 cases = ALLOC(case_list);
405 cases->case_name = tok.str;
406 scan(TOK_COLON, &tok);
407 get_declaration(&dec, DEF_UNION);
408 cases->case_decl = dec;
410 tailp = &cases->next;
411 scan(TOK_SEMICOLON, &tok);
412 scan3(TOK_CASE, TOK_DEFAULT, TOK_RBRACE, &tok);
415 if (tok.kind == TOK_DEFAULT) {
416 scan(TOK_COLON, &tok);
417 get_declaration(&dec, DEF_UNION);
418 defp->def.un.default_decl = ALLOC(declaration);
419 *defp->def.un.default_decl = dec;
420 scan(TOK_SEMICOLON, &tok);
421 scan(TOK_RBRACE, &tok);
423 defp->def.un.default_decl = NULL;
429 def_typedef(definition * defp)
433 defp->def_kind = DEF_TYPEDEF;
434 get_declaration(&dec, DEF_TYPEDEF);
435 defp->def_name = dec.name;
436 defp->def.ty.old_prefix = dec.prefix;
437 defp->def.ty.old_type = dec.type;
438 defp->def.ty.rel = dec.rel;
439 defp->def.ty.array_max = dec.array_max;
444 get_declaration(declaration * dec, defkind dkind)
448 get_type(&dec->prefix, &dec->type, dkind);
449 dec->rel = REL_ALIAS;
450 if (streq(dec->type, "void")) {
453 scan2(TOK_STAR, TOK_IDENT, &tok);
454 if (tok.kind == TOK_STAR) {
455 dec->rel = REL_POINTER;
456 scan(TOK_IDENT, &tok);
459 if (peekscan(TOK_LBRACKET, &tok)) {
460 if (dec->rel == REL_POINTER) {
461 error("no array-of-pointer declarations -- use typedef");
463 dec->rel = REL_VECTOR;
465 dec->array_max = tok.str;
466 scan(TOK_RBRACKET, &tok);
467 } else if (peekscan(TOK_LANGLE, &tok)) {
468 if (dec->rel == REL_POINTER) {
469 error("no array-of-pointer declarations -- use typedef");
471 dec->rel = REL_ARRAY;
472 if (peekscan(TOK_RANGLE, &tok)) {
473 dec->array_max = "~0"; /* unspecified size, use max */
476 dec->array_max = tok.str;
477 scan(TOK_RANGLE, &tok);
480 if (streq(dec->type, "opaque")) {
481 if (dec->rel != REL_ARRAY && dec->rel != REL_VECTOR) {
482 error("array declaration expected");
484 } else if (streq(dec->type, "string")) {
485 if (dec->rel != REL_ARRAY) {
486 error(" variable-length array declaration expected");
493 get_type(char **prefixp, char **typep, defkind dkind)
507 scan(TOK_IDENT, &tok);
515 (void)peekscan(TOK_INT, &tok);
518 *typep = "afs_int32";
519 (void)peekscan(TOK_INT, &tok);
522 if (dkind != DEF_UNION && dkind != DEF_PROGRAM) {
523 error("voids allowed only inside union and program definitions");
538 error("expected type specifier");
544 unsigned_dec(char **typep)
557 (void)peekscan(TOK_INT, &tok);
561 *typep = "afs_uint32";
562 (void)peekscan(TOK_INT, &tok);
576 def_package(definition * defp)
580 defp->def_kind = DEF_PACKAGE;
581 scan(TOK_IDENT, &tok);
582 defp->def_name = tok.str;
583 no_of_stat_funcs = 0;
584 if (PackageIndex++ >= MAX_PACKAGES)
585 error("Exceeded upper limit of package statements\n");
586 function_list_index = 0;
587 PackagePrefix[PackageIndex] = tok.str;
588 if (MasterPrefix == NULL)
589 MasterPrefix = tok.str;
590 no_of_opcodes[PackageIndex] = highest_opcode[PackageIndex] =
591 opcodesnotallowed[PackageIndex] = 0;
592 lowest_opcode[PackageIndex] = 99999;
593 proc_defined[PackageIndex] = NULL;
594 PackageStatIndex[PackageIndex] = NULL;
598 def_prefix(definition * defp)
602 defp->def_kind = DEF_PREFIX;
603 scan(TOK_IDENT, &tok);
604 defp->def_name = tok.str;
605 ServerPrefix = tok.str;
609 def_statindex(definition * defp)
614 defp->def_kind = DEF_CONST;
616 if (PackageIndex < 0)
617 error("'statindex' command must follow 'package' command!\n");
618 if (PackageStatIndex[PackageIndex])
619 error("Cannot have more then one 'statindex' per package!\n");
620 if (InvalidConstant(tok.str))
621 error("Index in 'statindex' command must be a constant!");
623 alloc(strlen(PackagePrefix[PackageIndex]) + strlen("STATINDEX") + 1);
624 strcpy(name, PackagePrefix[PackageIndex]);
625 strcat(name, "STATINDEX");
626 defp->def_name = name;
627 defp->def.co = tok.str;
628 PackageStatIndex[PackageIndex] = name;
629 StatIndex = atoi(tok.str);
633 def_startingopcode(definition * defp)
637 defp->def_kind = DEF_STARTINGOPCODE;
638 scan(TOK_IDENT, &tok);
639 defp->def_name = tok.str;
640 if (InvalidConstant(defp->def_name))
641 error("Opcode in 'startingopcode' command must be a constant!");
642 lowest_opcode[PackageIndex] = master_lowest_opcode = atoi(tok.str);
643 if (lowest_opcode[PackageIndex] < 0
644 || lowest_opcode[PackageIndex] > 99999)
646 ("startingopcode number is out of bounds (must be >= 0 < 100000)");
647 master_opcodenumber = lowest_opcode[PackageIndex];
648 opcodesnotallowed[PackageIndex] = 1;
652 def_split(definition * defp)
656 defp->def_kind = DEF_SPLITPREFIX;
661 scan(TOK_EQUAL, &tok);
662 scan(TOK_IDENT, &tok);
663 SplitStart = tok.str;
666 scan(TOK_EQUAL, &tok);
667 scan(TOK_IDENT, &tok);
673 error("syntax error in the 'splitprefix' line");
675 } while (tok.kind != TOK_SEMICOLON);
676 if (!SplitStart && !SplitEnd)
677 error("At least one param should be passed to 'splitprefix' cmd");
682 customize_struct(definition * defp)
686 definition *defp1 = ALLOC(definition);
687 spec_list *specs, **tailp;
689 defp->def_kind = DEF_CUSTOMIZED;
690 defp1->def_kind = DEF_SPECIAL;
691 tailp = &defp1->def.sd.specs;
692 for (listp = defp->def.st.decls; listp; listp = listp->next) {
694 if (streq(dec->type, "string") || (dec->rel == REL_POINTER)) {
695 specs = ALLOC(spec_list);
696 specs->sdef.string_name = dec->name;
697 specs->sdef.string_value = defp->def_name;
699 tailp = &specs->next;
703 STOREVAL(&special_defined, defp1);
707 structname(char *name)
709 static char namecontents[150];
712 strcpy(namecontents, name);
714 if (!strncmp(pnt, "struct", 6))
716 while (isspace(*pnt))
719 while (*pnt != ' ' && *pnt != '\0')
727 def_special(declaration * dec, definition * defp)
730 spec_list *specs, **tailp;
733 defp->def_kind = DEF_SPECIAL;
734 get_type(&dec->prefix, &dec->type, DEF_SPECIAL);
735 dec->rel = REL_POINTER;
736 scan(TOK_IDENT, &tok);
737 tailp = &defp->def.sd.specs;
739 specs = ALLOC(spec_list);
740 specs->sdef.string_name = tok.str;
741 get_param_type(defp, dec, &specs->sdef.string_value, &typename);
743 tailp = &specs->next;
744 scan2(TOK_COMMA, TOK_SEMICOLON, &tok);
745 if (tok.kind == TOK_SEMICOLON)
748 } while (tok.kind == TOK_IDENT);
750 STOREVAL(&special_defined, defp);
754 proc1_list *Proc_list, **Proc_listp;
757 check_proc(definition * defp, token * tokp, int noname)
763 if (PackageIndex < 0)
764 error("Procedure must be in a package!\n");
766 tokp->kind = TOK_PROC;
767 defp->def_kind = DEF_PROC;
769 defp->pc.proc_name = "";
771 defp->pc.proc_name = tokp->str;
773 defp->pc.proc_prefix = alloc(strlen(PackagePrefix[PackageIndex]) + 1);
774 strcpy(defp->pc.proc_prefix, PackagePrefix[PackageIndex]);
775 scan2(TOK_LPAREN, TOK_IDENT, &tok);
776 defp->pc.proc_serverstub = NULL;
777 if (tok.kind == TOK_IDENT) {
778 defp->pc.proc_serverstub = tok.str;
779 scan(TOK_LPAREN, &tok);
781 analyze_ProcParams(defp, &tok);
782 defp->pc.proc_opcodenum = -1;
783 scan4(TOK_SPLIT, TOK_MULTI, TOK_EQUAL, TOK_SEMICOLON, &tok);
784 if (tok.kind == TOK_MULTI) {
786 defp->pc.multi_flag = 1;
787 scan2(TOK_EQUAL, TOK_SEMICOLON, &tok);
789 defp->pc.multi_flag = 0;
791 if (tok.kind == TOK_SPLIT) {
793 defp->pc.split_flag = 1;
794 scan2(TOK_EQUAL, TOK_SEMICOLON, &tok);
796 defp->pc.split_flag = 0;
798 if (tok.kind == TOK_EQUAL) {
799 if (opcodesnotallowed[PackageIndex])
800 error("Opcode assignment isn't allowed here!");
802 if (InvalidConstant(tok.str))
803 error("Illegal Opcode assignment (Must be a constant opcode!)");
804 if (opcodenum_is_defined(atoi(tok.str)))
805 error("The opcode number is already used by a previous proc");
806 defp->pc.proc_opcodename = tok.str;
807 defp->pc.proc_opcodenum = atoi(tok.str);
808 if (defp->pc.proc_opcodenum < lowest_opcode[PackageIndex])
809 lowest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
810 if (defp->pc.proc_opcodenum < master_lowest_opcode)
811 master_lowest_opcode = defp->pc.proc_opcodenum;
812 if (defp->pc.proc_opcodenum > highest_opcode[PackageIndex])
813 highest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
814 if (defp->pc.proc_opcodenum > master_highest_opcode)
815 master_highest_opcode = defp->pc.proc_opcodenum;
816 scan(TOK_SEMICOLON, &tok);
818 if (master_opcodenumber == 99999)
819 master_opcodenumber = 0;
820 defp->pc.proc_opcodenum = master_opcodenumber++;
821 if (defp->pc.proc_opcodenum < lowest_opcode[PackageIndex])
822 lowest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
823 if (defp->pc.proc_opcodenum > highest_opcode[PackageIndex])
824 highest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
825 if (defp->pc.proc_opcodenum > master_highest_opcode)
826 master_highest_opcode = defp->pc.proc_opcodenum;
827 opcodesnotallowed[PackageIndex] = 1; /* force it */
829 no_of_opcodes[PackageIndex]++, master_no_of_opcodes++;
831 generate_code(defp, 0, 1);
832 if (Cflag || cflag) {
833 generate_code(defp, 1, 1);
835 generate_multi_macros(defp);
837 generate_code(defp, proc_split, 0);
840 if (function_list_index >= MAX_FUNCTIONS_PER_INTERFACE) {
841 error("too many functions in interface, "
842 "increase MAX_FUNCTIONS_PER_INTERFACE");
844 sprintf(function_list[PackageIndex][function_list_index], "%s%s%s",
845 prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
847 function_list_index++;
848 defp->statindex = no_of_stat_funcs;
849 no_of_stat_funcs_header[PackageIndex]++;
855 #define LEGALNUMS "0123456789"
857 InvalidConstant(char *name)
863 slen = (int)strlen(name);
864 return (slen != strspn(name, map));
868 opcodenum_is_defined(int opcode_num)
873 for (listp = proc_defined[PackageIndex]; listp != NULL;
874 listp = listp->next) {
875 defp = (definition *) listp->val;
876 if (opcode_num == defp->pc.proc_opcodenum)
884 analyze_ProcParams(definition * defp, token * tokp)
887 decl_list *decls, **tailp;
889 Proc_listp = &defp->pc.plists;
890 tailp = &defp->def.st.decls;
893 Proc_list = ALLOC(proc1_list);
894 memset(Proc_list, 0, sizeof(proc1_list));
895 Proc_list->pl.param_flag = 0;
896 switch (tokp->kind) {
898 hdle_param_tok(defp, &dec, tokp, DEF_INPARAM);
901 hdle_param_tok(defp, &dec, tokp, DEF_OUTPARAM);
904 hdle_param_tok(defp, &dec, tokp, DEF_INOUTPARAM);
910 hdle_param_tok(defp, &dec, tokp, DEF_NULL);
913 *Proc_listp = Proc_list;
914 Proc_listp = &Proc_list->next;
915 decls = ALLOC(decl_list);
916 memset(decls, 0, sizeof(decl_list));
917 if (tokp->kind != TOK_RPAREN)
920 tailp = &decls->next;
921 } while (tokp->kind != TOK_RPAREN);
927 generate_code(definition * defp, int proc_split_flag, int multi_flag)
930 handle_split_proc(defp, multi_flag);
932 if (Cflag || cflag) {
933 cs_Proc_CodeGeneration(defp, 0, "");
936 ss_Proc_CodeGeneration(defp);
938 if (Sflag || (cflag && xflag && !proc_split_flag) || hflag)
939 STOREVAL(&proc_defined[PackageIndex], defp);
944 handle_split_proc(definition * defp, int multi_flag)
946 char *startname = SplitStart, *endname = SplitEnd;
953 if (Cflag || cflag) {
955 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 0);
957 cs_Proc_CodeGeneration(defp, 1, startname);
959 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 1);
960 do_split(defp, IN, &numofparams, DEF_INPARAM, 0);
962 cs_Proc_CodeGeneration(defp, (multi_flag ? 3 : 2), endname);
964 do_split(defp, IN, &numofparams, DEF_INPARAM, 1);
968 ss_Proc_CodeGeneration(defp);
973 do_split(definition * defp, int direction, int *numofparams,
974 defkind param_kind, int restore_flag)
979 defp->pc.paramtypes[direction] = *numofparams;
980 for (plist = defp->pc.plists; plist; plist = plist->next) {
981 if (plist->component_kind == DEF_NULL
982 && plist->pl.param_kind == param_kind)
983 plist->component_kind = DEF_PARAM;
986 *numofparams = defp->pc.paramtypes[direction];
987 defp->pc.paramtypes[direction] = 0;
988 for (plist = defp->pc.plists; plist; plist = plist->next) {
989 if (plist->component_kind == DEF_PARAM
990 && plist->pl.param_kind == param_kind)
991 plist->component_kind = DEF_NULL;
998 hdle_param_tok(definition * defp, declaration * dec, token * tokp,
1001 static defkind last_param_kind = DEF_NULL;
1003 if (par_kind == DEF_NULL)
1004 Proc_list->pl.param_kind = last_param_kind;
1006 Proc_list->pl.param_kind = par_kind;
1007 last_param_kind = Proc_list->pl.param_kind;
1008 defp->pc.paramtypes[(int)last_param_kind]++;
1009 Proc_list->component_kind = DEF_PARAM;
1010 Proc_list->code = alloc(250);
1011 Proc_list->scode = alloc(250);
1012 get_declaration(dec, DEF_PARAM);
1013 Proc_list->pl.param_name = dec->name;
1014 get1_param_type(defp, dec, &Proc_list->pl.param_type);
1016 scan2(TOK_COMMA, TOK_RPAREN, tokp);
1017 if (tokp->kind == TOK_COMMA)
1023 get1_param_type(definition * defp, declaration * dec, char **param_type)
1025 char typecontents[100];
1027 if (streq(dec->type, "string")) {
1028 *param_type = "char *";
1031 strcpy(typecontents, dec->prefix);
1032 strcat(typecontents, " ");
1033 strcat(typecontents, dec->type);
1034 strcat(typecontents, " *");
1035 } else if (dec->rel == REL_POINTER) {
1036 strcpy(typecontents, dec->type);
1037 strcat(typecontents, " *");
1039 strcpy(typecontents, dec->type);
1040 *param_type = alloc(100);
1041 strcpy(*param_type, typecontents);
1047 get_param_type(definition * defp, declaration * dec, char **param_type,
1050 char typecontents[100];
1052 if (streq(dec->type, "string")) {
1053 *typename = "wrapstring";
1054 *param_type = "char *";
1056 *typename = dec->type;
1058 strcpy(typecontents, dec->prefix);
1059 strcat(typecontents, " ");
1060 strcat(typecontents, dec->type);
1061 strcat(typecontents, " *");
1062 dec->rel = REL_POINTER;
1063 } else if (dec->rel == REL_POINTER) {
1064 strcpy(typecontents, dec->type);
1065 strcat(typecontents, " *");
1067 strcpy(typecontents, dec->type);
1068 *param_type = alloc(100);
1069 strcpy(*param_type, typecontents);
1076 hndle_param_tail(definition * defp, declaration * dec, token * tokp,
1081 if (dec->rel == REL_POINTER)
1082 Proc_list->pl.param_flag |= INDIRECT_PARAM;
1084 Proc_list->pl.param_flag &= ~INDIRECT_PARAM;
1086 if (!(Proc_list->pl.param_flag & INDIRECT_PARAM))
1089 sprintf(Proc_list->code, "xdr_%s(&z_xdrs, %s%s)", typename, amp,
1090 Proc_list->pl.param_name);
1091 sprintf(Proc_list->scode, "xdr_%s(z_xdrs, &%s)", typename,
1092 Proc_list->pl.param_name);
1093 scan2(TOK_COMMA, TOK_RPAREN, tokp);
1094 if (tokp->kind == TOK_COMMA)
1101 cs_Proc_CodeGeneration(definition * defp, int split_flag, char *procheader)
1104 cs_ProcName_setup(defp, procheader, split_flag);
1106 cs_ProcParams_setup(defp, split_flag);
1107 cs_ProcMarshallInParams_setup(defp, split_flag);
1108 if (split_flag != 1) {
1109 cs_ProcSendPacket_setup(defp, split_flag);
1110 cs_ProcUnmarshallOutParams_setup(defp);
1112 cs_ProcTail_setup(defp, split_flag);
1115 if (!kflag && !split_flag && uflag) {
1116 ucs_ProcName_setup(defp, "ubik_", split_flag);
1118 ucs_ProcParams_setup(defp, split_flag);
1119 ucs_ProcTail_setup(defp, split_flag);
1125 cs_ProcName_setup(definition * defp, char *procheader, int split_flag)
1132 first_arg = "struct rx_call *z_call";
1134 first_arg = "struct rx_connection *z_conn";
1138 first_arg = "z_call";
1140 first_arg = "z_conn";
1145 f_print(fout, "int %s%s%s%s(%s", procheader, prefix,
1146 PackagePrefix[PackageIndex], defp->pc.proc_name, first_arg);
1148 if ((strlen(procheader) + strlen(prefix) +
1149 strlen(PackagePrefix[PackageIndex]) + strlen(defp->pc.proc_name)) >=
1150 MAX_FUNCTION_NAME_LEN) {
1151 error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
1154 for (plist = defp->pc.plists; plist; plist = plist->next) {
1155 if (plist->component_kind == DEF_PARAM) {
1158 if (plist->pl.param_kind == DEF_INPARAM &&
1159 strcmp(plist->pl.param_type, "char *") == 0) {
1160 f_print(fout, "const ");
1162 if (plist->pl.param_flag & OUT_STRING) {
1163 f_print(fout, "%s *%s", plist->pl.param_type,
1164 plist->pl.param_name);
1166 f_print(fout, "%s %s", plist->pl.param_type,
1167 plist->pl.param_name);
1170 f_print(fout, " %s", plist->pl.param_name);
1171 plist->pl.param_flag &= ~PROCESSED_PARAM;
1175 f_print(fout, ")\n");
1180 cs_ProcParams_setup(definition * defp, int split_flag)
1182 proc1_list *plist, *plist1;
1188 f_print(fout, "\tstruct rx_connection *z_conn;\n");
1190 f_print(fout, "\tstruct rx_call *z_call;\n");
1192 for (plist = defp->pc.plists; plist; plist = plist->next) {
1193 if (plist->component_kind == DEF_PARAM
1194 && !(plist->pl.param_flag & PROCESSED_PARAM)) {
1195 if (plist->pl.param_flag & OUT_STRING) {
1196 f_print(fout, "\t%s *%s", plist->pl.param_type,
1197 plist->pl.param_name);
1199 f_print(fout, "\t%s %s", plist->pl.param_type,
1200 plist->pl.param_name);
1202 plist->pl.param_flag |= PROCESSED_PARAM;
1203 for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
1204 if ((plist1->component_kind == DEF_PARAM)
1205 && streq(plist->pl.param_type, plist1->pl.param_type)
1206 && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
1208 char *pntr = strchr(plist1->pl.param_type, '*');
1211 if (plist1->pl.param_flag & OUT_STRING) {
1212 f_print(fout, ", *%s%s", star, plist1->pl.param_name);
1214 f_print(fout, ", %s%s", star, plist1->pl.param_name);
1216 plist1->pl.param_flag |= PROCESSED_PARAM;
1219 f_print(fout, ";\n");
1226 cs_ProcMarshallInParams_setup(definition * defp, int split_flag)
1228 int noofparams, i = 0;
1232 defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT] +
1233 defp->pc.paramtypes[OUT];
1235 f_print(fout, "{\n");
1237 f_print(fout, "\tstruct rx_call *z_call = rx_NewCall(z_conn);\n");
1238 if ((!split_flag) || (split_flag == 1)) {
1239 if (opcodesnotallowed[PackageIndex]) {
1240 f_print(fout, "\tstatic int z_op = %d;\n",
1241 defp->pc.proc_opcodenum);
1243 f_print(fout, "\tstatic int z_op = %s;\n",
1244 defp->pc.proc_opcodename);
1247 f_print(fout, "\tint z_result;\n");
1248 if (!(split_flag > 1) || (noofallparams != 0)) {
1249 f_print(fout, "\tXDR z_xdrs;\n");
1252 if ((!split_flag) || (split_flag == 1)) {
1253 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_ENCODE);\n");
1254 f_print(fout, "\n\t/* Marshal the arguments */\n");
1255 f_print(fout, "\tif ((!xdr_int(&z_xdrs, &z_op))");
1256 noofparams = defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT];
1257 for (plist = defp->pc.plists, dl = defp->def.st.decls; plist;
1258 plist = plist->next, dl = dl->next) {
1259 if (plist->component_kind == DEF_PARAM
1260 && (plist->pl.param_kind == DEF_INPARAM
1261 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1262 f_print(fout, "\n\t || (!%s)", plist->code);
1263 if (++i == noofparams) {
1265 ") {\n\t\tz_result = RXGEN_CC_MARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1272 ") {\n\t\tz_result = RXGEN_CC_MARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1280 cs_ProcSendPacket_setup(definition * defp, int split_flag)
1282 int noofoutparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1284 if (noofoutparams) {
1285 f_print(fout, "\t/* Un-marshal the reply arguments */\n");
1287 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
1289 f_print(fout, "\tz_xdrs.x_op = XDR_DECODE;\n");
1296 cs_ProcUnmarshallOutParams_setup(definition * defp)
1302 noofparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1304 for (plist = defp->pc.plists, dl = defp->def.st.decls, i = 0; plist;
1305 plist = plist->next, dl = dl->next) {
1306 if (plist->component_kind == DEF_PARAM
1307 && (plist->pl.param_kind == DEF_OUTPARAM
1308 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1310 f_print(fout, "\tif ((!%s)", plist->code);
1312 f_print(fout, "\n\t || (!%s)", plist->code);
1314 if (++i == noofparams) {
1316 ") {\n\t\tz_result = RXGEN_CC_UNMARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1325 cs_ProcTail_setup(definition * defp, int split_flag)
1327 f_print(fout, "\tz_result = RXGEN_SUCCESS;\n");
1328 if (defp->can_fail) {
1329 f_print(fout, "fail:\n");
1332 f_print(fout, "\tz_result = rx_EndCall(z_call, z_result);\n");
1334 if (xflag && split_flag != 1) {
1335 f_print(fout, "\tif (rx_enable_stats) {\n");
1336 if (PackageStatIndex[PackageIndex]) {
1338 "\t rx_RecordCallStatistics(z_call, %s,\n",
1339 PackageStatIndex[PackageIndex]);
1342 "\t rx_RecordCallStatistics(z_call, \n"
1343 "\t\t(((afs_uint32)(ntohs(rx_ServiceIdOf(rx_ConnectionOf(z_call))) << 16)) |\n"
1344 "\t\t((afs_uint32)ntohs(rx_PortOf(rx_PeerOf(rx_ConnectionOf(z_call)))))),\n");
1346 f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, 1);\n",
1347 no_of_stat_funcs, PackagePrefix[PackageIndex]);
1348 f_print(fout, "\t}\n\n");
1350 f_print(fout, "\treturn z_result;\n}\n\n");
1355 ss_Proc_CodeGeneration(definition * defp)
1358 ss_ProcName_setup(defp);
1360 ss_ProcParams_setup(defp);
1361 ss_ProcSpecial_setup(defp);
1362 ss_ProcUnmarshallInParams_setup(defp);
1363 ss_ProcCallRealProc_setup(defp);
1364 ss_ProcMarshallOutParams_setup(defp);
1365 ss_ProcTail_setup(defp);
1371 ss_ProcName_setup(definition * defp)
1375 if ((strlen(prefix) + strlen(PackagePrefix[PackageIndex]) +
1376 strlen(defp->pc.proc_name)) >= MAX_FUNCTION_NAME_LEN) {
1377 error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
1381 f_print(fout, "static afs_int32 _%s%s%s(", prefix,
1382 PackagePrefix[PackageIndex], defp->pc.proc_name);
1383 f_print(fout, "struct rx_call *z_call, XDR *z_xdrs)\n{\n");
1384 f_print(fout, "\t" "afs_int32 z_result;\n");
1386 for (plist = defp->pc.plists; plist; plist = plist->next)
1387 if (plist->component_kind == DEF_PARAM) {
1388 plist->pl.param_flag &= ~(PROCESSED_PARAM);
1389 plist->pl.string_name = NULL;
1396 ss_ProcParams_setup(definition * defp)
1398 proc1_list *plist, *plist1;
1402 for (plist = defp->pc.plists; plist; plist = plist->next) {
1403 if ((plist->component_kind == DEF_PARAM)
1404 && !(plist->pl.param_flag & PROCESSED_PARAM)) {
1405 if (plist->pl.param_flag & INDIRECT_PARAM) {
1406 char pres = '\0', *pntr = strchr(plist->pl.param_type, '*');
1412 f_print(fout, "\t%s %s", plist->pl.param_type,
1413 plist->pl.param_name);
1415 } else if (strchr(plist->pl.param_type, '*') == 0) {
1416 f_print(fout, "\t%s %s", plist->pl.param_type,
1417 plist->pl.param_name);
1419 plist->pl.param_flag |= FREETHIS_PARAM;
1420 f_print(fout, "\t%s %s=(%s)0", plist->pl.param_type,
1421 plist->pl.param_name, plist->pl.param_type);
1423 plist->pl.param_flag |= PROCESSED_PARAM;
1424 for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
1425 if ((plist1->component_kind == DEF_PARAM)
1426 && streq(plist->pl.param_type, plist1->pl.param_type)
1427 && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
1428 if (plist1->pl.param_flag & INDIRECT_PARAM) {
1429 f_print(fout, ", %s", plist1->pl.param_name);
1430 } else if (strchr(plist1->pl.param_type, '*') == 0) {
1431 f_print(fout, ", %s", plist1->pl.param_name);
1433 plist1->pl.param_flag |= FREETHIS_PARAM;
1434 f_print(fout, ", *%s=(%s)0", plist1->pl.param_name,
1435 plist1->pl.param_type);
1437 plist1->pl.param_flag |= PROCESSED_PARAM;
1440 f_print(fout, ";\n");
1443 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1444 defp1 = (definition *) listp->val;
1445 for (plist = defp->pc.plists; plist; plist = plist->next) {
1446 if (plist->component_kind == DEF_PARAM
1447 && (plist->pl.param_kind == DEF_OUTPARAM
1448 || plist->pl.param_kind == DEF_INOUTPARAM)
1449 && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1450 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1451 switch (defp1->pc.rel) {
1461 fprintf(fout, "\n");
1466 ss_ProcSpecial_setup(definition * defp)
1472 for (listp = special_defined; listp != NULL; listp = listp->next) {
1473 defp1 = (definition *) listp->val;
1475 for (plist = defp->pc.plists; plist; plist = plist->next) {
1476 if (plist->component_kind == DEF_PARAM
1477 && (plist->pl.param_kind == DEF_INPARAM
1478 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1479 spec_list *spec = defp1->def.sd.specs;
1481 strcpy(string, structname(spec->sdef.string_value));
1482 if (streq(string, structname(plist->pl.param_type))) {
1483 plist->pl.string_name = spec->sdef.string_name;
1484 plist->pl.param_flag |= FREETHIS_PARAM;
1485 fprintf(fout, "\n\t%s.%s = 0;", plist->pl.param_name,
1486 spec->sdef.string_name);
1491 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1492 defp1 = (definition *) listp->val;
1493 for (plist = defp->pc.plists; plist; plist = plist->next) {
1494 if (plist->component_kind == DEF_PARAM) {
1495 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1496 plist->pl.param_flag |= FREETHIS_PARAM;
1497 switch (defp1->pc.rel) {
1499 plist->pl.string_name = alloc(40);
1501 f_print(fout, "\n\t%s.val = 0;",
1502 plist->pl.param_name);
1503 f_print(fout, "\n\t%s.len = 0;",
1504 plist->pl.param_name);
1505 s_print(plist->pl.string_name, "val");
1507 f_print(fout, "\n\t%s.%s_val = 0;",
1508 plist->pl.param_name, defp1->def_name);
1509 f_print(fout, "\n\t%s.%s_len = 0;",
1510 plist->pl.param_name, defp1->def_name);
1511 s_print(plist->pl.string_name, "%s_val",
1516 f_print(fout, "\n\t%s = 0;", plist->pl.param_name);
1517 plist->pl.string_name = NULL;
1526 for (listp = complex_defined; listp != NULL; listp = listp->next) {
1527 defp1 = (definition *) listp->val;
1528 for (plist = defp->pc.plists; plist; plist = plist->next) {
1529 if (plist->component_kind == DEF_PARAM) {
1530 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1531 plist->pl.param_flag |= FREETHIS_PARAM;
1532 fprintf(fout, "\n\tmemset(&%s, 0, sizeof(%s));",
1533 plist->pl.param_name, defp1->def_name);
1539 f_print(fout, "\n");
1544 ss_ProcUnmarshallInParams_setup(definition * defp)
1546 int noofparams, noofoutparams, i;
1549 noofparams = defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT];
1550 noofoutparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1551 for (plist = defp->pc.plists, i = 0; plist; plist = plist->next) {
1552 if (plist->component_kind == DEF_PARAM
1553 && (plist->pl.param_kind == DEF_INPARAM
1554 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1556 f_print(fout, "\n\tif ((!%s)",
1557 (plist->scode ? plist->scode : plist->code));
1559 f_print(fout, "\n\t || (!%s)",
1560 (plist->scode ? plist->scode : plist->code));
1562 if (++i == noofparams) {
1563 if (!noofoutparams) {
1564 f_print(fout, ") {\n");
1566 f_print(fout, ") {\n");
1569 "\t\tz_result = RXGEN_SS_UNMARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1578 ss_ProcCallRealProc_setup(definition * defp)
1583 f_print(fout, "\tz_result = %s%s%s%s(z_call", prefix, ServerPrefix,
1584 PackagePrefix[PackageIndex], defp->pc.proc_name);
1585 for (plist = defp->pc.plists; plist; plist = plist->next) {
1586 if (plist->component_kind == DEF_PARAM) {
1587 if (plist->pl.param_flag & INDIRECT_PARAM) {
1588 f_print(fout, ", &%s", plist->pl.param_name);
1590 if (plist->pl.param_flag & OUT_STRING) {
1591 f_print(fout, ", &%s", plist->pl.param_name);
1593 f_print(fout, ", %s", plist->pl.param_name);
1598 f_print(fout, ");\n");
1600 f_print(fout, "\tif (z_result)\n\t\treturn z_result;\n");
1606 ss_ProcMarshallOutParams_setup(definition * defp)
1611 noofparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1613 f_print(fout, "\tz_xdrs->x_op = XDR_ENCODE;\n");
1615 for (plist = defp->pc.plists, i = 0; plist; plist = plist->next) {
1616 if (plist->component_kind == DEF_PARAM
1617 && (plist->pl.param_kind == DEF_OUTPARAM
1618 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1620 f_print(fout, "\tif ((!%s)",
1621 (plist->scode ? plist->scode : plist->code));
1623 f_print(fout, "\n\t || (!%s)",
1624 (plist->scode ? plist->scode : plist->code));
1626 if (++i == noofparams) {
1627 f_print(fout, ")\n\t\tz_result = RXGEN_SS_MARSHAL;\n");
1635 ss_ProcTail_frees(char *xdrfunc, int *somefrees) {
1637 f_print(fout, "\tz_xdrs->x_op = XDR_FREE;\n");
1638 f_print(fout, "\tif ((!%s)", xdrfunc);
1641 f_print(fout, "\n\t || (!%s)", xdrfunc);
1647 ss_ProcTail_setup(definition * defp)
1654 if (defp->can_fail) {
1655 f_print(fout, "fail:\n");
1658 for (plist = defp->pc.plists; plist; plist = plist->next) {
1659 if (plist->component_kind == DEF_PARAM
1660 && (plist->pl.param_flag & FREETHIS_PARAM))
1661 ss_ProcTail_frees(plist->scode, &somefrees);
1664 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1665 defp1 = (definition *) listp->val;
1666 for (plist = defp->pc.plists; plist; plist = plist->next) {
1667 if (plist->component_kind == DEF_PARAM
1668 && (plist->pl.param_kind == DEF_OUTPARAM
1669 || plist->pl.param_kind == DEF_INOUTPARAM)
1670 && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1671 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1672 switch (defp1->pc.rel) {
1675 ss_ProcTail_frees(plist->scode, &somefrees);
1685 for (listp = uniondef_defined; listp != NULL; listp = listp->next) {
1686 defp1 = (definition *) listp->val;
1687 for (plist = defp->pc.plists; plist; plist = plist->next) {
1688 if (plist->component_kind == DEF_PARAM
1689 && (plist->pl.param_kind == DEF_OUTPARAM
1690 || plist->pl.param_kind == DEF_INOUTPARAM)
1691 && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1692 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1693 if (plist->pl.param_flag & INDIRECT_PARAM) {
1694 ss_ProcTail_frees(plist->scode, &somefrees);
1702 f_print(fout, ")\n");
1703 f_print(fout, "\t\tz_result = RXGEN_SS_XDRFREE;\n\n");
1707 f_print(fout, "\tif (rx_enable_stats) {\n");
1708 f_print(fout, "\t rx_RecordCallStatistics(z_call,");
1709 if (PackageStatIndex[PackageIndex]) {
1710 f_print(fout, " %s,\n", PackageStatIndex[PackageIndex]);
1713 "\n\t\t(((afs_uint32)(ntohs(rx_ServiceIdOf(rx_ConnectionOf(z_call))) << 16)) |\n"
1714 "\t\t((afs_uint32)ntohs(rx_ServiceOf(rx_ConnectionOf(z_call))->servicePort))),\n");
1716 f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, 0);\n",
1717 no_of_stat_funcs, PackagePrefix[PackageIndex]);
1718 f_print(fout, "\t}\n\n");
1721 f_print(fout, "\treturn z_result;\n");
1722 f_print(fout, "}\n\n");
1727 ucs_ProcName_setup(definition * defp, char *procheader, int split_flag)
1733 f_print(fout, "int %s%s%s%s(struct ubik_client *aclient, afs_int32 aflags",
1734 procheader, prefix, PackagePrefix[PackageIndex],
1735 defp->pc.proc_name);
1737 f_print(fout, "int %s%s%s%s(aclient, aflags", procheader, prefix,
1738 PackagePrefix[PackageIndex], defp->pc.proc_name);
1741 if ((strlen(procheader) + strlen(prefix) +
1742 strlen(PackagePrefix[PackageIndex]) + strlen(defp->pc.proc_name)) >=
1743 MAX_FUNCTION_NAME_LEN) {
1744 error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
1747 for (plist = defp->pc.plists; plist; plist = plist->next) {
1748 if (plist->component_kind == DEF_PARAM) {
1751 if (plist->pl.param_kind == DEF_INPARAM &&
1752 strcmp(plist->pl.param_type, "char *") == 0) {
1753 f_print(fout, "const ");
1755 if (plist->pl.param_flag & OUT_STRING) {
1756 f_print(fout, "%s *%s", plist->pl.param_type,
1757 plist->pl.param_name);
1759 f_print(fout, "%s %s", plist->pl.param_type,
1760 plist->pl.param_name);
1763 plist->pl.param_flag &= ~PROCESSED_PARAM;
1764 f_print(fout, " %s", plist->pl.param_name);
1768 f_print(fout, ")\n");
1774 ucs_ProcParams_setup(definition * defp, int split_flag)
1776 proc1_list *plist, *plist1;
1781 f_print(fout, "\tstruct ubik_client *aclient;\n\tafs_int32 aflags;\n");
1782 for (plist = defp->pc.plists; plist; plist = plist->next) {
1783 if (plist->component_kind == DEF_PARAM
1784 && !(plist->pl.param_flag & PROCESSED_PARAM)) {
1785 if (plist->pl.param_flag & OUT_STRING) {
1786 f_print(fout, "\t%s *%s", plist->pl.param_type,
1787 plist->pl.param_name);
1789 f_print(fout, "\t%s %s", plist->pl.param_type,
1790 plist->pl.param_name);
1792 plist->pl.param_flag |= PROCESSED_PARAM;
1793 for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
1794 if ((plist1->component_kind == DEF_PARAM)
1795 && streq(plist->pl.param_type, plist1->pl.param_type)
1796 && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
1798 char *pntr = strchr(plist1->pl.param_type, '*');
1801 if (plist1->pl.param_flag & OUT_STRING) {
1802 f_print(fout, ", *%s%s", star, plist1->pl.param_name);
1804 f_print(fout, ", %s%s", star, plist1->pl.param_name);
1806 plist1->pl.param_flag |= PROCESSED_PARAM;
1809 f_print(fout, ";\n");
1815 ucs_ProcTail_setup(definition * defp, int split_flag)
1819 f_print(fout, "{\tafs_int32 rcode, code, newHost, thisHost, i, _ucount;\n");
1820 f_print(fout, "\tint chaseCount, pass, needsync;\n");
1821 #if 0 /* goes with block below */
1822 f_print(fout, "\tint j, inlist;\n");
1824 f_print(fout, "\tstruct rx_connection *tc;\n");
1825 f_print(fout, "\tstruct rx_peer *rxp;\n");
1826 f_print(fout, "\tshort origLevel;\n\n");
1827 f_print(fout, "\tif (!aclient)\n");
1828 f_print(fout, "\t\treturn UNOENT;\n");
1829 f_print(fout, "\tLOCK_UBIK_CLIENT(aclient);\n\n");
1830 f_print(fout, "\t restart:\n");
1831 f_print(fout, "\torigLevel = aclient->initializationState;\n");
1832 f_print(fout, "\trcode = UNOSERVERS;\n");
1833 f_print(fout, "\tchaseCount = needsync = 0;\n\n");
1834 #if 0 /* We should do some sort of caching algorithm for this, but I need to think about it - shadow 26 jun 06 */
1835 f_print(fout, "\tinlist = 0;\n");
1836 f_print(fout, "\tLOCK_UCLNT_CACHE;\n");
1837 f_print(fout, "\tfor (j = 0; ((j < SYNCCOUNT) && calls_needsync[j]); j++) {\n");
1838 f_print(fout, "\t\tif (calls_needsync[j] == (int *)%s%s%s) {\n", prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
1839 f_print(fout, "\t\t\tinlist = needsync = 1;\n");
1840 f_print(fout, "\t\t\tbreak;\n");
1841 f_print(fout, "\t\t}\n");
1842 f_print(fout, "\t}\n");
1843 f_print(fout, "\tUNLOCK_UCLNT_CACHE;\n");
1845 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");
1846 f_print(fout, "\tfor (pass = 0; pass < 2; pass++) { /*p */\n");
1847 f_print(fout, "\t\t/* For each entry in our servers list */\n");
1848 f_print(fout, "\t\tfor (_ucount = 0;; _ucount++) { /*s */\n\n");
1849 f_print(fout, "\t\tif (needsync) {\n");
1850 f_print(fout, "\t\t\t/* Need a sync site. Lets try to quickly find it */\n");
1851 f_print(fout, "\t\t\tif (aclient->syncSite) {\n");
1852 f_print(fout, "\t\t\t\tnewHost = aclient->syncSite; /* already in network order */\n");
1853 f_print(fout, "\t\t\t\taclient->syncSite = 0; /* Will reset if it works */\n");
1854 f_print(fout, "\t\t\t} else if (aclient->conns[3]) {\n");
1855 f_print(fout, "\t\t\t\t/* If there are fewer than four db servers in a cell,\n");
1856 f_print(fout, "\t\t\t\t* there's no point in making the GetSyncSite call.\n");
1857 f_print(fout, "\t\t\t\t* At best, it's a wash. At worst, it results in more\n");
1858 f_print(fout, "\t\t\t\t* RPCs than you would otherwise make.\n");
1859 f_print(fout, "\t\t\t\t*/\n");
1860 f_print(fout, "\t\t\t\ttc = aclient->conns[_ucount];\n");
1861 f_print(fout, "\t\t\t\tif (tc && rx_ConnError(tc)) {\n");
1862 f_print(fout, "\t\t\t\t\taclient->conns[_ucount] = tc = ubik_RefreshConn(tc);\n");
1863 f_print(fout, "\t\t\t\t}\n");
1864 f_print(fout, "\t\t\t\tif (!tc)\n");
1865 f_print(fout, "\t\t\t\t\tbreak;\n");
1866 f_print(fout, "\t\t\t\tcode = VOTE_GetSyncSite(tc, &newHost);\n");
1867 f_print(fout, "\t\t\t\tif (aclient->initializationState != origLevel)\n");
1868 f_print(fout, "\t\t\t\t\tgoto restart; /* somebody did a ubik_ClientInit */\n");
1869 f_print(fout, "\t\t\t\tif (code)\n");
1870 f_print(fout, "\t\t\t\t\tnewHost = 0;\n");
1871 f_print(fout, "\t\t\t\tnewHost = htonl(newHost); /* convert to network order */\n");
1872 f_print(fout, "\t\t\t} else {\n");
1873 f_print(fout, "\t\t\t\tnewHost = 0;\n");
1874 f_print(fout, "\t\t\t}\n");
1875 f_print(fout, "\t\t\tif (newHost) {\n");
1876 f_print(fout, "\t\t\t\t/* position count at the appropriate slot in the client\n");
1877 f_print(fout, "\t\t\t\t* structure and retry. If we can't find in slot, we'll\n");
1878 f_print(fout, "\t\t\t\t* just continue through the whole list \n");
1879 f_print(fout, "\t\t\t\t*/\n");
1880 f_print(fout, "\t\t\t\tfor (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {\n");
1881 f_print(fout, "\t\t\t\t\trxp = rx_PeerOf(aclient->conns[i]);\n");
1882 f_print(fout, "\t\t\t\t\tthisHost = rx_HostOf(rxp);\n");
1883 f_print(fout, "\t\t\t\t\tif (!thisHost)\n");
1884 f_print(fout, "\t\t\t\t\t\tbreak;\n");
1885 f_print(fout, "\t\t\t\t\tif (thisHost == newHost) {\n");
1886 f_print(fout, "\t\t\t\t\t\tif (chaseCount++ > 2)\n");
1887 f_print(fout, "\t\t\t\t\t\t\tbreak; /* avoid loop asking */\n");
1888 f_print(fout, "\t\t\t\t\t\t_ucount = i; /* this index is the sync site */\n");
1889 f_print(fout, "\t\t\t\t\t\tbreak;\n");
1890 f_print(fout, "\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n");
1891 f_print(fout, "\t\t/*needsync */\n");
1892 f_print(fout, "\t\ttc = aclient->conns[_ucount];\n");
1893 f_print(fout, "\t\tif (tc && rx_ConnError(tc)) {\n");
1894 f_print(fout, "\t\t\taclient->conns[_ucount] = tc = ubik_RefreshConn(tc);\n");
1895 f_print(fout, "\t\t}\n");
1896 f_print(fout, "\t\tif (!tc)\n");
1897 f_print(fout, "\t\t\tbreak;\n\n");
1898 f_print(fout, "\t\tif ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {\n");
1899 f_print(fout, "\t\t\tcontinue; /* this guy's down */\n");
1900 f_print(fout, "\t\t}\n");
1902 f_print(fout, "\t\trcode = %s%s%s(tc\n", prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
1903 for (plist = defp->pc.plists; plist; plist = plist->next) {
1904 if (plist->component_kind == DEF_PARAM) {
1905 plist->pl.param_flag &= ~PROCESSED_PARAM;
1906 f_print(fout, ", %s", plist->pl.param_name);
1909 f_print(fout, ");\n");
1910 f_print(fout, "\t\tif (aclient->initializationState != origLevel) {\n");
1911 f_print(fout, "\t\t\t/* somebody did a ubik_ClientInit */\n");
1912 f_print(fout, "\t\t\tif (rcode)\n");
1913 f_print(fout, "\t\t\t\tgoto restart; /* call failed */\n");
1914 f_print(fout, "\t\t\telse\n");
1915 f_print(fout, "\t\t\t\tgoto done; /* call suceeded */\n");
1916 f_print(fout, "\t\t}\n");
1917 f_print(fout, "\t\tif (rcode < 0) { /* network errors */\n");
1918 f_print(fout, "\t\t\taclient->states[_ucount] |= CFLastFailed; /* Mark server down */\n");
1919 f_print(fout, "\t\t} else if (rcode == UNOTSYNC) {\n");
1920 f_print(fout, "\t\t\tneedsync = 1;\n");
1921 f_print(fout, "\t\t} else if (rcode != UNOQUORUM) {\n");
1922 f_print(fout, "\t\t\t/* either misc ubik code, or misc appl code, or success. */\n");
1923 f_print(fout, "\t\t\taclient->states[_ucount] &= ~CFLastFailed; /* mark server up*/\n");
1924 f_print(fout, "\t\t\tgoto done; /* all done */\n");
1925 f_print(fout, "\t\t}\n");
1926 f_print(fout, "\t\t} /*s */\n");
1927 f_print(fout, "\t} /*p */\n\n");
1928 f_print(fout, "\tdone:\n");
1929 f_print(fout, "\tif (needsync) {\n");
1931 #if 0 /* We should do some sort of caching algorithm for this, but I need to think about it - shadow 26 jun 06 */
1932 f_print(fout, "\t\tif (!inlist) { /* Remember proc call that needs sync site */\n");
1933 f_print(fout, "\t\t\tLOCK_UCLNT_CACHE;\n");
1934 f_print(fout, "\t\t\tcalls_needsync[synccount % SYNCCOUNT] = (int *)%s%s%s;\n", prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
1935 f_print(fout, "\t\t\tsynccount++;\n");
1936 f_print(fout, "\t\t\tUNLOCK_UCLNT_CACHE;\n");
1937 f_print(fout, "\t\t\tinlist = 1;\n");
1938 f_print(fout, "\t\t}\n");
1940 f_print(fout, "\t\tif (!rcode) { /* Remember the sync site - cmd successful */\n");
1941 f_print(fout, "\t\t\trxp = rx_PeerOf(aclient->conns[_ucount]);\n");
1942 f_print(fout, "\t\t\taclient->syncSite = rx_HostOf(rxp);\n");
1943 f_print(fout, "\t\t}\n");
1944 f_print(fout, "\t}\n");
1945 f_print(fout, "\tUNLOCK_UBIK_CLIENT(aclient);\n");
1946 f_print(fout, "\treturn rcode;\n}\n\n");
1951 opcode_holes_exist(void)
1955 for (i = lowest_opcode[PackageIndex]; i < highest_opcode[PackageIndex];
1957 if (!opcodenum_is_defined(i))
1965 er_Proc_CodeGeneration(void)
1969 temp = PackageIndex;
1970 if (!combinepackages)
1972 for (; PackageIndex <= temp; PackageIndex++) {
1973 if (proc_defined[PackageIndex] == NULL)
1975 if (combinepackages || opcode_holes_exist()) {
1976 er_HeadofOldStyleProc_setup();
1977 er_BodyofOldStyleProc_setup();
1978 er_TailofOldStyleProc_setup();
1979 er_HeadofOldStyleProc_setup2();
1980 er_BodyofOldStyleProc_setup2();
1981 er_TailofOldStyleProc_setup2();
1983 er_ProcDeclExterns_setup();
1984 er_ProcProcsArray_setup();
1985 er_ProcMainBody_setup();
1988 PackageIndex = temp;
1993 er_ProcDeclExterns_setup(void)
2001 f_print(fout, "\n");
2002 for (listp = proc_defined[PackageIndex]; listp != NULL;
2003 listp = listp->next) {
2004 defp = (definition *) listp->val;
2005 if (defp->pc.proc_serverstub) {
2006 f_print(fout, "afs_int32 %s();\n", defp->pc.proc_serverstub);
2013 er_ProcProcsArray_setup(void)
2018 if ((listp = proc_defined[PackageIndex])) {
2019 defp = (definition *) listp->val;
2021 f_print(fout, "\nstatic char *opnames%d[] = {\"%s%s\"",
2022 PackageIndex, defp->pc.proc_prefix, defp->pc.proc_name);
2025 if (defp->pc.proc_serverstub) {
2026 f_print(fout, "\nstatic afs_int32 (*StubProcsArray%d[])() = {%s",
2027 PackageIndex, defp->pc.proc_serverstub);
2030 "\nstatic afs_int32 (*StubProcsArray%d[])(struct rx_call *z_call, XDR *z_xdrs) = {_%s%s%s",
2031 PackageIndex, prefix, defp->pc.proc_prefix,
2032 ((definition *) listp->val)->pc.proc_name);
2033 defp = (definition *) listp->val;
2036 listp = listp->next;
2038 for (; listp != NULL; listp = listp->next) {
2039 defp = (definition *) listp->val;
2041 f_print(fout, ", \"%s%s\"",defp->pc.proc_prefix,defp->pc.proc_name);
2044 if (defp->pc.proc_serverstub) {
2045 f_print(fout, ",%s", defp->pc.proc_serverstub);
2047 f_print(fout, ", _%s%s%s", prefix, defp->pc.proc_prefix,
2048 defp->pc.proc_name);
2052 f_print(fout, "};\n\n");
2057 er_ProcMainBody_setup(void)
2060 f_print(fout, "char *%sTranslateOpCode(int op)\n{\n",
2061 PackagePrefix[PackageIndex]);
2062 f_print(fout, "\tif (op < %sLOWEST_OPCODE || op > %sHIGHEST_OPCODE)\n\t\treturn NULL;\n",
2063 PackagePrefix[PackageIndex], PackagePrefix[PackageIndex]);
2064 f_print(fout, "\treturn opnames%d[op - %sLOWEST_OPCODE];\n}\n",
2065 PackageIndex, PackagePrefix[PackageIndex]);
2066 f_print(fout, "struct %sstats *%sOpCodeStats(int op)\n{\n",
2067 PackagePrefix[PackageIndex], 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 NULL;/*%d %s*/\n}\n",
2071 PackageIndex, PackagePrefix[PackageIndex]);
2075 f_print(fout, "int %s%sExecuteRequest(struct rx_call *z_call)\n",
2076 prefix, PackagePrefix[PackageIndex]);
2077 f_print(fout, "{\n\tint op;\n");
2078 f_print(fout, "\tXDR z_xdrs;\n");
2079 f_print(fout, "\t" "afs_int32 z_result;\n\n");
2080 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
2082 "\tif (!xdr_int(&z_xdrs, &op))\n\t\tz_result = RXGEN_DECODE;\n");
2084 "\telse if (op < %sLOWEST_OPCODE || op > %sHIGHEST_OPCODE)\n\t\tz_result = RXGEN_OPCODE;\n",
2085 PackagePrefix[PackageIndex], PackagePrefix[PackageIndex]);
2087 "\telse\n\t\tz_result = (*StubProcsArray%d[op - %sLOWEST_OPCODE])(z_call, &z_xdrs);\n",
2088 PackageIndex, PackagePrefix[PackageIndex]);
2089 f_print(fout, "\treturn hton_syserr_conv(z_result);\n}\n");
2093 er_HeadofOldStyleProc_setup2(void)
2096 f_print(fout, "int %sOpCodeIndex(int op)\n{\n", (combinepackages ? MasterPrefix : PackagePrefix[PackageIndex]));
2097 f_print(fout, "\tswitch (op) {\n");
2102 er_HeadofOldStyleProc_setup(void)
2105 f_print(fout, "char *%sTranslateOpCode(int op)\n{\n",
2106 (combinepackages ? MasterPrefix : PackagePrefix[PackageIndex]));
2110 "\nint %s%sExecuteRequest (struct rx_call *z_call)\n",
2112 (combinepackages ? MasterPrefix : PackagePrefix[PackageIndex]));
2113 f_print(fout, "{\n");
2114 f_print(fout, "\tint op;\n");
2115 f_print(fout, "\tXDR z_xdrs;\n");
2116 f_print(fout, "\t" "afs_int32 z_result;\n\n");
2117 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
2118 f_print(fout, "\tz_result = RXGEN_DECODE;\n");
2119 f_print(fout, "\tif (!xdr_int(&z_xdrs, &op)) goto fail;\n");
2121 f_print(fout, "\tswitch (op) {\n");
2125 er_BodyofOldStyleProc_setup(void)
2129 if (combinepackages) {
2130 int temp = PackageIndex;
2131 for (PackageIndex = 0; PackageIndex <= temp; PackageIndex++) {
2132 for (listp = proc_defined[PackageIndex]; listp != NULL;
2133 listp = listp->next)
2134 proc_er_case((definition *) listp->val);
2136 PackageIndex = temp;
2138 for (listp = proc_defined[PackageIndex]; listp != NULL;
2139 listp = listp->next)
2140 proc_er_case((definition *) listp->val);
2146 proc_er_case(definition * defp)
2149 f_print(fout, "\t\tcase %d:", defp->pc.proc_opcodenum);
2150 f_print(fout, "\treturn \"%s%s\";\n",
2151 defp->pc.proc_prefix, defp->pc.proc_name);
2154 if (opcodesnotallowed[PackageIndex]) {
2155 f_print(fout, "\t\tcase %d:\n", defp->pc.proc_opcodenum);
2157 f_print(fout, "\t\tcase %s:\n", defp->pc.proc_opcodename);
2159 if (defp->pc.proc_serverstub) {
2160 f_print(fout, "\t\t\tz_result = %s(z_call, &z_xdrs);\n",
2161 defp->pc.proc_serverstub);
2163 f_print(fout, "\t\t\tz_result = _%s%s%s(z_call, &z_xdrs);\n", prefix,
2164 defp->pc.proc_prefix, defp->pc.proc_name);
2166 f_print(fout, "\t\t\tbreak;\n");
2170 proc_op_case(definition * defp)
2172 f_print(fout, "\t\tcase %d:", defp->pc.proc_opcodenum);
2173 f_print(fout, "\treturn %d;\n",
2178 er_BodyofOldStyleProc_setup2(void)
2184 if (combinepackages) {
2185 int temp = PackageIndex;
2186 for (PackageIndex = 0; PackageIndex <= temp; PackageIndex++) {
2187 for (listp = proc_defined[PackageIndex]; listp != NULL;
2188 listp = listp->next)
2189 proc_op_case((definition *) listp->val);
2191 PackageIndex = temp;
2193 for (listp = proc_defined[PackageIndex]; listp != NULL;
2194 listp = listp->next)
2195 proc_op_case((definition *) listp->val);
2200 er_TailofOldStyleProc_setup2(void)
2203 f_print(fout, "\t\tdefault:\n");
2204 f_print(fout, "\t\t\treturn -1;\n\t}\n}\n");
2209 er_TailofOldStyleProc_setup(void)
2211 f_print(fout, "\t\tdefault:\n");
2213 f_print(fout, "\t\t\treturn NULL;\n\t}\n}\n");
2216 f_print(fout, "\t\t\tz_result = RXGEN_OPCODE;\n");
2217 f_print(fout, "\t\t\tbreak;\n\t}\n");
2218 f_print(fout, "fail:\n");
2219 f_print(fout, "\treturn z_result;\n}\n");
2223 h_ProcMainBody_setup(void)
2225 f_print(fout,"\nextern int %s%sExecuteRequest(struct rx_call *);\n",
2226 prefix, PackagePrefix[PackageIndex]);
2230 h_HeadofOldStyleProc_setup(void)
2232 char *pprefix = (combinepackages ? MasterPrefix :
2233 PackagePrefix[PackageIndex]);
2234 f_print(fout,"\nstruct %sstats{\n\tint statsver;\n};", pprefix);
2235 f_print(fout,"\nextern int %s%sExecuteRequest(struct rx_call *);\n",
2237 f_print(fout,"\nextern int %sOpCodeIndex(int op);\n", PackagePrefix[PackageIndex]);
2241 h_Proc_CodeGeneration(void)
2245 temp = PackageIndex;
2246 if (!combinepackages)
2248 for (; PackageIndex <= temp; PackageIndex++) {
2249 if (combinepackages || opcode_holes_exist()) {
2250 h_HeadofOldStyleProc_setup();
2252 h_ProcMainBody_setup();
2255 PackageIndex = temp;
2259 proc_h_case(definition * defp)
2261 f_print(fout, "#define opcode_%s%s \t((afs_uint64)((%uLL << 32) + %sOpCodeIndex(%u)))\n",
2262 defp->pc.proc_prefix, defp->pc.proc_name, StatIndex,
2263 defp->pc.proc_prefix, defp->pc.proc_opcodenum);
2267 h_opcode_stats_pkg(char *pprefix, int lowest, int highest, int nops,
2268 int statfuncs, char *ptype, list *proclist)
2276 "\n/* Opcode-related useful stats for %spackage: %s */\n",
2278 f_print(fout, "#define %sLOWEST_OPCODE %d\n", pprefix, lowest);
2279 f_print(fout, "#define %sHIGHEST_OPCODE %d\n", pprefix, highest);
2280 f_print(fout, "#define %sNUMBER_OPCODES %d\n\n", pprefix, nops);
2282 for (listp = proclist; listp != NULL;
2283 listp = listp->next)
2284 proc_h_case((definition *) listp->val);
2287 f_print(fout, "#define %sNO_OF_STAT_FUNCS\t%d\n\n",
2288 pprefix, statfuncs);
2289 f_print(fout, "AFS_RXGEN_EXPORT\n");
2290 f_print(fout, "extern const char *%sfunction_names[];\n\n",
2296 h_opcode_stats(void)
2298 if (combinepackages) {
2299 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]);
2302 for (i = 0; i <= PackageIndex; i++) {
2303 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]);
2310 generate_multi_macros(definition * defp)
2312 char *startname = SplitStart, *endname = SplitEnd;
2321 f_print(fout, "\n#include <rx/rx_multi.h>");
2323 f_print(fout, "\n#define multi_%s%s(", PackagePrefix[PackageIndex],
2324 defp->pc.proc_name);
2325 for (plist = defp->pc.plists; plist; plist = plist->next) {
2326 if (plist->component_kind == DEF_PARAM) {
2329 f_print(fout, "%s", plist->pl.param_name);
2331 f_print(fout, ", %s", plist->pl.param_name);
2335 f_print(fout, ") \\\n");
2337 startname = "Start";
2340 f_print(fout, "\tmulti_Body(%s%s%s(multi_call", startname,
2341 PackagePrefix[PackageIndex], defp->pc.proc_name);
2342 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 0);
2343 for (plist = defp->pc.plists; plist; plist = plist->next) {
2344 if (plist->component_kind == DEF_PARAM)
2345 f_print(fout, ", %s", plist->pl.param_name);
2347 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 1);
2348 f_print(fout, "), %s%s%s(multi_call", endname,
2349 PackagePrefix[PackageIndex], defp->pc.proc_name);
2350 do_split(defp, IN, &numofparams, DEF_INPARAM, 0);
2351 for (plist = defp->pc.plists; plist; plist = plist->next) {
2352 if (plist->component_kind == DEF_PARAM) {
2353 f_print(fout, ", %s", plist->pl.param_name);
2356 do_split(defp, IN, &numofparams, DEF_INPARAM, 1);
2357 f_print(fout, "))\n\n");
2362 IsRxgenToken(token * tokp)
2364 if (tokp->kind == TOK_PACKAGE || tokp->kind == TOK_PREFIX
2365 || tokp->kind == TOK_SPECIAL || tokp->kind == TOK_STARTINGOPCODE
2366 || tokp->kind == TOK_SPLITPREFIX || tokp->kind == TOK_PROC
2367 || tokp->kind == TOK_STATINDEX)
2373 IsRxgenDefinition(definition * def)
2375 if (def->def_kind == DEF_PACKAGE || def->def_kind == DEF_PREFIX
2376 || def->def_kind == DEF_SPECIAL || def->def_kind == DEF_STARTINGOPCODE
2377 || def->def_kind == DEF_SPLITPREFIX || def->def_kind == DEF_PROC)