Affix
view release on metacpan or search on metacpan
infix/src/arch/riscv/abi_riscv64_emitters.h view on Meta::CPAN
#pragma once
/**
* Copyright (c) 2026 Sanko Robinson
*
* This source code is dual-licensed under the Artistic License 2.0 or the MIT License.
* You may choose to use this code under the terms of either license.
*
* SPDX-License-Identifier: (Artistic-2.0 OR MIT)
*
* The documentation blocks within this file are licensed under the
* Creative Commons Attribution 4.0 International License (CC BY 4.0).
*
* SPDX-License-Identifier: CC-BY-4.0
*/
/**
* @file abi_riscv64_emitters.h
* @brief Public interface for emitting RISC-V (RV64GC) instructions.
* @ingroup internal_abi_riscv64
*
* @internal
* The RISC-V backend is compiled as a "unity build" (`abi_riscv64.c` is included at the end of
* `src/jit/trampoline.c`), so the implementation of these functions lives in the corresponding
* `abi_riscv64_emitters.c` file, and this header declares their prototypes for use elsewhere.
*
* Every emitter appends a single, valid 32-bit RISC-V instruction to a `code_buffer`.
* @endinternal
*/
#include "common/infix_internals.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
/**
* @internal
* @brief Emit an `addi rd, rs1, imm` instruction. Used for stack frame adjustment and
* constant arithmetic.
*/
INFIX_INTERNAL void infix_riscv64_emit_addi(code_buffer * buf, uint8_t rd, uint8_t rs1, int32_t imm);
/**
* @internal
* @brief Emit an `addiw rd, rs1, imm` instruction (the RV64I 32-bit sign-extending variant).
*/
INFIX_INTERNAL void infix_riscv64_emit_addiw(code_buffer * buf, uint8_t rd, uint8_t rs1, int32_t imm);
/**
* @internal
* @brief Emit an `add rd, rs1, rs2` instruction. Used to compute pointers and offsets.
*/
INFIX_INTERNAL void infix_riscv64_emit_add(code_buffer * buf, uint8_t rd, uint8_t rs1, uint8_t rs2);
/**
* @internal
* @brief Emit a `sub rd, rs1, rs2` instruction.
*/
INFIX_INTERNAL void infix_riscv64_emit_sub(code_buffer * buf, uint8_t rd, uint8_t rs1, uint8_t rs2);
/**
* @internal
* @brief Emit a `slli rd, rs1, shamt` instruction.
*/
INFIX_INTERNAL void infix_riscv64_emit_slli(code_buffer * buf, uint8_t rd, uint8_t rs1, uint8_t shamt);
/**
* @internal
* @brief Emit a `srli rd, rs1, shamt` instruction.
*/
INFIX_INTERNAL void infix_riscv64_emit_srli(code_buffer * buf, uint8_t rd, uint8_t rs1, uint8_t shamt);
/**
* @internal
* @brief Emit a `lui rd, imm20` instruction.
*/
INFIX_INTERNAL void infix_riscv64_emit_lui(code_buffer * buf, uint8_t rd, uint32_t imm20);
/**
* @internal
* @brief Emit an `auipc rd, imm20` instruction.
*/
INFIX_INTERNAL void infix_riscv64_emit_auipc(code_buffer * buf, uint8_t rd, uint32_t imm20);
/**
* @internal
* @brief Emit a `jal rd, imm20` instruction (a near-relative call/jump).
*/
INFIX_INTERNAL void infix_riscv64_emit_jal(code_buffer * buf, uint8_t rd, int32_t imm20);
/**
* @internal
* @brief Emit a `jalr rd, rs1, imm12` instruction (an indirect call/jump).
*/
INFIX_INTERNAL void infix_riscv64_emit_jalr(code_buffer * buf, uint8_t rd, uint8_t rs1, int32_t imm12);
/**
* @internal
* @brief Emit a `beq rs1, rs2, imm12` instruction.
*/
INFIX_INTERNAL void infix_riscv64_emit_beq(code_buffer * buf, uint8_t rs1, uint8_t rs2, int32_t imm12);
/**
* @internal
* @brief Emit a `bne rs1, rs2, imm12` instruction.
*/
INFIX_INTERNAL void infix_riscv64_emit_bne(code_buffer * buf, uint8_t rs1, uint8_t rs2, int32_t imm12);
/**
* @internal
( run in 0.392 second using v1.01-cache-2.11-cpan-2e0ccfb7a10 )