| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef TCUNAS_H |
| 21 |
#define TCUNAS_H |
| 22 |
|
| 23 |
#include <stdio.h> |
| 24 |
#include <stdarg.h> |
| 25 |
|
| 26 |
#include "t3std.h" |
| 27 |
#include "tcgen.h" |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
class CTcUnasSrc |
| 35 |
{ |
| 36 |
public: |
| 37 |
virtual ~CTcUnasSrc() { } |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
virtual int next_byte(char *ch) = 0; |
| 44 |
|
| 45 |
|
| 46 |
virtual ulong get_ofs() const = 0; |
| 47 |
}; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
class CTcUnasSrcCodeStr: public CTcUnasSrc |
| 53 |
{ |
| 54 |
public: |
| 55 |
CTcUnasSrcCodeStr(CTcCodeStream *str) |
| 56 |
{ |
| 57 |
|
| 58 |
str_ = str; |
| 59 |
|
| 60 |
|
| 61 |
ofs_ = 0; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
int next_byte(char *ch) |
| 66 |
{ |
| 67 |
|
| 68 |
if (ofs_ < str_->get_ofs()) |
| 69 |
{ |
| 70 |
*ch = str_->get_byte_at(ofs_); |
| 71 |
++ofs_; |
| 72 |
return 0; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
return 1; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
ulong get_ofs() const |
| 81 |
{ |
| 82 |
return ofs_; |
| 83 |
} |
| 84 |
|
| 85 |
protected: |
| 86 |
|
| 87 |
CTcCodeStream *str_; |
| 88 |
|
| 89 |
|
| 90 |
ulong ofs_; |
| 91 |
}; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
class CTcUnasOut |
| 98 |
{ |
| 99 |
public: |
| 100 |
virtual ~CTcUnasOut() { } |
| 101 |
|
| 102 |
|
| 103 |
virtual void print(const char *fmt, ...) = 0; |
| 104 |
}; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
class CTcUnasOutStdio: public CTcUnasOut |
| 111 |
{ |
| 112 |
public: |
| 113 |
void print(const char *fmt, ...) |
| 114 |
{ |
| 115 |
va_list va; |
| 116 |
|
| 117 |
|
| 118 |
va_start(va, fmt); |
| 119 |
vprintf(fmt, va); |
| 120 |
va_end(va); |
| 121 |
} |
| 122 |
}; |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
class CTcUnasOutFile: public CTcUnasOut |
| 129 |
{ |
| 130 |
public: |
| 131 |
CTcUnasOutFile(osfildef *fp) { fp_ = fp; } |
| 132 |
|
| 133 |
void print(const char *fmt, ...) |
| 134 |
{ |
| 135 |
char buf[1024]; |
| 136 |
va_list va; |
| 137 |
|
| 138 |
|
| 139 |
va_start(va, fmt); |
| 140 |
t3vsprintf(buf, sizeof(buf), fmt, va); |
| 141 |
va_end(va); |
| 142 |
|
| 143 |
|
| 144 |
os_fprintz(fp_, buf); |
| 145 |
} |
| 146 |
|
| 147 |
protected: |
| 148 |
|
| 149 |
osfildef *fp_; |
| 150 |
}; |
| 151 |
|
| 152 |
#endif |
| 153 |
|