// File: 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
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0xa0(%rbp)
movq %rdi, %rax
movq %rax, -0x98(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x90(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %esi
movl $0x21, %edx
callq 0x1f560
testb $0x1, %al
jne 0xc340c
leaq -0x19(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0x7650
movq -0xa0(%rbp), %rdi
movq -0xa8(%rbp), %rdx
leaq 0x7b4c1(%rip), %rsi     # 0x13e89e
callq 0x7520
jmp 0xc33e4
leaq -0x19(%rbp), %rdi
callq 0x73d0
jmp 0xc366a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x19(%rbp), %rdi
callq 0x73d0
jmp 0xc367a
movq -0x90(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0xc(%rax), %esi
callq 0xea90
movq %rax, -0x38(%rbp)
movb $0x0, -0x39(%rbp)
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
addl $-0xc, %eax
movl %eax, %ecx
movq %rcx, -0xb0(%rbp)
subl $0x3, %eax
ja 0xc35a7
movq -0xb0(%rbp), %rax
leaq 0x8220f(%rip), %rcx     # 0x145660
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x74, -0x39(%rbp)
jmp 0xc35a9
movq -0x38(%rbp), %rax
cmpl $0x2, 0x8c(%rax)
jne 0xc3483
movq -0x38(%rbp), %rax
cmpl $0x6, 0x84(%rax)
je 0xc3483
movb $0x75, -0x39(%rbp)
jmp 0xc3487
movb $0x74, -0x39(%rbp)
jmp 0xc35a9
movb $0x73, -0x39(%rbp)
jmp 0xc35a9
movq -0x38(%rbp), %rax
movl 0x64(%rax), %eax
movl %eax, -0x40(%rbp)
cmpl $0x2, -0x40(%rbp)
jne 0xc358b
movq -0x90(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x8(%rax), %esi
movl $0x3, %edx
callq 0x1f560
testb $0x1, %al
jne 0xc34ca
jmp 0xc3565
movq -0x90(%rbp), %rsi
addq $0x8, %rsi
movq -0x18(%rbp), %rdx
leaq -0x80(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x54c20
movq -0xc0(%rbp), %rdi
movl $0x18, %esi
callq 0xef50
movb %al, -0xb1(%rbp)
jmp 0xc3502
movb -0xb1(%rbp), %al
andb $0x1, %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %cl
movb $0x74, %al
movb $0x75, %dl
movb %dl, -0xc2(%rbp)
testb $0x1, %cl
movb %al, -0xc1(%rbp)
jne 0xc3537
movb -0xc2(%rbp), %al
movb %al, -0xc1(%rbp)
movb -0xc1(%rbp), %al
movb %al, -0x39(%rbp)
leaq -0x80(%rbp), %rdi
callq 0xf250
jmp 0xc3589
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0xf250
jmp 0xc367a
movq -0x90(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x8(%rax), %esi
movl $0x2, %edx
callq 0x1f560
testb $0x1, %al
jne 0xc3583
jmp 0xc3587
movb $0x62, -0x39(%rbp)
jmp 0xc3589
jmp 0xc35a5
cmpl $0x9, -0x40(%rbp)
jne 0xc3597
movb $0x62, -0x39(%rbp)
jmp 0xc35a3
cmpl $0xc, -0x40(%rbp)
jne 0xc35a1
movb $0x75, -0x39(%rbp)
jmp 0xc35a3
jmp 0xc35a5
jmp 0xc35a9
jmp 0xc35a9
cmpb $0x0, -0x39(%rbp)
jne 0xc3606
leaq -0x82(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x7650
movq -0xa0(%rbp), %rdi
movq -0xd0(%rbp), %rdx
leaq 0x7b2c7(%rip), %rsi     # 0x13e89e
callq 0x7520
jmp 0xc35de
leaq -0x82(%rbp), %rdi
callq 0x73d0
jmp 0xc366a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x82(%rbp), %rdi
callq 0x73d0
jmp 0xc367a
movq -0x90(%rbp), %rdi
movb -0x39(%rbp), %al
movb %al, -0xd1(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %esi
movl $0x21, %edx
callq 0x23520
movq -0x90(%rbp), %rdi
movl %eax, -0xd8(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %esi
movl $0x22, %edx
callq 0x23520
movq -0xa0(%rbp), %rdi
movq -0x90(%rbp), %rsi
movl -0xd8(%rbp), %ecx
movl %eax, %r8d
movb -0xd1(%rbp), %al
movsbl %al, %edx
callq 0xc3d20
movq -0x98(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x7640
nopw %cs:(%rax,%rax)