From: Felix Frank Date: Fri, 12 Nov 2010 23:10:31 +0000 (+0100) Subject: rxgen: add *TranslateOpcode functions to XDR code X-Git-Tag: upstream/1.8.0_pre1^2~4494 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=5c77a6ca2460c3e79125a614037824db35480905;p=packages%2Fo%2Fopenafs.git rxgen: add *TranslateOpcode functions to XDR code Administrative commands and server binaries can benefit from the ability to translate RPC OpCode numbers to proper function names. For this purpose, rxgen now emits the function char *PKGTranslateOpCode(int) where PKG is replaced by the respective package prefix. The function is generated in the exact same way that ExecuteRequest is. This way, the right optimization (array storage vs. generated case statement) according to the respective sparseness of OpCodes in the different RX packages is maintained. Change-Id: Ib083597c0841f50518afd2b159b98c0447e13da0 Reviewed-on: http://gerrit.openafs.org/3305 Reviewed-by: Derrick Brashear Tested-by: BuildBot --- diff --git a/src/rxgen/rpc_main.c b/src/rxgen/rpc_main.c index afc812b4f..374fb326b 100644 --- a/src/rxgen/rpc_main.c +++ b/src/rxgen/rpc_main.c @@ -424,8 +424,10 @@ c_output(char *infile, char *define, int extend, char *outfile, int append) } } + f_print(fout, "\n};\n"); } + er_Proc_CodeGeneration(); } if (extend && tell == ftell(fout)) { diff --git a/src/rxgen/rpc_parse.c b/src/rxgen/rpc_parse.c index da0dd329d..a650bdbf2 100644 --- a/src/rxgen/rpc_parse.c +++ b/src/rxgen/rpc_parse.c @@ -931,7 +931,7 @@ generate_code(definition * defp, int proc_split_flag, int multi_flag) if (Sflag || cflag) ss_Proc_CodeGeneration(defp); } - if (Sflag) + if (Sflag || (cflag && xflag && !proc_split_flag)) STOREVAL(&proc_defined[PackageIndex], defp); } @@ -2042,6 +2042,9 @@ er_ProcDeclExterns_setup(void) list *listp; definition *defp; + if ( !Sflag ) + return; + f_print(fout, "\n"); for (listp = proc_defined[PackageIndex]; listp != NULL; listp = listp->next) { @@ -2061,25 +2064,36 @@ er_ProcProcsArray_setup(void) if ((listp = proc_defined[PackageIndex])) { defp = (definition *) listp->val; - if (defp->pc.proc_serverstub) { - f_print(fout, "\nstatic afs_int32 (*StubProcsArray%d[])() = {%s", - PackageIndex, defp->pc.proc_serverstub); - } else { - f_print(fout, - "\nstatic afs_int32 (*StubProcsArray%d[])(struct rx_call *z_call, XDR *z_xdrs) = {_%s%s%s", - PackageIndex, prefix, defp->pc.proc_prefix, - ((definition *) listp->val)->pc.proc_name); - defp = (definition *) listp->val; + if ( cflag ) { + f_print(fout, "\nstatic char *opnames%d[] = {\"%s%s\"", + PackageIndex, defp->pc.proc_prefix, defp->pc.proc_name); + } + else { + if (defp->pc.proc_serverstub) { + f_print(fout, "\nstatic afs_int32 (*StubProcsArray%d[])() = {%s", + PackageIndex, defp->pc.proc_serverstub); + } else { + f_print(fout, + "\nstatic afs_int32 (*StubProcsArray%d[])(struct rx_call *z_call, XDR *z_xdrs) = {_%s%s%s", + PackageIndex, prefix, defp->pc.proc_prefix, + ((definition *) listp->val)->pc.proc_name); + defp = (definition *) listp->val; + } } listp = listp->next; } for (; listp != NULL; listp = listp->next) { defp = (definition *) listp->val; - if (defp->pc.proc_serverstub) { - f_print(fout, ",%s", defp->pc.proc_serverstub); - } else { - f_print(fout, ", _%s%s%s", prefix, defp->pc.proc_prefix, - defp->pc.proc_name); + if ( cflag ) { + f_print(fout, ", \"%s%s\"",defp->pc.proc_prefix,defp->pc.proc_name); + } + else { + if (defp->pc.proc_serverstub) { + f_print(fout, ",%s", defp->pc.proc_serverstub); + } else { + f_print(fout, ", _%s%s%s", prefix, defp->pc.proc_prefix, + defp->pc.proc_name); + } } } f_print(fout, "};\n\n"); @@ -2089,6 +2103,15 @@ er_ProcProcsArray_setup(void) static void er_ProcMainBody_setup(void) { + if ( cflag ) { + f_print(fout, "char *%sTranslateOpCode(int op)\n{\n", + PackagePrefix[PackageIndex]); + f_print(fout, "\tif (op < %sLOWEST_OPCODE || op > %sHIGHEST_OPCODE)\n\t\treturn NULL;\n", + PackagePrefix[PackageIndex], PackagePrefix[PackageIndex]); + f_print(fout, "\treturn opnames%d[op - %sLOWEST_OPCODE];\n}\n", + PackageIndex, PackagePrefix[PackageIndex]); + return; + } f_print(fout, "int %s%sExecuteRequest(struct rx_call *z_call)\n", prefix, PackagePrefix[PackageIndex]); f_print(fout, "{\n\tint op;\n"); @@ -2110,17 +2133,23 @@ er_ProcMainBody_setup(void) static void er_HeadofOldStyleProc_setup(void) { - f_print(fout, - "\nint %s%sExecuteRequest (struct rx_call *z_call)\n", - prefix, + if ( cflag ) { + f_print(fout, "char *%sTranslateOpCode(int op)\n{\n", (combinepackages ? MasterPrefix : PackagePrefix[PackageIndex])); - f_print(fout, "{\n"); - f_print(fout, "\tint op;\n"); - f_print(fout, "\tXDR z_xdrs;\n"); - f_print(fout, "\t" "afs_int32 z_result;\n\n"); - f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n"); - f_print(fout, "\tz_result = RXGEN_DECODE;\n"); - f_print(fout, "\tif (!xdr_int(&z_xdrs, &op)) goto fail;\n"); + } + else { + f_print(fout, + "\nint %s%sExecuteRequest (struct rx_call *z_call)\n", + prefix, + (combinepackages ? MasterPrefix : PackagePrefix[PackageIndex])); + f_print(fout, "{\n"); + f_print(fout, "\tint op;\n"); + f_print(fout, "\tXDR z_xdrs;\n"); + f_print(fout, "\t" "afs_int32 z_result;\n\n"); + f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n"); + f_print(fout, "\tz_result = RXGEN_DECODE;\n"); + f_print(fout, "\tif (!xdr_int(&z_xdrs, &op)) goto fail;\n"); + } f_print(fout, "\tswitch (op) {\n"); } @@ -2148,6 +2177,12 @@ er_BodyofOldStyleProc_setup(void) static void proc_er_case(definition * defp) { + if ( cflag ) { + f_print(fout, "\t\tcase %d:", defp->pc.proc_opcodenum); + f_print(fout, "\treturn \"%s%s\";\n", + defp->pc.proc_prefix, defp->pc.proc_name); + return; + } if (opcodesnotallowed[PackageIndex]) { f_print(fout, "\t\tcase %d:\n", defp->pc.proc_opcodenum); } else { @@ -2168,6 +2203,10 @@ static void er_TailofOldStyleProc_setup(void) { f_print(fout, "\t\tdefault:\n"); + if ( cflag ) { + f_print(fout, "\t\t\treturn NULL;\n\t}\n}\n"); + return; + } f_print(fout, "\t\t\tz_result = RXGEN_OPCODE;\n"); f_print(fout, "\t\t\tbreak;\n\t}\n"); f_print(fout, "fail:\n");