#include "source/parsed_operand.h"
#include <cassert>
#include "source/util/hex_float.h"
namespace spvtools {
void EmitNumericLiteral(std::ostream* out, const spv_parsed_instruction_t& inst,
const spv_parsed_operand_t& operand) {
if (operand.type != SPV_OPERAND_TYPE_LITERAL_INTEGER &&
operand.type != SPV_OPERAND_TYPE_LITERAL_FLOAT &&
operand.type != SPV_OPERAND_TYPE_TYPED_LITERAL_NUMBER &&
operand.type != SPV_OPERAND_TYPE_OPTIONAL_LITERAL_INTEGER &&
operand.type != SPV_OPERAND_TYPE_OPTIONAL_TYPED_LITERAL_INTEGER)
return;
if (operand.num_words < 1) return;
if (operand.num_words > 2) return;
const uint32_t word = inst.words[operand.offset];
if (operand.num_words == 1) {
switch (operand.number_kind) {
case SPV_NUMBER_SIGNED_INT:
*out << int32_t(word);
break;
case SPV_NUMBER_UNSIGNED_INT:
*out << word;
break;
case SPV_NUMBER_FLOATING:
if (operand.number_bit_width == 16) {
*out << spvtools::utils::FloatProxy<spvtools::utils::Float16>(
uint16_t(word & 0xFFFF));
} else {
*out << spvtools::utils::FloatProxy<float>(word);
}
break;
default:
break;
}
} else if (operand.num_words == 2) {
uint64_t bits =
uint64_t(word) | (uint64_t(inst.words[operand.offset + 1]) << 32);
switch (operand.number_kind) {
case SPV_NUMBER_SIGNED_INT:
*out << int64_t(bits);
break;
case SPV_NUMBER_UNSIGNED_INT:
*out << bits;
break;
case SPV_NUMBER_FLOATING:
*out << spvtools::utils::FloatProxy<double>(bits);
break;
default:
break;
}
}
}
}