BFC-Compiler
A C23 Brainfuck compiler
Toggle main menu visibility
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
20
typedef
enum
21
{
22
IR_ADD,
23
IR_MOVE,
24
IR_PUT,
25
IR_GET,
26
IR_SET,
27
IR_LOOP
28
}
bfc_ir_token_type_t
;
29
30
typedef
struct
bfc_ir_block
bfc_ir_block_t;
31
37
typedef
struct
38
{
39
bfc_ir_token_type_t
op;
40
41
union
42
{
43
int64_t imm;
44
bfc_ir_block_t* body;
45
} val;
46
}
bfc_ir_instr_t
;
47
51
struct
bfc_ir_block
52
{
53
bfc_ir_instr_t
* instructions;
54
55
size_t
length;
56
size_t
capacity;
57
};
58
62
[[nodiscard, gnu::const]]
63
bfc_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]]
69
bfc_ir_instr_t
bfc_ir_make_zero_instr
(
bfc_ir_token_type_t
const
ir_token_type);
70
81
[[gnu::nonnull(1, 2)]]
82
bfc_error_t
bfc_ir_create
(bfc_ir_block_t** root_block,
bfc_token_stream_t
const
*
const
tok_stream);
83
91
[[gnu::nonnull(1)]]
92
bfc_error_t
bfc_ir_optimize_rep
(bfc_ir_block_t** ir_block);
93
97
void
bfc_ir_destroy
(bfc_ir_block_t** proot_block);
98
99
#endif
// BFC_IR_H
bfc_error.h
Compiler error values and diagnostics.
bfc_ir_create
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_ir_optimize_rep
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_make_imm_instr
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
bfc_ir_destroy
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
bfc_ir_token_type_t
Operations understood by the optimizer and code generator.
Definition
bfc_ir.h:21
bfc_ir_make_zero_instr
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
bfc_token.h
Brainfuck token definitions and token-stream ownership.
bfc_error_t
Error value propagated through compiler stages.
Definition
bfc_error.h:42
bfc_ir_block
Owning, dynamically sized sequence of IR instructions.
Definition
bfc_ir.h:52
bfc_ir_instr_t
One IR instruction.
Definition
bfc_ir.h:38
bfc_token_stream_t
Owning token sequence produced by the lexer.
Definition
bfc_token.h:51
include
bfc_ir.h
Generated by
1.17.0