1% mkbytes.red Copyright (C) Codemist 2016-20 2 3 4% Create bytes.h out of opcodes.red 5% 6% Run ONCE when opcodes.red is created and then leave as documentation! 7% Also after generating bytes.h you need to go 8% filesign -u bytes.h 9% to get its signature correct. 10 11 12 13%% 14%% Copyright (C) 2020, A C Norman, Codemist. * 15%% * 16%% Redistribution and use in source and binary forms, with or without * 17%% modification, are permitted provided that the following conditions are * 18%% met: * 19%% * 20%% * Redistributions of source code must retain the relevant * 21%% copyright notice, this list of conditions and the following * 22%% disclaimer. * 23%% * Redistributions in binary form must reproduce the above * 24%% copyright notice, this list of conditions and the following * 25%% disclaimer in the documentation and/or other materials provided * 26%% with the distribution. * 27%% * 28%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * 29%% "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * 30%% LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * 31%% FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * 32%% COPYRIGHT OWNERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * 33%% INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * 34%% BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * 35%% OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * 36%% ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * 37%% TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * 38%% THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 39%% DAMAGE. * 40%% 41 42% $Id: mkbytes.red 5433 2020-10-15 21:09:02Z arthurcnorman $ 43 44symbolic; 45 46global '(s!:opcodelist); 47 48if not boundp '!@cslbase then !@cslbase := "../cslbase"; 49 50off lower; 51in "$cslbase/opcodes.red"$ 52on lower; 53 54begin 55 scalar o, oo, n; 56 o := open("$cslbase/bytes.h", 'output); 57 oo := wrs o; 58 59 printc "/* bytes.h Copyright (C) Codemist 1993-2004 */"; 60 terpri(); 61 printc "/* Signature: 38cd8141 31-Mar-2004 */"; 62 terpri(); 63 printc "/*"; 64 printc " * Bytecode interpreter support."; 65 printc " *"; 66 printc " * April 1993"; 67 printc " */"; 68 terpri(); 69% printc "#define JUMP_BACK 0x01 /* select direction of jump */"; 70% printc "#define JUMP_LONG 0x02 /* select 16 vs 8 bit offset */"; 71% terpri(); 72 n := 0; 73 for each v in s!:opcodelist do << 74 princ "#define OP_"; 75 princ v; 76 ttab 32; 77 princ "0x"; 78 if n < 16 then princ "0"; 79 prinhex n; 80 terpri(); 81 n := n + 1 >>; 82 terpri(); 83 printc "/* end of bytes.h */"; 84 terpri(); 85 wrs oo; 86 close o; 87 o := open("$cslbase/opnames.c", 'output); 88 oo := wrs o; 89 printc "/* opnames.c Copyright (C) Codemist 1993-2004 */"; 90 terpri(); 91 printc "/* Signature: 38cd8141 31-Mar-2002 */"; 92 terpri(); 93 terpri(); 94 printc "static char *opnames[256] ="; 95 printc "{"; 96 n := 0; 97 for each v in s!:opcodelist do << 98 princ " "; princ '!"; 99 princ v; princ '!"; 100 princ ","; 101 ttab 32; 102 princ "/* 0x"; 103 if n < 16 then princ "0"; 104 prinhex n; 105 printc " */"; 106 n := n + 1 >>; 107 while n < 256 do << 108 princ " "; princ '!"; princ "xxxx"; princ '!"; 109 if n neq 255 then princ ","; 110 ttab 32; 111 princ "/* 0x"; 112 if n < 16 then princ "0"; 113 prinhex n; 114 printc " */"; 115 n := n + 1 >>; 116 printc "};"; 117 terpri(); 118 wrs oo; 119 close o; 120 return "bytes.h and opcodes.c made" 121end; 122 123 124bye; 125