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>
52 #include "rpc_parse.h"
55 list *proc_defined[MAX_PACKAGES], *special_defined, *typedef_defined,
57 char *SplitStart = NULL;
58 char *SplitEnd = NULL;
59 char *MasterPrefix = NULL;
60 char *ServerPrefix = "";
61 char *PackagePrefix[MAX_PACKAGES];
62 char *PackageStatIndex[MAX_PACKAGES];
63 int no_of_stat_funcs = 0; /*
64 * current function number in client interface
67 int no_of_stat_funcs_header[MAX_PACKAGES]; /*
68 * Total number of functions in client
71 int no_of_opcodes[MAX_PACKAGES], master_no_of_opcodes = 0;
72 int lowest_opcode[MAX_PACKAGES], master_lowest_opcode = 99999;
73 int highest_opcode[MAX_PACKAGES], master_highest_opcode = 0;
74 int master_opcodenumber = 99999;
75 int opcodesnotallowed[MAX_PACKAGES];
76 int combinepackages = 0;
77 int PackageIndex = -1;
78 int PerProcCounter = 0;
82 * Character arrays to keep list of function names as we process the file
85 char function_list[MAX_PACKAGES]
86 [MAX_FUNCTIONS_PER_PACKAGE]
87 [MAX_FUNCTION_NAME_LEN];
88 int function_list_index;
90 /* static prototypes */
91 static void isdefined(definition * defp);
92 static void def_struct(definition * defp);
93 static void def_program(definition * defp);
94 static void def_enum(definition * defp);
95 static void def_const(definition * defp);
96 static void def_union(definition * defp);
97 static void def_typedef(definition * defp);
98 static void get_declaration(declaration * dec, defkind dkind);
99 static void get_type(char **prefixp, char **typep, defkind dkind);
100 static void unsigned_dec(char **typep);
101 static void def_package(definition * defp);
102 static void def_prefix(definition * defp);
103 static void def_statindex(definition * defp);
104 static void def_startingopcode(definition * defp);
105 static void def_split(definition * defp);
106 static void customize_struct(definition * defp);
107 static char *structname(char *name);
108 static void def_special(declaration * dec, definition * defp);
109 static void check_proc(definition * defp, token * tokp, int noname);
110 static int InvalidConstant(char *name);
111 static int opcodenum_is_defined(int opcode_num);
112 static void analyze_ProcParams(definition * defp, token * tokp);
113 static void generate_code(definition * defp, int proc_split_flag,
115 static void handle_split_proc(definition * defp, int multi_flag);
116 static void do_split(definition * defp, int direction, int *numofparams,
117 defkind param_kind, int restore_flag);
118 static void hdle_param_tok(definition * defp, declaration * dec, token * tokp,
120 static void get1_param_type(definition * defp, declaration * dec,
122 static void get_param_type(definition * defp, declaration * dec,
123 char **param_type, char **typename);
125 static void hndle_param_tail(definition * defp, declaration * dec,
126 token * tokp, char *typename);
128 static void cs_Proc_CodeGeneration(definition * defp, int split_flag,
130 static void cs_ProcName_setup(definition * defp, char *procheader,
132 static void cs_ProcParams_setup(definition * defp, int split_flag);
133 static void cs_ProcMarshallInParams_setup(definition * defp, int split_flag);
134 static void cs_ProcSendPacket_setup(definition * defp, int split_flag);
135 static void cs_ProcUnmarshallOutParams_setup(definition * defp);
136 static void cs_ProcTail_setup(definition * defp, int split_flag);
137 static void ss_Proc_CodeGeneration(definition * defp);
138 static void ss_ProcName_setup(definition * defp);
139 static void ss_ProcParams_setup(definition * defp, int *somefrees);
140 static void ss_ProcSpecial_setup(definition * defp, int *somefrees);
141 static void ss_ProcUnmarshallInParams_setup(definition * defp);
142 static void ss_ProcCallRealProc_setup(definition * defp);
143 static void ss_ProcMarshallOutParams_setup(definition * defp);
144 static void ss_ProcTail_setup(definition * defp, int somefrees);
145 static int opcode_holes_exist(void);
146 static void er_ProcDeclExterns_setup(void);
147 static void er_ProcProcsArray_setup(void);
148 static void er_ProcMainBody_setup(void);
149 static void er_HeadofOldStyleProc_setup(void);
150 static void er_BodyofOldStyleProc_setup(void);
151 static void proc_er_case(definition * defp);
152 static void er_TailofOldStyleProc_setup(void);
157 * return the next definition you see
165 defp = ALLOC(definition);
166 memset((char *)defp, 0, sizeof(definition));
202 def_special(&dec, defp);
205 case TOK_STARTINGOPCODE:
206 def_startingopcode(defp);
211 customize_struct(defp);
213 case TOK_SPLITPREFIX:
218 if (tok.kind == TOK_LPAREN) {
220 check_proc(defp, &tok, 1);
222 check_proc(defp, &tok, 0);
225 check_proc(defp, &tok, 0);
229 check_proc(defp, &tok, 1);
232 error("definition keyword expected");
234 if (!IsRxgenToken(&tok)) {
235 scan(TOK_SEMICOLON, &tok);
243 isdefined(definition * defp)
245 STOREVAL(&defined, defp);
250 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 decls = ALLOC(decl_list);
268 tailp = &decls->next;
269 scan(TOK_SEMICOLON, &tok);
271 } while (tok.kind != TOK_RBRACE);
277 def_program(definition * defp)
281 version_list **vtailp;
285 defp->def_kind = DEF_PROGRAM;
286 scan(TOK_IDENT, &tok);
287 defp->def_name = tok.str;
288 scan(TOK_LBRACE, &tok);
289 vtailp = &defp->def.pr.versions;
290 scan(TOK_VERSION, &tok);
292 scan(TOK_IDENT, &tok);
293 vlist = ALLOC(version_list);
294 vlist->vers_name = tok.str;
295 scan(TOK_LBRACE, &tok);
296 ptailp = &vlist->procs;
298 plist = ALLOC(proc_list);
299 get_type(&plist->res_prefix, &plist->res_type, DEF_PROGRAM);
300 if (streq(plist->res_type, "opaque")) {
301 error("illegal result type");
303 scan(TOK_IDENT, &tok);
304 plist->proc_name = tok.str;
305 scan(TOK_LPAREN, &tok);
306 get_type(&plist->arg_prefix, &plist->arg_type, DEF_PROGRAM);
307 if (streq(plist->arg_type, "opaque")) {
308 error("illegal argument type");
310 scan(TOK_RPAREN, &tok);
311 scan(TOK_EQUAL, &tok);
313 scan(TOK_SEMICOLON, &tok);
314 plist->proc_num = tok.str;
316 ptailp = &plist->next;
318 } while (tok.kind != TOK_RBRACE);
320 vtailp = &vlist->next;
321 scan(TOK_RBRACE, &tok);
322 scan(TOK_EQUAL, &tok);
324 vlist->vers_num = tok.str;
325 scan(TOK_SEMICOLON, &tok);
326 scan2(TOK_VERSION, TOK_RBRACE, &tok);
327 } while (tok.kind == TOK_VERSION);
328 scan(TOK_EQUAL, &tok);
330 defp->def.pr.prog_num = tok.str;
335 def_enum(definition * defp)
339 enumval_list **tailp;
341 defp->def_kind = DEF_ENUM;
342 scan(TOK_IDENT, &tok);
343 defp->def_name = tok.str;
344 scan(TOK_LBRACE, &tok);
345 tailp = &defp->def.en.vals;
347 scan(TOK_IDENT, &tok);
348 elist = ALLOC(enumval_list);
349 elist->name = tok.str;
350 elist->assignment = NULL;
351 scan3(TOK_COMMA, TOK_RBRACE, TOK_EQUAL, &tok);
352 if (tok.kind == TOK_EQUAL) {
354 elist->assignment = tok.str;
355 scan2(TOK_COMMA, TOK_RBRACE, &tok);
358 tailp = &elist->next;
359 } while (tok.kind != TOK_RBRACE);
364 def_const(definition * defp)
368 defp->def_kind = DEF_CONST;
369 scan(TOK_IDENT, &tok);
370 defp->def_name = tok.str;
371 scan(TOK_EQUAL, &tok);
372 scan2(TOK_IDENT, TOK_STRCONST, &tok);
373 defp->def.co = tok.str;
377 def_union(definition * defp)
384 defp->def_kind = DEF_UNION;
385 scan(TOK_IDENT, &tok);
386 defp->def_name = tok.str;
387 scan(TOK_SWITCH, &tok);
388 scan(TOK_LPAREN, &tok);
389 get_declaration(&dec, DEF_UNION);
390 defp->def.un.enum_decl = dec;
391 tailp = &defp->def.un.cases;
392 scan(TOK_RPAREN, &tok);
393 scan(TOK_LBRACE, &tok);
394 scan(TOK_CASE, &tok);
395 while (tok.kind == TOK_CASE) {
396 scan(TOK_IDENT, &tok);
397 cases = ALLOC(case_list);
398 cases->case_name = tok.str;
399 scan(TOK_COLON, &tok);
400 get_declaration(&dec, DEF_UNION);
401 cases->case_decl = dec;
403 tailp = &cases->next;
404 scan(TOK_SEMICOLON, &tok);
405 scan3(TOK_CASE, TOK_DEFAULT, TOK_RBRACE, &tok);
408 if (tok.kind == TOK_DEFAULT) {
409 scan(TOK_COLON, &tok);
410 get_declaration(&dec, DEF_UNION);
411 defp->def.un.default_decl = ALLOC(declaration);
412 *defp->def.un.default_decl = dec;
413 scan(TOK_SEMICOLON, &tok);
414 scan(TOK_RBRACE, &tok);
416 defp->def.un.default_decl = NULL;
422 def_typedef(definition * defp)
426 defp->def_kind = DEF_TYPEDEF;
427 get_declaration(&dec, DEF_TYPEDEF);
428 defp->def_name = dec.name;
429 defp->def.ty.old_prefix = dec.prefix;
430 defp->def.ty.old_type = dec.type;
431 defp->def.ty.rel = dec.rel;
432 defp->def.ty.array_max = dec.array_max;
437 get_declaration(declaration * dec, defkind dkind)
441 get_type(&dec->prefix, &dec->type, dkind);
442 dec->rel = REL_ALIAS;
443 if (streq(dec->type, "void")) {
446 scan2(TOK_STAR, TOK_IDENT, &tok);
447 if (tok.kind == TOK_STAR) {
448 dec->rel = REL_POINTER;
449 scan(TOK_IDENT, &tok);
452 if (peekscan(TOK_LBRACKET, &tok)) {
453 if (dec->rel == REL_POINTER) {
454 error("no array-of-pointer declarations -- use typedef");
456 dec->rel = REL_VECTOR;
458 dec->array_max = tok.str;
459 scan(TOK_RBRACKET, &tok);
460 } else if (peekscan(TOK_LANGLE, &tok)) {
461 if (dec->rel == REL_POINTER) {
462 error("no array-of-pointer declarations -- use typedef");
464 dec->rel = REL_ARRAY;
465 if (peekscan(TOK_RANGLE, &tok)) {
466 dec->array_max = "~0"; /* unspecified size, use max */
469 dec->array_max = tok.str;
470 scan(TOK_RANGLE, &tok);
473 if (streq(dec->type, "opaque")) {
474 if (dec->rel != REL_ARRAY && dec->rel != REL_VECTOR) {
475 error("array declaration expected");
477 } else if (streq(dec->type, "string")) {
478 if (dec->rel != REL_ARRAY) {
479 error(" variable-length array declaration expected");
486 get_type(char **prefixp, char **typep, defkind dkind)
500 scan(TOK_IDENT, &tok);
508 (void)peekscan(TOK_INT, &tok);
511 *typep = "afs_int32";
512 (void)peekscan(TOK_INT, &tok);
515 if (dkind != DEF_UNION && dkind != DEF_PROGRAM) {
516 error("voids allowed only inside union and program definitions");
531 error("expected type specifier");
537 unsigned_dec(char **typep)
550 (void)peekscan(TOK_INT, &tok);
554 *typep = "afs_uint32";
555 (void)peekscan(TOK_INT, &tok);
569 def_package(definition * defp)
573 defp->def_kind = DEF_PACKAGE;
574 scan(TOK_IDENT, &tok);
575 defp->def_name = tok.str;
576 no_of_stat_funcs = 0;
577 if (PackageIndex++ >= MAX_PACKAGES)
578 error("Exceeded upper limit of package statements\n");
579 function_list_index = 0;
580 PackagePrefix[PackageIndex] = tok.str;
581 if (MasterPrefix == NULL)
582 MasterPrefix = tok.str;
583 no_of_opcodes[PackageIndex] = highest_opcode[PackageIndex] =
584 opcodesnotallowed[PackageIndex] = 0;
585 lowest_opcode[PackageIndex] = 99999;
586 proc_defined[PackageIndex] = NULL;
587 PackageStatIndex[PackageIndex] = NULL;
591 def_prefix(definition * defp)
595 defp->def_kind = DEF_PREFIX;
596 scan(TOK_IDENT, &tok);
597 defp->def_name = tok.str;
598 ServerPrefix = tok.str;
602 def_statindex(definition * defp)
607 defp->def_kind = DEF_CONST;
609 if (PackageIndex < 0)
610 error("'statindex' command must follow 'package' command!\n");
611 if (PackageStatIndex[PackageIndex])
612 error("Cannot have more then one 'statindex' per package!\n");
613 if (InvalidConstant(tok.str))
614 error("Index in 'statindex' command must be a constant!");
616 alloc(strlen(PackagePrefix[PackageIndex]) + strlen("STATINDEX") + 1);
617 strcpy(name, PackagePrefix[PackageIndex]);
618 strcat(name, "STATINDEX");
619 defp->def_name = name;
620 defp->def.co = tok.str;
621 PackageStatIndex[PackageIndex] = name;
625 def_startingopcode(definition * defp)
629 defp->def_kind = DEF_STARTINGOPCODE;
630 scan(TOK_IDENT, &tok);
631 defp->def_name = tok.str;
632 if (InvalidConstant(defp->def_name))
633 error("Opcode in 'startingopcode' command must be a constant!");
634 lowest_opcode[PackageIndex] = master_lowest_opcode = atoi(tok.str);
635 if (lowest_opcode[PackageIndex] < 0
636 || lowest_opcode[PackageIndex] > 99999)
638 ("startingopcode number is out of bounds (must be >= 0 < 100000)");
639 master_opcodenumber = lowest_opcode[PackageIndex];
640 opcodesnotallowed[PackageIndex] = 1;
644 def_split(definition * defp)
648 defp->def_kind = DEF_SPLITPREFIX;
653 scan(TOK_EQUAL, &tok);
654 scan(TOK_IDENT, &tok);
655 SplitStart = tok.str;
658 scan(TOK_EQUAL, &tok);
659 scan(TOK_IDENT, &tok);
665 error("syntax error in the 'splitprefix' line");
667 } while (tok.kind != TOK_SEMICOLON);
668 if (!SplitStart && !SplitEnd)
669 error("At least one param should be passed to 'splitprefix' cmd");
674 customize_struct(definition * defp)
678 definition *defp1 = ALLOC(definition);
679 spec_list *specs, **tailp;
681 defp->def_kind = DEF_CUSTOMIZED;
682 defp1->def_kind = DEF_SPECIAL;
683 tailp = &defp1->def.sd.specs;
684 for (listp = defp->def.st.decls; listp; listp = listp->next) {
686 if (streq(dec->type, "string") || (dec->rel == REL_POINTER)) {
687 specs = ALLOC(spec_list);
688 specs->sdef.string_name = dec->name;
689 specs->sdef.string_value = defp->def_name;
691 tailp = &specs->next;
695 STOREVAL(&special_defined, defp1);
699 structname(char *name)
701 static char namecontents[150];
704 strcpy(namecontents, name);
706 if (!strncmp(pnt, "struct", 6))
708 while (isspace(*pnt))
711 while (*pnt != ' ' && *pnt != '\0')
719 def_special(declaration * dec, definition * defp)
722 spec_list *specs, **tailp;
725 defp->def_kind = DEF_SPECIAL;
726 get_type(&dec->prefix, &dec->type, DEF_SPECIAL);
727 dec->rel = REL_POINTER;
728 scan(TOK_IDENT, &tok);
729 tailp = &defp->def.sd.specs;
731 specs = ALLOC(spec_list);
732 specs->sdef.string_name = tok.str;
733 get_param_type(defp, dec, &specs->sdef.string_value, &typename);
735 tailp = &specs->next;
736 scan2(TOK_COMMA, TOK_SEMICOLON, &tok);
737 if (tok.kind == TOK_SEMICOLON)
740 } while (tok.kind == TOK_IDENT);
742 STOREVAL(&special_defined, defp);
746 proc1_list *Proc_list, **Proc_listp;
749 check_proc(definition * defp, token * tokp, int noname)
755 if (PackageIndex < 0)
756 error("Procedure must be in a package!\n");
758 tokp->kind = TOK_PROC;
759 defp->def_kind = DEF_PROC;
761 defp->pc.proc_name = "";
763 defp->pc.proc_name = tokp->str;
765 defp->pc.proc_prefix = alloc(strlen(PackagePrefix[PackageIndex]) + 1);
766 strcpy(defp->pc.proc_prefix, PackagePrefix[PackageIndex]);
767 scan2(TOK_LPAREN, TOK_IDENT, &tok);
768 defp->pc.proc_serverstub = NULL;
769 if (tok.kind == TOK_IDENT) {
770 defp->pc.proc_serverstub = tok.str;
771 scan(TOK_LPAREN, &tok);
773 analyze_ProcParams(defp, &tok);
774 defp->pc.proc_opcodenum = -1;
775 scan4(TOK_SPLIT, TOK_MULTI, TOK_EQUAL, TOK_SEMICOLON, &tok);
776 if (tok.kind == TOK_MULTI) {
778 defp->pc.multi_flag = 1;
779 scan2(TOK_EQUAL, TOK_SEMICOLON, &tok);
781 defp->pc.multi_flag = 0;
783 if (tok.kind == TOK_SPLIT) {
785 defp->pc.split_flag = 1;
786 scan2(TOK_EQUAL, TOK_SEMICOLON, &tok);
788 defp->pc.split_flag = 0;
790 if (tok.kind == TOK_EQUAL) {
791 if (opcodesnotallowed[PackageIndex])
792 error("Opcode assignment isn't allowed here!");
794 if (InvalidConstant(tok.str))
795 error("Illegal Opcode assignment (Must be a constant opcode!)");
796 if (opcodenum_is_defined(atoi(tok.str)))
797 error("The opcode number is already used by a previous proc");
798 defp->pc.proc_opcodename = tok.str;
799 defp->pc.proc_opcodenum = atoi(tok.str);
800 if (defp->pc.proc_opcodenum < lowest_opcode[PackageIndex])
801 lowest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
802 if (defp->pc.proc_opcodenum < master_lowest_opcode)
803 master_lowest_opcode = defp->pc.proc_opcodenum;
804 if (defp->pc.proc_opcodenum > highest_opcode[PackageIndex])
805 highest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
806 if (defp->pc.proc_opcodenum > master_highest_opcode)
807 master_highest_opcode = defp->pc.proc_opcodenum;
808 scan(TOK_SEMICOLON, &tok);
810 if (master_opcodenumber == 99999)
811 master_opcodenumber = 0;
812 defp->pc.proc_opcodenum = master_opcodenumber++;
813 if (defp->pc.proc_opcodenum < lowest_opcode[PackageIndex])
814 lowest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
815 if (defp->pc.proc_opcodenum > highest_opcode[PackageIndex])
816 highest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
817 if (defp->pc.proc_opcodenum > master_highest_opcode)
818 master_highest_opcode = defp->pc.proc_opcodenum;
819 opcodesnotallowed[PackageIndex] = 1; /* force it */
821 no_of_opcodes[PackageIndex]++, master_no_of_opcodes++;
823 generate_code(defp, 0, 1);
824 if (Cflag || cflag) {
825 generate_code(defp, 1, 1);
827 generate_multi_macros(defp);
829 generate_code(defp, proc_split, 0);
832 if (function_list_index >= MAX_FUNCTIONS_PER_INTERFACE) {
833 error("too many functions in interface, "
834 "increase MAX_FUNCTIONS_PER_INTERFACE");
836 sprintf(function_list[PackageIndex][function_list_index], "%s%s%s",
837 prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
839 function_list_index++;
840 no_of_stat_funcs_header[PackageIndex]++;
846 #define LEGALNUMS "0123456789"
848 InvalidConstant(char *name)
854 slen = (int)strlen(name);
855 return (slen != strspn(name, map));
859 opcodenum_is_defined(int opcode_num)
864 for (listp = proc_defined[PackageIndex]; listp != NULL;
865 listp = listp->next) {
866 defp = (definition *) listp->val;
867 if (opcode_num == defp->pc.proc_opcodenum)
875 analyze_ProcParams(definition * defp, token * tokp)
878 decl_list *decls, **tailp;
880 Proc_listp = &defp->pc.plists;
881 tailp = &defp->def.st.decls;
884 Proc_list = ALLOC(proc1_list);
885 memset((char *)Proc_list, 0, sizeof(proc1_list));
886 Proc_list->pl.param_flag = 0;
887 switch (tokp->kind) {
889 hdle_param_tok(defp, &dec, tokp, DEF_INPARAM);
892 hdle_param_tok(defp, &dec, tokp, DEF_OUTPARAM);
895 hdle_param_tok(defp, &dec, tokp, DEF_INOUTPARAM);
901 hdle_param_tok(defp, &dec, tokp, DEF_NULL);
904 *Proc_listp = Proc_list;
905 Proc_listp = &Proc_list->next;
906 decls = ALLOC(decl_list);
907 memset((char *)decls, 0, sizeof(decl_list));
908 if (tokp->kind != TOK_RPAREN)
911 tailp = &decls->next;
912 } while (tokp->kind != TOK_RPAREN);
918 generate_code(definition * defp, int proc_split_flag, int multi_flag)
921 handle_split_proc(defp, multi_flag);
923 if (Cflag || cflag) {
924 cs_Proc_CodeGeneration(defp, 0, "");
927 ss_Proc_CodeGeneration(defp);
930 STOREVAL(&proc_defined[PackageIndex], defp);
935 handle_split_proc(definition * defp, int multi_flag)
937 char *startname = SplitStart, *endname = SplitEnd;
944 if (Cflag || cflag) {
946 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 0);
948 cs_Proc_CodeGeneration(defp, 1, startname);
950 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 1);
951 do_split(defp, IN, &numofparams, DEF_INPARAM, 0);
953 cs_Proc_CodeGeneration(defp, (multi_flag ? 3 : 2), endname);
955 do_split(defp, IN, &numofparams, DEF_INPARAM, 1);
959 ss_Proc_CodeGeneration(defp);
964 do_split(definition * defp, int direction, int *numofparams,
965 defkind param_kind, int restore_flag)
970 defp->pc.paramtypes[direction] = *numofparams;
971 for (plist = defp->pc.plists; plist; plist = plist->next) {
972 if (plist->component_kind == DEF_NULL
973 && plist->pl.param_kind == param_kind)
974 plist->component_kind = DEF_PARAM;
977 *numofparams = defp->pc.paramtypes[direction];
978 defp->pc.paramtypes[direction] = 0;
979 for (plist = defp->pc.plists; plist; plist = plist->next) {
980 if (plist->component_kind == DEF_PARAM
981 && plist->pl.param_kind == param_kind)
982 plist->component_kind = DEF_NULL;
989 hdle_param_tok(definition * defp, declaration * dec, token * tokp,
992 static defkind last_param_kind = DEF_NULL;
994 if (par_kind == DEF_NULL)
995 Proc_list->pl.param_kind = last_param_kind;
997 Proc_list->pl.param_kind = par_kind;
998 last_param_kind = Proc_list->pl.param_kind;
999 defp->pc.paramtypes[(int)last_param_kind]++;
1000 Proc_list->component_kind = DEF_PARAM;
1001 Proc_list->code = alloc(250);
1002 Proc_list->scode = alloc(250);
1003 get_declaration(dec, DEF_PARAM);
1004 Proc_list->pl.param_name = dec->name;
1005 get1_param_type(defp, dec, &Proc_list->pl.param_type);
1007 scan2(TOK_COMMA, TOK_RPAREN, tokp);
1008 if (tokp->kind == TOK_COMMA)
1014 get1_param_type(definition * defp, declaration * dec, char **param_type)
1016 char typecontents[100];
1018 if (streq(dec->type, "string")) {
1019 *param_type = "char *";
1022 strcpy(typecontents, dec->prefix);
1023 strcat(typecontents, " ");
1024 strcat(typecontents, dec->type);
1025 strcat(typecontents, " *");
1026 } else if (dec->rel == REL_POINTER) {
1027 strcpy(typecontents, dec->type);
1028 strcat(typecontents, " *");
1030 strcpy(typecontents, dec->type);
1031 *param_type = alloc(100);
1032 strcpy(*param_type, typecontents);
1038 get_param_type(definition * defp, declaration * dec, char **param_type,
1041 char typecontents[100];
1043 if (streq(dec->type, "string")) {
1044 *typename = "wrapstring";
1045 *param_type = "char *";
1047 *typename = dec->type;
1049 strcpy(typecontents, dec->prefix);
1050 strcat(typecontents, " ");
1051 strcat(typecontents, dec->type);
1052 strcat(typecontents, " *");
1053 dec->rel = REL_POINTER;
1054 } else if (dec->rel == REL_POINTER) {
1055 strcpy(typecontents, dec->type);
1056 strcat(typecontents, " *");
1058 strcpy(typecontents, dec->type);
1059 *param_type = alloc(100);
1060 strcpy(*param_type, typecontents);
1067 hndle_param_tail(definition * defp, declaration * dec, token * tokp,
1072 if (dec->rel == REL_POINTER)
1073 Proc_list->pl.param_flag |= INDIRECT_PARAM;
1075 Proc_list->pl.param_flag &= ~INDIRECT_PARAM;
1077 if (!(Proc_list->pl.param_flag & INDIRECT_PARAM))
1080 sprintf(Proc_list->code, "xdr_%s(&z_xdrs, %s%s)", typename, amp,
1081 Proc_list->pl.param_name);
1082 sprintf(Proc_list->scode, "xdr_%s(z_xdrs, &%s)", typename,
1083 Proc_list->pl.param_name);
1084 scan2(TOK_COMMA, TOK_RPAREN, tokp);
1085 if (tokp->kind == TOK_COMMA)
1092 cs_Proc_CodeGeneration(definition * defp, int split_flag, char *procheader)
1095 cs_ProcName_setup(defp, procheader, split_flag);
1097 cs_ProcParams_setup(defp, split_flag);
1098 cs_ProcMarshallInParams_setup(defp, split_flag);
1099 if (split_flag != 1) {
1100 cs_ProcSendPacket_setup(defp, split_flag);
1101 cs_ProcUnmarshallOutParams_setup(defp);
1103 cs_ProcTail_setup(defp, split_flag);
1109 cs_ProcName_setup(definition * defp, char *procheader, int split_flag)
1115 f_print(fout, "int %s%s%s%s(z_call", procheader, prefix,
1116 PackagePrefix[PackageIndex], defp->pc.proc_name);
1118 f_print(fout, "int %s%s%s%s(z_conn", procheader, prefix,
1119 PackagePrefix[PackageIndex], defp->pc.proc_name);
1122 if ((strlen(procheader) + strlen(prefix) +
1123 strlen(PackagePrefix[PackageIndex]) + strlen(defp->pc.proc_name)) >=
1124 MAX_FUNCTION_NAME_LEN) {
1125 error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
1128 for (plist = defp->pc.plists; plist; plist = plist->next) {
1129 if (plist->component_kind == DEF_PARAM) {
1130 plist->pl.param_flag &= ~PROCESSED_PARAM;
1131 f_print(fout, ", %s", plist->pl.param_name);
1134 f_print(fout, ")\n");
1140 cs_ProcParams_setup(definition * defp, int split_flag)
1142 proc1_list *plist, *plist1;
1145 f_print(fout, "\tregister struct rx_connection *z_conn;\n");
1147 f_print(fout, "\tregister struct rx_call *z_call;\n");
1149 for (plist = defp->pc.plists; plist; plist = plist->next) {
1150 if (plist->component_kind == DEF_PARAM
1151 && !(plist->pl.param_flag & PROCESSED_PARAM)) {
1152 if (plist->pl.param_flag & OUT_STRING) {
1153 f_print(fout, "\t%s *%s", plist->pl.param_type,
1154 plist->pl.param_name);
1156 f_print(fout, "\t%s %s", plist->pl.param_type,
1157 plist->pl.param_name);
1159 plist->pl.param_flag |= PROCESSED_PARAM;
1160 for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
1161 if ((plist1->component_kind == DEF_PARAM)
1162 && streq(plist->pl.param_type, plist1->pl.param_type)
1163 && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
1165 char *pntr = strchr(plist1->pl.param_type, '*');
1168 if (plist1->pl.param_flag & OUT_STRING) {
1169 f_print(fout, ", *%s%s", star, plist1->pl.param_name);
1171 f_print(fout, ", %s%s", star, plist1->pl.param_name);
1173 plist1->pl.param_flag |= PROCESSED_PARAM;
1176 f_print(fout, ";\n");
1183 cs_ProcMarshallInParams_setup(definition * defp, int split_flag)
1185 int noofparams, i = 0;
1189 defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT] +
1190 defp->pc.paramtypes[OUT];
1192 f_print(fout, "{\n");
1194 f_print(fout, "\tstruct rx_call *z_call = rx_NewCall(z_conn);\n");
1195 if ((!split_flag) || (split_flag == 1)) {
1196 if (opcodesnotallowed[PackageIndex]) {
1197 f_print(fout, "\tstatic int z_op = %d;\n",
1198 defp->pc.proc_opcodenum);
1200 f_print(fout, "\tstatic int z_op = %s;\n",
1201 defp->pc.proc_opcodename);
1204 f_print(fout, "\tint z_result;\n");
1205 if (!(split_flag > 1) || (noofallparams != 0)) {
1206 f_print(fout, "\tXDR z_xdrs;\n");
1209 * Print out client side stat gathering call
1211 if (xflag && split_flag != 1) {
1212 f_print(fout, "\tstruct clock __QUEUE, __EXEC;\n");
1215 if ((!split_flag) || (split_flag == 1)) {
1216 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_ENCODE);\n");
1217 f_print(fout, "\n\t/* Marshal the arguments */\n");
1218 f_print(fout, "\tif ((!xdr_int(&z_xdrs, &z_op))");
1219 noofparams = defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT];
1220 for (plist = defp->pc.plists, dl = defp->def.st.decls; plist;
1221 plist = plist->next, dl = dl->next) {
1222 if (plist->component_kind == DEF_PARAM
1223 && (plist->pl.param_kind == DEF_INPARAM
1224 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1225 f_print(fout, "\n\t || (!%s)", plist->code);
1226 if (++i == noofparams) {
1228 ") {\n\t\tz_result = RXGEN_CC_MARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1235 ") {\n\t\tz_result = RXGEN_CC_MARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1243 cs_ProcSendPacket_setup(definition * defp, int split_flag)
1245 int noofoutparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1247 if (noofoutparams) {
1248 f_print(fout, "\t/* Un-marshal the reply arguments */\n");
1250 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
1252 f_print(fout, "\tz_xdrs.x_op = XDR_DECODE;\n");
1259 cs_ProcUnmarshallOutParams_setup(definition * defp)
1265 noofparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1267 for (plist = defp->pc.plists, dl = defp->def.st.decls, i = 0; plist;
1268 plist = plist->next, dl = dl->next) {
1269 if (plist->component_kind == DEF_PARAM
1270 && (plist->pl.param_kind == DEF_OUTPARAM
1271 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1273 f_print(fout, "\tif ((!%s)", plist->code);
1275 f_print(fout, "\n\t || (!%s)", plist->code);
1277 if (++i == noofparams) {
1279 ") {\n\t\tz_result = RXGEN_CC_UNMARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1288 cs_ProcTail_setup(definition * defp, int split_flag)
1290 f_print(fout, "\tz_result = RXGEN_SUCCESS;\n");
1291 if (defp->can_fail) {
1292 f_print(fout, "fail:\n");
1295 f_print(fout, "\tz_result = rx_EndCall(z_call, z_result);\n");
1297 if (xflag && split_flag != 1) {
1298 f_print(fout, "\tif (rx_enable_stats) {\n");
1299 f_print(fout, "\t clock_GetTime(&__EXEC);\n");
1300 f_print(fout, "\t clock_Sub(&__EXEC, &z_call->startTime);\n");
1301 f_print(fout, "\t __QUEUE = z_call->startTime;\n");
1302 f_print(fout, "\t clock_Sub(&__QUEUE, &z_call->queueTime);\n");
1303 if (PackageStatIndex[PackageIndex]) {
1306 "\t rx_IncrementTimeAndCount(z_conn->peer, %s,\n",
1307 PackageStatIndex[PackageIndex]);
1310 "\t rx_IncrementTimeAndCount(z_call->conn->peer, %s,\n",
1311 PackageStatIndex[PackageIndex]);
1316 "\t rx_IncrementTimeAndCount(z_conn->peer,\n"
1317 "\t\t(((afs_uint32)(ntohs(z_conn->serviceId) << 16)) \n"
1318 "\t\t| ((afs_uint32)ntohs(z_conn->peer->port))),\n");
1321 "\t rx_IncrementTimeAndCount(z_call->conn->peer,\n"
1322 "\t\t(((afs_uint32)(ntohs(z_call->conn->serviceId) << 16)) |\n"
1323 "\t\t((afs_uint32)ntohs(z_call->conn->peer->port))),\n");
1327 f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, &__QUEUE, &__EXEC,\n",
1328 no_of_stat_funcs, PackagePrefix[PackageIndex]);
1330 "\t\t&z_call->bytesSent, &z_call->bytesRcvd, 1);\n");
1332 f_print(fout, "\t}\n\n");
1334 f_print(fout, "\treturn z_result;\n}\n\n");
1339 ss_Proc_CodeGeneration(definition * defp)
1344 ss_ProcName_setup(defp);
1346 ss_ProcParams_setup(defp, &somefrees);
1347 ss_ProcSpecial_setup(defp, &somefrees);
1348 ss_ProcUnmarshallInParams_setup(defp);
1349 ss_ProcCallRealProc_setup(defp);
1350 ss_ProcMarshallOutParams_setup(defp);
1351 ss_ProcTail_setup(defp, somefrees);
1357 ss_ProcName_setup(definition * defp)
1361 if ((strlen(prefix) + strlen(PackagePrefix[PackageIndex]) +
1362 strlen(defp->pc.proc_name)) >= MAX_FUNCTION_NAME_LEN) {
1363 error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
1367 f_print(fout, "static afs_int32 _%s%s%s(", prefix,
1368 PackagePrefix[PackageIndex], defp->pc.proc_name);
1369 f_print(fout, "struct rx_call *z_call, XDR *z_xdrs)\n{\n");
1370 f_print(fout, "\t" "afs_int32 z_result;\n");
1372 f_print(fout, "\tstruct clock __QUEUE, __EXEC;\n");
1375 for (plist = defp->pc.plists; plist; plist = plist->next)
1376 if (plist->component_kind == DEF_PARAM) {
1377 plist->pl.param_flag &= ~(PROCESSED_PARAM);
1378 plist->pl.string_name = NULL;
1385 ss_ProcParams_setup(definition * defp, int *somefrees)
1387 proc1_list *plist, *plist1;
1391 for (plist = defp->pc.plists; plist; plist = plist->next) {
1392 if ((plist->component_kind == DEF_PARAM)
1393 && !(plist->pl.param_flag & PROCESSED_PARAM)) {
1394 if (plist->pl.param_flag & INDIRECT_PARAM) {
1395 char pres = '\0', *pntr = strchr(plist->pl.param_type, '*');
1401 f_print(fout, "\t%s %s", plist->pl.param_type,
1402 plist->pl.param_name);
1404 } else if (strchr(plist->pl.param_type, '*') == 0) {
1405 f_print(fout, "\t%s %s", plist->pl.param_type,
1406 plist->pl.param_name);
1408 plist->pl.param_flag |= FREETHIS_PARAM;
1410 f_print(fout, "\t%s %s=(%s)0", plist->pl.param_type,
1411 plist->pl.param_name, plist->pl.param_type);
1413 plist->pl.param_flag |= PROCESSED_PARAM;
1414 for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
1415 if ((plist1->component_kind == DEF_PARAM)
1416 && streq(plist->pl.param_type, plist1->pl.param_type)
1417 && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
1418 if (plist1->pl.param_flag & INDIRECT_PARAM) {
1419 f_print(fout, ", %s", plist1->pl.param_name);
1420 } else if (strchr(plist1->pl.param_type, '*') == 0) {
1421 f_print(fout, ", %s", plist1->pl.param_name);
1423 plist1->pl.param_flag |= FREETHIS_PARAM;
1425 f_print(fout, ", *%s=(%s)0", plist1->pl.param_name,
1426 plist1->pl.param_type);
1428 plist1->pl.param_flag |= PROCESSED_PARAM;
1431 f_print(fout, ";\n");
1434 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1435 defp1 = (definition *) listp->val;
1436 for (plist = defp->pc.plists; plist; plist = plist->next) {
1437 if (plist->component_kind == DEF_PARAM
1438 && (plist->pl.param_kind == DEF_OUTPARAM
1439 || plist->pl.param_kind == DEF_INOUTPARAM)
1440 && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1441 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1442 switch (defp1->pc.rel) {
1451 fprintf(fout, "\n");
1456 ss_ProcSpecial_setup(definition * defp, int *somefrees)
1462 for (listp = special_defined; listp != NULL; listp = listp->next) {
1463 defp1 = (definition *) listp->val;
1464 for (plist = defp->pc.plists; plist; plist = plist->next) {
1465 if (plist->component_kind == DEF_PARAM
1466 && (plist->pl.param_kind == DEF_INPARAM
1467 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1468 spec_list *spec = defp1->def.sd.specs;
1470 strcpy(string, structname(spec->sdef.string_value));
1471 if (streq(string, structname(plist->pl.param_type))) {
1472 plist->pl.string_name = spec->sdef.string_name;
1473 plist->pl.param_flag |= FREETHIS_PARAM;
1475 fprintf(fout, "\n\t%s.%s = 0;", plist->pl.param_name,
1476 spec->sdef.string_name);
1482 fprintf(fout, "\n");
1483 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1484 defp1 = (definition *) listp->val;
1485 for (plist = defp->pc.plists; plist; plist = plist->next) {
1486 if (plist->component_kind == DEF_PARAM) {
1487 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1488 plist->pl.param_flag |= FREETHIS_PARAM;
1490 switch (defp1->pc.rel) {
1492 f_print(fout, "\n\t%s.%s_val = 0;",
1493 plist->pl.param_name, defp1->def_name);
1494 f_print(fout, "\n\t%s.%s_len = 0;",
1495 plist->pl.param_name, defp1->def_name);
1496 plist->pl.string_name = alloc(40);
1497 s_print(plist->pl.string_name, "%s_val",
1501 f_print(fout, "\n\t%s = 0;", plist->pl.param_name);
1502 plist->pl.string_name = NULL;
1509 f_print(fout, "\n");
1514 ss_ProcUnmarshallInParams_setup(definition * defp)
1516 int noofparams, noofoutparams, i;
1519 noofparams = defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT];
1520 noofoutparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1521 for (plist = defp->pc.plists, i = 0; plist; plist = plist->next) {
1522 if (plist->component_kind == DEF_PARAM
1523 && (plist->pl.param_kind == DEF_INPARAM
1524 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1526 f_print(fout, "\n\tif ((!%s)",
1527 (plist->scode ? plist->scode : plist->code));
1529 f_print(fout, "\n\t || (!%s)",
1530 (plist->scode ? plist->scode : plist->code));
1532 if (++i == noofparams) {
1533 if (!noofoutparams) {
1534 f_print(fout, ") {\n");
1536 f_print(fout, ") {\n");
1539 "\t\tz_result = RXGEN_SS_UNMARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1548 ss_ProcCallRealProc_setup(definition * defp)
1553 f_print(fout, "\tz_result = %s%s%s%s(z_call", prefix, ServerPrefix,
1554 PackagePrefix[PackageIndex], defp->pc.proc_name);
1555 for (plist = defp->pc.plists; plist; plist = plist->next) {
1556 if (plist->component_kind == DEF_PARAM) {
1557 if (plist->pl.param_flag & INDIRECT_PARAM) {
1558 f_print(fout, ", &%s", plist->pl.param_name);
1560 if (plist->pl.param_flag & OUT_STRING) {
1561 f_print(fout, ", &%s", plist->pl.param_name);
1563 f_print(fout, ", %s", plist->pl.param_name);
1568 f_print(fout, ");\n");
1570 f_print(fout, "\tif (z_result)\n\t\treturn z_result;\n");
1576 ss_ProcMarshallOutParams_setup(definition * defp)
1581 noofparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1583 f_print(fout, "\tz_xdrs->x_op = XDR_ENCODE;\n");
1585 for (plist = defp->pc.plists, i = 0; plist; plist = plist->next) {
1586 if (plist->component_kind == DEF_PARAM
1587 && (plist->pl.param_kind == DEF_OUTPARAM
1588 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1590 f_print(fout, "\tif ((!%s)",
1591 (plist->scode ? plist->scode : plist->code));
1593 f_print(fout, "\n\t || (!%s)",
1594 (plist->scode ? plist->scode : plist->code));
1596 if (++i == noofparams) {
1597 f_print(fout, ")\n\t\tz_result = RXGEN_SS_MARSHAL;\n");
1606 ss_ProcTail_setup(definition * defp, int somefrees)
1613 if (defp->can_fail) {
1614 f_print(fout, "fail:\n");
1616 for (plist = defp->pc.plists; plist; plist = plist->next) {
1617 if (plist->component_kind == DEF_PARAM
1618 && (plist->pl.param_flag & FREETHIS_PARAM))
1622 f_print(fout, "\tz_xdrs->x_op = XDR_FREE;\n");
1623 for (plist = defp->pc.plists; plist; plist = plist->next) {
1624 if (plist->component_kind == DEF_PARAM
1625 && (plist->pl.param_flag & FREETHIS_PARAM)) {
1626 char *dot = "", *extens = "";
1627 if (plist->pl.string_name) {
1629 extens = plist->pl.string_name;
1631 f_print(fout, "\tif (!%s) goto fail1;\n", plist->scode);
1634 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1635 defp1 = (definition *) listp->val;
1636 for (plist = defp->pc.plists; plist; plist = plist->next) {
1637 if (plist->component_kind == DEF_PARAM
1638 && (plist->pl.param_kind == DEF_OUTPARAM
1639 || plist->pl.param_kind == DEF_INOUTPARAM)
1640 && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1641 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1642 switch (defp1->pc.rel) {
1645 if (!somefrees && !firsttime) {
1647 f_print(fout, "\tz_xdrs->x_op = XDR_FREE;\n");
1650 f_print(fout, "\tif (!%s) goto fail1;\n",
1658 for (listp = uniondef_defined; listp != NULL; listp = listp->next) {
1659 defp1 = (definition *) listp->val;
1660 for (plist = defp->pc.plists; plist; plist = plist->next) {
1661 if (plist->component_kind == DEF_PARAM
1662 && (plist->pl.param_kind == DEF_OUTPARAM
1663 || plist->pl.param_kind == DEF_INOUTPARAM)
1664 && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1665 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1666 if (plist->pl.param_flag & INDIRECT_PARAM) {
1667 if (!somefrees && !firsttime) {
1669 f_print(fout, "\tz_xdrs->x_op = XDR_FREE;\n");
1672 f_print(fout, "\tif (!%s) goto fail1;\n",
1681 f_print(fout, "\tif (rx_enable_stats) {\n");
1682 f_print(fout, "\t clock_GetTime(&__EXEC);\n");
1683 f_print(fout, "\t clock_Sub(&__EXEC, &z_call->startTime);\n");
1684 f_print(fout, "\t __QUEUE = z_call->startTime;\n");
1685 f_print(fout, "\t clock_Sub(&__QUEUE, &z_call->queueTime);\n");
1686 f_print(fout, "\t rx_IncrementTimeAndCount(z_call->conn->peer,");
1687 if (PackageStatIndex[PackageIndex]) {
1688 f_print(fout, " %s,\n", PackageStatIndex[PackageIndex]);
1691 "\n\t\t(((afs_uint32)(ntohs(z_call->conn->serviceId) << 16)) |\n"
1692 "\t\t((afs_uint32)ntohs(z_call->conn->service->servicePort))),\n");
1694 f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, &__QUEUE, &__EXEC,\n",
1695 no_of_stat_funcs, PackagePrefix[PackageIndex]);
1696 f_print(fout, "\t\t&z_call->bytesSent, &z_call->bytesRcvd, 0);\n");
1697 f_print(fout, "\t}\n\n");
1700 f_print(fout, "\treturn z_result;\n");
1702 f_print(fout, "fail1:\n");
1705 f_print(fout, "\tif (rx_enable_stats) {\n");
1706 f_print(fout, "\t clock_GetTime(&__EXEC);\n");
1707 f_print(fout, "\t clock_Sub(&__EXEC, &z_call->startTime);\n");
1708 f_print(fout, "\t __QUEUE = z_call->startTime;\n");
1709 f_print(fout, "\t clock_Sub(&__QUEUE, &z_call->queueTime);\n");
1711 "\t rx_IncrementTimeAndCount(z_call->conn->peer,");
1712 if (PackageStatIndex[PackageIndex]) {
1713 f_print(fout, " %s,\n", PackageStatIndex[PackageIndex]);
1716 "\n\t\t(((afs_uint32)(ntohs(z_call->conn->serviceId) << 16)) |\n"
1717 "\t\t((afs_uint32)ntohs(z_call->conn->service->servicePort))),\n");
1719 f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, &__QUEUE, &__EXEC,\n",
1720 no_of_stat_funcs, PackagePrefix[PackageIndex]);
1722 "\t\t&z_call->bytesSent, &z_call->bytesRcvd, 0);\n");
1723 f_print(fout, "\t}\n\n");
1726 f_print(fout, "\treturn RXGEN_SS_XDRFREE;\n}\n\n");
1728 f_print(fout, "}\n\n");
1734 opcode_holes_exist(void)
1738 for (i = lowest_opcode[PackageIndex]; i < highest_opcode[PackageIndex];
1740 if (!opcodenum_is_defined(i))
1748 er_Proc_CodeGeneration(void)
1752 temp = PackageIndex;
1753 if (!combinepackages)
1755 for (; PackageIndex <= temp; PackageIndex++) {
1756 if (proc_defined[PackageIndex] == NULL)
1758 if (combinepackages || opcode_holes_exist()) {
1759 er_HeadofOldStyleProc_setup();
1760 er_BodyofOldStyleProc_setup();
1761 er_TailofOldStyleProc_setup();
1763 er_ProcDeclExterns_setup();
1764 er_ProcProcsArray_setup();
1765 er_ProcMainBody_setup();
1768 PackageIndex = temp;
1773 er_ProcDeclExterns_setup(void)
1778 f_print(fout, "\n");
1779 for (listp = proc_defined[PackageIndex]; listp != NULL;
1780 listp = listp->next) {
1781 defp = (definition *) listp->val;
1782 if (defp->pc.proc_serverstub) {
1783 f_print(fout, "afs_int32 %s();\n", defp->pc.proc_serverstub);
1790 er_ProcProcsArray_setup(void)
1795 if ((listp = proc_defined[PackageIndex])) {
1796 defp = (definition *) listp->val;
1797 if (defp->pc.proc_serverstub) {
1798 f_print(fout, "\nstatic afs_int32 (*StubProcsArray%d[])() = {%s",
1799 PackageIndex, defp->pc.proc_serverstub);
1802 "\nstatic afs_int32 (*StubProcsArray%d[])(struct rx_call *z_call, XDR *z_xdrs) = {_%s%s%s",
1803 PackageIndex, prefix, defp->pc.proc_prefix,
1804 ((definition *) listp->val)->pc.proc_name);
1805 defp = (definition *) listp->val;
1807 listp = listp->next;
1809 for (; listp != NULL; listp = listp->next) {
1810 defp = (definition *) listp->val;
1811 if (defp->pc.proc_serverstub) {
1812 f_print(fout, ",%s", defp->pc.proc_serverstub);
1814 f_print(fout, ", _%s%s%s", prefix, defp->pc.proc_prefix,
1815 defp->pc.proc_name);
1818 f_print(fout, "};\n\n");
1823 er_ProcMainBody_setup(void)
1825 f_print(fout, "int %s%sExecuteRequest(register struct rx_call *z_call)\n",
1826 prefix, PackagePrefix[PackageIndex]);
1827 f_print(fout, "{\n\tint op;\n");
1828 f_print(fout, "\tXDR z_xdrs;\n");
1829 f_print(fout, "\t" "afs_int32 z_result;\n\n");
1830 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
1832 "\tif (!xdr_int(&z_xdrs, &op))\n\t\tz_result = RXGEN_DECODE;\n");
1834 "\telse if (op < %sLOWEST_OPCODE || op > %sHIGHEST_OPCODE)\n\t\tz_result = RXGEN_OPCODE;\n",
1835 PackagePrefix[PackageIndex], PackagePrefix[PackageIndex]);
1837 "\telse\n\t\tz_result = (*StubProcsArray%d[op - %sLOWEST_OPCODE])(z_call, &z_xdrs);\n",
1838 PackageIndex, PackagePrefix[PackageIndex]);
1839 f_print(fout, "\treturn hton_syserr_conv(z_result);\n}\n");
1844 er_HeadofOldStyleProc_setup(void)
1847 "\nint %s%sExecuteRequest (register struct rx_call *z_call)\n",
1849 (combinepackages ? MasterPrefix : PackagePrefix[PackageIndex]));
1850 f_print(fout, "{\n");
1851 f_print(fout, "\tint op;\n");
1852 f_print(fout, "\tXDR z_xdrs;\n");
1853 f_print(fout, "\t" "afs_int32 z_result;\n\n");
1854 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
1855 f_print(fout, "\tz_result = RXGEN_DECODE;\n");
1856 f_print(fout, "\tif (!xdr_int(&z_xdrs, &op)) goto fail;\n");
1857 f_print(fout, "\tswitch (op) {\n");
1861 er_BodyofOldStyleProc_setup(void)
1865 if (combinepackages) {
1866 int temp = PackageIndex;
1867 for (PackageIndex = 0; PackageIndex <= temp; PackageIndex++) {
1868 for (listp = proc_defined[PackageIndex]; listp != NULL;
1869 listp = listp->next)
1870 proc_er_case((definition *) listp->val);
1872 PackageIndex = temp;
1874 for (listp = proc_defined[PackageIndex]; listp != NULL;
1875 listp = listp->next)
1876 proc_er_case((definition *) listp->val);
1882 proc_er_case(definition * defp)
1884 if (opcodesnotallowed[PackageIndex]) {
1885 f_print(fout, "\t\tcase %d:\n", defp->pc.proc_opcodenum);
1887 f_print(fout, "\t\tcase %s:\n", defp->pc.proc_opcodename);
1889 if (defp->pc.proc_serverstub) {
1890 f_print(fout, "\t\t\tz_result = %s(z_call, &z_xdrs);\n",
1891 defp->pc.proc_serverstub);
1893 f_print(fout, "\t\t\tz_result = _%s%s%s(z_call, &z_xdrs);\n", prefix,
1894 defp->pc.proc_prefix, defp->pc.proc_name);
1896 f_print(fout, "\t\t\tbreak;\n");
1901 er_TailofOldStyleProc_setup(void)
1903 f_print(fout, "\t\tdefault:\n");
1904 f_print(fout, "\t\t\tz_result = RXGEN_OPCODE;\n");
1905 f_print(fout, "\t\t\tbreak;\n\t}\n");
1906 f_print(fout, "fail:\n");
1907 f_print(fout, "\treturn z_result;\n}\n");
1912 h_opcode_stats(void)
1914 if (combinepackages) {
1916 "\n/* Opcode-related useful stats for Master package: %s */\n",
1918 f_print(fout, "#define %sLOWEST_OPCODE %d\n", MasterPrefix,
1919 master_lowest_opcode);
1920 f_print(fout, "#define %sHIGHEST_OPCODE %d\n", MasterPrefix,
1921 master_highest_opcode);
1922 f_print(fout, "#define %sNUMBER_OPCODES %d\n\n", MasterPrefix,
1923 master_no_of_opcodes);
1925 f_print(fout, "#define %sNO_OF_STAT_FUNCS\t%d\n\n", MasterPrefix,
1926 no_of_stat_funcs_header[0]);
1927 f_print(fout, "AFS_RXGEN_EXPORT\n");
1928 f_print(fout, "extern const char *%sfunction_names[];\n\n",
1933 for (i = 0; i <= PackageIndex; i++) {
1935 "\n/* Opcode-related useful stats for package: %s */\n",
1937 f_print(fout, "#define %sLOWEST_OPCODE %d\n", PackagePrefix[i],
1939 f_print(fout, "#define %sHIGHEST_OPCODE %d\n",
1940 PackagePrefix[i], highest_opcode[i]);
1941 f_print(fout, "#define %sNUMBER_OPCODES %d\n\n",
1942 PackagePrefix[i], no_of_opcodes[i]);
1944 f_print(fout, "#define %sNO_OF_STAT_FUNCS\t%d\n\n",
1945 PackagePrefix[i], no_of_stat_funcs_header[i]);
1946 f_print(fout, "AFS_RXGEN_EXPORT\n");
1947 f_print(fout, "extern const char *%sfunction_names[];\n\n",
1956 generate_multi_macros(definition * defp)
1958 char *startname = SplitStart, *endname = SplitEnd;
1967 f_print(fout, "\n#include <rx/rx_multi.h>");
1969 f_print(fout, "\n#define multi_%s%s(", PackagePrefix[PackageIndex],
1970 defp->pc.proc_name);
1971 for (plist = defp->pc.plists; plist; plist = plist->next) {
1972 if (plist->component_kind == DEF_PARAM) {
1975 f_print(fout, "%s", plist->pl.param_name);
1977 f_print(fout, ", %s", plist->pl.param_name);
1981 f_print(fout, ") \\\n");
1983 startname = "Start";
1986 f_print(fout, "\tmulti_Body(%s%s%s(multi_call", startname,
1987 PackagePrefix[PackageIndex], defp->pc.proc_name);
1988 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 0);
1989 for (plist = defp->pc.plists; plist; plist = plist->next) {
1990 if (plist->component_kind == DEF_PARAM)
1991 f_print(fout, ", %s", plist->pl.param_name);
1993 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 1);
1994 f_print(fout, "), %s%s%s(multi_call", endname,
1995 PackagePrefix[PackageIndex], defp->pc.proc_name);
1996 do_split(defp, IN, &numofparams, DEF_INPARAM, 0);
1997 for (plist = defp->pc.plists; plist; plist = plist->next) {
1998 if (plist->component_kind == DEF_PARAM) {
1999 f_print(fout, ", %s", plist->pl.param_name);
2002 do_split(defp, IN, &numofparams, DEF_INPARAM, 1);
2003 f_print(fout, "))\n\n");
2008 IsRxgenToken(token * tokp)
2010 if (tokp->kind == TOK_PACKAGE || tokp->kind == TOK_PREFIX
2011 || tokp->kind == TOK_SPECIAL || tokp->kind == TOK_STARTINGOPCODE
2012 || tokp->kind == TOK_SPLITPREFIX || tokp->kind == TOK_PROC
2013 || tokp->kind == TOK_STATINDEX)
2019 IsRxgenDefinition(definition * def)
2021 if (def->def_kind == DEF_PACKAGE || def->def_kind == DEF_PREFIX
2022 || def->def_kind == DEF_SPECIAL || def->def_kind == DEF_STARTINGOPCODE
2023 || def->def_kind == DEF_SPLITPREFIX || def->def_kind == DEF_PROC)