Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sampsyo/bril
Browse files Browse the repository at this point in the history
  • Loading branch information
kq-li committed Dec 5, 2020
2 parents 0d52279 + b9b6b25 commit 52a3981
Show file tree
Hide file tree
Showing 70 changed files with 1,269 additions and 57 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ There are some quick-start instructions below for some of the main tools, but
check out the docs for more details about what's available.

[docs]: https://capra.cs.cornell.edu/bril/
[langref]: https://capra.cs.cornell.edu/bril/langref.html
[langref]: https://capra.cs.cornell.edu/bril/lang/index.html
[brilts]: https://github.com/sampsyo/bril/blob/master/bril-ts/bril.ts


Expand Down Expand Up @@ -65,5 +65,5 @@ Install it with [pip][]:
Then run all the tests by typing `make test`.

[pip]: https://packaging.python.org/tutorials/installing-packages/
[cs6120]: https://www.cs.cornell.edu/courses/cs6120/2019fa/
[cs6120]: https://www.cs.cornell.edu/courses/cs6120/2020fa/
[turnt]: https://github.com/cucapra/turnt
2 changes: 1 addition & 1 deletion benchmarks/sieve.bril
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# Find the next value `p` in `table` that's greater than
# `currentP`, and is not marked. If there are no numbers
# in the table left that meet those criteria, return 0.
@findNextP(table: ptr<book>, tableSize: int, currentP: int) : int {
@findNextP(table: ptr<bool>, tableSize: int, currentP: int) : int {
zero: int = const 0;
one: int = const 1;
p: int = id currentP;
Expand Down
2 changes: 2 additions & 0 deletions bril-rs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/target
Cargo.lock
11 changes: 11 additions & 0 deletions bril-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "bril-rs"
version = "0.1.0"
authors = ["Patrick LaFontaine <32135464+Pat-Lafon@users.noreply.github.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
142 changes: 142 additions & 0 deletions bril-rs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
use serde::{Deserialize, Serialize};
use std::io::{self, Read};

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Program {
pub functions: Vec<Function>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Function {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub args: Option<Vec<Argument>>,
#[serde(rename = "type")]
#[serde(skip_serializing_if = "Option::is_none")]
pub return_type: Option<Type>,
pub instrs: Vec<Code>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Argument {
pub name: String,
#[serde(rename = "type")]
pub arg_type: Type,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(untagged)]
pub enum Code {
Label { label: String },
Instruction(Instruction),
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(untagged)]
pub enum Instruction {
Constant {
op: ConstOps,
dest: String,
#[serde(rename = "type")]
const_type: Type,
value: Literal,
},
Value {
op: ValueOps,
dest: String,
#[serde(rename = "type")]
op_type: Type,
#[serde(skip_serializing_if = "Option::is_none")]
args: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
funcs: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
labels: Option<Vec<String>>,
},
Effect {
op: EffectOps,
#[serde(skip_serializing_if = "Option::is_none")]
args: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
funcs: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
labels: Option<Vec<String>>,
},
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum ConstOps {
#[serde(rename = "const")]
Const,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum EffectOps {
#[serde(rename = "jmp")]
Jump,
#[serde(rename = "br")]
Branch,
Call,
#[serde(rename = "ret")]
Return,
Print,
Nop,
Store,
Free,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum ValueOps {
Add,
Sub,
Mul,
Div,
Eq,
Lt,
Gt,
Le,
Ge,
Not,
And,
Or,
Call,
Id,
Phi,
Fadd,
Fsub,
Fmul,
Fdiv,
Feq,
Flt,
Fgt,
Fle,
Fge,
Alloc,
Load,
PtrAdd,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum Type {
Int,
Bool,
Float,
#[serde(rename = "ptr")]
Pointer(Box<Type>),
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(untagged)]
pub enum Literal {
Int(i64),
Bool(bool),
Float(f64),
}

pub fn load_program() -> Program {
let mut buffer = String::new();
io::stdin().read_to_string(&mut buffer).unwrap();
serde_json::from_str(&buffer).unwrap()
}
3 changes: 2 additions & 1 deletion bril-ts/bril.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ interface Op {
*/
export interface EffectOperation extends Op {
op: "br" | "jmp" | "print" | "ret" | "call" |
"store" | "free";
"store" | "free" |
"speculate" | "guard" | "commit";
}

/**
Expand Down
Loading

0 comments on commit 52a3981

Please sign in to comment.