]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
rxgen: add *TranslateOpcode functions to XDR code
authorFelix Frank <Felix.Frank@Alumni.TU-Berlin.de>
Fri, 12 Nov 2010 23:10:31 +0000 (00:10 +0100)
committerDerrick Brashear <shadow@dementix.org>
Thu, 15 Dec 2011 04:17:59 +0000 (20:17 -0800)
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.

Reviewed-on: http://gerrit.openafs.org/3305
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
(cherry picked from commit 5c77a6ca2460c3e79125a614037824db35480905)

Change-Id: I23d7af2dd07e02255783de0523fce58dbe46d31e
Reviewed-on: http://gerrit.openafs.org/6267
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>
src/rxgen/rpc_main.c
src/rxgen/rpc_parse.c

index 20a147e7741d43f754b7dd8ffbfb524e4072a359..d6236d39e2efcad25149451b7383c924a28450f1 100644 (file)
@@ -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)) {
index a75b111a479e8d1fc835f1ce15f74a73af141dfa..a88a069a97e36c35f8fc07f2dfbdf1469742a8d5 100644 (file)
@@ -921,7 +921,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);
 }
 
@@ -2031,6 +2031,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) {
@@ -2050,25 +2053,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");
@@ -2078,6 +2092,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");
@@ -2099,17 +2122,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");
 }
 
@@ -2137,6 +2166,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 {
@@ -2157,6 +2192,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");