-
Notifications
You must be signed in to change notification settings - Fork 0
/
retlib.h
110 lines (79 loc) · 2.32 KB
/
retlib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef H_RETLIB
#define H_RETLIB
#include <stdio.h>
#include <stdlib.h>
/*
* String declarations
*/
// Includes NULL byte
#define STRING_PADDING ( sizeof(retstringImpl) )
// Pre-define a mask to remove unaligned bits
#define STRING_PADMASK ( ~ (size_t)(7) )
// ex: 0x...F8
#define STRING_MAXSIZE ( ((size_t)(-1) & STRING_PADMASK) )
// ex: 0x...F0
#define STRING_MAXRESERVED ( STRING_MAXSIZE - sizeof(retstringImpl) )
// STRING_MAXRESERVED - NULL byte
#define STRING_MAXLENGTH ( STRING_MAXRESERVED - 1 )
typedef struct retstringImpl {
size_t reservedLength;
size_t length;
char contents[];
} retstringImpl;
typedef char* retstring;
retstring NewString( size_t maxLength );
retstring DuplicateCString( const char* cstring );
retstring DuplicateString( const retstring );
retstring CompactString( retstring destString );
unsigned ReleaseString( retstring* retstringPtr );
size_t StringLength( retstring source );
size_t StringReservedLength( retstring source );
unsigned ClearString( retstring destString );
retstring AppendChar( retstring destString, char ch );
retstring AppendCString( retstring destString, const char* sourceString );
retstring AppendString( retstring destString, retstring sourceString );
int CompareToCString( retstring left, const char* right );
int CompareStrings( retstring left, retstring right );
int CompareToCStringNC( retstring left, const char* right );
int CompareStringsNC( retstring left, retstring right );
/*
* Symbol table declarations
*/
typedef struct Symbol {
retstring* name;
void* node;
} Symbol;
typedef struct SymbolTable {
Symbol* root;
size_t count;
} SymbolTable;
SymbolTable* NewSymbolTable( void );
void ReleaseSymbolTable( SymbolTable** symTabPtr );
/*
* Code generator declarations
*/
// Instruction buffer
typedef struct X86Instruction {
unsigned fieldsUsed;
} X86Instruction;
typedef struct Executable {
FILE* handle;
} Executable;
Executable* CreateExecutable( const retstring fileName );
unsigned CloseExecutable( Executable** executablePtr );
/*
* Parser declarations
*/
typedef struct Parser {
FILE* handle;
unsigned line;
unsigned column;
unsigned nextLine;
unsigned nextColumn;
char ch;
char nextCh;
} Parser;
Parser* OpenSource( const retstring fileName );
unsigned CloseSource( Parser** parserPtr );
int ReadChar( Parser* source );
#endif