// File: /workspace/github_cpp_makefile_star2_O2/rossy[P]crossc/SPIRV-Cross/spirv_hlsl.cpp
// Function: spirv_cross::CompilerHLSL::to_resource_binding[abi:cxx11](spirv_cross::SPIRVariable const&)
string CompilerHLSL::to_resource_binding(const SPIRVariable &var)
{
	// TODO: Basic implementation, might need special consideration for RW/RO structured buffers,
	// RW/RO images, and so on.

	if (!has_decoration(var.self, DecorationBinding))
		return "";

	const auto &type = get<SPIRType>(var.basetype);
	char space = '\0';

	switch (type.basetype)
	{
	case SPIRType::SampledImage:
		space = 't'; // SRV
		break;

	case SPIRType::Image:
		if (type.image.sampled == 2 && type.image.dim != DimSubpassData)
			space = 'u'; // UAV
		else
			space = 't'; // SRV
		break;

	case SPIRType::Sampler:
		space = 's';
		break;

	case SPIRType::Struct:
	{
		auto storage = type.storage;
		if (storage == StorageClassUniform)
		{
			if (has_decoration(type.self, DecorationBufferBlock))
			{
				Bitset flags = ir.get_buffer_block_flags(var);
				bool is_readonly = flags.get(DecorationNonWritable);
				space = is_readonly ? 't' : 'u'; // UAV
			}
			else if (has_decoration(type.self, DecorationBlock))
				space = 'b'; // Constant buffers
		}
		else if (storage == StorageClassPushConstant)
			space = 'b'; // Constant buffers
		else if (storage == StorageClassStorageBuffer)
			space = 'u'; // UAV

		break;
	}
	default:
		break;
	}

	if (!space)
		return "";

	return to_resource_register(space, get_decoration(var.self, DecorationBinding),
	                            get_decoration(var.self, DecorationDescriptorSet));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movl 0x8(%rdx), %esi
pushq $0x21
popq %rdx
movq %r14, %rdi
callq 0x103d2
testb %al, %al
je 0x54e33
movl 0xc(%r15), %esi
movq %r14, %rdi
callq 0x90a4
movq %rax, %r12
movl 0xc(%rax), %eax
addl $-0xc, %eax
cmpl $0x3, %eax
ja 0x54e33
leaq 0x41328(%rip), %rcx     # 0x96074
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x64(%r12), %eax
cmpl $0xc, %eax
je 0x54e1a
movb $0x62, %r13b
cmpl $0x9, %eax
je 0x54de4
cmpl $0x2, %eax
jne 0x54e33
movl 0x8(%r12), %esi
pushq $0x3
popq %rdx
movq %r14, %rdi
callq 0x103d2
testb %al, %al
je 0x54e1f
leaq 0x8(%r14), %rsi
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movq %r15, %rdx
callq 0x1fb0a
btl $0x18, (%r12)
setae %r13b
orb $0x74, %r13b
leaq 0x10(%rsp), %rdi
callq 0xb51c
jmp 0x54de4
movb $0x74, %r13b
jmp 0x54de4
movb $0x73, %r13b
jmp 0x54de4
cmpl $0x2, 0x8c(%r12)
setne %al
cmpl $0x6, 0x84(%r12)
sete %r13b
orb %al, %r13b
xorb $0x75, %r13b
movl 0x8(%r15), %esi
pushq $0x21
popq %rdx
movq %r14, %rdi
callq 0x12174
movl %eax, %ebp
movl 0x8(%r15), %esi
pushq $0x22
popq %rdx
movq %r14, %rdi
callq 0x12174
movzbl %r13b, %edx
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %ecx
movl %eax, %r8d
callq 0x5527c
jmp 0x54e47
movb $0x75, %r13b
jmp 0x54de4
movl 0x8(%r12), %esi
pushq $0x2
popq %rdx
movq %r14, %rdi
callq 0x103d2
testb %al, %al
jne 0x54de4
leaq 0x3aa4d(%rip), %rsi     # 0x8f887
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x6100
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop