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 <afs/param.h>
38 #if defined(AFS_SUN5_ENV) || defined(AFS_NT40_ENV)
40 #if defined(AFS_SUN5_ENV)
48 #include "rpc_parse.h"
51 list *proc_defined[MAX_PACKAGES], *special_defined, *typedef_defined, *uniondef_defined;
52 char *SplitStart = NULL;
53 char *SplitEnd = NULL;
54 char *MasterPrefix = NULL;
55 char *ServerPrefix = "";
56 char *PackagePrefix[MAX_PACKAGES];
57 char *PackageStatIndex[MAX_PACKAGES];
58 int no_of_stat_funcs = 0; /*
59 * current function number in client interface
62 int no_of_stat_funcs_header[MAX_PACKAGES]; /*
63 * Total number of functions in client
66 int no_of_opcodes[MAX_PACKAGES], master_no_of_opcodes = 0;
67 int lowest_opcode[MAX_PACKAGES], master_lowest_opcode = 99999;
68 int highest_opcode[MAX_PACKAGES], master_highest_opcode = 0;
69 int master_opcodenumber = 99999;
70 int opcodesnotallowed[MAX_PACKAGES];
71 int combinepackages = 0;
72 int PackageIndex = -1;
73 int PerProcCounter = 0;
77 * Character arrays to keep list of function names as we process the file
80 char function_list[MAX_PACKAGES]
81 [MAX_FUNCTIONS_PER_PACKAGE]
82 [MAX_FUNCTION_NAME_LEN];
83 int function_list_index;
85 extern int pushed, scan_print;
94 static get_declaration();
96 static unsigned_dec();
99 static def_startingopcode();
100 static def_statindex();
102 static customize_struct();
103 static def_special();
105 static int InvalidConstant();
106 static opcodenum_is_defined();
107 static analyze_ProcParams();
108 static generate_code();
109 static handle_split_proc();
111 static hdle_param_tok();
112 static get1_param_type();
113 static get_param_type();
114 static cs_Proc_CodeGeneration();
115 static cs_ProcName_setup();
116 static cs_ProcParams_setup();
117 static cs_ProcMarshallInParams_setup();
118 static cs_ProcSendPacket_setup();
119 static cs_ProcUnmarshallOutParams_setup();
120 static cs_ProcTail_setup();
121 static ss_Proc_CodeGeneration();
122 static ss_ProcName_setup();
123 static ss_ProcParams_setup();
124 static ss_ProcSpecial_setup();
125 static ss_ProcUnmarshallInParams_setup();
126 static ss_ProcCallRealProc_setup();
127 static ss_ProcMarshallOutParams_setup();
128 static ss_ProcTail_setup();
129 static er_ProcDeclExterns_setup();
130 static er_ProcProcsArray_setup();
131 static er_ProcMainBody_setup();
132 static er_HeadofOldStyleProc_setup();
133 static er_BodyofOldStyleProc_setup();
134 static proc_er_case();
135 static er_TailofOldStyleProc_setup();
138 * return the next definition you see
146 defp = ALLOC(definition);
147 bzero((char *)defp, sizeof(definition));
183 def_special(&dec, defp);
186 case TOK_STARTINGOPCODE:
187 def_startingopcode(defp);
192 customize_struct(defp);
194 case TOK_SPLITPREFIX:
199 if (tok.kind == TOK_LPAREN) {
201 check_proc(defp, &tok, 1);
204 check_proc(defp, &tok, 0);
207 check_proc(defp, &tok, 0);
211 check_proc(defp, &tok, 1);
214 error("definition keyword expected");
216 if (!IsRxgenToken(&tok))
218 scan(TOK_SEMICOLON,&tok);
228 STOREVAL(&defined, defp);
241 defp->def_kind = DEF_STRUCT;
243 scan(TOK_IDENT, &tok);
244 defp->def_name = tok.str;
245 scan(TOK_LBRACE, &tok);
246 tailp = &defp->def.st.decls;
248 get_declaration(&dec, DEF_STRUCT);
249 decls = ALLOC(decl_list);
252 tailp = &decls->next;
253 scan(TOK_SEMICOLON, &tok);
255 } while (tok.kind != TOK_RBRACE);
266 version_list **vtailp;
270 defp->def_kind = DEF_PROGRAM;
271 scan(TOK_IDENT, &tok);
272 defp->def_name = tok.str;
273 scan(TOK_LBRACE, &tok);
274 vtailp = &defp->def.pr.versions;
275 scan(TOK_VERSION, &tok);
277 scan(TOK_IDENT, &tok);
278 vlist = ALLOC(version_list);
279 vlist->vers_name = tok.str;
280 scan(TOK_LBRACE, &tok);
281 ptailp = &vlist->procs;
283 plist = ALLOC(proc_list);
284 get_type(&plist->res_prefix, &plist->res_type, DEF_PROGRAM);
285 if (streq(plist->res_type, "opaque")) {
286 error("illegal result type");
288 scan(TOK_IDENT, &tok);
289 plist->proc_name = tok.str;
290 scan(TOK_LPAREN, &tok);
291 get_type(&plist->arg_prefix, &plist->arg_type, DEF_PROGRAM);
292 if (streq(plist->arg_type, "opaque")) {
293 error("illegal argument type");
295 scan(TOK_RPAREN, &tok);
296 scan(TOK_EQUAL, &tok);
298 scan(TOK_SEMICOLON, &tok);
299 plist->proc_num = tok.str;
301 ptailp = &plist->next;
303 } while (tok.kind != TOK_RBRACE);
305 vtailp = &vlist->next;
306 scan(TOK_RBRACE, &tok);
307 scan(TOK_EQUAL, &tok);
309 vlist->vers_num = tok.str;
310 scan(TOK_SEMICOLON, &tok);
311 scan2(TOK_VERSION, TOK_RBRACE, &tok);
312 } while (tok.kind == TOK_VERSION);
313 scan(TOK_EQUAL, &tok);
315 defp->def.pr.prog_num = tok.str;
325 enumval_list **tailp;
327 defp->def_kind = DEF_ENUM;
328 scan(TOK_IDENT, &tok);
329 defp->def_name = tok.str;
330 scan(TOK_LBRACE, &tok);
331 tailp = &defp->def.en.vals;
333 scan(TOK_IDENT, &tok);
334 elist = ALLOC(enumval_list);
335 elist->name = tok.str;
336 elist->assignment = NULL;
337 scan3(TOK_COMMA, TOK_RBRACE, TOK_EQUAL, &tok);
338 if (tok.kind == TOK_EQUAL) {
340 elist->assignment = tok.str;
341 scan2(TOK_COMMA, TOK_RBRACE, &tok);
344 tailp = &elist->next;
345 } while (tok.kind != TOK_RBRACE);
355 defp->def_kind = DEF_CONST;
356 scan(TOK_IDENT, &tok);
357 defp->def_name = tok.str;
358 scan(TOK_EQUAL, &tok);
359 scan2(TOK_IDENT, TOK_STRCONST, &tok);
360 defp->def.co = tok.str;
372 defp->def_kind = DEF_UNION;
373 scan(TOK_IDENT, &tok);
374 defp->def_name = tok.str;
375 scan(TOK_SWITCH, &tok);
376 scan(TOK_LPAREN, &tok);
377 get_declaration(&dec, DEF_UNION);
378 defp->def.un.enum_decl = dec;
379 tailp = &defp->def.un.cases;
380 scan(TOK_RPAREN, &tok);
381 scan(TOK_LBRACE, &tok);
382 scan(TOK_CASE, &tok);
383 while (tok.kind == TOK_CASE) {
384 scan(TOK_IDENT, &tok);
385 cases = ALLOC(case_list);
386 cases->case_name = tok.str;
387 scan(TOK_COLON, &tok);
388 get_declaration(&dec, DEF_UNION);
389 cases->case_decl = dec;
391 tailp = &cases->next;
392 scan(TOK_SEMICOLON, &tok);
393 scan3(TOK_CASE, TOK_DEFAULT, TOK_RBRACE, &tok);
396 if (tok.kind == TOK_DEFAULT) {
397 scan(TOK_COLON, &tok);
398 get_declaration(&dec, DEF_UNION);
399 defp->def.un.default_decl = ALLOC(declaration);
400 *defp->def.un.default_decl = dec;
401 scan(TOK_SEMICOLON, &tok);
402 scan(TOK_RBRACE, &tok);
404 defp->def.un.default_decl = NULL;
415 defp->def_kind = DEF_TYPEDEF;
416 get_declaration(&dec, DEF_TYPEDEF);
417 defp->def_name = dec.name;
418 defp->def.ty.old_prefix = dec.prefix;
419 defp->def.ty.old_type = dec.type;
420 defp->def.ty.rel = dec.rel;
421 defp->def.ty.array_max = dec.array_max;
426 get_declaration(dec, dkind)
432 get_type(&dec->prefix, &dec->type, dkind);
433 dec->rel = REL_ALIAS;
434 if (streq(dec->type, "void")) {
437 scan2(TOK_STAR, TOK_IDENT, &tok);
438 if (tok.kind == TOK_STAR) {
439 dec->rel = REL_POINTER;
440 scan(TOK_IDENT, &tok);
443 if (peekscan(TOK_LBRACKET, &tok)) {
444 if (dec->rel == REL_POINTER) {
445 error("no array-of-pointer declarations -- use typedef");
447 dec->rel = REL_VECTOR;
449 dec->array_max = tok.str;
450 scan(TOK_RBRACKET, &tok);
451 } else if (peekscan(TOK_LANGLE, &tok)) {
452 if (dec->rel == REL_POINTER) {
453 error("no array-of-pointer declarations -- use typedef");
455 dec->rel = REL_ARRAY;
456 if (peekscan(TOK_RANGLE, &tok)) {
457 dec->array_max = "~0"; /* unspecified size, use max */
460 dec->array_max = tok.str;
461 scan(TOK_RANGLE, &tok);
464 if (streq(dec->type, "opaque")) {
465 if (dec->rel != REL_ARRAY && dec->rel != REL_VECTOR) {
466 error("array declaration expected");
468 } else if (streq(dec->type, "string")) {
469 if (dec->rel != REL_ARRAY) {
470 error(" variable-length array declaration expected");
477 get_type(prefixp, typep, dkind)
494 scan(TOK_IDENT, &tok);
502 (void) peekscan(TOK_INT, &tok);
505 *typep = "afs_int32";
506 (void) peekscan(TOK_INT, &tok);
509 if (dkind != DEF_UNION && dkind != DEF_PROGRAM) {
510 error("voids allowed only inside union and program definitions");
525 error("expected type specifier");
545 (void) peekscan(TOK_INT, &tok);
549 *typep = "afs_uint32";
550 (void) peekscan(TOK_INT, &tok);
569 defp->def_kind = DEF_PACKAGE;
570 scan(TOK_IDENT, &tok);
571 defp->def_name = tok.str;
572 no_of_stat_funcs = 0;
573 if (PackageIndex++ >= MAX_PACKAGES)
574 error("Exceeded upper limit of package statements\n");
575 function_list_index = 0;
576 PackagePrefix[PackageIndex] = tok.str;
577 if (MasterPrefix == NULL)
578 MasterPrefix = tok.str;
579 no_of_opcodes[PackageIndex] = highest_opcode[PackageIndex] = opcodesnotallowed[PackageIndex] = 0;
580 lowest_opcode[PackageIndex] = 99999;
581 proc_defined[PackageIndex] = NULL;
582 PackageStatIndex[PackageIndex] = NULL;
591 defp->def_kind = DEF_PREFIX;
592 scan(TOK_IDENT, &tok);
593 defp->def_name = tok.str;
594 ServerPrefix = tok.str;
604 defp->def_kind = DEF_CONST;
606 if (PackageIndex < 0)
607 error("'statindex' command must follow 'package' command!\n");
608 if (PackageStatIndex[PackageIndex])
609 error("Cannot have more then one 'statindex' per package!\n");
610 if (InvalidConstant(tok.str))
611 error("Index in 'statindex' command must be a constant!");
612 name = alloc(strlen(PackagePrefix[PackageIndex])+strlen("STATINDEX")+1);
613 strcpy(name, PackagePrefix[PackageIndex]);
614 strcat(name, "STATINDEX");
615 defp->def_name = name;
616 defp->def.co = tok.str;
617 PackageStatIndex[PackageIndex] = name;
621 def_startingopcode(defp)
626 defp->def_kind = DEF_STARTINGOPCODE;
627 scan(TOK_IDENT, &tok);
628 defp->def_name = tok.str;
629 if (InvalidConstant(defp->def_name))
630 error("Opcode in 'startingopcode' command must be a constant!");
631 lowest_opcode[PackageIndex] = master_lowest_opcode = atoi(tok.str);
632 if (lowest_opcode[PackageIndex] < 0 || lowest_opcode[PackageIndex] > 99999)
633 error("startingopcode number is out of bounds (must be >= 0 < 100000)");
634 master_opcodenumber = lowest_opcode[PackageIndex];
635 opcodesnotallowed[PackageIndex]=1;
644 defp->def_kind = DEF_SPLITPREFIX;
649 scan(TOK_EQUAL, &tok);
650 scan(TOK_IDENT, &tok);
651 SplitStart = tok.str;
654 scan(TOK_EQUAL, &tok);
655 scan(TOK_IDENT, &tok);
661 error("syntax error in the 'splitprefix' line");
663 } while (tok.kind != TOK_SEMICOLON);
664 if (!SplitStart && !SplitEnd)
665 error("At least one param should be passed to 'splitprefix' cmd");
670 customize_struct(defp)
675 definition *defp1 = ALLOC(definition);
676 spec_list *specs, **tailp;
678 defp->def_kind = DEF_CUSTOMIZED;
679 defp1->def_kind = DEF_SPECIAL;
680 tailp = &defp1->def.sd.specs;
681 for (listp = defp->def.st.decls; listp; listp = listp->next) {
683 if (streq(dec->type, "string") || (dec->rel == REL_POINTER)) {
684 specs = ALLOC(spec_list);
685 specs->sdef.string_name = dec->name;
686 specs->sdef.string_value = defp->def_name;
688 tailp = &specs->next;
692 STOREVAL(&special_defined, defp1);
700 char namecontents[150], *pnt, *pnt1;
702 strcpy(namecontents, name);
704 if (!strncmp(pnt, "struct", 6)) pnt += 6;
705 while (isspace(*pnt)) pnt++;
707 while (*pnt != ' ' && *pnt != '\0') pnt++;
714 def_special(dec, defp)
719 spec_list *specs, **tailp;
722 defp->def_kind = DEF_SPECIAL;
723 get_type(&dec->prefix, &dec->type, DEF_SPECIAL);
724 dec->rel = REL_POINTER;
725 scan(TOK_IDENT, &tok);
726 tailp = &defp->def.sd.specs;
728 specs = ALLOC(spec_list);
729 specs->sdef.string_name = tok.str;
730 get_param_type(defp, dec, &specs->sdef.string_value, &typename);
732 tailp = &specs->next;
733 scan2(TOK_COMMA, TOK_SEMICOLON, &tok);
734 if (tok.kind == TOK_SEMICOLON)
737 } while (tok.kind == TOK_IDENT);
739 STOREVAL(&special_defined, defp);
743 proc1_list *Proc_list, **Proc_listp;
746 check_proc(defp, tokp, noname)
755 tokp->kind = TOK_PROC;
756 defp->def_kind = DEF_PROC;
758 defp->pc.proc_name = "";
760 defp->pc.proc_name = tokp->str;
762 defp->pc.proc_prefix = alloc(strlen(PackagePrefix[PackageIndex])+1);
763 strcpy(defp->pc.proc_prefix, PackagePrefix[PackageIndex]);
764 scan2(TOK_LPAREN, TOK_IDENT, &tok);
765 defp->pc.proc_serverstub = NULL;
766 if (tok.kind == TOK_IDENT) {
767 defp->pc.proc_serverstub = tok.str;
768 scan(TOK_LPAREN, &tok);
770 analyze_ProcParams(defp, &tok);
771 defp->pc.proc_opcodenum = -1;
772 scan4(TOK_SPLIT, TOK_MULTI, TOK_EQUAL, TOK_SEMICOLON, &tok);
773 if (tok.kind == TOK_MULTI) {
775 scan2(TOK_EQUAL, TOK_SEMICOLON, &tok);
777 if (tok.kind == TOK_SPLIT) {
779 scan2(TOK_EQUAL, TOK_SEMICOLON, &tok);
781 if (tok.kind == TOK_EQUAL) {
782 if (opcodesnotallowed[PackageIndex])
783 error("Opcode assignment isn't allowed here!");
785 if (InvalidConstant(tok.str))
786 error("Illegal Opcode assignment (Must be a constant opcode!)");
787 if (opcodenum_is_defined(atoi(tok.str)))
788 error("The opcode number is already used by a previous proc");
789 defp->pc.proc_opcodename = tok.str;
790 defp->pc.proc_opcodenum = atoi(tok.str);
791 if (defp->pc.proc_opcodenum < lowest_opcode[PackageIndex])
792 lowest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
793 if (defp->pc.proc_opcodenum < master_lowest_opcode)
794 master_lowest_opcode = defp->pc.proc_opcodenum;
795 if (defp->pc.proc_opcodenum > highest_opcode[PackageIndex])
796 highest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
797 if (defp->pc.proc_opcodenum > master_highest_opcode)
798 master_highest_opcode = defp->pc.proc_opcodenum;
799 scan(TOK_SEMICOLON, &tok);
801 if (master_opcodenumber == 99999) master_opcodenumber = 0;
802 defp->pc.proc_opcodenum = master_opcodenumber++;
803 if (defp->pc.proc_opcodenum < lowest_opcode[PackageIndex])
804 lowest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
805 if (defp->pc.proc_opcodenum > highest_opcode[PackageIndex])
806 highest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
807 if (defp->pc.proc_opcodenum > master_highest_opcode)
808 master_highest_opcode = defp->pc.proc_opcodenum;
809 opcodesnotallowed[PackageIndex] = 1; /* force it */
811 no_of_opcodes[PackageIndex]++, master_no_of_opcodes++;
813 generate_code(defp, 0, 1);
814 if (Cflag || cflag) {
815 generate_code(defp, 1, 1);
817 generate_multi_macros(defp);
819 generate_code(defp, proc_split, 0);
822 if (function_list_index >= MAX_FUNCTIONS_PER_INTERFACE) {
823 error("too many functions in interface, "
824 "increase MAX_FUNCTIONS_PER_INTERFACE");
826 sprintf(function_list[PackageIndex][function_list_index],
829 PackagePrefix[PackageIndex],
832 function_list_index++;
833 no_of_stat_funcs_header[PackageIndex]++;
839 #define LEGALNUMS "0123456789"
841 InvalidConstant(name)
849 return(slen != strspn(name, map));
853 opcodenum_is_defined(opcode_num)
859 for (listp = proc_defined[PackageIndex]; listp != NULL; listp = listp->next) {
860 defp = (definition *)listp->val;
861 if (opcode_num == defp->pc.proc_opcodenum)
869 analyze_ProcParams(defp, tokp)
874 decl_list *decls, **tailp;
876 Proc_listp = &defp->pc.plists;
877 tailp = &defp->def.st.decls;
880 Proc_list = ALLOC(proc1_list);
881 bzero((char *)Proc_list, sizeof(proc1_list));
882 Proc_list->pl.param_flag = 0;
883 switch (tokp->kind) {
885 hdle_param_tok(defp, &dec, tokp, DEF_INPARAM);
888 hdle_param_tok(defp, &dec, tokp, DEF_OUTPARAM);
891 hdle_param_tok(defp, &dec, tokp, DEF_INOUTPARAM);
897 hdle_param_tok(defp, &dec, tokp, DEF_NULL);
900 *Proc_listp = Proc_list;
901 Proc_listp = &Proc_list->next;
902 decls = ALLOC(decl_list);
903 bzero((char *)decls, sizeof(decl_list));
906 tailp = &decls->next;
907 } while (tokp->kind != TOK_RPAREN);
913 generate_code(defp, proc_split_flag, multi_flag)
919 handle_split_proc(defp, multi_flag);
921 if (Cflag || cflag) {
922 cs_Proc_CodeGeneration(defp, 0, "");
925 ss_Proc_CodeGeneration(defp);
928 STOREVAL(&proc_defined[PackageIndex], defp);
933 handle_split_proc(defp, 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(defp, direction, numofparams, param_kind, restore_flag)
966 int direction, *numofparams, restore_flag;
972 defp->pc.paramtypes[direction] = *numofparams;
973 for (plist = defp->pc.plists; plist; plist = plist->next) {
974 if (plist->component_kind == DEF_NULL && plist->pl.param_kind == param_kind)
975 plist->component_kind = DEF_PARAM;
978 *numofparams = defp->pc.paramtypes[direction];
979 defp->pc.paramtypes[direction] = 0;
980 for (plist = defp->pc.plists; plist; plist = plist->next) {
981 if (plist->component_kind == DEF_PARAM && plist->pl.param_kind == param_kind)
982 plist->component_kind = DEF_NULL;
989 hdle_param_tok(defp, dec, tokp, par_kind)
995 static defkind last_param_kind = DEF_NULL;
997 if (par_kind == DEF_NULL)
998 Proc_list->pl.param_kind = last_param_kind;
1000 Proc_list->pl.param_kind = par_kind;
1001 last_param_kind = Proc_list->pl.param_kind;
1002 defp->pc.paramtypes[(int)last_param_kind]++;
1003 Proc_list->component_kind = DEF_PARAM;
1004 Proc_list->code = alloc(250);
1005 Proc_list->scode = alloc(250);
1006 get_declaration(dec, DEF_PARAM);
1007 Proc_list->pl.param_name = dec->name;
1008 get1_param_type(defp, dec, &Proc_list->pl.param_type);
1010 scan2(TOK_COMMA, TOK_RPAREN, tokp);
1011 if (tokp->kind == TOK_COMMA)
1017 get1_param_type(defp, dec, param_type)
1022 char typecontents[100];
1024 if (streq(dec->type,"string")) {
1025 *param_type = "char *";
1028 strcpy(typecontents, dec->prefix);
1029 strcat(typecontents, " ");
1030 strcat(typecontents, dec->type);
1031 strcat(typecontents, " *");
1032 } else if (dec->rel == REL_POINTER) {
1033 strcpy(typecontents, dec->type);
1034 strcat(typecontents, " *");
1036 strcpy(typecontents, dec->type);
1037 *param_type = alloc(100);
1038 strcpy(*param_type, typecontents);
1044 get_param_type(defp, dec, param_type, typename)
1047 char **param_type, **typename;
1049 char typecontents[100];
1051 if (streq(dec->type,"string")) {
1052 *typename = "wrapstring";
1053 *param_type = "char *";
1055 *typename = dec->type;
1057 strcpy(typecontents, dec->prefix);
1058 strcat(typecontents, " ");
1059 strcat(typecontents, dec->type);
1060 strcat(typecontents, " *");
1061 dec->rel = REL_POINTER;
1062 } else if (dec->rel == REL_POINTER) {
1063 strcpy(typecontents, dec->type);
1064 strcat(typecontents, " *");
1066 strcpy(typecontents, dec->type);
1067 *param_type = alloc(100);
1068 strcpy(*param_type, typecontents);
1074 hndle_param_tail(defp, dec, tokp, typename)
1082 if (dec->rel == REL_POINTER)
1083 Proc_list->pl.param_flag |= INDIRECT_PARAM;
1085 Proc_list->pl.param_flag &= ~INDIRECT_PARAM;
1087 if (!(Proc_list->pl.param_flag & INDIRECT_PARAM))
1090 sprintf(Proc_list->code, "xdr_%s(&z_xdrs, %s%s)", typename, amp, Proc_list->pl.param_name);
1091 sprintf(Proc_list->scode, "xdr_%s(z_xdrs, &%s)", typename, Proc_list->pl.param_name);
1092 scan2(TOK_COMMA, TOK_RPAREN, tokp);
1093 if (tokp->kind == TOK_COMMA)
1099 cs_Proc_CodeGeneration(defp, split_flag, procheader)
1105 cs_ProcName_setup(defp, procheader, split_flag);
1107 cs_ProcParams_setup(defp, split_flag);
1108 cs_ProcMarshallInParams_setup(defp, split_flag);
1109 if (split_flag != 1) {
1110 cs_ProcSendPacket_setup(defp, split_flag);
1111 cs_ProcUnmarshallOutParams_setup(defp);
1113 cs_ProcTail_setup(defp, split_flag);
1119 cs_ProcName_setup(defp, procheader, split_flag)
1128 f_print(fout, "int %s%s%s%s(z_call", procheader, prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
1130 f_print(fout, "int %s%s%s%s(z_conn", procheader, prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
1133 if ((strlen(procheader) + strlen(prefix) + strlen(PackagePrefix[PackageIndex]) + strlen(defp->pc.proc_name)) >= MAX_FUNCTION_NAME_LEN) {
1134 error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
1137 for (plist = defp->pc.plists; plist; plist = plist->next) {
1138 if (plist->component_kind == DEF_PARAM) {
1139 plist->pl.param_flag &= ~PROCESSED_PARAM;
1140 f_print(fout, ", %s", plist->pl.param_name);
1143 f_print(fout, ")\n");
1149 cs_ProcParams_setup(defp, split_flag)
1153 proc1_list *plist, *plist1;
1156 f_print(fout, "\tregister struct rx_connection *z_conn;\n");
1158 f_print(fout, "\tregister struct rx_call *z_call;\n");
1160 for (plist = defp->pc.plists; plist; plist = plist->next) {
1161 if (plist->component_kind == DEF_PARAM && !(plist->pl.param_flag & PROCESSED_PARAM)) {
1162 if (plist->pl.param_flag & OUT_STRING) {
1163 f_print(fout, "\t%s *%s", plist->pl.param_type, plist->pl.param_name);
1165 f_print(fout, "\t%s %s", plist->pl.param_type, plist->pl.param_name);
1167 plist->pl.param_flag |= PROCESSED_PARAM;
1168 for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
1169 if ((plist1->component_kind == DEF_PARAM) && streq(plist->pl.param_type, plist1->pl.param_type) && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
1171 char *pntr = index(plist1->pl.param_type, '*');
1172 if (pntr) star = "*";
1173 if (plist1->pl.param_flag & OUT_STRING) {
1174 f_print(fout, ", *%s%s", star, plist1->pl.param_name);
1176 f_print(fout, ", %s%s", star, plist1->pl.param_name);
1178 plist1->pl.param_flag |= PROCESSED_PARAM;
1181 f_print(fout, ";\n");
1188 cs_ProcMarshallInParams_setup(defp, split_flag)
1192 int noofparams, i=0;
1195 int noofallparams = defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT] +
1196 defp->pc.paramtypes[OUT];
1198 f_print(fout, "{\n");
1200 f_print(fout, "\tstruct rx_call *z_call = rx_NewCall(z_conn);\n");
1201 if ((!split_flag) || (split_flag == 1)) {
1202 if (opcodesnotallowed[PackageIndex]) {
1203 f_print(fout, "\tstatic int z_op = %d;\n", defp->pc.proc_opcodenum);
1205 f_print(fout, "\tstatic int z_op = %s;\n", defp->pc.proc_opcodename);
1208 f_print(fout, "\tint z_result;\n");
1209 if (!(split_flag > 1) || (noofallparams != 0)) {
1210 f_print(fout, "\tXDR z_xdrs;\n");
1213 * Print out client side stat gathering call
1215 if (xflag && split_flag != 1) {
1216 f_print(fout, "\tstruct clock __QUEUE, __EXEC;\n");
1219 if ((!split_flag) || (split_flag == 1)) {
1220 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_ENCODE);\n");
1221 f_print(fout, "\n\t/* Marshal the arguments */\n");
1222 f_print(fout, "\tif ((!xdr_int(&z_xdrs, &z_op))");
1223 noofparams = defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT];
1224 for (plist = defp->pc.plists, dl=defp->def.st.decls; plist; plist = plist->next, dl = dl->next) {
1225 if (plist->component_kind == DEF_PARAM && (plist->pl.param_kind == DEF_INPARAM || plist->pl.param_kind == DEF_INOUTPARAM)) {
1226 f_print(fout, "\n\t || (!%s)", plist->code);
1227 if (++i == noofparams) {
1228 f_print(fout, ") {\n\t\tz_result = RXGEN_CC_MARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1234 f_print(fout, ") {\n\t\tz_result = RXGEN_CC_MARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1242 cs_ProcSendPacket_setup(defp, split_flag)
1246 int noofoutparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1248 if (noofoutparams) {
1249 f_print(fout, "\t/* Un-marshal the reply arguments */\n");
1251 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
1253 f_print(fout, "\tz_xdrs.x_op = XDR_DECODE;\n");
1260 cs_ProcUnmarshallOutParams_setup(defp)
1267 noofparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1269 for (plist = defp->pc.plists, dl=defp->def.st.decls,i = 0; plist; plist = plist->next, dl=dl->next) {
1270 if (plist->component_kind == DEF_PARAM && (plist->pl.param_kind == DEF_OUTPARAM || plist->pl.param_kind == DEF_INOUTPARAM)) {
1272 f_print(fout, "\tif ((!%s)", plist->code);
1274 f_print(fout, "\n\t || (!%s)", plist->code);
1276 if (++i == noofparams) {
1277 f_print(fout, ") {\n\t\tz_result = RXGEN_CC_UNMARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1286 cs_ProcTail_setup(defp, 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",
1329 PackagePrefix[PackageIndex]);
1330 f_print(fout, "\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(defp)
1345 ss_ProcName_setup(defp);
1347 ss_ProcParams_setup(defp, &somefrees);
1348 ss_ProcSpecial_setup(defp, &somefrees);
1349 ss_ProcUnmarshallInParams_setup(defp);
1350 ss_ProcCallRealProc_setup(defp);
1351 ss_ProcMarshallOutParams_setup(defp);
1352 ss_ProcTail_setup(defp, somefrees);
1358 ss_ProcName_setup(defp)
1363 if ((strlen(prefix) + strlen(PackagePrefix[PackageIndex]) + strlen(defp->pc.proc_name)) >= MAX_FUNCTION_NAME_LEN) {
1364 error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
1368 f_print(fout, "afs_int32 _%s%s%s(z_call, z_xdrs)\n", prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
1369 f_print(fout, "\tstruct rx_call *z_call;\n\tXDR *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 = (char *)0;
1385 ss_ProcParams_setup(defp, somefrees)
1389 proc1_list *plist, *plist1;
1392 int preserve_flag = 0;
1394 for (plist = defp->pc.plists; plist; plist = plist->next) {
1395 if ((plist->component_kind == DEF_PARAM) && !(plist->pl.param_flag & PROCESSED_PARAM)) {
1396 if (plist->pl.param_flag & INDIRECT_PARAM) {
1397 char pres, *pntr = index(plist->pl.param_type, '*');
1398 if (pntr){ --pntr; pres = *pntr; *pntr = (char)0; }
1399 f_print(fout, "\t%s %s", plist->pl.param_type, plist->pl.param_name);
1401 } else if (index(plist->pl.param_type, '*') == 0) {
1402 f_print(fout, "\t%s %s", plist->pl.param_type, plist->pl.param_name);
1404 plist->pl.param_flag |= FREETHIS_PARAM;
1406 f_print(fout, "\t%s %s=(%s)0", plist->pl.param_type, plist->pl.param_name, plist->pl.param_type);
1408 plist->pl.param_flag |= PROCESSED_PARAM;
1409 for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
1410 if ((plist1->component_kind == DEF_PARAM) && streq(plist->pl.param_type, plist1->pl.param_type) && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
1411 if (plist1->pl.param_flag & INDIRECT_PARAM) {
1412 f_print(fout, ", %s", plist1->pl.param_name);
1413 } else if (index(plist1->pl.param_type, '*') == 0) {
1414 f_print(fout, ", %s", plist1->pl.param_name);
1416 plist1->pl.param_flag |= FREETHIS_PARAM;
1418 f_print(fout, ", *%s=(%s)0", plist1->pl.param_name, plist1->pl.param_type);
1420 plist1->pl.param_flag |= PROCESSED_PARAM;
1423 f_print(fout, ";\n");
1426 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1427 defp1 = (definition *)listp->val;
1428 for (plist=defp->pc.plists; plist; plist=plist->next) {
1429 if (plist->component_kind == DEF_PARAM && (plist->pl.param_kind == DEF_OUTPARAM || plist->pl.param_kind == DEF_INOUTPARAM) && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1430 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1431 switch (defp1->pc.rel) {
1440 fprintf(fout, "\n");
1445 ss_ProcSpecial_setup(defp, somefrees)
1453 for (listp = special_defined; listp != NULL; listp = listp->next) {
1454 defp1 = (definition *)listp->val;
1455 for (plist=defp->pc.plists; plist; plist=plist->next) {
1456 if (plist->component_kind == DEF_PARAM && (plist->pl.param_kind == DEF_INPARAM || plist->pl.param_kind == DEF_INOUTPARAM)) {
1457 spec_list *spec = defp1->def.sd.specs;
1459 strcpy(string, structname(spec->sdef.string_value));
1460 if (streq(string, structname(plist->pl.param_type))) {
1461 plist->pl.string_name = spec->sdef.string_name;
1462 plist->pl.param_flag |= FREETHIS_PARAM;
1464 fprintf(fout, "\n\t%s.%s = 0;", plist->pl.param_name, spec->sdef.string_name);
1470 fprintf(fout, "\n");
1471 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1472 defp1 = (definition *)listp->val;
1473 for (plist=defp->pc.plists; plist; plist=plist->next) {
1474 if (plist->component_kind == DEF_PARAM ) {
1475 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1476 plist->pl.param_flag |= FREETHIS_PARAM;
1478 switch (defp1->pc.rel) {
1480 f_print(fout, "\n\t%s.%s_val = 0;", plist->pl.param_name, defp1->def_name);
1481 f_print(fout, "\n\t%s.%s_len = 0;", plist->pl.param_name, defp1->def_name);
1482 plist->pl.string_name = alloc(40);
1483 s_print(plist->pl.string_name, "%s_val", defp1->def_name);
1486 f_print(fout, "\n\t%s = 0;", plist->pl.param_name);
1487 plist->pl.string_name = NULL;
1494 f_print(fout, "\n");
1499 ss_ProcUnmarshallInParams_setup(defp)
1502 int noofparams, noofoutparams, i;
1505 noofparams = defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT];
1506 noofoutparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1507 for (plist = defp->pc.plists, i=0; plist; plist = plist->next) {
1508 if (plist->component_kind == DEF_PARAM && (plist->pl.param_kind == DEF_INPARAM || plist->pl.param_kind == DEF_INOUTPARAM)) {
1510 f_print(fout, "\n\tif ((!%s)", (plist->scode ? plist->scode : plist->code));
1512 f_print(fout, "\n\t || (!%s)", (plist->scode ? plist->scode : plist->code));
1514 if (++i == noofparams) {
1515 if (!noofoutparams) {
1516 f_print(fout, ") {\n");
1518 f_print(fout, ") {\n");
1520 f_print(fout, "\t\tz_result = RXGEN_SS_UNMARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1529 ss_ProcCallRealProc_setup(defp)
1535 f_print(fout, "\tz_result = %s%s%s%s(z_call", prefix, ServerPrefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
1536 for (plist = defp->pc.plists; plist; plist = plist->next) {
1537 if (plist->component_kind == DEF_PARAM) {
1538 if (plist->pl.param_flag & INDIRECT_PARAM) {
1539 f_print(fout, ", &%s", plist->pl.param_name);
1541 if (plist->pl.param_flag & OUT_STRING) {
1542 f_print(fout, ", &%s", plist->pl.param_name);
1544 f_print(fout, ", %s", plist->pl.param_name);
1549 f_print(fout, ");\n");
1551 f_print(fout, "\tif (z_result)\n\t\treturn z_result;\n");
1557 ss_ProcMarshallOutParams_setup(defp)
1563 noofparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1565 f_print(fout, "\tz_xdrs->x_op = XDR_ENCODE;\n");
1567 for (plist = defp->pc.plists, i=0; plist; plist = plist->next) {
1568 if (plist->component_kind == DEF_PARAM && (plist->pl.param_kind == DEF_OUTPARAM || plist->pl.param_kind == DEF_INOUTPARAM)) {
1570 f_print(fout, "\tif ((!%s)", (plist->scode ? plist->scode : plist->code));
1572 f_print(fout, "\n\t || (!%s)", (plist->scode ? plist->scode : plist->code));
1574 if (++i == noofparams) {
1575 f_print(fout, ")\n\t\tz_result = RXGEN_SS_MARSHAL;\n");
1584 ss_ProcTail_setup(defp, somefrees)
1593 if (defp->can_fail) {
1594 f_print(fout, "fail:\n");
1596 for (plist = defp->pc.plists; plist; plist = plist->next) {
1597 if (plist->component_kind == DEF_PARAM && (plist->pl.param_flag & FREETHIS_PARAM))
1601 f_print(fout, "\tz_xdrs->x_op = XDR_FREE;\n");
1602 for (plist = defp->pc.plists; plist; plist = plist->next) {
1603 if (plist->component_kind == DEF_PARAM && (plist->pl.param_flag & FREETHIS_PARAM)) {
1604 char *dot = "", *extens = "";
1605 if (plist->pl.string_name) {
1607 extens = plist->pl.string_name;
1609 f_print(fout, "\tif (!%s) goto fail1;\n", plist->scode);
1612 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1613 defp1 = (definition *)listp->val;
1614 for (plist=defp->pc.plists; plist; plist=plist->next) {
1615 if (plist->component_kind == DEF_PARAM && (plist->pl.param_kind == DEF_OUTPARAM || plist->pl.param_kind == DEF_INOUTPARAM) && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1616 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1617 switch (defp1->pc.rel) {
1620 if (!somefrees && !firsttime) {
1622 f_print(fout, "\tz_xdrs->x_op = XDR_FREE;\n");
1625 f_print(fout, "\tif (!%s) goto fail1;\n", plist->scode);
1632 for (listp = uniondef_defined; listp != NULL; listp = listp->next) {
1633 defp1 = (definition *)listp->val;
1634 for (plist=defp->pc.plists; plist; plist=plist->next) {
1635 if (plist->component_kind == DEF_PARAM && (plist->pl.param_kind == DEF_OUTPARAM || plist->pl.param_kind == DEF_INOUTPARAM) && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1636 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1637 if (plist->pl.param_flag & INDIRECT_PARAM) {
1638 if (!somefrees && !firsttime) {
1640 f_print(fout, "\tz_xdrs->x_op = XDR_FREE;\n");
1643 f_print(fout, "\tif (!%s) goto fail1;\n", plist->scode);
1651 f_print(fout, "\tif (rx_enable_stats) {\n");
1652 f_print(fout, "\t clock_GetTime(&__EXEC);\n");
1653 f_print(fout, "\t clock_Sub(&__EXEC, &z_call->startTime);\n");
1654 f_print(fout, "\t __QUEUE = z_call->startTime;\n");
1655 f_print(fout, "\t clock_Sub(&__QUEUE, &z_call->queueTime);\n");
1656 f_print(fout, "\t rx_IncrementTimeAndCount(z_call->conn->peer,");
1657 if (PackageStatIndex[PackageIndex]) {
1658 f_print(fout, " %s,\n", PackageStatIndex[PackageIndex]);
1661 "\n\t\t(((afs_uint32)(ntohs(z_call->conn->serviceId) << 16)) |\n"
1662 "\t\t((afs_uint32)ntohs(z_call->conn->service->servicePort))),\n");
1664 f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, &__QUEUE, &__EXEC,\n",
1666 PackagePrefix[PackageIndex]);
1667 f_print(fout, "\t\t&z_call->bytesSent, &z_call->bytesRcvd, 0);\n");
1668 f_print(fout, "\t}\n\n");
1671 f_print(fout, "\treturn z_result;\n");
1673 f_print(fout, "fail1:\n");
1676 f_print(fout, "\tif (rx_enable_stats) {\n");
1677 f_print(fout, "\t clock_GetTime(&__EXEC);\n");
1678 f_print(fout, "\t clock_Sub(&__EXEC, &z_call->startTime);\n");
1679 f_print(fout, "\t __QUEUE = z_call->startTime;\n");
1680 f_print(fout, "\t clock_Sub(&__QUEUE, &z_call->queueTime);\n");
1681 f_print(fout, "\t rx_IncrementTimeAndCount(z_call->conn->peer,");
1682 if (PackageStatIndex[PackageIndex]) {
1683 f_print(fout, " %s,\n", PackageStatIndex[PackageIndex]);
1686 "\n\t\t(((afs_uint32)(ntohs(z_call->conn->serviceId) << 16)) |\n"
1687 "\t\t((afs_uint32)ntohs(z_call->conn->service->servicePort))),\n");
1689 f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, &__QUEUE, &__EXEC,\n",
1691 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 RXGEN_SS_XDRFREE;\n}\n\n");
1698 f_print(fout, "}\n\n");
1704 opcode_holes_exist()
1708 for (i=lowest_opcode[PackageIndex]; i<highest_opcode[PackageIndex]; i++) {
1709 if (!opcodenum_is_defined(i))
1717 er_Proc_CodeGeneration()
1721 temp = PackageIndex;
1722 if (!combinepackages) PackageIndex = 0;
1723 for (; PackageIndex <= temp; PackageIndex++) {
1724 if (proc_defined[PackageIndex] == NULL) continue;
1725 if (combinepackages || opcode_holes_exist()) {
1726 er_HeadofOldStyleProc_setup();
1727 er_BodyofOldStyleProc_setup();
1728 er_TailofOldStyleProc_setup();
1730 er_ProcDeclExterns_setup();
1731 er_ProcProcsArray_setup();
1732 er_ProcMainBody_setup();
1735 PackageIndex = temp;
1740 er_ProcDeclExterns_setup()
1745 f_print(fout, "\n");
1746 for (listp = proc_defined[PackageIndex]; listp != NULL; listp = listp->next) {
1747 defp = (definition *)listp->val;
1748 if (defp->pc.proc_serverstub) {
1749 f_print(fout, "afs_int32 %s();\n", defp->pc.proc_serverstub);
1751 f_print(fout, "afs_int32 _%s%s%s();\n", prefix, defp->pc.proc_prefix, defp->pc.proc_name);
1758 er_ProcProcsArray_setup()
1763 if (listp = proc_defined[PackageIndex]) {
1764 defp = (definition *)listp->val;
1765 if (defp->pc.proc_serverstub){
1766 f_print(fout, "\nstatic afs_int32 (*StubProcsArray%d[])() = {%s", PackageIndex, defp->pc.proc_serverstub);
1768 f_print(fout, "\nstatic afs_int32 (*StubProcsArray%d[])() = {_%s%s%s", PackageIndex, prefix, defp->pc.proc_prefix, (defp = (definition *)listp->val)->pc.proc_name);
1770 listp = listp->next;
1772 for (; listp != NULL; listp = listp->next) {
1773 defp = (definition *)listp->val;
1774 if (defp->pc.proc_serverstub) {
1775 f_print(fout, ",%s", defp->pc.proc_serverstub);
1777 f_print(fout, ", _%s%s%s", prefix, defp->pc.proc_prefix, defp->pc.proc_name);
1780 f_print(fout, "};\n\n");
1785 er_ProcMainBody_setup()
1787 f_print(fout, "%s%sExecuteRequest(z_call)\n", prefix, PackagePrefix[PackageIndex]);
1788 f_print(fout, "\tregister struct rx_call *z_call;\n");
1789 f_print(fout, "{\n\tint op;\n");
1790 f_print(fout, "\tXDR z_xdrs;\n");
1791 f_print(fout, "\t" "afs_int32 z_result;\n\n");
1792 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
1793 f_print(fout, "\tif (!xdr_int(&z_xdrs, &op))\n\t\tz_result = RXGEN_DECODE;\n");
1794 f_print(fout, "\telse if (op < %sLOWEST_OPCODE || op > %sHIGHEST_OPCODE)\n\t\tz_result = RXGEN_OPCODE;\n", PackagePrefix[PackageIndex], PackagePrefix[PackageIndex]);
1795 f_print(fout, "\telse\n\t\tz_result = (*StubProcsArray%d[op - %sLOWEST_OPCODE])(z_call, &z_xdrs);\n", PackageIndex, PackagePrefix[PackageIndex]);
1796 f_print(fout, "\treturn hton_syserr_conv(z_result);\n}\n");
1801 er_HeadofOldStyleProc_setup()
1803 f_print(fout, "\n%s%sExecuteRequest (z_call)\n", prefix, (combinepackages ? MasterPrefix : PackagePrefix[PackageIndex]));
1804 f_print(fout, "\tregister struct rx_call *z_call;\n");
1805 f_print(fout, "{\n");
1806 f_print(fout, "\tint op;\n");
1807 f_print(fout, "\tXDR z_xdrs;\n");
1808 f_print(fout, "\t" "afs_int32 z_result;\n\n");
1809 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
1810 f_print(fout, "\tz_result = RXGEN_DECODE;\n");
1811 f_print(fout, "\tif (!xdr_int(&z_xdrs, &op)) goto fail;\n");
1812 f_print(fout, "\tswitch (op) {\n");
1816 er_BodyofOldStyleProc_setup()
1820 if (combinepackages) {
1821 int temp = PackageIndex;
1822 for (PackageIndex = 0; PackageIndex <= temp; PackageIndex++) {
1823 for (listp = proc_defined[PackageIndex]; listp != NULL; listp = listp->next)
1824 proc_er_case((definition *)listp->val);
1826 PackageIndex = temp;
1828 for (listp = proc_defined[PackageIndex]; listp != NULL; listp = listp->next)
1829 proc_er_case((definition *)listp->val);
1838 if (opcodesnotallowed[PackageIndex]) {
1839 f_print(fout, "\t\tcase %d: {\n", defp->pc.proc_opcodenum);
1841 f_print(fout, "\t\tcase %s: {\n", defp->pc.proc_opcodename);
1843 if (defp->pc.proc_serverstub) {
1844 f_print(fout, "\t\t\t" "afs_int32 %s();\n", defp->pc.proc_serverstub);
1845 f_print(fout, "\t\t\tz_result = %s(z_call, &z_xdrs);\n", defp->pc.proc_serverstub);
1847 f_print(fout, "\t\t\t" "afs_int32 _%s%s%s();\n", prefix, defp->pc.proc_prefix, defp->pc.proc_name);
1848 f_print(fout, "\t\t\tz_result = _%s%s%s(z_call, &z_xdrs);\n", prefix, defp->pc.proc_prefix, defp->pc.proc_name);
1850 f_print(fout, "\t\t\tbreak;\n\t\t}\n");
1855 er_TailofOldStyleProc_setup()
1857 f_print(fout, "\t\tdefault:\n");
1858 f_print(fout, "\t\t\tz_result = RXGEN_OPCODE;\n");
1859 f_print(fout, "\t\t\tbreak;\n\t}\n");
1860 f_print(fout, "fail:\n");
1861 f_print(fout, "\treturn z_result;\n}\n");
1865 int h_opcode_stats()
1867 if (combinepackages) {
1868 f_print(fout, "\n/* Opcode-related useful stats for Master package: %s */\n", MasterPrefix);
1869 f_print(fout, "#define %sLOWEST_OPCODE %d\n", MasterPrefix, master_lowest_opcode);
1870 f_print(fout, "#define %sHIGHEST_OPCODE %d\n", MasterPrefix, master_highest_opcode);
1871 f_print(fout, "#define %sNUMBER_OPCODES %d\n\n", MasterPrefix, master_no_of_opcodes);
1873 f_print(fout, "#define %sNO_OF_STAT_FUNCS\t%d\n\n", MasterPrefix, no_of_stat_funcs_header[0]);
1874 f_print(fout, "AFS_RXGEN_EXPORT\n");
1875 f_print(fout, "extern const char *%sfunction_names[];\n\n", MasterPrefix);
1879 for (i=0; i <= PackageIndex; i++) {
1880 f_print(fout, "\n/* Opcode-related useful stats for package: %s */\n", PackagePrefix[i]);
1881 f_print(fout, "#define %sLOWEST_OPCODE %d\n", PackagePrefix[i], lowest_opcode[i]);
1882 f_print(fout, "#define %sHIGHEST_OPCODE %d\n", PackagePrefix[i], highest_opcode[i]);
1883 f_print(fout, "#define %sNUMBER_OPCODES %d\n\n", PackagePrefix[i], no_of_opcodes[i]);
1885 f_print(fout, "#define %sNO_OF_STAT_FUNCS\t%d\n\n", PackagePrefix[i], no_of_stat_funcs_header[i]);
1886 f_print(fout, "AFS_RXGEN_EXPORT\n");
1887 f_print(fout, "extern const char *%sfunction_names[];\n\n", PackagePrefix[i]);
1894 int generate_multi_macros(defp)
1897 char *startname = SplitStart, *endname = SplitEnd;
1905 f_print(fout, "\n#include <rx/rx_multi.h>");
1907 f_print(fout, "\n#define multi_%s%s(", PackagePrefix[PackageIndex],defp->pc.proc_name);
1908 for (plist = defp->pc.plists; plist; plist = plist->next) {
1909 if (plist->component_kind == DEF_PARAM) {
1912 f_print(fout, "%s", plist->pl.param_name);
1914 f_print(fout, ", %s", plist->pl.param_name);
1918 f_print(fout, ") \\\n");
1919 if (!startname) startname = "Start";
1920 if (!endname) endname = "End";
1921 f_print(fout, "\tmulti_Body(%s%s%s(multi_call", startname, PackagePrefix[PackageIndex], defp->pc.proc_name);
1922 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 0);
1923 for (plist = defp->pc.plists; plist; plist = plist->next) {
1924 if (plist->component_kind == DEF_PARAM)
1925 f_print(fout, ", %s", plist->pl.param_name);
1927 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 1);
1928 f_print(fout, "), %s%s%s(multi_call", endname, PackagePrefix[PackageIndex], defp->pc.proc_name);
1929 do_split(defp, IN, &numofparams, DEF_INPARAM, 0);
1930 for (plist = defp->pc.plists; plist; plist = plist->next) {
1931 if (plist->component_kind == DEF_PARAM) {
1932 f_print(fout, ", %s", plist->pl.param_name);
1935 do_split(defp, IN, &numofparams, DEF_INPARAM, 1);
1936 f_print(fout, "))\n\n");
1944 if (tokp->kind == TOK_PACKAGE || tokp->kind == TOK_PREFIX ||
1945 tokp->kind == TOK_SPECIAL || tokp->kind == TOK_STARTINGOPCODE ||
1946 tokp->kind == TOK_SPLITPREFIX || tokp->kind == TOK_PROC ||
1947 tokp->kind == TOK_STATINDEX)
1953 IsRxgenDefinition(def)
1956 if (def->def_kind == DEF_PACKAGE || def->def_kind == DEF_PREFIX || def->def_kind == DEF_SPECIAL || def->def_kind == DEF_STARTINGOPCODE || def->def_kind == DEF_SPLITPREFIX || def->def_kind == DEF_PROC)