sirit/tests/main.cpp

44 lines
1.1 KiB
C++
Raw Normal View History

2018-08-23 09:59:57 +02:00
/* This file is part of the sirit project.
* Copyright (c) 2018 ReinUsesLisp
* This software may be used and distributed according to the terms of the GNU
* General Public License version 2 or any later version.
*/
#include <sirit/sirit.h>
2018-08-26 01:16:37 +02:00
#include <cstdio>
#include <cstdlib>
class MyModule : public Sirit::Module {
public:
MyModule() {}
~MyModule() = default;
void Generate() {
AddCapability(spv::Capability::Shader);
SetMemoryModel(spv::AddressingModel::Logical, spv::MemoryModel::GLSL450);
auto main_type{TypeFunction(TypeVoid())};
auto main_func{EmitFunction(TypeVoid(), spv::FunctionControlMask::MaskNone, main_type)};
Add(main_func);
Add(EmitLabel());
Add(EmitReturn());
Add(EmitFunctionEnd());
AddEntryPoint(spv::ExecutionModel::Vertex, main_func, "main");
}
};
int main(int argc, char** argv) {
MyModule module;
module.Generate();
module.Optimize(2);
std::vector<std::uint8_t> code{module.Assembly()};
FILE* file = fopen("sirit.spv", "wb");
fwrite(code.data(), 1, code.size(), file);
fclose(file);
2018-08-23 09:59:57 +02:00
return 0;
}