BFC-Compiler
A C23 Brainfuck compiler
Loading...
Searching...
No Matches
bfc_ir.h
Go to the documentation of this file.
1
8#ifndef BFC_IR_H
9#define BFC_IR_H
10
11#include <stddef.h>
12#include <stdint.h>
13
14#include "bfc_error.h"
15#include "bfc_token.h"
16
20typedef enum
21{
22 IR_ADD,
23 IR_MOVE,
24 IR_PUT,
25 IR_GET,
26 IR_SET,
27 IR_LOOP
29
30typedef struct bfc_ir_block bfc_ir_block_t;
31
37typedef struct
38{
40
41 union
42 {
43 int64_t imm;
44 bfc_ir_block_t* body;
45 } val;
47
52{
53 bfc_ir_instr_t* instructions;
54
55 size_t length;
56 size_t capacity;
57};
58
62[[nodiscard, gnu::const]]
63bfc_ir_instr_t bfc_ir_make_imm_instr(bfc_ir_token_type_t const ir_token_type, int64_t const imm);
64
68[[nodiscard, gnu::const]]
70
81[[gnu::nonnull(1, 2)]]
82bfc_error_t bfc_ir_create(bfc_ir_block_t** root_block, bfc_token_stream_t const* const tok_stream);
83
91[[gnu::nonnull(1)]]
92bfc_error_t bfc_ir_optimize_rep(bfc_ir_block_t** ir_block);
93
97void bfc_ir_destroy(bfc_ir_block_t** proot_block);
98
99#endif // BFC_IR_H
Compiler error values and diagnostics.
bfc_error_t bfc_ir_create(bfc_ir_block_t **root_block, bfc_token_stream_t const *const tok_stream)
Builds a nested IR tree from the token stream.
Definition bfc_ir.c:56
bfc_error_t bfc_ir_optimize_rep(bfc_ir_block_t **ir_block)
Optimizes repeated operations and recognized clear loops in place.
Definition bfc_ir.c:236
bfc_ir_instr_t bfc_ir_make_imm_instr(bfc_ir_token_type_t const ir_token_type, int64_t const imm)
Constructs an immediate-valued IR instruction.
Definition bfc_ir.c:35
void bfc_ir_destroy(bfc_ir_block_t **proot_block)
Recursively destroys an IR block and all nested loop bodies.
Definition bfc_ir.c:340
bfc_ir_token_type_t
Operations understood by the optimizer and code generator.
Definition bfc_ir.h:21
bfc_ir_instr_t bfc_ir_make_zero_instr(bfc_ir_token_type_t const ir_token_type)
Constructs an IR instruction with a zero-initialized operand union.
Definition bfc_ir.c:46
Brainfuck token definitions and token-stream ownership.
Error value propagated through compiler stages.
Definition bfc_error.h:42
Owning, dynamically sized sequence of IR instructions.
Definition bfc_ir.h:52
One IR instruction.
Definition bfc_ir.h:38
Owning token sequence produced by the lexer.
Definition bfc_token.h:51