Skip to content

Commit

Permalink
Add a number of missing noexcept specifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
fwsGonzo committed Jun 29, 2024
1 parent 8764a1d commit f2f1617
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion lib/libriscv/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace riscv
template <int W>
static std::shared_ptr<DecodedExecuteSegment<W>> empty_shared = std::make_shared<DecodedExecuteSegment<W>>(0, 0, 0, 0);
template <int W>
std::shared_ptr<DecodedExecuteSegment<W>>& CPU<W>::empty_execute_segment() {
std::shared_ptr<DecodedExecuteSegment<W>>& CPU<W>::empty_execute_segment() noexcept {
return empty_shared<W>;
}

Expand Down
28 changes: 14 additions & 14 deletions lib/libriscv/cpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,24 @@ namespace riscv
/// @brief Get the current PC
/// @return The current PC address
address_t pc() const noexcept { return registers().pc; }
void increment_pc(int delta);
void increment_pc(int delta) noexcept;
void jump(address_t);
void aligned_jump(address_t);
void aligned_jump(address_t) noexcept;

/// @brief Retrieve current register state
/// @return Current register state
RISCV_ALWAYS_INLINE auto& registers() { return this->m_regs; }
RISCV_ALWAYS_INLINE auto& registers() noexcept { return this->m_regs; }
/// @brief Retrieve current register state
/// @return Current register state
RISCV_ALWAYS_INLINE const auto& registers() const { return this->m_regs; }
RISCV_ALWAYS_INLINE const auto& registers() const noexcept { return this->m_regs; }

int cpu_id() const noexcept { return m_cpuid; }

auto& reg(uint32_t idx) { return registers().get(idx); }
const auto& reg(uint32_t idx) const { return registers().get(idx); }
auto& cireg(uint16_t idx) { return registers().get(idx + 0x8); }
const auto& cireg(uint16_t idx) const { return registers().get(idx + 0x8); }
auto& ciflp(uint16_t idx) { return registers().getfl(idx + 0x8); }
auto& reg(uint32_t idx) noexcept { return registers().get(idx); }
const auto& reg(uint32_t idx) const noexcept { return registers().get(idx); }
auto& cireg(uint16_t idx) noexcept { return registers().get(idx + 0x8); }
const auto& cireg(uint16_t idx) const noexcept { return registers().get(idx + 0x8); }
auto& ciflp(uint16_t idx) noexcept { return registers().getfl(idx + 0x8); }

Machine<W>& machine() noexcept;
const Machine<W>& machine() const noexcept;
Expand Down Expand Up @@ -98,7 +98,7 @@ namespace riscv
format_t read_next_instruction_slowpath() const RISCV_COLD_PATH();
static const instruction_t& decode(format_t);
// Convert a RISC-V instruction into a fast bytecode
static size_t computed_index_for(format_t bits);
static size_t computed_index_for(format_t bits) noexcept;

/// @brief Serializes the current CPU state to a vector
/// @param vec The vector to serialize into
Expand All @@ -120,23 +120,23 @@ namespace riscv
CPU(Machine<W>&, unsigned cpu_id, const Machine<W>& other); // Fork

DecodedExecuteSegment<W>& init_execute_area(const void* data, address_t begin, address_t length);
void set_execute_segment(DecodedExecuteSegment<W>& seg) { m_exec = &seg; }
void set_execute_segment(DecodedExecuteSegment<W>& seg) noexcept { m_exec = &seg; }
auto& current_execute_segment() noexcept { return *m_exec; }
auto& current_execute_segment() const noexcept { return *m_exec; }
struct NextExecuteReturn {
DecodedExecuteSegment<W>* exec;
address_t pc;
};
NextExecuteReturn next_execute_segment(address_t pc);
static std::shared_ptr<DecodedExecuteSegment<W>>& empty_execute_segment();
static std::shared_ptr<DecodedExecuteSegment<W>>& empty_execute_segment() noexcept;
bool is_executable(address_t addr) const noexcept;

// Override the function that gets called when the CPU
// throws an execute space protection fault.
void set_fault_handler(execute_fault_t func) { m_fault = func; }
void set_fault_handler(execute_fault_t func) noexcept { m_fault = func; }

// Override how to produce the next active execute segment
void set_override_new_execute_segment(override_execute_segment_t func) { m_override_exec = func; }
void set_override_new_execute_segment(override_execute_segment_t func) noexcept { m_override_exec = func; }

// Override how to handle unknown instructions, so that you may implement your own
static inline std::function<const instruction_t& (format_t)> on_unimplemented_instruction;
Expand Down
4 changes: 2 additions & 2 deletions lib/libriscv/cpu_inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ inline void CPU<W>::jump(const address_t dst)
}

template<int W>
inline void CPU<W>::aligned_jump(const address_t dst)
inline void CPU<W>::aligned_jump(const address_t dst) noexcept
{
this->registers().pc = dst;
}

template<int W>
inline void CPU<W>::increment_pc(int delta)
inline void CPU<W>::increment_pc(int delta) noexcept
{
registers().pc += delta;
}
2 changes: 1 addition & 1 deletion lib/libriscv/decode_bytecodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace riscv {

template <int W>
size_t CPU<W>::computed_index_for(rv32i_instruction instr)
size_t CPU<W>::computed_index_for(rv32i_instruction instr) noexcept
{
if (instr.whole == RV32_INSTR_BLOCK_END)
return RV32I_BC_FUNCBLOCK;
Expand Down
14 changes: 7 additions & 7 deletions lib/libriscv/machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ namespace riscv
/// @tparam ...Args The types of results to return.
/// @param ...args The results to return.
template <typename... Args>
inline void set_result(Args... args);
void set_result(Args... args) noexcept;

/// @brief Convert the result of a C library function call that
/// returns 0 or positive on success, and -1 on failure. errno
Expand Down Expand Up @@ -291,27 +291,27 @@ namespace riscv
// Stdout, stderr (for when the guest wants to write)
void print(const char*, size_t) const;
auto& get_printer() const noexcept { return m_printer; }
void set_printer(printer_func pf = default_printer) const { m_printer = pf; }
void set_printer(printer_func pf = default_printer) noexcept { m_printer = pf; }
// Stdin (for when the guest wants to read)
long stdin_read(char*, size_t) const;
auto& get_stdin() const noexcept { return m_stdin; }
void set_stdin(stdin_func sin = default_stdin) const { m_stdin = sin; }
void set_stdin(stdin_func sin = default_stdin) noexcept { m_stdin = sin; }
// Debug printer (for when the machine wants to inform)
void debug_print(const char*, size_t) const;
auto& get_debug_printer() const noexcept { return m_debug_printer; }
void set_debug_printer(printer_func pf = default_printer) const { m_debug_printer = pf; }
void set_debug_printer(printer_func pf = default_printer) noexcept { m_debug_printer = pf; }
// Monotonic time function (used by RDTIME and RDTIMEH)
uint64_t rdtime() const { return m_rdtime(*this); }
auto& get_rdtime() const noexcept { return m_rdtime; }
void set_rdtime(rdtime_func tf = default_rdtime) const { m_rdtime = tf; }
void set_rdtime(rdtime_func tf = default_rdtime) noexcept { m_rdtime = tf; }

// Push something onto the stack, moving the current stack pointer.
address_t stack_push(const void* data, size_t length);
address_t stack_push(const std::string& string);
template <typename T>
address_t stack_push(const T& pod_type);
// Realign the stack pointer, to make sure that function calls succeed
void realign_stack();
void realign_stack() noexcept;

/// @brief An internal function that facilitates function
/// calls into the guest program.
Expand Down Expand Up @@ -391,7 +391,7 @@ namespace riscv
const MultiThreading<W>& threads() const;
MultiThreading<W>& threads();
bool has_threads() const noexcept { return this->m_mt != nullptr; }
int gettid() const;
int gettid() const noexcept;
// FileDescriptors: Access to translation between guest fds
// and real system fds. The destructor also closes all opened files.
const FileDescriptors& fds() const;
Expand Down
6 changes: 3 additions & 3 deletions lib/libriscv/machine_inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ inline auto Machine<W>::sysargs() const {

template <int W>
template <typename... Args>
inline void Machine<W>::set_result(Args... args) {
inline void Machine<W>::set_result(Args... args) noexcept {
size_t i = 0;
size_t f = 0;
([&] {
if constexpr (std::is_integral_v<Args>) {
cpu.registers().at(REG_ARG0 + i++) = args;
cpu.registers().get(REG_ARG0 + i++) = args;
}
else if constexpr (std::is_same_v<Args, float>)
cpu.registers().getfl(REG_FA0 + f++).set_float(args);
Expand Down Expand Up @@ -244,7 +244,7 @@ address_type<W> Machine<W>::stack_push(const T& type)
}

template <int W> inline
void Machine<W>::realign_stack()
void Machine<W>::realign_stack() noexcept
{
// the RISC-V calling convention mandates a 16-byte alignment
cpu.reg(REG_SP) &= ~address_t{0xF};
Expand Down
8 changes: 4 additions & 4 deletions lib/libriscv/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ namespace riscv
void print_backtrace(std::function<void(std::string_view)>, bool ra = true) const;

// Counts all the memory used by the machine, execute segments, pages, etc.
uint64_t memory_usage_total() const;
uint64_t memory_usage_total() const noexcept;
// Helpers for memory usage
size_t pages_active() const noexcept { return m_pages.size(); }
size_t owned_pages_active() const noexcept;
Expand All @@ -133,14 +133,14 @@ namespace riscv
void set_page_attr(address_t, size_t len, PageAttributes);
void set_pageno_attr(address_t pageno, PageAttributes);
std::string get_page_info(address_t addr) const;
static inline address_t page_number(const address_t address) {
static inline address_t page_number(const address_t address) noexcept {
return address / Page::size();
}
// Page creation & destruction
template <typename... Args>
Page& allocate_page(address_t page, Args&& ...);
void invalidate_cache(address_t pageno, Page*) const;
void invalidate_reset_cache() const;
void invalidate_cache(address_t pageno, Page*) const noexcept;
void invalidate_reset_cache() const noexcept;
void free_pages(address_t, size_t len);
bool free_pageno(address_t pageno);

Expand Down
4 changes: 2 additions & 2 deletions lib/libriscv/memory_inline_pages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ inline const Page& Memory<W>::get_pageno(const address_t pageno) const
}

template <int W> inline void
Memory<W>::invalidate_cache(address_t pageno, Page* page) const
Memory<W>::invalidate_cache(address_t pageno, Page* page) const noexcept
{
// NOTE: It is only possible to keep the write page as long as
// the page tables are node-based. In that case, we only have
Expand All @@ -71,7 +71,7 @@ Memory<W>::invalidate_cache(address_t pageno, Page* page) const
(void)page;
}
template <int W> inline void
Memory<W>::invalidate_reset_cache() const
Memory<W>::invalidate_reset_cache() const noexcept
{
m_rd_cache.pageno = (address_t)-1;
m_wr_cache.pageno = (address_t)-1;
Expand Down
2 changes: 1 addition & 1 deletion lib/libriscv/memory_rw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ namespace riscv
}

template <int W>
uint64_t Memory<W>::memory_usage_total() const
uint64_t Memory<W>::memory_usage_total() const noexcept
{
uint64_t total = 0;
total += sizeof(Machine<W>);
Expand Down
6 changes: 3 additions & 3 deletions lib/libriscv/posix/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,18 @@ void Machine<W>::setup_posix_threads()
}

template <int W>
int Machine<W>::gettid() const
int Machine<W>::gettid() const noexcept
{
if (m_mt) return m_mt->get_tid();
return 0;
}

#ifdef RISCV_32I
template void Machine<4>::setup_posix_threads();
template int Machine<4>::gettid() const;
template int Machine<4>::gettid() const noexcept;
#endif
#ifdef RISCV_64I
template void Machine<8>::setup_posix_threads();
template int Machine<8>::gettid() const;
template int Machine<8>::gettid() const noexcept;
#endif
} // riscv
2 changes: 1 addition & 1 deletion lib/libriscv/threads.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct MultiThreading

thread_t* create(int flags, address_t ctid, address_t ptid,
address_t stack, address_t tls, address_t stkbase, address_t stksize);
int get_tid() const { return m_current->tid; }
int get_tid() const noexcept { return m_current->tid; }
thread_t* get_thread();
thread_t* get_thread(int tid); /* or nullptr */
bool preempt();
Expand Down

0 comments on commit f2f1617

Please sign in to comment.