11// Copyright (C) 2022-2023 Jonathan Müller and lauf contributors
22// SPDX-License-Identifier: BSL-1.0
33
4+ #include < algorithm>
45#include < lauf/asm/builder.hpp>
56
67#include < cstdio>
@@ -372,7 +373,7 @@ LAUF_NOINLINE lauf_asm_inst* emit_body(lauf_asm_inst* ip, lauf_asm_builder* b,
372373 assert (insts[dest->offset ].op () == lauf::asm_op::block);
373374 auto dest_offset = dest->offset + 1 ;
374375
375- jump->jump .offset = std::int32_t (dest_offset - cur_offset);
376+ LAUF_BITFIELD_CONVERSION ( jump->jump .offset = std::int32_t (dest_offset - cur_offset) );
376377 }
377378
378379 return ip;
@@ -437,7 +438,7 @@ void emit_debug_location(lauf_asm_builder* b)
437438 for (auto loc : block.debug_locations )
438439 {
439440 // We also have the initial block instruction that affects the inst_idx.
440- loc.inst_idx += block.offset + 1 ;
441+ loc.inst_idx += static_cast < uint16_t >( block.offset + 1 ) ;
441442 cont.push_back (arena, loc);
442443 }
443444 }
@@ -489,8 +490,7 @@ bool lauf_asm_build_finish(lauf_asm_builder* b)
489490 auto result = std::size_t (0 );
490491
491492 for (auto & block : b->blocks )
492- if (block.vstack .max_size () > result)
493- result = block.vstack .max_size ();
493+ result = std::max (block.vstack .max_size (), result);
494494
495495 if (result > UINT16_MAX)
496496 b->error (context, " per-function vstack size limit exceeded" );
@@ -541,7 +541,7 @@ lauf_asm_local* lauf_asm_build_local(lauf_asm_builder* b, lauf_asm_layout layout
541541
542542 // The offset is the current size, we don't need to worry about alignment.
543543 offset = std::uint16_t (b->local_allocation_size + sizeof (lauf_runtime_stack_frame));
544- b->local_allocation_size += layout.size ;
544+ b->local_allocation_size += static_cast < uint16_t >( layout.size ) ;
545545 }
546546 else
547547 {
@@ -553,7 +553,7 @@ lauf_asm_local* lauf_asm_build_local(lauf_asm_builder* b, lauf_asm_layout layout
553553 // for a pointer.
554554 // Since `layout.alignment` is a multiple of it (as a power of two bigger than it), and
555555 // size a multiple of alignment, `layout.alignment + layout.size` is as well.
556- b->local_allocation_size += layout.alignment + layout.size ;
556+ b->local_allocation_size += static_cast < uint16_t >( layout.alignment + layout.size ) ;
557557 // Since we don't know the exact alignment offset, we can't compute it statically.
558558 offset = UINT16_MAX;
559559 }
@@ -708,6 +708,8 @@ const lauf_asm_block* lauf_asm_inst_branch(lauf_asm_builder* b, const lauf_asm_b
708708 b->cur ->next [0 ] = if_false;
709709 b->cur ->next [1 ] = if_true;
710710 break ;
711+ default :
712+ LAUF_UNREACHABLE;
711713 }
712714 }
713715 else
@@ -1006,7 +1008,7 @@ void lauf_asm_inst_global_addr(lauf_asm_builder* b, const lauf_asm_global* globa
10061008 b->cur ->insts .push_back (*b, LAUF_BUILD_INST_VALUE (global_addr, global->allocation_idx ));
10071009 b->cur ->vstack .push_constant (*b, [&] {
10081010 lauf_runtime_value result;
1009- result.as_address .allocation = global->allocation_idx ;
1011+ LAUF_BITFIELD_CONVERSION ( result.as_address .allocation = global->allocation_idx ) ;
10101012 result.as_address .offset = 0 ;
10111013 result.as_address .generation = 0 ; // Always true for globals.
10121014 return result;
@@ -1240,7 +1242,7 @@ void lauf_asm_inst_aggregate_member(lauf_asm_builder* b, size_t member_index,
12401242
12411243namespace
12421244{
1243- enum load_store_constant
1245+ enum load_store_constant : uint8_t
12441246{
12451247 load_store_dynamic,
12461248 load_store_local,
@@ -1381,4 +1383,3 @@ void lauf_asm_inst_store_field(lauf_asm_builder* b, lauf_asm_type type, size_t f
13811383 lauf_asm_inst_call_builtin (b, builtin);
13821384 }
13831385}
1384-
0 commit comments