You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.0 KiB

  1. /* This file contains code shared by the compiler and the peephole
  2. optimizer.
  3. */
  4. /* Minimum number of bytes necessary to encode instruction with EXTENDED_ARGs */
  5. static int
  6. instrsize(unsigned int oparg)
  7. {
  8. return oparg <= 0xff ? 2 :
  9. oparg <= 0xffff ? 4 :
  10. oparg <= 0xffffff ? 6 :
  11. 8;
  12. }
  13. /* Spits out op/oparg pair using ilen bytes. codestr should be pointed at the
  14. desired location of the first EXTENDED_ARG */
  15. static void
  16. write_op_arg(unsigned char *codestr, unsigned char opcode,
  17. unsigned int oparg, int ilen)
  18. {
  19. switch (ilen) {
  20. case 8:
  21. *codestr++ = EXTENDED_ARG;
  22. *codestr++ = (oparg >> 24) & 0xff;
  23. case 6:
  24. *codestr++ = EXTENDED_ARG;
  25. *codestr++ = (oparg >> 16) & 0xff;
  26. case 4:
  27. *codestr++ = EXTENDED_ARG;
  28. *codestr++ = (oparg >> 8) & 0xff;
  29. case 2:
  30. *codestr++ = opcode;
  31. *codestr++ = oparg & 0xff;
  32. break;
  33. default:
  34. assert(0);
  35. }
  36. }