• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14.record panda.String <external>
15.record IO <external>
16.function void IO.printString(panda.String a0) <external>
17.function void IO.printI32(i32 a0) <external>
18
19# void do() {
20#    String[] v6 = new String[5];
21#    for(int i = 0; i < 5; i++) {
22#       String[] s = allocString();
23#       v6[i] = s[0];
24#   }
25#   for(int i = 0; i < 5; i++) {
26#       // we expect that v6[i] is still reachable
27#       printString(v6[i]);
28#   }
29# }
30
31# String[] allocString() {
32#   String[] v1 = new String[1];
33#   v1[0] = "asdf"
34#   return v1
35#}
36
37.function i32 main(){
38    call.short do
39
40    # safe-point for trigger GC in the end
41    lda.str "finish test\n"
42    sta.obj v2
43    call.short IO.printString, v2, v2
44
45    ldai 0
46    return
47}
48
49# String[] v1 = new String[1];
50# v1[0] = "asdf"
51# return v1
52.function panda.String[] allocString(){
53    lda.str "asdf\n"
54    sta.obj v2
55
56    movi v0, 1
57    # v1 = new String[v0]
58    newarr v1, v0, panda.String[]
59
60    # v1[v3] = v2
61    lda.obj v2
62    movi v3, 0
63    starr.obj v1, v3
64
65    lda.obj v1
66    return.obj
67}
68
69.function void do (){
70    movi v0, 5
71
72    # v6 = new String[v0]
73    newarr v6, v0, panda.String[]
74
75    # (for int v2=0; v2 != v0; v2++)
76    movi v2, 0
77    ldai 0
78    loop:
79        jeq v0, loop_exit
80
81
82        # v5=allocString()[0]  + print v5
83        call.short allocString
84        sta.obj v3
85
86        movi v4, 0
87        lda v4
88        ldarr.obj v3
89        sta.obj v5
90        #call.short IO.printString, v5, v5
91
92        # v6[v2] = v5
93        lda.obj v5
94        starr.obj v6, v2
95
96        inci v2, 1
97        lda v2
98        jmp loop
99    loop_exit:
100        subi 1
101        sta v2
102
103
104    movi v0, 5
105    movi v2, 0
106    ldai 0
107    loop2:
108        jeq v0, loop2_exit
109
110        movi v4, 0
111        lda v4
112        ldarr.obj v6
113        sta.obj v5
114        call.short IO.printString, v5, v5
115
116        inci v2,1
117        lda v2
118        jmp loop2
119    loop2_exit:
120        subi 1
121        sta v2
122    return.void
123}
124