-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgpuc.h
140 lines (95 loc) · 3.78 KB
/
gpuc.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#pragma once
#ifdef GPUC_H_25A109C0_B38B_4E2F_BFDD_8B6B28467F01
#if GPUC_H_25A109C0_B38B_4E2F_BFDD_8B6B28467F01 < 100 ||\
GPUC_H_25A109C0_B38B_4E2F_BFDD_8B6B28467F01 > 199
#error "expected gpuc v1"
#endif
#else
#define GPUC_H_25A109C0_B38B_4E2F_BFDD_8B6B28467F01 100
#include <stdbool.h>
//------------------------------------------------------------------------------
#ifdef __cplusplus
#define GPUC_EXTERN_C_BEGIN extern "C" {
#define GPUC_EXTERN_C_END }
#else
#define GPUC_EXTERN_C_BEGIN /* extern "C" { */
#define GPUC_EXTERN_C_END /* } */
#endif // __cplusplus
//------------------------------------------------------------------------------
#define GPUC(GPUC) _GPUC(GPUC)
#define _GPUC(GPUC) #GPUC
//------------------------------------------------------------------------------
GPUC_EXTERN_C_BEGIN
//------------------------------------------------------------------------------
typedef struct GpucSubstring {
const char* head;
unsigned length;
} GpucSubstring;
//------------------------------------------------------------------------------
typedef struct GpucLocation {
GpucSubstring file;
GpucSubstring site;
GpucSubstring context;
unsigned line;
unsigned column;
} GpucLocation;
size_t gpucLocationStringWrite(char** out, const GpucLocation*);
size_t gpucLocationStringLength(const GpucLocation*);
const char* gpucLocationStringAlloc(const GpucLocation*);
void gpucLocationPrint(const GpucLocation*);
//------------------------------------------------------------------------------
typedef enum GpucDiagnosticLevel {
GpucDiagnosticLevel_Note,
GpucDiagnosticLevel_Warning,
GpucDiagnosticLevel_Error,
} GpucDiagnosticLevel;
typedef struct GpucDiagnostic {
GpucDiagnosticLevel level;
GpucLocation location;
char message[];
} GpucDiagnostic;
size_t gpucDiagnosticStringWrite(char** out, const GpucDiagnostic*);
size_t gpucDiagnosticStringLength(const GpucDiagnostic*);
const char* gpucDiagnosticStringAlloc(const GpucDiagnostic*);
void gpucDiagnosticPrint(const GpucDiagnostic*);
void gpucDiagnosticPrintLine(const GpucDiagnostic*);
//------------------------------------------------------------------------------
typedef enum GpucLanguage {
GpucLanguage_Default,
#define GpucLanguage(A,B,C,D)\
((unsigned)(\
(((unsigned)(A)) << 24)|\
(((unsigned)(B)) << 16)|\
(((unsigned)(C)) << 8)|\
(((unsigned)(D)) << 0)))
GpucLanguage_GPUC = GpucLanguage('G','P', 0,0),
GpucLanguage_GLSL_330 = GpucLanguage('G','L', 3,3),
GpucLanguage_HLSL_11 = GpucLanguage('H','L',11,0),
GpucLanguage_Metal_1 = GpucLanguage('M','E', 1,0),
#undef GpucLanguage
} GpucLanguage;
typedef enum GpucStage {
GpucStage_None,
GpucStage_Compute,
GpucStage_Vertex,
GpucStage_Fragment,
} GpucStage;
//------------------------------------------------------------------------------
typedef struct GpucModule GpucModule;
GpucModule* gpucModuleAlloc(const char* file, const char* source);
void gpucModuleFree(GpucModule*);
bool gpucModuleCompile(GpucModule*);
void gpucModulePrintDebug(const GpucModule*);
void gpucModulePrintDiagnostics(const GpucModule* const module);
void gpucModulePrintLexemes(const GpucModule* const module);
void gpucModulePrintAST(const GpucModule* const module);
const GpucDiagnostic* gpucModuleGetDiagnostic(const GpucModule*, unsigned index);
const char* gpucModuleGetTranslation(
GpucModule*,
GpucStage,
GpucLanguage);
//------------------------------------------------------------------------------
int gpucTests(void);
//------------------------------------------------------------------------------
GPUC_EXTERN_C_END
#endif // GPUC_H_25A109C0_B38B_4E2F_BFDD_8B6B28467F01