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 scan2(TOK_EQUAL, TOK_SEMICOLON, &tok);
780 if (tok.kind == TOK_SPLIT) {
782 defp->pc.split_flag = 1;
783 scan2(TOK_EQUAL, TOK_SEMICOLON, &tok);
785 defp->pc.split_flag = 0;
787 if (tok.kind == TOK_EQUAL) {
788 if (opcodesnotallowed[PackageIndex])
789 error("Opcode assignment isn't allowed here!");
791 if (InvalidConstant(tok.str))
792 error("Illegal Opcode assignment (Must be a constant opcode!)");
793 if (opcodenum_is_defined(atoi(tok.str)))
794 error("The opcode number is already used by a previous proc");
795 defp->pc.proc_opcodename = tok.str;
796 defp->pc.proc_opcodenum = atoi(tok.str);
797 if (defp->pc.proc_opcodenum < lowest_opcode[PackageIndex])
798 lowest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
799 if (defp->pc.proc_opcodenum < master_lowest_opcode)
800 master_lowest_opcode = defp->pc.proc_opcodenum;
801 if (defp->pc.proc_opcodenum > highest_opcode[PackageIndex])
802 highest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
803 if (defp->pc.proc_opcodenum > master_highest_opcode)
804 master_highest_opcode = defp->pc.proc_opcodenum;
805 scan(TOK_SEMICOLON, &tok);
807 if (master_opcodenumber == 99999)
808 master_opcodenumber = 0;
809 defp->pc.proc_opcodenum = master_opcodenumber++;
810 if (defp->pc.proc_opcodenum < lowest_opcode[PackageIndex])
811 lowest_opcode[PackageIndex] = 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 opcodesnotallowed[PackageIndex] = 1; /* force it */
818 no_of_opcodes[PackageIndex]++, master_no_of_opcodes++;
820 generate_code(defp, 0, 1);
821 if (Cflag || cflag) {
822 generate_code(defp, 1, 1);
824 generate_multi_macros(defp);
826 generate_code(defp, proc_split, 0);
829 if (function_list_index >= MAX_FUNCTIONS_PER_INTERFACE) {
830 error("too many functions in interface, "
831 "increase MAX_FUNCTIONS_PER_INTERFACE");
833 sprintf(function_list[PackageIndex][function_list_index], "%s%s%s",
834 prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
836 function_list_index++;
837 no_of_stat_funcs_header[PackageIndex]++;
843 #define LEGALNUMS "0123456789"
845 InvalidConstant(char *name)
852 return (slen != strspn(name, map));
856 opcodenum_is_defined(int opcode_num)
861 for (listp = proc_defined[PackageIndex]; listp != NULL;
862 listp = listp->next) {
863 defp = (definition *) listp->val;
864 if (opcode_num == defp->pc.proc_opcodenum)
872 analyze_ProcParams(definition * defp, token * tokp)
875 decl_list *decls, **tailp;
877 Proc_listp = &defp->pc.plists;
878 tailp = &defp->def.st.decls;
881 Proc_list = ALLOC(proc1_list);
882 memset((char *)Proc_list, 0, sizeof(proc1_list));
883 Proc_list->pl.param_flag = 0;
884 switch (tokp->kind) {
886 hdle_param_tok(defp, &dec, tokp, DEF_INPARAM);
889 hdle_param_tok(defp, &dec, tokp, DEF_OUTPARAM);
892 hdle_param_tok(defp, &dec, tokp, DEF_INOUTPARAM);
898 hdle_param_tok(defp, &dec, tokp, DEF_NULL);
901 *Proc_listp = Proc_list;
902 Proc_listp = &Proc_list->next;
903 decls = ALLOC(decl_list);
904 memset((char *)decls, 0, sizeof(decl_list));
907 tailp = &decls->next;
908 } while (tokp->kind != TOK_RPAREN);
914 generate_code(definition * defp, int proc_split_flag, int multi_flag)
917 handle_split_proc(defp, multi_flag);
919 if (Cflag || cflag) {
920 cs_Proc_CodeGeneration(defp, 0, "");
923 ss_Proc_CodeGeneration(defp);
926 STOREVAL(&proc_defined[PackageIndex], defp);
931 handle_split_proc(definition * defp, int multi_flag)
933 char *startname = SplitStart, *endname = SplitEnd;
940 if (Cflag || cflag) {
942 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 0);
944 cs_Proc_CodeGeneration(defp, 1, startname);
946 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 1);
947 do_split(defp, IN, &numofparams, DEF_INPARAM, 0);
949 cs_Proc_CodeGeneration(defp, (multi_flag ? 3 : 2), endname);
951 do_split(defp, IN, &numofparams, DEF_INPARAM, 1);
955 ss_Proc_CodeGeneration(defp);
960 do_split(definition * defp, int direction, int *numofparams,
961 defkind param_kind, int restore_flag)
966 defp->pc.paramtypes[direction] = *numofparams;
967 for (plist = defp->pc.plists; plist; plist = plist->next) {
968 if (plist->component_kind == DEF_NULL
969 && plist->pl.param_kind == param_kind)
970 plist->component_kind = DEF_PARAM;
973 *numofparams = defp->pc.paramtypes[direction];
974 defp->pc.paramtypes[direction] = 0;
975 for (plist = defp->pc.plists; plist; plist = plist->next) {
976 if (plist->component_kind == DEF_PARAM
977 && plist->pl.param_kind == param_kind)
978 plist->component_kind = DEF_NULL;
985 hdle_param_tok(definition * defp, declaration * dec, token * tokp,
988 static defkind last_param_kind = DEF_NULL;
990 if (par_kind == DEF_NULL)
991 Proc_list->pl.param_kind = last_param_kind;
993 Proc_list->pl.param_kind = par_kind;
994 last_param_kind = Proc_list->pl.param_kind;
995 defp->pc.paramtypes[(int)last_param_kind]++;
996 Proc_list->component_kind = DEF_PARAM;
997 Proc_list->code = alloc(250);
998 Proc_list->scode = alloc(250);
999 get_declaration(dec, DEF_PARAM);
1000 Proc_list->pl.param_name = dec->name;
1001 get1_param_type(defp, dec, &Proc_list->pl.param_type);
1003 scan2(TOK_COMMA, TOK_RPAREN, tokp);
1004 if (tokp->kind == TOK_COMMA)
1010 get1_param_type(definition * defp, declaration * dec, char **param_type)
1012 char typecontents[100];
1014 if (streq(dec->type, "string")) {
1015 *param_type = "char *";
1018 strcpy(typecontents, dec->prefix);
1019 strcat(typecontents, " ");
1020 strcat(typecontents, dec->type);
1021 strcat(typecontents, " *");
1022 } else if (dec->rel == REL_POINTER) {
1023 strcpy(typecontents, dec->type);
1024 strcat(typecontents, " *");
1026 strcpy(typecontents, dec->type);
1027 *param_type = alloc(100);
1028 strcpy(*param_type, typecontents);
1034 get_param_type(definition * defp, declaration * dec, char **param_type,
1037 char typecontents[100];
1039 if (streq(dec->type, "string")) {
1040 *typename = "wrapstring";
1041 *param_type = "char *";
1043 *typename = dec->type;
1045 strcpy(typecontents, dec->prefix);
1046 strcat(typecontents, " ");
1047 strcat(typecontents, dec->type);
1048 strcat(typecontents, " *");
1049 dec->rel = REL_POINTER;
1050 } else if (dec->rel == REL_POINTER) {
1051 strcpy(typecontents, dec->type);
1052 strcat(typecontents, " *");
1054 strcpy(typecontents, dec->type);
1055 *param_type = alloc(100);
1056 strcpy(*param_type, typecontents);
1063 hndle_param_tail(definition * defp, declaration * dec, token * tokp,
1068 if (dec->rel == REL_POINTER)
1069 Proc_list->pl.param_flag |= INDIRECT_PARAM;
1071 Proc_list->pl.param_flag &= ~INDIRECT_PARAM;
1073 if (!(Proc_list->pl.param_flag & INDIRECT_PARAM))
1076 sprintf(Proc_list->code, "xdr_%s(&z_xdrs, %s%s)", typename, amp,
1077 Proc_list->pl.param_name);
1078 sprintf(Proc_list->scode, "xdr_%s(z_xdrs, &%s)", typename,
1079 Proc_list->pl.param_name);
1080 scan2(TOK_COMMA, TOK_RPAREN, tokp);
1081 if (tokp->kind == TOK_COMMA)
1088 cs_Proc_CodeGeneration(definition * defp, int split_flag, char *procheader)
1091 cs_ProcName_setup(defp, procheader, split_flag);
1093 cs_ProcParams_setup(defp, split_flag);
1094 cs_ProcMarshallInParams_setup(defp, split_flag);
1095 if (split_flag != 1) {
1096 cs_ProcSendPacket_setup(defp, split_flag);
1097 cs_ProcUnmarshallOutParams_setup(defp);
1099 cs_ProcTail_setup(defp, split_flag);
1105 cs_ProcName_setup(definition * defp, char *procheader, int split_flag)
1111 f_print(fout, "int %s%s%s%s(z_call", procheader, prefix,
1112 PackagePrefix[PackageIndex], defp->pc.proc_name);
1114 f_print(fout, "int %s%s%s%s(z_conn", procheader, prefix,
1115 PackagePrefix[PackageIndex], defp->pc.proc_name);
1118 if ((strlen(procheader) + strlen(prefix) +
1119 strlen(PackagePrefix[PackageIndex]) + strlen(defp->pc.proc_name)) >=
1120 MAX_FUNCTION_NAME_LEN) {
1121 error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
1124 for (plist = defp->pc.plists; plist; plist = plist->next) {
1125 if (plist->component_kind == DEF_PARAM) {
1126 plist->pl.param_flag &= ~PROCESSED_PARAM;
1127 f_print(fout, ", %s", plist->pl.param_name);
1130 f_print(fout, ")\n");
1136 cs_ProcParams_setup(definition * defp, int split_flag)
1138 proc1_list *plist, *plist1;
1141 f_print(fout, "\tregister struct rx_connection *z_conn;\n");
1143 f_print(fout, "\tregister struct rx_call *z_call;\n");
1145 for (plist = defp->pc.plists; plist; plist = plist->next) {
1146 if (plist->component_kind == DEF_PARAM
1147 && !(plist->pl.param_flag & PROCESSED_PARAM)) {
1148 if (plist->pl.param_flag & OUT_STRING) {
1149 f_print(fout, "\t%s *%s", plist->pl.param_type,
1150 plist->pl.param_name);
1152 f_print(fout, "\t%s %s", plist->pl.param_type,
1153 plist->pl.param_name);
1155 plist->pl.param_flag |= PROCESSED_PARAM;
1156 for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
1157 if ((plist1->component_kind == DEF_PARAM)
1158 && streq(plist->pl.param_type, plist1->pl.param_type)
1159 && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
1161 char *pntr = strchr(plist1->pl.param_type, '*');
1164 if (plist1->pl.param_flag & OUT_STRING) {
1165 f_print(fout, ", *%s%s", star, plist1->pl.param_name);
1167 f_print(fout, ", %s%s", star, plist1->pl.param_name);
1169 plist1->pl.param_flag |= PROCESSED_PARAM;
1172 f_print(fout, ";\n");
1179 cs_ProcMarshallInParams_setup(definition * defp, int split_flag)
1181 int noofparams, i = 0;
1185 defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT] +
1186 defp->pc.paramtypes[OUT];
1188 f_print(fout, "{\n");
1190 f_print(fout, "\tstruct rx_call *z_call = rx_NewCall(z_conn);\n");
1191 if ((!split_flag) || (split_flag == 1)) {
1192 if (opcodesnotallowed[PackageIndex]) {
1193 f_print(fout, "\tstatic int z_op = %d;\n",
1194 defp->pc.proc_opcodenum);
1196 f_print(fout, "\tstatic int z_op = %s;\n",
1197 defp->pc.proc_opcodename);
1200 f_print(fout, "\tint z_result;\n");
1201 if (!(split_flag > 1) || (noofallparams != 0)) {
1202 f_print(fout, "\tXDR z_xdrs;\n");
1205 * Print out client side stat gathering call
1207 if (xflag && split_flag != 1) {
1208 f_print(fout, "\tstruct clock __QUEUE, __EXEC;\n");
1211 if ((!split_flag) || (split_flag == 1)) {
1212 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_ENCODE);\n");
1213 f_print(fout, "\n\t/* Marshal the arguments */\n");
1214 f_print(fout, "\tif ((!xdr_int(&z_xdrs, &z_op))");
1215 noofparams = defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT];
1216 for (plist = defp->pc.plists, dl = defp->def.st.decls; plist;
1217 plist = plist->next, dl = dl->next) {
1218 if (plist->component_kind == DEF_PARAM
1219 && (plist->pl.param_kind == DEF_INPARAM
1220 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1221 f_print(fout, "\n\t || (!%s)", plist->code);
1222 if (++i == noofparams) {
1224 ") {\n\t\tz_result = RXGEN_CC_MARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1231 ") {\n\t\tz_result = RXGEN_CC_MARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1239 cs_ProcSendPacket_setup(definition * defp, int split_flag)
1241 int noofoutparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1243 if (noofoutparams) {
1244 f_print(fout, "\t/* Un-marshal the reply arguments */\n");
1246 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
1248 f_print(fout, "\tz_xdrs.x_op = XDR_DECODE;\n");
1255 cs_ProcUnmarshallOutParams_setup(definition * defp)
1261 noofparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1263 for (plist = defp->pc.plists, dl = defp->def.st.decls, i = 0; plist;
1264 plist = plist->next, dl = dl->next) {
1265 if (plist->component_kind == DEF_PARAM
1266 && (plist->pl.param_kind == DEF_OUTPARAM
1267 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1269 f_print(fout, "\tif ((!%s)", plist->code);
1271 f_print(fout, "\n\t || (!%s)", plist->code);
1273 if (++i == noofparams) {
1275 ") {\n\t\tz_result = RXGEN_CC_UNMARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1284 cs_ProcTail_setup(definition * defp, int split_flag)
1286 f_print(fout, "\tz_result = RXGEN_SUCCESS;\n");
1287 if (defp->can_fail) {
1288 f_print(fout, "fail:\n");
1291 f_print(fout, "\tz_result = rx_EndCall(z_call, z_result);\n");
1293 if (xflag && split_flag != 1) {
1294 f_print(fout, "\tif (rx_enable_stats) {\n");
1295 f_print(fout, "\t clock_GetTime(&__EXEC);\n");
1296 f_print(fout, "\t clock_Sub(&__EXEC, &z_call->startTime);\n");
1297 f_print(fout, "\t __QUEUE = z_call->startTime;\n");
1298 f_print(fout, "\t clock_Sub(&__QUEUE, &z_call->queueTime);\n");
1299 if (PackageStatIndex[PackageIndex]) {
1302 "\t rx_IncrementTimeAndCount(z_conn->peer, %s,\n",
1303 PackageStatIndex[PackageIndex]);
1306 "\t rx_IncrementTimeAndCount(z_call->conn->peer, %s,\n",
1307 PackageStatIndex[PackageIndex]);
1312 "\t rx_IncrementTimeAndCount(z_conn->peer,\n"
1313 "\t\t(((afs_uint32)(ntohs(z_conn->serviceId) << 16)) \n"
1314 "\t\t| ((afs_uint32)ntohs(z_conn->peer->port))),\n");
1317 "\t rx_IncrementTimeAndCount(z_call->conn->peer,\n"
1318 "\t\t(((afs_uint32)(ntohs(z_call->conn->serviceId) << 16)) |\n"
1319 "\t\t((afs_uint32)ntohs(z_call->conn->peer->port))),\n");
1323 f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, &__QUEUE, &__EXEC,\n",
1324 no_of_stat_funcs, PackagePrefix[PackageIndex]);
1326 "\t\t&z_call->bytesSent, &z_call->bytesRcvd, 1);\n");
1328 f_print(fout, "\t}\n\n");
1330 f_print(fout, "\treturn z_result;\n}\n\n");
1335 ss_Proc_CodeGeneration(definition * defp)
1340 ss_ProcName_setup(defp);
1342 ss_ProcParams_setup(defp, &somefrees);
1343 ss_ProcSpecial_setup(defp, &somefrees);
1344 ss_ProcUnmarshallInParams_setup(defp);
1345 ss_ProcCallRealProc_setup(defp);
1346 ss_ProcMarshallOutParams_setup(defp);
1347 ss_ProcTail_setup(defp, somefrees);
1353 ss_ProcName_setup(definition * defp)
1357 if ((strlen(prefix) + strlen(PackagePrefix[PackageIndex]) +
1358 strlen(defp->pc.proc_name)) >= MAX_FUNCTION_NAME_LEN) {
1359 error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
1363 f_print(fout, "static afs_int32 _%s%s%s(", prefix,
1364 PackagePrefix[PackageIndex], defp->pc.proc_name);
1365 f_print(fout, "struct rx_call *z_call, XDR *z_xdrs)\n{\n");
1366 f_print(fout, "\t" "afs_int32 z_result;\n");
1368 f_print(fout, "\tstruct clock __QUEUE, __EXEC;\n");
1371 for (plist = defp->pc.plists; plist; plist = plist->next)
1372 if (plist->component_kind == DEF_PARAM) {
1373 plist->pl.param_flag &= ~(PROCESSED_PARAM);
1374 plist->pl.string_name = NULL;
1381 ss_ProcParams_setup(definition * defp, int *somefrees)
1383 proc1_list *plist, *plist1;
1387 for (plist = defp->pc.plists; plist; plist = plist->next) {
1388 if ((plist->component_kind == DEF_PARAM)
1389 && !(plist->pl.param_flag & PROCESSED_PARAM)) {
1390 if (plist->pl.param_flag & INDIRECT_PARAM) {
1391 char pres = '\0', *pntr = strchr(plist->pl.param_type, '*');
1397 f_print(fout, "\t%s %s", plist->pl.param_type,
1398 plist->pl.param_name);
1400 } else if (strchr(plist->pl.param_type, '*') == 0) {
1401 f_print(fout, "\t%s %s", plist->pl.param_type,
1402 plist->pl.param_name);
1404 plist->pl.param_flag |= FREETHIS_PARAM;
1406 f_print(fout, "\t%s %s=(%s)0", plist->pl.param_type,
1407 plist->pl.param_name, plist->pl.param_type);
1409 plist->pl.param_flag |= PROCESSED_PARAM;
1410 for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
1411 if ((plist1->component_kind == DEF_PARAM)
1412 && streq(plist->pl.param_type, plist1->pl.param_type)
1413 && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
1414 if (plist1->pl.param_flag & INDIRECT_PARAM) {
1415 f_print(fout, ", %s", plist1->pl.param_name);
1416 } else if (strchr(plist1->pl.param_type, '*') == 0) {
1417 f_print(fout, ", %s", plist1->pl.param_name);
1419 plist1->pl.param_flag |= FREETHIS_PARAM;
1421 f_print(fout, ", *%s=(%s)0", plist1->pl.param_name,
1422 plist1->pl.param_type);
1424 plist1->pl.param_flag |= PROCESSED_PARAM;
1427 f_print(fout, ";\n");
1430 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1431 defp1 = (definition *) listp->val;
1432 for (plist = defp->pc.plists; plist; plist = plist->next) {
1433 if (plist->component_kind == DEF_PARAM
1434 && (plist->pl.param_kind == DEF_OUTPARAM
1435 || plist->pl.param_kind == DEF_INOUTPARAM)
1436 && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1437 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1438 switch (defp1->pc.rel) {
1447 fprintf(fout, "\n");
1452 ss_ProcSpecial_setup(definition * defp, int *somefrees)
1458 for (listp = special_defined; listp != NULL; listp = listp->next) {
1459 defp1 = (definition *) listp->val;
1460 for (plist = defp->pc.plists; plist; plist = plist->next) {
1461 if (plist->component_kind == DEF_PARAM
1462 && (plist->pl.param_kind == DEF_INPARAM
1463 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1464 spec_list *spec = defp1->def.sd.specs;
1466 strcpy(string, structname(spec->sdef.string_value));
1467 if (streq(string, structname(plist->pl.param_type))) {
1468 plist->pl.string_name = spec->sdef.string_name;
1469 plist->pl.param_flag |= FREETHIS_PARAM;
1471 fprintf(fout, "\n\t%s.%s = 0;", plist->pl.param_name,
1472 spec->sdef.string_name);
1478 fprintf(fout, "\n");
1479 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1480 defp1 = (definition *) listp->val;
1481 for (plist = defp->pc.plists; plist; plist = plist->next) {
1482 if (plist->component_kind == DEF_PARAM) {
1483 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1484 plist->pl.param_flag |= FREETHIS_PARAM;
1486 switch (defp1->pc.rel) {
1488 f_print(fout, "\n\t%s.%s_val = 0;",
1489 plist->pl.param_name, defp1->def_name);
1490 f_print(fout, "\n\t%s.%s_len = 0;",
1491 plist->pl.param_name, defp1->def_name);
1492 plist->pl.string_name = alloc(40);
1493 s_print(plist->pl.string_name, "%s_val",
1497 f_print(fout, "\n\t%s = 0;", plist->pl.param_name);
1498 plist->pl.string_name = NULL;
1505 f_print(fout, "\n");
1510 ss_ProcUnmarshallInParams_setup(definition * defp)
1512 int noofparams, noofoutparams, i;
1515 noofparams = defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT];
1516 noofoutparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1517 for (plist = defp->pc.plists, i = 0; plist; plist = plist->next) {
1518 if (plist->component_kind == DEF_PARAM
1519 && (plist->pl.param_kind == DEF_INPARAM
1520 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1522 f_print(fout, "\n\tif ((!%s)",
1523 (plist->scode ? plist->scode : plist->code));
1525 f_print(fout, "\n\t || (!%s)",
1526 (plist->scode ? plist->scode : plist->code));
1528 if (++i == noofparams) {
1529 if (!noofoutparams) {
1530 f_print(fout, ") {\n");
1532 f_print(fout, ") {\n");
1535 "\t\tz_result = RXGEN_SS_UNMARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1544 ss_ProcCallRealProc_setup(definition * defp)
1549 f_print(fout, "\tz_result = %s%s%s%s(z_call", prefix, ServerPrefix,
1550 PackagePrefix[PackageIndex], defp->pc.proc_name);
1551 for (plist = defp->pc.plists; plist; plist = plist->next) {
1552 if (plist->component_kind == DEF_PARAM) {
1553 if (plist->pl.param_flag & INDIRECT_PARAM) {
1554 f_print(fout, ", &%s", plist->pl.param_name);
1556 if (plist->pl.param_flag & OUT_STRING) {
1557 f_print(fout, ", &%s", plist->pl.param_name);
1559 f_print(fout, ", %s", plist->pl.param_name);
1564 f_print(fout, ");\n");
1566 f_print(fout, "\tif (z_result)\n\t\treturn z_result;\n");
1572 ss_ProcMarshallOutParams_setup(definition * defp)
1577 noofparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1579 f_print(fout, "\tz_xdrs->x_op = XDR_ENCODE;\n");
1581 for (plist = defp->pc.plists, i = 0; plist; plist = plist->next) {
1582 if (plist->component_kind == DEF_PARAM
1583 && (plist->pl.param_kind == DEF_OUTPARAM
1584 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1586 f_print(fout, "\tif ((!%s)",
1587 (plist->scode ? plist->scode : plist->code));
1589 f_print(fout, "\n\t || (!%s)",
1590 (plist->scode ? plist->scode : plist->code));
1592 if (++i == noofparams) {
1593 f_print(fout, ")\n\t\tz_result = RXGEN_SS_MARSHAL;\n");
1602 ss_ProcTail_setup(definition * defp, int somefrees)
1609 if (defp->can_fail) {
1610 f_print(fout, "fail:\n");
1612 for (plist = defp->pc.plists; plist; plist = plist->next) {
1613 if (plist->component_kind == DEF_PARAM
1614 && (plist->pl.param_flag & FREETHIS_PARAM))
1618 f_print(fout, "\tz_xdrs->x_op = XDR_FREE;\n");
1619 for (plist = defp->pc.plists; plist; plist = plist->next) {
1620 if (plist->component_kind == DEF_PARAM
1621 && (plist->pl.param_flag & FREETHIS_PARAM)) {
1622 char *dot = "", *extens = "";
1623 if (plist->pl.string_name) {
1625 extens = plist->pl.string_name;
1627 f_print(fout, "\tif (!%s) goto fail1;\n", plist->scode);
1630 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1631 defp1 = (definition *) listp->val;
1632 for (plist = defp->pc.plists; plist; plist = plist->next) {
1633 if (plist->component_kind == DEF_PARAM
1634 && (plist->pl.param_kind == DEF_OUTPARAM
1635 || plist->pl.param_kind == DEF_INOUTPARAM)
1636 && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1637 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1638 switch (defp1->pc.rel) {
1641 if (!somefrees && !firsttime) {
1643 f_print(fout, "\tz_xdrs->x_op = XDR_FREE;\n");
1646 f_print(fout, "\tif (!%s) goto fail1;\n",
1654 for (listp = uniondef_defined; listp != NULL; listp = listp->next) {
1655 defp1 = (definition *) listp->val;
1656 for (plist = defp->pc.plists; plist; plist = plist->next) {
1657 if (plist->component_kind == DEF_PARAM
1658 && (plist->pl.param_kind == DEF_OUTPARAM
1659 || plist->pl.param_kind == DEF_INOUTPARAM)
1660 && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1661 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1662 if (plist->pl.param_flag & INDIRECT_PARAM) {
1663 if (!somefrees && !firsttime) {
1665 f_print(fout, "\tz_xdrs->x_op = XDR_FREE;\n");
1668 f_print(fout, "\tif (!%s) goto fail1;\n",
1677 f_print(fout, "\tif (rx_enable_stats) {\n");
1678 f_print(fout, "\t clock_GetTime(&__EXEC);\n");
1679 f_print(fout, "\t clock_Sub(&__EXEC, &z_call->startTime);\n");
1680 f_print(fout, "\t __QUEUE = z_call->startTime;\n");
1681 f_print(fout, "\t clock_Sub(&__QUEUE, &z_call->queueTime);\n");
1682 f_print(fout, "\t rx_IncrementTimeAndCount(z_call->conn->peer,");
1683 if (PackageStatIndex[PackageIndex]) {
1684 f_print(fout, " %s,\n", PackageStatIndex[PackageIndex]);
1687 "\n\t\t(((afs_uint32)(ntohs(z_call->conn->serviceId) << 16)) |\n"
1688 "\t\t((afs_uint32)ntohs(z_call->conn->service->servicePort))),\n");
1690 f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, &__QUEUE, &__EXEC,\n",
1691 no_of_stat_funcs, PackagePrefix[PackageIndex]);
1692 f_print(fout, "\t\t&z_call->bytesSent, &z_call->bytesRcvd, 0);\n");
1693 f_print(fout, "\t}\n\n");
1696 f_print(fout, "\treturn z_result;\n");
1698 f_print(fout, "fail1:\n");
1701 f_print(fout, "\tif (rx_enable_stats) {\n");
1702 f_print(fout, "\t clock_GetTime(&__EXEC);\n");
1703 f_print(fout, "\t clock_Sub(&__EXEC, &z_call->startTime);\n");
1704 f_print(fout, "\t __QUEUE = z_call->startTime;\n");
1705 f_print(fout, "\t clock_Sub(&__QUEUE, &z_call->queueTime);\n");
1707 "\t rx_IncrementTimeAndCount(z_call->conn->peer,");
1708 if (PackageStatIndex[PackageIndex]) {
1709 f_print(fout, " %s,\n", PackageStatIndex[PackageIndex]);
1712 "\n\t\t(((afs_uint32)(ntohs(z_call->conn->serviceId) << 16)) |\n"
1713 "\t\t((afs_uint32)ntohs(z_call->conn->service->servicePort))),\n");
1715 f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, &__QUEUE, &__EXEC,\n",
1716 no_of_stat_funcs, PackagePrefix[PackageIndex]);
1718 "\t\t&z_call->bytesSent, &z_call->bytesRcvd, 0);\n");
1719 f_print(fout, "\t}\n\n");
1722 f_print(fout, "\treturn RXGEN_SS_XDRFREE;\n}\n\n");
1724 f_print(fout, "}\n\n");
1730 opcode_holes_exist(void)
1734 for (i = lowest_opcode[PackageIndex]; i < highest_opcode[PackageIndex];
1736 if (!opcodenum_is_defined(i))
1744 er_Proc_CodeGeneration(void)
1748 temp = PackageIndex;
1749 if (!combinepackages)
1751 for (; PackageIndex <= temp; PackageIndex++) {
1752 if (proc_defined[PackageIndex] == NULL)
1754 if (combinepackages || opcode_holes_exist()) {
1755 er_HeadofOldStyleProc_setup();
1756 er_BodyofOldStyleProc_setup();
1757 er_TailofOldStyleProc_setup();
1759 er_ProcDeclExterns_setup();
1760 er_ProcProcsArray_setup();
1761 er_ProcMainBody_setup();
1764 PackageIndex = temp;
1769 er_ProcDeclExterns_setup(void)
1774 f_print(fout, "\n");
1775 for (listp = proc_defined[PackageIndex]; listp != NULL;
1776 listp = listp->next) {
1777 defp = (definition *) listp->val;
1778 if (defp->pc.proc_serverstub) {
1779 f_print(fout, "afs_int32 %s();\n", defp->pc.proc_serverstub);
1786 er_ProcProcsArray_setup(void)
1791 if ((listp = proc_defined[PackageIndex])) {
1792 defp = (definition *) listp->val;
1793 if (defp->pc.proc_serverstub) {
1794 f_print(fout, "\nstatic afs_int32 (*StubProcsArray%d[])() = {%s",
1795 PackageIndex, defp->pc.proc_serverstub);
1798 "\nstatic afs_int32 (*StubProcsArray%d[])(struct rx_call *z_call, XDR *z_xdrs) = {_%s%s%s",
1799 PackageIndex, prefix, defp->pc.proc_prefix,
1800 ((definition *) listp->val)->pc.proc_name);
1801 defp = (definition *) listp->val;
1803 listp = listp->next;
1805 for (; listp != NULL; listp = listp->next) {
1806 defp = (definition *) listp->val;
1807 if (defp->pc.proc_serverstub) {
1808 f_print(fout, ",%s", defp->pc.proc_serverstub);
1810 f_print(fout, ", _%s%s%s", prefix, defp->pc.proc_prefix,
1811 defp->pc.proc_name);
1814 f_print(fout, "};\n\n");
1819 er_ProcMainBody_setup(void)
1821 f_print(fout, "int %s%sExecuteRequest(register struct rx_call *z_call)\n",
1822 prefix, PackagePrefix[PackageIndex]);
1823 f_print(fout, "{\n\tint op;\n");
1824 f_print(fout, "\tXDR z_xdrs;\n");
1825 f_print(fout, "\t" "afs_int32 z_result;\n\n");
1826 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
1828 "\tif (!xdr_int(&z_xdrs, &op))\n\t\tz_result = RXGEN_DECODE;\n");
1830 "\telse if (op < %sLOWEST_OPCODE || op > %sHIGHEST_OPCODE)\n\t\tz_result = RXGEN_OPCODE;\n",
1831 PackagePrefix[PackageIndex], PackagePrefix[PackageIndex]);
1833 "\telse\n\t\tz_result = (*StubProcsArray%d[op - %sLOWEST_OPCODE])(z_call, &z_xdrs);\n",
1834 PackageIndex, PackagePrefix[PackageIndex]);
1835 f_print(fout, "\treturn hton_syserr_conv(z_result);\n}\n");
1840 er_HeadofOldStyleProc_setup(void)
1843 "\nint %s%sExecuteRequest (register struct rx_call *z_call)\n",
1845 (combinepackages ? MasterPrefix : PackagePrefix[PackageIndex]));
1846 f_print(fout, "{\n");
1847 f_print(fout, "\tint op;\n");
1848 f_print(fout, "\tXDR z_xdrs;\n");
1849 f_print(fout, "\t" "afs_int32 z_result;\n\n");
1850 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
1851 f_print(fout, "\tz_result = RXGEN_DECODE;\n");
1852 f_print(fout, "\tif (!xdr_int(&z_xdrs, &op)) goto fail;\n");
1853 f_print(fout, "\tswitch (op) {\n");
1857 er_BodyofOldStyleProc_setup(void)
1861 if (combinepackages) {
1862 int temp = PackageIndex;
1863 for (PackageIndex = 0; PackageIndex <= temp; PackageIndex++) {
1864 for (listp = proc_defined[PackageIndex]; listp != NULL;
1865 listp = listp->next)
1866 proc_er_case((definition *) listp->val);
1868 PackageIndex = temp;
1870 for (listp = proc_defined[PackageIndex]; listp != NULL;
1871 listp = listp->next)
1872 proc_er_case((definition *) listp->val);
1878 proc_er_case(definition * defp)
1880 if (opcodesnotallowed[PackageIndex]) {
1881 f_print(fout, "\t\tcase %d:\n", defp->pc.proc_opcodenum);
1883 f_print(fout, "\t\tcase %s:\n", defp->pc.proc_opcodename);
1885 if (defp->pc.proc_serverstub) {
1886 f_print(fout, "\t\t\tz_result = %s(z_call, &z_xdrs);\n",
1887 defp->pc.proc_serverstub);
1889 f_print(fout, "\t\t\tz_result = _%s%s%s(z_call, &z_xdrs);\n", prefix,
1890 defp->pc.proc_prefix, defp->pc.proc_name);
1892 f_print(fout, "\t\t\tbreak;\n");
1897 er_TailofOldStyleProc_setup(void)
1899 f_print(fout, "\t\tdefault:\n");
1900 f_print(fout, "\t\t\tz_result = RXGEN_OPCODE;\n");
1901 f_print(fout, "\t\t\tbreak;\n\t}\n");
1902 f_print(fout, "fail:\n");
1903 f_print(fout, "\treturn z_result;\n}\n");
1908 h_opcode_stats(void)
1910 if (combinepackages) {
1912 "\n/* Opcode-related useful stats for Master package: %s */\n",
1914 f_print(fout, "#define %sLOWEST_OPCODE %d\n", MasterPrefix,
1915 master_lowest_opcode);
1916 f_print(fout, "#define %sHIGHEST_OPCODE %d\n", MasterPrefix,
1917 master_highest_opcode);
1918 f_print(fout, "#define %sNUMBER_OPCODES %d\n\n", MasterPrefix,
1919 master_no_of_opcodes);
1921 f_print(fout, "#define %sNO_OF_STAT_FUNCS\t%d\n\n", MasterPrefix,
1922 no_of_stat_funcs_header[0]);
1923 f_print(fout, "AFS_RXGEN_EXPORT\n");
1924 f_print(fout, "extern const char *%sfunction_names[];\n\n",
1929 for (i = 0; i <= PackageIndex; i++) {
1931 "\n/* Opcode-related useful stats for package: %s */\n",
1933 f_print(fout, "#define %sLOWEST_OPCODE %d\n", PackagePrefix[i],
1935 f_print(fout, "#define %sHIGHEST_OPCODE %d\n",
1936 PackagePrefix[i], highest_opcode[i]);
1937 f_print(fout, "#define %sNUMBER_OPCODES %d\n\n",
1938 PackagePrefix[i], no_of_opcodes[i]);
1940 f_print(fout, "#define %sNO_OF_STAT_FUNCS\t%d\n\n",
1941 PackagePrefix[i], no_of_stat_funcs_header[i]);
1942 f_print(fout, "AFS_RXGEN_EXPORT\n");
1943 f_print(fout, "extern const char *%sfunction_names[];\n\n",
1952 generate_multi_macros(definition * defp)
1954 char *startname = SplitStart, *endname = SplitEnd;
1963 f_print(fout, "\n#include <rx/rx_multi.h>");
1965 f_print(fout, "\n#define multi_%s%s(", PackagePrefix[PackageIndex],
1966 defp->pc.proc_name);
1967 for (plist = defp->pc.plists; plist; plist = plist->next) {
1968 if (plist->component_kind == DEF_PARAM) {
1971 f_print(fout, "%s", plist->pl.param_name);
1973 f_print(fout, ", %s", plist->pl.param_name);
1977 f_print(fout, ") \\\n");
1979 startname = "Start";
1982 f_print(fout, "\tmulti_Body(%s%s%s(multi_call", startname,
1983 PackagePrefix[PackageIndex], defp->pc.proc_name);
1984 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 0);
1985 for (plist = defp->pc.plists; plist; plist = plist->next) {
1986 if (plist->component_kind == DEF_PARAM)
1987 f_print(fout, ", %s", plist->pl.param_name);
1989 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 1);
1990 f_print(fout, "), %s%s%s(multi_call", endname,
1991 PackagePrefix[PackageIndex], defp->pc.proc_name);
1992 do_split(defp, IN, &numofparams, DEF_INPARAM, 0);
1993 for (plist = defp->pc.plists; plist; plist = plist->next) {
1994 if (plist->component_kind == DEF_PARAM) {
1995 f_print(fout, ", %s", plist->pl.param_name);
1998 do_split(defp, IN, &numofparams, DEF_INPARAM, 1);
1999 f_print(fout, "))\n\n");
2004 IsRxgenToken(token * tokp)
2006 if (tokp->kind == TOK_PACKAGE || tokp->kind == TOK_PREFIX
2007 || tokp->kind == TOK_SPECIAL || tokp->kind == TOK_STARTINGOPCODE
2008 || tokp->kind == TOK_SPLITPREFIX || tokp->kind == TOK_PROC
2009 || tokp->kind == TOK_STATINDEX)
2015 IsRxgenDefinition(definition * def)
2017 if (def->def_kind == DEF_PACKAGE || def->def_kind == DEF_PREFIX
2018 || def->def_kind == DEF_SPECIAL || def->def_kind == DEF_STARTINGOPCODE
2019 || def->def_kind == DEF_SPLITPREFIX || def->def_kind == DEF_PROC)