default.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. #include "decl.h"
  2. #include <system.h>
  3. /* This file contains a number of funtions which will be called to handle
  4. * the 'DEF_C_INSTR' (e.g., C_loe).
  5. */
  6. #define _ICON 0
  7. #define _UCON 4
  8. #define _FCON 8
  9. #define C_DEE 12
  10. #define C_FIL 15
  11. #define C_GTO 18
  12. #define C_INE 21
  13. #define C_LAE 24
  14. #define C_LDE 27
  15. #define C_LOE 30
  16. #define C_SDE 33
  17. #define C_STE 36
  18. #define C_ZRE 39
  19. struct { char *name; int segment, generated; }
  20. def_info[] = {
  21. /* _ICON */ { "C_con_icon", SEGCON, 0},
  22. { "C_rom_icon", SEGROM, 0},
  23. { "C_hol_icon", NOSEG, 0},
  24. { "C_bss_icon", NOSEG, 0},
  25. /* _UCON */ { "C_con_ucon", SEGCON, 0},
  26. { "C_rom_ucon", SEGROM, 0},
  27. { "C_hol_ucon", NOSEG, 0},
  28. { "C_bss_ucon", NOSEG, 0},
  29. /* _FCON */ { "C_con_fcon", SEGCON, 0},
  30. { "C_rom_fcon", SEGROM, 0},
  31. { "C_hol_fcon", NOSEG, 0},
  32. { "C_bss_fcon", NOSEG, 0},
  33. /* C_DEE */ { "C_dee", SEGTXT, 0},
  34. { "C_dee_dnam", SEGTXT, 0},
  35. { "C_dee_dlb", SEGTXT, 0},
  36. /* C_FIL */ { "C_fil", SEGTXT, 0},
  37. { "C_fil_dnam", SEGTXT, 0},
  38. { "C_fil_dlb", SEGTXT, 0},
  39. /* C_GTO */ { "C_gto", SEGTXT, 0},
  40. { "C_gto_dnam", SEGTXT, 0},
  41. { "C_gto_dlb", SEGTXT, 0},
  42. /* C_INE */ { "C_ine", SEGTXT, 0},
  43. { "C_ine_dnam", SEGTXT, 0},
  44. { "C_ine_dlb", SEGTXT, 0},
  45. /* C_LAE */ { "C_lae", SEGTXT, 0},
  46. { "C_lae_dnam", SEGTXT, 0},
  47. { "C_lae_dlb", SEGTXT, 0},
  48. /* C_LDE */ { "C_lde", SEGTXT, 0},
  49. { "C_lde_dnam", SEGTXT, 0},
  50. { "C_lde_dlb", SEGTXT, 0},
  51. /* C_LOE */ { "C_loe", SEGTXT, 0},
  52. { "C_loe_dnam", SEGTXT, 0},
  53. { "C_loe_dlb", SEGTXT, 0},
  54. /* C_SDE */ { "C_sde", SEGTXT, 0},
  55. { "C_sde_dnam", SEGTXT, 0},
  56. { "C_sde_dlb", SEGTXT, 0},
  57. /* C_STE */ { "C_ste", SEGTXT, 0},
  58. { "C_ste_dnam", SEGTXT, 0},
  59. { "C_ste_dlb", SEGTXT, 0},
  60. /* C_ZRE */ { "C_zre", SEGTXT, 0},
  61. { "C_zre_dnam", SEGTXT, 0},
  62. { "C_zre_dlb", SEGTXT, 0}
  63. }; /* This big array contains information about the
  64. * functions that will be generated from the descrip-
  65. * tion of 1 DEF_C_INSTR. It contains the name, the
  66. * segment and a flag of these instructions. The flag
  67. * is used to determine if the instruction is explicitly
  68. * given in the EM_table or not.
  69. */
  70. File *save_file; /* Save original output-file in this variable */
  71. int def_start, /* Index in def_info[], start of the expanded C_INSTR */
  72. def_end, /* last expanded C_INSTR index. */
  73. save_lineno;
  74. extern File *outfile;
  75. extern char yytext[];
  76. extern int yylineno;
  77. init_defaults( instr)
  78. char *instr;
  79. /* Save current output-file and write on a file called ".default" */
  80. {
  81. save_file = outfile;
  82. save_lineno = yylineno;
  83. sys_open( ".default", OP_WRITE, &outfile);
  84. set_def_params( instr);
  85. }
  86. int bss_or_hol_instr( index)
  87. int index;
  88. {
  89. return ( index == _ICON + 2 || index == _ICON + 3 ||
  90. index == _UCON + 2 || index == _UCON + 3 ||
  91. index == _FCON + 2 || index == _FCON + 3);
  92. }
  93. set_def_params( instr)
  94. char *instr;
  95. /* Give 'def_start' and 'def_end' their correct values. */
  96. {
  97. int low, high, mid, rel;
  98. if ( *instr == '.') { /* ..icon | ..ucon | ..fcon */
  99. switch ( *(instr+2)) {
  100. case 'i' : def_start = _ICON;
  101. break;
  102. case 'u' : def_start = _UCON;
  103. break;
  104. case 'f' : def_start = _FCON;
  105. break;
  106. }
  107. def_end = def_start + 3;
  108. }
  109. else {
  110. low = C_DEE;
  111. high = C_ZRE;
  112. while ( TRUE) {
  113. mid = ( low + high) / 6 * 3;
  114. rel = strncmp( instr, def_info[mid].name, 5);
  115. if ( rel == 0 )
  116. break;
  117. else if ( high == low)
  118. abort();
  119. else if ( rel < 0)
  120. high = mid;
  121. else
  122. /* be careful : 'mid' is truncated */
  123. low = ( mid == low ? low + 3: mid);
  124. }
  125. def_start = mid;
  126. def_end = def_start + 2;
  127. }
  128. }
  129. #include <stdio.h>
  130. #include "Lpars.h"
  131. handle_defaults()
  132. /* Switch back to original output-file and start generating the functions
  133. * from the file ".default".
  134. */
  135. {
  136. FILE *old, *tmp, *switch_input();
  137. int i, old_yylineno;
  138. extern int CD_pos;
  139. sys_close( outfile);
  140. outfile = save_file;
  141. tmp = fopen( ".default", "r");
  142. old = switch_input( tmp);
  143. old_yylineno = yylineno;
  144. for ( i = def_start; i <= def_end; i++) {
  145. yylineno = save_lineno;
  146. if ( !def_info[i].generated) {
  147. set_C_instr_info( def_info[i].name);
  148. segment = def_info[i].segment;
  149. set_outfile( def_info[i].name);
  150. header( def_info[i].name);
  151. CD_pos = TRUE; /* Set mylex() in correct state */
  152. if ( bss_or_hol_instr( i)) {
  153. extnd_header();
  154. /* Rest of body is just the same as the corres-
  155. * ponding C_con_xxx C_rom_xxx instruction
  156. * so set correct info.
  157. */
  158. set_C_instr_info( def_info[(i>>2)<<2].name);
  159. segment = UNKNOWN;
  160. /* to prevent another dump_label+switchseg */
  161. def_row();
  162. out( "}}\n\n");
  163. }
  164. else
  165. def_row();
  166. rewind( tmp);
  167. }
  168. }
  169. fclose( tmp);
  170. switch_input( old);
  171. yylineno = old_yylineno;
  172. }
  173. def_admn( instr)
  174. char *instr;
  175. /* Mark this 'instr' as being generated */
  176. {
  177. int low, high, mid, rel;
  178. low = _ICON;
  179. high = C_ZRE + 2;
  180. while ( TRUE) {
  181. mid = ( low + high) / 2;
  182. rel = strcmp( instr, def_info[mid].name);
  183. if ( rel == 0 )
  184. break;
  185. else if ( high == low)
  186. return;
  187. else if ( rel < 0)
  188. high = mid;
  189. else
  190. low = ( mid == low ? low + 1: mid);
  191. }
  192. def_info[mid].generated = 1;
  193. }
  194. extnd_header()
  195. /* Generates code for loooking at the parameters 'nbytes' and 'i' of the
  196. * bss an hol pseudo-instructions.
  197. */
  198. {
  199. out( "if ( %s == 0 ) {\n", C_instr_info->arg_id[3]);
  200. out( "common( %s);\n", C_instr_info->arg_id[0]);
  201. out( "}\nelse {\n");
  202. set_segment( SEGCON);
  203. out( "for ( %s = 0; %s < %s/EM_WSIZE; %s++) {\n",
  204. C_instr_info->arg_id[3], C_instr_info->arg_id[3],
  205. C_instr_info->arg_id[0], C_instr_info->arg_id[3]);
  206. }