-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,076 additions
and
16 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,32 @@ | ||
name: "Compiler CI" | ||
|
||
on: | ||
push: | ||
paths: | ||
- "ohdlc/**" | ||
- ".github/workflows/**" | ||
pull_request: | ||
paths: | ||
- "ohdlc/**" | ||
- ".github/workflows/**" | ||
merge_group: | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
build_and_test: | ||
name: "[Compiler] Cargo Build & Test" | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
toolchain: | ||
- stable | ||
defaults: | ||
run: | ||
working-directory: ohdlc | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} | ||
- run: cargo build --verbose | ||
- run: cargo test --verbose |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,17 @@ | ||
#![deny(rust_2018_idioms)] | ||
|
||
use message::Messages; | ||
|
||
// TODO: can we get unused errors back? :3 | ||
pub mod ast; | ||
pub mod ir; | ||
pub mod lexer; | ||
pub mod message; | ||
pub mod parser; | ||
pub mod span; | ||
pub mod symbol; | ||
|
||
pub static MESSAGES: Messages = Messages::new(); | ||
|
||
#[derive(Clone)] | ||
pub struct Source<'s>(pub String, pub &'s str); |
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
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,78 @@ | ||
mod std { | ||
enum Logical { | ||
High, | ||
Low, | ||
} | ||
} | ||
use ::std::Logical; | ||
|
||
mod x { | ||
use y; | ||
} | ||
|
||
mod y { | ||
use x; | ||
} | ||
|
||
record MyRecord { | ||
a: Logical, | ||
b: Logical, | ||
} | ||
|
||
enum MyEnum { | ||
A, | ||
B, | ||
C, | ||
D, | ||
E, | ||
} | ||
|
||
entity HalfAdder { | ||
in a: Logical, | ||
in b: Logical, | ||
out o: Logical, | ||
out c: Logical, | ||
} | ||
|
||
arch RTL for HalfAdder { | ||
o <= a xor b; | ||
c <= a and b; | ||
} | ||
|
||
use a::b::Lol; | ||
|
||
mod a { | ||
use other::b; | ||
} | ||
|
||
mod other { | ||
mod b { | ||
entity Lol { } | ||
} | ||
} | ||
|
||
entity FullAdder { | ||
in a: Logical, | ||
in b: Logical, | ||
in ci: Logical, | ||
out o: Logical, | ||
out co: Logical, | ||
} | ||
|
||
arch RTL for FullAdder { | ||
HalfAdder(RTL) { | ||
a <= a, | ||
b <= b, | ||
o => signal s, | ||
c => signal cb, | ||
} | ||
|
||
HalfAdder(RTL) { | ||
a <= s, | ||
b <= ci, | ||
o => o, | ||
c => signal cc, | ||
} | ||
|
||
co <= cb or cc; | ||
} |
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,109 @@ | ||
use ariadne::{Label, Report}; | ||
use bumpalo::Bump; | ||
use insta::assert_debug_snapshot; | ||
use ohdlc::{ | ||
ir::{ | ||
import_bucket::ImportBucket, | ||
name_lookup::NameLookup, | ||
registry::Registry, | ||
stages::{ | ||
flatten_lookup::FlattenLookupStage, refine_types::RefineTypesStage, rough::RoughStage, | ||
}, | ||
}, | ||
lexer::Lexer, | ||
parser::Parser, | ||
Source, MESSAGES, | ||
}; | ||
|
||
#[test] | ||
fn main() { | ||
let source = Source("work.ohd".to_owned(), include_str!("basic.ohd")); | ||
|
||
println!("[STAGE] Lexer"); | ||
|
||
let lexer = Lexer::new(&source.1); | ||
report_messages(&source); | ||
let lexer = lexer.unwrap(); | ||
|
||
println!("[STAGE] Parser"); | ||
|
||
let parser_arena = Bump::new(); | ||
|
||
let mut parser = Parser::new(&parser_arena, source.clone(), lexer); | ||
|
||
let root = parser.parse(); | ||
let root = match root { | ||
Ok(tree) => tree, | ||
Err(messages) => { | ||
MESSAGES.extend(messages); | ||
report_messages(&source); | ||
panic!(); | ||
} | ||
}; | ||
|
||
assert_debug_snapshot!(root); | ||
|
||
let ir_arena = Bump::new(); | ||
let mut registry = Registry::default(); | ||
let mut name_lookup = NameLookup::new(); | ||
let mut import_bucket = ImportBucket::new(); | ||
|
||
{ | ||
let rough = RoughStage { | ||
arena: &ir_arena, | ||
registry: &mut registry, | ||
name_lookup: &mut name_lookup, | ||
import_bucket: &mut import_bucket, | ||
root: &root, | ||
}; | ||
rough.lower(); | ||
report_messages(&source); | ||
} | ||
|
||
let name_lookup = { | ||
let resolve = FlattenLookupStage { | ||
registry: ®istry, | ||
name_lookup, | ||
import_bucket, | ||
resolvables: Vec::new(), | ||
}; | ||
let lookup = resolve.lower(); | ||
report_messages(&source); | ||
lookup | ||
}; | ||
let name_lookup = name_lookup.unwrap(); | ||
|
||
let refined_types = { | ||
let refine_types = RefineTypesStage { | ||
arena: &ir_arena, | ||
name_lookup: &name_lookup, | ||
module_registry: ®istry.modules, | ||
}; | ||
let refined_types = refine_types.lower(registry.types); | ||
report_messages(&source); | ||
Registry { | ||
modules: registry.modules, | ||
types: refined_types, | ||
} | ||
}; | ||
|
||
assert_debug_snapshot!(refined_types); | ||
} | ||
|
||
fn report_messages(source: &Source<'_>) { | ||
MESSAGES.drain(|msg| { | ||
let filename = source.0.as_str(); | ||
|
||
let report = | ||
Report::build(msg.kind, filename, msg.location.0) | ||
.with_message(msg.message) | ||
.with_labels(msg.labels.into_iter().map(|label| { | ||
Label::new((filename, label.span.into())).with_message(label.message) | ||
})) | ||
.finish(); | ||
|
||
report | ||
.eprint((filename, ariadne::Source::from(source.1))) | ||
.unwrap(); | ||
}); | ||
} |
Oops, something went wrong.