tclbdd

Check-in [28643a8e70]
Login

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

Overview
Comment:Made example code quieter.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:28643a8e70975969765e2398186fe3df8993d9cd
User & Date: kbk 2013-12-21 01:21:02
Context
2013-12-21
03:04
run example quietly check-in: 8da5c0dbfe user: kbk tags: trunk
01:21
Made example code quieter. check-in: 28643a8e70 user: kbk tags: trunk
00:47
Fix problem where a bead pointer was kept across a possible realloc leading to a read of freed memory check-in: 56cfd0fd3f user: kbk tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to examples/loadProgram.tcl.

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
..
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
    }
    return [list $reads $writes $seq]
}
    
proc analyzeProgram {program db} {
    # pass 1 - find variables, resolve labels, calculate domain sizes
    lassign [pass1 $program] vars labels
    puts [list variables: {*}$vars]
    puts [list labels: {*}$labels]
    set stbits [fdbits [llength $program]]
    set vbits [fdbits [dict size $vars]]
    puts "statements need $stbits bits, vars need $vbits bits"

    # Create the program database
    
    bdd::fddd::database create $db \
	[bdd::fddd::concatenate \
	     [bdd::fddd::domain v $vbits bigendian] \
	     [bdd::fddd::interleave \
................................................................................
    
    $db relation reads st v
    $db relation writes st v
    $db relation seq st st2

    # pass 2 - discover 'reads', 'writes', 'seq' relations
    lassign [pass2 $program $vars $labels] reads writes seq
    puts "reads: $reads"
    puts "writes: $writes"
    puts "seq: $seq"

    # TODO - Load incrementally in pass 2
    
    $db load reads $reads
    $db load writes $writes
    $db load seq $seq

    # Return the variable dictionary, since it is not readily recoverable

    return $vars
}







<
<


<







 







<
<
<











72
73
74
75
76
77
78


79
80

81
82
83
84
85
86
87
..
91
92
93
94
95
96
97



98
99
100
101
102
103
104
105
106
107
108
    }
    return [list $reads $writes $seq]
}
    
proc analyzeProgram {program db} {
    # pass 1 - find variables, resolve labels, calculate domain sizes
    lassign [pass1 $program] vars labels


    set stbits [fdbits [llength $program]]
    set vbits [fdbits [dict size $vars]]


    # Create the program database
    
    bdd::fddd::database create $db \
	[bdd::fddd::concatenate \
	     [bdd::fddd::domain v $vbits bigendian] \
	     [bdd::fddd::interleave \
................................................................................
    
    $db relation reads st v
    $db relation writes st v
    $db relation seq st st2

    # pass 2 - discover 'reads', 'writes', 'seq' relations
    lassign [pass2 $program $vars $labels] reads writes seq




    # TODO - Load incrementally in pass 2
    
    $db load reads $reads
    $db load writes $writes
    $db load seq $seq

    # Return the variable dictionary, since it is not readily recoverable

    return $vars
}

Changes to examples/reach.tcl.

1
2
3
4
5

6

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
115
116
117
118
119
120
121

122
123
124
125
126
127
128
...
134
135
136
137
138
139
140

141
142
143
144
145
146
147
148
149
150
source [file join [file dirname [info script]] loadProgram.tcl]

proc profile! {db var} {
    puts "$var: [$db profile $var]"
}

interp alias {} profile {} profile!


source [file join [file dirname [info script]] program1.tcl]

set vars [analyzeProgram $program db]

puts "profiles:"
puts "reads:  [db profile reads]"
puts "writes: [db profile writes]"
puts "seq:    [db profile seq]"

#############################################################################

# PROPOSED OBJECT CODE OF A DATALOG PROGRAM

# flowspast(v,st,st2) means: Control may pass from the end of
# instruction 'st1' to the start of instruction 'st2' without
................................................................................
}]

#############################################################################

# Report on reachability analysis

reachability db

puts [format {%-16s %2s  %-32s %-16s} PRODUCERS {} INSTRUCTIONS CONSUMERS]
set i 0
foreach stmt $program {

    query1 db $i
    set flowsto {}
    db enumerate result q1result {
................................................................................
    query2 db $i
    set flowsfrom {}
    db enumerate result q2result {
	lappend flowsfrom \
	    [lindex $vars [expr {2*[dict get $result v]}]] \
	    [dict get $result st2]
    }

    puts [format "%-16s %2d: %-32s %-16s" \
	      [lsort -stride 2 -index 0 -ascii \
		   [lsort -stride 2 -index 1 -integer $flowsto]] \
	      $i \
	      $stmt \
	      [lsort -stride 2 -index 0 -ascii \
		   [lsort -stride 2 -index 1 -integer $flowsfrom]]]

    incr i
}





>
|
>





|
|
<
|







 







>







 







>










1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
...
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
...
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
source [file join [file dirname [info script]] loadProgram.tcl]

proc profile! {db var} {
    puts "$var: [$db profile $var]"
}

# interp alias {} profile {} profile!
proc profile args {}

source [file join [file dirname [info script]] program1.tcl]

set vars [analyzeProgram $program db]

profile db reads
profile db writes

profile db seq

#############################################################################

# PROPOSED OBJECT CODE OF A DATALOG PROGRAM

# flowspast(v,st,st2) means: Control may pass from the end of
# instruction 'st1' to the start of instruction 'st2' without
................................................................................
}]

#############################################################################

# Report on reachability analysis

reachability db

puts [format {%-16s %2s  %-32s %-16s} PRODUCERS {} INSTRUCTIONS CONSUMERS]
set i 0
foreach stmt $program {

    query1 db $i
    set flowsto {}
    db enumerate result q1result {
................................................................................
    query2 db $i
    set flowsfrom {}
    db enumerate result q2result {
	lappend flowsfrom \
	    [lindex $vars [expr {2*[dict get $result v]}]] \
	    [dict get $result st2]
    }

    puts [format "%-16s %2d: %-32s %-16s" \
	      [lsort -stride 2 -index 0 -ascii \
		   [lsort -stride 2 -index 1 -integer $flowsto]] \
	      $i \
	      $stmt \
	      [lsort -stride 2 -index 0 -ascii \
		   [lsort -stride 2 -index 1 -integer $flowsfrom]]]

    incr i
}