BFC-Compiler
A C23 Brainfuck compiler
Loading...
Searching...
No Matches
bfc_codegen_internal.h
Go to the documentation of this file.
1
8#ifndef BFC_CODEGEN_INTERNAL_H
9#define BFC_CODEGEN_INTERNAL_H
10
11#include <stddef.h>
12#include <stdint.h>
13
14#include "bfc_codegen.h"
15#include "bfc_target.h"
16
24typedef struct
25{
26 bfc_target_t target;
27
28 bfc_error_t (*emit_header)(bfc_asm_t* asm_prog);
29 bfc_error_t (*emit_data_section)(bfc_asm_t* asm_prog);
30 bfc_error_t (*emit_symbol)(bfc_asm_t* asm_prog);
31 bfc_error_t (*emit_end)(bfc_asm_t* asm_prog);
32
33 bfc_error_t (*emit_op_add)(bfc_asm_t* asm_prog, int64_t imm);
34 bfc_error_t (*emit_op_move)(bfc_asm_t* asm_prog, int64_t imm);
35 bfc_error_t (*emit_op_get)(bfc_asm_t* asm_prog);
36 bfc_error_t (*emit_op_put)(bfc_asm_t* asm_prog);
37 bfc_error_t (*emit_op_set)(bfc_asm_t* asm_prog, int64_t imm);
38
39 bfc_error_t (*emit_loop_test_z)(bfc_asm_t* asm_prog, const char* label);
40
41 bfc_error_t (*emit_loop_test_nz)(bfc_asm_t* asm_prog, const char* label);
43
51struct bfc_asm
52{
53 const bfc_backend_t* backend;
54
55 size_t label_id;
56
57 char* buffer;
58 size_t length;
59 size_t capacity;
60};
61
68extern const bfc_backend_t BFC_BACKEND_WINDOWS_I386;
69extern const bfc_backend_t BFC_BACKEND_WINDOWS_AARCH64;
70
73
74extern const bfc_backend_t BFC_BACKEND_LINUX_AARCH64;
75extern const bfc_backend_t BFC_BACKEND_LINUX_X86_64;
76
82[[gnu::nonnull(1, 2)]]
83bfc_error_t bfc_codegen_emit_text(bfc_asm_t* asm_prog, const char* text);
84
90[[gnu::nonnull(1, 2)]]
91bfc_error_t bfc_codegen_emit_block(bfc_asm_t* asm_prog, const bfc_ir_block_t* ir_block);
92
98[[gnu::nonnull(1, 2), gnu::format(printf, 2, 3)]]
99bfc_error_t bfc_codegen_emitf(bfc_asm_t* asm_prog, const char* format, ...);
100
101#endif // BFC_CODEGEN_INTERNAL_H
Public assembly code-generation interface.
struct bfc_asm bfc_asm_t
Opaque generated-assembly object.
Definition bfc_codegen.h:18
const bfc_backend_t BFC_BACKEND_MACOS_AARCH64
Immutable backend descriptor exported to generic code generation.
Definition bfc_backend_macos_aarch64.c:276
bfc_error_t bfc_codegen_emitf(bfc_asm_t *asm_prog, const char *format,...)
Formats and appends one assembly fragment.
Definition bfc_codegen.c:175
bfc_error_t bfc_codegen_emit_text(bfc_asm_t *asm_prog, const char *text)
Appends raw text to the assembly buffer.
Definition bfc_codegen.c:91
const bfc_backend_t BFC_BACKEND_MACOS_X86_64
Immutable backend descriptor exported to generic code generation.
Definition bfc_backend_macos_x86_64.c:230
const bfc_backend_t BFC_BACKEND_WINDOWS_X86_64
Backend descriptor declarations.
bfc_error_t bfc_codegen_emit_block(bfc_asm_t *asm_prog, const bfc_ir_block_t *ir_block)
Recursively emits every instruction in an IR block.
Definition bfc_codegen.c:138
Target architecture and operating-system interface.
Mutable assembly-generation state shared by generic codegen and backends.
Definition bfc_codegen_internal.h:52
Immutable callback table implemented by one target backend.
Definition bfc_codegen_internal.h:25
Error value propagated through compiler stages.
Definition bfc_error.h:42
Architecture and operating-system pair used to select a backend.
Definition bfc_target.h:38