2018-10-18 08:27:17 +01: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
|
|
|
|
* Lesser General Public License version 2.1 or any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "insts.h"
|
|
|
|
#include "sirit/sirit.h"
|
2018-10-31 06:37:36 +00:00
|
|
|
#include <cassert>
|
2018-10-18 08:27:17 +01:00
|
|
|
|
|
|
|
namespace Sirit {
|
|
|
|
|
2018-11-01 00:22:00 +00:00
|
|
|
Ref Module::OpVariable(Ref result_type, spv::StorageClass storage_class,
|
|
|
|
Ref initializer) {
|
2018-10-23 09:05:40 +01:00
|
|
|
auto op{new Op(spv::Op::OpVariable, bound++, result_type)};
|
2018-10-18 08:27:17 +01:00
|
|
|
AddEnum(op, storage_class);
|
|
|
|
if (initializer) {
|
|
|
|
op->Add(initializer);
|
|
|
|
}
|
|
|
|
return AddCode(op);
|
|
|
|
}
|
|
|
|
|
2018-11-01 00:22:00 +00:00
|
|
|
Ref Module::OpLoad(Ref result_type, Ref pointer,
|
|
|
|
std::optional<spv::MemoryAccessMask> memory_access) {
|
2018-10-31 07:16:26 +00:00
|
|
|
auto op{new Op(spv::Op::OpLoad, bound++, result_type)};
|
|
|
|
op->Add(pointer);
|
|
|
|
if (memory_access) {
|
|
|
|
AddEnum(op, *memory_access);
|
|
|
|
}
|
|
|
|
return AddCode(op);
|
|
|
|
}
|
|
|
|
|
2018-11-01 00:22:00 +00:00
|
|
|
Ref Module::OpStore(Ref pointer, Ref object,
|
|
|
|
std::optional<spv::MemoryAccessMask> memory_access) {
|
2018-10-31 08:05:06 +00:00
|
|
|
auto op{new Op(spv::Op::OpStore)};
|
|
|
|
op->Add(pointer);
|
|
|
|
op->Add(object);
|
|
|
|
if (memory_access) {
|
|
|
|
AddEnum(op, *memory_access);
|
|
|
|
}
|
|
|
|
return AddCode(op);
|
|
|
|
}
|
|
|
|
|
2018-11-01 00:22:00 +00:00
|
|
|
Ref Module::OpAccessChain(Ref result_type, Ref base,
|
|
|
|
const std::vector<Ref>& indexes) {
|
2018-10-31 06:37:36 +00:00
|
|
|
assert(indexes.size() > 0);
|
|
|
|
auto op{new Op(spv::Op::OpAccessChain, bound++, result_type)};
|
|
|
|
op->Add(base);
|
|
|
|
op->Add(indexes);
|
|
|
|
return AddCode(op);
|
|
|
|
}
|
|
|
|
|
2018-11-01 00:22:00 +00:00
|
|
|
Ref Module::OpCompositeInsert(Ref result_type, Ref object, Ref composite,
|
|
|
|
const std::vector<Literal>& indexes) {
|
2018-10-31 08:05:06 +00:00
|
|
|
auto op{new Op(spv::Op::OpCompositeInsert, bound++, result_type)};
|
|
|
|
op->Add(object);
|
|
|
|
op->Add(composite);
|
|
|
|
op->Add(indexes);
|
|
|
|
return AddCode(op);
|
|
|
|
}
|
|
|
|
|
2018-10-18 08:27:17 +01:00
|
|
|
} // namespace Sirit
|