ops.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #include "c.h"
  2. /* ops [ {csilhfdxp}=n ]...
  3. * prints lcc dag operator set for a given set of type sizes.
  4. */
  5. static char list[] = { 'c', 's', 'i', 'l', 'h', 'f', 'd', 'x', 'p', 0 };
  6. static int sizes[] = { 1, 2, 4, 4, 8, 4, 8, 16, 8 };
  7. static int doop(int op, int type, const char *sz, const char *opname) {
  8. int count = 0;
  9. static int last;
  10. if (op == LOAD)
  11. return 0;
  12. if (last != 0 && last != op)
  13. printf("\n");
  14. last = op;
  15. if (type == B || type == V) {
  16. printf(" %s=%d", opname, op + type);
  17. count++;
  18. } else {
  19. int i, done = 0;
  20. const char *s;
  21. for (i = 0; sz[i] != '\0' && (s = strchr(list, sz[i])) != NULL; i++) {
  22. int n = sizes[s-list];
  23. if ((done&(1<<n)) == 0) {
  24. printf(" %s%d=%d", opname, n, op + type + sizeop(n));
  25. count++;
  26. }
  27. done |= 1<<n;
  28. }
  29. }
  30. printf("\n");
  31. return count;
  32. }
  33. int main(int argc, char *argv[]) {
  34. int i, count = 0;
  35. for (i = 1; i < argc; i++) {
  36. char c, *s;
  37. int n;
  38. if (sscanf(argv[i], "%c=%d", &c, &n) == 2
  39. && n > 0 && (s = strchr(list, c)) != NULL)
  40. sizes[s-list] = n;
  41. else {
  42. fprintf(stderr, "usage: %s [ {csilhfdxp}=n ]...\n", argv[0]);
  43. exit(EXIT_FAILURE);
  44. }
  45. }
  46. #define gop(x,n)
  47. #define op(x,t,s) count += doop(x,t,#s,#x #t);
  48. gop(CNST,1)
  49. op(CNST,F,fdx)
  50. op(CNST,I,csilh)
  51. op(CNST,P,p)
  52. op(CNST,U,csilh)
  53. gop(ARG,2)
  54. op(ARG,B,-)
  55. op(ARG,F,fdx)
  56. op(ARG,I,ilh)
  57. op(ARG,P,p)
  58. op(ARG,U,ilh)
  59. gop(ASGN,3)
  60. op(ASGN,B,-)
  61. op(ASGN,F,fdx)
  62. op(ASGN,I,csilh)
  63. op(ASGN,P,p)
  64. op(ASGN,U,csilh)
  65. gop(INDIR,4)
  66. op(INDIR,B,-)
  67. op(INDIR,F,fdx)
  68. op(INDIR,I,csilh)
  69. op(INDIR,P,p)
  70. op(INDIR,U,csilh)
  71. gop(CVF,7)
  72. op(CVF,F,fdx)
  73. op(CVF,I,ilh)
  74. gop(CVI,8)
  75. op(CVI,F,fdx)
  76. op(CVI,I,csilh)
  77. op(CVI,U,csilhp)
  78. gop(CVP,9)
  79. op(CVP,U,p)
  80. gop(CVU,11)
  81. op(CVU,I,csilh)
  82. op(CVU,P,p)
  83. op(CVU,U,csilh)
  84. gop(NEG,12)
  85. op(NEG,F,fdx)
  86. op(NEG,I,ilh)
  87. gop(CALL,13)
  88. op(CALL,B,-)
  89. op(CALL,F,fdx)
  90. op(CALL,I,ilh)
  91. op(CALL,P,p)
  92. op(CALL,U,ilh)
  93. op(CALL,V,-)
  94. gop(RET,15)
  95. op(RET,F,fdx)
  96. op(RET,I,ilh)
  97. op(RET,P,p)
  98. op(RET,U,ilh)
  99. op(RET,V,-)
  100. gop(ADDRG,16)
  101. op(ADDRG,P,p)
  102. gop(ADDRF,17)
  103. op(ADDRF,P,p)
  104. gop(ADDRL,18)
  105. op(ADDRL,P,p)
  106. gop(ADD,19)
  107. op(ADD,F,fdx)
  108. op(ADD,I,ilh)
  109. op(ADD,P,p)
  110. op(ADD,U,ilhp)
  111. gop(SUB,20)
  112. op(SUB,F,fdx)
  113. op(SUB,I,ilh)
  114. op(SUB,P,p)
  115. op(SUB,U,ilhp)
  116. gop(LSH,21)
  117. op(LSH,I,ilh)
  118. op(LSH,U,ilh)
  119. gop(MOD,22)
  120. op(MOD,I,ilh)
  121. op(MOD,U,ilh)
  122. gop(RSH,23)
  123. op(RSH,I,ilh)
  124. op(RSH,U,ilh)
  125. gop(BAND,24)
  126. op(BAND,I,ilh)
  127. op(BAND,U,ilh)
  128. gop(BCOM,25)
  129. op(BCOM,I,ilh)
  130. op(BCOM,U,ilh)
  131. gop(BOR,26)
  132. op(BOR,I,ilh)
  133. op(BOR,U,ilh)
  134. gop(BXOR,27)
  135. op(BXOR,I,ilh)
  136. op(BXOR,U,ilh)
  137. gop(DIV,28)
  138. op(DIV,F,fdx)
  139. op(DIV,I,ilh)
  140. op(DIV,U,ilh)
  141. gop(MUL,29)
  142. op(MUL,F,fdx)
  143. op(MUL,I,ilh)
  144. op(MUL,U,ilh)
  145. gop(EQ,30)
  146. op(EQ,F,fdx)
  147. op(EQ,I,ilh)
  148. op(EQ,U,ilhp)
  149. gop(GE,31)
  150. op(GE,F,fdx)
  151. op(GE,I,ilh)
  152. op(GE,U,ilhp)
  153. gop(GT,32)
  154. op(GT,F,fdx)
  155. op(GT,I,ilh)
  156. op(GT,U,ilhp)
  157. gop(LE,33)
  158. op(LE,F,fdx)
  159. op(LE,I,ilh)
  160. op(LE,U,ilhp)
  161. gop(LT,34)
  162. op(LT,F,fdx)
  163. op(LT,I,ilh)
  164. op(LT,U,ilhp)
  165. gop(NE,35)
  166. op(NE,F,fdx)
  167. op(NE,I,ilh)
  168. op(NE,U,ilhp)
  169. gop(JUMP,36)
  170. op(JUMP,V,-)
  171. gop(LABEL,37)
  172. op(LABEL,V,-)
  173. gop(LOAD,14)
  174. op(LOAD,B,-)
  175. op(LOAD,F,fdx)
  176. op(LOAD,I,csilh)
  177. op(LOAD,P,p)
  178. op(LOAD,U,csilhp)
  179. #undef gop
  180. #undef op
  181. fprintf(stderr, "%d operators\n", count);
  182. return EXIT_SUCCESS;
  183. }