00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <stdlib.h>
00013
00014 #include "asl.h"
00015 #include "opcode.hd"
00016 #include "nlp.h"
00017 #include "r_opn.hd"
00018
00019
00020
00021 typedef struct {
00022 efunc *fp;
00023 int op;
00024 } AslCouPair;
00025
00026
00027
00028
00029
00030
00031 static int pair_compare (const void *p1, const void *p2) {
00032
00033
00034
00035 register size_t f1 = Intcast (((AslCouPair *) p1) -> fp);
00036 register size_t f2 = Intcast (((AslCouPair *) p2) -> fp);
00037
00038 if (f1 < f2) return -1;
00039 else if (f1 > f2) return 1;
00040 else return 0;
00041 }
00042
00043
00044
00045
00046 AslCouPair opmap [N_OPS];
00047
00048
00049
00050
00051 size_t getOperator (efunc *f) {
00052
00053 static char first_call = 1;
00054 AslCouPair key, *res;
00055
00056
00057
00058 if ((Intcast f < N_OPS) &&
00059 (Intcast f > -N_OPS))
00060 return Intcast f;
00061
00062 key.fp = f;
00063
00064 if (first_call) {
00065
00066 register int i=0;
00067 register AslCouPair *ops = opmap;
00068
00069
00070 while (i<N_OPS) {
00071 ops -> fp = r_ops [ops -> op = i++];
00072 ops++;
00073 }
00074
00075
00076 qsort (opmap, N_OPS, sizeof (AslCouPair), pair_compare);
00077 first_call = 0;
00078 }
00079
00080
00081 res = (AslCouPair *) bsearch (&key, opmap, N_OPS, sizeof (AslCouPair), pair_compare);
00082
00083 if (!res)
00084 return -1;
00085
00086 return res -> op;
00087 }