| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
// Copyright (c) 2023 Yuki Kimoto |
|
2
|
|
|
|
|
|
|
// MIT License |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
#include |
|
5
|
|
|
|
|
|
|
#include |
|
6
|
|
|
|
|
|
|
#include |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#include "spvm_opcode_list.h" |
|
9
|
|
|
|
|
|
|
#include "spvm_allocator.h" |
|
10
|
|
|
|
|
|
|
#include "spvm_compiler.h" |
|
11
|
|
|
|
|
|
|
#include "spvm_opcode.h" |
|
12
|
|
|
|
|
|
|
|
|
13
|
306890
|
|
|
|
|
|
SPVM_OPCODE_LIST* SPVM_OPCODE_LIST_new(SPVM_COMPILER* compiler) { |
|
14
|
|
|
|
|
|
|
(void)compiler; |
|
15
|
|
|
|
|
|
|
|
|
16
|
306890
|
|
|
|
|
|
SPVM_OPCODE_LIST* opcodes = SPVM_ALLOCATOR_alloc_memory_block_permanent(compiler->current_each_compile_allocator, sizeof(SPVM_OPCODE_LIST)); |
|
17
|
306890
|
|
|
|
|
|
opcodes->capacity = 64; |
|
18
|
306890
|
|
|
|
|
|
opcodes->length = 0; |
|
19
|
|
|
|
|
|
|
|
|
20
|
306890
|
|
|
|
|
|
int64_t values_size = (int64_t)opcodes->capacity * (int64_t)sizeof(SPVM_OPCODE); |
|
21
|
306890
|
|
|
|
|
|
SPVM_OPCODE* values = SPVM_ALLOCATOR_alloc_memory_block_permanent(compiler->current_each_compile_allocator, values_size); |
|
22
|
306890
|
|
|
|
|
|
opcodes->values = values; |
|
23
|
|
|
|
|
|
|
|
|
24
|
306890
|
|
|
|
|
|
return opcodes; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
9351432
|
|
|
|
|
|
void SPVM_OPCODE_LIST_push_opcode(SPVM_COMPILER* compiler, SPVM_OPCODE_LIST* opcodes, SPVM_OPCODE* opcode) { |
|
28
|
|
|
|
|
|
|
(void)compiler; |
|
29
|
|
|
|
|
|
|
|
|
30
|
9351432
|
|
|
|
|
|
int32_t length = opcodes->length; |
|
31
|
9351432
|
|
|
|
|
|
int32_t capacity = opcodes->capacity; |
|
32
|
|
|
|
|
|
|
|
|
33
|
9351432
|
100
|
|
|
|
|
if (length >= capacity) { |
|
34
|
61937
|
|
|
|
|
|
int32_t new_capacity = capacity * 2; |
|
35
|
|
|
|
|
|
|
|
|
36
|
61937
|
|
|
|
|
|
int64_t new_values_size = (int64_t)new_capacity * (int64_t)sizeof(SPVM_OPCODE); |
|
37
|
61937
|
|
|
|
|
|
SPVM_OPCODE* new_values = SPVM_ALLOCATOR_alloc_memory_block_permanent(compiler->current_each_compile_allocator, new_values_size); |
|
38
|
61937
|
|
|
|
|
|
memcpy(new_values, opcodes->values, capacity * sizeof(SPVM_OPCODE)); |
|
39
|
61937
|
|
|
|
|
|
opcodes->values = new_values; |
|
40
|
|
|
|
|
|
|
|
|
41
|
61937
|
|
|
|
|
|
opcodes->capacity = new_capacity; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
9351432
|
50
|
|
|
|
|
assert(opcode); |
|
45
|
9351432
|
|
|
|
|
|
memcpy(&opcodes->values[length], opcode, sizeof(SPVM_OPCODE)); |
|
46
|
|
|
|
|
|
|
|
|
47
|
9351432
|
|
|
|
|
|
opcodes->length++; |
|
48
|
9351432
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
void SPVM_OPCODE_LIST_free(SPVM_COMPILER* compiler, SPVM_OPCODE_LIST* opcodes) { |
|
51
|
|
|
|
|
|
|
(void)compiler; |
|
52
|
0
|
|
|
|
|
|
} |