|
| 1 | +/** |
| 2 | + * @file frame.h |
| 3 | + * @brief Frame |
| 4 | + * File containing the definition of a frame structure and functions to realize |
| 5 | + * operations to change it. |
| 6 | + * |
| 7 | + */ |
| 8 | + |
1 | 9 | #pragma once
|
2 | 10 |
|
3 | 11 | #include <stdio.h>
|
|
6 | 14 | #include <assert.h>
|
7 | 15 | #include "classfile.h"
|
8 | 16 |
|
| 17 | +/** |
| 18 | + * @brief Frame structure. |
| 19 | + * |
| 20 | + * Structure that stores the information that defines and is utilized by a frame from a JVM. |
| 21 | + */ |
9 | 22 | typedef struct Frame {
|
10 |
| - void *jvm; /* pointer to respective jvm reference */ |
11 |
| - uint32_t n_locals; /* computed at compile time */ |
12 |
| - uint64_t *locals; /* array of local variables */ |
13 |
| - uint32_t n_operands; /* computed at compile time */ |
14 |
| - uint64_t *operands; /* stack of operands */ |
15 |
| - uint32_t i; /* top of stack index */ |
16 |
| - cp_info *cp; /* reference to constant pool of class */ |
17 |
| - uint32_t pc; /* jvm's pc upon method call */ |
18 |
| - int32_t class_index; /* class index in method area */ |
19 |
| - int32_t method_index; /* method index in class */ |
| 23 | + void *jvm; /**< pointer to respective jvm reference */ |
| 24 | + uint32_t n_locals; /**< computed at compile time */ |
| 25 | + uint64_t *locals; /**< array of local variables */ |
| 26 | + uint32_t n_operands; /**< computed at compile time */ |
| 27 | + uint64_t *operands; /**< stack of operands */ |
| 28 | + uint32_t i; /**< top of stack index */ |
| 29 | + cp_info *cp; /**< reference to constant pool of class */ |
| 30 | + uint32_t pc; /**< jvm's pc upon method call */ |
| 31 | + int32_t class_index; /**< class index in method area */ |
| 32 | + int32_t method_index; /**< method index in class */ |
20 | 33 | } Frame;
|
21 | 34 |
|
| 35 | +/** |
| 36 | + * Initializes a frame pointed by a jvm |
| 37 | + */ |
22 | 38 | void init_frame(Frame *f, void *jvm, uint32_t n_locals, uint32_t n_operands, cp_info *cp,
|
23 | 39 | int32_t class_index, int32_t method_index);
|
| 40 | + |
| 41 | +/** |
| 42 | + * Deinitializes frame memory area pointed to by jvm pointer. |
| 43 | + * Notably, locals, operands, and auxiliary structures are freed |
| 44 | + * @param f non-null pointer to a frame struct to be deinitialized |
| 45 | + */ |
24 | 46 | void deinit_frame(Frame *f);
|
25 | 47 |
|
| 48 | +/** |
| 49 | + * Push an integer to the top of the frame operand stack. |
| 50 | + * @param operand integer operand to be added to the stack. |
| 51 | + * @param f pointer to the current frame. |
| 52 | + */ |
26 | 53 | void push_stack(Frame *f, uint64_t operand);
|
| 54 | + |
| 55 | +/** |
| 56 | + * Pop an integer of the top of the frame operand stack. |
| 57 | + * @param f pointer to the current frame. |
| 58 | + */ |
27 | 59 | uint64_t pop_stack(Frame *f);
|
| 60 | + |
| 61 | +/** |
| 62 | + * Return de value of an integer of the top of the frame operand stack. |
| 63 | + * @param f pointer to the current frame. |
| 64 | + */ |
28 | 65 | uint64_t peek_stack(Frame *f);
|
29 | 66 |
|
| 67 | + |
| 68 | +/** |
| 69 | + * Push a double to the top of the frame operand stack. |
| 70 | + * @param operand double operand to be added to the stack. |
| 71 | + * @param f pointer to the current frame. |
| 72 | + */ |
30 | 73 | void push_stack_double(Frame *f, double d);
|
| 74 | + |
| 75 | +/** |
| 76 | + * Pop a double of the top of the frame operand stack. |
| 77 | + * @param f pointer to the current frame. |
| 78 | + */ |
31 | 79 | double pop_stack_double(Frame *f);
|
32 | 80 |
|
| 81 | + |
| 82 | +/** |
| 83 | + * Push a long to the top of the frame operand stack. |
| 84 | + * @param operand long operand to be added to the stack. |
| 85 | + * @param f pointer to the current frame. |
| 86 | + */ |
33 | 87 | void push_stack_long(Frame *f, int64_t x);
|
| 88 | + |
| 89 | +/** |
| 90 | + * Pop a long of the top of the frame operand stack. |
| 91 | + * @param f pointer to the current frame. |
| 92 | + */ |
34 | 93 | int64_t pop_stack_long(Frame *f);
|
35 | 94 |
|
| 95 | + |
| 96 | +/** |
| 97 | + * Push a float to the top of the frame operand stack. |
| 98 | + * @param operand float operand to be added to the stack. |
| 99 | + * @param f pointer to the current frame. |
| 100 | + */ |
36 | 101 | void push_stack_float(Frame *f, float x);
|
| 102 | + |
| 103 | +/** |
| 104 | + * Pop a float of the top of the frame operand stack. |
| 105 | + * @param f pointer to the current frame. |
| 106 | + */ |
37 | 107 | float pop_stack_float(Frame *f);
|
38 | 108 |
|
| 109 | +/** |
| 110 | + * Push a 32 bits integer to the top of the frame operand stack. |
| 111 | + * @param operand integer operand to be added to the stack. |
| 112 | + * @param f pointer to the current frame. |
| 113 | + */ |
39 | 114 | void push_stack_int(Frame *f, int32_t x);
|
| 115 | + |
| 116 | +/** |
| 117 | + * Pop a 32 bits integer of the top of the frame operand stack. |
| 118 | + * @param f pointer to the current frame. |
| 119 | + */ |
40 | 120 | int32_t pop_stack_int(Frame *f);
|
41 | 121 |
|
| 122 | + |
| 123 | +/** |
| 124 | + * Push a void pointer to the top of the frame operand stack. |
| 125 | + * @param operand pointer operand to be added to the stack. |
| 126 | + * @param f pointer to the current frame. |
| 127 | + */ |
42 | 128 | void push_stack_pointer(Frame *f, void *ptr);
|
| 129 | + |
| 130 | +/** |
| 131 | + * Pop a void pointer of the top of the frame operand stack. |
| 132 | + * @param f pointer to the current frame. |
| 133 | + */ |
43 | 134 | void *pop_stack_pointer(Frame *f);
|
44 | 135 |
|
| 136 | + |
| 137 | +/** |
| 138 | + * Push a byte to the top of the frame operand stack. |
| 139 | + * @param operand byte operand to be added to the stack. |
| 140 | + * @param f pointer to the current frame. |
| 141 | + */ |
45 | 142 | void push_stack_byte(Frame *f, int8_t x);
|
| 143 | + |
| 144 | +/** |
| 145 | + * Pop a byte of the top of the frame operand stack. |
| 146 | + * @param f pointer to the current frame. |
| 147 | + */ |
46 | 148 | int8_t pop_stack_byte(Frame *f);
|
47 | 149 |
|
48 | 150 | void frame_set_local(Frame *f, uint32_t index, uint64_t value);
|
|
0 commit comments