Skip to content

Instantly share code, notes, and snippets.

@solson
Created December 29, 2015 00:17
Show Gist options
  • Save solson/480175dcf7639df69906 to your computer and use it in GitHub Desktop.
Save solson/480175dcf7639df69906 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.38.0 (20140413.2041)
-->
<!-- Title: Mir Pages: 1 -->
<svg width="533pt" height="341pt"
viewBox="0.00 0.00 533.00 341.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 337)">
<title>Mir</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-337 529,-337 529,4 -4,4"/>
<text text-anchor="start" x="171.5" y="-37.8" font-family="monospace" font-size="14.00">fn(a0: usize) &#45;&gt; usize</text>
<text text-anchor="start" x="171.5" y="-22.8" font-family="monospace" font-size="14.00">let v0: usize; // n</text>
<text text-anchor="start" x="171.5" y="-7.8" font-family="monospace" font-size="14.00">let t0: ();</text>
<!-- bb0 -->
<g id="node1" class="node"><title>bb0</title>
<polygon fill="gray" stroke="none" points="142.5,-307.5 142.5,-328.5 256.5,-328.5 256.5,-307.5 142.5,-307.5"/>
<polygon fill="none" stroke="black" points="142.5,-307.5 142.5,-328.5 256.5,-328.5 256.5,-307.5 142.5,-307.5"/>
<text text-anchor="start" x="195" y="-314.3" font-family="monospace" font-size="14.00">0</text>
<polygon fill="none" stroke="black" points="142.5,-286.5 142.5,-307.5 256.5,-307.5 256.5,-286.5 142.5,-286.5"/>
<text text-anchor="start" x="145.5" y="-293.3" font-family="monospace" font-size="14.00">v0 = a0</text>
<polygon fill="none" stroke="black" points="142.5,-265.5 142.5,-286.5 256.5,-286.5 256.5,-265.5 142.5,-265.5"/>
<text text-anchor="start" x="145.5" y="-272.3" font-family="monospace" font-size="14.00">switchInt(v0)</text>
</g>
<!-- bb3 -->
<g id="node4" class="node"><title>bb3</title>
<polygon fill="gray" stroke="none" points="8.5,-185.5 8.5,-206.5 155.5,-206.5 155.5,-185.5 8.5,-185.5"/>
<polygon fill="none" stroke="black" points="8.5,-185.5 8.5,-206.5 155.5,-206.5 155.5,-185.5 8.5,-185.5"/>
<text text-anchor="start" x="77.5" y="-192.3" font-family="monospace" font-size="14.00">3</text>
<polygon fill="none" stroke="black" points="8.5,-164.5 8.5,-185.5 155.5,-185.5 155.5,-164.5 8.5,-164.5"/>
<text text-anchor="start" x="11.5" y="-171.3" font-family="monospace" font-size="14.00">ReturnPointer = 3</text>
<polygon fill="none" stroke="black" points="8.5,-143.5 8.5,-164.5 155.5,-164.5 155.5,-143.5 8.5,-143.5"/>
<text text-anchor="start" x="11.5" y="-150.3" font-family="monospace" font-size="14.00">goto</text>
</g>
<!-- bb0&#45;&gt;bb3 -->
<g id="edge1" class="edge"><title>bb0&#45;&gt;bb3</title>
<path fill="none" stroke="black" d="M134.062,-269.532C122.703,-262.549 111.871,-254.086 103.5,-244 97.9556,-237.319 93.7967,-229.205 90.6807,-220.951"/>
<polygon fill="black" stroke="black" points="93.9439,-219.671 87.4812,-211.276 87.2979,-221.869 93.9439,-219.671"/>
<text text-anchor="middle" x="108" y="-232.8" font-family="monospace" font-size="14.00">5</text>
</g>
<!-- bb0&#45;&gt;bb3 -->
<g id="edge2" class="edge"><title>bb0&#45;&gt;bb3</title>
<path fill="none" stroke="black" d="M158.442,-261.961C151.961,-256.117 145.443,-249.997 139.5,-244 131.756,-236.186 123.833,-227.497 116.429,-219.024"/>
<polygon fill="black" stroke="black" points="118.978,-216.621 109.796,-211.335 113.678,-221.193 118.978,-216.621"/>
<text text-anchor="middle" x="148" y="-232.8" font-family="monospace" font-size="14.00">10</text>
</g>
<!-- bb0&#45;&gt;bb3 -->
<g id="edge3" class="edge"><title>bb0&#45;&gt;bb3</title>
<path fill="none" stroke="black" d="M181.129,-261.995C174.251,-250.784 165.821,-238.735 156.5,-229 152.722,-225.054 148.606,-221.22 144.311,-217.541"/>
<polygon fill="black" stroke="black" points="146.38,-214.712 136.422,-211.094 141.95,-220.132 146.38,-214.712"/>
<text text-anchor="middle" x="176" y="-232.8" font-family="monospace" font-size="14.00">15</text>
</g>
<!-- bb4 -->
<g id="node5" class="node"><title>bb4</title>
<polygon fill="gray" stroke="none" points="189.5,-185.5 189.5,-206.5 336.5,-206.5 336.5,-185.5 189.5,-185.5"/>
<polygon fill="none" stroke="black" points="189.5,-185.5 189.5,-206.5 336.5,-206.5 336.5,-185.5 189.5,-185.5"/>
<text text-anchor="start" x="258.5" y="-192.3" font-family="monospace" font-size="14.00">4</text>
<polygon fill="none" stroke="black" points="189.5,-164.5 189.5,-185.5 336.5,-185.5 336.5,-164.5 189.5,-164.5"/>
<text text-anchor="start" x="192.5" y="-171.3" font-family="monospace" font-size="14.00">ReturnPointer = 2</text>
<polygon fill="none" stroke="black" points="189.5,-143.5 189.5,-164.5 336.5,-164.5 336.5,-143.5 189.5,-143.5"/>
<text text-anchor="start" x="192.5" y="-150.3" font-family="monospace" font-size="14.00">goto</text>
</g>
<!-- bb0&#45;&gt;bb4 -->
<g id="edge4" class="edge"><title>bb0&#45;&gt;bb4</title>
<path fill="none" stroke="black" d="M208.898,-261.956C212.471,-251.098 217.026,-239.27 222.5,-229 224.218,-225.777 226.128,-222.542 228.157,-219.35"/>
<polygon fill="black" stroke="black" points="231.074,-221.283 233.749,-211.031 225.265,-217.377 231.074,-221.283"/>
<text text-anchor="middle" x="231" y="-232.8" font-family="monospace" font-size="14.00">20</text>
</g>
<!-- bb0&#45;&gt;bb4 -->
<g id="edge5" class="edge"><title>bb0&#45;&gt;bb4</title>
<path fill="none" stroke="black" d="M228.251,-261.969C232.351,-256.174 236.266,-250.067 239.5,-244 243.392,-236.699 246.819,-228.61 249.759,-220.642"/>
<polygon fill="black" stroke="black" points="253.118,-221.638 253.102,-211.044 246.508,-219.336 253.118,-221.638"/>
<text text-anchor="middle" x="254" y="-232.8" font-family="monospace" font-size="14.00">30</text>
</g>
<!-- bb5 -->
<g id="node6" class="node"><title>bb5</title>
<polygon fill="gray" stroke="none" points="370.5,-185.5 370.5,-206.5 517.5,-206.5 517.5,-185.5 370.5,-185.5"/>
<polygon fill="none" stroke="black" points="370.5,-185.5 370.5,-206.5 517.5,-206.5 517.5,-185.5 370.5,-185.5"/>
<text text-anchor="start" x="439.5" y="-192.3" font-family="monospace" font-size="14.00">5</text>
<polygon fill="none" stroke="black" points="370.5,-164.5 370.5,-185.5 517.5,-185.5 517.5,-164.5 370.5,-164.5"/>
<text text-anchor="start" x="373.5" y="-171.3" font-family="monospace" font-size="14.00">ReturnPointer = 1</text>
<polygon fill="none" stroke="black" points="370.5,-143.5 370.5,-164.5 517.5,-164.5 517.5,-143.5 370.5,-143.5"/>
<text text-anchor="start" x="373.5" y="-150.3" font-family="monospace" font-size="14.00">goto</text>
</g>
<!-- bb0&#45;&gt;bb5 -->
<g id="edge6" class="edge"><title>bb0&#45;&gt;bb5</title>
<path fill="none" stroke="black" d="M264.567,-264.5C295.019,-249.523 331.572,-231.546 363.68,-215.756"/>
<polygon fill="black" stroke="black" points="365.62,-218.702 373.049,-211.148 362.53,-212.421 365.62,-218.702"/>
<text text-anchor="middle" x="373" y="-232.8" font-family="monospace" font-size="14.00">otherwise</text>
</g>
<!-- bb1 -->
<g id="node2" class="node"><title>bb1</title>
<polygon fill="gray" stroke="none" points="234.5,-78 234.5,-99 290.5,-99 290.5,-78 234.5,-78"/>
<polygon fill="none" stroke="black" points="234.5,-78 234.5,-99 290.5,-99 290.5,-78 234.5,-78"/>
<text text-anchor="start" x="258" y="-84.8" font-family="monospace" font-size="14.00">1</text>
<polygon fill="none" stroke="black" points="234.5,-57 234.5,-78 290.5,-78 290.5,-57 234.5,-57"/>
<text text-anchor="start" x="237.5" y="-63.8" font-family="monospace" font-size="14.00">return</text>
</g>
<!-- bb2 -->
<g id="node3" class="node"><title>bb2</title>
<polygon fill="gray" stroke="none" points="290.5,-297.5 290.5,-318.5 354.5,-318.5 354.5,-297.5 290.5,-297.5"/>
<polygon fill="none" stroke="black" points="290.5,-297.5 290.5,-318.5 354.5,-318.5 354.5,-297.5 290.5,-297.5"/>
<text text-anchor="start" x="318" y="-304.3" font-family="monospace" font-size="14.00">2</text>
<polygon fill="none" stroke="black" points="290.5,-276.5 290.5,-297.5 354.5,-297.5 354.5,-276.5 290.5,-276.5"/>
<text text-anchor="start" x="293.5" y="-283.3" font-family="monospace" font-size="14.00">diverge</text>
</g>
<!-- bb3&#45;&gt;bb1 -->
<g id="edge7" class="edge"><title>bb3&#45;&gt;bb1</title>
<path fill="none" stroke="black" d="M147.101,-139.887C170.367,-127.612 196.014,-114.08 217.209,-102.897"/>
<polygon fill="black" stroke="black" points="219.092,-105.86 226.304,-98.0981 215.826,-99.6691 219.092,-105.86"/>
</g>
<!-- bb4&#45;&gt;bb1 -->
<g id="edge8" class="edge"><title>bb4&#45;&gt;bb1</title>
<path fill="none" stroke="black" d="M262.5,-139.752C262.5,-131.107 262.5,-121.847 262.5,-113.228"/>
<polygon fill="black" stroke="black" points="266,-113.116 262.5,-103.116 259,-113.116 266,-113.116"/>
</g>
<!-- bb5&#45;&gt;bb1 -->
<g id="edge9" class="edge"><title>bb5&#45;&gt;bb1</title>
<path fill="none" stroke="black" d="M377.899,-139.887C354.633,-127.612 328.986,-114.08 307.791,-102.897"/>
<polygon fill="black" stroke="black" points="309.174,-99.6691 298.696,-98.0981 305.908,-105.86 309.174,-99.6691"/>
</g>
</g>
</svg>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#![feature(rustc_attrs)]
#![allow(dead_code)]
#[rustc_mir(graphviz = "empty.dot")]
fn empty() {}
#[rustc_mir(graphviz = "constant.dot")]
fn constant() -> i32 {
42
}
#[rustc_mir(graphviz = "increment.dot")]
fn increment(x: i32) -> i32 {
x + 1
}
#[rustc_mir(graphviz = "factorial_recursive.dot")]
fn factorial_recursive(n: usize) -> usize {
if n == 0 {
1
} else {
n * factorial_recursive(n - 1)
}
}
#[rustc_mir(graphviz = "factorial_iterative.dot")]
fn factorial_iterative(n: usize) -> usize {
let mut prod = 1;
for x in 1..n {
prod *= x;
}
prod
}
#[rustc_mir(graphviz = "factorial_fold.dot")]
fn factorial_fold(n: usize) -> usize {
(1..n).fold(1, |prod, x| prod * x)
}
#[rustc_mir(graphviz = "wat.dot")]
fn wat(n: usize) -> usize {
let mut prod = 1;
(1..n).fold((), |(), x| { prod *= x; });
prod
}
#[rustc_mir(graphviz = "multi_switch.dot")]
fn multi_switch(n: usize) -> usize {
match n {
5 | 10 | 15 => 3,
20 | 30 => 2,
_ => 1,
}
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment