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
<?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="488pt" height="669pt"
viewBox="0.00 0.00 488.00 669.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 665)">
<title>Mir</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-665 484,-665 484,4 -4,4"/>
<text text-anchor="start" x="149" y="-127.8" font-family="monospace" font-size="14.00">fn(a0: usize) &#45;&gt; usize</text>
<text text-anchor="start" x="149" y="-112.8" font-family="monospace" font-size="14.00">let v0: usize; // n</text>
<text text-anchor="start" x="149" y="-97.8" font-family="monospace" font-size="14.00">let t0: ();</text>
<text text-anchor="start" x="149" y="-82.8" font-family="monospace" font-size="14.00">let t1: bool;</text>
<text text-anchor="start" x="149" y="-67.8" font-family="monospace" font-size="14.00">let t2: usize;</text>
<text text-anchor="start" x="149" y="-52.8" font-family="monospace" font-size="14.00">let t3: usize;</text>
<text text-anchor="start" x="149" y="-37.8" font-family="monospace" font-size="14.00">let t4: usize;</text>
<text text-anchor="start" x="149" y="-22.8" font-family="monospace" font-size="14.00">let t5: usize;</text>
<text text-anchor="start" x="149" y="-7.8" font-family="monospace" font-size="14.00">let t6: usize;</text>
<!-- bb0 -->
<g id="node1" class="node"><title>bb0</title>
<polygon fill="gray" stroke="none" points="73.5,-635.5 73.5,-656.5 195.5,-656.5 195.5,-635.5 73.5,-635.5"/>
<polygon fill="none" stroke="black" points="73.5,-635.5 73.5,-656.5 195.5,-656.5 195.5,-635.5 73.5,-635.5"/>
<text text-anchor="start" x="130" y="-642.3" font-family="monospace" font-size="14.00">0</text>
<polygon fill="none" stroke="black" points="73.5,-584.5 73.5,-635.5 195.5,-635.5 195.5,-584.5 73.5,-584.5"/>
<text text-anchor="start" x="76.5" y="-621.3" font-family="monospace" font-size="14.00">v0 = a0</text>
<text text-anchor="start" x="76.5" y="-606.3" font-family="monospace" font-size="14.00">t2 = v0</text>
<text text-anchor="start" x="76.5" y="-591.3" font-family="monospace" font-size="14.00">t1 = Eq(t2, 0)</text>
<polygon fill="none" stroke="black" points="73.5,-563.5 73.5,-584.5 195.5,-584.5 195.5,-563.5 73.5,-563.5"/>
<text text-anchor="start" x="76.5" y="-570.3" font-family="monospace" font-size="14.00">if(t1)</text>
</g>
<!-- bb3 -->
<g id="node4" class="node"><title>bb3</title>
<polygon fill="gray" stroke="none" points="8.5,-364.5 8.5,-385.5 155.5,-385.5 155.5,-364.5 8.5,-364.5"/>
<polygon fill="none" stroke="black" points="8.5,-364.5 8.5,-385.5 155.5,-385.5 155.5,-364.5 8.5,-364.5"/>
<text text-anchor="start" x="77.5" y="-371.3" font-family="monospace" font-size="14.00">3</text>
<polygon fill="none" stroke="black" points="8.5,-343.5 8.5,-364.5 155.5,-364.5 155.5,-343.5 8.5,-343.5"/>
<text text-anchor="start" x="11.5" y="-350.3" font-family="monospace" font-size="14.00">ReturnPointer = 1</text>
<polygon fill="none" stroke="black" points="8.5,-322.5 8.5,-343.5 155.5,-343.5 155.5,-322.5 8.5,-322.5"/>
<text text-anchor="start" x="11.5" y="-329.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="M115.52,-559.977C109.966,-543.913 104.358,-525.879 100.5,-509 92.2491,-472.898 87.3739,-431.146 84.6319,-400.309"/>
<polygon fill="black" stroke="black" points="88.1151,-399.961 83.7819,-390.293 81.1401,-400.553 88.1151,-399.961"/>
<text text-anchor="middle" x="126.5" y="-530.8" font-family="monospace" font-size="14.00">true</text>
</g>
<!-- bb4 -->
<g id="node5" class="node"><title>bb4</title>
<polygon fill="gray" stroke="none" points="117.5,-483.5 117.5,-504.5 355.5,-504.5 355.5,-483.5 117.5,-483.5"/>
<polygon fill="none" stroke="black" points="117.5,-483.5 117.5,-504.5 355.5,-504.5 355.5,-483.5 117.5,-483.5"/>
<text text-anchor="start" x="232" y="-490.3" font-family="monospace" font-size="14.00">4</text>
<polygon fill="none" stroke="black" points="117.5,-432.5 117.5,-483.5 355.5,-483.5 355.5,-432.5 117.5,-432.5"/>
<text text-anchor="start" x="120.5" y="-469.3" font-family="monospace" font-size="14.00">t3 = v0</text>
<text text-anchor="start" x="120.5" y="-454.3" font-family="monospace" font-size="14.00">t6 = v0</text>
<text text-anchor="start" x="120.5" y="-439.3" font-family="monospace" font-size="14.00">t5 = Sub(t6, 1)</text>
<polygon fill="none" stroke="black" points="117.5,-411.5 117.5,-432.5 355.5,-432.5 355.5,-411.5 117.5,-411.5"/>
<text text-anchor="start" x="120.5" y="-418.3" font-family="monospace" font-size="14.00">t4 = factorial_recursive(t5)</text>
</g>
<!-- bb0&#45;&gt;bb4 -->
<g id="edge2" class="edge"><title>bb0&#45;&gt;bb4</title>
<path fill="none" stroke="black" d="M168.181,-559.969C177.36,-546.471 187.387,-531.725 196.863,-517.789"/>
<polygon fill="black" stroke="black" points="199.951,-519.473 202.68,-509.235 194.163,-515.537 199.951,-519.473"/>
<text text-anchor="middle" x="210.5" y="-530.8" font-family="monospace" font-size="14.00">false</text>
</g>
<!-- bb1 -->
<g id="node2" class="node"><title>bb1</title>
<polygon fill="gray" stroke="none" points="141.5,-168 141.5,-189 197.5,-189 197.5,-168 141.5,-168"/>
<polygon fill="none" stroke="black" points="141.5,-168 141.5,-189 197.5,-189 197.5,-168 141.5,-168"/>
<text text-anchor="start" x="165" y="-174.8" font-family="monospace" font-size="14.00">1</text>
<polygon fill="none" stroke="black" points="141.5,-147 141.5,-168 197.5,-168 197.5,-147 141.5,-147"/>
<text text-anchor="start" x="144.5" y="-153.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="144.5,-265.5 144.5,-286.5 208.5,-286.5 208.5,-265.5 144.5,-265.5"/>
<polygon fill="none" stroke="black" points="144.5,-265.5 144.5,-286.5 208.5,-286.5 208.5,-265.5 144.5,-265.5"/>
<text text-anchor="start" x="172" y="-272.3" font-family="monospace" font-size="14.00">2</text>
<polygon fill="none" stroke="black" points="144.5,-244.5 144.5,-265.5 208.5,-265.5 208.5,-244.5 144.5,-244.5"/>
<text text-anchor="start" x="147.5" y="-251.3" font-family="monospace" font-size="14.00">diverge</text>
</g>
<!-- bb3&#45;&gt;bb1 -->
<g id="edge3" class="edge"><title>bb3&#45;&gt;bb1</title>
<path fill="none" stroke="black" d="M91.8202,-318.987C99.9907,-293.667 112.504,-258.822 127.5,-230 132.537,-220.319 138.851,-210.352 145.041,-201.353"/>
<polygon fill="black" stroke="black" points="147.986,-203.251 150.892,-193.063 142.267,-199.215 147.986,-203.251"/>
</g>
<!-- bb4&#45;&gt;bb2 -->
<g id="edge5" class="edge"><title>bb4&#45;&gt;bb2</title>
<path fill="none" stroke="black" d="M220.892,-407.816C210.301,-374.099 196.573,-330.398 187.205,-300.577"/>
<polygon fill="black" stroke="black" points="190.422,-299.139 184.085,-290.647 183.743,-301.236 190.422,-299.139"/>
<text text-anchor="middle" x="239.5" y="-350.8" font-family="monospace" font-size="14.00">unwind</text>
</g>
<!-- bb5 -->
<g id="node6" class="node"><title>bb5</title>
<polygon fill="gray" stroke="none" points="243.5,-275.5 243.5,-296.5 472.5,-296.5 472.5,-275.5 243.5,-275.5"/>
<polygon fill="none" stroke="black" points="243.5,-275.5 243.5,-296.5 472.5,-296.5 472.5,-275.5 243.5,-275.5"/>
<text text-anchor="start" x="353.5" y="-282.3" font-family="monospace" font-size="14.00">5</text>
<polygon fill="none" stroke="black" points="243.5,-254.5 243.5,-275.5 472.5,-275.5 472.5,-254.5 243.5,-254.5"/>
<text text-anchor="start" x="246.5" y="-261.3" font-family="monospace" font-size="14.00">ReturnPointer = Mul(t3, t4)</text>
<polygon fill="none" stroke="black" points="243.5,-233.5 243.5,-254.5 472.5,-254.5 472.5,-233.5 243.5,-233.5"/>
<text text-anchor="start" x="246.5" y="-240.3" font-family="monospace" font-size="14.00">goto</text>
</g>
<!-- bb4&#45;&gt;bb5 -->
<g id="edge4" class="edge"><title>bb4&#45;&gt;bb5</title>
<path fill="none" stroke="black" d="M267.975,-407.816C287.203,-377.464 311.557,-339.021 330.008,-309.896"/>
<polygon fill="black" stroke="black" points="333.137,-311.497 335.532,-301.176 327.224,-307.75 333.137,-311.497"/>
<text text-anchor="middle" x="346.5" y="-350.8" font-family="monospace" font-size="14.00">return</text>
</g>
<!-- bb5&#45;&gt;bb1 -->
<g id="edge6" class="edge"><title>bb5&#45;&gt;bb1</title>
<path fill="none" stroke="black" d="M289.362,-229.887C264.425,-217.22 236.856,-203.215 214.45,-191.834"/>
<polygon fill="black" stroke="black" points="216.005,-188.698 205.504,-187.289 212.835,-194.939 216.005,-188.698"/>
</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.
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.
#![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