bitter.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
  3. * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
  4. * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
  5. */
  6. /*$Header: /tmp_amd/presto/export/kbs/jutta/src/gsm/RCS/bitter.c,v 1.1 1992/10/28 00:28:39 jutta Exp $*/
  7. /* Generate code to pack a bit array from a name:#bits description */
  8. #include <stdio.h>
  9. #include "taste.h"
  10. #include "proto.h"
  11. void write_code P2((s_spex, n_spex), struct spex * s_spex, int n_spex)
  12. {
  13. struct spex * sp = s_spex;
  14. int bits = 8;
  15. int vars;
  16. if (!n_spex) return;
  17. vars = sp->varsize;
  18. while (n_spex) {
  19. if (bits == 8) printf("\t*c++ = ");
  20. else printf("\t | ");
  21. if (vars == bits) {
  22. printf( (bits==8? "%s & 0x%lX;\n" : "(%s & 0x%lX);\n"),
  23. sp->var,
  24. ~(0xfffffffe << (bits - 1)));
  25. if (!-- n_spex) break;
  26. sp++;
  27. vars = sp->varsize;
  28. bits = 8;
  29. } else if (vars < bits) {
  30. printf( "((%s & 0x%lX) << %d)",
  31. sp->var,
  32. ~(0xfffffffe << (vars - 1)),
  33. bits - vars);
  34. bits -= vars;
  35. if (!--n_spex) {
  36. puts(";");
  37. break;
  38. }
  39. else putchar('\n');
  40. sp++;
  41. vars = sp->varsize;
  42. } else {
  43. printf("((%s >> %d) & 0x%X);\n",
  44. sp->var,
  45. vars - bits,
  46. ~(0xfffffffe << (bits - 1)));
  47. vars -= bits;
  48. bits = 8;
  49. }
  50. }
  51. }