comwrite.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*****************************************************************************
  2. * File: comwrite.c
  3. * Purpose: writes comments about C programs and descriptions about dos
  4. * interrupts in the string line given.
  5. * Project: dcc
  6. * (C) Cristina Cifuentes
  7. ****************************************************************************/
  8. #include "dcc.h"
  9. #include <string.h>
  10. #include <sstream>
  11. using namespace std;
  12. #define intSize 40
  13. static const char *int21h[] =
  14. {
  15. "Terminate process",
  16. "Character input with echo",
  17. "Character output",
  18. "Auxiliary input",
  19. "Auxiliary output",
  20. "Printer output",
  21. "Direct console i/o",
  22. "Unfiltered char i w/o echo",
  23. "Character input without echo",
  24. "Display string",
  25. "Buffered keyboard input",
  26. "Check input status",
  27. "Flush input buffer and then input",
  28. "Disk reset",
  29. "Select disk",
  30. "Open file",
  31. "Close file",
  32. "Find first file",
  33. "Find next file",
  34. "Delete file",
  35. "Sequential read",
  36. "Sequential write",
  37. "Create file",
  38. "Rename file",
  39. "Reserved",
  40. "Get current disk",
  41. "Set DTA address",
  42. "Get default drive data",
  43. "Get drive data",
  44. "Reserved",
  45. "Reserved",
  46. "Reserved",
  47. "Reserved",
  48. "Random read",
  49. "Random write",
  50. "Get file size",
  51. "Set relative record number",
  52. "Set interrupt vector",
  53. "Create new PSP",
  54. "Random block read",
  55. "Random block write",
  56. "Parse filename",
  57. "Get date",
  58. "Set date",
  59. "Get time",
  60. "Set time",
  61. "Set verify flag",
  62. "Get DTA address",
  63. "Get MSDOS version number",
  64. "Terminate and stay resident",
  65. "Reserved",
  66. "Get or set break flag",
  67. "Reserved",
  68. "Get interrupt vector",
  69. "Get drive allocation info",
  70. "Reserved",
  71. "Get or set country info",
  72. "Create directory",
  73. "Delete directory",
  74. "Set current directory",
  75. "Create file",
  76. "Open file",
  77. "Close file",
  78. "Read file or device",
  79. "Write file or device",
  80. "Delete file",
  81. "Set file pointer",
  82. "Get or set file attributes",
  83. "IOCTL (i/o control)",
  84. "Duplicate handle",
  85. "Redirect handle",
  86. "Get current directory",
  87. "Alloate memory block",
  88. "Release memory block",
  89. "Resize memory block",
  90. "Execute program (exec)",
  91. "Terminate process with return code",
  92. "Get return code",
  93. "Find first file",
  94. "Find next file",
  95. "Reserved",
  96. "Reserved",
  97. "Reserved",
  98. "Reserved",
  99. "Get verify flag",
  100. "Reserved",
  101. "Rename file",
  102. "Get or set file date & time",
  103. "Get or set allocation strategy",
  104. "Get extended error information",
  105. "Create temporary file",
  106. "Create new file",
  107. "Lock or unlock file region",
  108. "Reserved",
  109. "Get machine name",
  110. "Device redirection",
  111. "Reserved",
  112. "Reserved",
  113. "Get PSP address",
  114. "Get DBCS lead byte table",
  115. "Reserved",
  116. "Get extended country information",
  117. "Get or set code page",
  118. "Set handle count",
  119. "Commit file",
  120. "Reserved",
  121. "Reserved",
  122. "Reserved",
  123. "Extended open file"
  124. };
  125. static const char *intOthers[] = {
  126. "Exit", /* 0x20 */
  127. "", /* other table */
  128. "Terminate handler address", /* 0x22 */
  129. "Ctrl-C handler address", /* 0x23 */
  130. "Critical-error handler address", /* 0x24 */
  131. "Absolute disk read", /* 0x25 */
  132. "Absolute disk write", /* 0x26 */
  133. "Terminate and stay resident", /* 0x27 */
  134. "Reserved", /* 0x28 */
  135. "Reserved", /* 0x29 */
  136. "Reserved", /* 0x2A */
  137. "Reserved", /* 0x2B */
  138. "Reserved", /* 0x2C */
  139. "Reserved", /* 0x2D */
  140. "Reserved" /* 0x2E */
  141. };
  142. /* Writes the description of the current interrupt. Appends it to the
  143. * string s. */
  144. void ICODE::writeIntComment (std::ostringstream &s)
  145. {
  146. s<<"\t/* ";
  147. if (ic.ll.src.op() == 0x21)
  148. {
  149. s <<int21h[ic.ll.dst.off];
  150. }
  151. else if (ic.ll.src.op() > 0x1F && ic.ll.src.op() < 0x2F)
  152. {
  153. s <<intOthers[ic.ll.src.op() - 0x20];
  154. }
  155. else if (ic.ll.src.op() == 0x2F)
  156. {
  157. switch (ic.ll.dst.off)
  158. {
  159. case 0x01 :
  160. s << "Print spooler";
  161. break;
  162. case 0x02:
  163. s << "Assign";
  164. break;
  165. case 0x10:
  166. s << "Share";
  167. break;
  168. case 0xB7:
  169. s << "Append";
  170. }
  171. }
  172. else
  173. s<<"Unknown int";
  174. s<<" */\n";
  175. }
  176. //, &cCode.decl
  177. void Function::writeProcComments()
  178. {
  179. int i;
  180. ID *id; /* Pointer to register argument identifier */
  181. STKSYM * psym; /* Pointer to register argument symbol */
  182. /* About the parameters */
  183. if (this->cbParam)
  184. cCode.appendDecl("/* Takes %d bytes of parameters.\n",this->cbParam);
  185. else if (this->flg & REG_ARGS)
  186. {
  187. cCode.appendDecl("/* Uses register arguments:\n");
  188. for (i = 0; i < this->args.numArgs; i++)
  189. {
  190. psym = &this->args.sym[i];
  191. if (psym->regs->expr.ident.idType == REGISTER)
  192. {
  193. id = &this->localId.id_arr[psym->regs->expr.ident.idNode.regiIdx];
  194. if (psym->regs->expr.ident.regiType == WORD_REG)
  195. cCode.appendDecl(" * %s = %s.\n", psym->name,
  196. wordReg[id->id.regi - rAX]);
  197. else /* BYTE_REG */
  198. cCode.appendDecl(" * %s = %s.\n", psym->name,
  199. byteReg[id->id.regi - rAL]);
  200. }
  201. else /* long register */
  202. {
  203. id = &this->localId.id_arr[psym->regs->expr.ident.idNode.longIdx];
  204. cCode.appendDecl(" * %s = %s:%s.\n", psym->name,
  205. wordReg[id->id.longId.h - rAX],
  206. wordReg[id->id.longId.l - rAX]);
  207. }
  208. }
  209. }
  210. else
  211. cCode.appendDecl("/* Takes no parameters.\n");
  212. /* Type of procedure */
  213. if (this->flg & PROC_RUNTIME)
  214. cCode.appendDecl(" * Runtime support routine of the compiler.\n");
  215. if (this->flg & PROC_IS_HLL)
  216. cCode.appendDecl(" * High-level language prologue code.\n");
  217. if (this->flg & PROC_ASM)
  218. {
  219. cCode.appendDecl(" * Untranslatable routine. Assembler provided.\n");
  220. if (this->flg & PROC_IS_FUNC)
  221. switch (this->retVal.type) {
  222. case TYPE_BYTE_SIGN: case TYPE_BYTE_UNSIGN:
  223. cCode.appendDecl(" * Return value in register al.\n");
  224. break;
  225. case TYPE_WORD_SIGN: case TYPE_WORD_UNSIGN:
  226. cCode.appendDecl(" * Return value in register ax.\n");
  227. break;
  228. case TYPE_LONG_SIGN: case TYPE_LONG_UNSIGN:
  229. cCode.appendDecl(" * Return value in registers dx:ax.\n");
  230. break;
  231. } /* eos */
  232. }
  233. /* Calling convention */
  234. if (this->flg & CALL_PASCAL)
  235. cCode.appendDecl(" * Pascal calling convention.\n");
  236. else if (this->flg & CALL_C)
  237. cCode.appendDecl(" * C calling convention.\n");
  238. else if (this->flg & CALL_UNKNOWN)
  239. cCode.appendDecl(" * Unknown calling convention.\n");
  240. /* Other flags */
  241. if (this->flg & (PROC_BADINST | PROC_IJMP))
  242. cCode.appendDecl(" * Incomplete due to an %s.\n",
  243. (this->flg & PROC_BADINST)? "untranslated opcode":
  244. "indirect JMP");
  245. if (this->flg & PROC_ICALL)
  246. cCode.appendDecl(" * Indirect call procedure.\n");
  247. if (this->flg & IMPURE)
  248. cCode.appendDecl(" * Contains impure code.\n");
  249. if (this->flg & NOT_HLL)
  250. cCode.appendDecl(" * Contains instructions not normally used by compilers.\n");
  251. if (this->flg & FLOAT_OP)
  252. cCode.appendDecl(" * Contains coprocessor instructions.\n");
  253. /* Graph reducibility */
  254. if (this->flg & GRAPH_IRRED)
  255. cCode.appendDecl(" * Irreducible control flow graph.\n");
  256. cCode.appendDecl(" */\n{\n");
  257. }