Compare commits

..

190 Commits

Author SHA1 Message Date
xushiwei
908f0047f8 Merge pull request #199 from visualfc/index
ssa: checkIndex for index/indexAddr
2024-05-18 16:48:26 +08:00
xushiwei
e533903cee Merge pull request #202 from xushiwei/q
py/torch; llpyg: use pysigfetch (by goplus/hdq)
2024-05-18 16:46:56 +08:00
xushiwei
1be8052caa llpyg: fix pysigfetch error handling 2024-05-18 16:45:02 +08:00
xushiwei
668ce4bd2d py/torch; llpyg: use pysigfetch (by goplus/hdq) 2024-05-18 16:03:49 +08:00
visualfc
e7fd038493 ssa: checkIndex for index/indexAddr 2024-05-18 11:08:39 +08:00
visualfc
03edb3bbbe runtime: assertRuntimeError assertNegativeShift assertIndexRange 2024-05-18 10:16:57 +08:00
xushiwei
307a1a295a Merge pull request #201 from xushiwei/q
mv x/ => c/
2024-05-17 22:43:39 +08:00
xushiwei
446df58e92 TestSqlite 2024-05-17 22:41:39 +08:00
xushiwei
1ad5caba93 cl: _testlibc/sqlite fix 2024-05-17 22:38:32 +08:00
xushiwei
9eddc0e4f0 submodule c/llama2/llama2.c 2024-05-17 22:34:34 +08:00
xushiwei
087ba0d81d mv x/ => c/ 2024-05-17 22:33:57 +08:00
xushiwei
3c5cd8f38f Merge pull request #200 from xushiwei/q
py/torch
2024-05-17 21:50:00 +08:00
xushiwei
367743530f py/torch 2024-05-17 21:46:38 +08:00
xushiwei
7370ce2793 Merge pull request #198 from xushiwei/q
Cstr (for Go+)
2024-05-17 21:19:51 +08:00
xushiwei
ba61b42ef5 Cstr (for Go+) 2024-05-17 21:14:41 +08:00
xushiwei
f7e362dd90 Merge pull request #197 from visualfc/global_array
ssa: fix global array
2024-05-17 19:38:51 +08:00
visualfc
66da072fd7 ssa: fix global array 2024-05-17 19:30:56 +08:00
xushiwei
d763534208 Merge pull request #196 from xushiwei/q
build: checkFlag fix (for Go+)
2024-05-17 13:57:31 +08:00
xushiwei
ad05898543 build: checkFlag fix (for Go+) 2024-05-17 13:54:00 +08:00
xushiwei
f930f7878d Merge pull request #195 from xushiwei/q
cl: out.ll regen
2024-05-17 11:16:58 +08:00
xushiwei
d6a75c411b _testpy/pi 2024-05-17 11:14:19 +08:00
xushiwei
568a71e0dc cl: out.ll regen 2024-05-17 11:11:22 +08:00
xushiwei
c92e9aac2c Merge pull request #189 from tsingbx/main_return_0
Main return 0
2024-05-17 11:09:20 +08:00
xushiwei
3012c4a3ff Merge branch 'main' into main_return_0 2024-05-17 11:05:09 +08:00
xushiwei
ebe338ac9a Merge pull request #193 from visualfc/type
ssa: type uint/byte/int32/uint32/int64/uint64
2024-05-17 11:04:12 +08:00
tsingbx
a45523a48c run gentests 2024-05-17 09:48:21 +08:00
tsingbx
5bfeea67d7 change main return to C int 2024-05-17 09:31:48 +08:00
visualfc
f35f15d36c ssa: type uint/byte/int32/uint32/int64/uint64 2024-05-17 09:28:57 +08:00
tsingbx
057af792df main return type chang to C int 2024-05-17 09:06:53 +08:00
xushiwei
41a850e7b2 Merge pull request #194 from xushiwei/q
py/{numpy, pandas}
2024-05-17 09:04:56 +08:00
xushiwei
6be70390a6 py/{numpy, pandas} 2024-05-17 09:01:36 +08:00
xushiwei
1cfe3ee9f8 Merge pull request #192 from xushiwei/q
pysig.Parse; py/pandas
2024-05-17 05:30:18 +08:00
xushiwei
c1927c985a pysig.Parse; py/pandas 2024-05-17 05:25:13 +08:00
xushiwei
309f42994b Merge pull request #191 from visualfc/castint
ssa: fix castInt
2024-05-16 21:20:23 +08:00
visualfc
feb28ecace ssa: fix castInt 2024-05-16 20:43:16 +08:00
xushiwei
00f74b7f0a Merge pull request #190 from xushiwei/q
build fix: -L dir
2024-05-16 18:42:45 +08:00
xushiwei
fcc0e1776b build fix: -L dir 2024-05-16 18:40:49 +08:00
xushiwei
a5ec755c28 Merge pull request #188 from visualfc/shift_check
ssa: binop check shl/shr
2024-05-16 18:04:25 +08:00
visualfc
98945926ca ssa: binop check shl/shr 2024-05-16 16:27:49 +08:00
tsingbx
d3e3767df4 Merge branch 'main' of https://github.com/goplus/llgo into main_return_0 2024-05-16 15:35:05 +08:00
tsingbx
de1281bb66 Add return value to llvm's ir main function definition 2024-05-16 15:27:14 +08:00
xushiwei
07e55c3d89 Merge pull request #187 from visualfc/shift
ssa: binop fix shl/shr size
2024-05-16 10:48:03 +08:00
visualfc
6e4ebeddf4 ssa: binop fix shl/shr size 2024-05-16 10:20:02 +08:00
xushiwei
2b9fb88bf0 Merge pull request #183 from visualfc/print
ssa: builtin print/println
2024-05-16 09:40:14 +08:00
visualfc
022965b9c7 ssa: builtin print/println 2024-05-16 09:33:25 +08:00
xushiwei
6278718a24 Merge pull request #186 from xushiwei/q
README: Key modules
2024-05-16 07:08:46 +08:00
xushiwei
1675daafcd Key modules 2024-05-16 07:08:10 +08:00
xushiwei
ed5b6edf52 Merge pull request #185 from xushiwei/q
README: Development tools
2024-05-16 06:34:55 +08:00
xushiwei
638caa355c Development tools 2024-05-16 06:34:18 +08:00
xushiwei
78b2f9b455 Update README.md 2024-05-16 01:08:21 +08:00
xushiwei
2a35ffcc27 Merge pull request #184 from xushiwei/q
README
2024-05-16 00:06:24 +08:00
xushiwei
5eae8f9af6 README 2024-05-16 00:02:10 +08:00
xushiwei
25381e20d2 TestSqlite 2024-05-15 21:43:38 +08:00
xushiwei
fc35ff5cd1 Merge pull request #182 from xushiwei/q
sqlite demo
2024-05-15 21:39:00 +08:00
xushiwei
b10d00b426 rm TestSqlite 2024-05-15 21:36:48 +08:00
xushiwei
c634dc25b4 sqlite demo 2024-05-15 21:27:42 +08:00
xushiwei
2fb4561bf8 Merge pull request #181 from xushiwei/q
rm submodule sqlite
2024-05-15 21:14:10 +08:00
xushiwei
f167c6dcca rm submodule sqlite 2024-05-15 21:12:58 +08:00
xushiwei
555ace9e2e Merge pull request #179 from xushiwei/q
llgo/ssa: PyNewVar; pyLoad
2024-05-15 18:49:10 +08:00
xushiwei
d07ffb36ad TestUserdefExpr: pyVarTy 2024-05-15 18:45:53 +08:00
xushiwei
9e2b8b77c9 py/math: remove vars 2024-05-15 18:40:54 +08:00
xushiwei
29e4af4fb2 llgo/ssa: PyNewVar; pyLoad 2024-05-15 18:32:50 +08:00
xushiwei
91513a12b4 llgo/ssa: refactor python related names (PyXXX) 2024-05-15 17:19:47 +08:00
xushiwei
ee3f55dd41 compileGlobal: skip pyVar 2024-05-15 16:51:44 +08:00
xushiwei
c2e5a78076 compileFuncDecl remove param: call bool 2024-05-15 16:40:10 +08:00
xushiwei
da3ac3e93d Merge pull request #178 from xushiwei/q
README: python support
2024-05-15 16:05:01 +08:00
xushiwei
278ebbc9bd README: python support 2024-05-15 16:04:20 +08:00
xushiwei
546f93147e Merge pull request #177 from xushiwei/q
llgo instr: pyList
2024-05-15 15:46:18 +08:00
xushiwei
3e7bfbb45c llgo instr: pyList 2024-05-15 15:42:58 +08:00
xushiwei
c2cf0443ef Merge remote-tracking branch 'gop/main' into q 2024-05-15 14:49:25 +08:00
xushiwei
59d68c6438 llgo/ssa: PyList 2024-05-15 14:49:00 +08:00
xushiwei
e0ee199bf1 Merge pull request #176 from xushiwei/q
numpy demo: _pydemo/matrix
2024-05-15 13:59:43 +08:00
xushiwei
c1bf895674 llpyg: numpy/inspect 2024-05-15 13:57:26 +08:00
xushiwei
ea4d92e671 py/os fix 2024-05-15 13:51:58 +08:00
xushiwei
e3f56105d4 numpy demo: _pydemo/matrix 2024-05-15 13:49:19 +08:00
xushiwei
c447a87605 Merge pull request #175 from xushiwei/q
cl: _testpy/gcd
2024-05-15 13:33:56 +08:00
xushiwei
584e5b1f01 TestPrintf fix 2024-05-15 13:30:48 +08:00
xushiwei
207dc4c112 Merge pull request #174 from visualfc/append
ssa: add builtin append
2024-05-15 13:27:58 +08:00
xushiwei
6a3581f7a3 goTypes.cvtFunc fix: remove sig.Variadic flag 2024-05-15 13:24:44 +08:00
xushiwei
11e74975b3 llgo/ssa: rm HasVArg/IsVArg 2024-05-15 13:09:43 +08:00
xushiwei
75ef9ec524 x 2024-05-15 12:01:36 +08:00
xushiwei
9b742e777b cl: _testpy/gcd 2024-05-15 11:59:53 +08:00
visualfc
5d93565e16 ssa: add builtin append 2024-05-15 10:43:26 +08:00
xushiwei
cebfe5c95b Merge pull request #173 from xushiwei/q
cl: _testpy/pow (multiargs)
2024-05-15 08:57:09 +08:00
xushiwei
7881f3a53b x 2024-05-15 08:54:29 +08:00
xushiwei
56269bd52b cl: _testpy/pow (multiargs) 2024-05-15 08:44:00 +08:00
xushiwei
68c43a2cc9 Merge pull request #172 from xushiwei/q
py/numpy
2024-05-15 00:33:10 +08:00
xushiwei
120b507c75 numpy: array, etc 2024-05-15 00:29:54 +08:00
xushiwei
44fe7e8dc4 py/numpy 2024-05-14 23:56:55 +08:00
xushiwei
75d679f141 Merge pull request #171 from xushiwei/q
py/sys; llpyg: prompt import mod fail; py: fix typo
2024-05-14 22:36:03 +08:00
xushiwei
e9570f2400 llpyg: prompt import mod fail; py: fix typo 2024-05-14 22:33:36 +08:00
xushiwei
5b8567310c Merge pull request #170 from xushiwei/q
py/json, py/statistics; demo: statistics.mean
2024-05-14 21:08:14 +08:00
xushiwei
f882221db3 py/math 2024-05-14 21:06:25 +08:00
xushiwei
8c4d7bd641 py/json, py/statistics; demo: statistics.mean 2024-05-14 20:53:13 +08:00
xushiwei
6a78695fde Merge pull request #169 from xushiwei/q
llpyg fix: handle / in sig; llpyg math
2024-05-14 20:17:24 +08:00
xushiwei
73ad16dedd llpyg fix: handle / in sig 2024-05-14 20:14:59 +08:00
xushiwei
dd98112c5a Merge pull request #168 from xushiwei/q
llpyg os
2024-05-14 19:40:49 +08:00
xushiwei
47521d3579 llpyg fix: empty params 2024-05-14 19:38:30 +08:00
xushiwei
0c31300578 llpyg os 2024-05-14 19:19:46 +08:00
xushiwei
6340ff7da0 Merge pull request #166 from visualfc/stringcat
ssa: fix binop string cat ret type
2024-05-14 18:23:51 +08:00
xushiwei
b66cb49d80 Merge pull request #167 from xushiwei/q
llpyg
2024-05-14 18:22:41 +08:00
xushiwei
c884184220 py llgen 2024-05-14 18:19:44 +08:00
xushiwei
091fee61e0 llpyg: pkg.NewFuncDecl 2024-05-14 18:16:32 +08:00
xushiwei
172a268e77 llpyg: ready to test 2024-05-14 17:22:36 +08:00
visualfc
924715fe34 ssa: fix binop string cat ret type 2024-05-14 15:58:33 +08:00
xushiwei
35a73b4cde llpyg: todo 2024-05-14 15:34:53 +08:00
xushiwei
238f9593f9 Update README.md 2024-05-14 13:34:47 +08:00
xushiwei
9e8b5703dc Merge pull request #165 from xushiwei/q
llpyg => pydump
2024-05-14 13:27:51 +08:00
xushiwei
d8bd8be57e llpyg => pydump 2024-05-14 13:23:21 +08:00
xushiwei
a4d4e8b3a9 Merge pull request #164 from xushiwei/q
llgo/x/cjson
2024-05-14 11:52:22 +08:00
xushiwei
703dd17e33 llgo/x/cjson 2024-05-14 11:49:37 +08:00
xushiwei
bc654a462e Merge pull request #162 from xushiwei/q
build: support packages out of llgo
2024-05-14 08:49:11 +08:00
xushiwei
11535825c0 build: support packages out of llgo 2024-05-14 08:40:42 +08:00
xushiwei
196df40c99 Merge pull request #161 from xushiwei/q
llpyg sig fix
2024-05-14 00:34:58 +08:00
xushiwei
7aee6c3a15 llpyg sig fix 2024-05-14 00:31:30 +08:00
xushiwei
372b566d23 mv _xtool => chore/_xtool 2024-05-13 23:03:54 +08:00
xushiwei
9550354442 Merge pull request #160 from xushiwei/q
llpyg: todo
2024-05-13 22:12:17 +08:00
xushiwei
95c3ddfc39 math 2024-05-13 22:05:49 +08:00
xushiwei
bf4f2b6fa0 py/builtins: todo 2024-05-13 22:02:47 +08:00
xushiwei
d3f75a92ad llpyg: print doc 2024-05-13 21:01:39 +08:00
xushiwei
369495c8d3 Merge pull request #159 from xushiwei/q
llpyg: use inspect.Signature
2024-05-13 19:51:05 +08:00
xushiwei
dd52f71069 llpyg: use inspect.Signature 2024-05-13 19:48:33 +08:00
xushiwei
af8e2bc19d Merge pull request #158 from xushiwei/q
_xtool: llpyg
2024-05-13 18:34:33 +08:00
xushiwei
947e5591ea py llgo_autogen 2024-05-13 18:32:43 +08:00
xushiwei
521376e8e8 py 2024-05-13 18:29:00 +08:00
xushiwei
55c0adb23d _testpy/callpy fix 2024-05-13 18:25:05 +08:00
xushiwei
b20ad7047f _xtool: llpyg 2024-05-13 18:24:00 +08:00
xushiwei
fa3149c660 Update README.md 2024-05-13 01:27:02 +08:00
xushiwei
1463ed4835 Merge pull request #155 from xushiwei/q
retract v0.8.0
2024-05-13 01:01:25 +08:00
xushiwei
b959de18d5 retract v0.8.0 2024-05-13 01:00:54 +08:00
xushiwei
edac3f73c2 Merge pull request #154 from xushiwei/q
compileBlock bugfix: pyMod
2024-05-13 00:52:57 +08:00
xushiwei
388b19eed5 _testpy: sort by module name 2024-05-13 00:50:58 +08:00
xushiwei
a337136389 _testpy 2024-05-13 00:45:41 +08:00
xushiwei
31d5a8ac10 compileBlock bugfix: pyMod 2024-05-13 00:41:42 +08:00
xushiwei
46527f56ce Update README.md 2024-05-13 00:10:28 +08:00
xushiwei
a575c17eca Merge pull request #153 from xushiwei/q
README
2024-05-13 00:05:46 +08:00
xushiwei
a6ea3b1e6f README 2024-05-12 23:59:24 +08:00
xushiwei
4d2ad842a4 Merge pull request #152 from xushiwei/q
llgo/ssa: LoadPyModSyms; SetBlockEx AfterInit
2024-05-12 23:47:51 +08:00
xushiwei
ce0f5f3797 testpy: os.Getcwd 2024-05-12 23:45:56 +08:00
xushiwei
9e0d22ac90 x/sqlite/llgo_autogen.lla 2024-05-12 23:43:51 +08:00
xushiwei
ddc2c56115 gentests 2024-05-12 23:42:16 +08:00
xushiwei
acfbe6902a FuncDecl bugfix: even in C, we need to add ctx for method 2024-05-12 23:37:12 +08:00
xushiwei
f7dfab481b vkPyFunc => vkPyFuncRef 2024-05-12 23:08:44 +08:00
xushiwei
23692430d5 llgo/ssa: SetBlockEx AfterInit 2024-05-12 22:51:25 +08:00
xushiwei
03fe594339 compileBlock: use LoadPyModSyms 2024-05-12 20:03:27 +08:00
xushiwei
45babef689 compileBlock refactor 2024-05-12 18:42:45 +08:00
xushiwei
9ac0450255 llgo/ssa: LoadPyModSyms 2024-05-12 18:27:23 +08:00
xushiwei
b1d55f657d Merge pull request #151 from xushiwei/q
llgo/ssa: StringData/StringLen; cl: TestPython; build: PkgLinkExtern
2024-05-12 15:59:58 +08:00
xushiwei
aac5e7b3cd TestFromTestdata: print 2024-05-12 15:56:05 +08:00
xushiwei
791634c377 conflict fix 2024-05-12 15:52:29 +08:00
xushiwei
090149eab6 llgo/ssa: StringData/StringLen 2024-05-12 15:42:50 +08:00
xushiwei
acecbf587d cl: TestPython; build: PkgLinkExtern 2024-05-12 13:05:15 +08:00
xushiwei
4ef46971d0 Merge pull request #150 from xushiwei/q
TestFromTestpymath; llgo/ssa: NewPyFunc add param doInit
2024-05-12 12:18:09 +08:00
xushiwei
2e3cc49782 llgo/ssa: NewPyFunc add param doInit 2024-05-12 12:14:26 +08:00
xushiwei
8a0189b079 TestFromTestpymath 2024-05-12 11:51:46 +08:00
xushiwei
0edd7f6df0 Merge pull request #149 from xushiwei/q
PyInit
2024-05-12 11:28:04 +08:00
xushiwei
0b058bc2e8 test NewPyModVar 2024-05-12 11:26:09 +08:00
xushiwei
f9ef9cab81 TestSetBlockEx 2024-05-12 11:22:55 +08:00
xushiwei
fbb2150d88 TestFromTestpy 2024-05-12 11:13:04 +08:00
xushiwei
0912f1f509 PyInit 2024-05-12 11:11:19 +08:00
xushiwei
64c13fa9ae llgo/ssa: NewPyFunc fix 2024-05-12 00:24:56 +08:00
xushiwei
2a5f9d9641 Merge pull request #148 from xushiwei/q
_pydemo: callpy; PyFunction
2024-05-11 23:55:32 +08:00
xushiwei
6c32fe87e6 TestSetPython, TestPyFunc 2024-05-11 23:53:08 +08:00
xushiwei
09e9cc99d3 Merge pull request #147 from visualfc/typenamed
fix types named recursive
2024-05-11 23:42:06 +08:00
xushiwei
94a7ee024a llgo/ssa: pyCall; demo: _pydemo/callpy 2024-05-11 23:38:21 +08:00
xushiwei
a2d7a8c978 llgo/ssa: PyFunction; NewPyFunc 2024-05-11 21:55:50 +08:00
xushiwei
15499ddc14 cl: _testpy/math 2024-05-11 15:12:42 +08:00
xushiwei
97cb312386 llgo/ssa: b.NewPyModVar, b.ImportPyMod, PyObjectPtr, PyObjectPtrPtr 2024-05-11 15:07:50 +08:00
visualfc
92827a1f04 fix types named recursive 2024-05-11 13:34:08 +08:00
xushiwei
00222c7808 compileBlock: support pyModule init 2024-05-11 11:33:35 +08:00
xushiwei
427d87be68 cl: initPyModule 2024-05-11 10:07:46 +08:00
xushiwei
2560a333b6 FloatAsDouble => Float64 2024-05-11 06:55:57 +08:00
xushiwei
c6b76db789 Merge pull request #146 from xushiwei/q
LLGoPackage: PkgPyModule
2024-05-11 06:47:25 +08:00
xushiwei
1414853fce LLGoPackage: PkgPyModule 2024-05-11 06:44:45 +08:00
xushiwei
cbe384a3be Merge pull request #145 from xushiwei/q
pyimport & deomo: callpy (todo)
2024-05-11 06:25:35 +08:00
xushiwei
cca46573ea pyimport & deomo: callpy (todo) 2024-05-11 06:23:05 +08:00
xushiwei
2589c23998 Merge pull request #144 from xushiwei/q
nmindex: query auto add _ prefix
2024-05-11 05:45:26 +08:00
xushiwei
29830865d9 nmindex: query auto add _ prefix 2024-05-11 05:43:27 +08:00
xushiwei
35dbc7b0b5 Merge pull request #143 from xushiwei/q
mv x/<tool> => xtool/<tool>
2024-05-11 05:29:38 +08:00
xushiwei
cd266213ce mv x/<tool> => xtool/<tool> 2024-05-11 05:27:38 +08:00
xushiwei
875eadeb19 Merge pull request #142 from xushiwei/q
py/README
2024-05-11 05:18:41 +08:00
xushiwei
67896c63a7 py/README 2024-05-11 05:18:17 +08:00
xushiwei
c643f734e9 Merge pull request #141 from xushiwei/q
move python demos to _pydemo
2024-05-11 05:05:07 +08:00
xushiwei
31d91f5e87 move python demos to _pydemo 2024-05-11 05:04:02 +08:00
xushiwei
2a92f1bc55 Merge pull request #140 from xushiwei/q
py demo: hellpy, clpy, callpy
2024-05-11 04:31:40 +08:00
xushiwei
d9db5528f5 py demo: hellpy, clpy, callpy 2024-05-11 04:26:41 +08:00
xushiwei
22a4ffb78b Merge pull request #139 from visualfc/iface
typeAssert: bool float string
2024-05-11 02:49:31 +08:00
visualfc
1fb37c37fe binop: token.AND_NOT 2024-05-10 21:34:54 +08:00
visualfc
aae663e5e5 binop: bool eql/neq 2024-05-10 21:06:19 +08:00
visualfc
e985eda857 typeAssert: bool float string 2024-05-10 13:46:39 +08:00
195 changed files with 32088 additions and 1383 deletions

2
.gitignore vendored
View File

@@ -13,11 +13,13 @@ llgo_autogen.ll
stories*.bin
.DS_Store
err.log
numpy.txt
_go/
_runtime/
_tinygo/
build.dir/
.vscode/
# Test binary, built with `go test -c`
*.test

7
.gitmodules vendored
View File

@@ -1,6 +1,3 @@
[submodule "x/llama2/llama2.c"]
path = x/llama2/llama2.c
[submodule "c/llama2/llama2.c"]
path = c/llama2/llama2.c
url = https://github.com/karpathy/llama2.c.git
[submodule "x/sqlite/sqlite"]
path = x/sqlite/sqlite
url = https://github.com/sqlite/sqlite.git

209
README.md
View File

@@ -8,7 +8,185 @@ llgo - A Go compiler based on LLVM
[![GoDoc](https://pkg.go.dev/badge/github.com/goplus/llgo.svg)](https://pkg.go.dev/github.com/goplus/llgo)
[![Language](https://img.shields.io/badge/language-Go+-blue.svg)](https://github.com/goplus/gop)
This is a Go compiler based on LLVM in order to better integrate Go with the C ecosystem. It's a subproject of [the Go+ project](https://github.com/goplus/gop).
LLGo is a Go compiler based on LLVM in order to better integrate Go with the C ecosystem including Python. It's a subproject of [the Go+ project](https://github.com/goplus/gop).
## C standard libary support
```go
package main
import "github.com/goplus/llgo/c"
func main() {
c.Printf(c.Str("Hello world\n"))
}
```
This is a simple example of calling the C `printf` function to print `Hello world`. Here, `c.Str` is not a function for converting a Go string to a C string, but a built-in instruction supported by `llgo` for generating a C string constant.
The `_demo` directory contains some C standard libary related demos (it start with `_` to prevent the `go` command from compiling it):
* [hello](_demo/hello/hello.go): call C `printf` to print `Hello world`
* [concat](_demo/concat/concat.go): call C `fprintf` with `stderr`
* [qsort](_demo/qsort/qsort.go): call C function with a callback (eg. `qsort`)
To run these demos (If you haven't installed `llgo` yet, please refer to [How to install](#how-to-install)):
```sh
export LLGOROOT=`pwd`
cd <demo-directory> # eg. cd _demo/hello
llgo run .
```
See [github.com/goplus/llgo/c](https://pkg.go.dev/github.com/goplus/llgo/c) for more detials.
## Python support
You can import a Python library in LLGo!
And you can import any Python library into `llgo` through a program called `llpyg` (see [Development tools](#development-tools)). The currently imported libraries include:
* [sys](https://pkg.go.dev/github.com/goplus/llgo/py/sys)
* [os](https://pkg.go.dev/github.com/goplus/llgo/py/os)
* [math](https://pkg.go.dev/github.com/goplus/llgo/py/math)
* [json](https://pkg.go.dev/github.com/goplus/llgo/py/json)
* [inspect](https://pkg.go.dev/github.com/goplus/llgo/py/inspect)
* [statistics](https://pkg.go.dev/github.com/goplus/llgo/py/statistics)
* [numpy](https://pkg.go.dev/github.com/goplus/llgo/py/numpy)
Here is an example using the Python `math` library:
```go
package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/py"
"github.com/goplus/llgo/py/math"
)
func main() {
x := math.Sqrt(py.Float(2))
c.Printf(c.Str("sqrt(2) = %f\n"), x.Float64())
}
```
Here, We call `py.Float(2)` to create a Python number 2, and pass it to Pythons `math.sqrt` to get `x`. Then use `x.Float64()` to convert x to Go's `float64` type, and print the value through the C `printf` function.
Let's look at a slightly more complex example. For example, we use `numpy` to calculate:
```go
package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/py"
"github.com/goplus/llgo/py/numpy"
)
func main() {
a := py.List(
py.List(1.0, 2.0, 3.0),
py.List(4.0, 5.0, 6.0),
py.List(7.0, 8.0, 9.0),
)
b := py.List(
py.List(9.0, 8.0, 7.0),
py.List(6.0, 5.0, 4.0),
py.List(3.0, 2.0, 1.0),
)
x := numpy.Add(a, b)
c.Printf(c.Str("a+b = %s\n"), x.Str().CStr())
}
```
Here we define two 3x3 matrices a and b, add them to get x, and then print the result.
The `_pydemo` directory contains some python related demos:
* [callpy](_pydemo/callpy/callpy.go): call Python standard library function `math.sqrt`
* [pi](_pydemo/pi/pi.go): print python constants `math.pi`
* [statistics](_pydemo/statistics/statistics.go): define a python list and call `statistics.mean` to get the mean
* [matrix](_pydemo/matrix/matrix.go): a basic `numpy` demo
To run these demos, you need to set the `LLGO_LIB_PYTHON` environment variable first.
If Python is in the search path for `clang` linking, then `LLGO_LIB_PYTHON` only needs to be set to the name of the Python library. For example:
```sh
export LLGO_LIB_PYTHON=python3.12
```
You can also specify the path to tell `llgo` where the Python library is located:
```sh
export LLGO_LIB_PYTHON=/foo/bar/python3.12
```
For example, `/opt/homebrew/Frameworks/Python.framework/Versions/3.12/libpython3.12.dylib` is a typical python library location under macOS. So we should set it like this:
```sh
export LLGO_LIB_PYTHON=/opt/homebrew/Frameworks/Python.framework/Versions/3.12/python3.12
```
Note that the file name must be written in a platform-independent format, using `python3.12` instead of `libpython3.12.dylib`.
Then you can run the demos:
```sh
export LLGOROOT=`pwd`
cd <demo-directory> # eg. cd _pydemo/callpy
llgo run .
```
See [github.com/goplus/llgo/py](https://pkg.go.dev/github.com/goplus/llgo/py) for more detials.
## Other frequently used libraries
LLGo can easily import any libraries from the C ecosystem. Currently, this import process is still manual, but in the future, it will be automated similar to Python library imports.
The currently imported libraries include:
* [llama2.c](https://pkg.go.dev/github.com/goplus/llgo/c/llama2)
* [cjson](https://pkg.go.dev/github.com/goplus/llgo/c/cjson)
* [sqlite](https://pkg.go.dev/github.com/goplus/llgo/c/sqlite)
Here are some examples related to them:
* [llama2-c](_demo/llama2-c): inference Llama 2 (It's the first llgo AI example)
* [mkjson](c/cjson/_demo/mkjson/mkjson.go): create a json object and print it
* [sqlitedemo](c/sqlite/_demo/sqlitedemo/demo.go): a basic sqlite demo
## Go syntax support
The priority of `llgo` feature iteration is:
* Popular C/Python libraries
* Full Go syntax
* Go standard libraries
* Popular Go packages
Common Go syntax is already supported. Except for the following, which needs to be improved:
* interface (Limited support)
* map (Very limited support)
* panic (Limited support)
* recover (Not supported yet)
* defer (Not supported yet)
* gc (Not supported yet)
* chan (Not supported yet)
* goroutine (Not supported yet)
* generics (Not supported yet)
Here are some examples related to Go syntax:
* [concat](_demo/concat/concat.go): define a variadic function
* [genints](_demo/genints/genints.go): various forms of closure usage (including C function, recv.method and anonymous function)
## How to install
@@ -37,20 +215,25 @@ go install -v ./...
TODO
## Demo
## Development tools
The `_demo` directory contains our demos (it start with `_` to prevent the `go` command from compiling it):
* [pydump](chore/_xtool/pydump): It's the first program compiled by `llgo` (NOT `go`) in a production environment. It outputs symbol information (functions, variables, and constants) from a Python library in JSON format, preparing for the generation of corresponding packages in `llgo`.
* [llpyg](chore/llpyg): It is used to automatically convert Python libraries into Go packages that `llgo` can import. It depends on `pydump` to accomplish the task.
* [llgen](chore/llgen): It is used to compile Go packages into LLVM IR files (*.ll).
* [ssadump](chore/ssadump): It is a Go SSA builder and interpreter.
* [hello](_demo/hello/hello.go): call C printf to print `Hello world`
* [concat](_demo/concat/concat.go): call C fprintf with stderr, and Go variadic function
* [qsort](_demo/qsort/qsort.go): call C function with a callback (eg. qsort)
* [genints](_demo/genints/genints.go): various forms of closure usage (including C function, recv.method and anonymous function)
* [llama2-c](_demo/llama2-c): inference Llama 2 (It's the first llgo AI example)
* [hellopy](https://github.com/goplus/cpython/blob/main/_demo/hellopy/hello.go): link Python to Go and say `Hello world`
### How to run demos
How do I generate these tools?
```sh
cd <demo-directory> # eg. cd _demo/genints
llgo run .
go install -v ./... # compile all tools except pydump
cd chore/_xtool
llgo install ./... # compile pydump
```
## Key modules
Below are the key modules for understanding the implementation principles of `llgo`:
* [llgo/ssa](https://pkg.go.dev/github.com/goplus/llgo/ssa): It generates LLVM IR files (LLVM SSA) using the semantics (interfaces) of Go SSA. Although `LLVM SSA` and `Go SSA` are both IR languages, they work at completely different levels. `LLVM SSA` is closer to machine code, which abstracts different instruction sets. While `Go SSA` is closer to a high-level language. We can think of it as the instruction set of the `Go computer`. `llgo/ssa` is not just limited to the `llgo` compiler. If we view it as the high-level expressive power of `LLVM`, you'll find it very useful. Prior to `llgo/ssa`, you had to operate `LLVM` using machine code semantics. But now, with the advanced SSA form (in the semantics of Go SSA), you can conveniently utilize `LLVM`.
* [llgo/cl](https://pkg.go.dev/github.com/goplus/llgo/cl): It is the core of the llgo compiler. It converts a Go package into LLVM IR files. It depends on `llgo/ssa`.
* [llgo/internal/build](https://pkg.go.dev/github.com/goplus/llgo/internal/build): It strings together the entire compilation process of `llgo`. It depends on `llgo/ssa` and `llgo/cl`.

View File

@@ -2,7 +2,7 @@ package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/x/llama2"
"github.com/goplus/llgo/c/llama2"
)
func main() {

12
_pydemo/callpy/callpy.go Normal file
View File

@@ -0,0 +1,12 @@
package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/py"
"github.com/goplus/llgo/py/math"
)
func main() {
x := math.Sqrt(py.Float(2))
c.Printf(c.Str("sqrt(2) = %f\n"), x.Float64())
}

22
_pydemo/matrix/matrix.go Normal file
View File

@@ -0,0 +1,22 @@
package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/py"
"github.com/goplus/llgo/py/numpy"
)
func main() {
a := py.List(
py.List(1.0, 2.0, 3.0),
py.List(4.0, 5.0, 6.0),
py.List(7.0, 8.0, 9.0),
)
b := py.List(
py.List(9.0, 8.0, 7.0),
py.List(6.0, 5.0, 4.0),
py.List(3.0, 2.0, 1.0),
)
x := numpy.Add(a, b)
c.Printf(c.Str("a+b = %s\n"), x.Str().CStr())
}

10
_pydemo/pi/pi.go Normal file
View File

@@ -0,0 +1,10 @@
package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/py/math"
)
func main() {
c.Printf(c.Str("pi = %f\n"), math.Pi.Float64())
}

View File

@@ -0,0 +1,13 @@
package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/py"
"github.com/goplus/llgo/py/statistics"
)
func main() {
list := py.List(1.0, 2.0, 3.0, 4.0, 4.0)
mean := statistics.Mean(list)
c.Printf(c.Str("mean(1, 2, 3, 4, 4) = %f\n"), mean.Float64())
}

19
c/c.go
View File

@@ -25,12 +25,17 @@ const (
)
type (
Char = int8
Int = C.int
Uint = C.uint
Float = float32
Pointer = unsafe.Pointer
FilePtr = unsafe.Pointer
Char = int8
Int = C.int
Uint = C.uint
Long = int32
Ulong = uint32
LongLong = int64
UlongLong = uint64
Float = float32
Double = float64
Pointer = unsafe.Pointer
FilePtr = unsafe.Pointer
)
type integer interface {
@@ -66,7 +71,7 @@ func Memset(s Pointer, c Int, n uintptr) Pointer
// -----------------------------------------------------------------------------
//go:linkname GoStringData github.com/goplus/llgo/internal/runtime.StringData
//go:linkname GoStringData llgo.stringData
func GoStringData(string) *Char
// -----------------------------------------------------------------------------

35
c/cjson/README.md Normal file
View File

@@ -0,0 +1,35 @@
LLGo wrapper of DaveGamble/cJSON
=====
[![Build Status](https://github.com/goplus/cjson/actions/workflows/go.yml/badge.svg)](https://github.com/goplus/cjson/actions/workflows/go.yml)
[![GitHub release](https://img.shields.io/github/v/tag/goplus/cjson.svg?label=release)](https://github.com/goplus/cjson/releases)
[![GoDoc](https://pkg.go.dev/badge/github.com/goplus/cjson.svg)](https://pkg.go.dev/github.com/goplus/cjson)
[![Compiler](https://img.shields.io/badge/compiler-llgo-darkgreen.svg)](https://github.com/goplus/llgo)
[![Language](https://img.shields.io/badge/language-Go+-blue.svg)](https://github.com/goplus/gop)
## How to install
```sh
git clone https://github.com/goplus/cjson.git
cd cjson
git submodule init
git submodule update
mkdir build.dir
cd build.dir
cmake ../cJSON
sudo make install
```
## Demos
The `_demo` directory contains our demos (it start with `_` to prevent the `go` command from compiling it):
* [mkjson](_demo/mkjson/mkjson.go): create a json object and print it
### How to run demos
To run the demos in directory `_demo`:
```sh
cd <demo-directory> # eg. cd _demo/mkjson
llgo run .
```

View File

@@ -0,0 +1,27 @@
package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/c/cjson"
)
func main() {
mod := cjson.Object()
mod.SetItem(c.Str("name"), cjson.String(c.Str("math")))
syms := cjson.Array()
fn := cjson.Object()
fn.SetItem(c.Str("name"), cjson.String(c.Str("sqrt")))
fn.SetItem(c.Str("sig"), cjson.String(c.Str("(x, /)")))
syms.AddItem(fn)
v := cjson.Object()
v.SetItem(c.Str("name"), cjson.String(c.Str("pi")))
syms.AddItem(v)
mod.SetItem(c.Str("items"), syms)
c.Printf(c.Str("%s\n"), mod.CStr())
mod.Delete()
}

121
c/cjson/cjson.go Normal file
View File

@@ -0,0 +1,121 @@
/*
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cjson
import (
_ "unsafe"
"github.com/goplus/llgo/c"
)
const (
LLGoPackage = "link: cjson"
)
// llgo:type C
type JSON struct {
Unused [0]byte
}
//go:linkname Null C.cJSON_CreateNull
func Null() *JSON
//go:linkname True C.cJSON_CreateTrue
func True() *JSON
//go:linkname False C.cJSON_CreateFalse
func False() *JSON
//go:linkname Bool C.cJSON_CreateBool
func Bool(boolean c.Int) *JSON
//go:linkname Number C.cJSON_CreateNumber
func Number(num float64) *JSON
//go:linkname String C.cJSON_CreateString
func String(str *c.Char) *JSON
//go:linkname Array C.cJSON_CreateArray
func Array() *JSON
//go:linkname Object C.cJSON_CreateObject
func Object() *JSON
// raw json
//
//go:linkname Raw C.cJSON_CreateRaw
func Raw(raw *c.Char) *JSON
// Create a string where valuestring references a string so
// it will not be freed by Delete
//
//go:linkname StringRef C.cJSON_CreateStringReference
func StringRef(str *c.Char) *JSON
// Create an object that only references it's elements so
// they will not be freed by Delete
//
//go:linkname ObjectRef C.cJSON_CreateObjectReference
func ObjectRef(child *JSON) *JSON
// Create an array that only references it's elements so
// they will not be freed by Delete
//
//go:linkname ArrayRef C.cJSON_CreateArrayReference
func ArrayRef(child *JSON) *JSON
// Delete a JSON entity and all subentities.
//
// llgo:link (*JSON).Delete C.cJSON_Delete
func (o *JSON) Delete() {}
// Append item to the specified array.
//
// llgo:link (*JSON).AddItem C.cJSON_AddItemToArray
func (o *JSON) AddItem(item *JSON) c.Int { return 0 }
// Append item to the specified object.
//
// llgo:link (*JSON).SetItem C.cJSON_AddItemToObject
func (o *JSON) SetItem(key *c.Char, item *JSON) c.Int { return 0 }
// llgo:link (*JSON).CStr C.cJSON_PrintUnformatted
func (o *JSON) CStr() *c.Char { return nil }
// Same as CStr. Provided for Go+.
//
// llgo:link (*JSON).Cstr C.cJSON_PrintUnformatted
func (o *JSON) Cstr() *c.Char { return nil }
// Render a JSON entity to text for transfer/storage.
//
// llgo:link (*JSON).Print C.cJSON_Print
func (o *JSON) Print() *c.Char { return nil }
// Render a JSON entity to text for transfer/storage without any formatting.
//
// llgo:link (*JSON).PrintUnformatted C.cJSON_PrintUnformatted
func (o *JSON) PrintUnformatted() *c.Char { return nil }
// Render a JSON entity to text using a buffered strategy.
//
// prebuffer is a guess at the final size. guessing well reduces reallocation.
//
// fmt=0 gives unformatted, =1 gives formatted.
//
// llgo:link (*JSON).PrintBuffered C.cJSON_PrintBuffered
func (o *JSON) PrintBuffered(prebuffer c.Int, fmt c.Int) *c.Char { return nil }

BIN
c/cjson/llgo_autogen.lla Normal file

Binary file not shown.

159
c/llama2/llama2.go Normal file
View File

@@ -0,0 +1,159 @@
/*
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package llama2
import (
_ "unsafe"
"github.com/goplus/llgo/c"
)
const (
LLGoPackage = "link"
)
// -----------------------------------------------------------------------------
// llgo:type C
type TokenIndex struct {
Str *c.Char
Id c.Int
}
// llgo:type C
type Tokenizer struct {
Vocab **c.Char
VocabScores *c.Float
SortedVocab *TokenIndex
VocabSize c.Int
MaxTokenLength c.Uint
BytePieces [512]uint8 // stores all single-byte strings
}
//go:linkname BuildTokenizer C.build_tokenizer
func BuildTokenizer(t *Tokenizer, tokenizerPath *c.Char, vocabSize c.Int)
//go:linkname FreeTokenizer C.free_tokenizer
func FreeTokenizer(t *Tokenizer)
// -----------------------------------------------------------------------------
// llgo:type C
type Config struct {
Dim c.Int // transformer dimension
HiddenDim c.Int // for ffn layers
NLayers c.Int // number of layers
NHeads c.Int // number of query heads
NKVHeads c.Int // number of key/value heads (can be < query heads because of multiquery)
VocabSize c.Int // vocabulary size, usually 256 (byte-level)
SeqLen c.Int // max sequence length
}
// llgo:type C
type TransformerWeights struct {
// token embedding table
TokenEmbeddingTable *c.Float // (vocab_size, dim)
// weights for rmsnorms
RmsAttWeight *c.Float // (layer, dim) rmsnorm weights
RmsFfnWeight *c.Float // (layer, dim)
// weights for matmuls. note dim == n_heads * head_size
Wq *c.Float // (layer, dim, n_heads * head_size)
Wk *c.Float // (layer, dim, n_kv_heads * head_size)
Wv *c.Float // (layer, dim, n_kv_heads * head_size)
Wo *c.Float // (layer, n_heads * head_size, dim)
// weights for ffn
W1 *c.Float // (layer, hidden_dim, dim)
W2 *c.Float // (layer, dim, hidden_dim)
W3 *c.Float // (layer, hidden_dim, dim)
// final rmsnorm
RmsFinalWeight *c.Float // (dim,)
// (optional) classifier weights for the logits, on the last layer
Wcls *c.Float
}
// llgo:type C
type RunState struct {
// current wave of activations
X *c.Float // activation at current time stamp (dim,)
Xb *c.Float // same, but inside a residual branch (dim,)
Xb2 *c.Float // an additional buffer just for convenience (dim,)
Hb *c.Float // buffer for hidden dimension in the ffn (hidden_dim,)
Hb2 *c.Float // buffer for hidden dimension in the ffn (hidden_dim,)
Q *c.Float // query (dim,)
K *c.Float // key (dim,)
V *c.Float // value (dim,)
Att *c.Float // buffer for scores/attention values (n_heads, seq_len)
Logits *c.Float // output logits
// kv cache
KeyCache *c.Float // (layer, seq_len, dim)
ValueCache *c.Float // (layer, seq_len, dim)
}
// llgo:type C
type Transformer struct {
Config Config // the hyperparameters of the architecture (the blueprint)
Weights TransformerWeights // the weights of the model
State RunState // buffers for the "wave" of activations in the forward pass
// some more state needed to properly clean up the memory mapping (sigh)
Fd c.Int // file descriptor for memory mapping
Data *c.Float // memory mapped data pointer
FileSize uintptr // size of the checkpoint file in bytes
}
//go:linkname BuildTransformer C.build_transformer
func BuildTransformer(t *Transformer, checkpointPath *c.Char)
//go:linkname FreeTransformer C.free_transformer
func FreeTransformer(t *Transformer)
// -----------------------------------------------------------------------------
// llgo:type C
type ProbIndex struct {
Prob c.Float
Index c.Int
} // struct used when sorting probabilities during top-p sampling
// llgo:type C
type Sampler struct {
VocabSize c.Int
Probindex *ProbIndex // buffer used in top-p sampling
Temperature c.Float
Topp c.Float
RngState uint64
}
//go:linkname BuildSampler C.build_sampler
func BuildSampler(sampler *Sampler, vocabSize c.Int, temperature c.Float, topp c.Float, rngSeed uint64)
//go:linkname FreeSampler C.free_sampler
func FreeSampler(sampler *Sampler)
// -----------------------------------------------------------------------------
//go:linkname Generate C.generate
func Generate(
transformer *Transformer, tokenizer *Tokenizer, sampler *Sampler,
prompt *c.Char, steps c.Int)
//go:linkname Chat C.chat
func Chat(
transformer *Transformer, tokenizer *Tokenizer, sampler *Sampler,
cliUserPrompt *c.Char, cliSystemPrompt *c.Char, steps c.Int)
// -----------------------------------------------------------------------------

View File

@@ -1,6 +1,6 @@
{
"cl": [
"clang -emit-llvm -S -o llgo_autogen.ll -c llama2/run.c",
"zip llgo_autogen.lla llgo_autogen.ll"
"rm llgo_autogen.lla; zip llgo_autogen.lla llgo_autogen.ll"
]
}

35
c/sqlite/README.md Normal file
View File

@@ -0,0 +1,35 @@
LLGo wrapper of sqlite
=====
[![Build Status](https://github.com/goplus/sqlite/actions/workflows/go.yml/badge.svg)](https://github.com/goplus/sqlite/actions/workflows/go.yml)
[![GitHub release](https://img.shields.io/github/v/tag/goplus/sqlite.svg?label=release)](https://github.com/goplus/sqlite/releases)
[![GoDoc](https://pkg.go.dev/badge/github.com/goplus/sqlite.svg)](https://pkg.go.dev/github.com/goplus/sqlite)
[![Compiler](https://img.shields.io/badge/compiler-llgo-darkgreen.svg)](https://github.com/goplus/llgo)
[![Language](https://img.shields.io/badge/language-Go+-blue.svg)](https://github.com/goplus/gop)
## How to install
```sh
git clone https://github.com/goplus/sqlite.git
cd sqlite
git submodule init
git submodule update
mkdir build.dir
cd build.dir
../sqlite/configure --enable-shared
sudo make install
```
## Demos
The `_demo` directory contains our demos (it start with `_` to prevent the `go` command from compiling it):
* [sqlitedemo](_demo/sqlitedemo/demo.go): a basic sqlite demo
### How to run demos
To run the demos in directory `_demo`:
```sh
cd <demo-directory> # eg. cd _demo/sqlitedemo
llgo run .
```

View File

@@ -2,7 +2,7 @@ package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/x/sqlite"
"github.com/goplus/llgo/c/sqlite"
)
func main() {

BIN
c/sqlite/llgo_autogen.lla Normal file

Binary file not shown.

View File

@@ -22,27 +22,23 @@ import (
"github.com/goplus/llgo/c"
)
type (
Char = c.Char
Int = c.Int
Pointer = c.Pointer
)
const (
LLGoPackage = "link"
LLGoPackage = "link: sqlite3"
)
// llgo:type C
type Sqlite3 struct {
Unused [8]byte
}
// llgo:type C
type Stmt struct {
Unused [8]byte
}
// -----------------------------------------------------------------------------
type Errno Int
type Errno c.Int
const (
OK Errno = 0 // Successful result
@@ -81,10 +77,10 @@ const (
)
// llgo:link (Errno).Errstr C.sqlite3_errstr
func (err Errno) Errstr() *Char { return nil }
func (err Errno) Errstr() *c.Char { return nil }
// llgo:link (*Sqlite3).Errmsg C.sqlite3_errmsg
func (db *Sqlite3) Errmsg() *Char { return nil }
func (db *Sqlite3) Errmsg() *c.Char { return nil }
// llgo:link (*Sqlite3).Errcode C.sqlite3_errcode
func (db *Sqlite3) Errcode() Errno { return 0 }
@@ -95,13 +91,13 @@ func (db *Sqlite3) ExtendedErrcode() Errno { return 0 }
// -----------------------------------------------------------------------------
//go:linkname doOpen C.sqlite3_open
func doOpen(filename *Char, ppDb **Sqlite3) Errno
func doOpen(filename *c.Char, ppDb **Sqlite3) Errno
//go:linkname doOpenV2 C.sqlite3_open_v2
func doOpenV2(filename *Char, ppDb **Sqlite3, flags OpenFlags, zVfs *Char) Errno
func doOpenV2(filename *c.Char, ppDb **Sqlite3, flags OpenFlags, zVfs *c.Char) Errno
// OpenFlags represents SQLite open flags.
type OpenFlags Int
type OpenFlags c.Int
const (
OpenReadOnly OpenFlags = 0x00000001
@@ -130,7 +126,7 @@ const (
// Opening A New Database Connection
// filename: Database filename (UTF-8)
func Open(filename *Char) (db *Sqlite3, err Errno) {
func Open(filename *c.Char) (db *Sqlite3, err Errno) {
err = doOpen(filename, &db)
return
}
@@ -138,7 +134,7 @@ func Open(filename *Char) (db *Sqlite3, err Errno) {
// Opening A New Database Connection
// filename: Database filename (UTF-8)
// zVfs: Name of VFS module to use
func OpenV2(filename *Char, flags OpenFlags, zVfs *Char) (db *Sqlite3, err Errno) {
func OpenV2(filename *c.Char, flags OpenFlags, zVfs *c.Char) (db *Sqlite3, err Errno) {
err = doOpenV2(filename, &db, flags, zVfs)
return
}
@@ -156,22 +152,22 @@ func (db *Sqlite3) CloseV2() Errno { return 0 }
// -----------------------------------------------------------------------------
// llgo:link (*Sqlite3).doPrepare C.sqlite3_prepare
func (*Sqlite3) doPrepare(*Char, Int, **Stmt, **Char) Errno {
func (*Sqlite3) doPrepare(*c.Char, c.Int, **Stmt, **c.Char) Errno {
return 0
}
// llgo:link (*Sqlite3).doPrepareV2 C.sqlite3_prepare_v2
func (*Sqlite3) doPrepareV2(*Char, Int, **Stmt, **Char) Errno {
func (*Sqlite3) doPrepareV2(*c.Char, c.Int, **Stmt, **c.Char) Errno {
return 0
}
// llgo:link (*Sqlite3).doPrepareV3 C.sqlite3_prepare_v3
func (*Sqlite3) doPrepareV3(*Char, Int, PrepareFlags, **Stmt, **Char) Errno {
func (*Sqlite3) doPrepareV3(*c.Char, c.Int, PrepareFlags, **Stmt, **c.Char) Errno {
return 0
}
// PrepareFlags represents SQLite prepare flags.
type PrepareFlags Int
type PrepareFlags c.Int
const (
PreparePersistent PrepareFlags = 0x01
@@ -181,17 +177,17 @@ const (
// Compiling An SQL Statement
// tail: Pointer to unused portion of sql
func (db *Sqlite3) Prepare(sql string, tail **Char) (stmt *Stmt, err Errno) {
func (db *Sqlite3) Prepare(sql string, tail **c.Char) (stmt *Stmt, err Errno) {
err = db.doPrepare(c.GoStringData(sql), c.Int(len(sql)), &stmt, tail)
return
}
func (db *Sqlite3) PrepareV2(sql string, tail **Char) (stmt *Stmt, err Errno) {
func (db *Sqlite3) PrepareV2(sql string, tail **c.Char) (stmt *Stmt, err Errno) {
err = db.doPrepareV2(c.GoStringData(sql), c.Int(len(sql)), &stmt, tail)
return
}
func (db *Sqlite3) PrepareV3(sql string, flags PrepareFlags, tail **Char) (stmt *Stmt, err Errno) {
func (db *Sqlite3) PrepareV3(sql string, flags PrepareFlags, tail **c.Char) (stmt *Stmt, err Errno) {
err = db.doPrepareV3(c.GoStringData(sql), c.Int(len(sql)), flags, &stmt, tail)
return
}
@@ -204,10 +200,10 @@ func (stmt *Stmt) Close() Errno { return 0 }
// -----------------------------------------------------------------------------
// llgo:link (*Stmt).BindInt C.sqlite3_bind_int
func (*Stmt) BindInt(idx Int, val Int) Errno { return 0 }
func (*Stmt) BindInt(idx c.Int, val c.Int) Errno { return 0 }
// llgo:link (*Stmt).BindInt64 C.sqlite3_bind_int64
func (*Stmt) BindInt64(idx Int, val int64) Errno { return 0 }
func (*Stmt) BindInt64(idx c.Int, val int64) Errno { return 0 }
/*
const (
@@ -217,7 +213,9 @@ const (
*/
// llgo:link (*Stmt).BindText C.sqlite3_bind_text
func (*Stmt) BindText(idx Int, val *Char, nByte Int, destructor func(Pointer)) Errno { return 0 }
func (*Stmt) BindText(idx c.Int, val *c.Char, nByte c.Int, destructor func(c.Pointer)) Errno {
return 0
}
// -----------------------------------------------------------------------------
@@ -236,19 +234,19 @@ func (*Stmt) Step() Errno { return 0 }
// -----------------------------------------------------------------------------
// llgo:link (*Stmt).ColumnCount C.sqlite3_column_count
func (stmt *Stmt) ColumnCount() Int { return 0 }
func (stmt *Stmt) ColumnCount() c.Int { return 0 }
// llgo:link (*Stmt).ColumnName C.sqlite3_column_name
func (stmt *Stmt) ColumnName(idx Int) *Char { return nil }
func (stmt *Stmt) ColumnName(idx c.Int) *c.Char { return nil }
// llgo:link (*Stmt).ColumnInt C.sqlite3_column_int
func (stmt *Stmt) ColumnInt(idx Int) Int { return 0 }
func (stmt *Stmt) ColumnInt(idx c.Int) c.Int { return 0 }
// llgo:link (*Stmt).ColumnInt64 C.sqlite3_column_int64
func (stmt *Stmt) ColumnInt64(idx Int) int64 { return 0 }
func (stmt *Stmt) ColumnInt64(idx c.Int) int64 { return 0 }
// llgo:link (*Stmt).ColumnText C.sqlite3_column_text
func (stmt *Stmt) ColumnText(idx Int) *Char { return nil }
func (stmt *Stmt) ColumnText(idx c.Int) *c.Char { return nil }
// -----------------------------------------------------------------------------
@@ -256,8 +254,8 @@ func (stmt *Stmt) ColumnText(idx Int) *Char { return nil }
//
// llgo:link (*Sqlite3).Exec C.sqlite3_exec
func (*Sqlite3) Exec(
sql *Char, callback func(arg Pointer, resultCols Int, colVals, colNames **Char) Int,
arg Pointer, errmsg **Char) Errno {
sql *c.Char, callback func(arg c.Pointer, resultCols c.Int, colVals, colNames **c.Char) c.Int,
arg c.Pointer, errmsg **c.Char) Errno {
return 0
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/c/cjson"
"github.com/goplus/llgo/py"
"github.com/goplus/llgo/py/inspect"
)
func main() {
if c.Argc < 2 {
c.Fprintf(c.Stderr, c.Str("Usage: pydump <pythonLibPath>\n"))
return
}
pyLib := c.Index(c.Argv, 1)
py.Initialize()
root := cjson.Object()
root.SetItem(c.Str("name"), cjson.String(pyLib))
items := cjson.Array()
mod := py.ImportModule(pyLib)
keys := mod.ModuleGetDict().DictKeys()
for i, n := uintptr(0), keys.ListLen(); i < n; i++ {
key := keys.ListItem(i)
val := mod.GetAttr(key)
doc := val.GetAttrString(c.Str("__doc__"))
sym := cjson.Object()
sym.SetItem(c.Str("type"), cjson.String(val.Type().TypeName().CStr()))
sym.SetItem(c.Str("name"), cjson.String(key.CStr()))
if doc != nil {
sym.SetItem(c.Str("doc"), cjson.String(doc.CStr()))
}
if val.Callable() != 0 {
sig := inspect.Signature(val)
sym.SetItem(c.Str("sig"), cjson.String(sig.Str().CStr()))
}
items.AddItem(sym)
}
root.SetItem(c.Str("items"), items)
c.Printf(c.Str("%s\n"), root.CStr())
}

View File

@@ -22,7 +22,7 @@ import (
"log"
"os"
"github.com/goplus/llgo/x/ar"
"github.com/goplus/llgo/xtool/ar"
)
func main() {

View File

@@ -22,7 +22,7 @@ import (
"fmt"
"os"
"github.com/goplus/llgo/x/clang/parser"
"github.com/goplus/llgo/xtool/clang/parser"
)
var (

View File

@@ -20,7 +20,7 @@ import (
"fmt"
"os"
"github.com/goplus/llgo/x/clang/preprocessor"
"github.com/goplus/llgo/xtool/clang/preprocessor"
)
func usage() {

View File

@@ -33,6 +33,7 @@ func main() {
llgenDir(dir + "/cl/_testlibc")
llgenDir(dir + "/cl/_testrt")
llgenDir(dir+"/cl/_testpy", "")
llgenDir(dir+"/cl/_testdata", "")
}

242
chore/llpyg/llpyg.go Normal file
View File

@@ -0,0 +1,242 @@
/*
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
import (
"bytes"
"encoding/json"
"fmt"
"go/ast"
"go/token"
"go/types"
"log"
"os"
"os/exec"
"strings"
"github.com/goplus/gogen"
"github.com/goplus/llgo/chore/llpyg/pysig"
"github.com/goplus/llgo/ssa"
)
type symbol struct {
Name string `json:"name"`
Type string `json:"type"`
Doc string `json:"doc"`
Sig string `json:"sig"`
URL string `json:"url"`
}
type module struct {
Name string `json:"name"`
Items []*symbol `json:"items"`
}
func pydump(pyLib string) (mod module) {
var out bytes.Buffer
cmd := exec.Command("pydump", pyLib)
cmd.Stdout = &out
cmd.Stderr = os.Stderr
cmd.Run()
json.Unmarshal(out.Bytes(), &mod)
return
}
func pysigfetch(pyLib string, names []string) (mod module) {
var out bytes.Buffer
cmd := exec.Command("pysigfetch", pyLib, "-")
cmd.Stdin = strings.NewReader(strings.Join(names, " "))
cmd.Stdout = &out
cmd.Stderr = os.Stderr
cmd.Run()
json.Unmarshal(out.Bytes(), &mod)
return
}
func main() {
if len(os.Args) < 2 {
fmt.Fprintln(os.Stderr, "Usage: llpyg <pythonLibPath>")
return
}
pyLib := os.Args[1]
mod := pydump(pyLib)
if mod.Name != pyLib {
log.Printf("import module %s failed\n", pyLib)
os.Exit(1)
}
pkg := gogen.NewPackage("", pyLib, nil)
pkg.Import("unsafe").MarkForceUsed(pkg) // import _ "unsafe"
py := pkg.Import("github.com/goplus/llgo/py") // import "github.com/goplus/llgo/py"
f := func(cb *gogen.CodeBuilder) int {
cb.Val("py." + mod.Name)
return 1
}
defs := pkg.NewConstDefs(pkg.Types.Scope())
defs.New(f, 0, 0, nil, "LLGoPackage")
obj := py.Ref("Object").(*types.TypeName).Type().(*types.Named)
objPtr := types.NewPointer(obj)
ret := types.NewTuple(pkg.NewParam(0, "", objPtr))
ctx := &context{pkg, obj, objPtr, ret, nil, py}
ctx.genMod(pkg, &mod)
skips := ctx.skips
if n := len(skips); n > 0 {
log.Printf("==> There are %d signatures not found, fetch from doc site\n", n)
mod = pysigfetch(pyLib, skips)
ctx.skips = skips[:0]
ctx.genMod(pkg, &mod)
if len(mod.Items) > 0 {
skips = ctx.skips
}
if n := len(skips); n > 0 {
log.Printf("==> Skip %d symbols:\n%v\n", n, skips)
}
}
pkg.WriteTo(os.Stdout)
}
type context struct {
pkg *gogen.Package
obj *types.Named
objPtr *types.Pointer
ret *types.Tuple
skips []string
py gogen.PkgRef
}
func (ctx *context) genMod(pkg *gogen.Package, mod *module) {
for _, sym := range mod.Items {
switch sym.Type {
case "builtin_function_or_method", "function", "ufunc", "method-wrapper":
ctx.genFunc(pkg, sym)
case "str", "float", "bool", "type", "dict", "tuple", "list", "object", "module",
"int", "set", "frozenset", "flags", "bool_", "pybind11_type", "layout",
"memory_format", "qscheme", "dtype", "tensortype": // skip
case "": // pysigfetch: page not found
ctx.skips = append(ctx.skips, sym.Name)
default:
t := sym.Type
if len(t) > 0 && (t[0] >= 'a' && t[0] <= 'z') && !strings.HasSuffix(t, "_info") {
log.Panicln("unsupport type:", sym.Type)
}
}
}
}
func (ctx *context) genFunc(pkg *gogen.Package, sym *symbol) {
name, symSig := sym.Name, sym.Sig
if len(name) == 0 || name[0] == '_' {
return
}
if symSig == "<NULL>" {
ctx.skips = append(ctx.skips, name)
return
}
params, variadic := ctx.genParams(pkg, symSig)
name = genName(name, -1)
sig := types.NewSignatureType(nil, nil, nil, params, ctx.ret, variadic)
fn := pkg.NewFuncDecl(token.NoPos, name, sig)
list := ctx.genDoc(sym.Doc)
if sym.URL != "" {
if len(list) > 0 {
list = append(list, emptyCommentLine)
}
list = append(list, genSee(sym.URL))
}
if len(list) > 0 {
list = append(list, emptyCommentLine)
}
list = append(list, ctx.genLinkname(name, sym))
fn.SetComments(pkg, &ast.CommentGroup{List: list})
// fn.BodyStart(pkg).End()
}
func (ctx *context) genParams(pkg *gogen.Package, sig string) (*types.Tuple, bool) {
args := pysig.Parse(sig)
if len(args) == 0 {
return nil, false
}
n := len(args)
objPtr := ctx.objPtr
list := make([]*types.Var, 0, n)
for i := 0; i < n; i++ {
name := args[i].Name
if name == "/" {
continue
}
if name == "*" || name == "\\*" {
break
}
if strings.HasPrefix(name, "*") {
if name[1] != '*' {
list = append(list, ssa.VArg())
return types.NewTuple(list...), true
}
return types.NewTuple(list...), false
}
list = append(list, pkg.NewParam(0, genName(name, 0), objPtr))
}
return types.NewTuple(list...), false
}
func genName(name string, idxDontTitle int) string {
parts := strings.Split(name, "_")
for i, part := range parts {
if i != idxDontTitle && part != "" {
if c := part[0]; c >= 'a' && c <= 'z' {
part = string(c+'A'-'a') + part[1:]
}
parts[i] = part
}
}
name = strings.Join(parts, "")
switch name {
case "default", "func", "var", "":
name += "_"
}
return name
}
func (ctx *context) genLinkname(name string, sym *symbol) *ast.Comment {
return &ast.Comment{Text: "//go:linkname " + name + " py." + sym.Name}
}
func (ctx *context) genDoc(doc string) []*ast.Comment {
if doc == "" {
return make([]*ast.Comment, 0, 4)
}
lines := strings.Split(doc, "\n")
list := make([]*ast.Comment, len(lines), len(lines)+4)
for i, line := range lines {
list[i] = &ast.Comment{Text: "// " + line}
}
return list
}
func genSee(url string) *ast.Comment {
return &ast.Comment{Text: "// See " + url}
}
var (
emptyCommentLine = &ast.Comment{Text: "//"}
)

100
chore/llpyg/pysig/parse.go Normal file
View File

@@ -0,0 +1,100 @@
/*
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pysig
import (
"strings"
)
type Arg struct {
Name string
Type string
DefVal string
}
// Parse parses a Python function signature.
func Parse(sig string) (args []*Arg) {
sig = strings.TrimPrefix(sig, "(")
for {
pos := strings.IndexAny(sig, ",:=)")
if pos <= 0 {
return
}
arg := &Arg{Name: strings.TrimSpace(sig[:pos])}
args = append(args, arg)
c := sig[pos]
sig = sig[pos+1:]
switch c {
case ',':
continue
case ':':
arg.Type, sig = parseType(sig)
if strings.HasPrefix(sig, "=") {
arg.DefVal, sig = parseDefVal(sig[1:])
}
case '=':
arg.DefVal, sig = parseDefVal(sig)
case ')':
return
}
sig = strings.TrimPrefix(sig, ",")
}
}
const (
allSpecials = "([<'\""
)
var pairStops = map[byte]string{
'(': ")" + allSpecials,
'[': "]" + allSpecials,
'<': ">" + allSpecials,
'\'': "'" + allSpecials,
'"': "\"",
}
func parseText(sig string, stops string) (left string) {
for {
pos := strings.IndexAny(sig, stops)
if pos < 0 {
return sig
}
if c := sig[pos]; c != stops[0] {
if pstop, ok := pairStops[c]; ok {
sig = strings.TrimPrefix(parseText(sig[pos+1:], pstop), pstop[:1])
continue
}
}
return sig[pos:]
}
}
// stops: "=,)"
func parseType(sig string) (string, string) {
left := parseText(sig, "=,)"+allSpecials)
return resultOf(sig, left), left
}
// stops: ",)"
func parseDefVal(sig string) (string, string) {
left := parseText(sig, ",)"+allSpecials)
return resultOf(sig, left), left
}
func resultOf(sig, left string) string {
return strings.TrimSpace(sig[:len(sig)-len(left)])
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pysig
import "testing"
func TestParse(t *testing.T) {
type testCase struct {
sig string
args []*Arg
}
cases := []testCase{
{"(start=None, *, unit: 'str | None' = None) -> 'TimedeltaIndex'", []*Arg{
{Name: "start", DefVal: "None"},
{Name: "*"},
{Name: "unit", Type: "'str | None'", DefVal: "None"},
}},
{"()", nil},
{"(a =", []*Arg{{Name: "a"}}},
{"(a) -> int", []*Arg{{Name: "a"}}},
{"(a: int)", []*Arg{{Name: "a", Type: "int"}}},
{"(a: int = 1, b: float)", []*Arg{{Name: "a", Type: "int", DefVal: "1"}, {Name: "b", Type: "float"}}},
{"(a = <1>, b = 2.0)", []*Arg{{Name: "a", DefVal: "<1>"}, {Name: "b", DefVal: "2.0"}}},
{"(a: 'Suffixes' = ('_x', '_y'))", []*Arg{{Name: "a", Type: "'Suffixes'", DefVal: "('_x', '_y')"}}},
}
for _, c := range cases {
args := Parse(c.sig)
if len(args) != len(c.args) {
t.Fatalf("%s: len(args) = %v, want %v", c.sig, len(args), len(c.args))
}
for i, arg := range args {
want := c.args[i]
if arg.Name != want.Name || arg.Type != want.Type || arg.DefVal != want.DefVal {
t.Fatalf("%s: args[%v] = %v, want %v", c.sig, i, arg, want)
}
}
}
}

View File

@@ -21,7 +21,7 @@ import (
"log"
"os"
"github.com/goplus/llgo/x/env/llvm"
"github.com/goplus/llgo/xtool/env/llvm"
)
func main() {

View File

@@ -20,8 +20,8 @@ import (
"fmt"
"os"
"github.com/goplus/llgo/x/env/llvm"
"github.com/goplus/llgo/x/nm"
"github.com/goplus/llgo/xtool/env/llvm"
"github.com/goplus/llgo/xtool/nm"
)
func main() {
@@ -73,6 +73,11 @@ func makeIndex() {
}
func query(q string) {
if len(q) > 0 {
if c := q[0]; c != '*' && c != '_' {
q = "_" + q
}
}
files, err := nm.Query(indexDir(), q)
check(err)
for _, f := range files {

View File

@@ -18,14 +18,14 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
%2 = call i64 @main.max(i64 1, i64 2)
ret void
ret i32 0
}
define i64 @main.max(i64 %0, i64 %1) {

View File

@@ -1,7 +1,7 @@
; ModuleID = 'main'
source_filename = "main"
@main.hello = global ptr null
@main.hello = global [7 x i8] undef
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@@ -27,7 +27,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -35,7 +35,7 @@ _llgo_0:
call void @main.init()
%2 = call i64 @"github.com/goplus/llgo/cl/internal/stdio.Max"(i64 2, i64 100)
call void (ptr, ...) @printf(ptr @main.hello)
ret void
ret i32 0
}
declare void @"github.com/goplus/llgo/cl/internal/stdio.init"()

View File

@@ -1,7 +1,7 @@
; ModuleID = 'main'
source_filename = "main"
@main.format = global ptr null
@main.format = global [10 x i8] undef
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@@ -42,7 +42,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -50,7 +50,7 @@ _llgo_0:
call void @main.init()
%2 = call i64 @"(main.T).Add"(i64 1, i64 2)
call void (ptr, ...) @printf(ptr @main.format, i64 %2)
ret void
ret i32 0
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -13,6 +13,14 @@ func gwrite(b []byte) {
c.Printf(c.Str("%s"), b)
}
func printbool(v bool) {
if v {
printstring("true")
} else {
printstring("false")
}
}
func printfloat(v float64) {
switch {
case v != v:
@@ -177,14 +185,37 @@ func main() {
printnl()
prinfsub(100.1)
printnl()
printnum(float32(1e9))
printany(float32(1e9))
printnl()
printnum(float64(2e9))
printany(float64(2e9))
printnl()
var b bool = true
if b == true && b != false {
println("check bool", b)
}
n1 := 0b1001
n2 := 0b0011
println("check &^", n1&^n2 == 0b1000, n2&^n1 == 0b0010)
println(true, false, 'a', 'A', rune('中'),
int8(1), int16(2), int32(3), int64(4), 5,
uint8(1), uint16(2), uint32(3), uint64(4), uintptr(5),
"llgo")
}
func println(args ...any) {
for i, v := range args {
if i != 0 {
printstring(" ")
}
printany(v)
}
printnl()
}
func printnum(v any) {
func printany(v any) {
switch v := v.(type) {
case bool:
printbool(v)
case int:
printint(int64(v))
case int8:
@@ -211,6 +242,8 @@ func printnum(v any) {
printfloat(float64(v))
case float64:
printfloat(float64(v))
case string:
printstring(v)
}
}

View File

@@ -13,13 +13,19 @@ source_filename = "main"
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@1 = private unnamed_addr constant [5 x i8] c"llgo\00", align 1
@2 = private unnamed_addr constant [4 x i8] c"NaN\00", align 1
@3 = private unnamed_addr constant [5 x i8] c"+Inf\00", align 1
@4 = private unnamed_addr constant [5 x i8] c"-Inf\00", align 1
@5 = private unnamed_addr constant [17 x i8] c"0123456789abcdef\00", align 1
@6 = private unnamed_addr constant [2 x i8] c"-\00", align 1
@7 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@8 = private unnamed_addr constant [2 x i8] c" \00", align 1
@2 = private unnamed_addr constant [11 x i8] c"check bool\00", align 1
@3 = private unnamed_addr constant [9 x i8] c"check &^\00", align 1
@4 = private unnamed_addr constant [5 x i8] c"llgo\00", align 1
@5 = private unnamed_addr constant [5 x i8] c"true\00", align 1
@6 = private unnamed_addr constant [6 x i8] c"false\00", align 1
@7 = private unnamed_addr constant [4 x i8] c"NaN\00", align 1
@8 = private unnamed_addr constant [5 x i8] c"+Inf\00", align 1
@9 = private unnamed_addr constant [5 x i8] c"-Inf\00", align 1
@10 = private unnamed_addr constant [17 x i8] c"0123456789abcdef\00", align 1
@11 = private unnamed_addr constant [2 x i8] c"-\00", align 1
@12 = private unnamed_addr constant [2 x i8] c" \00", align 1
@13 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@14 = private unnamed_addr constant [2 x i8] c" \00", align 1
define %"github.com/goplus/llgo/internal/runtime.Slice" @main.bytes(%"github.com/goplus/llgo/internal/runtime.String" %0) {
_llgo_0:
@@ -45,7 +51,7 @@ _llgo_0:
define void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %0) {
_llgo_0:
%1 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %0)
%1 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
%2 = icmp eq i64 %1, 0
br i1 %2, label %_llgo_1, label %_llgo_2
@@ -71,7 +77,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -94,13 +100,115 @@ _llgo_0:
call void @main.printnl()
%3 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 13)
%4 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %3, i64 1315859240)
call void @main.printnum(%"github.com/goplus/llgo/internal/runtime.iface" %4)
call void @main.printany(%"github.com/goplus/llgo/internal/runtime.iface" %4)
call void @main.printnl()
%5 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 14)
%6 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %5, i64 4746175415993761792)
call void @main.printnum(%"github.com/goplus/llgo/internal/runtime.iface" %6)
call void @main.printany(%"github.com/goplus/llgo/internal/runtime.iface" %6)
call void @main.printnl()
ret void
br i1 true, label %_llgo_3, label %_llgo_2
_llgo_1: ; preds = %_llgo_3
%7 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
%8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %7, i64 0
%9 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @2, i64 10)
%10 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %9)
store %"github.com/goplus/llgo/internal/runtime.iface" %10, ptr %8, align 8
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %7, i64 1
%12 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1)
%13 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %12, i64 -1)
store %"github.com/goplus/llgo/internal/runtime.iface" %13, ptr %11, align 8
%14 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %7, i64 16, i64 2, i64 0, i64 2, i64 2)
call void @main.println(%"github.com/goplus/llgo/internal/runtime.Slice" %14)
br label %_llgo_2
_llgo_2: ; preds = %_llgo_3, %_llgo_1, %_llgo_0
%15 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 48)
%16 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %15, i64 0
%17 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @3, i64 8)
%18 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %17)
store %"github.com/goplus/llgo/internal/runtime.iface" %18, ptr %16, align 8
%19 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %15, i64 1
%20 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1)
%21 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %20, i64 -1)
store %"github.com/goplus/llgo/internal/runtime.iface" %21, ptr %19, align 8
%22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %15, i64 2
%23 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1)
%24 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %23, i64 -1)
store %"github.com/goplus/llgo/internal/runtime.iface" %24, ptr %22, align 8
%25 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %15, i64 16, i64 3, i64 0, i64 3, i64 3)
call void @main.println(%"github.com/goplus/llgo/internal/runtime.Slice" %25)
%26 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 256)
%27 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 0
%28 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1)
%29 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %28, i64 -1)
store %"github.com/goplus/llgo/internal/runtime.iface" %29, ptr %27, align 8
%30 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 1
%31 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1)
%32 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %31, i64 0)
store %"github.com/goplus/llgo/internal/runtime.iface" %32, ptr %30, align 8
%33 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 2
%34 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5)
%35 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %34, i64 97)
store %"github.com/goplus/llgo/internal/runtime.iface" %35, ptr %33, align 8
%36 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 3
%37 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5)
%38 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %37, i64 65)
store %"github.com/goplus/llgo/internal/runtime.iface" %38, ptr %36, align 8
%39 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 4
%40 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5)
%41 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %40, i64 20013)
store %"github.com/goplus/llgo/internal/runtime.iface" %41, ptr %39, align 8
%42 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 5
%43 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 3)
%44 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %43, i64 1)
store %"github.com/goplus/llgo/internal/runtime.iface" %44, ptr %42, align 8
%45 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 6
%46 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 4)
%47 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %46, i64 2)
store %"github.com/goplus/llgo/internal/runtime.iface" %47, ptr %45, align 8
%48 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 7
%49 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5)
%50 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %49, i64 3)
store %"github.com/goplus/llgo/internal/runtime.iface" %50, ptr %48, align 8
%51 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 8
%52 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 6)
%53 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %52, i64 4)
store %"github.com/goplus/llgo/internal/runtime.iface" %53, ptr %51, align 8
%54 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 9
%55 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
%56 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %55, i64 5)
store %"github.com/goplus/llgo/internal/runtime.iface" %56, ptr %54, align 8
%57 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 10
%58 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 8)
%59 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %58, i64 1)
store %"github.com/goplus/llgo/internal/runtime.iface" %59, ptr %57, align 8
%60 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 11
%61 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 9)
%62 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %61, i64 2)
store %"github.com/goplus/llgo/internal/runtime.iface" %62, ptr %60, align 8
%63 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 12
%64 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 10)
%65 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %64, i64 3)
store %"github.com/goplus/llgo/internal/runtime.iface" %65, ptr %63, align 8
%66 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 13
%67 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 11)
%68 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %67, i64 4)
store %"github.com/goplus/llgo/internal/runtime.iface" %68, ptr %66, align 8
%69 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 14
%70 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 12)
%71 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %70, i64 5)
store %"github.com/goplus/llgo/internal/runtime.iface" %71, ptr %69, align 8
%72 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 15
%73 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @4, i64 4)
%74 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %73)
store %"github.com/goplus/llgo/internal/runtime.iface" %74, ptr %72, align 8
%75 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %26, i64 16, i64 16, i64 0, i64 16, i64 16)
call void @main.println(%"github.com/goplus/llgo/internal/runtime.Slice" %75)
ret i32 0
_llgo_3: ; preds = %_llgo_0
br i1 true, label %_llgo_1, label %_llgo_2
}
define void @main.prinfsub(double %0) {
@@ -117,18 +225,223 @@ _llgo_0:
ret void
}
define void @main.printany(%"github.com/goplus/llgo/internal/runtime.iface" %0) {
_llgo_0:
%1 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1)
%2 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %1)
%3 = extractvalue { i64, i1 } %2, 0
%4 = trunc i64 %3 to i1
%5 = extractvalue { i64, i1 } %2, 1
br i1 %5, label %_llgo_2, label %_llgo_3
_llgo_1: ; preds = %_llgo_30, %_llgo_29, %_llgo_28, %_llgo_26, %_llgo_24, %_llgo_22, %_llgo_20, %_llgo_18, %_llgo_16, %_llgo_14, %_llgo_12, %_llgo_10, %_llgo_8, %_llgo_6, %_llgo_4, %_llgo_2
ret void
_llgo_2: ; preds = %_llgo_0
call void @main.printbool(i1 %4)
br label %_llgo_1
_llgo_3: ; preds = %_llgo_0
%6 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
%7 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %6)
%8 = extractvalue { i64, i1 } %7, 0
%9 = extractvalue { i64, i1 } %7, 1
br i1 %9, label %_llgo_4, label %_llgo_5
_llgo_4: ; preds = %_llgo_3
call void @main.printint(i64 %8)
br label %_llgo_1
_llgo_5: ; preds = %_llgo_3
%10 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 3)
%11 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %10)
%12 = extractvalue { i64, i1 } %11, 0
%13 = trunc i64 %12 to i8
%14 = extractvalue { i64, i1 } %11, 1
br i1 %14, label %_llgo_6, label %_llgo_7
_llgo_6: ; preds = %_llgo_5
%15 = sext i8 %13 to i64
call void @main.printint(i64 %15)
br label %_llgo_1
_llgo_7: ; preds = %_llgo_5
%16 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 4)
%17 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %16)
%18 = extractvalue { i64, i1 } %17, 0
%19 = trunc i64 %18 to i16
%20 = extractvalue { i64, i1 } %17, 1
br i1 %20, label %_llgo_8, label %_llgo_9
_llgo_8: ; preds = %_llgo_7
%21 = sext i16 %19 to i64
call void @main.printint(i64 %21)
br label %_llgo_1
_llgo_9: ; preds = %_llgo_7
%22 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5)
%23 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %22)
%24 = extractvalue { i64, i1 } %23, 0
%25 = trunc i64 %24 to i32
%26 = extractvalue { i64, i1 } %23, 1
br i1 %26, label %_llgo_10, label %_llgo_11
_llgo_10: ; preds = %_llgo_9
%27 = sext i32 %25 to i64
call void @main.printint(i64 %27)
br label %_llgo_1
_llgo_11: ; preds = %_llgo_9
%28 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 6)
%29 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %28)
%30 = extractvalue { i64, i1 } %29, 0
%31 = extractvalue { i64, i1 } %29, 1
br i1 %31, label %_llgo_12, label %_llgo_13
_llgo_12: ; preds = %_llgo_11
call void @main.printint(i64 %30)
br label %_llgo_1
_llgo_13: ; preds = %_llgo_11
%32 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 7)
%33 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %32)
%34 = extractvalue { i64, i1 } %33, 0
%35 = extractvalue { i64, i1 } %33, 1
br i1 %35, label %_llgo_14, label %_llgo_15
_llgo_14: ; preds = %_llgo_13
call void @main.printuint(i64 %34)
br label %_llgo_1
_llgo_15: ; preds = %_llgo_13
%36 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 8)
%37 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %36)
%38 = extractvalue { i64, i1 } %37, 0
%39 = trunc i64 %38 to i8
%40 = extractvalue { i64, i1 } %37, 1
br i1 %40, label %_llgo_16, label %_llgo_17
_llgo_16: ; preds = %_llgo_15
%41 = zext i8 %39 to i64
call void @main.printuint(i64 %41)
br label %_llgo_1
_llgo_17: ; preds = %_llgo_15
%42 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 9)
%43 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %42)
%44 = extractvalue { i64, i1 } %43, 0
%45 = trunc i64 %44 to i16
%46 = extractvalue { i64, i1 } %43, 1
br i1 %46, label %_llgo_18, label %_llgo_19
_llgo_18: ; preds = %_llgo_17
%47 = zext i16 %45 to i64
call void @main.printuint(i64 %47)
br label %_llgo_1
_llgo_19: ; preds = %_llgo_17
%48 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 10)
%49 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %48)
%50 = extractvalue { i64, i1 } %49, 0
%51 = trunc i64 %50 to i32
%52 = extractvalue { i64, i1 } %49, 1
br i1 %52, label %_llgo_20, label %_llgo_21
_llgo_20: ; preds = %_llgo_19
%53 = zext i32 %51 to i64
call void @main.printuint(i64 %53)
br label %_llgo_1
_llgo_21: ; preds = %_llgo_19
%54 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 11)
%55 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %54)
%56 = extractvalue { i64, i1 } %55, 0
%57 = extractvalue { i64, i1 } %55, 1
br i1 %57, label %_llgo_22, label %_llgo_23
_llgo_22: ; preds = %_llgo_21
call void @main.printuint(i64 %56)
br label %_llgo_1
_llgo_23: ; preds = %_llgo_21
%58 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 12)
%59 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %58)
%60 = extractvalue { i64, i1 } %59, 0
%61 = extractvalue { i64, i1 } %59, 1
br i1 %61, label %_llgo_24, label %_llgo_25
_llgo_24: ; preds = %_llgo_23
call void @main.printuint(i64 %60)
br label %_llgo_1
_llgo_25: ; preds = %_llgo_23
%62 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 13)
%63 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %62)
%64 = extractvalue { i64, i1 } %63, 0
%65 = trunc i64 %64 to i32
%66 = bitcast i32 %65 to float
%67 = extractvalue { i64, i1 } %63, 1
br i1 %67, label %_llgo_26, label %_llgo_27
_llgo_26: ; preds = %_llgo_25
%68 = fpext float %66 to double
call void @main.printfloat(double %68)
br label %_llgo_1
_llgo_27: ; preds = %_llgo_25
%69 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 14)
%70 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %69)
%71 = extractvalue { i64, i1 } %70, 0
%72 = bitcast i64 %71 to double
%73 = extractvalue { i64, i1 } %70, 1
br i1 %73, label %_llgo_28, label %_llgo_29
_llgo_28: ; preds = %_llgo_27
call void @main.printfloat(double %72)
br label %_llgo_1
_llgo_29: ; preds = %_llgo_27
%74 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24)
%75 = call { %"github.com/goplus/llgo/internal/runtime.String", i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2String"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %74)
%76 = extractvalue { %"github.com/goplus/llgo/internal/runtime.String", i1 } %75, 0
%77 = extractvalue { %"github.com/goplus/llgo/internal/runtime.String", i1 } %75, 1
br i1 %77, label %_llgo_30, label %_llgo_1
_llgo_30: ; preds = %_llgo_29
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %76)
br label %_llgo_1
}
define void @main.printbool(i1 %0) {
_llgo_0:
br i1 %0, label %_llgo_1, label %_llgo_3
_llgo_1: ; preds = %_llgo_0
%1 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @5, i64 4)
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %1)
br label %_llgo_2
_llgo_2: ; preds = %_llgo_3, %_llgo_1
ret void
_llgo_3: ; preds = %_llgo_0
%2 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @6, i64 5)
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %2)
br label %_llgo_2
}
define void @main.printfloat(double %0) {
_llgo_0:
%1 = fcmp one double %0, %0
br i1 %1, label %_llgo_1, label %_llgo_3
_llgo_1: ; preds = %_llgo_0
%2 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @2, i64 3)
%2 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @7, i64 3)
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %2)
ret void
_llgo_2: ; preds = %_llgo_7
%3 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @3, i64 4)
%3 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @8, i64 4)
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %3)
ret void
@@ -138,7 +451,7 @@ _llgo_3: ; preds = %_llgo_0
br i1 %5, label %_llgo_6, label %_llgo_7
_llgo_4: ; preds = %_llgo_10
%6 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @4, i64 4)
%6 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @9, i64 4)
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %6)
ret void
@@ -242,64 +555,66 @@ _llgo_24: ; preds = %_llgo_22
br label %_llgo_12
_llgo_25: ; preds = %_llgo_27
%43 = fptosi double %59 to i64
%44 = add i64 %60, 2
%43 = fptosi double %60 to i64
%44 = add i64 %61, 2
%45 = add i64 %43, 48
%46 = trunc i64 %45 to i8
%47 = getelementptr inbounds i8, ptr %11, i64 %44
store i8 %46, ptr %47, align 1
%48 = sitofp i64 %43 to double
%49 = fsub double %59, %48
%50 = fmul double %49, 1.000000e+01
%51 = add i64 %60, 1
%47 = icmp slt i64 %44, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %47)
%48 = getelementptr inbounds i8, ptr %11, i64 %44
store i8 %46, ptr %48, align 1
%49 = sitofp i64 %43 to double
%50 = fsub double %60, %49
%51 = fmul double %50, 1.000000e+01
%52 = add i64 %61, 1
br label %_llgo_27
_llgo_26: ; preds = %_llgo_27
%52 = getelementptr inbounds i8, ptr %11, i64 2
%53 = load i8, ptr %52, align 1
%54 = getelementptr inbounds i8, ptr %11, i64 1
store i8 %53, ptr %54, align 1
%55 = getelementptr inbounds i8, ptr %11, i64 2
store i8 46, ptr %55, align 1
%56 = getelementptr inbounds i8, ptr %11, i64 9
store i8 101, ptr %56, align 1
%57 = getelementptr inbounds i8, ptr %11, i64 10
store i8 43, ptr %57, align 1
%58 = icmp slt i64 %19, 0
br i1 %58, label %_llgo_28, label %_llgo_29
%53 = getelementptr inbounds i8, ptr %11, i64 2
%54 = load i8, ptr %53, align 1
%55 = getelementptr inbounds i8, ptr %11, i64 1
store i8 %54, ptr %55, align 1
%56 = getelementptr inbounds i8, ptr %11, i64 2
store i8 46, ptr %56, align 1
%57 = getelementptr inbounds i8, ptr %11, i64 9
store i8 101, ptr %57, align 1
%58 = getelementptr inbounds i8, ptr %11, i64 10
store i8 43, ptr %58, align 1
%59 = icmp slt i64 %19, 0
br i1 %59, label %_llgo_28, label %_llgo_29
_llgo_27: ; preds = %_llgo_25, %_llgo_12
%59 = phi double [ %18, %_llgo_12 ], [ %50, %_llgo_25 ]
%60 = phi i64 [ 0, %_llgo_12 ], [ %51, %_llgo_25 ]
%61 = icmp slt i64 %60, 7
br i1 %61, label %_llgo_25, label %_llgo_26
%60 = phi double [ %18, %_llgo_12 ], [ %51, %_llgo_25 ]
%61 = phi i64 [ 0, %_llgo_12 ], [ %52, %_llgo_25 ]
%62 = icmp slt i64 %61, 7
br i1 %62, label %_llgo_25, label %_llgo_26
_llgo_28: ; preds = %_llgo_26
%62 = sub i64 0, %19
%63 = getelementptr inbounds i8, ptr %11, i64 10
store i8 45, ptr %63, align 1
%63 = sub i64 0, %19
%64 = getelementptr inbounds i8, ptr %11, i64 10
store i8 45, ptr %64, align 1
br label %_llgo_29
_llgo_29: ; preds = %_llgo_28, %_llgo_26
%64 = phi i64 [ %19, %_llgo_26 ], [ %62, %_llgo_28 ]
%65 = sdiv i64 %64, 100
%66 = trunc i64 %65 to i8
%67 = add i8 %66, 48
%68 = getelementptr inbounds i8, ptr %11, i64 11
store i8 %67, ptr %68, align 1
%69 = sdiv i64 %64, 10
%70 = trunc i64 %69 to i8
%71 = urem i8 %70, 10
%72 = add i8 %71, 48
%73 = getelementptr inbounds i8, ptr %11, i64 12
store i8 %72, ptr %73, align 1
%74 = srem i64 %64, 10
%75 = trunc i64 %74 to i8
%76 = add i8 %75, 48
%77 = getelementptr inbounds i8, ptr %11, i64 13
store i8 %76, ptr %77, align 1
%78 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %11, i64 1, i64 14, i64 0, i64 14, i64 14)
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %78)
%65 = phi i64 [ %19, %_llgo_26 ], [ %63, %_llgo_28 ]
%66 = sdiv i64 %65, 100
%67 = trunc i64 %66 to i8
%68 = add i8 %67, 48
%69 = getelementptr inbounds i8, ptr %11, i64 11
store i8 %68, ptr %69, align 1
%70 = sdiv i64 %65, 10
%71 = trunc i64 %70 to i8
%72 = urem i8 %71, 10
%73 = add i8 %72, 48
%74 = getelementptr inbounds i8, ptr %11, i64 12
store i8 %73, ptr %74, align 1
%75 = srem i64 %65, 10
%76 = trunc i64 %75 to i8
%77 = add i8 %76, 48
%78 = getelementptr inbounds i8, ptr %11, i64 13
store i8 %77, ptr %78, align 1
%79 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %11, i64 1, i64 14, i64 0, i64 14, i64 14)
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %79)
ret void
}
@@ -309,43 +624,49 @@ _llgo_0:
br label %_llgo_3
_llgo_1: ; preds = %_llgo_3
%2 = urem i64 %14, 16
%3 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @5, i64 16)
%4 = call ptr @"github.com/goplus/llgo/internal/runtime.StringData"(%"github.com/goplus/llgo/internal/runtime.String" %3)
%2 = urem i64 %17, 16
%3 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @10, i64 16)
%4 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %3, 0
%5 = getelementptr inbounds i8, ptr %4, i64 %2
%6 = load i8, ptr %5, align 1
%7 = getelementptr inbounds i8, ptr %1, i64 %15
store i8 %6, ptr %7, align 1
%8 = icmp ult i64 %14, 16
br i1 %8, label %_llgo_5, label %_llgo_4
%7 = icmp slt i64 %18, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %7)
%8 = getelementptr inbounds i8, ptr %1, i64 %18
store i8 %6, ptr %8, align 1
%9 = icmp ult i64 %17, 16
br i1 %9, label %_llgo_5, label %_llgo_4
_llgo_2: ; preds = %_llgo_5, %_llgo_3
%9 = sub i64 %15, 1
%10 = getelementptr inbounds i8, ptr %1, i64 %9
store i8 120, ptr %10, align 1
%11 = sub i64 %9, 1
%12 = getelementptr inbounds i8, ptr %1, i64 %11
store i8 48, ptr %12, align 1
%13 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %1, i64 1, i64 100, i64 %11, i64 100, i64 100)
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %13)
%10 = sub i64 %18, 1
%11 = icmp slt i64 %10, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %11)
%12 = getelementptr inbounds i8, ptr %1, i64 %10
store i8 120, ptr %12, align 1
%13 = sub i64 %10, 1
%14 = icmp slt i64 %13, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %14)
%15 = getelementptr inbounds i8, ptr %1, i64 %13
store i8 48, ptr %15, align 1
%16 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %1, i64 1, i64 100, i64 %13, i64 100, i64 100)
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %16)
ret void
_llgo_3: ; preds = %_llgo_4, %_llgo_0
%14 = phi i64 [ %0, %_llgo_0 ], [ %17, %_llgo_4 ]
%15 = phi i64 [ 99, %_llgo_0 ], [ %18, %_llgo_4 ]
%16 = icmp sgt i64 %15, 0
br i1 %16, label %_llgo_1, label %_llgo_2
%17 = phi i64 [ %0, %_llgo_0 ], [ %20, %_llgo_4 ]
%18 = phi i64 [ 99, %_llgo_0 ], [ %21, %_llgo_4 ]
%19 = icmp sgt i64 %18, 0
br i1 %19, label %_llgo_1, label %_llgo_2
_llgo_4: ; preds = %_llgo_5, %_llgo_1
%17 = udiv i64 %14, 16
%18 = sub i64 %15, 1
%20 = udiv i64 %17, 16
%21 = sub i64 %18, 1
br label %_llgo_3
_llgo_5: ; preds = %_llgo_1
%19 = sub i64 100, %15
%20 = load i64, ptr @main.minhexdigits, align 4
%21 = icmp sge i64 %19, %20
br i1 %21, label %_llgo_2, label %_llgo_4
%22 = sub i64 100, %18
%23 = load i64, ptr @main.minhexdigits, align 4
%24 = icmp sge i64 %22, %23
br i1 %24, label %_llgo_2, label %_llgo_4
}
define void @main.printint(i64 %0) {
@@ -354,7 +675,7 @@ _llgo_0:
br i1 %1, label %_llgo_1, label %_llgo_2
_llgo_1: ; preds = %_llgo_0
%2 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @6, i64 1)
%2 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @11, i64 1)
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %2)
%3 = sub i64 0, %0
br label %_llgo_2
@@ -365,165 +686,50 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main.println(%"github.com/goplus/llgo/internal/runtime.Slice" %0) {
_llgo_0:
%1 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
br label %_llgo_1
_llgo_1: ; preds = %_llgo_5, %_llgo_0
%2 = phi i64 [ -1, %_llgo_0 ], [ %3, %_llgo_5 ]
%3 = add i64 %2, 1
%4 = icmp slt i64 %3, %1
br i1 %4, label %_llgo_2, label %_llgo_3
_llgo_2: ; preds = %_llgo_1
%5 = icmp slt i64 %3, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %5)
%6 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %6, i64 %3
%8 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %7, align 8
%9 = icmp ne i64 %3, 0
br i1 %9, label %_llgo_4, label %_llgo_5
_llgo_3: ; preds = %_llgo_1
call void @main.printnl()
ret void
_llgo_4: ; preds = %_llgo_2
%10 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @12, i64 1)
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %10)
br label %_llgo_5
_llgo_5: ; preds = %_llgo_4, %_llgo_2
call void @main.printany(%"github.com/goplus/llgo/internal/runtime.iface" %8)
br label %_llgo_1
}
define void @main.printnl() {
_llgo_0:
%0 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @7, i64 1)
%0 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @13, i64 1)
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %0)
ret void
}
define void @main.printnum(%"github.com/goplus/llgo/internal/runtime.iface" %0) {
_llgo_0:
%1 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
%2 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %1)
%3 = extractvalue { i64, i1 } %2, 0
%4 = extractvalue { i64, i1 } %2, 1
br i1 %4, label %_llgo_2, label %_llgo_3
_llgo_1: ; preds = %_llgo_26, %_llgo_25, %_llgo_24, %_llgo_22, %_llgo_20, %_llgo_18, %_llgo_16, %_llgo_14, %_llgo_12, %_llgo_10, %_llgo_8, %_llgo_6, %_llgo_4, %_llgo_2
ret void
_llgo_2: ; preds = %_llgo_0
call void @main.printint(i64 %3)
br label %_llgo_1
_llgo_3: ; preds = %_llgo_0
%5 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 3)
%6 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %5)
%7 = extractvalue { i64, i1 } %6, 0
%8 = extractvalue { i64, i1 } %6, 1
br i1 %8, label %_llgo_4, label %_llgo_5
_llgo_4: ; preds = %_llgo_3
call void @main.printint(i64 %7)
br label %_llgo_1
_llgo_5: ; preds = %_llgo_3
%9 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 4)
%10 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %9)
%11 = extractvalue { i64, i1 } %10, 0
%12 = extractvalue { i64, i1 } %10, 1
br i1 %12, label %_llgo_6, label %_llgo_7
_llgo_6: ; preds = %_llgo_5
call void @main.printint(i64 %11)
br label %_llgo_1
_llgo_7: ; preds = %_llgo_5
%13 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5)
%14 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %13)
%15 = extractvalue { i64, i1 } %14, 0
%16 = extractvalue { i64, i1 } %14, 1
br i1 %16, label %_llgo_8, label %_llgo_9
_llgo_8: ; preds = %_llgo_7
call void @main.printint(i64 %15)
br label %_llgo_1
_llgo_9: ; preds = %_llgo_7
%17 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 6)
%18 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %17)
%19 = extractvalue { i64, i1 } %18, 0
%20 = extractvalue { i64, i1 } %18, 1
br i1 %20, label %_llgo_10, label %_llgo_11
_llgo_10: ; preds = %_llgo_9
call void @main.printint(i64 %19)
br label %_llgo_1
_llgo_11: ; preds = %_llgo_9
%21 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 7)
%22 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %21)
%23 = extractvalue { i64, i1 } %22, 0
%24 = extractvalue { i64, i1 } %22, 1
br i1 %24, label %_llgo_12, label %_llgo_13
_llgo_12: ; preds = %_llgo_11
call void @main.printuint(i64 %23)
br label %_llgo_1
_llgo_13: ; preds = %_llgo_11
%25 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 8)
%26 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %25)
%27 = extractvalue { i64, i1 } %26, 0
%28 = extractvalue { i64, i1 } %26, 1
br i1 %28, label %_llgo_14, label %_llgo_15
_llgo_14: ; preds = %_llgo_13
call void @main.printuint(i64 %27)
br label %_llgo_1
_llgo_15: ; preds = %_llgo_13
%29 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 9)
%30 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %29)
%31 = extractvalue { i64, i1 } %30, 0
%32 = extractvalue { i64, i1 } %30, 1
br i1 %32, label %_llgo_16, label %_llgo_17
_llgo_16: ; preds = %_llgo_15
call void @main.printuint(i64 %31)
br label %_llgo_1
_llgo_17: ; preds = %_llgo_15
%33 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 10)
%34 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %33)
%35 = extractvalue { i64, i1 } %34, 0
%36 = extractvalue { i64, i1 } %34, 1
br i1 %36, label %_llgo_18, label %_llgo_19
_llgo_18: ; preds = %_llgo_17
call void @main.printuint(i64 %35)
br label %_llgo_1
_llgo_19: ; preds = %_llgo_17
%37 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 11)
%38 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %37)
%39 = extractvalue { i64, i1 } %38, 0
%40 = extractvalue { i64, i1 } %38, 1
br i1 %40, label %_llgo_20, label %_llgo_21
_llgo_20: ; preds = %_llgo_19
call void @main.printuint(i64 %39)
br label %_llgo_1
_llgo_21: ; preds = %_llgo_19
%41 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 12)
%42 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %41)
%43 = extractvalue { i64, i1 } %42, 0
%44 = extractvalue { i64, i1 } %42, 1
br i1 %44, label %_llgo_22, label %_llgo_23
_llgo_22: ; preds = %_llgo_21
call void @main.printuint(i64 %43)
br label %_llgo_1
_llgo_23: ; preds = %_llgo_21
%45 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 13)
%46 = call { float, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Float32"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %45)
%47 = extractvalue { float, i1 } %46, 0
%48 = extractvalue { float, i1 } %46, 1
br i1 %48, label %_llgo_24, label %_llgo_25
_llgo_24: ; preds = %_llgo_23
%49 = fpext float %47 to double
call void @main.printfloat(double %49)
br label %_llgo_1
_llgo_25: ; preds = %_llgo_23
%50 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 14)
%51 = call { double, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Float64"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %50)
%52 = extractvalue { double, i1 } %51, 0
%53 = extractvalue { double, i1 } %51, 1
br i1 %53, label %_llgo_26, label %_llgo_1
_llgo_26: ; preds = %_llgo_25
call void @main.printfloat(double %52)
br label %_llgo_1
}
define void @main.printsp() {
_llgo_0:
%0 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @8, i64 1)
%0 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @14, i64 1)
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %0)
ret void
}
@@ -541,28 +747,30 @@ _llgo_0:
br label %_llgo_3
_llgo_1: ; preds = %_llgo_3
%2 = urem i64 %8, 10
%2 = urem i64 %9, 10
%3 = add i64 %2, 48
%4 = trunc i64 %3 to i8
%5 = getelementptr inbounds i8, ptr %1, i64 %9
store i8 %4, ptr %5, align 1
%6 = icmp ult i64 %8, 10
br i1 %6, label %_llgo_2, label %_llgo_4
%5 = icmp slt i64 %10, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %5)
%6 = getelementptr inbounds i8, ptr %1, i64 %10
store i8 %4, ptr %6, align 1
%7 = icmp ult i64 %9, 10
br i1 %7, label %_llgo_2, label %_llgo_4
_llgo_2: ; preds = %_llgo_3, %_llgo_1
%7 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %1, i64 1, i64 100, i64 %9, i64 100, i64 100)
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
%8 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %1, i64 1, i64 100, i64 %10, i64 100, i64 100)
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %8)
ret void
_llgo_3: ; preds = %_llgo_4, %_llgo_0
%8 = phi i64 [ %0, %_llgo_0 ], [ %11, %_llgo_4 ]
%9 = phi i64 [ 99, %_llgo_0 ], [ %12, %_llgo_4 ]
%10 = icmp sgt i64 %9, 0
br i1 %10, label %_llgo_1, label %_llgo_2
%9 = phi i64 [ %0, %_llgo_0 ], [ %12, %_llgo_4 ]
%10 = phi i64 [ 99, %_llgo_0 ], [ %13, %_llgo_4 ]
%11 = icmp sgt i64 %10, 0
br i1 %11, label %_llgo_1, label %_llgo_2
_llgo_4: ; preds = %_llgo_1
%11 = udiv i64 %8, 10
%12 = sub i64 %9, 1
%12 = udiv i64 %9, 10
%13 = sub i64 %10, 1
br label %_llgo_3
}
@@ -587,8 +795,6 @@ _llgo_0:
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
declare i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare i32 @printf(ptr, ...)
declare void @"github.com/goplus/llgo/internal/runtime.init"()
@@ -599,12 +805,12 @@ declare ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64)
declare %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr, i64)
declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr, i64, i64, i64, i64, i64)
declare %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String")
declare ptr @"github.com/goplus/llgo/internal/runtime.StringData"(%"github.com/goplus/llgo/internal/runtime.String")
declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr, i64, i64, i64, i64, i64)
declare { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface", ptr)
declare { float, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Float32"(%"github.com/goplus/llgo/internal/runtime.iface", ptr)
declare { %"github.com/goplus/llgo/internal/runtime.String", i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2String"(%"github.com/goplus/llgo/internal/runtime.iface", ptr)
declare { double, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Float64"(%"github.com/goplus/llgo/internal/runtime.iface", ptr)
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)

View File

@@ -1,7 +1,7 @@
; ModuleID = 'main'
source_filename = "main"
@main.hello = global ptr null
@main.hello = global [7 x i8] undef
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@@ -26,14 +26,14 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
call void (ptr, ...) @printf(ptr @main.hello)
ret void
ret i32 0
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -1,7 +1,7 @@
; ModuleID = 'main'
source_filename = "main"
@main.format = global ptr null
@main.format = global [10 x i8] undef
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@@ -29,14 +29,14 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
call void (ptr, ...) @printf(ptr @main.format, i64 100)
ret void
ret i32 0
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -1,7 +1,7 @@
; ModuleID = 'main'
source_filename = "main"
@main.format = global ptr null
@main.format = global [10 x i8] undef
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@@ -35,14 +35,14 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
call void @"(*main.T).Print"(ptr @main.format, i64 100)
ret void
ret i32 0
}
declare void @printf(ptr, ...)

View File

@@ -25,7 +25,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -33,7 +33,7 @@ _llgo_0:
call void @main.init()
%2 = call i32 @main.f(i32 100)
%3 = call i32 (ptr, ...) @printf(ptr @0, i32 %2)
ret void
ret i32 0
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -20,7 +20,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -33,7 +33,7 @@ _llgo_1: ; preds = %_llgo_0
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
ret i32 0
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()

23
cl/_testdata/utf8/in.go Normal file
View File

@@ -0,0 +1,23 @@
package main
import (
"unicode/utf8"
)
func main() {
var str = "中abcd"
for i := 0; i < len(str); {
r, n := utf8.DecodeRuneInString(str[i:])
i += n
println(r)
}
println(index(2) == 3)
}
var array = [...]uint8{
1, 2, 3, 4, 5, 6, 7, 8,
}
func index(n int8) uint8 {
return array[n]
}

101
cl/_testdata/utf8/out.ll Normal file
View File

@@ -0,0 +1,101 @@
; ModuleID = 'main'
source_filename = "main"
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
@main.array = global [8 x i8] undef
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@0 = private unnamed_addr constant [8 x i8] c"\E4\B8\ADabcd\00", align 1
@1 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@2 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@3 = private unnamed_addr constant [8 x i8] c"\E4\B8\ADabcd\00", align 1
define i8 @main.index(i8 %0) {
_llgo_0:
%1 = icmp slt i8 %0, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %1)
%2 = zext i8 %0 to i64
%3 = getelementptr inbounds i8, ptr @main.array, i64 %2
%4 = load i8, ptr %3, align 1
ret i8 %4
}
define void @main.init() {
_llgo_0:
%0 = load i1, ptr @"main.init$guard", align 1
br i1 %0, label %_llgo_2, label %_llgo_1
_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"main.init$guard", align 1
call void @"unicode/utf8.init"()
store i8 1, ptr @main.array, align 1
store i8 2, ptr getelementptr inbounds (i8, ptr @main.array, i64 1), align 1
store i8 3, ptr getelementptr inbounds (i8, ptr @main.array, i64 2), align 1
store i8 4, ptr getelementptr inbounds (i8, ptr @main.array, i64 3), align 1
store i8 5, ptr getelementptr inbounds (i8, ptr @main.array, i64 4), align 1
store i8 6, ptr getelementptr inbounds (i8, ptr @main.array, i64 5), align 1
store i8 7, ptr getelementptr inbounds (i8, ptr @main.array, i64 6), align 1
store i8 8, ptr getelementptr inbounds (i8, ptr @main.array, i64 7), align 1
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
br label %_llgo_3
_llgo_1: ; preds = %_llgo_3
%2 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @0, i64 7)
%3 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %2, 1
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %2, i64 %14, i64 %3)
%5 = call { i32, i64 } @"unicode/utf8.DecodeRuneInString"(%"github.com/goplus/llgo/internal/runtime.String" %4)
%6 = extractvalue { i32, i64 } %5, 0
%7 = extractvalue { i32, i64 } %5, 1
%8 = add i64 %14, %7
%9 = sext i32 %6 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %9)
%10 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @1, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %10)
br label %_llgo_3
_llgo_2: ; preds = %_llgo_3
%11 = call i8 @main.index(i8 2)
%12 = icmp eq i8 %11, 3
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %12)
%13 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @2, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %13)
ret i32 0
_llgo_3: ; preds = %_llgo_1, %_llgo_0
%14 = phi i64 [ 0, %_llgo_0 ], [ %8, %_llgo_1 ]
%15 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @3, i64 7)
%16 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %15, 1
%17 = icmp slt i64 %14, %16
br i1 %17, label %_llgo_1, label %_llgo_2
}
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
declare void @"unicode/utf8.init"()
declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr, i64)
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String", i64, i64)
declare { i32, i64 } @"unicode/utf8.DecodeRuneInString"(%"github.com/goplus/llgo/internal/runtime.String")
declare void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64)
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
declare void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1)

View File

@@ -22,7 +22,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -43,12 +43,12 @@ _llgo_0:
store %"github.com/goplus/llgo/internal/runtime.iface" %11, ptr %9, align 8
%12 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %2, i64 16, i64 3, i64 0, i64 3, i64 3)
call void @main.test(%"github.com/goplus/llgo/internal/runtime.Slice" %12)
ret void
ret i32 0
}
define void @main.test(%"github.com/goplus/llgo/internal/runtime.Slice" %0) {
_llgo_0:
%1 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %0)
%1 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
br label %_llgo_1
_llgo_1: ; preds = %_llgo_2, %_llgo_0
@@ -58,12 +58,14 @@ _llgo_1: ; preds = %_llgo_2, %_llgo_0
br i1 %4, label %_llgo_2, label %_llgo_3
_llgo_2: ; preds = %_llgo_1
%5 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %0)
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %5, i64 %3
%7 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %6, align 8
%8 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
%9 = call i64 @"github.com/goplus/llgo/internal/runtime.I2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %7, ptr %8)
%10 = call i32 (ptr, ...) @printf(ptr @0, i64 %9)
%5 = icmp slt i64 %3, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %5)
%6 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %6, i64 %3
%8 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %7, align 8
%9 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
%10 = call i64 @"github.com/goplus/llgo/internal/runtime.I2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %8, ptr %9)
%11 = call i32 (ptr, ...) @printf(ptr @0, i64 %10)
br label %_llgo_1
_llgo_3: ; preds = %_llgo_1
@@ -80,9 +82,7 @@ declare %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llg
declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr, i64, i64, i64, i64, i64)
declare i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
declare i64 @"github.com/goplus/llgo/internal/runtime.I2Int"(%"github.com/goplus/llgo/internal/runtime.iface", ptr)

View File

@@ -20,7 +20,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -30,7 +30,7 @@ _llgo_0:
%3 = add i64 %2, 1
store i64 %3, ptr @main.a, align 4
%4 = load i64, ptr @main.a, align 4
ret void
ret i32 0
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -19,7 +19,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -36,7 +36,7 @@ _llgo_1: ; preds = %_llgo_3
br label %_llgo_3
_llgo_2: ; preds = %_llgo_3
ret void
ret i32 0
_llgo_3: ; preds = %_llgo_1, %_llgo_0
%7 = phi i32 [ 0, %_llgo_0 ], [ %6, %_llgo_1 ]

View File

@@ -2,7 +2,7 @@ package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/x/sqlite"
"github.com/goplus/llgo/c/sqlite"
)
func main() {

View File

@@ -13,7 +13,7 @@ _llgo_0:
br i1 %1, label %_llgo_1, label %_llgo_2
_llgo_1: ; preds = %_llgo_0
%2 = call ptr @sqlite3_errstr()
%2 = call ptr @sqlite3_errstr(i32 %0)
%3 = call i32 (ptr, ...) @printf(ptr @0, i32 %0, ptr %2)
call void @exit(i32 1)
br label %_llgo_2
@@ -35,21 +35,21 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
%2 = call { ptr, i32 } @"github.com/goplus/llgo/x/sqlite.OpenV2"(ptr @1, i32 130, ptr null)
%2 = call { ptr, i32 } @"github.com/goplus/llgo/c/sqlite.OpenV2"(ptr @1, i32 130, ptr null)
%3 = extractvalue { ptr, i32 } %2, 0
%4 = extractvalue { ptr, i32 } %2, 1
call void @main.check(i32 %4)
%5 = call i32 @sqlite3_close()
ret void
%5 = call i32 @sqlite3_close(ptr %3)
ret i32 0
}
declare ptr @sqlite3_errstr()
declare ptr @sqlite3_errstr(i32)
declare i32 @printf(ptr, ...)
@@ -57,6 +57,6 @@ declare void @exit(i32)
declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare { ptr, i32 } @"github.com/goplus/llgo/x/sqlite.OpenV2"(ptr, i32, ptr)
declare { ptr, i32 } @"github.com/goplus/llgo/c/sqlite.OpenV2"(ptr, i32, ptr)
declare i32 @sqlite3_close()
declare i32 @sqlite3_close(ptr)

15
cl/_testpy/callpy/in.go Normal file
View File

@@ -0,0 +1,15 @@
package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/py"
"github.com/goplus/llgo/py/math"
"github.com/goplus/llgo/py/os"
)
func main() {
x := math.Sqrt(py.Float(2))
wd := os.Getcwd()
c.Printf(c.Str("sqrt(2) = %f\n"), x.Float64())
c.Printf(c.Str("cwd = %s\n"), wd.CStr())
}

74
cl/_testpy/callpy/out.ll Normal file
View File

@@ -0,0 +1,74 @@
; ModuleID = 'main'
source_filename = "main"
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@__llgo_py.math.sqrt = linkonce global ptr null
@__llgo_py.os.getcwd = linkonce global ptr null
@0 = private unnamed_addr constant [14 x i8] c"sqrt(2) = %f\0A\00", align 1
@1 = private unnamed_addr constant [10 x i8] c"cwd = %s\0A\00", align 1
@__llgo_py.math = external global ptr
@2 = private unnamed_addr constant [5 x i8] c"sqrt\00", align 1
@__llgo_py.os = external global ptr
@3 = private unnamed_addr constant [7 x i8] c"getcwd\00", align 1
define void @main.init() {
_llgo_0:
%0 = load i1, ptr @"main.init$guard", align 1
br i1 %0, label %_llgo_2, label %_llgo_1
_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"main.init$guard", align 1
call void @"github.com/goplus/llgo/py/math.init"()
call void @"github.com/goplus/llgo/py/os.init"()
%1 = load ptr, ptr @__llgo_py.math, align 8
call void (ptr, ...) @llgoLoadPyModSyms(ptr %1, ptr @2, ptr @__llgo_py.math.sqrt, ptr null)
%2 = load ptr, ptr @__llgo_py.os, align 8
call void (ptr, ...) @llgoLoadPyModSyms(ptr %2, ptr @3, ptr @__llgo_py.os.getcwd, ptr null)
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
call void @Py_Initialize()
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
%2 = call ptr @PyFloat_FromDouble(double 2.000000e+00)
%3 = load ptr, ptr @__llgo_py.math.sqrt, align 8
%4 = call ptr @PyObject_CallOneArg(ptr %3, ptr %2)
%5 = load ptr, ptr @__llgo_py.os.getcwd, align 8
%6 = call ptr @PyObject_CallNoArgs(ptr %5)
%7 = call double @PyFloat_AsDouble(ptr %4)
%8 = call i32 (ptr, ...) @printf(ptr @0, double %7)
%9 = call ptr @PyUnicode_AsUTF8(ptr %6)
%10 = call i32 (ptr, ...) @printf(ptr @1, ptr %9)
ret i32 0
}
declare void @"github.com/goplus/llgo/py/math.init"()
declare void @"github.com/goplus/llgo/py/os.init"()
declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare ptr @PyFloat_FromDouble(double)
declare ptr @PyObject_CallOneArg(ptr, ptr)
declare ptr @PyObject_CallNoArgs(ptr)
declare double @PyFloat_AsDouble(ptr)
declare i32 @printf(ptr, ...)
declare ptr @PyUnicode_AsUTF8(ptr)
declare void @llgoLoadPyModSyms(ptr, ...)
declare void @Py_Initialize()

12
cl/_testpy/gcd/in.go Normal file
View File

@@ -0,0 +1,12 @@
package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/py"
"github.com/goplus/llgo/py/math"
)
func main() {
x := math.Gcd(py.Long(60), py.Long(20), py.Long(25))
c.Printf(c.Str("gcd(60, 20, 25) = %d\n"), x.Long())
}

59
cl/_testpy/gcd/out.ll Normal file
View File

@@ -0,0 +1,59 @@
; ModuleID = 'main'
source_filename = "main"
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@__llgo_py.math.gcd = linkonce global ptr null
@0 = private unnamed_addr constant [22 x i8] c"gcd(60, 20, 25) = %d\0A\00", align 1
@__llgo_py.math = external global ptr
@1 = private unnamed_addr constant [4 x i8] c"gcd\00", align 1
define void @main.init() {
_llgo_0:
%0 = load i1, ptr @"main.init$guard", align 1
br i1 %0, label %_llgo_2, label %_llgo_1
_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"main.init$guard", align 1
call void @"github.com/goplus/llgo/py/math.init"()
%1 = load ptr, ptr @__llgo_py.math, align 8
call void (ptr, ...) @llgoLoadPyModSyms(ptr %1, ptr @1, ptr @__llgo_py.math.gcd, ptr null)
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
call void @Py_Initialize()
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
%2 = call ptr @PyLong_FromLong(i32 60)
%3 = call ptr @PyLong_FromLong(i32 20)
%4 = call ptr @PyLong_FromLong(i32 25)
%5 = load ptr, ptr @__llgo_py.math.gcd, align 8
%6 = call ptr (ptr, ...) @PyObject_CallFunctionObjArgs(ptr %5, ptr %2, ptr %3, ptr %4, ptr null)
%7 = call i32 @PyLong_AsLong(ptr %6)
%8 = call i32 (ptr, ...) @printf(ptr @0, i32 %7)
ret i32 0
}
declare void @"github.com/goplus/llgo/py/math.init"()
declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare ptr @PyLong_FromLong(i32)
declare ptr @PyObject_CallFunctionObjArgs(ptr, ...)
declare i32 @PyLong_AsLong(ptr)
declare i32 @printf(ptr, ...)
declare void @llgoLoadPyModSyms(ptr, ...)
declare void @Py_Initialize()

14
cl/_testpy/math/in.go Normal file
View File

@@ -0,0 +1,14 @@
package math
import (
_ "unsafe"
"github.com/goplus/llgo/py"
)
const (
LLGoPackage = "py.math"
)
//go:linkname Sqrt py.sqrt
func Sqrt(x *py.Object) *py.Object

28
cl/_testpy/math/out.ll Normal file
View File

@@ -0,0 +1,28 @@
; ModuleID = 'math'
source_filename = "math"
@"math.init$guard" = global ptr null
@__llgo_py.math = linkonce global ptr null
@0 = private unnamed_addr constant [5 x i8] c"math\00", align 1
define void @math.init() {
_llgo_0:
%0 = load i1, ptr @"math.init$guard", align 1
br i1 %0, label %_llgo_2, label %_llgo_1
_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"math.init$guard", align 1
%1 = load ptr, ptr @__llgo_py.math, align 8
%2 = icmp ne ptr %1, null
br i1 %2, label %_llgo_2, label %_llgo_3
_llgo_2: ; preds = %_llgo_3, %_llgo_1, %_llgo_0
ret void
_llgo_3: ; preds = %_llgo_1
%3 = call ptr @PyImport_ImportModule(ptr @0)
store ptr %3, ptr @__llgo_py.math, align 8
br label %_llgo_2
}
declare ptr @PyImport_ImportModule(ptr)

24
cl/_testpy/matrix/in.go Normal file
View File

@@ -0,0 +1,24 @@
package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/py"
"github.com/goplus/llgo/py/numpy"
)
func main() {
a := py.List(
py.List(1.0, 2.0, 3.0),
py.List(4.0, 5.0, 6.0),
py.List(7.0, 8.0, 9.0),
)
b := py.List(
py.List(9.0, 8.0, 7.0),
py.List(6.0, 5.0, 4.0),
py.List(3.0, 2.0, 1.0),
)
x := numpy.Add(a, b)
c.Printf(c.Str("a = %s\n"), a.Str().CStr())
c.Printf(c.Str("a = %s\n"), b.Str().CStr())
c.Printf(c.Str("a+b = %s\n"), x.Str().CStr())
}

121
cl/_testpy/matrix/out.ll Normal file
View File

@@ -0,0 +1,121 @@
; ModuleID = 'main'
source_filename = "main"
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@__llgo_py.numpy.add = linkonce global ptr null
@0 = private unnamed_addr constant [8 x i8] c"a = %s\0A\00", align 1
@1 = private unnamed_addr constant [8 x i8] c"a = %s\0A\00", align 1
@2 = private unnamed_addr constant [10 x i8] c"a+b = %s\0A\00", align 1
@__llgo_py.numpy = external global ptr
@3 = private unnamed_addr constant [4 x i8] c"add\00", align 1
define void @main.init() {
_llgo_0:
%0 = load i1, ptr @"main.init$guard", align 1
br i1 %0, label %_llgo_2, label %_llgo_1
_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"main.init$guard", align 1
call void @"github.com/goplus/llgo/py/numpy.init"()
%1 = load ptr, ptr @__llgo_py.numpy, align 8
call void (ptr, ...) @llgoLoadPyModSyms(ptr %1, ptr @3, ptr @__llgo_py.numpy.add, ptr null)
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
call void @Py_Initialize()
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
%2 = call ptr @PyList_New(i64 3)
%3 = call ptr @PyFloat_FromDouble(double 1.000000e+00)
%4 = call i32 @PyList_SetItem(ptr %2, i64 0, ptr %3)
%5 = call ptr @PyFloat_FromDouble(double 2.000000e+00)
%6 = call i32 @PyList_SetItem(ptr %2, i64 1, ptr %5)
%7 = call ptr @PyFloat_FromDouble(double 3.000000e+00)
%8 = call i32 @PyList_SetItem(ptr %2, i64 2, ptr %7)
%9 = call ptr @PyList_New(i64 3)
%10 = call ptr @PyFloat_FromDouble(double 4.000000e+00)
%11 = call i32 @PyList_SetItem(ptr %9, i64 0, ptr %10)
%12 = call ptr @PyFloat_FromDouble(double 5.000000e+00)
%13 = call i32 @PyList_SetItem(ptr %9, i64 1, ptr %12)
%14 = call ptr @PyFloat_FromDouble(double 6.000000e+00)
%15 = call i32 @PyList_SetItem(ptr %9, i64 2, ptr %14)
%16 = call ptr @PyList_New(i64 3)
%17 = call ptr @PyFloat_FromDouble(double 7.000000e+00)
%18 = call i32 @PyList_SetItem(ptr %16, i64 0, ptr %17)
%19 = call ptr @PyFloat_FromDouble(double 8.000000e+00)
%20 = call i32 @PyList_SetItem(ptr %16, i64 1, ptr %19)
%21 = call ptr @PyFloat_FromDouble(double 9.000000e+00)
%22 = call i32 @PyList_SetItem(ptr %16, i64 2, ptr %21)
%23 = call ptr @PyList_New(i64 3)
%24 = call i32 @PyList_SetItem(ptr %23, i64 0, ptr %2)
%25 = call i32 @PyList_SetItem(ptr %23, i64 1, ptr %9)
%26 = call i32 @PyList_SetItem(ptr %23, i64 2, ptr %16)
%27 = call ptr @PyList_New(i64 3)
%28 = call ptr @PyFloat_FromDouble(double 9.000000e+00)
%29 = call i32 @PyList_SetItem(ptr %27, i64 0, ptr %28)
%30 = call ptr @PyFloat_FromDouble(double 8.000000e+00)
%31 = call i32 @PyList_SetItem(ptr %27, i64 1, ptr %30)
%32 = call ptr @PyFloat_FromDouble(double 7.000000e+00)
%33 = call i32 @PyList_SetItem(ptr %27, i64 2, ptr %32)
%34 = call ptr @PyList_New(i64 3)
%35 = call ptr @PyFloat_FromDouble(double 6.000000e+00)
%36 = call i32 @PyList_SetItem(ptr %34, i64 0, ptr %35)
%37 = call ptr @PyFloat_FromDouble(double 5.000000e+00)
%38 = call i32 @PyList_SetItem(ptr %34, i64 1, ptr %37)
%39 = call ptr @PyFloat_FromDouble(double 4.000000e+00)
%40 = call i32 @PyList_SetItem(ptr %34, i64 2, ptr %39)
%41 = call ptr @PyList_New(i64 3)
%42 = call ptr @PyFloat_FromDouble(double 3.000000e+00)
%43 = call i32 @PyList_SetItem(ptr %41, i64 0, ptr %42)
%44 = call ptr @PyFloat_FromDouble(double 2.000000e+00)
%45 = call i32 @PyList_SetItem(ptr %41, i64 1, ptr %44)
%46 = call ptr @PyFloat_FromDouble(double 1.000000e+00)
%47 = call i32 @PyList_SetItem(ptr %41, i64 2, ptr %46)
%48 = call ptr @PyList_New(i64 3)
%49 = call i32 @PyList_SetItem(ptr %48, i64 0, ptr %27)
%50 = call i32 @PyList_SetItem(ptr %48, i64 1, ptr %34)
%51 = call i32 @PyList_SetItem(ptr %48, i64 2, ptr %41)
%52 = load ptr, ptr @__llgo_py.numpy.add, align 8
%53 = call ptr (ptr, ...) @PyObject_CallFunctionObjArgs(ptr %52, ptr %23, ptr %48, ptr null)
%54 = call ptr @PyObject_Str(ptr %23)
%55 = call ptr @PyUnicode_AsUTF8(ptr %54)
%56 = call i32 (ptr, ...) @printf(ptr @0, ptr %55)
%57 = call ptr @PyObject_Str(ptr %48)
%58 = call ptr @PyUnicode_AsUTF8(ptr %57)
%59 = call i32 (ptr, ...) @printf(ptr @1, ptr %58)
%60 = call ptr @PyObject_Str(ptr %53)
%61 = call ptr @PyUnicode_AsUTF8(ptr %60)
%62 = call i32 (ptr, ...) @printf(ptr @2, ptr %61)
ret i32 0
}
declare void @"github.com/goplus/llgo/py/numpy.init"()
declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare ptr @PyList_New(i64)
declare ptr @PyFloat_FromDouble(double)
declare i32 @PyList_SetItem(ptr, i64, ptr)
declare ptr @PyObject_CallFunctionObjArgs(ptr, ...)
declare ptr @PyObject_Str(ptr)
declare ptr @PyUnicode_AsUTF8(ptr)
declare i32 @printf(ptr, ...)
declare void @llgoLoadPyModSyms(ptr, ...)
declare void @Py_Initialize()

10
cl/_testpy/pi/in.go Normal file
View File

@@ -0,0 +1,10 @@
package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/py/math"
)
func main() {
c.Printf(c.Str("pi = %f\n"), math.Pi.Float64())
}

49
cl/_testpy/pi/out.ll Normal file
View File

@@ -0,0 +1,49 @@
; ModuleID = 'main'
source_filename = "main"
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@0 = private unnamed_addr constant [9 x i8] c"pi = %f\0A\00", align 1
@__llgo_py.math = external global ptr
@1 = private unnamed_addr constant [3 x i8] c"pi\00", align 1
define void @main.init() {
_llgo_0:
%0 = load i1, ptr @"main.init$guard", align 1
br i1 %0, label %_llgo_2, label %_llgo_1
_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"main.init$guard", align 1
call void @"github.com/goplus/llgo/py/math.init"()
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
call void @Py_Initialize()
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
%2 = load ptr, ptr @__llgo_py.math, align 8
%3 = call ptr @PyObject_GetAttrString(ptr %2, ptr @1)
%4 = call double @PyFloat_AsDouble(ptr %3)
%5 = call i32 (ptr, ...) @printf(ptr @0, double %4)
ret i32 0
}
declare void @"github.com/goplus/llgo/py/math.init"()
declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare ptr @PyObject_GetAttrString(ptr, ptr)
declare double @PyFloat_AsDouble(ptr)
declare i32 @printf(ptr, ...)
declare void @Py_Initialize()

12
cl/_testpy/pow/in.go Normal file
View File

@@ -0,0 +1,12 @@
package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/py"
"github.com/goplus/llgo/py/math"
)
func main() {
x := math.Pow(py.Float(2), py.Float(3))
c.Printf(c.Str("pow(2, 3) = %f\n"), x.Float64())
}

58
cl/_testpy/pow/out.ll Normal file
View File

@@ -0,0 +1,58 @@
; ModuleID = 'main'
source_filename = "main"
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@__llgo_py.math.pow = linkonce global ptr null
@0 = private unnamed_addr constant [16 x i8] c"pow(2, 3) = %f\0A\00", align 1
@__llgo_py.math = external global ptr
@1 = private unnamed_addr constant [4 x i8] c"pow\00", align 1
define void @main.init() {
_llgo_0:
%0 = load i1, ptr @"main.init$guard", align 1
br i1 %0, label %_llgo_2, label %_llgo_1
_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"main.init$guard", align 1
call void @"github.com/goplus/llgo/py/math.init"()
%1 = load ptr, ptr @__llgo_py.math, align 8
call void (ptr, ...) @llgoLoadPyModSyms(ptr %1, ptr @1, ptr @__llgo_py.math.pow, ptr null)
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
call void @Py_Initialize()
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
%2 = call ptr @PyFloat_FromDouble(double 2.000000e+00)
%3 = call ptr @PyFloat_FromDouble(double 3.000000e+00)
%4 = load ptr, ptr @__llgo_py.math.pow, align 8
%5 = call ptr (ptr, ...) @PyObject_CallFunctionObjArgs(ptr %4, ptr %2, ptr %3, ptr null)
%6 = call double @PyFloat_AsDouble(ptr %5)
%7 = call i32 (ptr, ...) @printf(ptr @0, double %6)
ret i32 0
}
declare void @"github.com/goplus/llgo/py/math.init"()
declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare ptr @PyFloat_FromDouble(double)
declare ptr @PyObject_CallFunctionObjArgs(ptr, ...)
declare double @PyFloat_AsDouble(ptr)
declare i32 @printf(ptr, ...)
declare void @llgoLoadPyModSyms(ptr, ...)
declare void @Py_Initialize()

View File

@@ -20,7 +20,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -29,7 +29,7 @@ _llgo_0:
%2 = alloca i8, i64 4, align 1
%3 = call ptr @memcpy(ptr %2, ptr @0, i64 4)
%4 = call i32 (ptr, ...) @printf(ptr @1, ptr %2)
ret void
ret i32 0
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -27,27 +27,25 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
%2 = call %"github.com/goplus/llgo/internal/runtime.String" @main.hello()
%3 = call i64 @"github.com/goplus/llgo/internal/runtime.StringLen"(%"github.com/goplus/llgo/internal/runtime.String" %2)
%3 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %2, 1
%4 = add i64 %3, 1
%5 = alloca i8, i64 %4, align 1
%6 = call ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr %5, %"github.com/goplus/llgo/internal/runtime.String" %2)
%7 = call i32 (ptr, ...) @printf(ptr %6)
ret void
ret i32 0
}
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr, i64)
declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare i64 @"github.com/goplus/llgo/internal/runtime.StringLen"(%"github.com/goplus/llgo/internal/runtime.String")
declare ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr, %"github.com/goplus/llgo/internal/runtime.String")
declare i32 @printf(ptr, ...)

View File

@@ -29,7 +29,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -39,7 +39,7 @@ _llgo_0:
%3 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %2, i64 100)
%4 = call i64 @main.incVal(%"github.com/goplus/llgo/internal/runtime.iface" %3)
%5 = call i32 (ptr, ...) @printf(ptr @0, i64 %4)
ret void
ret i32 0
}
declare i64 @"github.com/goplus/llgo/internal/runtime.I2Int"(%"github.com/goplus/llgo/internal/runtime.iface", ptr)

View File

@@ -1,7 +1,7 @@
package main
import (
"github.com/goplus/llgo/internal/runtime/c"
"unsafe"
)
var a int64 = 1<<63 - 1
@@ -11,41 +11,19 @@ var n uint64 = 1<<64 - 1
func main() {
var s = []int{1, 2, 3, 4}
var a = [...]int{1, 2, 3, 4}
d := make([]byte, 4, 10)
println(s, len(s), cap(s))
println(d, len(d), cap(d))
println(len(a), cap(a), cap(&a), len(&a))
println(len([]int{1, 2, 3, 4}), len([4]int{1, 2, 3, 4}))
println(len(s[1:]), cap(s[1:]), len(s[1:2]), cap(s[1:2]), len(s[1:2:2]), cap(s[1:2:2]))
println(len(a[1:]), cap(a[1:]), len(a[1:2]), cap(a[1:2]), len(a[1:2:2]), cap(a[1:2:2]))
out(len(s))
out(len([]int{1, 2, 3, 4}))
out(len(a))
out(len(&a))
out(len([4]int{1, 2, 3, 4}))
out(cap(s))
out(cap(a))
out(cap(&a))
out(len(s[1:]))
out(cap(s[1:]))
out(len(s[1:2]))
out(cap(s[1:2]))
out(len(s[1:2:2]))
out(cap(s[1:2:2]))
out(len(a[1:]))
out(cap(a[1:]))
out(len(a[1:2]))
out(cap(a[1:2]))
out(len(a[1:2:2]))
out(cap(a[1:2:2]))
string_len("hello")
string_len("hello"[1:])
string_len("hello"[1:2])
string_len("hello"[5:])
}
func string_len(s string) {
out(len(s))
}
func out(n int) {
c.Printf(c.Str("%d\n"), n)
println("hello", "hello"[1:], "hello"[1:2], len("hello"[5:]))
println(append(s, 5, 6, 7, 8))
data := []byte{'a', 'b', 'c'}
data = append(data, "def"...)
println(data)
var i any = 100
println(true, 100, -100, uint(255), int32(-100), 100.5, i, &i, uintptr(unsafe.Pointer(&i)))
}

View File

@@ -3,6 +3,7 @@ source_filename = "main"
%"github.com/goplus/llgo/internal/runtime.Slice" = type { ptr, i64, i64 }
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
%"github.com/goplus/llgo/internal/runtime.iface" = type { ptr, ptr }
@main.a = global ptr null
@main.b = global ptr null
@@ -10,11 +11,50 @@ source_filename = "main"
@main.n = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@0 = private unnamed_addr constant [6 x i8] c"hello\00", align 1
@1 = private unnamed_addr constant [6 x i8] c"hello\00", align 1
@2 = private unnamed_addr constant [6 x i8] c"hello\00", align 1
@3 = private unnamed_addr constant [6 x i8] c"hello\00", align 1
@4 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
@0 = private unnamed_addr constant [2 x i8] c" \00", align 1
@1 = private unnamed_addr constant [2 x i8] c" \00", align 1
@2 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@3 = private unnamed_addr constant [2 x i8] c" \00", align 1
@4 = private unnamed_addr constant [2 x i8] c" \00", align 1
@5 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@6 = private unnamed_addr constant [2 x i8] c" \00", align 1
@7 = private unnamed_addr constant [2 x i8] c" \00", align 1
@8 = private unnamed_addr constant [2 x i8] c" \00", align 1
@9 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@10 = private unnamed_addr constant [2 x i8] c" \00", align 1
@11 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@12 = private unnamed_addr constant [2 x i8] c" \00", align 1
@13 = private unnamed_addr constant [2 x i8] c" \00", align 1
@14 = private unnamed_addr constant [2 x i8] c" \00", align 1
@15 = private unnamed_addr constant [2 x i8] c" \00", align 1
@16 = private unnamed_addr constant [2 x i8] c" \00", align 1
@17 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@18 = private unnamed_addr constant [2 x i8] c" \00", align 1
@19 = private unnamed_addr constant [2 x i8] c" \00", align 1
@20 = private unnamed_addr constant [2 x i8] c" \00", align 1
@21 = private unnamed_addr constant [2 x i8] c" \00", align 1
@22 = private unnamed_addr constant [2 x i8] c" \00", align 1
@23 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@24 = private unnamed_addr constant [6 x i8] c"hello\00", align 1
@25 = private unnamed_addr constant [6 x i8] c"hello\00", align 1
@26 = private unnamed_addr constant [6 x i8] c"hello\00", align 1
@27 = private unnamed_addr constant [6 x i8] c"hello\00", align 1
@28 = private unnamed_addr constant [2 x i8] c" \00", align 1
@29 = private unnamed_addr constant [2 x i8] c" \00", align 1
@30 = private unnamed_addr constant [2 x i8] c" \00", align 1
@31 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@32 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@33 = private unnamed_addr constant [4 x i8] c"def\00", align 1
@34 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@35 = private unnamed_addr constant [2 x i8] c" \00", align 1
@36 = private unnamed_addr constant [2 x i8] c" \00", align 1
@37 = private unnamed_addr constant [2 x i8] c" \00", align 1
@38 = private unnamed_addr constant [2 x i8] c" \00", align 1
@39 = private unnamed_addr constant [2 x i8] c" \00", align 1
@40 = private unnamed_addr constant [2 x i8] c" \00", align 1
@41 = private unnamed_addr constant [2 x i8] c" \00", align 1
@42 = private unnamed_addr constant [2 x i8] c" \00", align 1
@43 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
define void @main.init() {
_llgo_0:
@@ -32,7 +72,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -57,104 +97,220 @@ _llgo_0:
store i64 2, ptr %10, align 4
store i64 3, ptr %11, align 4
store i64 4, ptr %12, align 4
%13 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
call void @main.out(i64 %13)
%14 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
%15 = getelementptr inbounds i64, ptr %14, i64 0
store i64 1, ptr %15, align 4
%16 = getelementptr inbounds i64, ptr %14, i64 1
store i64 2, ptr %16, align 4
%17 = getelementptr inbounds i64, ptr %14, i64 2
store i64 3, ptr %17, align 4
%18 = getelementptr inbounds i64, ptr %14, i64 3
store i64 4, ptr %18, align 4
%19 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %14, i64 8, i64 4, i64 0, i64 4, i64 4)
%20 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %19)
call void @main.out(i64 %20)
call void @main.out(i64 4)
call void @main.out(i64 4)
call void @main.out(i64 4)
%21 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
call void @main.out(i64 %21)
call void @main.out(i64 4)
call void @main.out(i64 4)
%22 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
%23 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
%24 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
%25 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %24, i64 8, i64 %22, i64 1, i64 %23, i64 %22)
%26 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %25)
call void @main.out(i64 %26)
%27 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
%28 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
%29 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
%30 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %29, i64 8, i64 %27, i64 1, i64 %28, i64 %27)
%31 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %30)
call void @main.out(i64 %31)
%32 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
%33 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
%34 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %33, i64 8, i64 %32, i64 1, i64 2, i64 %32)
%35 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %34)
call void @main.out(i64 %35)
%36 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
%37 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
%38 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %37, i64 8, i64 %36, i64 1, i64 2, i64 %36)
%39 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %38)
call void @main.out(i64 %39)
%40 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
%41 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
%42 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %41, i64 8, i64 %40, i64 1, i64 2, i64 2)
%43 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %42)
call void @main.out(i64 %43)
%44 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
%45 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
%46 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %45, i64 8, i64 %44, i64 1, i64 2, i64 2)
%47 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %46)
call void @main.out(i64 %47)
%48 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 4, i64 4)
%49 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %48)
call void @main.out(i64 %49)
%50 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 4, i64 4)
%51 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %50)
call void @main.out(i64 %51)
%52 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 2, i64 4)
%53 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %52)
call void @main.out(i64 %53)
%54 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 2, i64 4)
%55 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %54)
call void @main.out(i64 %55)
%56 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 2, i64 2)
%57 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %56)
call void @main.out(i64 %57)
%58 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 2, i64 2)
%59 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %58)
call void @main.out(i64 %59)
%60 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @0, i64 5)
call void @main.string_len(%"github.com/goplus/llgo/internal/runtime.String" %60)
%61 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @1, i64 5)
%62 = call i64 @"github.com/goplus/llgo/internal/runtime.StringLen"(%"github.com/goplus/llgo/internal/runtime.String" %61)
%63 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %61, i64 1, i64 %62)
call void @main.string_len(%"github.com/goplus/llgo/internal/runtime.String" %63)
%64 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @2, i64 5)
%65 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %64, i64 1, i64 2)
call void @main.string_len(%"github.com/goplus/llgo/internal/runtime.String" %65)
%66 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @3, i64 5)
%67 = call i64 @"github.com/goplus/llgo/internal/runtime.StringLen"(%"github.com/goplus/llgo/internal/runtime.String" %66)
%68 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %66, i64 5, i64 %67)
call void @main.string_len(%"github.com/goplus/llgo/internal/runtime.String" %68)
ret void
}
define void @main.out(i64 %0) {
_llgo_0:
%1 = call i32 (ptr, ...) @printf(ptr @4, i64 %0)
ret void
}
define void @main.string_len(%"github.com/goplus/llgo/internal/runtime.String" %0) {
_llgo_0:
%1 = call i64 @"github.com/goplus/llgo/internal/runtime.StringLen"(%"github.com/goplus/llgo/internal/runtime.String" %0)
call void @main.out(i64 %1)
ret void
%13 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 10)
%14 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %13, i64 1, i64 10, i64 0, i64 4, i64 10)
%15 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 1
%16 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
call void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
%17 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @0, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %17)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %15)
%18 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @1, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %18)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %16)
%19 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @2, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %19)
%20 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %14, 1
%21 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %14, 2
call void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice" %14)
%22 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @3, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %22)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %20)
%23 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @4, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %23)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %21)
%24 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @5, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %24)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 4)
%25 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @6, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %25)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 4)
%26 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @7, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %26)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 4)
%27 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @8, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %27)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 4)
%28 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @9, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %28)
%29 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
%30 = getelementptr inbounds i64, ptr %29, i64 0
store i64 1, ptr %30, align 4
%31 = getelementptr inbounds i64, ptr %29, i64 1
store i64 2, ptr %31, align 4
%32 = getelementptr inbounds i64, ptr %29, i64 2
store i64 3, ptr %32, align 4
%33 = getelementptr inbounds i64, ptr %29, i64 3
store i64 4, ptr %33, align 4
%34 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %29, i64 8, i64 4, i64 0, i64 4, i64 4)
%35 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %34, 1
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %35)
%36 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @10, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %36)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 4)
%37 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @11, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %37)
%38 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
%39 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
%40 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0
%41 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %40, i64 8, i64 %38, i64 1, i64 %39, i64 %38)
%42 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %41, 1
%43 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
%44 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
%45 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0
%46 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %45, i64 8, i64 %43, i64 1, i64 %44, i64 %43)
%47 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %46, 2
%48 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
%49 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0
%50 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %49, i64 8, i64 %48, i64 1, i64 2, i64 %48)
%51 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %50, 1
%52 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
%53 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0
%54 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %53, i64 8, i64 %52, i64 1, i64 2, i64 %52)
%55 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %54, 2
%56 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
%57 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0
%58 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %57, i64 8, i64 %56, i64 1, i64 2, i64 2)
%59 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %58, 1
%60 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
%61 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0
%62 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %61, i64 8, i64 %60, i64 1, i64 2, i64 2)
%63 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %62, 2
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %42)
%64 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @12, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %64)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %47)
%65 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @13, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %65)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %51)
%66 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @14, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %66)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %55)
%67 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @15, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %67)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %59)
%68 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @16, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %68)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %63)
%69 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @17, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %69)
%70 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 4, i64 4)
%71 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %70, 1
%72 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 4, i64 4)
%73 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %72, 2
%74 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 2, i64 4)
%75 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %74, 1
%76 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 2, i64 4)
%77 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %76, 2
%78 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 2, i64 2)
%79 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %78, 1
%80 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 2, i64 2)
%81 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %80, 2
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %71)
%82 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @18, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %82)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %73)
%83 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @19, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %83)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %75)
%84 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @20, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %84)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %77)
%85 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @21, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %85)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %79)
%86 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @22, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %86)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %81)
%87 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @23, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %87)
%88 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @24, i64 5)
%89 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %88, 1
%90 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %88, i64 1, i64 %89)
%91 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @25, i64 5)
%92 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %91, i64 1, i64 2)
%93 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @26, i64 5)
%94 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %93, 1
%95 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %93, i64 5, i64 %94)
%96 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %95, 1
%97 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @27, i64 5)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %97)
%98 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @28, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %98)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %90)
%99 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @29, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %99)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %92)
%100 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @30, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %100)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %96)
%101 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @31, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %101)
%102 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
%103 = getelementptr inbounds i64, ptr %102, i64 0
store i64 5, ptr %103, align 4
%104 = getelementptr inbounds i64, ptr %102, i64 1
store i64 6, ptr %104, align 4
%105 = getelementptr inbounds i64, ptr %102, i64 2
store i64 7, ptr %105, align 4
%106 = getelementptr inbounds i64, ptr %102, i64 3
store i64 8, ptr %106, align 4
%107 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %102, i64 8, i64 4, i64 0, i64 4, i64 4)
%108 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %107, 0
%109 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %107, 1
%110 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.SliceAppend"(%"github.com/goplus/llgo/internal/runtime.Slice" %7, ptr %108, i64 %109, i64 8)
call void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice" %110)
%111 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @32, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %111)
%112 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 3)
%113 = getelementptr inbounds i8, ptr %112, i64 0
store i8 97, ptr %113, align 1
%114 = getelementptr inbounds i8, ptr %112, i64 1
store i8 98, ptr %114, align 1
%115 = getelementptr inbounds i8, ptr %112, i64 2
store i8 99, ptr %115, align 1
%116 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %112, i64 1, i64 3, i64 0, i64 3, i64 3)
%117 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @33, i64 3)
%118 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %117, 0
%119 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %117, 1
%120 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.SliceAppend"(%"github.com/goplus/llgo/internal/runtime.Slice" %116, ptr %118, i64 %119, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice" %120)
%121 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @34, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %121)
%122 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 16)
%123 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
%124 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %123, i64 100)
store %"github.com/goplus/llgo/internal/runtime.iface" %124, ptr %122, align 8
%125 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %122, align 8
%126 = ptrtoint ptr %122 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 true)
%127 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @35, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %127)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 100)
%128 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @36, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %128)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 -100)
%129 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @37, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %129)
call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 255)
%130 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @38, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %130)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 -100)
%131 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @39, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %131)
call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double 1.005000e+02)
%132 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @40, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %132)
call void @"github.com/goplus/llgo/internal/runtime.PrintIface"(%"github.com/goplus/llgo/internal/runtime.iface" %125)
%133 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @41, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %133)
call void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr %122)
%134 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @42, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %134)
call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %126)
%135 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @43, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %135)
ret i32 0
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()
@@ -163,16 +319,28 @@ declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr, i64, i64, i64, i64, i64)
declare i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr, i64)
declare i64 @"github.com/goplus/llgo/internal/runtime.StringLen"(%"github.com/goplus/llgo/internal/runtime.String")
declare void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64)
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String", i64, i64)
declare i32 @printf(ptr, ...)
declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.SliceAppend"(%"github.com/goplus/llgo/internal/runtime.Slice", ptr, i64, i64)
declare ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64)
declare %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr, i64)
declare void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1)
declare void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64)
declare void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double)
declare void @"github.com/goplus/llgo/internal/runtime.PrintIface"(%"github.com/goplus/llgo/internal/runtime.iface")
declare void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr)

View File

@@ -28,7 +28,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -48,7 +48,7 @@ _llgo_0:
store ptr null, ptr %8, align 8
%9 = load { ptr, ptr }, ptr %6, align 8
call void @main.callback(ptr @1, { ptr, ptr } %9)
ret void
ret i32 0
}
define void @main.print(ptr %0) {

View File

@@ -199,7 +199,7 @@ _llgo_2: ; preds = %_llgo_0
define void @main.cvtUinptr(i32 %0, i64 %1) {
_llgo_0:
%2 = sext i32 %0 to i64
%2 = zext i32 %0 to i64
%3 = icmp ne i64 %2, %1
br i1 %3, label %_llgo_1, label %_llgo_2
@@ -237,7 +237,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -298,7 +298,7 @@ _llgo_0:
call void @main.cvt32to64(i32 0, i64 0)
call void @main.cvt32to64(i32 2147483647, i64 2147483647)
call void @main.cvtUinptr(i32 1024, i64 1024)
ret void
ret i32 0
}
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr, i64)

View File

@@ -20,7 +20,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -47,7 +47,7 @@ _llgo_0:
%13 = extractvalue { ptr, ptr } %12, 1
%14 = extractvalue { ptr, ptr } %12, 0
call void %14(ptr %13)
ret void
ret i32 0
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -11,6 +11,10 @@ func concat(args ...string) (ret string) {
return
}
func info(s string) string {
return "" + s + "..."
}
func main() {
result := concat("Hello", " ", "World")
c.Fprintf(c.Stderr, c.Str("Hi, %s\n"), c.AllocaCStr(result))

View File

@@ -6,25 +6,27 @@ source_filename = "main"
@"main.init$guard" = global ptr null
@0 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1
@1 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1
@2 = private unnamed_addr constant [4 x i8] c"...\00", align 1
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@1 = private unnamed_addr constant [6 x i8] c"Hello\00", align 1
@2 = private unnamed_addr constant [2 x i8] c" \00", align 1
@3 = private unnamed_addr constant [6 x i8] c"World\00", align 1
@3 = private unnamed_addr constant [6 x i8] c"Hello\00", align 1
@4 = private unnamed_addr constant [2 x i8] c" \00", align 1
@5 = private unnamed_addr constant [6 x i8] c"World\00", align 1
@__stderrp = external global ptr
@4 = private unnamed_addr constant [8 x i8] c"Hi, %s\0A\00", align 1
@6 = private unnamed_addr constant [8 x i8] c"Hi, %s\0A\00", align 1
define %"github.com/goplus/llgo/internal/runtime.String" @main.concat(%"github.com/goplus/llgo/internal/runtime.Slice" %0) {
_llgo_0:
%1 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %0)
%1 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
%2 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @0, i64 0)
%3 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %2, 0
%4 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %2, 1
br label %_llgo_1
_llgo_1: ; preds = %_llgo_2, %_llgo_0
%5 = phi ptr [ %3, %_llgo_0 ], [ %18, %_llgo_2 ]
%6 = phi i64 [ %4, %_llgo_0 ], [ %19, %_llgo_2 ]
%5 = phi ptr [ %3, %_llgo_0 ], [ %19, %_llgo_2 ]
%6 = phi i64 [ %4, %_llgo_0 ], [ %20, %_llgo_2 ]
%7 = phi i64 [ -1, %_llgo_0 ], [ %12, %_llgo_2 ]
%8 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %8, i32 0, i32 0
@@ -37,18 +39,29 @@ _llgo_1: ; preds = %_llgo_2, %_llgo_0
br i1 %13, label %_llgo_2, label %_llgo_3
_llgo_2: ; preds = %_llgo_1
%14 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %0)
%15 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %14, i64 %12
%16 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %15, align 8
%17 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringCat"(%"github.com/goplus/llgo/internal/runtime.String" %11, %"github.com/goplus/llgo/internal/runtime.String" %16)
%18 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %17, 0
%19 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %17, 1
%14 = icmp slt i64 %12, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %14)
%15 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
%16 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %15, i64 %12
%17 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %16, align 8
%18 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringCat"(%"github.com/goplus/llgo/internal/runtime.String" %11, %"github.com/goplus/llgo/internal/runtime.String" %17)
%19 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %18, 0
%20 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %18, 1
br label %_llgo_1
_llgo_3: ; preds = %_llgo_1
ret %"github.com/goplus/llgo/internal/runtime.String" %11
}
define %"github.com/goplus/llgo/internal/runtime.String" @main.info(%"github.com/goplus/llgo/internal/runtime.String" %0) {
_llgo_0:
%1 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @1, i64 0)
%2 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringCat"(%"github.com/goplus/llgo/internal/runtime.String" %1, %"github.com/goplus/llgo/internal/runtime.String" %0)
%3 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @2, i64 3)
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringCat"(%"github.com/goplus/llgo/internal/runtime.String" %2, %"github.com/goplus/llgo/internal/runtime.String" %3)
ret %"github.com/goplus/llgo/internal/runtime.String" %4
}
define void @main.init() {
_llgo_0:
%0 = load i1, ptr @"main.init$guard", align 1
@@ -62,7 +75,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -70,28 +83,26 @@ _llgo_0:
call void @main.init()
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 48)
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i64 0
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @1, i64 5)
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @3, i64 5)
store %"github.com/goplus/llgo/internal/runtime.String" %4, ptr %3, align 8
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i64 1
%6 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @2, i64 1)
%6 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @4, i64 1)
store %"github.com/goplus/llgo/internal/runtime.String" %6, ptr %5, align 8
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i64 2
%8 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @3, i64 5)
%8 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @5, i64 5)
store %"github.com/goplus/llgo/internal/runtime.String" %8, ptr %7, align 8
%9 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %2, i64 16, i64 3, i64 0, i64 3, i64 3)
%10 = call %"github.com/goplus/llgo/internal/runtime.String" @main.concat(%"github.com/goplus/llgo/internal/runtime.Slice" %9)
%11 = load ptr, ptr @__stderrp, align 8
%12 = call i64 @"github.com/goplus/llgo/internal/runtime.StringLen"(%"github.com/goplus/llgo/internal/runtime.String" %10)
%12 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %10, 1
%13 = add i64 %12, 1
%14 = alloca i8, i64 %13, align 1
%15 = call ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr %14, %"github.com/goplus/llgo/internal/runtime.String" %10)
%16 = call i32 (ptr, ptr, ...) @fprintf(ptr %11, ptr @4, ptr %15)
ret void
%16 = call i32 (ptr, ptr, ...) @fprintf(ptr %11, ptr @6, ptr %15)
ret i32 0
}
declare i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringCat"(%"github.com/goplus/llgo/internal/runtime.String", %"github.com/goplus/llgo/internal/runtime.String")
@@ -103,8 +114,6 @@ declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr, i64, i64, i64, i64, i64)
declare i64 @"github.com/goplus/llgo/internal/runtime.StringLen"(%"github.com/goplus/llgo/internal/runtime.String")
declare ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr, %"github.com/goplus/llgo/internal/runtime.String")
declare i32 @fprintf(ptr, ptr, ...)

View File

@@ -19,14 +19,14 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
call void (ptr, ...) @printf(ptr @0)
ret void
ret i32 0
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -20,7 +20,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -28,7 +28,7 @@ _llgo_0:
call void @main.init()
%2 = load { [16 x i8], [2 x ptr] }, ptr @_bar_x, align 8
%3 = load { [16 x i8] }, ptr @_bar_y, align 1
ret void
ret i32 0
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -20,7 +20,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -28,7 +28,7 @@ _llgo_0:
call void @main.init()
%2 = load ptr, ptr @__stderrp, align 8
call void (ptr, ptr, ...) @fprintf(ptr %2, ptr @0, i64 100)
ret void
ret i32 0
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -3,9 +3,9 @@ source_filename = "main"
%"github.com/goplus/llgo/internal/abi.Type" = type { i64, i64, i32, i8, i8, i8, i8, { ptr, ptr }, ptr, i32, i32 }
@main.basicTypes = global ptr null
@main.basicTypes = global [25 x ptr] undef
@"main.init$guard" = global ptr null
@main.sizeBasicTypes = global ptr null
@main.sizeBasicTypes = global [25 x i64] undef
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@0 = private unnamed_addr constant [20 x i8] c"Kind: %d, Size: %d\0A\00", align 1
@@ -50,7 +50,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -63,7 +63,7 @@ _llgo_0:
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %2, i32 0, i32 0
%7 = load i64, ptr %6, align 4
%8 = call i32 (ptr, ...) @printf(ptr @0, i64 %5, i64 %7)
ret void
ret i32 0
}
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)

View File

@@ -25,14 +25,14 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
call void @main.foo(%"github.com/goplus/llgo/internal/runtime.iface" zeroinitializer)
ret void
ret i32 0
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -1,7 +1,7 @@
; ModuleID = 'main'
source_filename = "main"
@main.format = global ptr null
@main.format = global [10 x i8] undef
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@@ -29,7 +29,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -37,7 +37,7 @@ _llgo_0:
call void @main.init()
%2 = call i32 @strlen(ptr @main.format)
call void (ptr, ...) @printf(ptr @main.format, i32 %2)
ret void
ret i32 0
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -29,7 +29,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -119,16 +119,16 @@ _llgo_0:
%61 = load i64, ptr %60, align 4
%62 = call i32 (ptr, ...) @printf(ptr @3, i64 %61)
%63 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @5, i64 6)
%64 = call ptr @"github.com/goplus/llgo/internal/runtime.StringData"(%"github.com/goplus/llgo/internal/runtime.String" %63)
%64 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %63, 0
%65 = getelementptr inbounds i8, ptr %64, i64 2
%66 = load i8, ptr %65, align 1
%67 = call i32 (ptr, ...) @printf(ptr @4, i8 %66)
%68 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @7, i64 6)
%69 = call ptr @"github.com/goplus/llgo/internal/runtime.StringData"(%"github.com/goplus/llgo/internal/runtime.String" %68)
%69 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %68, 0
%70 = getelementptr inbounds i8, ptr %69, i64 1
%71 = load i8, ptr %70, align 1
%72 = call i32 (ptr, ...) @printf(ptr @6, i8 %71)
ret void
ret i32 0
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()
@@ -138,5 +138,3 @@ declare ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr, i64)
declare i32 @printf(ptr, ...)
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr, i64)
declare ptr @"github.com/goplus/llgo/internal/runtime.StringData"(%"github.com/goplus/llgo/internal/runtime.String")

View File

@@ -16,7 +16,7 @@ _llgo_0:
%2 = mul i64 %0, 4
%3 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 %2)
%4 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice"(ptr %3, i64 %0, i64 %0)
%5 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %4)
%5 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %4, 1
br label %_llgo_1
_llgo_1: ; preds = %_llgo_2, %_llgo_0
@@ -29,9 +29,11 @@ _llgo_2: ; preds = %_llgo_1
%9 = extractvalue { ptr, ptr } %1, 1
%10 = extractvalue { ptr, ptr } %1, 0
%11 = call i32 %10(ptr %9)
%12 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %4)
%13 = getelementptr inbounds i32, ptr %12, i64 %7
store i32 %11, ptr %13, align 4
%12 = icmp slt i64 %7, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %12)
%13 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %4, 0
%14 = getelementptr inbounds i32, ptr %13, i64 %7
store i32 %11, ptr %14, align 4
br label %_llgo_1
_llgo_3: ; preds = %_llgo_1
@@ -63,7 +65,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -76,7 +78,7 @@ _llgo_0:
store ptr null, ptr %4, align 8
%5 = load { ptr, ptr }, ptr %2, align 8
%6 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %5)
%7 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %6)
%7 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %6, 1
br label %_llgo_1
_llgo_1: ; preds = %_llgo_2, %_llgo_0
@@ -86,82 +88,86 @@ _llgo_1: ; preds = %_llgo_2, %_llgo_0
br i1 %10, label %_llgo_2, label %_llgo_3
_llgo_2: ; preds = %_llgo_1
%11 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %6)
%12 = getelementptr inbounds i32, ptr %11, i64 %9
%13 = load i32, ptr %12, align 4
%14 = call i32 (ptr, ...) @printf(ptr @0, i32 %13)
%11 = icmp slt i64 %9, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %11)
%12 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %6, 0
%13 = getelementptr inbounds i32, ptr %12, i64 %9
%14 = load i32, ptr %13, align 4
%15 = call i32 (ptr, ...) @printf(ptr @0, i32 %14)
br label %_llgo_1
_llgo_3: ; preds = %_llgo_1
%15 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 4)
store i32 1, ptr %15, align 4
%16 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
%17 = getelementptr inbounds { ptr }, ptr %16, i32 0, i32 0
store ptr %15, ptr %17, align 8
%18 = alloca { ptr, ptr }, align 8
%19 = getelementptr inbounds { ptr, ptr }, ptr %18, i32 0, i32 0
store ptr @"main.main$1", ptr %19, align 8
%20 = getelementptr inbounds { ptr, ptr }, ptr %18, i32 0, i32 1
store ptr %16, ptr %20, align 8
%21 = load { ptr, ptr }, ptr %18, align 8
%22 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %21)
%23 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %22)
%16 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 4)
store i32 1, ptr %16, align 4
%17 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
%18 = getelementptr inbounds { ptr }, ptr %17, i32 0, i32 0
store ptr %16, ptr %18, align 8
%19 = alloca { ptr, ptr }, align 8
%20 = getelementptr inbounds { ptr, ptr }, ptr %19, i32 0, i32 0
store ptr @"main.main$1", ptr %20, align 8
%21 = getelementptr inbounds { ptr, ptr }, ptr %19, i32 0, i32 1
store ptr %17, ptr %21, align 8
%22 = load { ptr, ptr }, ptr %19, align 8
%23 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %22)
%24 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %23, 1
br label %_llgo_4
_llgo_4: ; preds = %_llgo_5, %_llgo_3
%24 = phi i64 [ -1, %_llgo_3 ], [ %25, %_llgo_5 ]
%25 = add i64 %24, 1
%26 = icmp slt i64 %25, %23
br i1 %26, label %_llgo_5, label %_llgo_6
%25 = phi i64 [ -1, %_llgo_3 ], [ %26, %_llgo_5 ]
%26 = add i64 %25, 1
%27 = icmp slt i64 %26, %24
br i1 %27, label %_llgo_5, label %_llgo_6
_llgo_5: ; preds = %_llgo_4
%27 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %22)
%28 = getelementptr inbounds i32, ptr %27, i64 %25
%29 = load i32, ptr %28, align 4
%30 = call i32 (ptr, ...) @printf(ptr @1, i32 %29)
%28 = icmp slt i64 %26, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %28)
%29 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %23, 0
%30 = getelementptr inbounds i32, ptr %29, i64 %26
%31 = load i32, ptr %30, align 4
%32 = call i32 (ptr, ...) @printf(ptr @1, i32 %31)
br label %_llgo_4
_llgo_6: ; preds = %_llgo_4
%31 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 4)
%32 = getelementptr inbounds %main.generator, ptr %31, i32 0, i32 0
store i32 1, ptr %32, align 4
%33 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
%34 = getelementptr inbounds { ptr }, ptr %33, i32 0, i32 0
store ptr %31, ptr %34, align 8
%35 = alloca { ptr, ptr }, align 8
%36 = getelementptr inbounds { ptr, ptr }, ptr %35, i32 0, i32 0
store ptr @"main.next$bound", ptr %36, align 8
%37 = getelementptr inbounds { ptr, ptr }, ptr %35, i32 0, i32 1
store ptr %33, ptr %37, align 8
%38 = load { ptr, ptr }, ptr %35, align 8
%39 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %38)
%40 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %39)
%33 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 4)
%34 = getelementptr inbounds %main.generator, ptr %33, i32 0, i32 0
store i32 1, ptr %34, align 4
%35 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
%36 = getelementptr inbounds { ptr }, ptr %35, i32 0, i32 0
store ptr %33, ptr %36, align 8
%37 = alloca { ptr, ptr }, align 8
%38 = getelementptr inbounds { ptr, ptr }, ptr %37, i32 0, i32 0
store ptr @"main.next$bound", ptr %38, align 8
%39 = getelementptr inbounds { ptr, ptr }, ptr %37, i32 0, i32 1
store ptr %35, ptr %39, align 8
%40 = load { ptr, ptr }, ptr %37, align 8
%41 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %40)
%42 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %41, 1
br label %_llgo_7
_llgo_7: ; preds = %_llgo_8, %_llgo_6
%41 = phi i64 [ -1, %_llgo_6 ], [ %42, %_llgo_8 ]
%42 = add i64 %41, 1
%43 = icmp slt i64 %42, %40
br i1 %43, label %_llgo_8, label %_llgo_9
%43 = phi i64 [ -1, %_llgo_6 ], [ %44, %_llgo_8 ]
%44 = add i64 %43, 1
%45 = icmp slt i64 %44, %42
br i1 %45, label %_llgo_8, label %_llgo_9
_llgo_8: ; preds = %_llgo_7
%44 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %39)
%45 = getelementptr inbounds i32, ptr %44, i64 %42
%46 = load i32, ptr %45, align 4
%47 = call i32 (ptr, ...) @printf(ptr @2, i32 %46)
%46 = icmp slt i64 %44, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %46)
%47 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %41, 0
%48 = getelementptr inbounds i32, ptr %47, i64 %44
%49 = load i32, ptr %48, align 4
%50 = call i32 (ptr, ...) @printf(ptr @2, i32 %49)
br label %_llgo_7
_llgo_9: ; preds = %_llgo_7
ret void
ret i32 0
}
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice"(ptr, i64, i64)
declare i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -26,7 +26,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -34,7 +34,7 @@ _llgo_0:
call void @main.init()
call void @"github.com/goplus/llgo/cl/internal/linktarget.F"(ptr @0, ptr @1, ptr @2, ptr @3)
call void @"github.com/goplus/llgo/cl/internal/linktarget.F"(ptr @4, ptr @5, ptr @6, ptr @7)
ret void
ret i32 0
}
declare void @"github.com/goplus/llgo/cl/internal/linktarget.F"(ptr, ptr, ptr, ptr)

View File

@@ -19,7 +19,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -27,7 +27,7 @@ _llgo_0:
call void @main.init()
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.MakeSmallMap"()
%3 = call i32 (ptr, ...) @printf(ptr @0, <null operand!>)
ret void
ret i32 0
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()

42
cl/_testrt/mask/in.go Normal file
View File

@@ -0,0 +1,42 @@
package main
func main() {
println(mask(1))
println(mask_shl(127, 5))
println(mask_shl8(127, 5))
println(mask_shl8u(127, 5))
println(mask_shl8(127, 16))
println(mask_shl8u(127, 16))
println(mask_shr(127, 5))
println(mask_shr8(127, 5))
println(mask_shr8u(127, 5))
println(mask_shr8(127, 16))
}
func mask(x int8) int32 {
return int32(x) << 31 >> 31
}
func mask_shl8(x int8, y int) int8 {
return x << y
}
func mask_shl8u(x uint8, y int) uint8 {
return x << y
}
func mask_shl(x int, y int) int {
return x << y
}
func mask_shr8(x int8, y int) int8 {
return x >> y
}
func mask_shr8u(x uint8, y int) uint8 {
return x >> y
}
func mask_shr(x int, y int) int {
return x >> y
}

173
cl/_testrt/mask/out.ll Normal file
View File

@@ -0,0 +1,173 @@
; ModuleID = 'main'
source_filename = "main"
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@0 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@1 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@2 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@3 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@4 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@5 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@6 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@7 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@8 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@9 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
define void @main.init() {
_llgo_0:
%0 = load i1, ptr @"main.init$guard", align 1
br i1 %0, label %_llgo_2, label %_llgo_1
_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"main.init$guard", align 1
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
%2 = call i32 @main.mask(i8 1)
%3 = sext i32 %2 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %3)
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @0, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %4)
%5 = call i64 @main.mask_shl(i64 127, i64 5)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %5)
%6 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @1, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %6)
%7 = call i8 @main.mask_shl8(i8 127, i64 5)
%8 = sext i8 %7 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %8)
%9 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @2, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %9)
%10 = call i8 @main.mask_shl8u(i8 127, i64 5)
%11 = zext i8 %10 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %11)
%12 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @3, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %12)
%13 = call i8 @main.mask_shl8(i8 127, i64 16)
%14 = sext i8 %13 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %14)
%15 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @4, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %15)
%16 = call i8 @main.mask_shl8u(i8 127, i64 16)
%17 = zext i8 %16 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %17)
%18 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @5, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %18)
%19 = call i64 @main.mask_shr(i64 127, i64 5)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %19)
%20 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @6, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %20)
%21 = call i8 @main.mask_shr8(i8 127, i64 5)
%22 = sext i8 %21 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %22)
%23 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @7, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %23)
%24 = call i8 @main.mask_shr8u(i8 127, i64 5)
%25 = zext i8 %24 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %25)
%26 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @8, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %26)
%27 = call i8 @main.mask_shr8(i8 127, i64 16)
%28 = sext i8 %27 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %28)
%29 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @9, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %29)
ret i32 0
}
define i32 @main.mask(i8 %0) {
_llgo_0:
%1 = sext i8 %0 to i32
%2 = shl i32 %1, 31
%3 = select i1 false, i32 0, i32 %2
%4 = ashr i32 %3, 31
ret i32 %4
}
define i64 @main.mask_shl(i64 %0, i64 %1) {
_llgo_0:
%2 = icmp slt i64 %1, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertNegativeShift"(i1 %2)
%3 = icmp uge i64 %1, 64
%4 = shl i64 %0, %1
%5 = select i1 %3, i64 0, i64 %4
ret i64 %5
}
define i8 @main.mask_shl8(i8 %0, i64 %1) {
_llgo_0:
%2 = icmp slt i64 %1, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertNegativeShift"(i1 %2)
%3 = trunc i64 %1 to i8
%4 = icmp uge i8 %3, 8
%5 = shl i8 %0, %3
%6 = select i1 %4, i8 0, i8 %5
ret i8 %6
}
define i8 @main.mask_shl8u(i8 %0, i64 %1) {
_llgo_0:
%2 = icmp slt i64 %1, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertNegativeShift"(i1 %2)
%3 = trunc i64 %1 to i8
%4 = icmp uge i8 %3, 8
%5 = shl i8 %0, %3
%6 = select i1 %4, i8 0, i8 %5
ret i8 %6
}
define i64 @main.mask_shr(i64 %0, i64 %1) {
_llgo_0:
%2 = icmp slt i64 %1, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertNegativeShift"(i1 %2)
%3 = icmp uge i64 %1, 64
%4 = select i1 %3, i64 63, i64 %1
%5 = ashr i64 %0, %4
ret i64 %5
}
define i8 @main.mask_shr8(i8 %0, i64 %1) {
_llgo_0:
%2 = icmp slt i64 %1, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertNegativeShift"(i1 %2)
%3 = trunc i64 %1 to i8
%4 = icmp uge i8 %3, 8
%5 = select i1 %4, i8 7, i8 %3
%6 = ashr i8 %0, %5
ret i8 %6
}
define i8 @main.mask_shr8u(i8 %0, i64 %1) {
_llgo_0:
%2 = icmp slt i64 %1, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertNegativeShift"(i1 %2)
%3 = trunc i64 %1 to i8
%4 = icmp uge i8 %3, 8
%5 = lshr i8 %0, %3
%6 = select i1 %4, i8 0, i8 %5
ret i8 %6
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64)
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr, i64)
declare void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64)
declare void @"github.com/goplus/llgo/internal/runtime.AssertNegativeShift"(i1)

39
cl/_testrt/named/in.go Normal file
View File

@@ -0,0 +1,39 @@
package main
import "github.com/goplus/llgo/internal/runtime/c"
type mSpanList struct {
first *mspan
last *mspan
}
type minfo struct {
span *mspan
info int
}
type mspan struct {
next *mspan
prev *mspan
list *mSpanList
info minfo
value int
check func(int) int
}
func main() {
m := &mspan{}
m.value = 100
m.next = &mspan{}
m.next.value = 200
m.list = &mSpanList{}
m.list.last = &mspan{}
m.list.last.value = 300
m.info.info = 10
m.info.span = m
m.check = func(n int) int {
return m.value * n
}
c.Printf(c.Str("%d %d %d %d %d %d\n"), m.next.value, m.list.last.value, m.info.info,
m.info.span.value, m.check(-2), m.info.span.check(-3))
}

143
cl/_testrt/named/out.ll Normal file
View File

@@ -0,0 +1,143 @@
; ModuleID = 'main'
source_filename = "main"
%main.mspan = type { ptr, ptr, ptr, %main.minfo, i64, { ptr, ptr } }
%main.minfo = type { ptr, i64 }
%main.mSpanList = type { ptr, ptr }
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@0 = private unnamed_addr constant [19 x i8] c"%d %d %d %d %d %d\0A\00", align 1
define void @main.init() {
_llgo_0:
%0 = load i1, ptr @"main.init$guard", align 1
br i1 %0, label %_llgo_2, label %_llgo_1
_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"main.init$guard", align 1
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 8)
%3 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 64)
store ptr %3, ptr %2, align 8
%4 = load ptr, ptr %2, align 8
%5 = getelementptr inbounds %main.mspan, ptr %4, i32 0, i32 4
store i64 100, ptr %5, align 4
%6 = load ptr, ptr %2, align 8
%7 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 64)
%8 = getelementptr inbounds %main.mspan, ptr %6, i32 0, i32 0
store ptr %7, ptr %8, align 8
%9 = load ptr, ptr %2, align 8
%10 = getelementptr inbounds %main.mspan, ptr %9, i32 0, i32 0
%11 = load ptr, ptr %10, align 8
%12 = getelementptr inbounds %main.mspan, ptr %11, i32 0, i32 4
store i64 200, ptr %12, align 4
%13 = load ptr, ptr %2, align 8
%14 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 16)
%15 = getelementptr inbounds %main.mspan, ptr %13, i32 0, i32 2
store ptr %14, ptr %15, align 8
%16 = load ptr, ptr %2, align 8
%17 = getelementptr inbounds %main.mspan, ptr %16, i32 0, i32 2
%18 = load ptr, ptr %17, align 8
%19 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 64)
%20 = getelementptr inbounds %main.mSpanList, ptr %18, i32 0, i32 1
store ptr %19, ptr %20, align 8
%21 = load ptr, ptr %2, align 8
%22 = getelementptr inbounds %main.mspan, ptr %21, i32 0, i32 2
%23 = load ptr, ptr %22, align 8
%24 = getelementptr inbounds %main.mSpanList, ptr %23, i32 0, i32 1
%25 = load ptr, ptr %24, align 8
%26 = getelementptr inbounds %main.mspan, ptr %25, i32 0, i32 4
store i64 300, ptr %26, align 4
%27 = load ptr, ptr %2, align 8
%28 = getelementptr inbounds %main.mspan, ptr %27, i32 0, i32 3
%29 = getelementptr inbounds %main.minfo, ptr %28, i32 0, i32 1
store i64 10, ptr %29, align 4
%30 = load ptr, ptr %2, align 8
%31 = getelementptr inbounds %main.mspan, ptr %30, i32 0, i32 3
%32 = load ptr, ptr %2, align 8
%33 = getelementptr inbounds %main.minfo, ptr %31, i32 0, i32 0
store ptr %32, ptr %33, align 8
%34 = load ptr, ptr %2, align 8
%35 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
%36 = getelementptr inbounds { ptr }, ptr %35, i32 0, i32 0
store ptr %2, ptr %36, align 8
%37 = alloca { ptr, ptr }, align 8
%38 = getelementptr inbounds { ptr, ptr }, ptr %37, i32 0, i32 0
store ptr @"main.main$1", ptr %38, align 8
%39 = getelementptr inbounds { ptr, ptr }, ptr %37, i32 0, i32 1
store ptr %35, ptr %39, align 8
%40 = load { ptr, ptr }, ptr %37, align 8
%41 = getelementptr inbounds %main.mspan, ptr %34, i32 0, i32 5
store { ptr, ptr } %40, ptr %41, align 8
%42 = load ptr, ptr %2, align 8
%43 = getelementptr inbounds %main.mspan, ptr %42, i32 0, i32 0
%44 = load ptr, ptr %43, align 8
%45 = getelementptr inbounds %main.mspan, ptr %44, i32 0, i32 4
%46 = load i64, ptr %45, align 4
%47 = load ptr, ptr %2, align 8
%48 = getelementptr inbounds %main.mspan, ptr %47, i32 0, i32 2
%49 = load ptr, ptr %48, align 8
%50 = getelementptr inbounds %main.mSpanList, ptr %49, i32 0, i32 1
%51 = load ptr, ptr %50, align 8
%52 = getelementptr inbounds %main.mspan, ptr %51, i32 0, i32 4
%53 = load i64, ptr %52, align 4
%54 = load ptr, ptr %2, align 8
%55 = getelementptr inbounds %main.mspan, ptr %54, i32 0, i32 3
%56 = getelementptr inbounds %main.minfo, ptr %55, i32 0, i32 1
%57 = load i64, ptr %56, align 4
%58 = load ptr, ptr %2, align 8
%59 = getelementptr inbounds %main.mspan, ptr %58, i32 0, i32 3
%60 = getelementptr inbounds %main.minfo, ptr %59, i32 0, i32 0
%61 = load ptr, ptr %60, align 8
%62 = getelementptr inbounds %main.mspan, ptr %61, i32 0, i32 4
%63 = load i64, ptr %62, align 4
%64 = load ptr, ptr %2, align 8
%65 = getelementptr inbounds %main.mspan, ptr %64, i32 0, i32 5
%66 = load { ptr, ptr }, ptr %65, align 8
%67 = extractvalue { ptr, ptr } %66, 1
%68 = extractvalue { ptr, ptr } %66, 0
%69 = call i64 %68(ptr %67, i64 -2)
%70 = load ptr, ptr %2, align 8
%71 = getelementptr inbounds %main.mspan, ptr %70, i32 0, i32 3
%72 = getelementptr inbounds %main.minfo, ptr %71, i32 0, i32 0
%73 = load ptr, ptr %72, align 8
%74 = getelementptr inbounds %main.mspan, ptr %73, i32 0, i32 5
%75 = load { ptr, ptr }, ptr %74, align 8
%76 = extractvalue { ptr, ptr } %75, 1
%77 = extractvalue { ptr, ptr } %75, 0
%78 = call i64 %77(ptr %76, i64 -3)
%79 = call i32 (ptr, ...) @printf(ptr @0, i64 %46, i64 %53, i64 %57, i64 %63, i64 %69, i64 %78)
ret i32 0
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
define i64 @"main.main$1"(ptr %0, i64 %1) {
_llgo_0:
%2 = load { ptr }, ptr %0, align 8
%3 = extractvalue { ptr } %2, 0
%4 = load ptr, ptr %3, align 8
%5 = getelementptr inbounds %main.mspan, ptr %4, i32 0, i32 4
%6 = load i64, ptr %5, align 4
%7 = mul i64 %6, %1
ret i64 %7
}
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64)
declare i32 @printf(ptr, ...)

View File

@@ -22,7 +22,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8

View File

@@ -19,7 +19,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -48,13 +48,15 @@ _llgo_1: ; preds = %_llgo_2, %_llgo_0
br i1 %12, label %_llgo_2, label %_llgo_3
_llgo_2: ; preds = %_llgo_1
%13 = getelementptr inbounds i64, ptr %2, i64 %11
%14 = load i64, ptr %13, align 4
%15 = call i32 (ptr, ...) @printf(ptr @0, i64 %14)
%13 = icmp slt i64 %11, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %13)
%14 = getelementptr inbounds i64, ptr %2, i64 %11
%15 = load i64, ptr %14, align 4
%16 = call i32 (ptr, ...) @printf(ptr @0, i64 %15)
br label %_llgo_1
_llgo_3: ; preds = %_llgo_1
ret void
ret i32 0
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()
@@ -72,4 +74,6 @@ _llgo_0:
ret i32 %5
}
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
declare i32 @printf(ptr, ...)

View File

@@ -45,7 +45,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -69,7 +69,7 @@ _llgo_0:
%17 = extractvalue { ptr, ptr } %15, 0
%18 = call i64 %17(ptr %16, i64 100, i64 200)
%19 = call i32 (ptr, ...) @printf(ptr @2, i64 %18, i64 %14)
ret void
ret i32 0
}
define i64 @"main.add$1"(i64 %0, i64 %1) {

View File

@@ -1,7 +1,7 @@
; ModuleID = 'main'
source_filename = "main"
@main.format = global ptr null
@main.format = global [10 x i8] undef
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@@ -29,7 +29,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -37,7 +37,7 @@ _llgo_0:
call void @main.init()
%2 = call i32 @strlen(ptr @main.format)
call void (ptr, ...) @printf(ptr @main.format, i32 %2)
ret void
ret i32 0
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -3,7 +3,7 @@ source_filename = "main"
%main.Foo = type { i32, i1 }
@main.format = global ptr null
@main.format = global [10 x i8] undef
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@@ -57,7 +57,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -71,7 +71,7 @@ _llgo_0:
store i1 true, ptr %5, align 1
%6 = load %main.Foo, ptr %3, align 4
call void @"(main.Foo).Print"(%main.Foo %6)
ret void
ret i32 0
}
declare ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr, i64)

View File

@@ -21,7 +21,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -39,26 +39,28 @@ _llgo_0:
%7 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %2, i64 8, i64 4, i64 0, i64 4, i64 4)
%8 = call i64 @main.sum(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
%9 = call i32 (ptr, ...) @printf(ptr @0, i64 %8)
ret void
ret i32 0
}
define i64 @main.sum(%"github.com/goplus/llgo/internal/runtime.Slice" %0) {
_llgo_0:
%1 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %0)
%1 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
br label %_llgo_1
_llgo_1: ; preds = %_llgo_2, %_llgo_0
%2 = phi i64 [ 0, %_llgo_0 ], [ %9, %_llgo_2 ]
%2 = phi i64 [ 0, %_llgo_0 ], [ %10, %_llgo_2 ]
%3 = phi i64 [ -1, %_llgo_0 ], [ %4, %_llgo_2 ]
%4 = add i64 %3, 1
%5 = icmp slt i64 %4, %1
br i1 %5, label %_llgo_2, label %_llgo_3
_llgo_2: ; preds = %_llgo_1
%6 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %0)
%7 = getelementptr inbounds i64, ptr %6, i64 %4
%8 = load i64, ptr %7, align 4
%9 = add i64 %2, %8
%6 = icmp slt i64 %4, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %6)
%7 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
%8 = getelementptr inbounds i64, ptr %7, i64 %4
%9 = load i64, ptr %8, align 4
%10 = add i64 %2, %9
br label %_llgo_1
_llgo_3: ; preds = %_llgo_1
@@ -73,6 +75,4 @@ declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llg
declare i32 @printf(ptr, ...)
declare i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)

View File

@@ -1,7 +1,7 @@
; ModuleID = 'main'
source_filename = "main"
@main.format = global ptr null
@main.format = global [10 x i8] undef
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@@ -45,7 +45,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -57,7 +57,7 @@ _llgo_0:
store i32 100, ptr %3, align 4
store i1 true, ptr %4, align 1
call void @main.Print(ptr %2)
ret void
ret i32 0
}
declare void @printf(ptr, ...)

View File

@@ -25,7 +25,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main(i32 %0, ptr %1) {
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
@@ -33,7 +33,7 @@ _llgo_0:
call void @main.init()
call void @main.foo()
%2 = call i32 (ptr, ...) @printf(ptr @0)
ret void
ret i32 0
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -226,5 +226,5 @@ func TestErrVarOf(t *testing.T) {
}
ssaPkg := &ssa.Package{Pkg: pkgTypes}
g := &ssa.Global{Pkg: ssaPkg}
ctx.varOf(g)
ctx.varOf(nil, g)
}

View File

@@ -147,11 +147,23 @@ func TestCompileEx(t *testing.T, src any, fname, expected string) {
}
return rt
})
prog.SetPython(func() *types.Package {
rt, err := imp.Import(llssa.PkgPython)
if err != nil {
t.Fatal("load python failed:", err)
}
return rt
})
ret, err := cl.NewPackage(prog, foo, files)
if err != nil {
t.Fatal("cl.NewPackage failed:", err)
}
if prog.NeedPyInit { // call PyInit if needed
ret.PyInit()
}
if v := ret.String(); v != expected {
t.Fatalf("\n==> got:\n%s\n==> expected:\n%s\n", v, expected)
}

View File

@@ -123,6 +123,7 @@ type instrOrValue interface {
const (
PkgNormal = iota
PkgLLGo
PkgPyModule // py.<module>
PkgNoInit // noinit: a package that don't need to be initialized
PkgDeclOnly // decl: a package that only have declarations
PkgLinkIR // link llvm ir (.ll)
@@ -142,6 +143,7 @@ type context struct {
goProg *ssa.Program
goTyps *types.Package
goPkg *ssa.Package
pyMod string
link map[string]string // pkgPath.nameInPkg => linkname
loaded map[*types.Package]*pkgInfo // loaded packages
bvals map[ssa.Value]llssa.Expr // block values
@@ -150,6 +152,10 @@ type context struct {
phis []func()
}
func (p *context) inMain(instr ssa.Instruction) bool {
return instr.Parent().Name() == "main"
}
func (p *context) compileType(pkg llssa.Package, t *ssa.Type) {
tn := t.Object().(*types.TypeName)
if tn.IsAlias() { // don't need to compile alias type
@@ -183,7 +189,7 @@ func (p *context) compileMethods(pkg llssa.Package, typ types.Type) {
func (p *context) compileGlobal(pkg llssa.Package, gbl *ssa.Global) {
typ := gbl.Type()
name, vtype := p.varName(gbl.Pkg.Pkg, gbl)
if ignoreName(name) || checkCgo(gbl.Name()) {
if vtype == pyVar || ignoreName(name) || checkCgo(gbl.Name()) {
return
}
if debugInstr {
@@ -209,14 +215,21 @@ var (
argvTy = types.NewPointer(types.NewPointer(types.Typ[types.Int8]))
)
func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) llssa.Function {
func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Function, llssa.PyObjRef, int) {
pkgTypes, name, ftype := p.funcName(f, true)
if ftype != goFunc {
return nil
/*
if ftype == pyFunc {
// TODO(xsw): pyMod == ""
fnName := pysymPrefix + p.pyMod + "." + name
return nil, pkg.NewPyFunc(fnName, f.Signature, call), pyFunc
}
*/
return nil, nil, ignoredFunc
}
fn := pkg.FuncOf(name)
if fn != nil && fn.HasBody() {
return fn
return fn, nil, goFunc
}
var sig = f.Signature
@@ -229,7 +242,7 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) llssa.Func
sig = llssa.FuncAddCtx(ctx, sig)
} else {
if debugInstr {
log.Println("==> NewFunc", name, "type:", sig.Recv(), sig)
log.Println("==> NewFunc", name, "type:", sig.Recv(), sig, "ftype:", ftype)
}
}
if fn == nil {
@@ -237,10 +250,13 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) llssa.Func
argc := types.NewParam(token.NoPos, pkgTypes, "", types.Typ[types.Int32])
argv := types.NewParam(token.NoPos, pkgTypes, "", argvTy)
params := types.NewTuple(argc, argv)
sig = types.NewSignatureType(nil, nil, nil, params, nil, false)
ret := types.NewParam(token.NoPos, pkgTypes, "", p.prog.CInt().RawType())
results := types.NewTuple(ret)
sig = types.NewSignatureType(nil, nil, nil, params, results, false)
}
fn = pkg.NewFuncEx(name, sig, llssa.Background(ftype), hasCtx)
}
if nblk := len(f.Blocks); nblk > 0 {
fn.MakeBlocks(nblk) // to set fn.HasBody() = true
p.inits = append(p.inits, func() {
@@ -262,21 +278,34 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) llssa.Func
off[i] = p.compilePhis(b, block)
}
for i, block := range f.Blocks {
p.compileBlock(b, block, off[i], i == 0 && name == "main")
doMainInit := (i == 0 && name == "main")
doModInit := (i == 1 && f.Name() == "init" && sig.Recv() == nil)
p.compileBlock(b, block, off[i], doMainInit, doModInit)
}
for _, phi := range p.phis {
phi()
}
})
}
return fn
return fn, nil, goFunc
}
// funcOf returns a function by name and set ftype = goFunc, cFunc, etc.
// or returns nil and set ftype = llgoCstr, llgoAlloca, llgoUnreachable, etc.
func (p *context) funcOf(fn *ssa.Function) (ret llssa.Function, ftype int) {
_, name, ftype := p.funcName(fn, false)
if ftype == llgoInstr {
func (p *context) funcOf(fn *ssa.Function) (aFn llssa.Function, pyFn llssa.PyObjRef, ftype int) {
pkgTypes, name, ftype := p.funcName(fn, false)
switch ftype {
case pyFunc:
if kind, mod := pkgKindByScope(pkgTypes.Scope()); kind == PkgPyModule {
pkg := p.pkg
fnName := pysymPrefix + mod + "." + name
if pyFn = pkg.PyObjOf(fnName); pyFn == nil {
pyFn = pkg.PyNewFunc(fnName, fn.Signature, true)
return
}
}
ftype = ignoredFunc
case llgoInstr:
switch name {
case "cstr":
ftype = llgoCstr
@@ -288,31 +317,73 @@ func (p *context) funcOf(fn *ssa.Function) (ret llssa.Function, ftype int) {
ftype = llgoAlloca
case "allocaCStr":
ftype = llgoAllocaCStr
case "stringData":
ftype = llgoStringData
case "pyList":
ftype = llgoPyList
case "unreachable":
ftype = llgoUnreachable
case "bitCastTo64F":
ftype = llgoBitCastTo64F
case "bitCastTo32F":
ftype = llgoBitCastTo32F
default:
panic("unknown llgo instruction: " + name)
}
} else {
default:
pkg := p.pkg
if ret = pkg.FuncOf(name); ret == nil && len(fn.FreeVars) == 0 {
if aFn = pkg.FuncOf(name); aFn == nil {
if len(fn.FreeVars) > 0 {
return nil, nil, ignoredFunc
}
sig := fn.Signature
ret = pkg.NewFuncEx(name, sig, llssa.Background(ftype), false)
aFn = pkg.NewFuncEx(name, sig, llssa.Background(ftype), false)
}
}
return
}
func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, doInit bool) llssa.BasicBlock {
ret := p.fn.Block(block.Index)
func modOf(name string) string {
if pos := strings.LastIndexByte(name, '.'); pos > 0 {
return name[:pos]
}
return ""
}
func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, doMainInit, doModInit bool) llssa.BasicBlock {
var last int
var pyModInit bool
var prog = p.prog
var pkg = p.pkg
var instrs = block.Instrs[n:]
var ret = p.fn.Block(block.Index)
b.SetBlock(ret)
if doInit {
prog := p.prog
pkg := p.pkg
if doModInit {
if pyModInit = p.pyMod != ""; pyModInit {
last = len(instrs) - 1
instrs = instrs[:last]
} else {
// TODO(xsw): confirm pyMod don't need to call LoadPyModSyms
p.inits = append(p.inits, func() {
if objs := pkg.PyObjs(); len(objs) > 0 {
mods := make(map[string][]llssa.PyObjRef)
for name, obj := range objs {
modName := modOf(name)
mods[modName] = append(mods[modName], obj)
}
// sort by module name
modNames := make([]string, 0, len(mods))
for modName := range mods {
modNames = append(modNames, modName)
}
sort.Strings(modNames)
b.SetBlockEx(ret, llssa.AfterInit)
for _, modName := range modNames {
objs := mods[modName]
b.PyLoadModSyms(modName, objs...)
}
}
})
}
} else if doMainInit {
fn := p.fn
argc := pkg.NewVar("__llgo_argc", types.NewPointer(types.Typ[types.Int32]), llssa.InC)
argv := pkg.NewVar("__llgo_argv", types.NewPointer(argvTy), llssa.InC)
@@ -323,9 +394,23 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do
callRuntimeInit(b, pkg)
b.Call(pkg.FuncOf("main.init").Expr)
}
for _, instr := range block.Instrs[n:] {
for _, instr := range instrs {
p.compileInstr(b, instr)
}
if pyModInit {
jump := block.Instrs[n+last].(*ssa.Jump)
jumpTo := p.jumpTo(jump)
modPath := p.pyMod
modName := pysymPrefix + modPath
modPtr := pkg.PyNewModVar(modName, true).Expr
mod := b.Load(modPtr)
cond := b.BinOp(token.NEQ, mod, prog.Null(mod.Type))
newBlk := p.fn.MakeBlock()
b.If(cond, jumpTo, newBlk)
b.SetBlock(newBlk)
b.Store(modPtr, b.PyImportMod(modPath))
b.Jump(jumpTo)
}
return ret
}
@@ -334,8 +419,7 @@ const (
)
func callRuntimeInit(b llssa.Builder, pkg llssa.Package) {
sig := types.NewSignatureType(nil, nil, nil, nil, nil, false)
fn := pkg.NewFunc(RuntimeInit, sig, llssa.InC) // don't need to convert runtime.init
fn := pkg.NewFunc(RuntimeInit, llssa.NoArgsNoRet, llssa.InC) // don't need to convert runtime.init
b.Call(fn.Expr)
}
@@ -434,6 +518,15 @@ func (p *context) allocaCStr(b llssa.Builder, args []ssa.Value) (ret llssa.Expr)
panic("allocaCStr(s string): invalid arguments")
}
// func stringData(s string) *int8
func (p *context) stringData(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
if len(args) == 1 {
s := p.compileValue(b, args[0])
return b.StringData(s)
}
panic("stringData(s string): invalid arguments")
}
func isPhi(i ssa.Instruction) bool {
_, ok := i.(*ssa.Phi)
return ok
@@ -441,7 +534,7 @@ func isPhi(i ssa.Instruction) bool {
func (p *context) compilePhis(b llssa.Builder, block *ssa.BasicBlock) int {
ret := p.fn.Block(block.Index)
b.SetBlock(ret)
b.SetBlockEx(ret, llssa.AtEnd)
if ninstr := len(block.Instrs); ninstr > 0 {
if isPhi(block.Instrs[0]) {
n := 1
@@ -510,11 +603,17 @@ func (p *context) compileInstrOrValue(b llssa.Builder, iv instrOrValue, asValue
ret = b.BuiltinCall(fn, args...)
}
case *ssa.Function:
fn, ftype := p.compileFunction(cv)
aFn, pyFn, ftype := p.compileFunction(cv)
switch ftype {
case goFunc, cFunc:
args := p.compileValues(b, args, kind)
ret = b.Call(fn.Expr, args...)
ret = b.Call(aFn.Expr, args...)
case pyFunc:
args := p.compileValues(b, args, kind)
ret = b.Call(pyFn.Expr, args...)
case llgoPyList:
args := p.compileValues(b, args, fnHasVArg)
ret = b.PyList(args...)
case llgoCstr:
ret = cstr(b, args)
case llgoAdvance:
@@ -525,12 +624,10 @@ func (p *context) compileInstrOrValue(b llssa.Builder, iv instrOrValue, asValue
ret = p.alloca(b, args)
case llgoAllocaCStr:
ret = p.allocaCStr(b, args)
case llgoStringData:
ret = p.stringData(b, args)
case llgoUnreachable: // func unreachable()
b.Unreachable()
case llgoBitCastTo32F:
ret = b.BitCast(p.compileValue(b, args[0]), b.Prog.Type(types.Typ[types.Float32], llssa.InGo))
case llgoBitCastTo64F:
ret = b.BitCast(p.compileValue(b, args[0]), b.Prog.Float64())
default:
panic("todo")
}
@@ -650,6 +747,12 @@ func (p *context) compileInstrOrValue(b llssa.Builder, iv instrOrValue, asValue
return ret
}
func (p *context) jumpTo(v *ssa.Jump) llssa.BasicBlock {
fn := p.fn
succs := v.Block().Succs
return fn.Block(succs[0].Index)
}
func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
if iv, ok := instr.(instrOrValue); ok {
p.compileInstrOrValue(b, iv, false)
@@ -673,9 +776,7 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
val := p.compileValue(b, v.Val)
b.Store(ptr, val)
case *ssa.Jump:
fn := p.fn
succs := v.Block().Succs
jmpb := fn.Block(succs[0].Index)
jmpb := p.jumpTo(v)
b.Jump(jmpb)
case *ssa.Return:
var results []llssa.Expr
@@ -685,6 +786,10 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
results[i] = p.compileValue(b, r)
}
}
if p.inMain(instr) {
results = make([]llssa.Expr, 1)
results[0] = p.prog.IntVal(0, p.prog.CInt())
}
b.Return(results...)
case *ssa.If:
fn := p.fn
@@ -706,12 +811,13 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
}
}
func (p *context) compileFunction(v *ssa.Function) (llssa.Function, int) {
func (p *context) compileFunction(v *ssa.Function) (goFn llssa.Function, pyFn llssa.PyObjRef, kind int) {
// v.Pkg == nil: means auto generated function?
if v.Pkg == p.goPkg || v.Pkg == nil {
// function in this package
if fn := p.compileFuncDecl(p.pkg, v); fn != nil {
return fn, goFunc
goFn, pyFn, kind = p.compileFuncDecl(p.pkg, v)
if kind != ignoredFunc {
return
}
}
return p.funcOf(v)
@@ -730,11 +836,13 @@ func (p *context) compileValue(b llssa.Builder, v ssa.Value) llssa.Expr {
}
}
case *ssa.Function:
fn, _ := p.compileFunction(v)
return fn.Expr
aFn, pyFn, _ := p.compileFunction(v)
if aFn != nil {
return aFn.Expr
}
return pyFn.Expr
case *ssa.Global:
g := p.varOf(v)
return g.Expr
return p.varOf(b, v)
case *ssa.Const:
t := types.Default(v.Type())
return b.Const(v.Value, p.prog.Type(t, llssa.InGo))
@@ -814,6 +922,7 @@ func NewPackage(prog llssa.Program, pkg *ssa.Package, files []*ast.File) (ret ll
types.Unsafe: {kind: PkgDeclOnly}, // TODO(xsw): PkgNoInit or PkgDeclOnly?
},
}
ctx.initPyModule()
ctx.initFiles(pkgPath, files)
for _, m := range members {
member := m.val

View File

@@ -28,8 +28,12 @@ func testCompile(t *testing.T, src, expected string) {
cltest.TestCompileEx(t, src, "foo.go", expected)
}
func TestFromTestpy(t *testing.T) {
cltest.FromDir(t, "", "./_testpy", false)
}
func TestFromTestlibc(t *testing.T) {
cltest.FromDir(t, "", "./_testlibc", false)
cltest.FromDir(t, "", "./_testlibc", true)
}
func TestFromTestrt(t *testing.T) {
@@ -41,7 +45,15 @@ func TestFromTestdata(t *testing.T) {
}
func TestSqlite(t *testing.T) {
cltest.Pkg(t, "github.com/goplus/llgo/x/sqlite", "../x/sqlite/sqlite.ll")
cltest.Pkg(t, "github.com/goplus/llgo/c/sqlite", "../c/sqlite/llgo_autogen.ll")
}
func TestFromTestpymath(t *testing.T) {
cltest.Pkg(t, ssa.PkgPython+"/math", "../py/math/llgo_autogen.ll")
}
func TestPython(t *testing.T) {
cltest.Pkg(t, ssa.PkgPython, "../py/llgo_autogen.ll")
}
func TestRuntime(t *testing.T) {

View File

@@ -30,6 +30,8 @@ import (
"golang.org/x/tools/go/ssa"
)
// -----------------------------------------------------------------------------
type symInfo struct {
file string
fullName string
@@ -101,6 +103,8 @@ func pkgKind(v string) (int, string) {
// return PkgLinkBitCode
if strings.HasPrefix(v, "link:") { // "link: <libpath>"
return PkgLinkExtern, v[5:]
} else if strings.HasPrefix(v, "py.") { // "py.<module>"
return PkgPyModule, v[3:]
}
}
return PkgLLGo, ""
@@ -210,7 +214,7 @@ func (p *context) initLink(line string, prefix int, f func(inPkgName string) (fu
} else {
panic(line + ": no specified call convention. eg. //go:linkname Printf C.printf")
}
} else {
} else if c := inPkgName[0]; c >= 'A' && c <= 'Z' {
fmt.Fprintln(os.Stderr, "==>", line)
fmt.Fprintf(os.Stderr, "llgo: linkname %s not found and ignored\n", inPkgName)
}
@@ -303,17 +307,18 @@ const (
ignoredFunc = iota
goFunc = int(llssa.InGo)
cFunc = int(llssa.InC)
pyFunc = int(llssa.InPython)
llgoInstr = -1
llgoInstrBase = 0x80
llgoUnreachable = llgoInstrBase + 0
llgoCstr = llgoInstrBase + 1
llgoAlloca = llgoInstrBase + 2
llgoAllocaCStr = llgoInstrBase + 3
llgoAdvance = llgoInstrBase + 4
llgoIndex = llgoInstrBase + 5
llgoBitCastTo32F = llgoInstrBase + 6
llgoBitCastTo64F = llgoInstrBase + 7
llgoInstrBase = 0x80
llgoUnreachable = llgoInstrBase + 0
llgoCstr = llgoInstrBase + 1
llgoAlloca = llgoInstrBase + 2
llgoAllocaCStr = llgoInstrBase + 3
llgoAdvance = llgoInstrBase + 4
llgoIndex = llgoInstrBase + 5
llgoStringData = llgoInstrBase + 6
llgoPyList = llgoInstrBase + 7
)
func (p *context) funcName(fn *ssa.Function, ignore bool) (*types.Package, string, int) {
@@ -339,6 +344,9 @@ func (p *context) funcName(fn *ssa.Function, ignore bool) (*types.Package, strin
if strings.HasPrefix(v, "C.") {
return nil, v[2:], cFunc
}
if strings.HasPrefix(v, "py.") {
return pkg, v[3:], pyFunc
}
if strings.HasPrefix(v, "llgo.") {
return nil, v[5:], llgoInstr
}
@@ -351,24 +359,35 @@ const (
ignoredVar = iota
goVar = int(llssa.InGo)
cVar = int(llssa.InC)
pyVar = int(llssa.InPython)
)
func (p *context) varName(pkg *types.Package, v *ssa.Global) (vName string, vtype int) {
name := llssa.FullName(pkg, v.Name())
if v, ok := p.link[name]; ok {
if strings.HasPrefix(v, "py.") {
return v[3:], pyVar
}
return v, cVar
}
return name, goVar
}
func (p *context) varOf(v *ssa.Global) (ret llssa.Global) {
func (p *context) varOf(b llssa.Builder, v *ssa.Global) llssa.Expr {
pkgTypes := p.ensureLoaded(v.Pkg.Pkg)
pkg := p.pkg
name, vtype := p.varName(pkgTypes, v)
if ret = pkg.VarOf(name); ret == nil {
if vtype == pyVar {
if kind, mod := pkgKindByScope(pkgTypes.Scope()); kind == PkgPyModule {
return b.PyNewVar(pysymPrefix+mod, name).Expr
}
panic("unreachable")
}
ret := pkg.VarOf(name)
if ret == nil {
ret = pkg.NewVar(name, v.Type(), llssa.Background(vtype))
}
return
return ret.Expr
}
func (p *context) ensureLoaded(pkgTypes *types.Package) *types.Package {
@@ -391,3 +410,17 @@ func pkgKindByPath(pkgPath string) int {
}
return PkgNormal
}
// -----------------------------------------------------------------------------
const (
pysymPrefix = "__llgo_py."
)
func (p *context) initPyModule() {
if kind, mod := pkgKindByScope(p.goTyps.Scope()); kind == PkgPyModule {
p.pyMod = mod
}
}
// -----------------------------------------------------------------------------

2
go.mod
View File

@@ -18,3 +18,5 @@ require (
golang.org/x/mod v0.17.0 // indirect
golang.org/x/sync v0.7.0 // indirect
)
retract v0.8.0

Some files were not shown because too many files have changed in this diff Show More