BFC-Compiler
A C23 Brainfuck compiler
Loading...
Searching...
No Matches
bfc_backend_macos_x86_64.c File Reference

macOS x86-64 assembly backend. More...

#include "bfc_codegen_internal.h"
#include <inttypes.h>
#include <stddef.h>
#include <stdint.h>
#include "bfc_config.h"

Functions

static bfc_error_t emit_load_u64 (bfc_asm_t *asm_prog, uint64_t value)
 Materializes a full-width unsigned immediate in scratch register r11.
static bfc_error_t emit_header (bfc_asm_t *asm_prog)
 Emits Intel-syntax and text-section directives.
static bfc_error_t emit_data_section (bfc_asm_t *asm_prog)
 Declares the zero-initialized Brainfuck tape in Mach-O BSS.
static bfc_error_t emit_symbol (bfc_asm_t *asm_prog)
 Emits the macOS main symbol, stack-aligned prologue, and tape address.
static bfc_error_t emit_end (bfc_asm_t *asm_prog)
 Emits the ABI-compliant epilogue and zero process status.
static bfc_error_t emit_op_add (bfc_asm_t *asm_prog, int64_t imm)
 Lowers wrapping byte-cell addition.
static bfc_error_t emit_op_move (bfc_asm_t *asm_prog, int64_t imm)
 Moves the tape pointer using direct or register materialized immediates.
static bfc_error_t emit_op_get (bfc_asm_t *asm_prog)
 Calls getchar, maps EOF to zero, and stores one byte.
static bfc_error_t emit_op_put (bfc_asm_t *asm_prog)
 Zero-extends the current cell and calls putchar.
static bfc_error_t emit_op_set (bfc_asm_t *asm_prog, int64_t imm)
 Stores an immediate byte in the current cell.
static bfc_error_t emit_loop_test_z (bfc_asm_t *asm_prog, const char *label)
 Branches to the supplied label when the current cell is zero.
static bfc_error_t emit_loop_test_nz (bfc_asm_t *asm_prog, const char *label)
 Branches to the supplied label when the current cell is nonzero.

Variables

const bfc_backend_t BFC_BACKEND_MACOS_X86_64
 Immutable backend descriptor exported to generic code generation.

Detailed Description

macOS x86-64 assembly backend.

Implements Mach-O symbols, System V-style x86-64 calling conventions used by macOS, and Intel-syntax lowering for all IR operations.

Function Documentation

◆ emit_data_section()

bfc_error_t emit_data_section ( bfc_asm_t * asm_prog)
static

Declares the zero-initialized Brainfuck tape in Mach-O BSS.

◆ emit_end()

bfc_error_t emit_end ( bfc_asm_t * asm_prog)
static

Emits the ABI-compliant epilogue and zero process status.

◆ emit_header()

bfc_error_t emit_header ( bfc_asm_t * asm_prog)
static

Emits Intel-syntax and text-section directives.

◆ emit_load_u64()

bfc_error_t emit_load_u64 ( bfc_asm_t * asm_prog,
uint64_t value )
static

Materializes a full-width unsigned immediate in scratch register r11.

◆ emit_loop_test_nz()

bfc_error_t emit_loop_test_nz ( bfc_asm_t * asm_prog,
const char * label )
static

Branches to the supplied label when the current cell is nonzero.

◆ emit_loop_test_z()

bfc_error_t emit_loop_test_z ( bfc_asm_t * asm_prog,
const char * label )
static

Branches to the supplied label when the current cell is zero.

◆ emit_op_add()

bfc_error_t emit_op_add ( bfc_asm_t * asm_prog,
int64_t imm )
static

Lowers wrapping byte-cell addition.

◆ emit_op_get()

bfc_error_t emit_op_get ( bfc_asm_t * asm_prog)
static

Calls getchar, maps EOF to zero, and stores one byte.

◆ emit_op_move()

bfc_error_t emit_op_move ( bfc_asm_t * asm_prog,
int64_t imm )
static

Moves the tape pointer using direct or register materialized immediates.

◆ emit_op_put()

bfc_error_t emit_op_put ( bfc_asm_t * asm_prog)
static

Zero-extends the current cell and calls putchar.

◆ emit_op_set()

bfc_error_t emit_op_set ( bfc_asm_t * asm_prog,
int64_t imm )
static

Stores an immediate byte in the current cell.

◆ emit_symbol()

bfc_error_t emit_symbol ( bfc_asm_t * asm_prog)
static

Emits the macOS main symbol, stack-aligned prologue, and tape address.

Variable Documentation

◆ BFC_BACKEND_MACOS_X86_64

const bfc_backend_t BFC_BACKEND_MACOS_X86_64
Initial value:
= {
.target = {
.arch = BFC_ARCH_X86_64,
.os = BFC_OS_MACOS,
},
.emit_header = emit_header,
.emit_data_section = emit_data_section,
.emit_symbol = emit_symbol,
.emit_end = emit_end,
.emit_op_add = emit_op_add,
.emit_op_move = emit_op_move,
.emit_op_get = emit_op_get,
.emit_op_put = emit_op_put,
.emit_op_set = emit_op_set,
.emit_loop_test_z = emit_loop_test_z,
.emit_loop_test_nz = emit_loop_test_nz,
}
static bfc_error_t emit_data_section(bfc_asm_t *asm_prog)
Declares the zero-initialized Brainfuck tape in Mach-O BSS.
Definition bfc_backend_macos_aarch64.c:74
static bfc_error_t emit_op_set(bfc_asm_t *asm_prog, int64_t imm)
Stores a normalized immediate byte in the current cell.
Definition bfc_backend_macos_aarch64.c:224
static bfc_error_t emit_op_move(bfc_asm_t *asm_prog, int64_t imm)
Moves the tape pointer using direct or register materialized immediates.
Definition bfc_backend_macos_aarch64.c:155
static bfc_error_t emit_loop_test_nz(bfc_asm_t *asm_prog, const char *label)
Uses cbnz to branch when the current cell is nonzero.
Definition bfc_backend_macos_aarch64.c:263
static bfc_error_t emit_loop_test_z(bfc_asm_t *asm_prog, const char *label)
Uses cbz to branch when the current cell is zero.
Definition bfc_backend_macos_aarch64.c:247
static bfc_error_t emit_symbol(bfc_asm_t *asm_prog)
Emits the macOS main symbol, frame setup, saved tape register, and tape address.
Definition bfc_backend_macos_aarch64.c:92
static bfc_error_t emit_op_put(bfc_asm_t *asm_prog)
Loads the current byte and calls putchar.
Definition bfc_backend_macos_aarch64.c:210
static bfc_error_t emit_op_get(bfc_asm_t *asm_prog)
Calls getchar, maps EOF to zero, and stores one byte.
Definition bfc_backend_macos_aarch64.c:194
static bfc_error_t emit_header(bfc_asm_t *asm_prog)
Emits the initial text-section directives.
Definition bfc_backend_macos_aarch64.c:60
static bfc_error_t emit_op_add(bfc_asm_t *asm_prog, int64_t imm)
Loads, adds, and stores one wrapping byte cell.
Definition bfc_backend_macos_aarch64.c:131
static bfc_error_t emit_end(bfc_asm_t *asm_prog)
Restores callee-saved state and returns a zero process status.
Definition bfc_backend_macos_aarch64.c:114

Immutable backend descriptor exported to generic code generation.