summaryrefslogtreecommitdiff
path: root/CompilerTools.h
blob: 6f8ceac67a5f55892d9ebfc05ac0bda8f6d00a1f (plain)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "includes/mwcc_decomp.h"
#pragma once

extern void CompilerGetPString(short index, unsigned char *str);
extern void CompilerGetCString(short index, char *str);
extern unsigned char *CTool_CtoPstr(char *input);

typedef struct _AllocatorBlock {
	struct _AllocatorBlock *nextBlock;
	char **handle;
	long size;
	long remaining;
} AllocatorBlock;

typedef struct _Allocator {
	AllocatorBlock *blockList;
	long paddingSize;
	AllocatorBlock *lastBlockUsed;
	void *ptrToFreeArea;
	long remaining;
} Allocator;

typedef struct _HeapInfo {
    long _0;
    long _4;
    long _8;
    long xx_C;
    long _10;
    long _14;
    long _18;
} HeapInfo;

typedef struct _StringNode {
	struct _StringNode *next;
	long index;
	short hash;
	char data[1];
} StringNode;

typedef struct _GList {
	char **data;
	long size;
	long capacity;
	long expansion;
} GList;

extern long hash_name_id;
extern StringNode **name_hash_nodes;
extern void (*GListErrorProc)();

// extern void GListError();
extern int InitGList(GList *list, long capacity);
extern void FreeGList(GList *list);
extern void LockGList(GList *list);
extern void UnlockGList(GList *list);
extern void ShrinkGList(GList *list);
extern void AppendGListData(GList *list, const void *data, long size);
extern void AppendGListNoData(GList *list, long size);
extern void AppendGListByte(GList *list, char v);
extern void AppendGListWord(GList *list, short v);
extern void AppendGListTargetEndianWord(GList *list, short v);
extern void AppendGListLong(GList *list, long v);
extern void AppendGListTargetEndianLong(GList *list, long v);
extern void AppendGListID(GList *list, const char *str);
extern void AppendGListName(GList *list, const char *str);
extern void RemoveGListData(GList *list, long size);
extern char GetGListByte(GList *list);
extern short GetGListWord(GList *list);
extern long GetGListLong(GList *list);
extern short GetGListID(GList *list, char *buf);
extern void GetGListData(GList *list, char *buf, long size);
// extern long hashpjw(const char *str);
// extern short PHash(const unsigned char *str);
extern short CHash(const char *str);
extern StringNode *GetHashNameNode(const char *str);
extern StringNode *GetHashNameNodeHash(const char *str, short hash);
extern StringNode *GetHashNameNodeHash2(const char *str, short hash);
extern StringNode *GetHashNameNodeExport(const char *str);
extern long GetHashNameNodeExportID(StringNode *node);
extern StringNode *GetHashNameNodeByID(long id);
extern void NameHashExportReset();
extern void NameHashWriteNameTable(GList *list);
extern void NameHashWriteTargetEndianNameTable(GList *list);
extern void InitNameHash();

typedef void (*heaperror_t)();

extern long CTool_TotalHeapSize();
// extern void getheapinfo(HeapInfo *result, Allocator *heap);
extern void CTool_GetHeapInfo(HeapInfo *result, unsigned char heapID);
// extern void MoreHeapSpace(Allocator *alloc, long size);
extern int initheaps(heaperror_t failureCallback);
extern int initgheap(heaperror_t failureCallback);
extern heaperror_t getheaperror();
extern void setheaperror(heaperror_t failureCallback);
// extern void relheap(Allocator *alloc);
extern void releaseheaps();
extern void releasegheap();
extern void releaseoheap();
extern char *galloc(long size);
extern char *lalloc(long size);
extern char *aalloc(long size);
extern char *oalloc(long size);
extern char *balloc(long size);

extern void locklheap();
extern void unlocklheap();
extern void freelheap();
extern void freeaheap();
extern void freeoheap();
extern void freebheap();

extern char *ScanHex(char *str, long *output, Boolean *overflow);
extern char *ScanOct(char *str, long *output, Boolean *overflow);
extern char *ScanDec(char *str, long *output, Boolean *overflow);

// extern char *UnmangleClassname(char *work, char **pNameStart, short *pNameLength, char **a4, short *a5, Boolean a6);
// extern char *UnmangleAppend(char *src, char srcLen, char **pOutput, short *pOutputLen);
extern void OldUnmangle(char *input, char *output, Boolean flag);

extern short hash(char *str);
extern void memclr(void *buffer, long size);
extern void memclrw(void *buffer, long size);
extern void CToLowercase(char *src, char *dst);
extern int getbit(long v);
typedef struct {
    unsigned long a, b;
} WtfWord64; // this has to make sense, somehow... but how?
extern void CTool_EndianConvertWord64(WtfWord64 value, unsigned long long *p);
extern unsigned short CTool_EndianConvertInPlaceWord16Ptr(unsigned short *p);
extern unsigned long CTool_EndianConvertInPlaceWord32Ptr(unsigned long *p);
extern void CTool_EndianConvertVector128(); // not correct but idc
extern StringNode *CTool_GetPathName(const FSSpec *spec, long *mdDat);
extern Boolean strcat_safe(char *dst, const char *src, int maxLen);