@@ -89,7 +89,7 @@ func (term *TermRet) LLString() string {
89
89
// TermBr is an unconditional LLVM IR br terminator.
90
90
type TermBr struct {
91
91
// Target branch.
92
- Target * Block
92
+ Target value. Value // *ir. Block
93
93
94
94
// extra.
95
95
@@ -109,7 +109,7 @@ func NewBr(target *Block) *TermBr {
109
109
func (term * TermBr ) Succs () []* Block {
110
110
// Cache successors if not present.
111
111
if term .Successors == nil {
112
- term .Successors = []* Block {term .Target }
112
+ term .Successors = []* Block {term .Target .( * Block ) }
113
113
}
114
114
return term .Successors
115
115
}
@@ -132,9 +132,9 @@ type TermCondBr struct {
132
132
// Branching condition.
133
133
Cond value.Value
134
134
// True condition target branch.
135
- TargetTrue * Block
135
+ TargetTrue value. Value // *ir. Block
136
136
// False condition target branch.
137
- TargetFalse * Block
137
+ TargetFalse value. Value // *ir. Block
138
138
139
139
// extra.
140
140
@@ -154,7 +154,7 @@ func NewCondBr(cond value.Value, targetTrue, targetFalse *Block) *TermCondBr {
154
154
func (term * TermCondBr ) Succs () []* Block {
155
155
// Cache successors if not present.
156
156
if term .Successors == nil {
157
- term .Successors = []* Block {term .TargetTrue , term .TargetFalse }
157
+ term .Successors = []* Block {term .TargetTrue .( * Block ) , term .TargetFalse .( * Block ) }
158
158
}
159
159
return term .Successors
160
160
}
@@ -178,7 +178,7 @@ type TermSwitch struct {
178
178
// Control variable.
179
179
X value.Value
180
180
// Default target branch.
181
- TargetDefault * Block
181
+ TargetDefault value. Value // *ir. Block
182
182
// Switch cases.
183
183
Cases []* Case
184
184
@@ -201,9 +201,9 @@ func (term *TermSwitch) Succs() []*Block {
201
201
// Cache successors if not present.
202
202
if term .Successors == nil {
203
203
succs := make ([]* Block , 0 , 1 + len (term .Cases ))
204
- succs = append (succs , term .TargetDefault )
204
+ succs = append (succs , term .TargetDefault .( * Block ) )
205
205
for _ , c := range term .Cases {
206
- succs = append (succs , c .Target )
206
+ succs = append (succs , c .Target .( * Block ) )
207
207
}
208
208
term .Successors = succs
209
209
}
@@ -231,9 +231,9 @@ func (term *TermSwitch) LLString() string {
231
231
// Case is a switch case.
232
232
type Case struct {
233
233
// Case comparand.
234
- X constant. Constant // integer constant or integer constant expression
234
+ X value. Value // constant.Constant ( integer constant or integer constant expression)
235
235
// Case target branch.
236
- Target * Block
236
+ Target value. Value // *ir. Block
237
237
}
238
238
239
239
// NewCase returns a new switch case based on the given case comparand and
@@ -255,10 +255,12 @@ type TermIndirectBr struct {
255
255
// Target address.
256
256
Addr value.Value // blockaddress
257
257
// Set of valid target basic blocks.
258
- ValidTargets []* Block
258
+ ValidTargets []value. Value // slice of *ir. Block
259
259
260
260
// extra.
261
261
262
+ // Successor basic blocks of the terminator.
263
+ Successors []* Block
262
264
// (optional) Metadata.
263
265
Metadata
264
266
}
@@ -267,12 +269,24 @@ type TermIndirectBr struct {
267
269
// address (derived from a blockaddress constant) and set of valid target basic
268
270
// blocks.
269
271
func NewIndirectBr (addr constant.Constant , validTargets ... * Block ) * TermIndirectBr {
270
- return & TermIndirectBr {Addr : addr , ValidTargets : validTargets }
272
+ // convert validTargets slice to []value.Value.
273
+ var targets []value.Value
274
+ for _ , target := range validTargets {
275
+ targets = append (targets , target )
276
+ }
277
+ return & TermIndirectBr {Addr : addr , ValidTargets : targets }
271
278
}
272
279
273
280
// Succs returns the successor basic blocks of the terminator.
274
281
func (term * TermIndirectBr ) Succs () []* Block {
275
- return term .ValidTargets
282
+ // Cache successors if not present.
283
+ if term .Successors == nil {
284
+ // convert ValidTargets slice to []*ir.Block.
285
+ for _ , target := range term .ValidTargets {
286
+ term .Successors = append (term .Successors , target .(* Block ))
287
+ }
288
+ }
289
+ return term .Successors
276
290
}
277
291
278
292
// LLString returns the LLVM syntax representation of the terminator.
@@ -310,9 +324,9 @@ type TermInvoke struct {
310
324
// TODO: add metadata value?
311
325
Args []value.Value
312
326
// Normal control flow return point.
313
- Normal * Block
327
+ Normal value. Value // *ir. Block
314
328
// Exception control flow return point.
315
- Exception * Block
329
+ Exception value. Value // *ir. Block
316
330
317
331
// extra.
318
332
@@ -366,7 +380,7 @@ func (term *TermInvoke) Type() types.Type {
366
380
func (term * TermInvoke ) Succs () []* Block {
367
381
// Cache successors if not present.
368
382
if term .Successors == nil {
369
- term .Successors = []* Block {term .Normal , term .Exception }
383
+ term .Successors = []* Block {term .Normal .( * Block ) , term .Exception .( * Block ) }
370
384
}
371
385
return term .Successors
372
386
}
@@ -454,9 +468,9 @@ type TermCallBr struct {
454
468
// TODO: add metadata value?
455
469
Args []value.Value
456
470
// Normal control flow return point.
457
- Normal * Block
471
+ Normal value. Value // *ir. Block
458
472
// Other control flow return points.
459
- Others []* Block
473
+ Others []value. Value // slice of *ir. Block
460
474
461
475
// extra.
462
476
@@ -484,7 +498,12 @@ type TermCallBr struct {
484
498
//
485
499
// TODO: specify the set of underlying types of callee.
486
500
func NewCallBr (callee value.Value , args []value.Value , normal * Block , others ... * Block ) * TermCallBr {
487
- term := & TermCallBr {Callee : callee , Args : args , Normal : normal , Others : others }
501
+ // convert others slice to []value.Value.
502
+ var os []value.Value
503
+ for _ , other := range others {
504
+ os = append (os , other )
505
+ }
506
+ term := & TermCallBr {Callee : callee , Args : args , Normal : normal , Others : os }
488
507
// Compute type.
489
508
term .Type ()
490
509
return term
@@ -510,8 +529,11 @@ func (term *TermCallBr) Type() types.Type {
510
529
func (term * TermCallBr ) Succs () []* Block {
511
530
// Cache successors if not present.
512
531
if term .Successors == nil {
513
- term .Successors = []* Block {term .Normal }
514
- term .Successors = append (term .Successors , term .Others ... )
532
+ term .Successors = []* Block {term .Normal .(* Block )}
533
+ // convert others slice to []*ir.Block.
534
+ for _ , other := range term .Others {
535
+ term .Successors = append (term .Successors , other .(* Block ))
536
+ }
515
537
}
516
538
return term .Successors
517
539
}
@@ -633,11 +655,13 @@ type TermCatchSwitch struct {
633
655
// Name of local variable associated with the result.
634
656
LocalIdent
635
657
// Exception scope.
636
- Scope ExceptionScope // TODO: rename to Parent? rename to From?
658
+ // TODO: rename to Parent? rename to From?
659
+ Scope value.Value // ir.ExceptionScope
637
660
// Exception handlers.
638
- Handlers []* Block
661
+ Handlers []value. Value // []*ir. Block
639
662
// Unwind target; basic block or caller function.
640
- UnwindTarget UnwindTarget // TODO: rename to To? rename to DefaultTarget?
663
+ // TODO: rename to To? rename to DefaultTarget?
664
+ UnwindTarget value.Value // ir.UnwindTarget
641
665
642
666
// extra.
643
667
@@ -650,7 +674,12 @@ type TermCatchSwitch struct {
650
674
// NewCatchSwitch returns a new catchswitch terminator based on the given
651
675
// exception scope, exception handlers and unwind target.
652
676
func NewCatchSwitch (scope ExceptionScope , handlers []* Block , unwindTarget UnwindTarget ) * TermCatchSwitch {
653
- return & TermCatchSwitch {Scope : scope , Handlers : handlers , UnwindTarget : unwindTarget }
677
+ // convert handlers slice to []value.Value.
678
+ var hs []value.Value
679
+ for _ , handler := range handlers {
680
+ hs = append (hs , handler )
681
+ }
682
+ return & TermCatchSwitch {Scope : scope , Handlers : hs , UnwindTarget : unwindTarget }
654
683
}
655
684
656
685
// String returns the LLVM syntax representation of the terminator as a type-
@@ -668,10 +697,12 @@ func (term *TermCatchSwitch) Type() types.Type {
668
697
func (term * TermCatchSwitch ) Succs () []* Block {
669
698
// Cache successors if not present.
670
699
if term .Successors == nil {
700
+ // convert Handlers slice to []*ir.Block.
701
+ for _ , handler := range term .Handlers {
702
+ term .Successors = append (term .Successors , handler .(* Block ))
703
+ }
671
704
if unwindTarget , ok := term .UnwindTarget .(* Block ); ok {
672
- term .Successors = append (term .Handlers , unwindTarget )
673
- } else {
674
- term .Successors = term .Handlers
705
+ term .Successors = append (term .Successors , unwindTarget )
675
706
}
676
707
}
677
708
return term .Successors
@@ -703,9 +734,9 @@ func (term *TermCatchSwitch) LLString() string {
703
734
// TermCatchRet is an LLVM IR catchret terminator.
704
735
type TermCatchRet struct {
705
736
// Exit catchpad.
706
- From * InstCatchPad
737
+ From value. Value // *ir. InstCatchPad
707
738
// Target basic block to transfer control flow to.
708
- To * Block
739
+ To value. Value // *ir. Block
709
740
710
741
// extra.
711
742
@@ -725,7 +756,7 @@ func NewCatchRet(from *InstCatchPad, to *Block) *TermCatchRet {
725
756
func (term * TermCatchRet ) Succs () []* Block {
726
757
// Cache successors if not present.
727
758
if term .Successors == nil {
728
- term .Successors = []* Block {term .To }
759
+ term .Successors = []* Block {term .To .( * Block ) }
729
760
}
730
761
return term .Successors
731
762
}
@@ -747,9 +778,9 @@ func (term *TermCatchRet) LLString() string {
747
778
// TermCleanupRet is an LLVM IR cleanupret terminator.
748
779
type TermCleanupRet struct {
749
780
// Exit cleanuppad.
750
- From * InstCleanupPad
781
+ From value. Value // *ir. InstCleanupPad
751
782
// Unwind target; basic block or caller function.
752
- UnwindTarget UnwindTarget
783
+ UnwindTarget value. Value // ir. UnwindTarget
753
784
754
785
// extra.
755
786
0 commit comments