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>
46 #include "rpc_parse.h"
49 list *proc_defined[MAX_PACKAGES], *special_defined, *typedef_defined,
51 char *SplitStart = NULL;
52 char *SplitEnd = NULL;
53 char *MasterPrefix = NULL;
54 char *ServerPrefix = "";
55 char *PackagePrefix[MAX_PACKAGES];
56 char *PackageStatIndex[MAX_PACKAGES];
57 int no_of_stat_funcs = 0; /*
58 * current function number in client interface
61 int no_of_stat_funcs_header[MAX_PACKAGES]; /*
62 * Total number of functions in client
65 int no_of_opcodes[MAX_PACKAGES], master_no_of_opcodes = 0;
66 int lowest_opcode[MAX_PACKAGES], master_lowest_opcode = 99999;
67 int highest_opcode[MAX_PACKAGES], master_highest_opcode = 0;
68 int master_opcodenumber = 99999;
69 int opcodesnotallowed[MAX_PACKAGES];
70 int combinepackages = 0;
71 int PackageIndex = -1;
72 int PerProcCounter = 0;
76 * Character arrays to keep list of function names as we process the file
79 char function_list[MAX_PACKAGES]
80 [MAX_FUNCTIONS_PER_PACKAGE]
81 [MAX_FUNCTION_NAME_LEN];
82 int function_list_index;
84 /* static prototypes */
85 static void isdefined(definition * defp);
86 static void def_struct(definition * defp);
87 static void def_program(definition * defp);
88 static void def_enum(definition * defp);
89 static void def_const(definition * defp);
90 static void def_union(definition * defp);
91 static void def_typedef(definition * defp);
92 static void get_declaration(declaration * dec, defkind dkind);
93 static void get_type(char **prefixp, char **typep, defkind dkind);
94 static void unsigned_dec(char **typep);
95 static void def_package(definition * defp);
96 static void def_prefix(definition * defp);
97 static void def_statindex(definition * defp);
98 static void def_startingopcode(definition * defp);
99 static void def_split(definition * defp);
100 static void customize_struct(definition * defp);
101 static char *structname(char *name);
102 static void def_special(declaration * dec, definition * defp);
103 static void check_proc(definition * defp, token * tokp, int noname);
104 static int InvalidConstant(char *name);
105 static int opcodenum_is_defined(int opcode_num);
106 static void analyze_ProcParams(definition * defp, token * tokp);
107 static void generate_code(definition * defp, int proc_split_flag,
109 static void handle_split_proc(definition * defp, int multi_flag);
110 static void do_split(definition * defp, int direction, int *numofparams,
111 defkind param_kind, int restore_flag);
112 static void hdle_param_tok(definition * defp, declaration * dec, token * tokp,
114 static void get1_param_type(definition * defp, declaration * dec,
116 static void get_param_type(definition * defp, declaration * dec,
117 char **param_type, char **typename);
119 static void hndle_param_tail(definition * defp, declaration * dec,
120 token * tokp, char *typename);
122 static void cs_Proc_CodeGeneration(definition * defp, int split_flag,
124 static void cs_ProcName_setup(definition * defp, char *procheader,
126 static void cs_ProcParams_setup(definition * defp, int split_flag);
127 static void cs_ProcMarshallInParams_setup(definition * defp, int split_flag);
128 static void cs_ProcSendPacket_setup(definition * defp, int split_flag);
129 static void cs_ProcUnmarshallOutParams_setup(definition * defp);
130 static void cs_ProcTail_setup(definition * defp, int split_flag);
131 static void ucs_ProcName_setup(definition * defp, char *procheader,
133 static void ucs_ProcParams_setup(definition * defp, int split_flag);
134 static void ucs_ProcTail_setup(definition * defp, int split_flag);
135 static void ss_Proc_CodeGeneration(definition * defp);
136 static void ss_ProcName_setup(definition * defp);
137 static void ss_ProcParams_setup(definition * defp, int *somefrees);
138 static void ss_ProcSpecial_setup(definition * defp, int *somefrees);
139 static void ss_ProcUnmarshallInParams_setup(definition * defp);
140 static void ss_ProcCallRealProc_setup(definition * defp);
141 static void ss_ProcMarshallOutParams_setup(definition * defp);
142 static void ss_ProcTail_setup(definition * defp, int somefrees);
143 static int opcode_holes_exist(void);
144 static void er_ProcDeclExterns_setup(void);
145 static void er_ProcProcsArray_setup(void);
146 static void er_ProcMainBody_setup(void);
147 static void er_HeadofOldStyleProc_setup(void);
148 static void er_BodyofOldStyleProc_setup(void);
149 static void proc_er_case(definition * defp);
150 static void er_TailofOldStyleProc_setup(void);
155 * return the next definition you see
163 defp = ALLOC(definition);
164 memset((char *)defp, 0, sizeof(definition));
200 def_special(&dec, defp);
203 case TOK_STARTINGOPCODE:
204 def_startingopcode(defp);
209 customize_struct(defp);
211 case TOK_SPLITPREFIX:
216 if (tok.kind == TOK_LPAREN) {
218 check_proc(defp, &tok, 1);
220 check_proc(defp, &tok, 0);
223 check_proc(defp, &tok, 0);
227 check_proc(defp, &tok, 1);
230 error("definition keyword expected");
232 if (!IsRxgenToken(&tok)) {
233 scan(TOK_SEMICOLON, &tok);
241 isdefined(definition * defp)
243 STOREVAL(&defined, defp);
248 def_struct(definition * defp)
255 defp->def_kind = DEF_STRUCT;
257 scan(TOK_IDENT, &tok);
258 defp->def_name = tok.str;
259 scan(TOK_LBRACE, &tok);
260 tailp = &defp->def.st.decls;
262 get_declaration(&dec, DEF_STRUCT);
263 decls = ALLOC(decl_list);
266 tailp = &decls->next;
267 scan(TOK_SEMICOLON, &tok);
269 } while (tok.kind != TOK_RBRACE);
275 def_program(definition * defp)
279 version_list **vtailp;
283 defp->def_kind = DEF_PROGRAM;
284 scan(TOK_IDENT, &tok);
285 defp->def_name = tok.str;
286 scan(TOK_LBRACE, &tok);
287 vtailp = &defp->def.pr.versions;
288 scan(TOK_VERSION, &tok);
290 scan(TOK_IDENT, &tok);
291 vlist = ALLOC(version_list);
292 vlist->vers_name = tok.str;
293 scan(TOK_LBRACE, &tok);
294 ptailp = &vlist->procs;
296 plist = ALLOC(proc_list);
297 get_type(&plist->res_prefix, &plist->res_type, DEF_PROGRAM);
298 if (streq(plist->res_type, "opaque")) {
299 error("illegal result type");
301 scan(TOK_IDENT, &tok);
302 plist->proc_name = tok.str;
303 scan(TOK_LPAREN, &tok);
304 get_type(&plist->arg_prefix, &plist->arg_type, DEF_PROGRAM);
305 if (streq(plist->arg_type, "opaque")) {
306 error("illegal argument type");
308 scan(TOK_RPAREN, &tok);
309 scan(TOK_EQUAL, &tok);
311 scan(TOK_SEMICOLON, &tok);
312 plist->proc_num = tok.str;
314 ptailp = &plist->next;
316 } while (tok.kind != TOK_RBRACE);
318 vtailp = &vlist->next;
319 scan(TOK_RBRACE, &tok);
320 scan(TOK_EQUAL, &tok);
322 vlist->vers_num = tok.str;
323 scan(TOK_SEMICOLON, &tok);
324 scan2(TOK_VERSION, TOK_RBRACE, &tok);
325 } while (tok.kind == TOK_VERSION);
326 scan(TOK_EQUAL, &tok);
328 defp->def.pr.prog_num = tok.str;
333 def_enum(definition * defp)
337 enumval_list **tailp;
339 defp->def_kind = DEF_ENUM;
340 scan(TOK_IDENT, &tok);
341 defp->def_name = tok.str;
342 scan(TOK_LBRACE, &tok);
343 tailp = &defp->def.en.vals;
345 scan(TOK_IDENT, &tok);
346 elist = ALLOC(enumval_list);
347 elist->name = tok.str;
348 elist->assignment = NULL;
349 scan3(TOK_COMMA, TOK_RBRACE, TOK_EQUAL, &tok);
350 if (tok.kind == TOK_EQUAL) {
352 elist->assignment = tok.str;
353 scan2(TOK_COMMA, TOK_RBRACE, &tok);
356 tailp = &elist->next;
357 } while (tok.kind != TOK_RBRACE);
362 def_const(definition * defp)
366 defp->def_kind = DEF_CONST;
367 scan(TOK_IDENT, &tok);
368 defp->def_name = tok.str;
369 scan(TOK_EQUAL, &tok);
370 scan2(TOK_IDENT, TOK_STRCONST, &tok);
371 defp->def.co = tok.str;
375 def_union(definition * defp)
382 defp->def_kind = DEF_UNION;
383 scan(TOK_IDENT, &tok);
384 defp->def_name = tok.str;
385 scan(TOK_SWITCH, &tok);
386 scan(TOK_LPAREN, &tok);
387 get_declaration(&dec, DEF_UNION);
388 defp->def.un.enum_decl = dec;
389 tailp = &defp->def.un.cases;
390 scan(TOK_RPAREN, &tok);
391 scan(TOK_LBRACE, &tok);
392 scan(TOK_CASE, &tok);
393 while (tok.kind == TOK_CASE) {
394 scan(TOK_IDENT, &tok);
395 cases = ALLOC(case_list);
396 cases->case_name = tok.str;
397 scan(TOK_COLON, &tok);
398 get_declaration(&dec, DEF_UNION);
399 cases->case_decl = dec;
401 tailp = &cases->next;
402 scan(TOK_SEMICOLON, &tok);
403 scan3(TOK_CASE, TOK_DEFAULT, TOK_RBRACE, &tok);
406 if (tok.kind == TOK_DEFAULT) {
407 scan(TOK_COLON, &tok);
408 get_declaration(&dec, DEF_UNION);
409 defp->def.un.default_decl = ALLOC(declaration);
410 *defp->def.un.default_decl = dec;
411 scan(TOK_SEMICOLON, &tok);
412 scan(TOK_RBRACE, &tok);
414 defp->def.un.default_decl = NULL;
420 def_typedef(definition * defp)
424 defp->def_kind = DEF_TYPEDEF;
425 get_declaration(&dec, DEF_TYPEDEF);
426 defp->def_name = dec.name;
427 defp->def.ty.old_prefix = dec.prefix;
428 defp->def.ty.old_type = dec.type;
429 defp->def.ty.rel = dec.rel;
430 defp->def.ty.array_max = dec.array_max;
435 get_declaration(declaration * dec, defkind dkind)
439 get_type(&dec->prefix, &dec->type, dkind);
440 dec->rel = REL_ALIAS;
441 if (streq(dec->type, "void")) {
444 scan2(TOK_STAR, TOK_IDENT, &tok);
445 if (tok.kind == TOK_STAR) {
446 dec->rel = REL_POINTER;
447 scan(TOK_IDENT, &tok);
450 if (peekscan(TOK_LBRACKET, &tok)) {
451 if (dec->rel == REL_POINTER) {
452 error("no array-of-pointer declarations -- use typedef");
454 dec->rel = REL_VECTOR;
456 dec->array_max = tok.str;
457 scan(TOK_RBRACKET, &tok);
458 } else if (peekscan(TOK_LANGLE, &tok)) {
459 if (dec->rel == REL_POINTER) {
460 error("no array-of-pointer declarations -- use typedef");
462 dec->rel = REL_ARRAY;
463 if (peekscan(TOK_RANGLE, &tok)) {
464 dec->array_max = "~0"; /* unspecified size, use max */
467 dec->array_max = tok.str;
468 scan(TOK_RANGLE, &tok);
471 if (streq(dec->type, "opaque")) {
472 if (dec->rel != REL_ARRAY && dec->rel != REL_VECTOR) {
473 error("array declaration expected");
475 } else if (streq(dec->type, "string")) {
476 if (dec->rel != REL_ARRAY) {
477 error(" variable-length array declaration expected");
484 get_type(char **prefixp, char **typep, defkind dkind)
498 scan(TOK_IDENT, &tok);
506 (void)peekscan(TOK_INT, &tok);
509 *typep = "afs_int32";
510 (void)peekscan(TOK_INT, &tok);
513 if (dkind != DEF_UNION && dkind != DEF_PROGRAM) {
514 error("voids allowed only inside union and program definitions");
529 error("expected type specifier");
535 unsigned_dec(char **typep)
548 (void)peekscan(TOK_INT, &tok);
552 *typep = "afs_uint32";
553 (void)peekscan(TOK_INT, &tok);
567 def_package(definition * defp)
571 defp->def_kind = DEF_PACKAGE;
572 scan(TOK_IDENT, &tok);
573 defp->def_name = tok.str;
574 no_of_stat_funcs = 0;
575 if (PackageIndex++ >= MAX_PACKAGES)
576 error("Exceeded upper limit of package statements\n");
577 function_list_index = 0;
578 PackagePrefix[PackageIndex] = tok.str;
579 if (MasterPrefix == NULL)
580 MasterPrefix = tok.str;
581 no_of_opcodes[PackageIndex] = highest_opcode[PackageIndex] =
582 opcodesnotallowed[PackageIndex] = 0;
583 lowest_opcode[PackageIndex] = 99999;
584 proc_defined[PackageIndex] = NULL;
585 PackageStatIndex[PackageIndex] = NULL;
589 def_prefix(definition * defp)
593 defp->def_kind = DEF_PREFIX;
594 scan(TOK_IDENT, &tok);
595 defp->def_name = tok.str;
596 ServerPrefix = tok.str;
600 def_statindex(definition * defp)
605 defp->def_kind = DEF_CONST;
607 if (PackageIndex < 0)
608 error("'statindex' command must follow 'package' command!\n");
609 if (PackageStatIndex[PackageIndex])
610 error("Cannot have more then one 'statindex' per package!\n");
611 if (InvalidConstant(tok.str))
612 error("Index in 'statindex' command must be a constant!");
614 alloc(strlen(PackagePrefix[PackageIndex]) + strlen("STATINDEX") + 1);
615 strcpy(name, PackagePrefix[PackageIndex]);
616 strcat(name, "STATINDEX");
617 defp->def_name = name;
618 defp->def.co = tok.str;
619 PackageStatIndex[PackageIndex] = name;
623 def_startingopcode(definition * defp)
627 defp->def_kind = DEF_STARTINGOPCODE;
628 scan(TOK_IDENT, &tok);
629 defp->def_name = tok.str;
630 if (InvalidConstant(defp->def_name))
631 error("Opcode in 'startingopcode' command must be a constant!");
632 lowest_opcode[PackageIndex] = master_lowest_opcode = atoi(tok.str);
633 if (lowest_opcode[PackageIndex] < 0
634 || lowest_opcode[PackageIndex] > 99999)
636 ("startingopcode number is out of bounds (must be >= 0 < 100000)");
637 master_opcodenumber = lowest_opcode[PackageIndex];
638 opcodesnotallowed[PackageIndex] = 1;
642 def_split(definition * defp)
646 defp->def_kind = DEF_SPLITPREFIX;
651 scan(TOK_EQUAL, &tok);
652 scan(TOK_IDENT, &tok);
653 SplitStart = tok.str;
656 scan(TOK_EQUAL, &tok);
657 scan(TOK_IDENT, &tok);
663 error("syntax error in the 'splitprefix' line");
665 } while (tok.kind != TOK_SEMICOLON);
666 if (!SplitStart && !SplitEnd)
667 error("At least one param should be passed to 'splitprefix' cmd");
672 customize_struct(definition * defp)
676 definition *defp1 = ALLOC(definition);
677 spec_list *specs, **tailp;
679 defp->def_kind = DEF_CUSTOMIZED;
680 defp1->def_kind = DEF_SPECIAL;
681 tailp = &defp1->def.sd.specs;
682 for (listp = defp->def.st.decls; listp; listp = listp->next) {
684 if (streq(dec->type, "string") || (dec->rel == REL_POINTER)) {
685 specs = ALLOC(spec_list);
686 specs->sdef.string_name = dec->name;
687 specs->sdef.string_value = defp->def_name;
689 tailp = &specs->next;
693 STOREVAL(&special_defined, defp1);
697 structname(char *name)
699 static char namecontents[150];
702 strcpy(namecontents, name);
704 if (!strncmp(pnt, "struct", 6))
706 while (isspace(*pnt))
709 while (*pnt != ' ' && *pnt != '\0')
717 def_special(declaration * dec, definition * defp)
720 spec_list *specs, **tailp;
723 defp->def_kind = DEF_SPECIAL;
724 get_type(&dec->prefix, &dec->type, DEF_SPECIAL);
725 dec->rel = REL_POINTER;
726 scan(TOK_IDENT, &tok);
727 tailp = &defp->def.sd.specs;
729 specs = ALLOC(spec_list);
730 specs->sdef.string_name = tok.str;
731 get_param_type(defp, dec, &specs->sdef.string_value, &typename);
733 tailp = &specs->next;
734 scan2(TOK_COMMA, TOK_SEMICOLON, &tok);
735 if (tok.kind == TOK_SEMICOLON)
738 } while (tok.kind == TOK_IDENT);
740 STOREVAL(&special_defined, defp);
744 proc1_list *Proc_list, **Proc_listp;
747 check_proc(definition * defp, token * tokp, int noname)
753 if (PackageIndex < 0)
754 error("Procedure must be in a package!\n");
756 tokp->kind = TOK_PROC;
757 defp->def_kind = DEF_PROC;
759 defp->pc.proc_name = "";
761 defp->pc.proc_name = tokp->str;
763 defp->pc.proc_prefix = alloc(strlen(PackagePrefix[PackageIndex]) + 1);
764 strcpy(defp->pc.proc_prefix, PackagePrefix[PackageIndex]);
765 scan2(TOK_LPAREN, TOK_IDENT, &tok);
766 defp->pc.proc_serverstub = NULL;
767 if (tok.kind == TOK_IDENT) {
768 defp->pc.proc_serverstub = tok.str;
769 scan(TOK_LPAREN, &tok);
771 analyze_ProcParams(defp, &tok);
772 defp->pc.proc_opcodenum = -1;
773 scan4(TOK_SPLIT, TOK_MULTI, TOK_EQUAL, TOK_SEMICOLON, &tok);
774 if (tok.kind == TOK_MULTI) {
776 defp->pc.multi_flag = 1;
777 scan2(TOK_EQUAL, TOK_SEMICOLON, &tok);
779 defp->pc.multi_flag = 0;
781 if (tok.kind == TOK_SPLIT) {
783 defp->pc.split_flag = 1;
784 scan2(TOK_EQUAL, TOK_SEMICOLON, &tok);
786 defp->pc.split_flag = 0;
788 if (tok.kind == TOK_EQUAL) {
789 if (opcodesnotallowed[PackageIndex])
790 error("Opcode assignment isn't allowed here!");
792 if (InvalidConstant(tok.str))
793 error("Illegal Opcode assignment (Must be a constant opcode!)");
794 if (opcodenum_is_defined(atoi(tok.str)))
795 error("The opcode number is already used by a previous proc");
796 defp->pc.proc_opcodename = tok.str;
797 defp->pc.proc_opcodenum = atoi(tok.str);
798 if (defp->pc.proc_opcodenum < lowest_opcode[PackageIndex])
799 lowest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
800 if (defp->pc.proc_opcodenum < master_lowest_opcode)
801 master_lowest_opcode = defp->pc.proc_opcodenum;
802 if (defp->pc.proc_opcodenum > highest_opcode[PackageIndex])
803 highest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
804 if (defp->pc.proc_opcodenum > master_highest_opcode)
805 master_highest_opcode = defp->pc.proc_opcodenum;
806 scan(TOK_SEMICOLON, &tok);
808 if (master_opcodenumber == 99999)
809 master_opcodenumber = 0;
810 defp->pc.proc_opcodenum = master_opcodenumber++;
811 if (defp->pc.proc_opcodenum < lowest_opcode[PackageIndex])
812 lowest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
813 if (defp->pc.proc_opcodenum > highest_opcode[PackageIndex])
814 highest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
815 if (defp->pc.proc_opcodenum > master_highest_opcode)
816 master_highest_opcode = defp->pc.proc_opcodenum;
817 opcodesnotallowed[PackageIndex] = 1; /* force it */
819 no_of_opcodes[PackageIndex]++, master_no_of_opcodes++;
821 generate_code(defp, 0, 1);
822 if (Cflag || cflag) {
823 generate_code(defp, 1, 1);
825 generate_multi_macros(defp);
827 generate_code(defp, proc_split, 0);
830 if (function_list_index >= MAX_FUNCTIONS_PER_INTERFACE) {
831 error("too many functions in interface, "
832 "increase MAX_FUNCTIONS_PER_INTERFACE");
834 sprintf(function_list[PackageIndex][function_list_index], "%s%s%s",
835 prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
837 function_list_index++;
838 no_of_stat_funcs_header[PackageIndex]++;
844 #define LEGALNUMS "0123456789"
846 InvalidConstant(char *name)
852 slen = (int)strlen(name);
853 return (slen != strspn(name, map));
857 opcodenum_is_defined(int opcode_num)
862 for (listp = proc_defined[PackageIndex]; listp != NULL;
863 listp = listp->next) {
864 defp = (definition *) listp->val;
865 if (opcode_num == defp->pc.proc_opcodenum)
873 analyze_ProcParams(definition * defp, token * tokp)
876 decl_list *decls, **tailp;
878 Proc_listp = &defp->pc.plists;
879 tailp = &defp->def.st.decls;
882 Proc_list = ALLOC(proc1_list);
883 memset((char *)Proc_list, 0, sizeof(proc1_list));
884 Proc_list->pl.param_flag = 0;
885 switch (tokp->kind) {
887 hdle_param_tok(defp, &dec, tokp, DEF_INPARAM);
890 hdle_param_tok(defp, &dec, tokp, DEF_OUTPARAM);
893 hdle_param_tok(defp, &dec, tokp, DEF_INOUTPARAM);
899 hdle_param_tok(defp, &dec, tokp, DEF_NULL);
902 *Proc_listp = Proc_list;
903 Proc_listp = &Proc_list->next;
904 decls = ALLOC(decl_list);
905 memset((char *)decls, 0, sizeof(decl_list));
906 if (tokp->kind != TOK_RPAREN)
909 tailp = &decls->next;
910 } while (tokp->kind != TOK_RPAREN);
916 generate_code(definition * defp, int proc_split_flag, int 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(definition * defp, int multi_flag)
935 char *startname = SplitStart, *endname = SplitEnd;
942 if (Cflag || cflag) {
944 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 0);
946 cs_Proc_CodeGeneration(defp, 1, startname);
948 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 1);
949 do_split(defp, IN, &numofparams, DEF_INPARAM, 0);
951 cs_Proc_CodeGeneration(defp, (multi_flag ? 3 : 2), endname);
953 do_split(defp, IN, &numofparams, DEF_INPARAM, 1);
957 ss_Proc_CodeGeneration(defp);
962 do_split(definition * defp, int direction, int *numofparams,
963 defkind param_kind, int restore_flag)
968 defp->pc.paramtypes[direction] = *numofparams;
969 for (plist = defp->pc.plists; plist; plist = plist->next) {
970 if (plist->component_kind == DEF_NULL
971 && plist->pl.param_kind == param_kind)
972 plist->component_kind = DEF_PARAM;
975 *numofparams = defp->pc.paramtypes[direction];
976 defp->pc.paramtypes[direction] = 0;
977 for (plist = defp->pc.plists; plist; plist = plist->next) {
978 if (plist->component_kind == DEF_PARAM
979 && plist->pl.param_kind == param_kind)
980 plist->component_kind = DEF_NULL;
987 hdle_param_tok(definition * defp, declaration * dec, token * tokp,
990 static defkind last_param_kind = DEF_NULL;
992 if (par_kind == DEF_NULL)
993 Proc_list->pl.param_kind = last_param_kind;
995 Proc_list->pl.param_kind = par_kind;
996 last_param_kind = Proc_list->pl.param_kind;
997 defp->pc.paramtypes[(int)last_param_kind]++;
998 Proc_list->component_kind = DEF_PARAM;
999 Proc_list->code = alloc(250);
1000 Proc_list->scode = alloc(250);
1001 get_declaration(dec, DEF_PARAM);
1002 Proc_list->pl.param_name = dec->name;
1003 get1_param_type(defp, dec, &Proc_list->pl.param_type);
1005 scan2(TOK_COMMA, TOK_RPAREN, tokp);
1006 if (tokp->kind == TOK_COMMA)
1012 get1_param_type(definition * defp, declaration * dec, char **param_type)
1014 char typecontents[100];
1016 if (streq(dec->type, "string")) {
1017 *param_type = "char *";
1020 strcpy(typecontents, dec->prefix);
1021 strcat(typecontents, " ");
1022 strcat(typecontents, dec->type);
1023 strcat(typecontents, " *");
1024 } else if (dec->rel == REL_POINTER) {
1025 strcpy(typecontents, dec->type);
1026 strcat(typecontents, " *");
1028 strcpy(typecontents, dec->type);
1029 *param_type = alloc(100);
1030 strcpy(*param_type, typecontents);
1036 get_param_type(definition * defp, declaration * dec, char **param_type,
1039 char typecontents[100];
1041 if (streq(dec->type, "string")) {
1042 *typename = "wrapstring";
1043 *param_type = "char *";
1045 *typename = dec->type;
1047 strcpy(typecontents, dec->prefix);
1048 strcat(typecontents, " ");
1049 strcat(typecontents, dec->type);
1050 strcat(typecontents, " *");
1051 dec->rel = REL_POINTER;
1052 } else if (dec->rel == REL_POINTER) {
1053 strcpy(typecontents, dec->type);
1054 strcat(typecontents, " *");
1056 strcpy(typecontents, dec->type);
1057 *param_type = alloc(100);
1058 strcpy(*param_type, typecontents);
1065 hndle_param_tail(definition * defp, declaration * dec, token * tokp,
1070 if (dec->rel == REL_POINTER)
1071 Proc_list->pl.param_flag |= INDIRECT_PARAM;
1073 Proc_list->pl.param_flag &= ~INDIRECT_PARAM;
1075 if (!(Proc_list->pl.param_flag & INDIRECT_PARAM))
1078 sprintf(Proc_list->code, "xdr_%s(&z_xdrs, %s%s)", typename, amp,
1079 Proc_list->pl.param_name);
1080 sprintf(Proc_list->scode, "xdr_%s(z_xdrs, &%s)", typename,
1081 Proc_list->pl.param_name);
1082 scan2(TOK_COMMA, TOK_RPAREN, tokp);
1083 if (tokp->kind == TOK_COMMA)
1090 cs_Proc_CodeGeneration(definition * defp, int split_flag, char *procheader)
1093 cs_ProcName_setup(defp, procheader, split_flag);
1095 cs_ProcParams_setup(defp, split_flag);
1096 cs_ProcMarshallInParams_setup(defp, split_flag);
1097 if (split_flag != 1) {
1098 cs_ProcSendPacket_setup(defp, split_flag);
1099 cs_ProcUnmarshallOutParams_setup(defp);
1101 cs_ProcTail_setup(defp, split_flag);
1104 if (!kflag && !split_flag && uflag) {
1105 ucs_ProcName_setup(defp, "ubik_", split_flag);
1107 ucs_ProcParams_setup(defp, split_flag);
1108 ucs_ProcTail_setup(defp, split_flag);
1115 cs_ProcName_setup(definition * defp, char *procheader, int split_flag)
1121 f_print(fout, "int %s%s%s%s(z_call", procheader, prefix,
1122 PackagePrefix[PackageIndex], defp->pc.proc_name);
1124 f_print(fout, "int %s%s%s%s(z_conn", procheader, prefix,
1125 PackagePrefix[PackageIndex], defp->pc.proc_name);
1128 if ((strlen(procheader) + strlen(prefix) +
1129 strlen(PackagePrefix[PackageIndex]) + strlen(defp->pc.proc_name)) >=
1130 MAX_FUNCTION_NAME_LEN) {
1131 error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
1134 for (plist = defp->pc.plists; plist; plist = plist->next) {
1135 if (plist->component_kind == DEF_PARAM) {
1136 plist->pl.param_flag &= ~PROCESSED_PARAM;
1137 f_print(fout, ", %s", plist->pl.param_name);
1140 f_print(fout, ")\n");
1146 cs_ProcParams_setup(definition * defp, int split_flag)
1148 proc1_list *plist, *plist1;
1151 f_print(fout, "\tregister struct rx_connection *z_conn;\n");
1153 f_print(fout, "\tregister struct rx_call *z_call;\n");
1155 for (plist = defp->pc.plists; plist; plist = plist->next) {
1156 if (plist->component_kind == DEF_PARAM
1157 && !(plist->pl.param_flag & PROCESSED_PARAM)) {
1158 if (plist->pl.param_flag & OUT_STRING) {
1159 f_print(fout, "\t%s *%s", plist->pl.param_type,
1160 plist->pl.param_name);
1162 f_print(fout, "\t%s %s", plist->pl.param_type,
1163 plist->pl.param_name);
1165 plist->pl.param_flag |= PROCESSED_PARAM;
1166 for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
1167 if ((plist1->component_kind == DEF_PARAM)
1168 && streq(plist->pl.param_type, plist1->pl.param_type)
1169 && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
1171 char *pntr = strchr(plist1->pl.param_type, '*');
1174 if (plist1->pl.param_flag & OUT_STRING) {
1175 f_print(fout, ", *%s%s", star, plist1->pl.param_name);
1177 f_print(fout, ", %s%s", star, plist1->pl.param_name);
1179 plist1->pl.param_flag |= PROCESSED_PARAM;
1182 f_print(fout, ";\n");
1189 cs_ProcMarshallInParams_setup(definition * defp, int split_flag)
1191 int noofparams, i = 0;
1195 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",
1204 defp->pc.proc_opcodenum);
1206 f_print(fout, "\tstatic int z_op = %s;\n",
1207 defp->pc.proc_opcodename);
1210 f_print(fout, "\tint z_result;\n");
1211 if (!(split_flag > 1) || (noofallparams != 0)) {
1212 f_print(fout, "\tXDR z_xdrs;\n");
1215 * Print out client side stat gathering call
1217 if (xflag && split_flag != 1) {
1218 f_print(fout, "\tstruct clock __QUEUE, __EXEC;\n");
1221 if ((!split_flag) || (split_flag == 1)) {
1222 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_ENCODE);\n");
1223 f_print(fout, "\n\t/* Marshal the arguments */\n");
1224 f_print(fout, "\tif ((!xdr_int(&z_xdrs, &z_op))");
1225 noofparams = defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT];
1226 for (plist = defp->pc.plists, dl = defp->def.st.decls; plist;
1227 plist = plist->next, dl = dl->next) {
1228 if (plist->component_kind == DEF_PARAM
1229 && (plist->pl.param_kind == DEF_INPARAM
1230 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1231 f_print(fout, "\n\t || (!%s)", plist->code);
1232 if (++i == noofparams) {
1234 ") {\n\t\tz_result = RXGEN_CC_MARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1241 ") {\n\t\tz_result = RXGEN_CC_MARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1249 cs_ProcSendPacket_setup(definition * defp, int split_flag)
1251 int noofoutparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1253 if (noofoutparams) {
1254 f_print(fout, "\t/* Un-marshal the reply arguments */\n");
1256 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
1258 f_print(fout, "\tz_xdrs.x_op = XDR_DECODE;\n");
1265 cs_ProcUnmarshallOutParams_setup(definition * defp)
1271 noofparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1273 for (plist = defp->pc.plists, dl = defp->def.st.decls, i = 0; plist;
1274 plist = plist->next, dl = dl->next) {
1275 if (plist->component_kind == DEF_PARAM
1276 && (plist->pl.param_kind == DEF_OUTPARAM
1277 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1279 f_print(fout, "\tif ((!%s)", plist->code);
1281 f_print(fout, "\n\t || (!%s)", plist->code);
1283 if (++i == noofparams) {
1285 ") {\n\t\tz_result = RXGEN_CC_UNMARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1294 cs_ProcTail_setup(definition * defp, int split_flag)
1296 f_print(fout, "\tz_result = RXGEN_SUCCESS;\n");
1297 if (defp->can_fail) {
1298 f_print(fout, "fail:\n");
1301 f_print(fout, "\tz_result = rx_EndCall(z_call, z_result);\n");
1303 if (xflag && split_flag != 1) {
1304 f_print(fout, "\tif (rx_enable_stats) {\n");
1305 f_print(fout, "\t clock_GetTime(&__EXEC);\n");
1306 f_print(fout, "\t clock_Sub(&__EXEC, &z_call->startTime);\n");
1307 f_print(fout, "\t __QUEUE = z_call->startTime;\n");
1308 f_print(fout, "\t clock_Sub(&__QUEUE, &z_call->queueTime);\n");
1309 if (PackageStatIndex[PackageIndex]) {
1312 "\t rx_IncrementTimeAndCount(z_conn->peer, %s,\n",
1313 PackageStatIndex[PackageIndex]);
1316 "\t rx_IncrementTimeAndCount(z_call->conn->peer, %s,\n",
1317 PackageStatIndex[PackageIndex]);
1322 "\t rx_IncrementTimeAndCount(z_conn->peer,\n"
1323 "\t\t(((afs_uint32)(ntohs(z_conn->serviceId) << 16)) \n"
1324 "\t\t| ((afs_uint32)ntohs(z_conn->peer->port))),\n");
1327 "\t rx_IncrementTimeAndCount(z_call->conn->peer,\n"
1328 "\t\t(((afs_uint32)(ntohs(z_call->conn->serviceId) << 16)) |\n"
1329 "\t\t((afs_uint32)ntohs(z_call->conn->peer->port))),\n");
1333 f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, &__QUEUE, &__EXEC,\n",
1334 no_of_stat_funcs, PackagePrefix[PackageIndex]);
1336 "\t\t&z_call->bytesSent, &z_call->bytesRcvd, 1);\n");
1338 f_print(fout, "\t}\n\n");
1340 f_print(fout, "\treturn z_result;\n}\n\n");
1345 ss_Proc_CodeGeneration(definition * defp)
1350 ss_ProcName_setup(defp);
1352 ss_ProcParams_setup(defp, &somefrees);
1353 ss_ProcSpecial_setup(defp, &somefrees);
1354 ss_ProcUnmarshallInParams_setup(defp);
1355 ss_ProcCallRealProc_setup(defp);
1356 ss_ProcMarshallOutParams_setup(defp);
1357 ss_ProcTail_setup(defp, somefrees);
1363 ss_ProcName_setup(definition * defp)
1367 if ((strlen(prefix) + strlen(PackagePrefix[PackageIndex]) +
1368 strlen(defp->pc.proc_name)) >= MAX_FUNCTION_NAME_LEN) {
1369 error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
1373 f_print(fout, "static afs_int32 _%s%s%s(", prefix,
1374 PackagePrefix[PackageIndex], defp->pc.proc_name);
1375 f_print(fout, "struct rx_call *z_call, XDR *z_xdrs)\n{\n");
1376 f_print(fout, "\t" "afs_int32 z_result;\n");
1378 f_print(fout, "\tstruct clock __QUEUE, __EXEC;\n");
1381 for (plist = defp->pc.plists; plist; plist = plist->next)
1382 if (plist->component_kind == DEF_PARAM) {
1383 plist->pl.param_flag &= ~(PROCESSED_PARAM);
1384 plist->pl.string_name = NULL;
1391 ss_ProcParams_setup(definition * defp, int *somefrees)
1393 proc1_list *plist, *plist1;
1397 for (plist = defp->pc.plists; plist; plist = plist->next) {
1398 if ((plist->component_kind == DEF_PARAM)
1399 && !(plist->pl.param_flag & PROCESSED_PARAM)) {
1400 if (plist->pl.param_flag & INDIRECT_PARAM) {
1401 char pres = '\0', *pntr = strchr(plist->pl.param_type, '*');
1407 f_print(fout, "\t%s %s", plist->pl.param_type,
1408 plist->pl.param_name);
1410 } else if (strchr(plist->pl.param_type, '*') == 0) {
1411 f_print(fout, "\t%s %s", plist->pl.param_type,
1412 plist->pl.param_name);
1414 plist->pl.param_flag |= FREETHIS_PARAM;
1416 f_print(fout, "\t%s %s=(%s)0", plist->pl.param_type,
1417 plist->pl.param_name, plist->pl.param_type);
1419 plist->pl.param_flag |= PROCESSED_PARAM;
1420 for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
1421 if ((plist1->component_kind == DEF_PARAM)
1422 && streq(plist->pl.param_type, plist1->pl.param_type)
1423 && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
1424 if (plist1->pl.param_flag & INDIRECT_PARAM) {
1425 f_print(fout, ", %s", plist1->pl.param_name);
1426 } else if (strchr(plist1->pl.param_type, '*') == 0) {
1427 f_print(fout, ", %s", plist1->pl.param_name);
1429 plist1->pl.param_flag |= FREETHIS_PARAM;
1431 f_print(fout, ", *%s=(%s)0", plist1->pl.param_name,
1432 plist1->pl.param_type);
1434 plist1->pl.param_flag |= PROCESSED_PARAM;
1437 f_print(fout, ";\n");
1440 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1441 defp1 = (definition *) listp->val;
1442 for (plist = defp->pc.plists; plist; plist = plist->next) {
1443 if (plist->component_kind == DEF_PARAM
1444 && (plist->pl.param_kind == DEF_OUTPARAM
1445 || plist->pl.param_kind == DEF_INOUTPARAM)
1446 && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1447 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1448 switch (defp1->pc.rel) {
1457 fprintf(fout, "\n");
1462 ss_ProcSpecial_setup(definition * defp, int *somefrees)
1468 for (listp = special_defined; listp != NULL; listp = listp->next) {
1469 defp1 = (definition *) listp->val;
1470 for (plist = defp->pc.plists; plist; plist = plist->next) {
1471 if (plist->component_kind == DEF_PARAM
1472 && (plist->pl.param_kind == DEF_INPARAM
1473 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1474 spec_list *spec = defp1->def.sd.specs;
1476 strcpy(string, structname(spec->sdef.string_value));
1477 if (streq(string, structname(plist->pl.param_type))) {
1478 plist->pl.string_name = spec->sdef.string_name;
1479 plist->pl.param_flag |= FREETHIS_PARAM;
1481 fprintf(fout, "\n\t%s.%s = 0;", plist->pl.param_name,
1482 spec->sdef.string_name);
1488 fprintf(fout, "\n");
1489 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1490 defp1 = (definition *) listp->val;
1491 for (plist = defp->pc.plists; plist; plist = plist->next) {
1492 if (plist->component_kind == DEF_PARAM) {
1493 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1494 plist->pl.param_flag |= FREETHIS_PARAM;
1496 switch (defp1->pc.rel) {
1498 f_print(fout, "\n\t%s.%s_val = 0;",
1499 plist->pl.param_name, defp1->def_name);
1500 f_print(fout, "\n\t%s.%s_len = 0;",
1501 plist->pl.param_name, defp1->def_name);
1502 plist->pl.string_name = alloc(40);
1503 s_print(plist->pl.string_name, "%s_val",
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(definition * defp)
1522 int noofparams, noofoutparams, i;
1525 noofparams = defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT];
1526 noofoutparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1527 for (plist = defp->pc.plists, i = 0; plist; plist = plist->next) {
1528 if (plist->component_kind == DEF_PARAM
1529 && (plist->pl.param_kind == DEF_INPARAM
1530 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1532 f_print(fout, "\n\tif ((!%s)",
1533 (plist->scode ? plist->scode : plist->code));
1535 f_print(fout, "\n\t || (!%s)",
1536 (plist->scode ? plist->scode : plist->code));
1538 if (++i == noofparams) {
1539 if (!noofoutparams) {
1540 f_print(fout, ") {\n");
1542 f_print(fout, ") {\n");
1545 "\t\tz_result = RXGEN_SS_UNMARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1554 ss_ProcCallRealProc_setup(definition * defp)
1559 f_print(fout, "\tz_result = %s%s%s%s(z_call", prefix, ServerPrefix,
1560 PackagePrefix[PackageIndex], defp->pc.proc_name);
1561 for (plist = defp->pc.plists; plist; plist = plist->next) {
1562 if (plist->component_kind == DEF_PARAM) {
1563 if (plist->pl.param_flag & INDIRECT_PARAM) {
1564 f_print(fout, ", &%s", plist->pl.param_name);
1566 if (plist->pl.param_flag & OUT_STRING) {
1567 f_print(fout, ", &%s", plist->pl.param_name);
1569 f_print(fout, ", %s", plist->pl.param_name);
1574 f_print(fout, ");\n");
1576 f_print(fout, "\tif (z_result)\n\t\treturn z_result;\n");
1582 ss_ProcMarshallOutParams_setup(definition * defp)
1587 noofparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1589 f_print(fout, "\tz_xdrs->x_op = XDR_ENCODE;\n");
1591 for (plist = defp->pc.plists, i = 0; plist; plist = plist->next) {
1592 if (plist->component_kind == DEF_PARAM
1593 && (plist->pl.param_kind == DEF_OUTPARAM
1594 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1596 f_print(fout, "\tif ((!%s)",
1597 (plist->scode ? plist->scode : plist->code));
1599 f_print(fout, "\n\t || (!%s)",
1600 (plist->scode ? plist->scode : plist->code));
1602 if (++i == noofparams) {
1603 f_print(fout, ")\n\t\tz_result = RXGEN_SS_MARSHAL;\n");
1612 ss_ProcTail_setup(definition * defp, int somefrees)
1619 if (defp->can_fail) {
1620 f_print(fout, "fail:\n");
1622 for (plist = defp->pc.plists; plist; plist = plist->next) {
1623 if (plist->component_kind == DEF_PARAM
1624 && (plist->pl.param_flag & FREETHIS_PARAM))
1628 f_print(fout, "\tz_xdrs->x_op = XDR_FREE;\n");
1629 for (plist = defp->pc.plists; plist; plist = plist->next) {
1630 if (plist->component_kind == DEF_PARAM
1631 && (plist->pl.param_flag & FREETHIS_PARAM)) {
1632 char *dot = "", *extens = "";
1633 if (plist->pl.string_name) {
1635 extens = plist->pl.string_name;
1637 f_print(fout, "\tif (!%s) goto fail1;\n", plist->scode);
1640 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1641 defp1 = (definition *) listp->val;
1642 for (plist = defp->pc.plists; plist; plist = plist->next) {
1643 if (plist->component_kind == DEF_PARAM
1644 && (plist->pl.param_kind == DEF_OUTPARAM
1645 || plist->pl.param_kind == DEF_INOUTPARAM)
1646 && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1647 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1648 switch (defp1->pc.rel) {
1651 if (!somefrees && !firsttime) {
1653 f_print(fout, "\tz_xdrs->x_op = XDR_FREE;\n");
1656 f_print(fout, "\tif (!%s) goto fail1;\n",
1664 for (listp = uniondef_defined; listp != NULL; listp = listp->next) {
1665 defp1 = (definition *) listp->val;
1666 for (plist = defp->pc.plists; plist; plist = plist->next) {
1667 if (plist->component_kind == DEF_PARAM
1668 && (plist->pl.param_kind == DEF_OUTPARAM
1669 || plist->pl.param_kind == DEF_INOUTPARAM)
1670 && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1671 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1672 if (plist->pl.param_flag & INDIRECT_PARAM) {
1673 if (!somefrees && !firsttime) {
1675 f_print(fout, "\tz_xdrs->x_op = XDR_FREE;\n");
1678 f_print(fout, "\tif (!%s) goto fail1;\n",
1687 f_print(fout, "\tif (rx_enable_stats) {\n");
1688 f_print(fout, "\t clock_GetTime(&__EXEC);\n");
1689 f_print(fout, "\t clock_Sub(&__EXEC, &z_call->startTime);\n");
1690 f_print(fout, "\t __QUEUE = z_call->startTime;\n");
1691 f_print(fout, "\t clock_Sub(&__QUEUE, &z_call->queueTime);\n");
1692 f_print(fout, "\t rx_IncrementTimeAndCount(z_call->conn->peer,");
1693 if (PackageStatIndex[PackageIndex]) {
1694 f_print(fout, " %s,\n", PackageStatIndex[PackageIndex]);
1697 "\n\t\t(((afs_uint32)(ntohs(z_call->conn->serviceId) << 16)) |\n"
1698 "\t\t((afs_uint32)ntohs(z_call->conn->service->servicePort))),\n");
1700 f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, &__QUEUE, &__EXEC,\n",
1701 no_of_stat_funcs, PackagePrefix[PackageIndex]);
1702 f_print(fout, "\t\t&z_call->bytesSent, &z_call->bytesRcvd, 0);\n");
1703 f_print(fout, "\t}\n\n");
1706 f_print(fout, "\treturn z_result;\n");
1708 f_print(fout, "fail1:\n");
1711 f_print(fout, "\tif (rx_enable_stats) {\n");
1712 f_print(fout, "\t clock_GetTime(&__EXEC);\n");
1713 f_print(fout, "\t clock_Sub(&__EXEC, &z_call->startTime);\n");
1714 f_print(fout, "\t __QUEUE = z_call->startTime;\n");
1715 f_print(fout, "\t clock_Sub(&__QUEUE, &z_call->queueTime);\n");
1717 "\t rx_IncrementTimeAndCount(z_call->conn->peer,");
1718 if (PackageStatIndex[PackageIndex]) {
1719 f_print(fout, " %s,\n", PackageStatIndex[PackageIndex]);
1722 "\n\t\t(((afs_uint32)(ntohs(z_call->conn->serviceId) << 16)) |\n"
1723 "\t\t((afs_uint32)ntohs(z_call->conn->service->servicePort))),\n");
1725 f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, &__QUEUE, &__EXEC,\n",
1726 no_of_stat_funcs, PackagePrefix[PackageIndex]);
1728 "\t\t&z_call->bytesSent, &z_call->bytesRcvd, 0);\n");
1729 f_print(fout, "\t}\n\n");
1732 f_print(fout, "\treturn RXGEN_SS_XDRFREE;\n}\n\n");
1734 f_print(fout, "}\n\n");
1740 ucs_ProcName_setup(definition * defp, char *procheader, int split_flag)
1745 f_print(fout, "int %s%s%s%s(aclient, aflags", procheader, prefix,
1746 PackagePrefix[PackageIndex], defp->pc.proc_name);
1748 if ((strlen(procheader) + strlen(prefix) +
1749 strlen(PackagePrefix[PackageIndex]) + strlen(defp->pc.proc_name)) >=
1750 MAX_FUNCTION_NAME_LEN) {
1751 error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
1754 for (plist = defp->pc.plists; plist; plist = plist->next) {
1755 if (plist->component_kind == DEF_PARAM) {
1756 plist->pl.param_flag &= ~PROCESSED_PARAM;
1757 f_print(fout, ", %s", plist->pl.param_name);
1760 f_print(fout, ")\n");
1766 ucs_ProcParams_setup(definition * defp, int split_flag)
1768 proc1_list *plist, *plist1;
1770 f_print(fout, "\tregister struct ubik_client *aclient;\n\tafs_int32 aflags;\n");
1771 for (plist = defp->pc.plists; plist; plist = plist->next) {
1772 if (plist->component_kind == DEF_PARAM
1773 && !(plist->pl.param_flag & PROCESSED_PARAM)) {
1774 if (plist->pl.param_flag & OUT_STRING) {
1775 f_print(fout, "\t%s *%s", plist->pl.param_type,
1776 plist->pl.param_name);
1778 f_print(fout, "\t%s %s", plist->pl.param_type,
1779 plist->pl.param_name);
1781 plist->pl.param_flag |= PROCESSED_PARAM;
1782 for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
1783 if ((plist1->component_kind == DEF_PARAM)
1784 && streq(plist->pl.param_type, plist1->pl.param_type)
1785 && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
1787 char *pntr = strchr(plist1->pl.param_type, '*');
1790 if (plist1->pl.param_flag & OUT_STRING) {
1791 f_print(fout, ", *%s%s", star, plist1->pl.param_name);
1793 f_print(fout, ", %s%s", star, plist1->pl.param_name);
1795 plist1->pl.param_flag |= PROCESSED_PARAM;
1798 f_print(fout, ";\n");
1804 ucs_ProcTail_setup(definition * defp, int split_flag)
1808 f_print(fout, "{\tafs_int32 rcode, code, newHost, thisHost, i, _ucount;\n");
1809 f_print(fout, "\tint chaseCount, pass, needsync, inlist;\n");
1810 #if 0 /* goes with block below */
1811 f_print(fout, "\tint j;\n");
1813 f_print(fout, "\tstruct rx_connection *tc;\n");
1814 f_print(fout, "\tstruct rx_peer *rxp;\n");
1815 f_print(fout, "\tshort origLevel;\n\n");
1816 f_print(fout, "\tif (!aclient)\n");
1817 f_print(fout, "\t\treturn UNOENT;\n");
1818 f_print(fout, "\tLOCK_UBIK_CLIENT(aclient);\n\n");
1819 f_print(fout, "\t restart:\n");
1820 f_print(fout, "\torigLevel = aclient->initializationState;\n");
1821 f_print(fout, "\trcode = UNOSERVERS;\n");
1822 f_print(fout, "\tchaseCount = inlist = needsync = 0;\n\n");
1823 #if 0 /* We should do some sort of caching algorithm for this, but I need to think about it - shadow 26 jun 06 */
1824 f_print(fout, "\tLOCK_UCLNT_CACHE;\n");
1825 f_print(fout, "\tfor (j = 0; ((j < SYNCCOUNT) && calls_needsync[j]); j++) {\n");
1826 f_print(fout, "\t\tif (calls_needsync[j] == (int *)%s%s%s) {\n", prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
1827 f_print(fout, "\t\t\tinlist = needsync = 1;\n");
1828 f_print(fout, "\t\t\tbreak;\n");
1829 f_print(fout, "\t\t}\n");
1830 f_print(fout, "\t}\n");
1831 f_print(fout, "\tUNLOCK_UCLNT_CACHE;\n");
1833 f_print(fout, "\t/* \n\t* First pass, we try all servers that are up.\n\t* Second pass, we try all servers.\n\t*/\n");
1834 f_print(fout, "\tfor (pass = 0; pass < 2; pass++) { /*p */\n");
1835 f_print(fout, "\t\t/* For each entry in our servers list */\n");
1836 f_print(fout, "\t\tfor (_ucount = 0;; _ucount++) { /*s */\n\n");
1837 f_print(fout, "\t\tif (needsync) {\n");
1838 f_print(fout, "\t\t\t/* Need a sync site. Lets try to quickly find it */\n");
1839 f_print(fout, "\t\t\tif (aclient->syncSite) {\n");
1840 f_print(fout, "\t\t\t\tnewHost = aclient->syncSite; /* already in network order */\n");
1841 f_print(fout, "\t\t\t\taclient->syncSite = 0; /* Will reset if it works */\n");
1842 f_print(fout, "\t\t\t} else if (aclient->conns[3]) {\n");
1843 f_print(fout, "\t\t\t\t/* If there are fewer than four db servers in a cell,\n");
1844 f_print(fout, "\t\t\t\t* there's no point in making the GetSyncSite call.\n");
1845 f_print(fout, "\t\t\t\t* At best, it's a wash. At worst, it results in more\n");
1846 f_print(fout, "\t\t\t\t* RPCs than you would otherwise make.\n");
1847 f_print(fout, "\t\t\t\t*/\n");
1848 f_print(fout, "\t\t\t\ttc = aclient->conns[_ucount];\n");
1849 f_print(fout, "\t\t\t\tif (tc && rx_ConnError(tc)) {\n");
1850 f_print(fout, "\t\t\t\t\taclient->conns[_ucount] = tc = ubik_RefreshConn(tc);\n");
1851 f_print(fout, "\t\t\t\t}\n");
1852 f_print(fout, "\t\t\t\tif (!tc)\n");
1853 f_print(fout, "\t\t\t\t\tbreak;\n");
1854 f_print(fout, "\t\t\t\tcode = VOTE_GetSyncSite(tc, &newHost);\n");
1855 f_print(fout, "\t\t\t\tif (aclient->initializationState != origLevel)\n");
1856 f_print(fout, "\t\t\t\t\tgoto restart; /* somebody did a ubik_ClientInit */\n");
1857 f_print(fout, "\t\t\t\tif (code)\n");
1858 f_print(fout, "\t\t\t\t\tnewHost = 0;\n");
1859 f_print(fout, "\t\t\t\tnewHost = htonl(newHost); /* convert to network order */\n");
1860 f_print(fout, "\t\t\t} else {\n");
1861 f_print(fout, "\t\t\t\tnewHost = 0;\n");
1862 f_print(fout, "\t\t\t}\n");
1863 f_print(fout, "\t\t\tif (newHost) {\n");
1864 f_print(fout, "\t\t\t\t/* position count at the appropriate slot in the client\n");
1865 f_print(fout, "\t\t\t\t* structure and retry. If we can't find in slot, we'll\n");
1866 f_print(fout, "\t\t\t\t* just continue through the whole list \n");
1867 f_print(fout, "\t\t\t\t*/\n");
1868 f_print(fout, "\t\t\t\tfor (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {\n");
1869 f_print(fout, "\t\t\t\t\trxp = rx_PeerOf(aclient->conns[i]);\n");
1870 f_print(fout, "\t\t\t\t\tthisHost = rx_HostOf(rxp);\n");
1871 f_print(fout, "\t\t\t\t\tif (!thisHost)\n");
1872 f_print(fout, "\t\t\t\t\t\tbreak;\n");
1873 f_print(fout, "\t\t\t\t\tif (thisHost == newHost) {\n");
1874 f_print(fout, "\t\t\t\t\t\tif (chaseCount++ > 2)\n");
1875 f_print(fout, "\t\t\t\t\t\t\tbreak; /* avoid loop asking */\n");
1876 f_print(fout, "\t\t\t\t\t\t_ucount = i; /* this index is the sync site */\n");
1877 f_print(fout, "\t\t\t\t\t\tbreak;\n");
1878 f_print(fout, "\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n");
1879 f_print(fout, "\t\t/*needsync */\n");
1880 f_print(fout, "\t\ttc = aclient->conns[_ucount];\n");
1881 f_print(fout, "\t\tif (tc && rx_ConnError(tc)) {\n");
1882 f_print(fout, "\t\t\taclient->conns[_ucount] = tc = ubik_RefreshConn(tc);\n");
1883 f_print(fout, "\t\t}\n");
1884 f_print(fout, "\t\tif (!tc)\n");
1885 f_print(fout, "\t\t\tbreak;\n\n");
1886 f_print(fout, "\t\tif ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {\n");
1887 f_print(fout, "\t\t\tcontinue; /* this guy's down */\n");
1888 f_print(fout, "\t\t}\n");
1890 f_print(fout, "\t\trcode = %s%s%s(tc\n", prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
1891 for (plist = defp->pc.plists; plist; plist = plist->next) {
1892 if (plist->component_kind == DEF_PARAM) {
1893 plist->pl.param_flag &= ~PROCESSED_PARAM;
1894 f_print(fout, ", %s", plist->pl.param_name);
1897 f_print(fout, ");\n");
1898 f_print(fout, "\t\tif (aclient->initializationState != origLevel) {\n");
1899 f_print(fout, "\t\t\t/* somebody did a ubik_ClientInit */\n");
1900 f_print(fout, "\t\t\tif (rcode)\n");
1901 f_print(fout, "\t\t\t\tgoto restart; /* call failed */\n");
1902 f_print(fout, "\t\t\telse\n");
1903 f_print(fout, "\t\t\t\tgoto done; /* call suceeded */\n");
1904 f_print(fout, "\t\t}\n");
1905 f_print(fout, "\t\tif (rcode < 0) { /* network errors */\n");
1906 f_print(fout, "\t\t\taclient->states[_ucount] |= CFLastFailed; /* Mark server down */\n");
1907 f_print(fout, "\t\t} else if (rcode == UNOTSYNC) {\n");
1908 f_print(fout, "\t\t\tneedsync = 1;\n");
1909 f_print(fout, "\t\t} else if (rcode != UNOQUORUM) {\n");
1910 f_print(fout, "\t\t\t/* either misc ubik code, or misc appl code, or success. */\n");
1911 f_print(fout, "\t\t\taclient->states[_ucount] &= ~CFLastFailed; /* mark server up*/\n");
1912 f_print(fout, "\t\t\tgoto done; /* all done */\n");
1913 f_print(fout, "\t\t}\n");
1914 f_print(fout, "\t\t} /*s */\n");
1915 f_print(fout, "\t} /*p */\n\n");
1916 f_print(fout, "\tdone:\n");
1917 f_print(fout, "\tif (needsync) {\n");
1918 f_print(fout, "\t\tif (!inlist) { /* Remember proc call that needs sync site */\n");
1919 #if 0 /* We should do some sort of caching algorithm for this, but I need to think about it - shadow 26 jun 06 */
1920 f_print(fout, "\t\t\tLOCK_UCLNT_CACHE;\n");
1921 f_print(fout, "\t\t\tcalls_needsync[synccount % SYNCCOUNT] = (int *)%s%s%s;\n", prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
1922 f_print(fout, "\t\t\tsynccount++;\n");
1923 f_print(fout, "\t\t\tUNLOCK_UCLNT_CACHE;\n");
1925 f_print(fout, "\t\t\tinlist = 1;\n");
1926 f_print(fout, "\t\t}\n");
1927 f_print(fout, "\t\tif (!rcode) { /* Remember the sync site - cmd successful */\n");
1928 f_print(fout, "\t\t\trxp = rx_PeerOf(aclient->conns[_ucount]);\n");
1929 f_print(fout, "\t\t\taclient->syncSite = rx_HostOf(rxp);\n");
1930 f_print(fout, "\t\t}\n");
1931 f_print(fout, "\t}\n");
1932 f_print(fout, "\tUNLOCK_UBIK_CLIENT(aclient);\n");
1933 f_print(fout, "\treturn rcode;\n}\n\n");
1938 opcode_holes_exist(void)
1942 for (i = lowest_opcode[PackageIndex]; i < highest_opcode[PackageIndex];
1944 if (!opcodenum_is_defined(i))
1952 er_Proc_CodeGeneration(void)
1956 temp = PackageIndex;
1957 if (!combinepackages)
1959 for (; PackageIndex <= temp; PackageIndex++) {
1960 if (proc_defined[PackageIndex] == NULL)
1962 if (combinepackages || opcode_holes_exist()) {
1963 er_HeadofOldStyleProc_setup();
1964 er_BodyofOldStyleProc_setup();
1965 er_TailofOldStyleProc_setup();
1967 er_ProcDeclExterns_setup();
1968 er_ProcProcsArray_setup();
1969 er_ProcMainBody_setup();
1972 PackageIndex = temp;
1977 er_ProcDeclExterns_setup(void)
1982 f_print(fout, "\n");
1983 for (listp = proc_defined[PackageIndex]; listp != NULL;
1984 listp = listp->next) {
1985 defp = (definition *) listp->val;
1986 if (defp->pc.proc_serverstub) {
1987 f_print(fout, "afs_int32 %s();\n", defp->pc.proc_serverstub);
1994 er_ProcProcsArray_setup(void)
1999 if ((listp = proc_defined[PackageIndex])) {
2000 defp = (definition *) listp->val;
2001 if (defp->pc.proc_serverstub) {
2002 f_print(fout, "\nstatic afs_int32 (*StubProcsArray%d[])() = {%s",
2003 PackageIndex, defp->pc.proc_serverstub);
2006 "\nstatic afs_int32 (*StubProcsArray%d[])(struct rx_call *z_call, XDR *z_xdrs) = {_%s%s%s",
2007 PackageIndex, prefix, defp->pc.proc_prefix,
2008 ((definition *) listp->val)->pc.proc_name);
2009 defp = (definition *) listp->val;
2011 listp = listp->next;
2013 for (; listp != NULL; listp = listp->next) {
2014 defp = (definition *) listp->val;
2015 if (defp->pc.proc_serverstub) {
2016 f_print(fout, ",%s", defp->pc.proc_serverstub);
2018 f_print(fout, ", _%s%s%s", prefix, defp->pc.proc_prefix,
2019 defp->pc.proc_name);
2022 f_print(fout, "};\n\n");
2027 er_ProcMainBody_setup(void)
2029 f_print(fout, "int %s%sExecuteRequest(register struct rx_call *z_call)\n",
2030 prefix, PackagePrefix[PackageIndex]);
2031 f_print(fout, "{\n\tint op;\n");
2032 f_print(fout, "\tXDR z_xdrs;\n");
2033 f_print(fout, "\t" "afs_int32 z_result;\n\n");
2034 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
2036 "\tif (!xdr_int(&z_xdrs, &op))\n\t\tz_result = RXGEN_DECODE;\n");
2038 "\telse if (op < %sLOWEST_OPCODE || op > %sHIGHEST_OPCODE)\n\t\tz_result = RXGEN_OPCODE;\n",
2039 PackagePrefix[PackageIndex], PackagePrefix[PackageIndex]);
2041 "\telse\n\t\tz_result = (*StubProcsArray%d[op - %sLOWEST_OPCODE])(z_call, &z_xdrs);\n",
2042 PackageIndex, PackagePrefix[PackageIndex]);
2043 f_print(fout, "\treturn hton_syserr_conv(z_result);\n}\n");
2048 er_HeadofOldStyleProc_setup(void)
2051 "\nint %s%sExecuteRequest (register struct rx_call *z_call)\n",
2053 (combinepackages ? MasterPrefix : PackagePrefix[PackageIndex]));
2054 f_print(fout, "{\n");
2055 f_print(fout, "\tint op;\n");
2056 f_print(fout, "\tXDR z_xdrs;\n");
2057 f_print(fout, "\t" "afs_int32 z_result;\n\n");
2058 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
2059 f_print(fout, "\tz_result = RXGEN_DECODE;\n");
2060 f_print(fout, "\tif (!xdr_int(&z_xdrs, &op)) goto fail;\n");
2061 f_print(fout, "\tswitch (op) {\n");
2065 er_BodyofOldStyleProc_setup(void)
2069 if (combinepackages) {
2070 int temp = PackageIndex;
2071 for (PackageIndex = 0; PackageIndex <= temp; PackageIndex++) {
2072 for (listp = proc_defined[PackageIndex]; listp != NULL;
2073 listp = listp->next)
2074 proc_er_case((definition *) listp->val);
2076 PackageIndex = temp;
2078 for (listp = proc_defined[PackageIndex]; listp != NULL;
2079 listp = listp->next)
2080 proc_er_case((definition *) listp->val);
2086 proc_er_case(definition * defp)
2088 if (opcodesnotallowed[PackageIndex]) {
2089 f_print(fout, "\t\tcase %d:\n", defp->pc.proc_opcodenum);
2091 f_print(fout, "\t\tcase %s:\n", defp->pc.proc_opcodename);
2093 if (defp->pc.proc_serverstub) {
2094 f_print(fout, "\t\t\tz_result = %s(z_call, &z_xdrs);\n",
2095 defp->pc.proc_serverstub);
2097 f_print(fout, "\t\t\tz_result = _%s%s%s(z_call, &z_xdrs);\n", prefix,
2098 defp->pc.proc_prefix, defp->pc.proc_name);
2100 f_print(fout, "\t\t\tbreak;\n");
2105 er_TailofOldStyleProc_setup(void)
2107 f_print(fout, "\t\tdefault:\n");
2108 f_print(fout, "\t\t\tz_result = RXGEN_OPCODE;\n");
2109 f_print(fout, "\t\t\tbreak;\n\t}\n");
2110 f_print(fout, "fail:\n");
2111 f_print(fout, "\treturn z_result;\n}\n");
2116 h_opcode_stats(void)
2118 if (combinepackages) {
2120 "\n/* Opcode-related useful stats for Master package: %s */\n",
2122 f_print(fout, "#define %sLOWEST_OPCODE %d\n", MasterPrefix,
2123 master_lowest_opcode);
2124 f_print(fout, "#define %sHIGHEST_OPCODE %d\n", MasterPrefix,
2125 master_highest_opcode);
2126 f_print(fout, "#define %sNUMBER_OPCODES %d\n\n", MasterPrefix,
2127 master_no_of_opcodes);
2129 f_print(fout, "#define %sNO_OF_STAT_FUNCS\t%d\n\n", MasterPrefix,
2130 no_of_stat_funcs_header[0]);
2131 f_print(fout, "AFS_RXGEN_EXPORT\n");
2132 f_print(fout, "extern const char *%sfunction_names[];\n\n",
2137 for (i = 0; i <= PackageIndex; i++) {
2139 "\n/* Opcode-related useful stats for package: %s */\n",
2141 f_print(fout, "#define %sLOWEST_OPCODE %d\n", PackagePrefix[i],
2143 f_print(fout, "#define %sHIGHEST_OPCODE %d\n",
2144 PackagePrefix[i], highest_opcode[i]);
2145 f_print(fout, "#define %sNUMBER_OPCODES %d\n\n",
2146 PackagePrefix[i], no_of_opcodes[i]);
2148 f_print(fout, "#define %sNO_OF_STAT_FUNCS\t%d\n\n",
2149 PackagePrefix[i], no_of_stat_funcs_header[i]);
2150 f_print(fout, "AFS_RXGEN_EXPORT\n");
2151 f_print(fout, "extern const char *%sfunction_names[];\n\n",
2160 generate_multi_macros(definition * defp)
2162 char *startname = SplitStart, *endname = SplitEnd;
2171 f_print(fout, "\n#include <rx/rx_multi.h>");
2173 f_print(fout, "\n#define multi_%s%s(", PackagePrefix[PackageIndex],
2174 defp->pc.proc_name);
2175 for (plist = defp->pc.plists; plist; plist = plist->next) {
2176 if (plist->component_kind == DEF_PARAM) {
2179 f_print(fout, "%s", plist->pl.param_name);
2181 f_print(fout, ", %s", plist->pl.param_name);
2185 f_print(fout, ") \\\n");
2187 startname = "Start";
2190 f_print(fout, "\tmulti_Body(%s%s%s(multi_call", startname,
2191 PackagePrefix[PackageIndex], defp->pc.proc_name);
2192 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 0);
2193 for (plist = defp->pc.plists; plist; plist = plist->next) {
2194 if (plist->component_kind == DEF_PARAM)
2195 f_print(fout, ", %s", plist->pl.param_name);
2197 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 1);
2198 f_print(fout, "), %s%s%s(multi_call", endname,
2199 PackagePrefix[PackageIndex], defp->pc.proc_name);
2200 do_split(defp, IN, &numofparams, DEF_INPARAM, 0);
2201 for (plist = defp->pc.plists; plist; plist = plist->next) {
2202 if (plist->component_kind == DEF_PARAM) {
2203 f_print(fout, ", %s", plist->pl.param_name);
2206 do_split(defp, IN, &numofparams, DEF_INPARAM, 1);
2207 f_print(fout, "))\n\n");
2212 IsRxgenToken(token * tokp)
2214 if (tokp->kind == TOK_PACKAGE || tokp->kind == TOK_PREFIX
2215 || tokp->kind == TOK_SPECIAL || tokp->kind == TOK_STARTINGOPCODE
2216 || tokp->kind == TOK_SPLITPREFIX || tokp->kind == TOK_PROC
2217 || tokp->kind == TOK_STATINDEX)
2223 IsRxgenDefinition(definition * def)
2225 if (def->def_kind == DEF_PACKAGE || def->def_kind == DEF_PREFIX
2226 || def->def_kind == DEF_SPECIAL || def->def_kind == DEF_STARTINGOPCODE
2227 || def->def_kind == DEF_SPLITPREFIX || def->def_kind == DEF_PROC)