重置上传,新增了多个标准库,开始 TransPyV 自举实验

This commit is contained in:
2026-07-19 11:38:15 +08:00
parent 796222a300
commit 4e66207ba1
1041 changed files with 6597 additions and 27814 deletions

View File

@@ -97,36 +97,50 @@ def test_build_add(pool: memhub.MemPool | t.CPtr):
core: llvmlite.LLVMTypeCore | t.CPtr = llvmlite.LLVMTypeCore(pool)
mcore: llvmlite.LLVMModuleCore | t.CPtr = llvmlite.LLVMModuleCore(pool)
ty_i32: llvmlite.LLVMType | t.CPtr = core.Int32()
testcheck.info("DBG: step1 core/ty_i32 ok")
# 创建模块 + 函数
mod: llvmlite.Module | t.CPtr = mcore.NewModule("test_add")
testcheck.info("DBG: step2 NewModule ok")
func: llvmlite.Function | t.CPtr = mcore.CreateFunction(mod, "add", ty_i32)
testcheck.info("DBG: step3 CreateFunction ok")
# 添加参数
mcore.AddParam(func, ty_i32, "%a")
testcheck.info("DBG: step4 AddParam a ok")
mcore.AddParam(func, ty_i32, "%b")
testcheck.info("DBG: step5 AddParam b ok")
# 创建 entry 块
entry: llvmlite.BasicBlock | t.CPtr = mcore.CreateBlock(func, "entry")
testcheck.info("DBG: step6 CreateBlock ok")
# 创建 builder
builder: llvmlite.IRBuilder | t.CPtr = mcore.NewBuilder(func)
testcheck.info("DBG: step7 NewBuilder ok")
llvmlite.position_at_end(builder, entry)
testcheck.info("DBG: step8 position_at_end ok")
# 为参数创建 Value 包装
v_a: llvmlite.Value | t.CPtr = mcore.SSAValue(ty_i32, "%a")
testcheck.info("DBG: step9 SSAValue a ok")
v_b: llvmlite.Value | t.CPtr = mcore.SSAValue(ty_i32, "%b")
testcheck.info("DBG: step10 SSAValue b ok")
# %0 = add i32 %a, %b
v_c: llvmlite.Value | t.CPtr = llvmlite.build_add(builder, v_a, v_b)
testcheck.info("DBG: step11 build_add ok")
# ret i32 %0
llvmlite.build_ret(builder, v_c)
testcheck.info("DBG: step12 build_ret ok")
# 打印函数
buf: t.CChar | t.CPtr = pool.alloc(4096)
testcheck.info("DBG: step13 pool.alloc buf ok")
buf[0] = 0
mcore.PrintFunction(buf, 4096, func)
testcheck.info("DBG: step14 PrintFunction ok")
testcheck.info(buf)
# 验证关键内容

View File

@@ -1 +0,0 @@
{"llvmlite.__values": "05c11f22675c60cb", "__values": "05c11f22675c60cb", "llvmlite.__module": "21a7fcfc665f75ef", "__module": "21a7fcfc665f75ef", "atom": "271ea3decb810db2", "linkedlist": "2d39c6c7d3557b3e", "llvmlite.__types": "455ff4e74c3dbfb0", "__types": "455ff4e74c3dbfb0", "llvmlite.__builder": "46ea362b72c10a9e", "__builder": "46ea362b72c10a9e", "stdio": "6f62fe05c5ea1ceb", "stdarg": "71e0a3ffcb3ebfad", "w32.win32base": "7e529fe7a078cfef", "win32base": "7e529fe7a078cfef", "stdlib": "90c53dd6db8d41cf", "llvmlite.__init__": "95394ca8da0f655a", "__init__": "95394ca8da0f655a", "llvmlite": "95394ca8da0f655a", "string": "ab6e54ba9a669f76", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "viperlib": "c3b259b4059f8668", "viperio": "c9f4be41ca1cc2b4", "llvmlite.__verify": "d4117f5e00a6c3b5", "__verify": "d4117f5e00a6c3b5", "testcheck": "dd3002730623424b", "llvmlite.__function": "e0b84369e50c937c", "__function": "e0b84369e50c937c", "memhub": "ee084e9fc6ee413a", "stdint": "f5522571bcce7bcb", "main.__types": "455ff4e74c3dbfb0", "main.__function": "e0b84369e50c937c", "main.__values": "05c11f22675c60cb", "main.__module": "21a7fcfc665f75ef"}

View File

@@ -0,0 +1 @@
{"testcheck": "14d33679f7fadf1f", "llvmlite.__types": "15f1ded02f3aa5bc", "__types": "15f1ded02f3aa5bc", "llvmlite.__module": "21a7fcfc665f75ef", "__module": "21a7fcfc665f75ef", "atom": "271ea3decb810db2", "linkedlist": "2d39c6c7d3557b3e", "llvmlite.__function": "4dad2ba72ed7ba09", "__function": "4dad2ba72ed7ba09", "llvmlite.__verify": "6b3bc463fd044545", "__verify": "6b3bc463fd044545", "stdio": "6f62fe05c5ea1ceb", "stdarg": "71e0a3ffcb3ebfad", "w32.win32base": "7e529fe7a078cfef", "win32base": "7e529fe7a078cfef", "stdlib": "90c53dd6db8d41cf", "llvmlite.__builder": "946e087da91aaada", "__builder": "946e087da91aaada", "string": "9474791561654346", "llvmlite.__init__": "95394ca8da0f655a", "__init__": "95394ca8da0f655a", "llvmlite": "95394ca8da0f655a", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "viperlib": "c3b259b4059f8668", "viperio": "c9f4be41ca1cc2b4", "memhub": "f3560b99de458aec", "stdint": "f5522571bcce7bcb", "llvmlite.__values": "f9e36e2cd6fa659f", "__values": "f9e36e2cd6fa659f"}

View File

@@ -11,6 +11,7 @@ import string
import memhub
from linkedlist import GSListNode
@t.NoVTable
class ParamNode(GSListNode[ParamNode]):
Ty: t.CVoid | t.CPtr
class LLVMType(t.REnum):

View File

@@ -13,17 +13,21 @@ import stdio
from linkedlist import GSListNode, GSList
from .__types import LLVMType, ParamNode, TypePrint
@t.NoVTable
class Line(GSListNode[Line]):
Buf: t.CChar | t.CPtr
Len: t.CSizeT
@t.NoVTable
class BasicBlock(GSListNode[BasicBlock]):
Name: t.CChar | t.CPtr
Lines: GSList[Line] | t.CPtr
IsTerminated: t.CInt
@t.NoVTable
class Param(GSListNode[Param]):
Ty: LLVMType | t.CPtr
Name: t.CChar | t.CPtr
Attrs: t.CChar | t.CPtr
@t.NoVTable
class Function(GSListNode[Function]):
Name: t.CChar | t.CPtr
RetTy: LLVMType | t.CPtr

View File

@@ -19,6 +19,7 @@ VERIFY_ERR_DUPLICATE_DEF: t.CDefine = 2
VERIFY_ERR_UNDEFINED_USE: t.CDefine = 3
VERIFY_ERR_PHI_NOT_FIRST: t.CDefine = 4
@t.NoVTable
class NameEntry(GSListNode[NameEntry]):
Name: t.CChar | t.CPtr
class VerifyResult:

View File

@@ -14,6 +14,7 @@ from .__types import LLVMType, TypePrint
from .__values import Value, new_value, SSAValue
from .__function import Function, BasicBlock, block_append_text, function_move_block_to_end, _ll_name_needs_quote
@t.NoVTable
class IRBuilder:
Pool: memhub.MemBuddy | t.CPtr
Func: Function | t.CPtr
@@ -161,6 +162,7 @@ def build_gep_array(builder: IRBuilder | t.CPtr, array_ty: LLVMType | t.CPtr, el
def build_gep_struct(builder: IRBuilder | t.CPtr, struct_ty: LLVMType | t.CPtr, field_ty: LLVMType | t.CPtr, ptr: Value | t.CPtr, field_idx: t.CInt) -> Value | t.CPtr: pass
@t.NoVTable
class PhiIncoming(GSListNode[PhiIncoming]):
Val: Value | t.CPtr
Block: BasicBlock | t.CPtr
@@ -172,6 +174,7 @@ def new_phi_incoming(pool: memhub.MemBuddy | t.CPtr, val: Value | t.CPtr, block:
def build_phi(builder: IRBuilder | t.CPtr, ty: LLVMType | t.CPtr, incoming_head: PhiIncoming | t.CPtr, count: t.CInt) -> Value | t.CPtr: pass
@t.NoVTable
class SwitchCase(GSListNode[SwitchCase]):
CaseVal: Value | t.CPtr
Block: BasicBlock | t.CPtr

View File

@@ -46,3 +46,14 @@ def atoll(src: str) -> t.CInt64T: pass
def atof(src: str) -> t.CDouble: pass
def split(s: str, delim: str, result: t.CArray[str]) -> int: pass
ascii_lowercase: t.CExtern | str
ascii_uppercase: t.CExtern | str
ascii_letters: t.CExtern | str
digits: t.CExtern | str
hexdigits: t.CExtern | str
octdigits: t.CExtern | str
punctuation: t.CExtern | str
whitespace: t.CExtern | str
printable: t.CExtern | str

View File

@@ -1 +1 @@
{"D:\\Users\\TermiNexus\\Desktop\\TransPyC\\Test\\LLvmLiteTest\\App\\main.py": {"sha1": "3e914ffe8cc3c120", "mtime": 1783096320.3660233, "size": 50177}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\atom.py": {"sha1": "271ea3decb810db2", "mtime": 1782226548.693161, "size": 1290}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\linkedlist.py": {"sha1": "2d39c6c7d3557b3e", "mtime": 1782895405.2191627, "size": 16032}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\llvmlite\\__init__.py": {"sha1": "95394ca8da0f655a", "mtime": 1784089002.4168732, "size": 16338}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\llvmlite\\__builder.py": {"sha1": "46ea362b72c10a9e", "mtime": 1783657006.512418, "size": 48509}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\llvmlite\\__function.py": {"sha1": "e0b84369e50c937c", "mtime": 1784275582.4008405, "size": 16232}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\llvmlite\\__module.py": {"sha1": "21a7fcfc665f75ef", "mtime": 1784216086.0677392, "size": 20058}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\llvmlite\\__types.py": {"sha1": "455ff4e74c3dbfb0", "mtime": 1784088625.3087547, "size": 17902}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\llvmlite\\__values.py": {"sha1": "05c11f22675c60cb", "mtime": 1783584462.175312, "size": 6645}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\llvmlite\\__verify.py": {"sha1": "d4117f5e00a6c3b5", "mtime": 1783250231.8851368, "size": 14657}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\memhub.py": {"sha1": "ee084e9fc6ee413a", "mtime": 1784214242.4485993, "size": 17765}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\stdarg.py": {"sha1": "71e0a3ffcb3ebfad", "mtime": 1781258888.113146, "size": 277}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\stdint.py": {"sha1": "f5522571bcce7bcb", "mtime": 1782383975.8824987, "size": 4356}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\stdio.py": {"sha1": "6f62fe05c5ea1ceb", "mtime": 1783239556.0959673, "size": 714}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\stdlib.py": {"sha1": "90c53dd6db8d41cf", "mtime": 1783874975.3597875, "size": 375}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\string.py": {"sha1": "ab6e54ba9a669f76", "mtime": 1783933178.7264287, "size": 9922}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\testcheck.py": {"sha1": "dd3002730623424b", "mtime": 1783927513.1159866, "size": 1818}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\viperio.py": {"sha1": "c9f4be41ca1cc2b4", "mtime": 1782812279.506002, "size": 1556}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\viperlib.py": {"sha1": "c3b259b4059f8668", "mtime": 1782821991.979496, "size": 56772}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\w32\\win32base.py": {"sha1": "7e529fe7a078cfef", "mtime": 1782488356.7736557, "size": 2662}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\w32\\win32console.py": {"sha1": "bbdf3bbd4c3bc28c", "mtime": 1781200703.5338137, "size": 5604}}
{"D:\\Users\\TermiNexus\\Desktop\\TransPyC\\Test\\LLvmLiteTest\\App\\main.py": {"sha1": "5b8cf12a5862b640", "mtime": 1784384536.040362, "size": 50855}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\atom.py": {"sha1": "271ea3decb810db2", "mtime": 1782226548.693161, "size": 1290}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\linkedlist.py": {"sha1": "2d39c6c7d3557b3e", "mtime": 1782895405.2191627, "size": 16032}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\llvmlite\\__init__.py": {"sha1": "95394ca8da0f655a", "mtime": 1784089002.4168732, "size": 16338}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\llvmlite\\__builder.py": {"sha1": "946e087da91aaada", "mtime": 1784387312.9523027, "size": 48840}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\llvmlite\\__function.py": {"sha1": "4dad2ba72ed7ba09", "mtime": 1784387250.682758, "size": 16888}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\llvmlite\\__module.py": {"sha1": "21a7fcfc665f75ef", "mtime": 1784216086.0677392, "size": 20058}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\llvmlite\\__types.py": {"sha1": "15f1ded02f3aa5bc", "mtime": 1784387290.644663, "size": 17996}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\llvmlite\\__values.py": {"sha1": "f9e36e2cd6fa659f", "mtime": 1784387299.9652681, "size": 6739}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\llvmlite\\__verify.py": {"sha1": "6b3bc463fd044545", "mtime": 1784387320.0367622, "size": 14751}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\memhub.py": {"sha1": "f3560b99de458aec", "mtime": 1784375410.1873891, "size": 19458}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\stdarg.py": {"sha1": "71e0a3ffcb3ebfad", "mtime": 1781258888.113146, "size": 277}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\stdint.py": {"sha1": "f5522571bcce7bcb", "mtime": 1782383975.8824987, "size": 4356}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\stdio.py": {"sha1": "6f62fe05c5ea1ceb", "mtime": 1783239556.0959673, "size": 714}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\stdlib.py": {"sha1": "90c53dd6db8d41cf", "mtime": 1783874975.3597875, "size": 375}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\string.py": {"sha1": "9474791561654346", "mtime": 1784387475.6951904, "size": 10395}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\testcheck.py": {"sha1": "14d33679f7fadf1f", "mtime": 1784375629.8057406, "size": 1979}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\viperio.py": {"sha1": "c9f4be41ca1cc2b4", "mtime": 1782812279.506002, "size": 1556}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\viperlib.py": {"sha1": "c3b259b4059f8668", "mtime": 1782821991.979496, "size": 56772}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\w32\\win32base.py": {"sha1": "7e529fe7a078cfef", "mtime": 1782488356.7736557, "size": 2662}, "D:\\Users\\TermiNexus\\Desktop\\TransPyC\\includes\\w32\\win32console.py": {"sha1": "bbdf3bbd4c3bc28c", "mtime": 1781200703.5338137, "size": 5604}}

View File

@@ -1,21 +1,21 @@
05c11f22675c60cb:includes/llvmlite\__values.py
14d33679f7fadf1f:includes/testcheck.py
15f1ded02f3aa5bc:includes/llvmlite\__types.py
21a7fcfc665f75ef:includes/llvmlite\__module.py
271ea3decb810db2:includes/atom.py
2d39c6c7d3557b3e:includes/linkedlist.py
3e914ffe8cc3c120:main.py
455ff4e74c3dbfb0:includes/llvmlite\__types.py
46ea362b72c10a9e:includes/llvmlite\__builder.py
4dad2ba72ed7ba09:includes/llvmlite\__function.py
5b8cf12a5862b640:main.py
6b3bc463fd044545:includes/llvmlite\__verify.py
6f62fe05c5ea1ceb:includes/stdio.py
71e0a3ffcb3ebfad:includes/stdarg.py
7e529fe7a078cfef:includes/w32\win32base.py
90c53dd6db8d41cf:includes/stdlib.py
946e087da91aaada:includes/llvmlite\__builder.py
9474791561654346:includes/string.py
95394ca8da0f655a:includes/llvmlite\__init__.py
ab6e54ba9a669f76:includes/string.py
bbdf3bbd4c3bc28c:includes/w32\win32console.py
c3b259b4059f8668:includes/viperlib.py
c9f4be41ca1cc2b4:includes/viperio.py
d4117f5e00a6c3b5:includes/llvmlite\__verify.py
dd3002730623424b:includes/testcheck.py
e0b84369e50c937c:includes/llvmlite\__function.py
ee084e9fc6ee413a:includes/memhub.py
f3560b99de458aec:includes/memhub.py
f5522571bcce7bcb:includes/stdint.py
f9e36e2cd6fa659f:includes/llvmlite\__values.py

View File

@@ -34,7 +34,7 @@ class MemManager:
def free(self: MemManager, ptr: t.CVoid | t.CPtr) -> t.CInt: pass
def reset(self: MemManager) -> t.CInt: pass
def calloc(self: MemManager, count: t.CSizeT, size: t.CSizeT) -> t.CVoid | t.CPtr: pass
def realloc(self: MemManager, ptr: t.CVoid | t.CPtr, old_size: t.CSizeT, new_size: t.CSizeT) -> t.CVoid | t.CPtr: pass
def realloc(self: MemManager, ptr: t.CVoid | t.CPtr, new_size: t.CSizeT) -> t.CVoid | t.CPtr: pass
def __enter__(self: MemManager) -> 'MemManager' | t.CPtr: pass
def __exit__(self: MemManager) -> t.CInt: pass
def alloc_buf(self: MemManager, capacity: t.CSizeT) -> viperio.Buf | t.CPtr: pass
@@ -78,4 +78,9 @@ class MemBuddy(MemManager):
def alloc(self: MemBuddy, size: t.CSizeT) -> t.CVoid | t.CPtr: pass
def free(self: MemBuddy, ptr: t.CVoid | t.CPtr) -> t.CInt: pass
def reset(self: MemBuddy) -> t.CInt: pass
def realloc(self: MemBuddy, ptr: t.CVoid | t.CPtr, old_size: t.CSizeT, new_size: t.CSizeT) -> t.CVoid | t.CPtr: pass
def realloc(self: MemBuddy, ptr: t.CVoid | t.CPtr, new_size: t.CSizeT) -> t.CVoid | t.CPtr: pass
@property
def mem_size(self: MemBuddy) -> t.CSizeT: pass
def stats(self: MemBuddy) -> t.CSizeT: pass
def free_count(self: MemBuddy) -> t.CSizeT: pass
def self_check(self: MemBuddy) -> t.CInt: pass

View File

@@ -12,6 +12,7 @@ import memhub
from linkedlist import GSListNode
from .__types import LLVMType, TypePrint
@t.NoVTable
class Value(GSListNode[Value]):
Ty: LLVMType | t.CPtr
Name: t.CChar | t.CPtr