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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
|
/*
Vita Development Suite Libraries
*/
#ifndef _VDSUITE_USER_SHACCCG_TYPES_H
#define _VDSUITE_USER_SHACCCG_TYPES_H
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif // def __cplusplus
///////////////////////////////////////////////////////////////////////////////
// Forward declarations
///////////////////////////////////////////////////////////////////////////////
typedef struct SceShaccCgCompileOptions SceShaccCgCompileOptions;
typedef struct SceShaccCgSourceFile SceShaccCgSourceFile;
typedef struct SceShaccCgSourceLocation SceShaccCgSourceLocation;
///////////////////////////////////////////////////////////////////////////////
// Typedefs
///////////////////////////////////////////////////////////////////////////////
/** @brief A callback used when the compiler needs to open a file.
The includedFrom location will either be 0, if a primary file is being
opened, or it will point to the location of the #include directive.
If the file could not be opened, 0 is returned and errorString will be
updated to point to a representative message, explaining why the file
could not be opened.
On success, a non-zero pointer is returned. The caller takes ownership,
calling SceShaccCgCallbackReleaseFile when the returned SceShaccCgSourceFile
is no longer required.
@param[in] fileName
The absolute path of the file to be opened.
@param[in] includedFrom
The include location. Set to 0 for a primary file.
@param[in] compileOptions
The original options pointer used to invoke this compile.
@param[in] userData
Opaque pointer to user data.
@param[out] errorString
If 0 is returned and this pointer is non-zero, this output param should
be updated to contain a diagnostic message.
@return
A SceShaccCgSourceFile object to be destroyed later with
SceShaccCgCallbackReleaseFile.
@ingroup shacccg
*/
typedef SceShaccCgSourceFile* (*SceShaccCgCallbackOpenFile)(
const char *fileName,
const SceShaccCgSourceLocation *includedFrom,
const SceShaccCgCompileOptions *compileOptions,
void *userData,
const char **errorString);
/** @brief A callback used when the compiler needs to release file data.
This function is used to release memory that was previously allocated as
part of a call to SceShaccCgCallbackOpenFile. This will be called once per
"fileName" associated with that SceShaccCgSourceFile object when the
resources for the compile session are released.
@param[in] file
The SceShaccCgSourceFile object to be destroyed.
@param[in] compileOptions
The original options pointer used to invoke this compile.
@param[in] userData
Opaque pointer to user data.
@ingroup shacccg
*/
typedef void (*SceShaccCgCallbackReleaseFile)(
const SceShaccCgSourceFile *file,
const SceShaccCgCompileOptions *compileOptions,
void *userData);
/** @brief A callback used to search for a named file.
This function will search in all provided paths for the named file. If the
file could not be located, 0 is returned and errorString will have been
updated to a representative message, explaining why the file could not be
located.
On success, a non-zero string is returned. The caller takes ownership and
will release the allocation via the SceShaccCgCallbackReleaseFileName
callback.
@param[in] fileName
The name of the file to be located.
@param[in] includedFrom
The location of the include directive. Set to 0 for primary files.
@param[in] searchPathCount
The number of search paths provided via 'searchPaths'.
@param[in] searchPaths
The array of search paths. The size is provided via 'searchPathCount'.
@param[in] compileOptions
The original options pointer used to invoke this compile.
@param[in] userData
Opaque pointer to user data.
@param[out] errorString
If 0 is returned and if this pointer is non-zero, it should be updated
to contain a diagnostic message.
@return
A relative or absolute path to the file or 0 if the file could not be
located.
@ingroup shacccg
*/
typedef const char* (*SceShaccCgCallbackLocateFile)(
const char *fileName,
const SceShaccCgSourceLocation *includedFrom,
uint32_t searchPathCount,
const char *const*searchPaths,
const SceShaccCgCompileOptions *compileOptions,
void *userData,
const char **errorString);
/** @brief A callback used to retrieve the absolute path name for a given file.
Files are uniquely identified by absolute paths. If two include files lead
to the same absolute path, the previously found file is used and no call
to SceShaccCgCallbackOpenFile will be made. This function allows for a
translation from a relative path scheme to an absolute path scheme.
If there is no valid absolute path for the given file, 0 should be returned.
If a non-zero string is returned, the caller takes ownership and will release
the allocation via the SceShaccCgCallbackReleaseFileName callback.
This string will be the name passed to SceShaccCgCallbackOpenFile.
@param[in] fileName
The (possibly relative) file path for an include file, as provided
by SceShaccCgCallbackLocateFile.
@param[in] includedFrom
The location of the include directive.
@param[in] compileOptions
The original options pointer used to invoke this compile.
@param[in] userData
Opaque pointer to user data.
@return
The absolute file path or 0 if the file could not be located.
@ingroup shacccg
*/
typedef const char* (*SceShaccCgCallbackAbsolutePath)(
const char *fileName,
const SceShaccCgSourceLocation *includedFrom,
const SceShaccCgCompileOptions *compileOptions,
void *userData);
/** @brief A callback for the compiler to release a file name.
This function is used to release memory that was previously allocated as
part of a call to SceShaccCgCallbackLocateFile or
SceShaccCgCallbackAbsolutePath.
@param[in] fileName
The file name string to be destroyed.
@param[in] compileOptions
The original options pointer used to invoke this compile.
@param[in] userData
Opaque pointer to user data.
@ingroup shacccg
*/
typedef void (*SceShaccCgCallbackReleaseFileName)(
const char *fileName,
const SceShaccCgCompileOptions *compileOptions,
void *userData);
/** @brief Provides date information for the named file.
If the date attributes could not be read, 0 is returned and the results
will be considered invalid.
On success, timeLastStatusChange and timeLastModified will have been
updated and a non-zero value is returned.
The time values are encoded as time_t.
@param[in] file
A file object returned from SceShaccCgCallbackOpenFile.
@param[in] includedFrom
The location of the include directive.
@param[in] compileOptions
The original options pointer used to invoke this compile.
@param[in] userData
Opaque pointer to user data.
@param[out] timeLastStatusChange
A pointer to the time of last status change (i.e. creationTime).
@param[out] timeLastModified
A pointer to the time of last modification.
@return
Non-zero for success, 0 on failure.
@ingroup shacccg
*/
typedef int32_t (*SceShaccCgCallbackFileDate)(
const SceShaccCgSourceFile *file,
const SceShaccCgSourceLocation *includedFrom,
const SceShaccCgCompileOptions *compileOptions,
void *userData,
int64_t *timeLastStatusChange, ///< using time_t
int64_t *timeLastModified); ///< using time_t
/** @brief A callback used when the compiler needs to allocate memory.
This function is used to allocate memory. Memory must be 8 bytes aligned.
@param[in] memSize
Memory size.
@ingroup shacccg
*/
typedef void *(*SceShaccCgAllocator)(
size_t memSize);
/** @brief A callback used when the compiler needs to free memory.
This function is used to free memory.
@param[in] memPtr
Pointer to a memory block previously allocated with SceShaccCgAllocator
@ingroup shacccg
*/
typedef void (*SceShaccCgDeallocator)(
void *memPtr);
///////////////////////////////////////////////////////////////////////////////
// Constants
///////////////////////////////////////////////////////////////////////////////
/** @brief Classifies the severity of a diagnostic
@ingroup shacccg
*/
typedef enum SceShaccCgDiagnosticLevel {
SCE_SHACCCG_DIAGNOSTIC_LEVEL_INFO, ///< Informational message
SCE_SHACCCG_DIAGNOSTIC_LEVEL_WARNING, ///< Warning
SCE_SHACCCG_DIAGNOSTIC_LEVEL_ERROR ///< Error
} SceShaccCgDiagnosticLevel;
/** @brief Classifies the target profiles
@ingroup shacccg
*/
typedef enum SceShaccCgTargetProfile {
SCE_SHACCCG_PROFILE_VP, ///< vertex program
SCE_SHACCCG_PROFILE_FP ///< fragment program
} SceShaccCgTargetProfile;
/** @brief Classifies default callbacks
@ingroup shacccg
*/
typedef enum SceShaccCgCallbackDefaults {
SCE_SHACCCG_SYSTEM_FILES, ///< Default callback functions for using system files and paths.
SCE_SHACCCG_TRIVIAL ///< Default callback functions for using only the "openFile" callback.
} SceShaccCgCallbackDefaults;
/** @brief Classifies language
@ingroup shacccg
*/
typedef enum SceShaccCgLocale {
SCE_SHACCCG_ENGLISH, ///< English language setting.
SCE_SHACCCG_JAPANESE ///< Japanese language setting.
} SceShaccCgLocale;
///////////////////////////////////////////////////////////////////////////////
// Structs
///////////////////////////////////////////////////////////////////////////////
/** @brief Describes a source file
@note If the source file is referenced only through a #line directive,
the compiler will generate a SceShaccCgSourceFile object with a
NULL 'text' field and a 'size' field of 0.
@ingroup shacccg
*/
typedef struct SceShaccCgSourceFile {
const char *fileName; ///< The relative or absolute name of the file.
const char *text; ///< The contents of the source file.
uint32_t size; ///< The size of the 'text' array in bytes.
} SceShaccCgSourceFile;
/** @brief Describes a location in the source code.
@ingroup shacccg
*/
typedef struct SceShaccCgSourceLocation {
const SceShaccCgSourceFile *file; ///< The file containing the location.
uint32_t lineNumber; ///< The line number of the location.
uint32_t columnNumber; ///< The column number of the location.
} SceShaccCgSourceLocation;
/** @brief Describes the input data for a compilation job.
@ingroup shacccg
*/
typedef struct SceShaccCgCompileOptions {
const char *mainSourceFile; ///< The main Cg source file to compile.
SceShaccCgTargetProfile targetProfile; ///< The target profile.
const char *entryFunctionName; ///< The name of the entry function. Usually "main".
uint32_t searchPathCount; ///< The number of search paths for include files.
const char* const *searchPaths; ///< The search paths for include files.
uint32_t macroDefinitionCount; ///< The number of macro definitions provided.
const char* const *macroDefinitions; ///< The macro definitions in the form: MACRONAME or MACRONAME=VALUE
uint32_t includeFileCount; ///< The number of files to force include.
const char* const *includeFiles; ///< The files to include before the main source file.
uint32_t suppressedWarningsCount; ///< The number of warnings to suppressed.
const uint32_t *suppressedWarnings; ///< The id numbers of the warnings to be suppressed.
SceShaccCgLocale locale; ///< The language to use in diagnostics.
int32_t useFx; ///< Equivalent to -fx if non-zero, -nofx otherwise.
int32_t noStdlib; ///< Equivalent to -nostdlib if non-zero.
int32_t optimizationLevel; ///< Equivalent to -O?. Valid range is 0-4.
int32_t useFastmath; ///< Equivalent to -fastmath if non-zero.
int32_t useFastprecision; ///< Equivalent to -fastprecision if non-zero.
int32_t useFastint; ///< Equivalent to -fastint if non-zero.
int32_t positionInvariant; ///< Equivalent to -invpos if non-zero.
int32_t warningsAsErrors; ///< Equivalent to -Werror if non-zero.
int32_t performanceWarnings; ///< Equivalent to -Wperf if non-zero.
int32_t warningLevel; ///< Equivalent to -W?. Valid range is 0-4.
int32_t pedantic; ///< Equivalent to -pedantic if non-zero.
int32_t pedanticError; ///< Equivalent to -pedantic-error if non-zero.
int32_t xmlCache; ///< Equivalent to -xmlcache if non-zero.
int32_t stripSymbols; ///< When set to non zero compilation will produce a stripped gxp file
} SceCgcCompileOptions;
/** @brief Lists the user defined callbacks for compiler operations.
The SceShaccCgCallbackList structure is used in each of
sceShaccCgCompileProgram, SceShaccCgPreprocessProgram and
sceShaccCgGenerateDependencies in the same fashion.
In order to initialize instances of this structure, please always use
sceShaccCgInitializeCallbackList.
For details regarding the individual callbacks, please refer to their
respective documentations.
@ingroup shacccg
*/
typedef struct SceShaccCgCallbackList {
SceShaccCgCallbackOpenFile openFile; ///< The callback used to open a file.
SceShaccCgCallbackReleaseFile releaseFile; ///< The callback used to release an opened file (optional).
SceShaccCgCallbackLocateFile locateFile; ///< The callback used to indicate a file exists (optional).
SceShaccCgCallbackAbsolutePath absolutePath; ///< The callback used to indicate the absolute path of a file (optional).
SceShaccCgCallbackReleaseFileName releaseFileName; ///< The callback used to release an absolute path string (optional).
SceShaccCgCallbackFileDate fileDate; ///< The callback used to indicate file modification date (optional).
} SceShaccCgCallbackList;
/** @brief Describes a single compiler diagnostic.
@ingroup shacccg
*/
typedef struct SceShaccCgDiagnosticMessage {
SceShaccCgDiagnosticLevel level; ///< The severity of the diagnostic.
uint32_t code; ///< A unique code for each kind of diagnostic.
const SceShaccCgSourceLocation *location; ///< The location for which the diagnostic is reported (optional).
const char *message; ///< The diagnostic message.
} SceShaccCgDiagnosticMessage;
///////////////////////////////////////////////////////////////////////////////
// Functions for initializing common types
///////////////////////////////////////////////////////////////////////////////
/** @brief Initializes the compile options with the default values.
The following fields must be initialized by the user:
- mainSourceFile
- targetProfile
All other fields may be left in the state set by this function.
@param[out] options
The option structure that should be initialized.
@ingroup shacccg
*/
void sceShaccCgInitializeCompileOptions(
SceShaccCgCompileOptions *options);
/** @brief Initializes the callback list with the default values.
There are two kinds of defaults available:
- SCE_SHACCCG_SYSTEM_FILES uses the native file system of the operating
system in the same manner as the command-line version of psp2cgc.
This is the default behavior if no callback structure is provided for
a compilation/pre-processing/dependency job.
- SCE_SHACCCG_TRIVIAL provides placeholder implementations of all callbacks
but 'openFile'. The latter must always be provided by the user.
In the trivial case, the following defaults will be used:
- releaseFile: Does nothing.
- locateFile: Returns the same path it was called with.
- absolutePath: Returns the same path it was called with.
- releaseFileName: Does nothing.
- fileDate: Returns the current time.
@param[in] callbacks
The callbacks structure to be initialized.
@param[in] defaults
Indicates which set of default callbacks to initialize from.
@ingroup shacccg
*/
void sceShaccCgInitializeCallbackList(
SceShaccCgCallbackList *callbacks,
SceShaccCgCallbackDefaults defaults);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _VDSUITE_USER_SHACCCG_TYPES_H */
|