Debian Codegraph @

tads3/tcunas.h

raw symbols SCIP
1 /* $Header: d:/cvsroot/tads/tads3/TCUNAS.H,v 1.3 1999/07/11 00:46:58 MJRoberts Exp $ */cxx . . $ `<file>/tads3/tcunas.h`/
2
3 /*
4 * Copyright (c) 1999, 2002 Michael J. Roberts. All Rights Reserved.
5 *
6 * Please see the accompanying license file, LICENSE.TXT, for information
7 * on using and copying this software.
8 */
9 /*
10 Name
11 tcunas.h - TADS 3 Compiler Unassembler
12 Function
13
14 Notes
15
16 Modified
17 05/10/99 MJRoberts - Creation
18 */
19
20 #ifndef TCUNAS_H
21 #define TCUNAS_Hcxx . . $ `tads3/tcunas.h:21:9`!
22
23 #include <stdio.h>
24 #include <stdarg.h>
25
26 #include "t3std.h"cxx . . $ `<file>/tads3/t3std.h`/
27 #include "tcgen.h"cxx . . $ `<file>/tads3/tcgen.h`/
28
29
30 /* ------------------------------------------------------------------------ */
31 /*
32 * byte-code source for unassembler
33 */
34 class CTcUnasSrccxx . . $ CTcUnasSrc#
35 {
36 public:
37 virtual ~cxx . . $ CTcUnasSrc#`~CTcUnasSrc`(ced63f7c635d850d).CTcUnasSrccxx . . $ CTcUnasSrc#() { }
38
39 /*
40 * read the next byte; returns zero on success, non-zero at the end
41 * of the byte stream
42 */
43 virtual int next_bytecxx . . $ CTcUnasSrc#next_byte(1ef8e6ec083aabb9).(char *ch) = 0;
44
45 /* get the current offset */
46 virtual ulongcxx . . $ ulong# get_ofscxx . . $ CTcUnasSrc#get_ofs(fe4d2d262d4164a8).() const = 0;
47 };
48
49 /*
50 * code stream implementation of byte code source
51 */
52 class CTcUnasSrcCodeStrcxx . . $ CTcUnasSrcCodeStr#: public CTcUnasSrccxx . . $ CTcUnasSrc#
53 {
54 public:
55 CTcUnasSrcCodeStrcxx . . $ CTcUnasSrcCodeStr#CTcUnasSrcCodeStr(6d627c92261a18ab).(CTcCodeStreamcxx . . $ CTcCodeStream# *str)
56 {
57 /* remember our underlying code stream */
58 str_cxx . . $ CTcUnasSrcCodeStr#str_. = str;
59
60 /* start at the first byte of the code stream */
61 ofs_cxx . . $ CTcUnasSrcCodeStr#ofs_. = 0;
62 }
63
64 /* read from the code stream */
65 int next_bytecxx . . $ CTcUnasSrcCodeStr#next_byte(1ef8e6ec083aabb9).(char *ch)
66 {
67 /* if there's anything left, return the byte and bump the pointer */
68 if (ofs_cxx . . $ CTcUnasSrcCodeStr#ofs_. < str_cxx . . $ CTcUnasSrcCodeStr#str_.->get_ofscxx . . $ CTcDataStream#get_ofs(fe4d2d262d4164a8).())
69 {
70 *ch = str_cxx . . $ CTcUnasSrcCodeStr#str_.->get_byte_atcxx . . $ CTcDataStream#get_byte_at(3cbd0fc93da1c018).(ofs_cxx . . $ CTcUnasSrcCodeStr#ofs_.);
71 ++ofs_cxx . . $ CTcUnasSrcCodeStr#ofs_.;
72 return 0;
73 }
74
75 /* indicate end of file */
76 return 1;
77 }
78
79 /* get the current offset */
80 ulongcxx . . $ ulong# get_ofscxx . . $ CTcUnasSrcCodeStr#get_ofs(fe4d2d262d4164a8).() const
81 {
82 return ofs_cxx . . $ CTcUnasSrcCodeStr#ofs_.;
83 }
84
85 protected:
86 /* underlying code stream object */
87 CTcCodeStreamcxx . . $ CTcCodeStream# *str_cxx . . $ CTcUnasSrcCodeStr#str_.;
88
89 /* current read offset in code stream */
90 ulongcxx . . $ ulong# ofs_cxx . . $ CTcUnasSrcCodeStr#ofs_.;
91 };
92
93 /* ------------------------------------------------------------------------ */
94 /*
95 * output stream for unassembler
96 */
97 class CTcUnasOutcxx . . $ CTcUnasOut#
98 {
99 public:
100 virtual ~cxx . . $ CTcUnasOut#`~CTcUnasOut`(ced63f7c635d850d).CTcUnasOutcxx . . $ CTcUnasOut#() { }
101
102 /* write a line of text to the output, printf-style */
103 virtual void printcxx . . $ CTcUnasOut#print(326aeb464d16410c).(const char *fmt, ...) = 0;
104 };
105
106 /*
107 * stdio implementation of output stream - writes data to standard
108 * output
109 */
110 class CTcUnasOutStdiocxx . . $ CTcUnasOutStdio#: public CTcUnasOutcxx . . $ CTcUnasOut#
111 {
112 public:
113 void printcxx . . $ CTcUnasOutStdio#print(326aeb464d16410c).(const char *fmt, ...)
114 {
115 va_listcxx . . $ va_list# va;
116
117 /* display the data on the standard output */
118 va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(va, fmt);
119 vprintf(fmt, va);
120 va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(va);
121 }
122 };
123
124 /*
125 * Text file (osfildef) implementation of output stream. The file handle
126 * is managed by the caller.
127 */
128 class CTcUnasOutFilecxx . . $ CTcUnasOutFile#: public CTcUnasOutcxx . . $ CTcUnasOut#
129 {
130 public:
131 CTcUnasOutFilecxx . . $ CTcUnasOutFile#CTcUnasOutFile(350f9e409240e83b).(osfildef *fp) { fp_cxx . . $ CTcUnasOutFile#fp_. = fp; }
132
133 void printcxx . . $ CTcUnasOutFile#print(326aeb464d16410c).(const char *fmt, ...)
134 {
135 char buf[1024];
136 va_listcxx . . $ va_list# va;
137
138 /* format the text */
139 va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(va, fmt);
140 t3vsprintfcxx . . $ t3vsprintf(d36759acbd6350eb).(buf, sizeof(buf), fmt, va);
141 va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(va);
142
143 /* write the formatted text to the file */
144 os_fprintz(fp_cxx . . $ CTcUnasOutFile#fp_., buf);
145 }
146
147 protected:
148 /* our file handle */
149 osfildef *fp_cxx . . $ CTcUnasOutFile#fp_.;
150 };
151
152 #endif /* TCUNAS_H */
153