Git Product home page Git Product logo

bril-py's Introduction

this is my work through of this course. the programs written are mostly an academic exercise for me to learn more about how to think and reason about programs. bril functions can be represented as json like:

{"name": "<string>", "instrs": [<Instruction>, ...], "args": [<Argument>, ...], "type": <Type>}

for more documentation on bril's json representation

cfg

contains a program that parses the json representation of bril programs and creates a control flow graph. returning a DOT representation of the input program

make_labeled_blocks chunks a program into basic blocks and assigns an label to each basic block, it uses the label for basic blocks if it comes with one

make_cfg creates a graph representing the control flow graph of a program

print_graphviz spits out the DOT representation of the cfg

dce

contains some code to perform simple dead code elimination. returning a semantically equivalent bril json program with less dead code. and example program of what what this does may look like:

a = 1
a = 2
b = 3
if True:
  a = a-1
d = 4
print(a+b)

transforms into the following equivalent program

a = 2
b = 3
if True:
  a = a-1
print(a+b)

remove_reassigned_variables checks within a basic block to remove any instructions where variables are reassigned

remove_dead_code performs a dead code elimination across the entire function, removing any unused code and iterating till convergence

lvn

contains a program that performs value number within basic blocks (local value numbering). the idea is to disentangle variables from it's value. an example of a program that this technique could work on might be

a = 1
b = 1
c = a+b
b = 2
d = a+b

can be transformed into an semantically equivalent program

a = 1
b = a
c = a+a
b = 2
d = a+b

by associating a value number to each value and giving that value assigning it a variable, we can replace all instances where the redundant variables are used with the the variable associated with the value number. this is also dependent on the order of assignments, because reassignments can influence the values.

local_ssa performs static single assignment within a basic block, giving each assignment instruction a unique variable name

lvn performs local value numbering

bril-py's People

Contributors

space-miner avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.