-
Notifications
You must be signed in to change notification settings - Fork 0
/
tu.py
65 lines (49 loc) · 1.42 KB
/
tu.py
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
import logging
from logging import handlers
from enum import Enum
# global metadata
src_file_name = ''
as_file_name = ''
log_file_name = ''
toks = list()
ast = list()
var_pool = list()
var_tab = dict()
fun_pool = list()
fun_tab = dict()
logger = logging.getLogger("toyc")
PHASE_TAG_STR = "====================================="
SUBPHASE_TAG_STR = "-------------------------------------"
# unit test flag
class FlagCheck(Enum):
INVALID = 0
LEX = 1
AST = 2
CFG = 3
SYMTAB_IR = 4
CALL_GRAPH = 5
PASS = 6
CODEGEN = 7
FLAG_CHECK = FlagCheck.INVALID
def init_logger():
formatter = logging.Formatter(
'%(asctime)s | %(name)s | %(levelname)s: %(message)s')
logger.setLevel(logging.DEBUG)
stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.INFO)
stream_handler.setFormatter(formatter)
logFilePath = log_file_name
file_handler = logging.handlers.TimedRotatingFileHandler(
filename=logFilePath, when='midnight', backupCount=30)
formatter = logging.Formatter('%(message)s')
file_handler.setFormatter(formatter)
file_handler.setLevel(logging.DEBUG)
logger.addHandler(file_handler)
logger.addHandler(stream_handler)
def init_check_flag(check_flag):
global FLAG_CHECK
FLAG_CHECK = FlagCheck(check_flag)
def dump_checksum(file, checksum_str):
with open(file, 'w') as file:
file.write(checksum_str)
file.close()