-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdebug.c
130 lines (114 loc) · 2.97 KB
/
debug.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <stdio.h>
#include "debug.h"
#include "code.h"
#include "options.h"
char *codestr[OP_LENGTH] = {"",
"형", "항", "핫", "흣", "흡", "흑", "❤", "♡", "?", "!"
};
char *heartstr[] = {"",
"♥", "❤", "💕", "💖", "💗", "💘", "💙", "💚", "💛", "💜", "💝"
};
void print_debug_start ()
{
printf("프로그램을 실행합니다 (아무 키나 누르세요):");
}
void print_tree (struct Heart_Tree *t)
{
if (!t) {putchar('_'); return ;}
if (t->opcode == OP_SAVE) printf("%s", heartstr[t->value]);
else if (t->opcode == OP_REF) printf("%s", codestr[t->opcode]);
else {
printf("%s", codestr[t->opcode]);
print_tree(t->left);
print_tree(t->right);
}
}
void print_debug_info (struct Code *code)
{
int len;
int max_len = options.max_len;
for (len = 0; max_len; max_len /= 10, len++);
fflush(stdout);
printf("[%*d] ", len, code->code_num);
printf("%s %d %d", codestr[code->opcode], code->charcnt, code->dotcnt);
if (code->tree) putchar(' '), print_tree(code->tree);
puts("");
}
void print_stack_info ( struct Code *code,
struct Stack *stack_current,
struct Stack *Stack_Hash[10])
{
printf("현재 스택: %d\n", stack_current->stack_value);
for (int i = 0; i < 10; i++)
{
struct Stack *stack_debug = Stack_Hash[i];
while (stack_debug)
{
if (stack_debug->stack_value == 0 ||
stack_debug->stack_value == 1 ||
stack_debug->stack_value == 2)
{
stack_debug = stack_debug->next;
continue;
}
if (stack_debug->stack_value == options.pop_stack) {
printf("\033[1;31m");
options.pop_stack = 0;
}
printf("\t%d번 스택: ->", stack_debug->stack_value);
printf("\033[0m");
struct Value *v = stack_debug->value;
while (v)
{
if (v == options.last_push) {
printf("\033[1;33m");
options.last_push = NULL;
}
if (v->nan) printf(" (NaN)");
else printf(" (%lld/%lld)", v->top, v->bottom);
printf("\033[0m");
v = v->stackp;
}
puts("");
stack_debug = stack_debug->next;
}
}
}
void print_heart_info (struct Pointers *Pointers[12], struct Code *ref)
{
puts("등록된 명령어: ");
int len, max_len = options.max_len;
for (len = 0; max_len; max_len /= 10, len++);
for (int i = 0; i < 12; i++)
{
int is_print = 0;
struct Pointers *p = Pointers[i];
while (p)
{
printf("\t");
struct Code *code = p->code;
if (code == ref) printf("*");
printf("(%d, %s) [%*d] ", p->tag, heartstr[i], len, code->code_num);
printf("%s ", codestr[code->opcode]);
printf("%d %d", code->charcnt, code->dotcnt);
if (code->tree) putchar(' '), print_tree(code->tree);
p = p->next;
is_print = 1;
}
if (is_print) puts("");
}
}
void print_value_start ()
{
puts("출력 내용: \033[1;36m");
}
void print_value_end ()
{
puts("\033[0m\n");
}
void print_program_end(int endcode)
{
puts("\033[0m");
if (endcode) puts("\n\n프로그램이 비정상적으로 종료되었습니다\n");
else puts("\n\n프로그램이 정상적으로 종료되었습니다\n");
}