PulkoMandy | 17fc759 | 2022-07-28 18:27:54 +0200 | [diff] [blame] | 1 | /* Example of a code-generator for an Intel 386 or higher. */ |
| 2 | |
| 3 | #include "dt.h" |
| 4 | |
| 5 | /* We have extended types! What we have to do to support them: */ |
| 6 | /* - #define HAVE_EXT_TYPES |
| 7 | - #undef all standard types |
| 8 | - #define all standard types plus new types |
| 9 | - write eval_const and insert_const |
| 10 | - write typedefs for zmax and zumax |
| 11 | - write typname[] |
| 12 | - write conv_typ() |
| 13 | - optionally #define ISPOINTER, ISARITH, ISINT etc. |
| 14 | - optionally #define HAVE_TGT_PRINTVAL and write printval |
| 15 | - optionally #define POINTER_TYPE |
| 16 | - optionally #define HAVE_TGT_FALIGN and write falign |
| 17 | - optionally #define HAVE_TGT_SZOF and write szof |
| 18 | - optionally add functions for attribute-handling |
| 19 | */ |
| 20 | #define HAVE_EXT_TYPES 1 |
| 21 | |
| 22 | #define HAVE_TGT_PRINTVAL |
| 23 | |
| 24 | #undef CHAR |
| 25 | #undef SHORT |
| 26 | #undef INT |
| 27 | #undef LONG |
| 28 | #undef LLONG |
| 29 | #undef FLOAT |
| 30 | #undef DOUBLE |
| 31 | #undef LDOUBLE |
| 32 | #undef VOID |
| 33 | #undef POINTER |
| 34 | #undef ARRAY |
| 35 | #undef STRUCT |
| 36 | #undef UNION |
| 37 | #undef ENUM |
| 38 | #undef FUNKT |
| 39 | #undef MAXINT |
| 40 | #undef MAX_TYPE |
| 41 | |
| 42 | #define CHAR 1 |
| 43 | #define SHORT 2 |
| 44 | #define BSHORT 3 |
| 45 | #define INT 4 |
| 46 | #define BINT 5 |
| 47 | #define LONG 6 |
| 48 | #define BLONG 7 |
| 49 | #define LLONG 8 |
| 50 | #define BLLONG 9 |
| 51 | #define FLOAT 10 |
| 52 | #define BFLOAT 11 |
| 53 | #define DOUBLE 12 |
| 54 | #define BDOUBLE 13 |
| 55 | #define LDOUBLE 14 |
| 56 | #define BLDOUBLE 15 |
| 57 | #define VOID 16 |
| 58 | #define POINTER 17 |
| 59 | #define BPOINTER 18 |
| 60 | #define ARRAY 19 |
| 61 | #define STRUCT 20 |
| 62 | #define UNION 21 |
| 63 | #define ENUM 22 |
| 64 | #define FUNKT 23 |
| 65 | |
| 66 | #define MAXINT 24 /* should not be accesible to application */ |
| 67 | |
| 68 | #define MAX_TYPE MAXINT |
| 69 | |
| 70 | #define ISPOINTER(x) ((x&NQ)==POINTER||(x&NQ)==BPOINTER) |
| 71 | #define ISSCALAR(x) ((x&NQ)>=CHAR&&(x&NQ)<=BPOINTER) |
| 72 | #define ISINT(x) ((x&NQ)>=CHAR&&(x&NQ)<=BLLONG) |
| 73 | |
| 74 | typedef zllong zmax; |
| 75 | typedef zullong zumax; |
| 76 | |
| 77 | union atyps{ |
| 78 | zchar vchar; |
| 79 | zuchar vuchar; |
| 80 | zshort vshort; |
| 81 | zushort vushort; |
| 82 | zint vint; |
| 83 | zuint vuint; |
| 84 | zlong vlong; |
| 85 | zulong vulong; |
| 86 | zllong vllong; |
| 87 | zullong vullong; |
| 88 | zmax vmax; |
| 89 | zumax vumax; |
| 90 | zfloat vfloat; |
| 91 | zdouble vdouble; |
| 92 | zldouble vldouble; |
| 93 | }; |
| 94 | |
| 95 | /* This struct can be used to implement machine-specific */ |
| 96 | /* addressing-modes. */ |
| 97 | /* Not used in this code-generrator. */ |
| 98 | struct AddressingMode{ |
| 99 | int mode; |
| 100 | int base; |
| 101 | int idx; |
| 102 | int scal; |
| 103 | zmax offset; |
| 104 | struct Var *v; |
| 105 | }; |
| 106 | |
| 107 | /* The number of registers of the target machine. */ |
| 108 | #define MAXR 18 |
| 109 | |
| 110 | /* Number of commandline-options the code-generator accepts. */ |
| 111 | #define MAXGF 10 |
| 112 | |
| 113 | /* If this is set to zero vbcc will not generate ICs where the */ |
| 114 | /* target operand is the same as the 2nd source operand. */ |
| 115 | /* This can sometimes simplify the code-generator, but usually */ |
| 116 | /* the code is better if the code-generator allows it. */ |
| 117 | #define USEQ2ASZ 1 |
| 118 | |
| 119 | /* This specifies the smallest integer type that can be added to a */ |
| 120 | /* pointer. */ |
| 121 | #define MINADDI2P INT |
| 122 | #define MAXADDI2P LONG |
| 123 | |
| 124 | /* If the bytes of an integer are ordered most significant byte */ |
| 125 | /* byte first and then decreasing set BIGENDIAN to 1. */ |
| 126 | #define BIGENDIAN 0 |
| 127 | |
| 128 | /* If the bytes of an integer are ordered lest significant byte */ |
| 129 | /* byte first and then increasing set LITTLEENDIAN to 1. */ |
| 130 | #define LITTLEENDIAN 1 |
| 131 | |
| 132 | /* Note that BIGENDIAN and LITTLEENDIAN are mutually exclusive. */ |
| 133 | |
| 134 | /* If switch-statements should be generated as a sequence of */ |
| 135 | /* SUB,TST,BEQ ICs rather than COMPARE,BEQ ICs set this to 1. */ |
| 136 | /* This can yield better code on some machines. */ |
| 137 | #define SWITCHSUBS 0 |
| 138 | |
| 139 | /* In optimizing compilation certain library memcpy/strcpy-calls */ |
| 140 | /* with length known at compile-time will be inlined using an */ |
| 141 | /* ASSIGN-IC if the size is less or equal to INLINEMEMCPY. */ |
| 142 | /* The type used for the ASSIGN-IC will be UNSIGNED|CHAR. */ |
| 143 | #define INLINEMEMCPY 1024 |
| 144 | |
| 145 | /* We keep track of all registers modified by a function. */ |
| 146 | #define HAVE_REGS_MODIFIED 1 |
| 147 | |
| 148 | /* size of buffer for asm-output */ |
| 149 | #define EMIT_BUF_LEN 1024 /* should be enough */ |
| 150 | /* number of asm-output lines buffered */ |
| 151 | #define EMIT_BUF_DEPTH 4 |
| 152 | |
| 153 | /* We have no asm_peephole to optimize assembly-output */ |
| 154 | #define HAVE_TARGET_PEEPHOLE 0 |
| 155 | |
| 156 | #define JUMP_TABLE_DENSITY 0.8 |
| 157 | #define JUMP_TABLE_LENGTH 4 |
| 158 | |
| 159 | /* We use builtin libcalls for some operations */ |
| 160 | #define HAVE_LIBCALLS 1 |
| 161 | |
| 162 | /* support for variable-length arrays */ |
| 163 | #define ALLOCVLA_REG 1 |
| 164 | #define ALLOCVLA_INLINEASM "\tsubl\t%eax,%esp\n\tandl\t$-5,%esp\n\tmovl\t%esp,%eax" |
| 165 | /* TODO: find a better solution some time */ |
| 166 | #define FREEVLA_REG 0 |
| 167 | #define FREEVLA_INLINEASM "\tmovl\t(%esp),%esp\n\tsubl\t$4,%esp" |
| 168 | #define OLDSPVLA_INLINEASM "\tmovl\t%esp,%eax" |
| 169 | #define FPVLA_REG 7 |
| 170 | |
| 171 | /* do not create CONVERT_ICs from floats to unsigned integers */ |
| 172 | #define AVOID_FLOAT_TO_UNSIGNED 1 |
| 173 | |
| 174 | /* do not create CONVERT_ICs from unsigned integers to floats */ |
| 175 | #define AVOID_UNSIGNED_TO_FLOAT 1 |
| 176 | |