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>
36 #include <afsconfig.h>
49 #include "rpc_parse.h"
53 list *proc_defined[MAX_PACKAGES], *special_defined, *typedef_defined, *uniondef_defined;
54 char *SplitStart = NULL;
55 char *SplitEnd = NULL;
56 char *MasterPrefix = NULL;
57 char *ServerPrefix = "";
58 char *PackagePrefix[MAX_PACKAGES];
59 char *PackageStatIndex[MAX_PACKAGES];
60 int no_of_stat_funcs = 0; /*
61 * current function number in client interface
64 int no_of_stat_funcs_header[MAX_PACKAGES]; /*
65 * Total number of functions in client
68 int no_of_opcodes[MAX_PACKAGES], master_no_of_opcodes = 0;
69 int lowest_opcode[MAX_PACKAGES], master_lowest_opcode = 99999;
70 int highest_opcode[MAX_PACKAGES], master_highest_opcode = 0;
71 int master_opcodenumber = 99999;
72 int opcodesnotallowed[MAX_PACKAGES];
73 int combinepackages = 0;
74 int PackageIndex = -1;
75 int PerProcCounter = 0;
79 * Character arrays to keep list of function names as we process the file
82 char function_list[MAX_PACKAGES]
83 [MAX_FUNCTIONS_PER_PACKAGE]
84 [MAX_FUNCTION_NAME_LEN];
85 int function_list_index;
87 extern int pushed, scan_print;
96 static get_declaration();
98 static unsigned_dec();
101 static def_startingopcode();
102 static def_statindex();
104 static customize_struct();
105 static def_special();
107 static int InvalidConstant();
108 static opcodenum_is_defined();
109 static analyze_ProcParams();
110 static generate_code();
111 static handle_split_proc();
113 static hdle_param_tok();
114 static get1_param_type();
115 static get_param_type();
116 static cs_Proc_CodeGeneration();
117 static cs_ProcName_setup();
118 static cs_ProcParams_setup();
119 static cs_ProcMarshallInParams_setup();
120 static cs_ProcSendPacket_setup();
121 static cs_ProcUnmarshallOutParams_setup();
122 static cs_ProcTail_setup();
123 static ss_Proc_CodeGeneration();
124 static ss_ProcName_setup();
125 static ss_ProcParams_setup();
126 static ss_ProcProto_setup();
127 static ss_ProcSpecial_setup();
128 static ss_ProcUnmarshallInParams_setup();
129 static ss_ProcCallRealProc_setup();
130 static ss_ProcMarshallOutParams_setup();
131 static ss_ProcTail_setup();
132 static er_ProcDeclExterns_setup();
133 static er_ProcProcsArray_setup();
134 static er_ProcMainBody_setup();
135 static er_HeadofOldStyleProc_setup();
136 static er_BodyofOldStyleProc_setup();
137 static proc_er_case();
138 static er_TailofOldStyleProc_setup();
141 * return the next definition you see
149 defp = ALLOC(definition);
150 bzero((char *)defp, sizeof(definition));
186 def_special(&dec, defp);
189 case TOK_STARTINGOPCODE:
190 def_startingopcode(defp);
195 customize_struct(defp);
197 case TOK_SPLITPREFIX:
202 if (tok.kind == TOK_LPAREN) {
204 check_proc(defp, &tok, 1);
207 check_proc(defp, &tok, 0);
210 check_proc(defp, &tok, 0);
214 check_proc(defp, &tok, 1);
217 error("definition keyword expected");
219 if (!IsRxgenToken(&tok))
221 scan(TOK_SEMICOLON,&tok);
231 STOREVAL(&defined, defp);
244 defp->def_kind = DEF_STRUCT;
246 scan(TOK_IDENT, &tok);
247 defp->def_name = tok.str;
248 scan(TOK_LBRACE, &tok);
249 tailp = &defp->def.st.decls;
251 get_declaration(&dec, DEF_STRUCT);
252 decls = ALLOC(decl_list);
255 tailp = &decls->next;
256 scan(TOK_SEMICOLON, &tok);
258 } while (tok.kind != TOK_RBRACE);
269 version_list **vtailp;
273 defp->def_kind = DEF_PROGRAM;
274 scan(TOK_IDENT, &tok);
275 defp->def_name = tok.str;
276 scan(TOK_LBRACE, &tok);
277 vtailp = &defp->def.pr.versions;
278 scan(TOK_VERSION, &tok);
280 scan(TOK_IDENT, &tok);
281 vlist = ALLOC(version_list);
282 vlist->vers_name = tok.str;
283 scan(TOK_LBRACE, &tok);
284 ptailp = &vlist->procs;
286 plist = ALLOC(proc_list);
287 get_type(&plist->res_prefix, &plist->res_type, DEF_PROGRAM);
288 if (streq(plist->res_type, "opaque")) {
289 error("illegal result type");
291 scan(TOK_IDENT, &tok);
292 plist->proc_name = tok.str;
293 scan(TOK_LPAREN, &tok);
294 get_type(&plist->arg_prefix, &plist->arg_type, DEF_PROGRAM);
295 if (streq(plist->arg_type, "opaque")) {
296 error("illegal argument type");
298 scan(TOK_RPAREN, &tok);
299 scan(TOK_EQUAL, &tok);
301 scan(TOK_SEMICOLON, &tok);
302 plist->proc_num = tok.str;
304 ptailp = &plist->next;
306 } while (tok.kind != TOK_RBRACE);
308 vtailp = &vlist->next;
309 scan(TOK_RBRACE, &tok);
310 scan(TOK_EQUAL, &tok);
312 vlist->vers_num = tok.str;
313 scan(TOK_SEMICOLON, &tok);
314 scan2(TOK_VERSION, TOK_RBRACE, &tok);
315 } while (tok.kind == TOK_VERSION);
316 scan(TOK_EQUAL, &tok);
318 defp->def.pr.prog_num = tok.str;
328 enumval_list **tailp;
330 defp->def_kind = DEF_ENUM;
331 scan(TOK_IDENT, &tok);
332 defp->def_name = tok.str;
333 scan(TOK_LBRACE, &tok);
334 tailp = &defp->def.en.vals;
336 scan(TOK_IDENT, &tok);
337 elist = ALLOC(enumval_list);
338 elist->name = tok.str;
339 elist->assignment = NULL;
340 scan3(TOK_COMMA, TOK_RBRACE, TOK_EQUAL, &tok);
341 if (tok.kind == TOK_EQUAL) {
343 elist->assignment = tok.str;
344 scan2(TOK_COMMA, TOK_RBRACE, &tok);
347 tailp = &elist->next;
348 } while (tok.kind != TOK_RBRACE);
358 defp->def_kind = DEF_CONST;
359 scan(TOK_IDENT, &tok);
360 defp->def_name = tok.str;
361 scan(TOK_EQUAL, &tok);
362 scan2(TOK_IDENT, TOK_STRCONST, &tok);
363 defp->def.co = tok.str;
375 defp->def_kind = DEF_UNION;
376 scan(TOK_IDENT, &tok);
377 defp->def_name = tok.str;
378 scan(TOK_SWITCH, &tok);
379 scan(TOK_LPAREN, &tok);
380 get_declaration(&dec, DEF_UNION);
381 defp->def.un.enum_decl = dec;
382 tailp = &defp->def.un.cases;
383 scan(TOK_RPAREN, &tok);
384 scan(TOK_LBRACE, &tok);
385 scan(TOK_CASE, &tok);
386 while (tok.kind == TOK_CASE) {
387 scan(TOK_IDENT, &tok);
388 cases = ALLOC(case_list);
389 cases->case_name = tok.str;
390 scan(TOK_COLON, &tok);
391 get_declaration(&dec, DEF_UNION);
392 cases->case_decl = dec;
394 tailp = &cases->next;
395 scan(TOK_SEMICOLON, &tok);
396 scan3(TOK_CASE, TOK_DEFAULT, TOK_RBRACE, &tok);
399 if (tok.kind == TOK_DEFAULT) {
400 scan(TOK_COLON, &tok);
401 get_declaration(&dec, DEF_UNION);
402 defp->def.un.default_decl = ALLOC(declaration);
403 *defp->def.un.default_decl = dec;
404 scan(TOK_SEMICOLON, &tok);
405 scan(TOK_RBRACE, &tok);
407 defp->def.un.default_decl = NULL;
418 defp->def_kind = DEF_TYPEDEF;
419 get_declaration(&dec, DEF_TYPEDEF);
420 defp->def_name = dec.name;
421 defp->def.ty.old_prefix = dec.prefix;
422 defp->def.ty.old_type = dec.type;
423 defp->def.ty.rel = dec.rel;
424 defp->def.ty.array_max = dec.array_max;
429 get_declaration(dec, dkind)
435 get_type(&dec->prefix, &dec->type, dkind);
436 dec->rel = REL_ALIAS;
437 if (streq(dec->type, "void")) {
440 scan2(TOK_STAR, TOK_IDENT, &tok);
441 if (tok.kind == TOK_STAR) {
442 dec->rel = REL_POINTER;
443 scan(TOK_IDENT, &tok);
446 if (peekscan(TOK_LBRACKET, &tok)) {
447 if (dec->rel == REL_POINTER) {
448 error("no array-of-pointer declarations -- use typedef");
450 dec->rel = REL_VECTOR;
452 dec->array_max = tok.str;
453 scan(TOK_RBRACKET, &tok);
454 } else if (peekscan(TOK_LANGLE, &tok)) {
455 if (dec->rel == REL_POINTER) {
456 error("no array-of-pointer declarations -- use typedef");
458 dec->rel = REL_ARRAY;
459 if (peekscan(TOK_RANGLE, &tok)) {
460 dec->array_max = "~0"; /* unspecified size, use max */
463 dec->array_max = tok.str;
464 scan(TOK_RANGLE, &tok);
467 if (streq(dec->type, "opaque")) {
468 if (dec->rel != REL_ARRAY && dec->rel != REL_VECTOR) {
469 error("array declaration expected");
471 } else if (streq(dec->type, "string")) {
472 if (dec->rel != REL_ARRAY) {
473 error(" variable-length array declaration expected");
480 get_type(prefixp, typep, dkind)
497 scan(TOK_IDENT, &tok);
505 (void) peekscan(TOK_INT, &tok);
508 *typep = "afs_int32";
509 (void) peekscan(TOK_INT, &tok);
512 if (dkind != DEF_UNION && dkind != DEF_PROGRAM) {
513 error("voids allowed only inside union and program definitions");
528 error("expected type specifier");
548 (void) peekscan(TOK_INT, &tok);
552 *typep = "afs_uint32";
553 (void) peekscan(TOK_INT, &tok);
572 defp->def_kind = DEF_PACKAGE;
573 scan(TOK_IDENT, &tok);
574 defp->def_name = tok.str;
575 no_of_stat_funcs = 0;
576 if (PackageIndex++ >= MAX_PACKAGES)
577 error("Exceeded upper limit of package statements\n");
578 function_list_index = 0;
579 PackagePrefix[PackageIndex] = tok.str;
580 if (MasterPrefix == NULL)
581 MasterPrefix = tok.str;
582 no_of_opcodes[PackageIndex] = highest_opcode[PackageIndex] = opcodesnotallowed[PackageIndex] = 0;
583 lowest_opcode[PackageIndex] = 99999;
584 proc_defined[PackageIndex] = NULL;
585 PackageStatIndex[PackageIndex] = NULL;
594 defp->def_kind = DEF_PREFIX;
595 scan(TOK_IDENT, &tok);
596 defp->def_name = tok.str;
597 ServerPrefix = tok.str;
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!");
615 name = alloc(strlen(PackagePrefix[PackageIndex])+strlen("STATINDEX")+1);
616 strcpy(name, PackagePrefix[PackageIndex]);
617 strcat(name, "STATINDEX");
618 defp->def_name = name;
619 defp->def.co = tok.str;
620 PackageStatIndex[PackageIndex] = name;
624 def_startingopcode(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 || lowest_opcode[PackageIndex] > 99999)
636 error("startingopcode number is out of bounds (must be >= 0 < 100000)");
637 master_opcodenumber = lowest_opcode[PackageIndex];
638 opcodesnotallowed[PackageIndex]=1;
647 defp->def_kind = DEF_SPLITPREFIX;
652 scan(TOK_EQUAL, &tok);
653 scan(TOK_IDENT, &tok);
654 SplitStart = tok.str;
657 scan(TOK_EQUAL, &tok);
658 scan(TOK_IDENT, &tok);
664 error("syntax error in the 'splitprefix' line");
666 } while (tok.kind != TOK_SEMICOLON);
667 if (!SplitStart && !SplitEnd)
668 error("At least one param should be passed to 'splitprefix' cmd");
673 customize_struct(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);
703 char namecontents[150], *pnt, *pnt1;
705 strcpy(namecontents, name);
707 if (!strncmp(pnt, "struct", 6)) pnt += 6;
708 while (isspace(*pnt)) pnt++;
710 while (*pnt != ' ' && *pnt != '\0') pnt++;
717 def_special(dec, 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(defp, tokp, noname)
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 scan2(TOK_EQUAL, TOK_SEMICOLON, &tok);
784 if (tok.kind == TOK_EQUAL) {
785 if (opcodesnotallowed[PackageIndex])
786 error("Opcode assignment isn't allowed here!");
788 if (InvalidConstant(tok.str))
789 error("Illegal Opcode assignment (Must be a constant opcode!)");
790 if (opcodenum_is_defined(atoi(tok.str)))
791 error("The opcode number is already used by a previous proc");
792 defp->pc.proc_opcodename = tok.str;
793 defp->pc.proc_opcodenum = atoi(tok.str);
794 if (defp->pc.proc_opcodenum < lowest_opcode[PackageIndex])
795 lowest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
796 if (defp->pc.proc_opcodenum < master_lowest_opcode)
797 master_lowest_opcode = defp->pc.proc_opcodenum;
798 if (defp->pc.proc_opcodenum > highest_opcode[PackageIndex])
799 highest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
800 if (defp->pc.proc_opcodenum > master_highest_opcode)
801 master_highest_opcode = defp->pc.proc_opcodenum;
802 scan(TOK_SEMICOLON, &tok);
804 if (master_opcodenumber == 99999) master_opcodenumber = 0;
805 defp->pc.proc_opcodenum = master_opcodenumber++;
806 if (defp->pc.proc_opcodenum < lowest_opcode[PackageIndex])
807 lowest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
808 if (defp->pc.proc_opcodenum > highest_opcode[PackageIndex])
809 highest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
810 if (defp->pc.proc_opcodenum > master_highest_opcode)
811 master_highest_opcode = defp->pc.proc_opcodenum;
812 opcodesnotallowed[PackageIndex] = 1; /* force it */
814 no_of_opcodes[PackageIndex]++, master_no_of_opcodes++;
816 generate_code(defp, 0, 1);
817 if (Cflag || cflag) {
818 generate_code(defp, 1, 1);
820 generate_multi_macros(defp);
822 generate_code(defp, proc_split, 0);
825 if (function_list_index >= MAX_FUNCTIONS_PER_INTERFACE) {
826 error("too many functions in interface, "
827 "increase MAX_FUNCTIONS_PER_INTERFACE");
829 sprintf(function_list[PackageIndex][function_list_index],
832 PackagePrefix[PackageIndex],
835 function_list_index++;
836 no_of_stat_funcs_header[PackageIndex]++;
842 #define LEGALNUMS "0123456789"
844 InvalidConstant(name)
852 return(slen != strspn(name, map));
856 opcodenum_is_defined(opcode_num)
862 for (listp = proc_defined[PackageIndex]; listp != NULL; listp = listp->next) {
863 defp = (definition *)listp->val;
864 if (opcode_num == defp->pc.proc_opcodenum)
872 analyze_ProcParams(defp, tokp)
877 decl_list *decls, **tailp;
879 Proc_listp = &defp->pc.plists;
880 tailp = &defp->def.st.decls;
883 Proc_list = ALLOC(proc1_list);
884 bzero((char *)Proc_list, sizeof(proc1_list));
885 Proc_list->pl.param_flag = 0;
886 switch (tokp->kind) {
888 hdle_param_tok(defp, &dec, tokp, DEF_INPARAM);
891 hdle_param_tok(defp, &dec, tokp, DEF_OUTPARAM);
894 hdle_param_tok(defp, &dec, tokp, DEF_INOUTPARAM);
900 hdle_param_tok(defp, &dec, tokp, DEF_NULL);
903 *Proc_listp = Proc_list;
904 Proc_listp = &Proc_list->next;
905 decls = ALLOC(decl_list);
906 bzero((char *)decls, sizeof(decl_list));
909 tailp = &decls->next;
910 } while (tokp->kind != TOK_RPAREN);
916 generate_code(defp, proc_split_flag, multi_flag)
922 handle_split_proc(defp, multi_flag);
924 if (Cflag || cflag) {
925 cs_Proc_CodeGeneration(defp, 0, "");
928 ss_Proc_CodeGeneration(defp);
931 STOREVAL(&proc_defined[PackageIndex], defp);
936 handle_split_proc(defp, multi_flag)
940 char *startname = SplitStart, *endname = SplitEnd;
947 if (Cflag || cflag) {
949 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 0);
951 cs_Proc_CodeGeneration(defp, 1, startname);
953 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 1);
954 do_split(defp, IN, &numofparams, DEF_INPARAM, 0);
956 cs_Proc_CodeGeneration(defp, (multi_flag ? 3 : 2), endname);
958 do_split(defp, IN, &numofparams, DEF_INPARAM, 1);
962 ss_Proc_CodeGeneration(defp);
967 do_split(defp, direction, numofparams, param_kind, restore_flag)
969 int direction, *numofparams, restore_flag;
975 defp->pc.paramtypes[direction] = *numofparams;
976 for (plist = defp->pc.plists; plist; plist = plist->next) {
977 if (plist->component_kind == DEF_NULL && plist->pl.param_kind == param_kind)
978 plist->component_kind = DEF_PARAM;
981 *numofparams = defp->pc.paramtypes[direction];
982 defp->pc.paramtypes[direction] = 0;
983 for (plist = defp->pc.plists; plist; plist = plist->next) {
984 if (plist->component_kind == DEF_PARAM && plist->pl.param_kind == param_kind)
985 plist->component_kind = DEF_NULL;
992 hdle_param_tok(defp, dec, tokp, par_kind)
998 static defkind last_param_kind = DEF_NULL;
1000 if (par_kind == DEF_NULL)
1001 Proc_list->pl.param_kind = last_param_kind;
1003 Proc_list->pl.param_kind = par_kind;
1004 last_param_kind = Proc_list->pl.param_kind;
1005 defp->pc.paramtypes[(int)last_param_kind]++;
1006 Proc_list->component_kind = DEF_PARAM;
1007 Proc_list->code = alloc(250);
1008 Proc_list->scode = alloc(250);
1009 get_declaration(dec, DEF_PARAM);
1010 Proc_list->pl.param_name = dec->name;
1011 get1_param_type(defp, dec, &Proc_list->pl.param_type);
1013 scan2(TOK_COMMA, TOK_RPAREN, tokp);
1014 if (tokp->kind == TOK_COMMA)
1020 get1_param_type(defp, dec, param_type)
1025 char typecontents[100];
1027 if (streq(dec->type,"string")) {
1028 *param_type = "char *";
1031 strcpy(typecontents, dec->prefix);
1032 strcat(typecontents, " ");
1033 strcat(typecontents, dec->type);
1034 strcat(typecontents, " *");
1035 } else if (dec->rel == REL_POINTER) {
1036 strcpy(typecontents, dec->type);
1037 strcat(typecontents, " *");
1039 strcpy(typecontents, dec->type);
1040 *param_type = alloc(100);
1041 strcpy(*param_type, typecontents);
1047 get_param_type(defp, dec, param_type, typename)
1050 char **param_type, **typename;
1052 char typecontents[100];
1054 if (streq(dec->type,"string")) {
1055 *typename = "wrapstring";
1056 *param_type = "char *";
1058 *typename = dec->type;
1060 strcpy(typecontents, dec->prefix);
1061 strcat(typecontents, " ");
1062 strcat(typecontents, dec->type);
1063 strcat(typecontents, " *");
1064 dec->rel = REL_POINTER;
1065 } else if (dec->rel == REL_POINTER) {
1066 strcpy(typecontents, dec->type);
1067 strcat(typecontents, " *");
1069 strcpy(typecontents, dec->type);
1070 *param_type = alloc(100);
1071 strcpy(*param_type, typecontents);
1077 hndle_param_tail(defp, dec, tokp, typename)
1085 if (dec->rel == REL_POINTER)
1086 Proc_list->pl.param_flag |= INDIRECT_PARAM;
1088 Proc_list->pl.param_flag &= ~INDIRECT_PARAM;
1090 if (!(Proc_list->pl.param_flag & INDIRECT_PARAM))
1093 sprintf(Proc_list->code, "xdr_%s(&z_xdrs, %s%s)", typename, amp, Proc_list->pl.param_name);
1094 sprintf(Proc_list->scode, "xdr_%s(z_xdrs, &%s)", typename, Proc_list->pl.param_name);
1095 scan2(TOK_COMMA, TOK_RPAREN, tokp);
1096 if (tokp->kind == TOK_COMMA)
1102 cs_Proc_CodeGeneration(defp, split_flag, procheader)
1108 cs_ProcName_setup(defp, procheader, split_flag);
1110 cs_ProcParams_setup(defp, split_flag);
1111 cs_ProcMarshallInParams_setup(defp, split_flag);
1112 if (split_flag != 1) {
1113 cs_ProcSendPacket_setup(defp, split_flag);
1114 cs_ProcUnmarshallOutParams_setup(defp);
1116 cs_ProcTail_setup(defp, split_flag);
1122 cs_ProcName_setup(defp, procheader, split_flag)
1131 f_print(fout, "int %s%s%s%s(z_call", procheader, prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
1133 f_print(fout, "int %s%s%s%s(z_conn", procheader, prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
1136 if ((strlen(procheader) + strlen(prefix) + strlen(PackagePrefix[PackageIndex]) + strlen(defp->pc.proc_name)) >= MAX_FUNCTION_NAME_LEN) {
1137 error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
1140 for (plist = defp->pc.plists; plist; plist = plist->next) {
1141 if (plist->component_kind == DEF_PARAM) {
1142 plist->pl.param_flag &= ~PROCESSED_PARAM;
1143 f_print(fout, ", %s", plist->pl.param_name);
1146 f_print(fout, ")\n");
1152 cs_ProcParams_setup(defp, split_flag)
1156 proc1_list *plist, *plist1;
1159 f_print(fout, "\tregister struct rx_connection *z_conn;\n");
1161 f_print(fout, "\tregister struct rx_call *z_call;\n");
1163 for (plist = defp->pc.plists; plist; plist = plist->next) {
1164 if (plist->component_kind == DEF_PARAM && !(plist->pl.param_flag & PROCESSED_PARAM)) {
1165 if (plist->pl.param_flag & OUT_STRING) {
1166 f_print(fout, "\t%s *%s", plist->pl.param_type, plist->pl.param_name);
1168 f_print(fout, "\t%s %s", plist->pl.param_type, plist->pl.param_name);
1170 plist->pl.param_flag |= PROCESSED_PARAM;
1171 for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
1172 if ((plist1->component_kind == DEF_PARAM) && streq(plist->pl.param_type, plist1->pl.param_type) && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
1174 char *pntr = index(plist1->pl.param_type, '*');
1175 if (pntr) star = "*";
1176 if (plist1->pl.param_flag & OUT_STRING) {
1177 f_print(fout, ", *%s%s", star, plist1->pl.param_name);
1179 f_print(fout, ", %s%s", star, plist1->pl.param_name);
1181 plist1->pl.param_flag |= PROCESSED_PARAM;
1184 f_print(fout, ";\n");
1191 cs_ProcMarshallInParams_setup(defp, split_flag)
1195 int noofparams, i=0;
1198 int noofallparams = defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT] +
1199 defp->pc.paramtypes[OUT];
1201 f_print(fout, "{\n");
1203 f_print(fout, "\tstruct rx_call *z_call = rx_NewCall(z_conn);\n");
1204 if ((!split_flag) || (split_flag == 1)) {
1205 if (opcodesnotallowed[PackageIndex]) {
1206 f_print(fout, "\tstatic int z_op = %d;\n", defp->pc.proc_opcodenum);
1208 f_print(fout, "\tstatic int z_op = %s;\n", defp->pc.proc_opcodename);
1211 f_print(fout, "\tint z_result;\n");
1212 if (!(split_flag > 1) || (noofallparams != 0)) {
1213 f_print(fout, "\tXDR z_xdrs;\n");
1216 * Print out client side stat gathering call
1218 if (xflag && split_flag != 1) {
1219 f_print(fout, "\tstruct clock __QUEUE, __EXEC;\n");
1222 if ((!split_flag) || (split_flag == 1)) {
1223 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_ENCODE);\n");
1224 f_print(fout, "\n\t/* Marshal the arguments */\n");
1225 f_print(fout, "\tif ((!xdr_int(&z_xdrs, &z_op))");
1226 noofparams = defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT];
1227 for (plist = defp->pc.plists, dl=defp->def.st.decls; plist; plist = plist->next, dl = dl->next) {
1228 if (plist->component_kind == DEF_PARAM && (plist->pl.param_kind == DEF_INPARAM || plist->pl.param_kind == DEF_INOUTPARAM)) {
1229 f_print(fout, "\n\t || (!%s)", plist->code);
1230 if (++i == noofparams) {
1231 f_print(fout, ") {\n\t\tz_result = RXGEN_CC_MARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1237 f_print(fout, ") {\n\t\tz_result = RXGEN_CC_MARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1245 cs_ProcSendPacket_setup(defp, split_flag)
1249 int noofoutparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1251 if (noofoutparams) {
1252 f_print(fout, "\t/* Un-marshal the reply arguments */\n");
1254 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
1256 f_print(fout, "\tz_xdrs.x_op = XDR_DECODE;\n");
1263 cs_ProcUnmarshallOutParams_setup(defp)
1270 noofparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1272 for (plist = defp->pc.plists, dl=defp->def.st.decls,i = 0; plist; plist = plist->next, dl=dl->next) {
1273 if (plist->component_kind == DEF_PARAM && (plist->pl.param_kind == DEF_OUTPARAM || plist->pl.param_kind == DEF_INOUTPARAM)) {
1275 f_print(fout, "\tif ((!%s)", plist->code);
1277 f_print(fout, "\n\t || (!%s)", plist->code);
1279 if (++i == noofparams) {
1280 f_print(fout, ") {\n\t\tz_result = RXGEN_CC_UNMARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1289 cs_ProcTail_setup(defp, split_flag)
1293 f_print(fout, "\tz_result = RXGEN_SUCCESS;\n");
1294 if (defp->can_fail) {
1295 f_print(fout, "fail:\n");
1298 f_print(fout, "\tz_result = rx_EndCall(z_call, z_result);\n");
1300 if (xflag && split_flag != 1) {
1301 f_print(fout, "\tif (rx_enable_stats) {\n");
1302 f_print(fout, "\t clock_GetTime(&__EXEC);\n");
1303 f_print(fout, "\t clock_Sub(&__EXEC, &z_call->startTime);\n");
1304 f_print(fout, "\t __QUEUE = z_call->startTime;\n");
1305 f_print(fout, "\t clock_Sub(&__QUEUE, &z_call->queueTime);\n");
1306 if (PackageStatIndex[PackageIndex]) {
1309 "\t rx_IncrementTimeAndCount(z_conn->peer, %s,\n",
1310 PackageStatIndex[PackageIndex]);
1313 "\t rx_IncrementTimeAndCount(z_call->conn->peer, %s,\n",
1314 PackageStatIndex[PackageIndex]);
1319 "\t rx_IncrementTimeAndCount(z_conn->peer,\n"
1320 "\t\t(((afs_uint32)(ntohs(z_conn->serviceId) << 16)) \n"
1321 "\t\t| ((afs_uint32)ntohs(z_conn->peer->port))),\n");
1324 "\t rx_IncrementTimeAndCount(z_call->conn->peer,\n"
1325 "\t\t(((afs_uint32)(ntohs(z_call->conn->serviceId) << 16)) |\n"
1326 "\t\t((afs_uint32)ntohs(z_call->conn->peer->port))),\n");
1330 f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, &__QUEUE, &__EXEC,\n",
1332 PackagePrefix[PackageIndex]);
1333 f_print(fout, "\t\t&z_call->bytesSent, &z_call->bytesRcvd, 1);\n");
1335 f_print(fout, "\t}\n\n");
1337 f_print(fout, "\treturn z_result;\n}\n\n");
1342 ss_Proc_CodeGeneration(defp)
1348 ss_ProcName_setup(defp);
1350 ss_ProcParams_setup(defp, &somefrees);
1351 ss_ProcProto_setup(defp, &somefrees);
1352 ss_ProcSpecial_setup(defp, &somefrees);
1353 ss_ProcUnmarshallInParams_setup(defp);
1354 ss_ProcCallRealProc_setup(defp);
1355 ss_ProcMarshallOutParams_setup(defp);
1356 ss_ProcTail_setup(defp, somefrees);
1362 ss_ProcName_setup(defp)
1367 if ((strlen(prefix) + strlen(PackagePrefix[PackageIndex]) + strlen(defp->pc.proc_name)) >= MAX_FUNCTION_NAME_LEN) {
1368 error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
1372 f_print(fout, "afs_int32 _%s%s%s(z_call, z_xdrs)\n", prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
1373 f_print(fout, "\tstruct rx_call *z_call;\n\tXDR *z_xdrs;\n{\n");
1374 f_print(fout, "\t" "afs_int32 z_result;\n");
1376 f_print(fout, "\tstruct clock __QUEUE, __EXEC;\n");
1379 for (plist = defp->pc.plists; plist; plist = plist->next)
1380 if (plist->component_kind == DEF_PARAM) {
1381 plist->pl.param_flag &= ~(PROCESSED_PARAM);
1382 plist->pl.string_name = (char *)0;
1389 ss_ProcParams_setup(defp, somefrees)
1393 proc1_list *plist, *plist1;
1396 int preserve_flag = 0;
1398 for (plist = defp->pc.plists; plist; plist = plist->next) {
1399 if ((plist->component_kind == DEF_PARAM) && !(plist->pl.param_flag & PROCESSED_PARAM)) {
1400 if (plist->pl.param_flag & INDIRECT_PARAM) {
1401 char pres, *pntr = index(plist->pl.param_type, '*');
1402 if (pntr){ --pntr; pres = *pntr; *pntr = (char)0; }
1403 f_print(fout, "\t%s %s", plist->pl.param_type, plist->pl.param_name);
1405 } else if (index(plist->pl.param_type, '*') == 0) {
1406 f_print(fout, "\t%s %s", plist->pl.param_type, plist->pl.param_name);
1408 plist->pl.param_flag |= FREETHIS_PARAM;
1410 f_print(fout, "\t%s %s=(%s)0", plist->pl.param_type, plist->pl.param_name, plist->pl.param_type);
1412 plist->pl.param_flag |= PROCESSED_PARAM;
1413 for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
1414 if ((plist1->component_kind == DEF_PARAM) && streq(plist->pl.param_type, plist1->pl.param_type) && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
1415 if (plist1->pl.param_flag & INDIRECT_PARAM) {
1416 f_print(fout, ", %s", plist1->pl.param_name);
1417 } else if (index(plist1->pl.param_type, '*') == 0) {
1418 f_print(fout, ", %s", plist1->pl.param_name);
1420 plist1->pl.param_flag |= FREETHIS_PARAM;
1422 f_print(fout, ", *%s=(%s)0", plist1->pl.param_name, 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 && (plist->pl.param_kind == DEF_OUTPARAM || plist->pl.param_kind == DEF_INOUTPARAM) && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1434 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1435 switch (defp1->pc.rel) {
1444 fprintf(fout, "\n");
1449 ss_ProcProto_setup(defp, somefrees)
1453 proc1_list *plist, *plist1;
1456 int preserve_flag = 0;
1458 f_print(fout, "#ifndef KERNEL\n");
1459 f_print(fout, "\tafs_int32 %s%s%s%s();\n", prefix, ServerPrefix,
1460 PackagePrefix[PackageIndex], defp->pc.proc_name);
1461 f_print(fout, "#endif\n");
1466 ss_ProcSpecial_setup(defp, somefrees)
1474 for (listp = special_defined; listp != NULL; listp = listp->next) {
1475 defp1 = (definition *)listp->val;
1476 for (plist=defp->pc.plists; plist; plist=plist->next) {
1477 if (plist->component_kind == DEF_PARAM && (plist->pl.param_kind == DEF_INPARAM || plist->pl.param_kind == DEF_INOUTPARAM)) {
1478 spec_list *spec = defp1->def.sd.specs;
1480 strcpy(string, structname(spec->sdef.string_value));
1481 if (streq(string, structname(plist->pl.param_type))) {
1482 plist->pl.string_name = spec->sdef.string_name;
1483 plist->pl.param_flag |= FREETHIS_PARAM;
1485 fprintf(fout, "\n\t%s.%s = 0;", plist->pl.param_name, spec->sdef.string_name);
1491 fprintf(fout, "\n");
1492 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1493 defp1 = (definition *)listp->val;
1494 for (plist=defp->pc.plists; plist; plist=plist->next) {
1495 if (plist->component_kind == DEF_PARAM ) {
1496 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1497 plist->pl.param_flag |= FREETHIS_PARAM;
1499 switch (defp1->pc.rel) {
1501 f_print(fout, "\n\t%s.%s_val = 0;", plist->pl.param_name, defp1->def_name);
1502 f_print(fout, "\n\t%s.%s_len = 0;", plist->pl.param_name, defp1->def_name);
1503 plist->pl.string_name = alloc(40);
1504 s_print(plist->pl.string_name, "%s_val", defp1->def_name);
1507 f_print(fout, "\n\t%s = 0;", plist->pl.param_name);
1508 plist->pl.string_name = NULL;
1515 f_print(fout, "\n");
1520 ss_ProcUnmarshallInParams_setup(defp)
1523 int noofparams, noofoutparams, i;
1526 noofparams = defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT];
1527 noofoutparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1528 for (plist = defp->pc.plists, i=0; plist; plist = plist->next) {
1529 if (plist->component_kind == DEF_PARAM && (plist->pl.param_kind == DEF_INPARAM || plist->pl.param_kind == DEF_INOUTPARAM)) {
1531 f_print(fout, "\n\tif ((!%s)", (plist->scode ? plist->scode : plist->code));
1533 f_print(fout, "\n\t || (!%s)", (plist->scode ? plist->scode : plist->code));
1535 if (++i == noofparams) {
1536 if (!noofoutparams) {
1537 f_print(fout, ") {\n");
1539 f_print(fout, ") {\n");
1541 f_print(fout, "\t\tz_result = RXGEN_SS_UNMARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1550 ss_ProcCallRealProc_setup(defp)
1556 f_print(fout, "\tz_result = %s%s%s%s(z_call", prefix, ServerPrefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
1557 for (plist = defp->pc.plists; plist; plist = plist->next) {
1558 if (plist->component_kind == DEF_PARAM) {
1559 if (plist->pl.param_flag & INDIRECT_PARAM) {
1560 f_print(fout, ", &%s", plist->pl.param_name);
1562 if (plist->pl.param_flag & OUT_STRING) {
1563 f_print(fout, ", &%s", plist->pl.param_name);
1565 f_print(fout, ", %s", plist->pl.param_name);
1570 f_print(fout, ");\n");
1572 f_print(fout, "\tif (z_result)\n\t\treturn z_result;\n");
1578 ss_ProcMarshallOutParams_setup(defp)
1584 noofparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1586 f_print(fout, "\tz_xdrs->x_op = XDR_ENCODE;\n");
1588 for (plist = defp->pc.plists, i=0; plist; plist = plist->next) {
1589 if (plist->component_kind == DEF_PARAM && (plist->pl.param_kind == DEF_OUTPARAM || plist->pl.param_kind == DEF_INOUTPARAM)) {
1591 f_print(fout, "\tif ((!%s)", (plist->scode ? plist->scode : plist->code));
1593 f_print(fout, "\n\t || (!%s)", (plist->scode ? plist->scode : plist->code));
1595 if (++i == noofparams) {
1596 f_print(fout, ")\n\t\tz_result = RXGEN_SS_MARSHAL;\n");
1605 ss_ProcTail_setup(defp, somefrees)
1614 if (defp->can_fail) {
1615 f_print(fout, "fail:\n");
1617 for (plist = defp->pc.plists; plist; plist = plist->next) {
1618 if (plist->component_kind == DEF_PARAM && (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 && (plist->pl.param_flag & FREETHIS_PARAM)) {
1625 char *dot = "", *extens = "";
1626 if (plist->pl.string_name) {
1628 extens = plist->pl.string_name;
1630 f_print(fout, "\tif (!%s) goto fail1;\n", plist->scode);
1633 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1634 defp1 = (definition *)listp->val;
1635 for (plist=defp->pc.plists; plist; plist=plist->next) {
1636 if (plist->component_kind == DEF_PARAM && (plist->pl.param_kind == DEF_OUTPARAM || plist->pl.param_kind == DEF_INOUTPARAM) && !(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", plist->scode);
1653 for (listp = uniondef_defined; listp != NULL; listp = listp->next) {
1654 defp1 = (definition *)listp->val;
1655 for (plist=defp->pc.plists; plist; plist=plist->next) {
1656 if (plist->component_kind == DEF_PARAM && (plist->pl.param_kind == DEF_OUTPARAM || plist->pl.param_kind == DEF_INOUTPARAM) && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1657 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1658 if (plist->pl.param_flag & INDIRECT_PARAM) {
1659 if (!somefrees && !firsttime) {
1661 f_print(fout, "\tz_xdrs->x_op = XDR_FREE;\n");
1664 f_print(fout, "\tif (!%s) goto fail1;\n", plist->scode);
1672 f_print(fout, "\tif (rx_enable_stats) {\n");
1673 f_print(fout, "\t clock_GetTime(&__EXEC);\n");
1674 f_print(fout, "\t clock_Sub(&__EXEC, &z_call->startTime);\n");
1675 f_print(fout, "\t __QUEUE = z_call->startTime;\n");
1676 f_print(fout, "\t clock_Sub(&__QUEUE, &z_call->queueTime);\n");
1677 f_print(fout, "\t rx_IncrementTimeAndCount(z_call->conn->peer,");
1678 if (PackageStatIndex[PackageIndex]) {
1679 f_print(fout, " %s,\n", PackageStatIndex[PackageIndex]);
1682 "\n\t\t(((afs_uint32)(ntohs(z_call->conn->serviceId) << 16)) |\n"
1683 "\t\t((afs_uint32)ntohs(z_call->conn->service->servicePort))),\n");
1685 f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, &__QUEUE, &__EXEC,\n",
1687 PackagePrefix[PackageIndex]);
1688 f_print(fout, "\t\t&z_call->bytesSent, &z_call->bytesRcvd, 0);\n");
1689 f_print(fout, "\t}\n\n");
1692 f_print(fout, "\treturn z_result;\n");
1694 f_print(fout, "fail1:\n");
1697 f_print(fout, "\tif (rx_enable_stats) {\n");
1698 f_print(fout, "\t clock_GetTime(&__EXEC);\n");
1699 f_print(fout, "\t clock_Sub(&__EXEC, &z_call->startTime);\n");
1700 f_print(fout, "\t __QUEUE = z_call->startTime;\n");
1701 f_print(fout, "\t clock_Sub(&__QUEUE, &z_call->queueTime);\n");
1702 f_print(fout, "\t rx_IncrementTimeAndCount(z_call->conn->peer,");
1703 if (PackageStatIndex[PackageIndex]) {
1704 f_print(fout, " %s,\n", PackageStatIndex[PackageIndex]);
1707 "\n\t\t(((afs_uint32)(ntohs(z_call->conn->serviceId) << 16)) |\n"
1708 "\t\t((afs_uint32)ntohs(z_call->conn->service->servicePort))),\n");
1710 f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, &__QUEUE, &__EXEC,\n",
1712 PackagePrefix[PackageIndex]);
1713 f_print(fout, "\t\t&z_call->bytesSent, &z_call->bytesRcvd, 0);\n");
1714 f_print(fout, "\t}\n\n");
1717 f_print(fout, "\treturn RXGEN_SS_XDRFREE;\n}\n\n");
1719 f_print(fout, "}\n\n");
1725 opcode_holes_exist()
1729 for (i=lowest_opcode[PackageIndex]; i<highest_opcode[PackageIndex]; i++) {
1730 if (!opcodenum_is_defined(i))
1738 er_Proc_CodeGeneration()
1742 temp = PackageIndex;
1743 if (!combinepackages) PackageIndex = 0;
1744 for (; PackageIndex <= temp; PackageIndex++) {
1745 if (proc_defined[PackageIndex] == NULL) continue;
1746 if (combinepackages || opcode_holes_exist()) {
1747 er_HeadofOldStyleProc_setup();
1748 er_BodyofOldStyleProc_setup();
1749 er_TailofOldStyleProc_setup();
1751 er_ProcDeclExterns_setup();
1752 er_ProcProcsArray_setup();
1753 er_ProcMainBody_setup();
1756 PackageIndex = temp;
1761 er_ProcDeclExterns_setup()
1766 f_print(fout, "\n");
1767 for (listp = proc_defined[PackageIndex]; listp != NULL; listp = listp->next) {
1768 defp = (definition *)listp->val;
1769 if (defp->pc.proc_serverstub) {
1770 f_print(fout, "afs_int32 %s();\n", defp->pc.proc_serverstub);
1772 f_print(fout, "afs_int32 _%s%s%s();\n", prefix, defp->pc.proc_prefix, defp->pc.proc_name);
1779 er_ProcProcsArray_setup()
1784 if (listp = proc_defined[PackageIndex]) {
1785 defp = (definition *)listp->val;
1786 if (defp->pc.proc_serverstub){
1787 f_print(fout, "\nstatic afs_int32 (*StubProcsArray%d[])() = {%s", PackageIndex, defp->pc.proc_serverstub);
1789 f_print(fout, "\nstatic afs_int32 (*StubProcsArray%d[])() = {_%s%s%s", PackageIndex, prefix, defp->pc.proc_prefix, (defp = (definition *)listp->val)->pc.proc_name);
1791 listp = listp->next;
1793 for (; listp != NULL; listp = listp->next) {
1794 defp = (definition *)listp->val;
1795 if (defp->pc.proc_serverstub) {
1796 f_print(fout, ",%s", defp->pc.proc_serverstub);
1798 f_print(fout, ", _%s%s%s", prefix, defp->pc.proc_prefix, defp->pc.proc_name);
1801 f_print(fout, "};\n\n");
1806 er_ProcMainBody_setup()
1808 f_print(fout, "int %s%sExecuteRequest(z_call)\n", prefix, PackagePrefix[PackageIndex]);
1809 f_print(fout, "\tregister struct rx_call *z_call;\n");
1810 f_print(fout, "{\n\tint op;\n");
1811 f_print(fout, "\tXDR z_xdrs;\n");
1812 f_print(fout, "\t" "afs_int32 z_result;\n\n");
1813 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
1814 f_print(fout, "\tif (!xdr_int(&z_xdrs, &op))\n\t\tz_result = RXGEN_DECODE;\n");
1815 f_print(fout, "\telse if (op < %sLOWEST_OPCODE || op > %sHIGHEST_OPCODE)\n\t\tz_result = RXGEN_OPCODE;\n", PackagePrefix[PackageIndex], PackagePrefix[PackageIndex]);
1816 f_print(fout, "\telse\n\t\tz_result = (*StubProcsArray%d[op - %sLOWEST_OPCODE])(z_call, &z_xdrs);\n", PackageIndex, PackagePrefix[PackageIndex]);
1817 f_print(fout, "\treturn hton_syserr_conv(z_result);\n}\n");
1822 er_HeadofOldStyleProc_setup()
1824 f_print(fout, "\nint %s%sExecuteRequest (z_call)\n", prefix, (combinepackages ? MasterPrefix : PackagePrefix[PackageIndex]));
1825 f_print(fout, "\tregister struct rx_call *z_call;\n");
1826 f_print(fout, "{\n");
1827 f_print(fout, "\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");
1831 f_print(fout, "\tz_result = RXGEN_DECODE;\n");
1832 f_print(fout, "\tif (!xdr_int(&z_xdrs, &op)) goto fail;\n");
1833 f_print(fout, "\tswitch (op) {\n");
1837 er_BodyofOldStyleProc_setup()
1841 if (combinepackages) {
1842 int temp = PackageIndex;
1843 for (PackageIndex = 0; PackageIndex <= temp; PackageIndex++) {
1844 for (listp = proc_defined[PackageIndex]; listp != NULL; listp = listp->next)
1845 proc_er_case((definition *)listp->val);
1847 PackageIndex = temp;
1849 for (listp = proc_defined[PackageIndex]; listp != NULL; listp = listp->next)
1850 proc_er_case((definition *)listp->val);
1859 if (opcodesnotallowed[PackageIndex]) {
1860 f_print(fout, "\t\tcase %d: {\n", defp->pc.proc_opcodenum);
1862 f_print(fout, "\t\tcase %s: {\n", defp->pc.proc_opcodename);
1864 if (defp->pc.proc_serverstub) {
1865 f_print(fout, "\t\t\t" "afs_int32 %s();\n", defp->pc.proc_serverstub);
1866 f_print(fout, "\t\t\tz_result = %s(z_call, &z_xdrs);\n", defp->pc.proc_serverstub);
1868 f_print(fout, "\t\t\t" "afs_int32 _%s%s%s();\n", prefix, defp->pc.proc_prefix, defp->pc.proc_name);
1869 f_print(fout, "\t\t\tz_result = _%s%s%s(z_call, &z_xdrs);\n", prefix, defp->pc.proc_prefix, defp->pc.proc_name);
1871 f_print(fout, "\t\t\tbreak;\n\t\t}\n");
1876 er_TailofOldStyleProc_setup()
1878 f_print(fout, "\t\tdefault:\n");
1879 f_print(fout, "\t\t\tz_result = RXGEN_OPCODE;\n");
1880 f_print(fout, "\t\t\tbreak;\n\t}\n");
1881 f_print(fout, "fail:\n");
1882 f_print(fout, "\treturn z_result;\n}\n");
1886 int h_opcode_stats()
1888 if (combinepackages) {
1889 f_print(fout, "\n/* Opcode-related useful stats for Master package: %s */\n", MasterPrefix);
1890 f_print(fout, "#define %sLOWEST_OPCODE %d\n", MasterPrefix, master_lowest_opcode);
1891 f_print(fout, "#define %sHIGHEST_OPCODE %d\n", MasterPrefix, master_highest_opcode);
1892 f_print(fout, "#define %sNUMBER_OPCODES %d\n\n", MasterPrefix, master_no_of_opcodes);
1894 f_print(fout, "#define %sNO_OF_STAT_FUNCS\t%d\n\n", MasterPrefix, no_of_stat_funcs_header[0]);
1895 f_print(fout, "AFS_RXGEN_EXPORT\n");
1896 f_print(fout, "extern const char *%sfunction_names[];\n\n", MasterPrefix);
1900 for (i=0; i <= PackageIndex; i++) {
1901 f_print(fout, "\n/* Opcode-related useful stats for package: %s */\n", PackagePrefix[i]);
1902 f_print(fout, "#define %sLOWEST_OPCODE %d\n", PackagePrefix[i], lowest_opcode[i]);
1903 f_print(fout, "#define %sHIGHEST_OPCODE %d\n", PackagePrefix[i], highest_opcode[i]);
1904 f_print(fout, "#define %sNUMBER_OPCODES %d\n\n", PackagePrefix[i], no_of_opcodes[i]);
1906 f_print(fout, "#define %sNO_OF_STAT_FUNCS\t%d\n\n", PackagePrefix[i], no_of_stat_funcs_header[i]);
1907 f_print(fout, "AFS_RXGEN_EXPORT\n");
1908 f_print(fout, "extern const char *%sfunction_names[];\n\n", PackagePrefix[i]);
1915 int generate_multi_macros(defp)
1918 char *startname = SplitStart, *endname = SplitEnd;
1926 f_print(fout, "\n#include <rx/rx_multi.h>");
1928 f_print(fout, "\n#define multi_%s%s(", PackagePrefix[PackageIndex],defp->pc.proc_name);
1929 for (plist = defp->pc.plists; plist; plist = plist->next) {
1930 if (plist->component_kind == DEF_PARAM) {
1933 f_print(fout, "%s", plist->pl.param_name);
1935 f_print(fout, ", %s", plist->pl.param_name);
1939 f_print(fout, ") \\\n");
1940 if (!startname) startname = "Start";
1941 if (!endname) endname = "End";
1942 f_print(fout, "\tmulti_Body(%s%s%s(multi_call", startname, PackagePrefix[PackageIndex], defp->pc.proc_name);
1943 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 0);
1944 for (plist = defp->pc.plists; plist; plist = plist->next) {
1945 if (plist->component_kind == DEF_PARAM)
1946 f_print(fout, ", %s", plist->pl.param_name);
1948 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 1);
1949 f_print(fout, "), %s%s%s(multi_call", endname, PackagePrefix[PackageIndex], defp->pc.proc_name);
1950 do_split(defp, IN, &numofparams, DEF_INPARAM, 0);
1951 for (plist = defp->pc.plists; plist; plist = plist->next) {
1952 if (plist->component_kind == DEF_PARAM) {
1953 f_print(fout, ", %s", plist->pl.param_name);
1956 do_split(defp, IN, &numofparams, DEF_INPARAM, 1);
1957 f_print(fout, "))\n\n");
1965 if (tokp->kind == TOK_PACKAGE || tokp->kind == TOK_PREFIX ||
1966 tokp->kind == TOK_SPECIAL || tokp->kind == TOK_STARTINGOPCODE ||
1967 tokp->kind == TOK_SPLITPREFIX || tokp->kind == TOK_PROC ||
1968 tokp->kind == TOK_STATINDEX)
1974 IsRxgenDefinition(def)
1977 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)