TC-6 Scheduling Samples
Once your eseq
and call
canonicalized, normalize
cjump
s: they must be followed by their “false” label. This
goes in two steps:
- 1.Split in basic blocks.
A basic block is a sequence of code starting with a label, ending with a jump (conditional or not), and with no jumps, no labels inside.
- 2.Build the traces.
Now put all the basic blocks into a single sequence.
The following example highlights the need for new labels: at least one for the entry point, and one for the exit point.
1 & 2
$ tc -L 1-and-2.tig
/* == Low Level Intermediate representation. == */
# Routine: _main
label main
# Prologue
# Body
seq
label l3
cjump ne
const 1
const 0
name l0
name l1
label l1
label l2
jump
name l4
label l0
jump
name l2
label l4
seq end
# Epilogue
label end
$ echo $?
0
The following example contains many jumps. Compare the HIR to the LIR.
while 10 | 20 do if 30 | 40 then break else break
$ tc -H broken-while.tig
/* == High Level Intermediate representation. == */
# Routine: _main
label main
# Prologue
# Body
seq
seq
label l1
seq
cjump ne
const 10
const 0
name l3
name l4
label l3
cjump ne
const 1
const 0
name l2
name l0
label l4
cjump ne
const 20
const 0
name l2
name l0
seq end
label l2
seq
seq
cjump ne
const 30
const 0
name l8
name l9
label l8
cjump ne
const 1
const 0
name l5
name l6
label l9
cjump ne
const 40
const 0
name l5
name l6
seq end
label l5
jump
name l0
jump
name l7
label l6
jump
name l0
label l7
seq end
jump
name l1
label l0
seq end
sxp
const 0
seq end
# Epilogue
label end
$ echo $?
0
$ tc -L broken-while.tig
/* == Low Level Intermediate representation. == */
# Routine: _main
label main
# Prologue
# Body
seq
label l10
label l1
cjump ne
const 10
const 0
name l3
name l4
label l4
cjump ne
const 20
const 0
name l2
name l0
label l0
jump
name l11
label l2
cjump ne
const 30
const 0
name l8
name l9
label l9
cjump ne
const 40
const 0
name l5
name l6
label l6
jump
name l0
label l5
jump
name l0
label l8
cjump ne
const 1
const 0
name l5
name l13
label l13
jump
name l6
label l3
cjump ne
const 1
const 0
name l2
name l14
label l14
jump
name l0
label l11
seq end
# Epilogue
label end
$ echo $?
0