File Coverage

lib/SPVM/Builder/src/spvm_field.c
Criterion Covered Total %
statement 2 16 12.5
branch 0 18 0.0
condition n/a
subroutine n/a
pod n/a
total 2 34 5.8


line stmt bran cond sub pod time code
1             // Copyright (c) 2023 Yuki Kimoto
2             // MIT License
3              
4             #include
5             #include
6              
7             #include "spvm_field.h"
8              
9             #include "spvm_allocator.h"
10             #include "spvm_type.h"
11             #include "spvm_op.h"
12             #include "spvm_compiler.h"
13             #include "spvm_basic_type.h"
14              
15 27936           SPVM_FIELD* SPVM_FIELD_new(SPVM_COMPILER* compiler) {
16            
17 27936           return SPVM_ALLOCATOR_alloc_memory_block_permanent(compiler->current_each_compile_allocator, sizeof(SPVM_FIELD));
18             }
19              
20 0           int32_t SPVM_FIELD_get_size(SPVM_COMPILER* compiler, SPVM_FIELD* field) {
21            
22 0           SPVM_TYPE* field_type = field->type;
23            
24             int32_t size;
25 0 0         if (field_type->dimension == 0 && field_type->basic_type->id >= SPVM_NATIVE_C_BASIC_TYPE_ID_BYTE && field_type->basic_type->id <= SPVM_NATIVE_C_BASIC_TYPE_ID_DOUBLE) {
    0          
    0          
26 0 0         if (field_type->basic_type->id == SPVM_NATIVE_C_BASIC_TYPE_ID_BYTE) {
27 0           size = sizeof(int8_t);
28             }
29 0 0         else if (field_type->basic_type->id == SPVM_NATIVE_C_BASIC_TYPE_ID_SHORT) {
30 0           size = sizeof(int16_t);
31             }
32 0 0         else if (field_type->basic_type->id == SPVM_NATIVE_C_BASIC_TYPE_ID_INT || field_type->basic_type->id == SPVM_NATIVE_C_BASIC_TYPE_ID_FLOAT) {
    0          
33 0           size = sizeof(int32_t);
34             }
35 0 0         else if (field_type->basic_type->id == SPVM_NATIVE_C_BASIC_TYPE_ID_LONG || field_type->basic_type->id == SPVM_NATIVE_C_BASIC_TYPE_ID_DOUBLE) {
    0          
36 0           size = sizeof(int64_t);
37             }
38             else {
39 0           assert(0);
40             }
41             }
42             else {
43 0           size = sizeof(void*);
44             }
45            
46 0           return size;
47             }