+ type_t *type = skip_typeref(literal->base.type);
+ ir_mode *mode = get_ir_mode_storage(type);
+ const char *string = literal->value.begin;
+ size_t size = literal->value.size;
+ ir_tarval *tv;
+
+ switch (literal->base.kind) {
+ case EXPR_LITERAL_WIDE_CHARACTER: {
+ utf32 v = read_utf8_char(&string);
+ char buf[128];
+ size_t len = snprintf(buf, sizeof(buf), UTF32_PRINTF_FORMAT, v);
+
+ tv = new_tarval_from_str(buf, len, mode);
+ goto make_const;
+ }
+ case EXPR_LITERAL_CHARACTER: {
+ long long int v;
+ bool char_is_signed
+ = get_atomic_type_flags(ATOMIC_TYPE_CHAR) & ATOMIC_TYPE_FLAG_SIGNED;
+ if (size == 1 && char_is_signed) {
+ v = (signed char)string[0];
+ } else {
+ v = 0;
+ for (size_t i = 0; i < size; ++i) {
+ v = (v << 8) | ((unsigned char)string[i]);
+ }
+ }
+ char buf[128];
+ size_t len = snprintf(buf, sizeof(buf), "%lld", v);
+
+ tv = new_tarval_from_str(buf, len, mode);
+ goto make_const;
+ }
+ case EXPR_LITERAL_INTEGER:
+ case EXPR_LITERAL_INTEGER_OCTAL:
+ case EXPR_LITERAL_INTEGER_HEXADECIMAL:
+ assert(literal->target_value != NULL);
+ tv = literal->target_value;
+ goto make_const;
+ case EXPR_LITERAL_FLOATINGPOINT:
+ tv = new_tarval_from_str(string, size, mode);
+ goto make_const;
+ case EXPR_LITERAL_FLOATINGPOINT_HEXADECIMAL: {
+ char buffer[size + 2];
+ memcpy(buffer, "0x", 2);
+ memcpy(buffer+2, string, size);
+ tv = new_tarval_from_str(buffer, size+2, mode);
+ goto make_const;
+ }
+ case EXPR_LITERAL_BOOLEAN:
+ if (string[0] == 't') {
+ tv = get_mode_one(mode);
+ } else {
+ assert(string[0] == 'f');
+ tv = get_mode_null(mode);
+ }
+ goto make_const;
+ case EXPR_LITERAL_MS_NOOP:
+ tv = get_mode_null(mode);
+ goto make_const;
+ default:
+ break;
+ }
+ panic("Invalid literal kind found");
+
+make_const: ;
+ dbg_info *dbgi = get_dbg_info(&literal->base.source_position);
+ ir_node *res = new_d_Const(dbgi, tv);
+ ir_mode *mode_arith = get_ir_mode_arithmetic(type);
+ return create_conv(dbgi, res, mode_arith);