mkbytes.red 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. % Create bytes.h out of opcodes.red
  2. %
  3. % Run ONCE when opcodes.red is created and then leave as documentation!
  4. % Also after generating bytes.h you need to go
  5. % filesign -u bytes.h
  6. % to get its signature correct.
  7. %
  8. % This code may be used and modified, and redistributed in binary
  9. % or source form, subject to the "CCL Public License", which should
  10. % accompany it. This license is a variant on the BSD license, and thus
  11. % permits use of code derived from this in either open and commercial
  12. % projects: but it does require that updates to this code be made
  13. % available back to the originators of the package.
  14. % Before merging other code in with this or linking this code
  15. % with other packages or libraries please check that the license terms
  16. % of the other material are compatible with those of this.
  17. %
  18. symbolic;
  19. global '(s!:opcodelist);
  20. if not boundp '!@cslbase then !@cslbase := "../cslbase";
  21. off lower;
  22. in "$cslbase/opcodes.red"$
  23. on lower;
  24. begin
  25. scalar o, oo, n;
  26. o := open("$cslbase/bytes.h", 'output);
  27. oo := wrs o;
  28. printc "/* bytes.h Copyright (C) Codemist 1993-2002 */";
  29. terpri();
  30. printc "/* Signature: 38cd8141 31-Mar-2002 */";
  31. terpri();
  32. printc "/*";
  33. printc " * Bytecode interpreter support.";
  34. printc " *";
  35. printc " * April 1993";
  36. printc " */";
  37. terpri();
  38. % printc "#define JUMP_BACK 0x01 /* select direction of jump */";
  39. % printc "#define JUMP_LONG 0x02 /* select 16 vs 8 bit offset */";
  40. % terpri();
  41. n := 0;
  42. for each v in s!:opcodelist do <<
  43. princ "#define OP_";
  44. princ v;
  45. ttab 32;
  46. princ "0x";
  47. if n < 16 then princ "0";
  48. prinhex n;
  49. terpri();
  50. n := n + 1 >>;
  51. terpri();
  52. printc "/* end of bytes.h */";
  53. terpri();
  54. wrs oo;
  55. close o;
  56. o := open("$cslbase/opnames.c", 'output);
  57. oo := wrs o;
  58. printc "/* opnames.c Copyright (C) Codemist 1993-2002 */";
  59. terpri();
  60. printc "/* Signature: 38cd8141 31-Mar-2002 */";
  61. terpri();
  62. terpri();
  63. printc "static char *opnames[256] =";
  64. printc "{";
  65. n := 0;
  66. for each v in s!:opcodelist do <<
  67. princ " "; princ '!";
  68. princ v; princ '!";
  69. princ ",";
  70. ttab 32;
  71. princ "/* 0x";
  72. if n < 16 then princ "0";
  73. prinhex n;
  74. printc " */";
  75. n := n + 1 >>;
  76. while n < 256 do <<
  77. princ " "; princ '!"; princ "xxxx"; princ '!";
  78. if n neq 255 then princ ",";
  79. ttab 32;
  80. princ "/* 0x";
  81. if n < 16 then princ "0";
  82. prinhex n;
  83. printc " */";
  84. n := n + 1 >>;
  85. printc "};";
  86. terpri();
  87. wrs oo;
  88. close o;
  89. return "bytes.h and opcodes.c made"
  90. end;
  91. bye;