Check-in [2e3b3ea76f]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add 'buiilder.tcl' inadvertently omitted from previous commit
Timelines: family | ancestors | descendants | both | notworking | kbk-refactor-varargs
Files: files | file ages | folders
SHA3-256: 2e3b3ea76fb44c4db84341934f870b8e4c4e90aca0e5271ad2ae390165f5dcad
User & Date: kbk 2018-12-27 19:47:15.827
Context
2019-01-13
15:38
Merge the (not-working) vararg reform branch. It appears that both these tasks need to be attacked at the same time because the changes are tightly interwoven. check-in: 05c93c9cc5 user: kbk tags: notworking, kbk-refactor-callframe
2018-12-27
19:47
Add 'buiilder.tcl' inadvertently omitted from previous commit Closed-Leaf check-in: 2e3b3ea76f user: kbk tags: notworking, kbk-refactor-varargs
19:44
Very rough beginning of a refactored 'varargs' pass check-in: 7c9d400e5e user: kbk tags: notworking, kbk-refactor-varargs
Changes
Unified Diff Ignore Whitespace Patch
Added quadcode/builder.tcl.






































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# builder.tcl --
#
#	Class that allows for building new quadcode inside a
#	quadcode::transformer.
#
# Copyright (c) 2018 by Kevin B. Kenny
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# Some passes that modify quadcode do fairly extensive code rewriting, and
# it's convenient have procedures to track these and allow access at a level
# closer to an 'assembly language'. This class contains convenience methods
# to allow automatic tracking of variable uses and defs, named temporaries,
# and named basic blocks.
#
#------------------------------------------------------------------------------

# quadcode::builder --
#
#	Class with support methods for building quadcode.
#
oo::class create quadcode::builder {

    variable xfmr;		# quadcode::transformer object containing
    ;				# the quadcode of interest.

    variable b;			# Basic block number under construction

    variable bb;		# Content of the basic block under construction

    variable bbindex;		# Dictionary whose keys are the names of
    ;				# basic blocks and whose values are the
    ;				# basic block numbers.

    variable varindex;		# Dictionary whose keys are named variables
    ;				# and whose values are the SSA names of the
    ;				# variables.
}

# quadcode::builder constructor --
#
#	Makes a quadcode::builder to allow for assembling quadcode.
#
# Parameters:
#	xfmr - quadcode::transformer object containing the subprogram
#	b - Basic block number under construction
#	bb - Basic block content of the block under construction

oo::define quadcode::builder constructor {xfmr_ b_ bb_} {
    set xfmr $xfmr_
    set b $b_
    set bb $bb_
    set bbindex {}
    set varindex {}
}

# quadcode::builder maketemp --
#
#	Makes a temporary variable.
#
# Parameters:
#	name - Base name for the temporary.
#
# Results:
#	Returns the name of the constructed temporary.
#
# Side effects:
#	Stores the name as the most recent instance of the temporary.

oo::define quadcode::builder method maketemp {name} {
    set ssaname [$xfmr newVarInstance [list temp @$name]]
    dict set varindex $name $ssaname
    return $ssaname
}

# quadcode::builder method emit --
#
#	Emits an instruction into the basic block under construction.
#
# Parameters:
#	q - Quadcode instruction to emit
#
# Results:
#	None.
#
# Side effects:
#	Appends the instruction to the basic bnlock under construction.
#	If the instruction is a jump, adds the basic block predecessor
#	relationship. If the instruction is an assignment, updates the
#	ud-chain of the assigned variable. Updates the du-chains of all
#	variables used oin the instruction.

oo::define quadcode::builder method emit {q} {

    # Split the instruction
    lassign $q opcode res argl

    # Handle the result
    switch -exact -- [lindex $res 0] {
        "bb" {

	    # Instruction is a jump, link the basic block to the jump target
            $xfmr bblink $b [lindex $res 1]
        }
        "temp" - "var" {

	    # Instrtuction is an assignment, update the ud-chain.
            dict set udchain $res $b
        }
    }

    # Handle the arguments
    foreach arg [lrange $q 2 end] {
        switch -exact -- [lindex $arg 0] {
            "temp" - "var" {

		# Argument is an SSA value, update the du-chain.
		$xfmr addUse $arg $b
            }
        }
    }

    # Add the instruction to the block
    lappend bb $q

    return
}

# quadcode::builder method bb --
#
#	Returns the content of the basic block under construction.
#
# Results:
#	Returns the instructions.

oo::define quadcode::builder method bb {} {
    return $bb
}

# Local Variables:
# mode: tcl
# fill-column: 78
# auto-fill-function: nil
# buffer-file-coding-system: utf-8-unix
# indent-tabs-mode: nil
# End: