Rewrote the comments in the libraries under 'includes' in English (excluding those inside folders)
This commit is contained in:
@@ -218,9 +218,9 @@ def create_global_string(pool: memhub.MemBuddy | t.CPtr, mod: LLVMModule | t.CPt
|
||||
global_set_constant(gv, 1)
|
||||
|
||||
# 构造初始化值文本: c"contents\00"
|
||||
# LLVM IR 字符串字面量格式: c"<chars>" 其中非打印字符用 \xx 转义
|
||||
# 这里简单处理: 直接复制原始字节,末尾加 \00
|
||||
init_buf: t.CChar | t.CPtr = pool.alloc(slen + 8) # c"..." + \00 + "
|
||||
# LLVM IR 字符串字面量格式: c"<chars>" 其中 " 和 \ 及非打印字符用 \xx 转义
|
||||
# 缓冲区大小: 最坏情况每个字符4字节(\xx)+ c"..." + \00 + "
|
||||
init_buf: t.CChar | t.CPtr = pool.alloc(slen * 4 + 8)
|
||||
if init_buf is None: return None
|
||||
pos: t.CSizeT = 0
|
||||
init_buf[pos] = 'c'
|
||||
@@ -229,8 +229,26 @@ def create_global_string(pool: memhub.MemBuddy | t.CPtr, mod: LLVMModule | t.CPt
|
||||
pos += 1
|
||||
i: t.CSizeT = 0
|
||||
while i < slen:
|
||||
init_buf[pos] = text[i]
|
||||
pos += 1
|
||||
ch: t.CUInt8T = text[i]
|
||||
if ch == 0x22 or ch == 0x5C or ch < 0x20 or ch >= 0x7F:
|
||||
# 需要转义: " → \22, \ → \5c, 非打印字符 → \xx
|
||||
init_buf[pos] = '\\'
|
||||
pos += 1
|
||||
hi: t.CInt = (ch >> 4) & 0x0F
|
||||
lo: t.CInt = ch & 0x0F
|
||||
if hi < 10:
|
||||
init_buf[pos] = 0x30 + hi
|
||||
else:
|
||||
init_buf[pos] = 0x61 + hi - 10
|
||||
pos += 1
|
||||
if lo < 10:
|
||||
init_buf[pos] = 0x30 + lo
|
||||
else:
|
||||
init_buf[pos] = 0x61 + lo - 10
|
||||
pos += 1
|
||||
else:
|
||||
init_buf[pos] = ch
|
||||
pos += 1
|
||||
i += 1
|
||||
# 末尾 NUL 字节
|
||||
init_buf[pos] = '\\'
|
||||
|
||||
Reference in New Issue
Block a user