-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ Binding LangWriter
- Loading branch information
Showing
17 changed files
with
326 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ build | |
vs* | ||
vsxmake* | ||
*.user | ||
.idea/ | ||
cmake*/ | ||
CMakeLists.txt | ||
|
||
# Prerequisites | ||
*.d | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2024 REMqb (remqb at remqb dot fr) | ||
// This file is part of the "Nazara Shading Language" project | ||
// For conditions of distribution and use, see copyright notice in Config.hpp | ||
|
||
#pragma once | ||
|
||
#ifndef CNZSL_LANGWRITER_H | ||
#define CNZSL_LANGWRITER_H | ||
|
||
#include <CNZSL/Config.h> | ||
#include <CNZSL/Module.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#else | ||
#endif | ||
|
||
|
||
/// Opaque pointer on nzsl::LangWriter | ||
typedef struct NZSLLangWriter_s *NZSLLangWriter; | ||
|
||
typedef struct NZSLLangWriterOutputInternal_s *NZSLLangWriterOutputInternal; | ||
typedef struct | ||
{ | ||
NZSLLangWriterOutputInternal internal; | ||
const char* code; | ||
size_t codeLen; | ||
} NZSLLangWriterOutput_s; | ||
typedef NZSLLangWriterOutput_s *NZSLLangWriterOutput; | ||
|
||
NZSLLangWriter NZSL_API nzslLangWriterCreate(void); | ||
|
||
NZSLLangWriterOutput NZSL_API nzslLangWriterGenerate(NZSLLangWriter writer, NZSLModule module); | ||
|
||
void NZSL_API nzslLangWriterDestroy(NZSLLangWriter writer); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
|
||
#endif //CNZSL_LANGWRITER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (C) 2024 REMqb (remqb at remqb dot fr) | ||
// This file is part of the "Nazara Shading Language" project | ||
// For conditions of distribution and use, see copyright notice in Config.hpp | ||
|
||
#pragma once | ||
|
||
#ifndef CNZSL_SPIRVWRITER_H | ||
#define CNZSL_SPIRVWRITER_H | ||
|
||
#include <CNZSL/Config.h> | ||
#include <CNZSL/Module.h> | ||
|
||
#ifdef __cplusplus | ||
#include <cstddef> | ||
extern "C" { | ||
#else | ||
#includ <stddef.h> | ||
#endif | ||
|
||
|
||
/// Opaque pointer on nzsl::SpirvWriter | ||
typedef struct NZSLSpirvWriter_s *NZSLSpirvWriter; | ||
|
||
typedef struct | ||
{ | ||
uint32_t spvMajorVersion; | ||
uint32_t spvMinorVersion; | ||
} NZSLSpirvWriterEnvironment; | ||
|
||
typedef struct NZSLSpirvWriterOutputInternal_s *NZSLSpirvWriterOutputInternal; | ||
typedef struct | ||
{ | ||
NZSLSpirvWriterOutputInternal internal; | ||
const uint32_t* spirv; | ||
size_t spirvLen; | ||
} NZSLSpirvWriterOutput_s; | ||
typedef NZSLSpirvWriterOutput_s *NZSLSpirvWriterOutput; | ||
|
||
NZSLSpirvWriter NZSL_API nzslSpirvWriterCreate(void); | ||
|
||
int NZSL_API nzslSpirvWriterSetEnv(NZSLSpirvWriter writer, NZSLSpirvWriterEnvironment env); | ||
|
||
NZSLSpirvWriterOutput NZSL_API nzslSpirvWriterGenerate(NZSLSpirvWriter writer, NZSLModule module); | ||
|
||
void NZSL_API nzslSpirvWriterDestroy(NZSLSpirvWriter writer); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
|
||
#endif //CNZSL_SPIRVWRITER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright (C) 2024 REMqb (remqb at remqb dot fr) | ||
// This file is part of the "Nazara Shading Language" project | ||
// For conditions of distribution and use, see copyright notice in Config.hpp | ||
|
||
#include <NZSL/LangWriter.hpp> | ||
#include <string> | ||
|
||
#include <CNZSL/LangWriter.h> | ||
#include <CNZSL/Error.hpp> | ||
|
||
using namespace std::literals; | ||
|
||
extern "C" { | ||
|
||
|
||
NZSLLangWriter NZSL_API nzslLangWriterCreate(void) { | ||
nzsl::LangWriter* writer = nullptr; | ||
|
||
try { | ||
writer = new nzsl::LangWriter; | ||
} catch (std::exception& e) { | ||
cnzsl::setError("nzslLangWriterCreate failed: "s + e.what()); | ||
} catch (...) { | ||
cnzsl::setError("nzslLangWriterCreate failed with unknown error"); | ||
} | ||
|
||
return reinterpret_cast<NZSLLangWriter>(writer); | ||
} | ||
|
||
NZSLLangWriterOutput NZSL_API nzslLangWriterGenerate(NZSLLangWriter writer, NZSLModule module) { | ||
auto writerPtr = reinterpret_cast<nzsl::LangWriter*>(writer); | ||
auto modulePtr = reinterpret_cast<nzsl::Ast::ModulePtr *>(module); | ||
|
||
NZSLLangWriterOutput output = nullptr; | ||
|
||
try { | ||
auto generated = new std::string{writerPtr->Generate(**modulePtr)}; | ||
|
||
try | ||
{ | ||
output = new NZSLLangWriterOutput_s{ | ||
.internal = reinterpret_cast<NZSLLangWriterOutputInternal>(generated), | ||
.code = generated->data(), | ||
.codeLen = generated->size() | ||
}; | ||
} catch(...) { | ||
delete generated; | ||
|
||
throw; | ||
} | ||
} catch (std::exception& e) { | ||
cnzsl::setError("nzslLangWriterGenerate failed: "s + e.what()); | ||
} catch (...) { | ||
cnzsl::setError("nzslLangWriterGenerate failed with unknown error"); | ||
} | ||
|
||
return output; | ||
} | ||
|
||
void NZSL_API nzslLangWriterOutputDestroy(NZSLLangWriterOutput output) { | ||
auto outputPtr = reinterpret_cast<std::string*>(output->internal); | ||
|
||
delete outputPtr; | ||
delete output; | ||
} | ||
|
||
void NZSL_API nzslLangWriterDestroy(NZSLLangWriter writer) { | ||
auto writerPtr = reinterpret_cast<nzsl::LangWriter*>(writer); | ||
|
||
delete writerPtr; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.