Print this page
new smatch

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/compile-i386.c
          +++ new/usr/src/tools/smatch/src/compile-i386.c
↓ open down ↓ 185 lines elided ↑ open up ↑
 186  186  };
 187  187  
 188  188  
 189  189  static struct function *current_func = NULL;
 190  190  static struct textbuf *unit_post_text = NULL;
 191  191  static const char *current_section;
 192  192  
 193  193  static void emit_comment(const char * fmt, ...) FORMAT_ATTR(1);
 194  194  static void emit_move(struct storage *src, struct storage *dest,
 195  195                        struct symbol *ctype, const char *comment);
 196      -static int type_is_signed(struct symbol *sym);
 197  196  static struct storage *x86_address_gen(struct expression *expr);
 198  197  static struct storage *x86_symbol_expr(struct symbol *sym);
 199  198  static void x86_symbol(struct symbol *sym);
 200  199  static struct storage *x86_statement(struct statement *stmt);
 201  200  static struct storage *x86_expression(struct expression *expr);
 202  201  
 203  202  enum registers {
 204  203          NOREG,
 205  204           AL,  DL,  CL,  BL,  AH,  DH,  CH,  BH, // 8-bit
 206  205           AX,  DX,  CX,  BX,  SI,  DI,  BP,  SP, // 16-bit
↓ open down ↓ 238 lines elided ↑ open up ↑
 445  444          case STOR_ARG:
 446  445                  strcpy(name, pretty_offset((int) arg_offset(s)));
 447  446                  break;
 448  447          case STOR_SYM:
 449  448                  strcpy(name, show_ident(s->sym->ident));
 450  449                  break;
 451  450          case STOR_REG:
 452  451                  strcpy(name, s->reg->name);
 453  452                  break;
 454  453          case STOR_VALUE:
 455      -                sprintf(name, "$%Ld", s->value);
      454 +                sprintf(name, "$%lld", s->value);
 456  455                  break;
 457  456          case STOR_LABEL:
 458  457                  sprintf(name, "%s.L%d", s->flags & STOR_LABEL_VAL ? "$" : "",
 459  458                          s->label);
 460  459                  break;
 461  460          case STOR_LABELSYM:
 462  461                  sprintf(name, "%s.LS%p", s->flags & STOR_LABEL_VAL ? "$" : "",
 463  462                          s->labelsym);
 464  463                  break;
 465  464          }
↓ open down ↓ 464 lines elided ↑ open up ↑
 930  929          switch (bit_size) {
 931  930          case 8:         type = "byte";  ll = (char) ll; break;
 932  931          case 16:        type = "value"; ll = (short) ll; break;
 933  932          case 32:        type = "long";  ll = (int) ll; break;
 934  933          case 64:        type = "quad";  break;
 935  934          default:        type = NULL;    break;
 936  935          }
 937  936  
 938  937          assert(type != NULL);
 939  938  
 940      -        printf("\t.%s\t%Ld\n", type, ll);
      939 +        printf("\t.%s\t%lld\n", type, ll);
 941  940  }
 942  941  
 943  942  static void emit_global_noinit(const char *name, unsigned long modifiers,
 944  943                                 unsigned long alignment, unsigned int byte_size)
 945  944  {
 946  945          char s[64];
 947  946  
 948  947          if (modifiers & MOD_STATIC) {
 949  948                  sprintf(s, "\t.local\t%s\n", name);
 950  949                  textbuf_push(&unit_post_text, s);
↓ open down ↓ 205 lines elided ↑ open up ↑
1156 1155  static void emit_move(struct storage *src, struct storage *dest,
1157 1156                        struct symbol *ctype, const char *comment)
1158 1157  {
1159 1158          unsigned int bits;
1160 1159          unsigned int is_signed;
1161 1160          unsigned int is_dest = (src->type == STOR_REG);
1162 1161          const char *opname;
1163 1162  
1164 1163          if (ctype) {
1165 1164                  bits = ctype->bit_size;
1166      -                is_signed = type_is_signed(ctype);
     1165 +                is_signed = is_signed_type(ctype);
1167 1166          } else {
1168 1167                  bits = 32;
1169 1168                  is_signed = 0;
1170 1169          }
1171 1170  
1172 1171          /*
1173 1172           * Are we moving from a register to a register?
1174 1173           * Make the new reg to be the "cache".
1175 1174           */
1176 1175          if ((dest->type == STOR_REG) && (src->type == STOR_REG)) {
↓ open down ↓ 171 lines elided ↑ open up ↑
1348 1347          struct storage *dest, *src;
1349 1348          const char *opname = NULL;
1350 1349          const char *suffix = NULL;
1351 1350          char opstr[16];
1352 1351          int is_signed;
1353 1352  
1354 1353          /* Divides have special register constraints */
1355 1354          if ((expr->op == '/') || (expr->op == '%'))
1356 1355                  return emit_divide(expr, left, right);
1357 1356  
1358      -        is_signed = type_is_signed(expr->ctype);
     1357 +        is_signed = is_signed_type(expr->ctype);
1359 1358  
1360 1359          switch (expr->op) {
1361 1360          case '+':
1362 1361                  opname = "add";
1363 1362                  break;
1364 1363          case '-':
1365 1364                  opname = "sub";
1366 1365                  break;
1367 1366          case '&':
1368 1367                  opname = "and";
↓ open down ↓ 179 lines elided ↑ open up ↑
1548 1547          jmplbl = new_storage(STOR_LABEL);
1549 1548          jmplbl->flags |= STOR_WANTS_FREE;
1550 1549          jmplbl->label = f->ret_target;
1551 1550          insn("jmp", jmplbl, NULL, NULL);
1552 1551  
1553 1552          return val;
1554 1553  }
1555 1554  
1556 1555  static struct storage *emit_conditional_expr(struct expression *expr)
1557 1556  {
1558      -        struct storage *cond, *true = NULL, *false = NULL;
     1557 +        struct storage *cond, *stot = NULL, *stof = NULL;
1559 1558          struct storage *new = stack_alloc(expr->ctype->bit_size / 8);
1560 1559          int target_false, cond_end;
1561 1560  
1562 1561          /* evaluate conditional */
1563 1562          cond = x86_expression(expr->conditional);
1564 1563          target_false = emit_conditional_test(cond);
1565 1564  
1566 1565          /* handle if-true part of the expression */
1567      -        true = x86_expression(expr->cond_true);
     1566 +        stot = x86_expression(expr->cond_true);
1568 1567  
1569      -        emit_copy(new, true, expr->ctype);
     1568 +        emit_copy(new, stot, expr->ctype);
1570 1569  
1571 1570          cond_end = emit_conditional_end(target_false);
1572 1571  
1573 1572          /* handle if-false part of the expression */
1574      -        false = x86_expression(expr->cond_false);
     1573 +        stof = x86_expression(expr->cond_false);
1575 1574  
1576      -        emit_copy(new, false, expr->ctype);
     1575 +        emit_copy(new, stof, expr->ctype);
1577 1576  
1578 1577          /* end of conditional; jump target for if-true branch */
1579 1578          emit_label(cond_end, "end conditional");
1580 1579  
1581 1580          return new;
1582 1581  }
1583 1582  
1584 1583  static struct storage *emit_select_expr(struct expression *expr)
1585 1584  {
1586 1585          struct storage *cond = x86_expression(expr->conditional);
1587      -        struct storage *true = x86_expression(expr->cond_true);
1588      -        struct storage *false = x86_expression(expr->cond_false);
     1586 +        struct storage *stot = x86_expression(expr->cond_true);
     1587 +        struct storage *stof = x86_expression(expr->cond_false);
1589 1588          struct storage *reg_cond, *reg_true, *reg_false;
1590 1589          struct storage *new = stack_alloc(4);
1591 1590  
1592 1591          emit_comment("begin SELECT");
1593 1592          reg_cond = get_reg_value(cond, get_regclass(expr->conditional));
1594      -        reg_true = get_reg_value(true, get_regclass(expr));
1595      -        reg_false = get_reg_value(false, get_regclass(expr));
     1593 +        reg_true = get_reg_value(stot, get_regclass(expr));
     1594 +        reg_false = get_reg_value(stof, get_regclass(expr));
1596 1595  
1597 1596          /*
1598 1597           * Do the actual select: check the conditional for zero,
1599 1598           * move false over true if zero
1600 1599           */ 
1601 1600          insn("test", reg_cond, reg_cond, NULL);
1602 1601          insn("cmovz", reg_false, reg_true, NULL);
1603 1602  
1604 1603          /* Store it back */
1605 1604          emit_move(reg_true, new, expr->ctype, NULL);
↓ open down ↓ 623 lines elided ↑ open up ↑
2229 2228  
2230 2229  static struct storage *x86_symbol_expr(struct symbol *sym)
2231 2230  {
2232 2231          struct storage *new = stack_alloc(4);
2233 2232  
2234 2233          if (sym->ctype.modifiers & (MOD_TOPLEVEL | MOD_EXTERN | MOD_STATIC)) {
2235 2234                  printf("\tmovi.%d\t\tv%d,$%s\n", bits_in_pointer, new->pseudo, show_ident(sym->ident));
2236 2235                  return new;
2237 2236          }
2238 2237          if (sym->ctype.modifiers & MOD_ADDRESSABLE) {
2239      -                printf("\taddi.%d\t\tv%d,vFP,$%lld\n", bits_in_pointer, new->pseudo, sym->value);
     2238 +                printf("\taddi.%d\t\tv%d,vFP,$%lld\n", bits_in_pointer, new->pseudo, 0LL);
2240 2239                  return new;
2241 2240          }
2242 2241          printf("\taddi.%d\t\tv%d,vFP,$offsetof(%s:%p)\n", bits_in_pointer, new->pseudo, show_ident(sym->ident), sym);
2243 2242          return new;
2244 2243  }
2245 2244  
2246 2245  static void x86_symbol_init(struct symbol *sym)
2247 2246  {
2248 2247          struct symbol_private *priv = sym->aux;
2249 2248          struct expression *expr = sym->initializer;
↓ open down ↓ 7 lines elided ↑ open up ↑
2257 2256          if (!priv) {
2258 2257                  priv = calloc(1, sizeof(*priv));
2259 2258                  sym->aux = priv;
2260 2259                  /* FIXME: leak! we don't free... */
2261 2260                  /* (well, we don't free symbols either) */
2262 2261          }
2263 2262  
2264 2263          priv->addr = new;
2265 2264  }
2266 2265  
2267      -static int type_is_signed(struct symbol *sym)
2268      -{
2269      -        if (sym->type == SYM_NODE)
2270      -                sym = sym->ctype.base_type;
2271      -        if (sym->type == SYM_PTR)
2272      -                return 0;
2273      -        return !(sym->ctype.modifiers & MOD_UNSIGNED);
2274      -}
2275      -
2276 2266  static struct storage *x86_label_expr(struct expression *expr)
2277 2267  {
2278 2268          struct storage *new = stack_alloc(4);
2279 2269          printf("\tmovi.%d\t\tv%d,.L%p\n", bits_in_pointer, new->pseudo, expr->label_symbol);
2280 2270          return new;
2281 2271  }
2282 2272  
2283 2273  static struct storage *x86_statement_expr(struct expression *expr)
2284 2274  {
2285 2275          return x86_statement(expr->statement);
↓ open down ↓ 120 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX