-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement a simple cpp program to count the most frequent control op …
…in a bril program; include several test cases to test my implementation out
- Loading branch information
1 parent
05bf45a
commit f1b7845
Showing
16 changed files
with
1,080 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*/.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@main { | ||
v0: int = const 1; | ||
v1: int = const 2; | ||
v2: int = add v0 v1; | ||
print v2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"functions": [ | ||
{ | ||
"instrs": [ | ||
{ | ||
"dest": "v0", | ||
"op": "const", | ||
"type": "int", | ||
"value": 1 | ||
}, | ||
{ | ||
"dest": "v1", | ||
"op": "const", | ||
"type": "int", | ||
"value": 2 | ||
}, | ||
{ | ||
"args": [ | ||
"v0", | ||
"v1" | ||
], | ||
"dest": "v2", | ||
"op": "add", | ||
"type": "int" | ||
}, | ||
{ | ||
"args": [ | ||
"v2" | ||
], | ||
"op": "print" | ||
} | ||
], | ||
"name": "main" | ||
} | ||
] | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
@main(input: int) { | ||
n: int = id input; | ||
zero: int = const 0; | ||
icount: int = id zero; | ||
site: ptr<int> = alloc n; | ||
result: int = call @queen zero n icount site; | ||
print result; | ||
free site; | ||
} | ||
@queen(n: int, queens: int, icount: int, site: ptr<int>): int { | ||
one: int = const 1; | ||
ite: int = id one; | ||
ret_cond: bool = eq n queens; | ||
br ret_cond .next.ret .for.cond; | ||
.next.ret: | ||
icount: int = add icount one; | ||
ret icount; | ||
.for.cond: | ||
for_cond_0: bool = le ite queens; | ||
br for_cond_0 .for.body .next.ret.1; | ||
.for.body: | ||
nptr: ptr<int> = ptradd site n; | ||
store nptr ite; | ||
is_valid: bool = call @valid n site; | ||
br is_valid .rec.func .next.loop; | ||
.rec.func: | ||
n_1: int = add n one; | ||
icount: int = call @queen n_1 queens icount site; | ||
.next.loop: | ||
ite: int = add ite one; | ||
jmp .for.cond; | ||
.next.ret.1: | ||
ret icount; | ||
} | ||
@valid(n: int, site: ptr<int>): bool { | ||
zero: int = const 0; | ||
one: int = const 1; | ||
true: bool = eq one one; | ||
false: bool = eq zero one; | ||
ite: int = id zero; | ||
.for.cond: | ||
for_cond: bool = lt ite n; | ||
br for_cond .for.body .ret.end; | ||
.for.body: | ||
iptr: ptr<int> = ptradd site ite; | ||
nptr: ptr<int> = ptradd site n; | ||
help_0: int = const 500; | ||
vali: int = load iptr; | ||
valn: int = load nptr; | ||
eq_cond_0: bool = eq vali valn; | ||
br eq_cond_0 .true.ret.0 .false.else; | ||
.true.ret.0: | ||
ret false; | ||
.false.else: | ||
sub_0: int = sub vali valn; | ||
sub_1: int = sub valn vali; | ||
sub_2: int = sub n ite; | ||
eq_cond_1: bool = eq sub_0 sub_2; | ||
eq_cond_2: bool = eq sub_1 sub_2; | ||
eq_cond_12: bool = or eq_cond_1 eq_cond_2; | ||
br eq_cond_12 .true.ret.1 .false.loop; | ||
.true.ret.1: | ||
ret false; | ||
.false.loop: | ||
ite: int = add ite one; | ||
jmp .for.cond; | ||
.ret.end: | ||
ret true; | ||
} |
Oops, something went wrong.