-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
mach_dxc.h
132 lines (100 loc) · 4.01 KB
/
mach_dxc.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
#ifndef MACH_DXC_H_
#define MACH_DXC_H_
#ifdef __cplusplus
extern "C" {
#endif
#if defined(MACH_DXC_C_SHARED_LIBRARY)
# if defined(_WIN32)
# if defined(MACH_DXC_C_IMPLEMENTATION)
# define MACH_EXPORT __declspec(dllexport)
# else
# define MACH_EXPORT __declspec(dllimport)
# endif
# else // defined(_WIN32)
# if defined(MACH_DXC_C_IMPLEMENTATION)
# define MACH_EXPORT __attribute__((visibility("default")))
# else
# define MACH_EXPORT
# endif
# endif // defined(_WIN32)
#else // defined(MACH_DXC_C_SHARED_LIBRARY)
# define MACH_EXPORT
#endif // defined(MACH_DXC_C_SHARED_LIBRARY)
#if !defined(MACH_OBJECT_ATTRIBUTE)
#define MACH_OBJECT_ATTRIBUTE
#endif
#include <stddef.h>
typedef struct MachDxcCompilerImpl* MachDxcCompiler MACH_OBJECT_ATTRIBUTE;
typedef struct MachDxcCompileResultImpl* MachDxcCompileResult MACH_OBJECT_ATTRIBUTE;
typedef struct MachDxcCompileErrorImpl* MachDxcCompileError MACH_OBJECT_ATTRIBUTE;
typedef struct MachDxcCompileObjectImpl* MachDxcCompileObject MACH_OBJECT_ATTRIBUTE;
typedef struct MachDxcIncludeResult {
const char* header_data; // UTF-8 or null
size_t header_length;
} MachDxcIncludeResult;
typedef MachDxcIncludeResult* (*MachDxcIncludeFunc)(void* ctx, const char* header_name);
typedef int (*MachDxcFreeIncludeFunc)(void* ctx, MachDxcIncludeResult* result);
typedef struct MachDxcIncludeCallbacks {
void* include_ctx;
MachDxcIncludeFunc include_func;
MachDxcFreeIncludeFunc free_func;
} MachDxcIncludeCallbacks;
typedef struct MachDxcCompileOptions {
// Required
char const* code;
size_t code_len;
char const* const* args;
size_t args_len;
// Optional
MachDxcIncludeCallbacks* include_callbacks; // nullable
} MachDxcCompileOptions;
//----------------
// MachDxcCompiler
//----------------
/// Initializes a DXC compiler
///
/// Invoke machDxcDeinit when done with the compiler.
MACH_EXPORT MachDxcCompiler machDxcInit();
/// Deinitializes the DXC compiler.
MACH_EXPORT void machDxcDeinit(MachDxcCompiler compiler);
//---------------------
// MachDxcCompileResult
//---------------------
/// Compiles the given code with the given dxc.exe CLI arguments
///
/// Invoke machDxcCompileResultDeinit when done with the result.
MACH_EXPORT MachDxcCompileResult machDxcCompile(
MachDxcCompiler compiler,
MachDxcCompileOptions* options
);
/// Returns an error object, or null in the case of success.
///
/// Invoke machDxcCompileErrorDeinit when done with the error, iff it was non-null.
MACH_EXPORT MachDxcCompileError machDxcCompileResultGetError(MachDxcCompileResult err);
/// Returns the compiled object code, or null if an error occurred.
MACH_EXPORT MachDxcCompileObject machDxcCompileResultGetObject(MachDxcCompileResult err);
/// Deinitializes the DXC compiler.
MACH_EXPORT void machDxcCompileResultDeinit(MachDxcCompileResult err);
//---------------------
// MachDxcCompileObject
//---------------------
/// Returns a pointer to the raw bytes of the compiled object file.
MACH_EXPORT char const* machDxcCompileObjectGetBytes(MachDxcCompileObject err);
/// Returns the length of the compiled object file.
MACH_EXPORT size_t machDxcCompileObjectGetBytesLength(MachDxcCompileObject err);
/// Deinitializes the compiled object, calling Get methods after this is illegal.
MACH_EXPORT void machDxcCompileObjectDeinit(MachDxcCompileObject err);
//--------------------
// MachDxcCompileError
//--------------------
/// Returns a pointer to the null-terminated UTF-8 encoded error string. This includes
/// compiler warnings, unless they were disabled in the compile arguments.
MACH_EXPORT char const* machDxcCompileErrorGetString(MachDxcCompileError err);
/// Returns the length of the error string.
MACH_EXPORT size_t machDxcCompileErrorGetStringLength(MachDxcCompileError err);
/// Deinitializes the error, calling Get methods after this is illegal.
MACH_EXPORT void machDxcCompileErrorDeinit(MachDxcCompileError err);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // MACH_DXC_H_