Skip to content

Commit

Permalink
Add commit hooks (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-hartl authored Mar 29, 2024
1 parent 46f2734 commit 66173a4
Show file tree
Hide file tree
Showing 104 changed files with 5,358 additions and 4,769 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
### Rust template
# Generated by Cargo
# will have compiled files and executables
debug/
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
out

.idea
5 changes: 5 additions & 0 deletions .rusty-hook.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[hooks]
pre-commit = "cargo fmt --all"
pre-push = "cargo build"
[logging]
verbose = true
11 changes: 6 additions & 5 deletions ir/Cargo.toml → Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[workspace]
resolver = "2"
members = [
"crates/back",
"crates/compiler",
"crates/front",
"crates/middle"]
"ir/crates/back",
"ir/crates/compiler",
"ir/crates/front",
"ir/crates/middle",
"lang"
]

[profile.release]
opt-level = 3
Expand All @@ -15,7 +17,6 @@ strip = "symbols"

[profile.dev.package."*"]
opt-level = 3

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


18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,21 @@ See [here](./lang/README.md) for more information.
## Example Package Manager

Yet to be implemented.

## Project setup

### Setup git commit hooks

To manage git hooks, we use [Rusty Hook](https://github.com/swellaby/rusty-hook).

To install Rusty Hook, run the following command:

```bash
cargo install rusty-hook
```

To install the git hooks, run the following command:

```bash
rusty-hook init
```
File renamed without changes.
4 changes: 2 additions & 2 deletions ir/crates/back/src/codegen/machine/abi/calling_convention.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::codegen::{
pub trait CallingConvention {
type Reg: machine::PhysicalRegister;

fn parameter_slots(params: impl Iterator<Item=Size>)
-> impl Iterator<Item=Slot<Self::Reg>>;
fn parameter_slots(params: impl Iterator<Item = Size>)
-> impl Iterator<Item = Slot<Self::Reg>>;

fn return_slot(size: Size) -> Slot<Self::Reg>;
}
Expand Down
2 changes: 1 addition & 1 deletion ir/crates/back/src/codegen/machine/abi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub use calling_convention::CallingConvention;

pub mod calling_convention;
pub mod calling_convention;
4 changes: 2 additions & 2 deletions ir/crates/back/src/codegen/machine/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ use crate::codegen::{
},
Function,
},
Instr,
TargetMachine,
},
selection_dag::Immediate,
};
use crate::codegen::machine::Instr;

type Reg<B> = <<B as Backend>::TM as TargetMachine>::Reg;
type BackInstr<B> = <<B as Backend>::TM as TargetMachine>::Instr;

pub trait Backend {
type TM: TargetMachine;

type P: Pattern<TM=Self::TM>;
type P: Pattern<TM = Self::TM>;

fn patterns() -> &'static [Self::P];

Expand Down
10 changes: 3 additions & 7 deletions ir/crates/back/src/codegen/machine/function/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ use daggy::{
petgraph::prelude::Bfs,
Walker,
};
use natrix_middle::instruction::CmpOp;
use rustc_hash::FxHashMap;
use tracing::debug;

use natrix_middle::instruction::CmpOp;

use crate::codegen::{
machine::{
backend::{
Expand All @@ -21,6 +20,7 @@ use crate::codegen::{
InstrOperand,
PseudoInstr,
},
Instr,
MachInstr,
Register,
Size,
Expand All @@ -35,7 +35,6 @@ use crate::codegen::{
PseudoOp,
},
};
use crate::codegen::machine::Instr;

#[derive(Debug)]
pub struct FunctionBuilder<TM: TargetMachine> {
Expand Down Expand Up @@ -226,10 +225,7 @@ impl<TM: TargetMachine> FunctionBuilder<TM> {
mbb
}

fn operand_to_matched_pattern_operand(
&self,
src: &Operand<TM>,
) -> MatchedPatternOperand<TM> {
fn operand_to_matched_pattern_operand(&self, src: &Operand<TM>) -> MatchedPatternOperand<TM> {
match src {
Operand::Reg(reg) => MatchedPatternOperand::Reg(*reg),
Operand::Imm(imm) => MatchedPatternOperand::Imm(imm.clone()),
Expand Down
17 changes: 9 additions & 8 deletions ir/crates/back/src/codegen/machine/function/cfg.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use daggy::{
NodeIndex,
petgraph::{
Directed,
Direction,
prelude::{
Bfs,
DfsPostOrder,
StableGraph,
},
Directed,
Direction,
},
NodeIndex,
Walker,
};
use index_vec::IndexVec;
Expand All @@ -18,8 +18,10 @@ use rustc_hash::FxHashMap;
use crate::codegen::{
machine::{
instr::InstrOperand,
Instr,
InstrId,
MachInstr,
TargetMachine,
},
register_allocator::{
InstrNumbering,
Expand All @@ -28,7 +30,6 @@ use crate::codegen::{
ProgPoint,
},
};
use crate::codegen::machine::{Instr, TargetMachine};

index_vec::define_index_type! {
pub struct BasicBlockId = u32;
Expand Down Expand Up @@ -83,25 +84,25 @@ impl Cfg {
}

/// Traverses the cfg using a post order depth first traversal
pub fn dfs_postorder(&self) -> impl Iterator<Item=BasicBlockId> + '_ {
pub fn dfs_postorder(&self) -> impl Iterator<Item = BasicBlockId> + '_ {
DfsPostOrder::new(&self.graph, self.entry_node())
.iter(&self.graph)
.map(|node| self.node_to_block_map[&node])
}

pub fn bfs(&self) -> impl Iterator<Item=BasicBlockId> + '_ {
pub fn bfs(&self) -> impl Iterator<Item = BasicBlockId> + '_ {
Bfs::new(&self.graph, self.entry_node())
.iter(&self.graph)
.map(|node| self.node_to_block_map[&node])
}

pub fn predecessors(&self, bb: BasicBlockId) -> impl Iterator<Item=BasicBlockId> + '_ {
pub fn predecessors(&self, bb: BasicBlockId) -> impl Iterator<Item = BasicBlockId> + '_ {
self.graph
.neighbors_directed(self.block_to_node_map[&bb], Direction::Incoming)
.map(|node| self.node_to_block_map[&node])
}

pub fn successors(&self, bb: BasicBlockId) -> impl Iterator<Item=BasicBlockId> + '_ {
pub fn successors(&self, bb: BasicBlockId) -> impl Iterator<Item = BasicBlockId> + '_ {
self.graph
.neighbors(self.block_to_node_map[&bb])
.map(|node| self.node_to_block_map[&node])
Expand Down
34 changes: 17 additions & 17 deletions ir/crates/back/src/codegen/machine/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ use std::fmt::{
Formatter,
};

pub use cfg::{
BasicBlock,
BasicBlockId,
Cfg,
};
use cranelift_entity::{
entity_impl,
PrimaryMap,
Expand All @@ -15,28 +20,26 @@ use smallvec::{
};
use tracing::debug;

pub use cfg::{BasicBlock, BasicBlockId, Cfg};

use crate::codegen::machine::{
abi::{
calling_convention::Slot,
CallingConvention,
},
asm::Assembler,
backend::Backend,
instr::{
InstrOperand,
PseudoInstr,
},
InstrId,
isa::PhysicalRegister,
MachInstr,
reg::VRegInfo,
Instr,
InstrId,
MachInstr,
Size,
TargetMachine,
VReg,
};
use crate::codegen::machine::asm::Assembler;
use crate::codegen::machine::Instr;

pub mod builder;
pub mod cfg;
Expand Down Expand Up @@ -114,8 +117,8 @@ impl<TM: TargetMachine> Function<TM> {
}

pub fn expand_pseudo_instructions<B>(&mut self)
where
B: Backend<TM=TM>,
where
B: Backend<TM = TM>,
{
debug!("Expanding pseudo instructions for function {}", self.name);
for bb in &mut self.basic_blocks {
Expand All @@ -139,14 +142,11 @@ impl<TM: TargetMachine> Function<TM> {
smallvec![B::ret()]
}
Some(value) => {
let return_slot =
TM::CallingConvention::return_slot(match value {
InstrOperand::Reg(reg) => {
reg.try_as_physical().unwrap().size()
}
InstrOperand::Imm(imm) => imm.size,
InstrOperand::Label(_) => unreachable!(),
});
let return_slot = TM::CallingConvention::return_slot(match value {
InstrOperand::Reg(reg) => reg.try_as_physical().unwrap().size(),
InstrOperand::Imm(imm) => imm.size,
InstrOperand::Label(_) => unreachable!(),
});
match return_slot {
Slot::Register(dest) => {
let instr = match value {
Expand Down Expand Up @@ -233,7 +233,7 @@ impl<TM: TargetMachine> Function<TM> {
impl<TM: TargetMachine> Display for Function<TM> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
writeln!(f, "function {}:", self.name)?;
let bbs: Box<dyn Iterator<Item=BasicBlockId>> = match &self.cfg {
let bbs: Box<dyn Iterator<Item = BasicBlockId>> = match &self.cfg {
Some(cfg) => Box::new(cfg.ordered().into_iter()),
None => Box::new(self.basic_blocks.indices().into_iter()),
};
Expand Down
10 changes: 6 additions & 4 deletions ir/crates/back/src/codegen/machine/instr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ use smallvec::{
};

use crate::codegen::{
machine::Register,
machine::{
function::BasicBlockId,
isa::MachInstr as MInstr,
Register,
TargetMachine,
},
selection_dag::Immediate,
};
use crate::codegen::machine::function::BasicBlockId;
use crate::codegen::machine::isa::MachInstr as MInstr;
use crate::codegen::machine::TargetMachine;

index_vec::define_index_type! {
pub struct InstrId = u32;
Expand Down
16 changes: 8 additions & 8 deletions ir/crates/back/src/codegen/machine/isa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::codegen::machine::{
instr::InstrOperand,
reg::Register,
Size,
TargetMachine,
};
use crate::codegen::machine::TargetMachine;

pub trait PhysicalRegister: Debug + Clone + Copy + PartialEq + Eq + Sized + Hash + 'static {
fn name(&self) -> &'static str;
Expand All @@ -30,9 +30,9 @@ pub trait PhysicalRegister: Debug + Clone + Copy + PartialEq + Eq + Sized + Hash

fn superregs(&self) -> Option<&'static [Self]>;

fn regclass(&self) -> impl Iterator<Item=Self>
where
Self: 'static,
fn regclass(&self) -> impl Iterator<Item = Self>
where
Self: 'static,
{
self.subregs()
.into_iter()
Expand All @@ -43,16 +43,16 @@ pub trait PhysicalRegister: Debug + Clone + Copy + PartialEq + Eq + Sized + Hash
}

fn has_subreg(&self, other: Self) -> bool
where
Self: 'static,
where
Self: 'static,
{
self.subregs()
.map_or(false, |subregs| subregs.contains(&other))
}

fn interferes_with(self, other: Self) -> bool
where
Self: 'static,
where
Self: 'static,
{
if self == other {
return true;
Expand Down
Loading

0 comments on commit 66173a4

Please sign in to comment.