home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples1.exe / smc / macros.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  8.3 KB  |  356 lines

  1. /*****************************************************************************
  2.  *
  3.  *  The following file is pre-preprocessed and fed into the SafeC+ compiler,
  4.  *  since it doesn't support macros with arguments and all that other stuff.
  5.  *  It is included directly as an ordinary source file when the compiler is
  6.  *  built as a C++ program.
  7.  */
  8.  
  9. #include "smcPCH.h"
  10. #pragma hdrstop
  11.  
  12. #ifdef  __PREPROCESS__
  13. #include "macros.h"
  14. #else
  15. #include "genIL.h"
  16. #endif
  17.  
  18. /*****************************************************************************/
  19.  
  20. /*****************************************************************************/
  21.  
  22. #include "tokens.h"
  23. #include "treeops.h"
  24.  
  25. /*****************************************************************************/
  26.  
  27. #ifdef  __UMG__
  28. #include "symsizes.h"
  29. #include "typsizes.h"
  30. #endif
  31.  
  32. /*****************************************************************************/
  33.  
  34. #include "config.h"
  35.  
  36. optionDesc      optionInfo[] =
  37. {
  38.     #define CMDOPT(name, type, phase, defval)                           \
  39.     {                                                                   \
  40.         offsetof(compConfig, cc##name),                                 \
  41.         sizeof(type),                                                   \
  42.         phase,                                                          \
  43.         (int)defval                                                     \
  44.     },
  45.  
  46.     #include "options.h"
  47. };
  48.  
  49. /*****************************************************************************/
  50.  
  51. #ifdef  __SMC__
  52.  
  53. #undef  SMC_ERR
  54. #undef  SMC_WR1
  55. #undef  SMC_WRN
  56. #define SMC_ERR(name, lvl, str)  name,
  57. #define SMC_WR1(name, lvl, str)  name, WRNfirstWarn = name,
  58. #define SMC_WRN(name, lvl, str)  name,
  59. enum    errors
  60. {
  61.     #include "errors.h"
  62.  
  63.     WRNafterWarn
  64. };
  65. #undef  SMC_ERR
  66. #undef  SMC_WR1
  67. #undef  SMC_WRN
  68.  
  69. const
  70. unsigned    WRNcountWarn = WRNafterWarn - WRNfirstWarn + 1;
  71.  
  72. #endif
  73.  
  74. /*****************************************************************************/
  75.  
  76. #undef  SMC_ERR
  77. #define SMC_ERR(name, lvl, str)  str,
  78. #define SMC_WR1(name, lvl, str)  str,
  79. #define SMC_WRN(name, lvl, str)  str,
  80. const   char *          errorTable[] =
  81. {
  82.     #include "errors.h"
  83. };
  84. #undef  SMC_ERR
  85. #undef  SMC_WR1
  86. #undef  SMC_WRN
  87.  
  88. /*****************************************************************************/
  89.  
  90. #undef  SMC_ERR
  91. #define SMC_ERR(name, lvl, str)
  92. #define SMC_WR1(name, lvl, str)  lvl,
  93. #define SMC_WRN(name, lvl, str)  lvl,
  94. BYTE                    warnDefault[] =
  95. {
  96.     #include "errors.h"
  97. };
  98. #undef  SMC_ERR
  99. #undef  SMC_WR1
  100. #undef  SMC_WRN
  101.  
  102. /*****************************************************************************/
  103.  
  104. #include "attrs.h"
  105.  
  106. const char    *     attrNames[] =
  107. {
  108.     #define ATTRDEF(ename, sname) sname,
  109.     #include "attrlist.h"
  110. };
  111.  
  112. /*****************************************************************************/
  113.  
  114. static
  115. unsigned char       optokens[] =
  116. {
  117.     #define TREEOP(en,tk,sn,IL,pr,ok) tk,
  118.     #include "toplist.h"
  119. };
  120.  
  121. tokens              treeOp2token(treeOps oper)
  122. {
  123.     assert(oper < arraylen(optokens));
  124.     assert(optokens[oper] != tkNone);
  125.  
  126.     return (tokens)optokens[oper];
  127. }
  128.  
  129. /*****************************************************************************/
  130.  
  131. #ifdef  DEBUG
  132.  
  133. static
  134. const   char *      treeNodeNames[] =
  135. {
  136.     #define TREEOP(en,tk,sn,IL,pr,ok) sn,
  137.     #include "toplist.h"
  138. };
  139.  
  140. const   char    *   treeNodeName(treeOps op)
  141. {
  142.     assert(op < sizeof(treeNodeNames)/sizeof(treeNodeNames[0]));
  143.  
  144.     return  treeNodeNames[op];
  145. }
  146.  
  147. #endif
  148.  
  149. /*****************************************************************************/
  150.  
  151. const
  152. unsigned char       TreeNode::tnOperKindTable[] =
  153. {
  154.     #define TREEOP(en,tk,sn,IL,pr,ok) ok,
  155.     #include "toplist.h"
  156. };
  157.  
  158. /*****************************************************************************/
  159.  
  160. const
  161. kwdDsc              hashTab::hashKwdDescs[tkKwdCount] =
  162. {
  163.     #define KEYWORD(str, nam, info, prec2, op2, prec1, op1, mod) { op1,op2,prec1,prec2,nam,mod,info },
  164.     #define KWDNOID(str, nam, info, prec2, op2, prec1, op1, mod) { op1,op2,prec1,prec2,nam,mod,info },
  165.     #define KWDFAKE(str, nam, info, prec2, op2, prec1, op1, mod)
  166.     #include "keywords.h"
  167. };
  168.  
  169. const
  170. char *              hashTab::hashKwdNtab[tkKwdCount] =
  171. {
  172.     #define KEYWORD(str, nam, info, prec2, op2, prec1, op1, mod) str,
  173.     #define KWDNOID(str, nam, info, prec2, op2, prec1, op1, mod) str,
  174.     #define KWDFAKE(str, nam, info, prec2, op2, prec1, op1, mod)
  175.     #include "keywords.h"
  176. };
  177.  
  178. /*****************************************************************************/
  179.  
  180. #ifdef  DEBUG
  181.  
  182. const char *        tokenNames[] =
  183. {
  184.     #define KEYWORD(str, nam, info, prec2, op2, prec1, op1, mod) str,
  185.     #include "keywords.h"
  186. };
  187.  
  188. #endif
  189.  
  190. /*****************************************************************************/
  191.  
  192. #ifdef  __SMC__
  193.  
  194. enum    var_types
  195. {
  196.     #define DEF_TP(tn,sz,al,nm,tf) TYP_##tn,
  197.     #include "typelist.h"
  198.     #undef  DEF_TP
  199.  
  200.     TYP_COUNT,
  201.  
  202.     TYP_lastIntrins = TYP_LONGDBL
  203. };
  204.  
  205. #endif
  206.  
  207. /*****************************************************************************/
  208.  
  209. BYTE                symTab::stIntrTypeSizes[] =
  210. {
  211.     #define DEF_TP(tn,sz,al,nm,tf) sz,
  212.     #include "typelist.h"
  213.     #undef  DEF_TP
  214. };
  215.  
  216. BYTE                symTab::stIntrTypeAligns[] =
  217. {
  218.     #define DEF_TP(tn,sz,al,nm,tf) al,
  219.     #include "typelist.h"
  220.     #undef  DEF_TP
  221. };
  222.  
  223. BYTE                varTypeClassification[] =
  224. {
  225.     #define DEF_TP(tn,sz,al,nm,tf) tf,
  226.     #include "typelist.h"
  227.     #undef  DEF_TP
  228. };
  229.  
  230. normString          symTab::stIntrinsicTypeName(var_types vt)
  231. {
  232.     static
  233.     const   char *      typeNames[] =
  234.     {
  235.         #define DEF_TP(tn,sz,al,nm,tf) nm,
  236.         #include "typelist.h"
  237.         #undef  DEF_TP
  238.     };
  239.  
  240.     assert(vt < sizeof(typeNames)/sizeof(typeNames[0]));
  241.  
  242.     return  typeNames[vt];
  243. }
  244.  
  245. /*****************************************************************************/
  246.  
  247. #ifdef  __SMC__
  248.  
  249. enum    ILopcodes
  250. {
  251.     #define OPDEF(name, str, decs, incs, args, optp, stdlen, stdop1, stdop2, flow) name,
  252.     #include "opcode.def"
  253.     #undef  OPDEF
  254.  
  255.     CEE_count,
  256.  
  257.     CEE_UNREACHED,                  // fake value: end of block is unreached
  258. };
  259.  
  260. #endif
  261.  
  262. /*****************************************************************************/
  263.  
  264. ILencoding          ILopcodeCodes[] =
  265. {
  266.     #define OPDEF(name, str, decs, incs, args, optp, stdlen, stdop1, stdop2, flow) { stdop1, stdop2, stdlen },
  267.     #include "opcode.def"
  268.     #undef  OPDEF
  269. };
  270.  
  271. /*****************************************************************************/
  272.  
  273. #define Push0    0
  274. #define Push1    1
  275. #define PushI    1
  276. #define PushI8   1
  277. #define PushR4   1
  278. #define PushR8   1
  279. #define PushRef  1
  280. #define VarPush  0
  281.  
  282. #define Pop0     0
  283. #define Pop1    -1
  284. #define PopI    -1
  285. #define PopI8   -1
  286. #define PopR4   -1
  287. #define PopR8   -1
  288. #define PopRef  -1
  289. #define VarPop   0
  290.  
  291. signed  char        ILopcodeStack[] =
  292. {
  293.     #define OPDEF(name, str, decs, incs, args, optp, stdlen, stdop1, stdop2, flow) ((incs)+(decs)),
  294.     #include "opcode.def"
  295.     #undef  OPDEF
  296. };
  297.  
  298. /*****************************************************************************/
  299.  
  300. #ifdef  DEBUG
  301.  
  302. const char *        opcodeNames[] =
  303. {
  304.     #define OPDEF(nam,str,op,decs,incs,ops,otp, len, op1, op2) str,
  305.     #include "opcode.def"
  306.     #undef  OPDEF
  307. };
  308.  
  309. const char *        opcodeName(unsigned op)
  310. {
  311.     assert(op < sizeof(opcodeNames)/sizeof(*opcodeNames));
  312.  
  313.     return  opcodeNames[op];
  314. }
  315.  
  316. #endif
  317.  
  318. /*****************************************************************************/
  319.  
  320. const   char *      MDnamesStr[] =
  321. {
  322.     #define MD_NAME(ovop, name) name,
  323.     #include "MDnames.h"
  324.     #undef  MD_NAME
  325. };
  326.  
  327. #ifdef  DEBUG
  328.  
  329. const  ovlOpFlavors MDnamesChk[] =
  330. {
  331.     #define MD_NAME(ovop, name) OVOP_##ovop,
  332.     #include "MDnames.h"
  333.     #undef  MD_NAME
  334. };
  335.  
  336. #endif
  337.  
  338. #include "MDstrns.h"
  339.  
  340. ovlOpFlavors        MDfindOvop(const char *name)
  341. {
  342.     unsigned        i;
  343.  
  344.     // This is pretty lame -- is there a better way?
  345.  
  346.     for (i = 0; i < arraylen(MDnamesStr); i++)
  347.     {
  348.         if  (MDnamesStr[i] && !strcmp(name, MDnamesStr[i]))
  349.             return  (ovlOpFlavors)i;
  350.     }
  351.  
  352.     return  OVOP_NONE;
  353. }
  354.  
  355. /*****************************************************************************/
  356.