Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ And then follow these steps:

mkdir -p circt/llvm/build
pushd circt/llvm/build
cmake ../llvm \
cmake -G Ninja ../llvm \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_BUILD_EXAMPLES=OFF \
-DLLVM_ENABLE_ASSERTIONS=ON \
Expand All @@ -32,19 +32,19 @@ And then follow these steps:
-DLLVM_INSTALL_UTILS=ON \
-DLLVM_OPTIMIZED_TABLEGEN=ON \
-DLLVM_TARGETS_TO_BUILD="host"
cmake --build .
ninja -j$(nproc)
popd

#### Build CIRCT

mkdir -p circt/build
pushd circt/build
cmake .. \
cmake -G Ninja .. \
-DCMAKE_BUILD_TYPE=Release \
-DMLIR_DIR=$PWD/../llvm/build/lib/cmake/mlir \
-DLLVM_DIR=$PWD/../llvm/build/lib/cmake/llvm \
-DLLVM_ENABLE_ASSERTIONS=ON
cmake --build .
ninja -j$(nproc)
popd

#### Build Moore
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.66"
channel = "1.87"

2 changes: 1 addition & 1 deletion src/bin/moore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ unsafe extern "C" fn moore_mlir_diagnostic_handler(
let sess: &Session = (sess as *const Session).as_ref().unwrap();

// Map the severity from MLIR to Moore.
#[allow(non_upper_case_globals)]
#[allow(non_upper_case_globals,non_snake_case)]
let severity = match mlirDiagnosticGetSeverity(diag) {
MlirDiagnosticSeverity_MlirDiagnosticError => Severity::Error,
MlirDiagnosticSeverity_MlirDiagnosticWarning => Severity::Warning,
Expand Down
2 changes: 1 addition & 1 deletion src/circt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,5 @@ mod crate_prelude {
pub use crate::mlir::*;
pub use crate::prelude::*;
pub use crate::sys::*;
pub use num::{BigInt, BigRational, One, ToPrimitive, Zero};
pub use num::{BigInt, BigRational, ToPrimitive, Zero};
}
53 changes: 50 additions & 3 deletions src/derive/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

use heck::CamelCase;
use proc_macro::TokenStream;
use proc_macro2::Span;
use quote::{format_ident, quote, ToTokens};
use std::{
cell::RefCell,
collections::{BTreeSet, HashSet},
collections::{BTreeSet, HashSet},
};
use syn::visit::Visit;
use syn::{visit::Visit, Ident};

// CAUTION: This is all wildly unstable and relies on the compiler maintaining
// a certain order between proc macro expansions. So this could break any
Expand Down Expand Up @@ -155,9 +156,37 @@ pub(crate) fn derive_query_db(input: TokenStream) -> TokenStream {
let key_name = format_ident!("{}QueryKey", name.to_string().to_camel_case());
let key_indices = (0..arg_types.len()).map(syn::Index::from);
let doc = format!("The arguments passed to the `{}` query.", name);
// If there is one arg and it is a &dyn *Node then the default derived `PartialEq` and `Hash`
// traits aren't valid for the way nodes are used in the caches. They need to depend on
// the node `id()` instead.
// let mut derive_list: Vec<proc_macro2::Literal> = Vec::new();
// derive_list.push(proc_macro2::Literal::string("Clone"));
// let mut derive_list: proc_macro2::TokenStream = "Clone, PartialEq, Eq, Hash".parse().unwrap();
let mut derive_list: Vec<proc_macro2::TokenTree> =
vec!["Clone", "PartialEq", "Eq", "Hash"].into_iter().map(|i| Ident::new(i, Span::call_site()).into()).collect();
let mut derive_hash_eq = false;
if arg_types.len() == 1 {
if let syn::Type::Reference(ref_type) = &arg_types[0] {
if let syn::Type::TraitObject(t_obj) = ref_type.elem.as_ref() {
if t_obj.dyn_token.is_some() {
if t_obj.bounds.len() == 1 {
if let syn::TypeParamBound::Trait(bound) = t_obj.bounds.first().unwrap() {
let t_ident = bound.path.segments.last().unwrap().ident.to_string();
if t_ident.contains("Node") {
derive_hash_eq = true;
derive_list =
vec!["Clone", "Eq"].into_iter().map(|i| Ident::new(i, Span::call_site()).into()).collect();
}
}
}
}
}
}
}
let derive_tokens = derive_list; //proc_macro2::TokenStream::from_iter(derive_list);
keys.push(quote! {
#[doc = #doc]
#[derive(Clone, PartialEq, Eq, Hash)]
#[derive (#(#derive_tokens),*) ]
pub struct #key_name #key_generics (#(pub #arg_types),*);

impl #key_generics std::fmt::Debug for #key_name #key_generics {
Expand All @@ -166,6 +195,20 @@ pub(crate) fn derive_query_db(input: TokenStream) -> TokenStream {
}
}
});
if derive_hash_eq {
keys.push(quote! {
impl #key_generics PartialEq for #key_name #key_generics {
fn eq(&self, other: &Self) -> bool {
self.0.id() == other.0.id()
}
}
impl #key_generics std::hash::Hash for #key_name #key_generics {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.0.id().hash(state);
}
}
});
}

// Determine the cache field name.
let cache_name = format_ident!("cached_{}", name);
Expand Down Expand Up @@ -305,6 +348,10 @@ pub(crate) fn derive_query_db(input: TokenStream) -> TokenStream {
#(#keys)*
});

// Uncomment for debugging with procout
// let module_ident = syn::Ident::new("query", proc_macro2::Span::mixed_site());
// procout::procout(&output, Some(module_ident), Some("/tmp/query_procout.rs"));

// Produce some output.
// println!("{}", output);
output.into()
Expand Down
6 changes: 5 additions & 1 deletion src/svlog/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3743,7 +3743,11 @@ pub enum ModulePortKind<'a> {
Port,
/// An interface signal.
IntfSignal {
intf: &'a ast::Interface<'a>,
/* [email protected] 20 June 2025
* Clippy says this is never read. That is sort of correct, only intf.ast is read. Grrr.
*/
#[allow(dead_code)]
intf: &'a ast::Interface<'a>,
env: ParamEnv,
decl_id: NodeId,
},
Expand Down
6 changes: 3 additions & 3 deletions src/svlog/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,17 +334,17 @@ impl<'t> GlobalArenas<'t> {
}

/// Allocate an AST root.
pub fn alloc_ast_root(&'t self, ast: ast::Root<'t>) -> &'t ast::Root {
pub fn alloc_ast_root(&'t self, ast: ast::Root<'t>) -> &'t ast::Root<'t> {
self.ast_roots.alloc(ast)
}

/// Allocate an AST type.
pub fn alloc_ast_type(&'t self, ast: ast::Type<'t>) -> &'t ast::Type {
pub fn alloc_ast_type(&'t self, ast: ast::Type<'t>) -> &'t ast::Type<'t> {
self.ast_types.alloc(ast)
}

/// Allocate an AST expression.
pub fn alloc_ast_expr(&'t self, ast: ast::Expr<'t>) -> &'t ast::Expr {
pub fn alloc_ast_expr(&'t self, ast: ast::Expr<'t>) -> &'t ast::Expr<'t> {
self.ast_exprs.alloc(ast)
}

Expand Down
4 changes: 1 addition & 3 deletions src/svlog/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,7 @@ mod queries {
value::*,
};
use std::{
cell::RefCell,
collections::{HashMap, HashSet},
sync::Arc,
cell::RefCell, collections::{HashMap, HashSet}, sync::Arc,
};

moore_derive::derive_query_db! {
Expand Down
2 changes: 1 addition & 1 deletion src/svlog/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<'a, T: WalkVisitor<'a>> WalkVisitor<'a> for Vec<T> {

impl<'a, T: WalkVisitor<'a>> WalkVisitor<'a> for Option<T> {
fn walk(&'a self, visitor: &mut dyn Visitor<'a>) {
for x in self {
if let Some(x) = self {
x.walk(visitor);
}
}
Expand Down
15 changes: 14 additions & 1 deletion src/svlog/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,14 +1109,27 @@ pub(crate) fn scope_location<'a>(
}

/// A location of a node within its enclosing scope.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, Copy, Eq)]
pub struct ScopeLocation<'a> {
/// The node which generates the enclosing scope.
pub scope: &'a dyn ScopedNode<'a>,
/// The lexical order within that scope.
pub order: usize,
}

impl<'a> PartialEq for ScopeLocation<'a> {
fn eq(&self, other: &Self) -> bool {
self.scope.id() == other.scope.id() && self.order == other.order
}
}

impl<'a> Hash for ScopeLocation<'a> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.scope.id().hash(state);
self.order.hash(state);
}
}

/// Resolve a local name in a scope.
///
/// This traverses up the scope tree until a definition with visibility `LOCAL`
Expand Down
2 changes: 1 addition & 1 deletion src/svlog/syntax/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Lexer<'a> {
}

impl<'a> Lexer<'a> {
pub fn new(input: Preprocessor<'a>) -> Lexer {
pub fn new(input: Preprocessor<'a>) -> Lexer<'a> {
Lexer {
input: input,
peek: [(CatTokenKind::Eof, INVALID_SPAN); 4],
Expand Down
4 changes: 2 additions & 2 deletions src/vhdl/hir/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ make_arenas!(
package: Package2<'t>,
type_decl: TypeDecl2<'t>,
subtype_ind: SubtypeInd2<'t>,
const_decl: ConstDecl<'t>,
const_decl: crate::hir::obj_decl::ConstDecl<'t>,
lit_expr: LitExpr,

package_slot: Slot<'t, Package2<'t>>,
type_decl_slot: Slot<'t, TypeDecl2<'t>>,
subtype_ind_slot: Slot<'t, SubtypeInd2<'t>>,
const_decl_slot: Slot<'t, ConstDecl<'t>>,
const_decl_slot: Slot<'t, crate::hir::obj_decl::ConstDecl<'t>>,
}
);
5 changes: 1 addition & 4 deletions src/vhdl/hir/misc.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
// Copyright (c) 2016-2021 Fabian Schuiki

use std;

use crate::hir::prelude::*;

pub fn apply_use_clauses<'a, I>(clauses: I, context: AllocContext)
where
I: IntoIterator<Item = &'a ast::CompoundName>,
{
for u in clauses.into_iter() {
let e = apply_use_clause(u, context);
std::mem::forget(e);
let _ = apply_use_clause(u, context);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/vhdl/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub use self::expr::*;
pub use self::lib::*;
pub use self::misc::*;
pub use self::node::*;
pub use self::obj_decl::*;
pub use self::pkg::*;
pub use self::slot::*;
pub use self::subtype_decl::*;
Expand Down
4 changes: 2 additions & 2 deletions src/vhdl/hir/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ pub use crate::common::score::Result;
pub use crate::common::source::{Span, Spanned};
pub use crate::common::NodeId;

pub use crate::arenas::{Alloc, AllocInto, AllocOwned, AllocOwnedInto, AllocOwnedSelf, AllocSelf};
pub use crate::arenas::{Alloc, AllocInto, AllocOwned, AllocOwnedInto};
pub use crate::hir::node::*;
pub use crate::hir::slot::*;
pub use crate::hir::visit::Visitor;
pub use crate::hir::AllocContext;
pub use crate::scope2::{Def2, ScopeContext, ScopeData, TypeVariantDef};
pub use crate::score::ResolvableName;
pub use crate::syntax::ast;
pub use crate::ty2::{self, Type};
pub use crate::ty2::Type;
14 changes: 7 additions & 7 deletions src/vhdl/scope2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ impl<'t> Def2<'t> {
impl<'t> PartialEq for Def2<'t> {
fn eq(&self, other: &Self) -> bool {
match (*self, *other) {
(Def2::Node(a), Def2::Node(b)) => (a as *const _ == b as *const _),
(Def2::Lib(a), Def2::Lib(b)) => (a as *const _ == b as *const _),
(Def2::Pkg(a), Def2::Pkg(b)) => (a as *const _ == b as *const _),
(Def2::Type(a), Def2::Type(b)) => (a as *const _ == b as *const _),
(Def2::Enum(a), Def2::Enum(b)) => (a == b),
(Def2::Unit(a), Def2::Unit(b)) => (a == b),
(Def2::Node(a), Def2::Node(b)) => std::ptr::addr_eq(a as *const _, b as *const _),
(Def2::Lib(a), Def2::Lib(b)) => a as *const _ == b as *const _,
(Def2::Pkg(a), Def2::Pkg(b)) => std::ptr::addr_eq(a as *const _, b as *const _),
(Def2::Type(a), Def2::Type(b)) => std::ptr::addr_eq(a as *const _, b as *const _),
(Def2::Enum(a), Def2::Enum(b)) => a == b,
(Def2::Unit(a), Def2::Unit(b)) => a == b,
_ => false,
}
}
Expand Down Expand Up @@ -250,7 +250,7 @@ impl<'t> fmt::Debug for TypeVariantDef<'t> {

impl<'t> PartialEq for TypeVariantDef<'t> {
fn eq(&self, other: &Self) -> bool {
self.0 as *const _ == other.0 as *const _ && self.1 == other.1
std::ptr::addr_eq(self.0 as *const _, other.0 as *const _) && self.1 == other.1
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/vhdl/ty2/subtypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use std::fmt::{Debug, Display};

pub use num::BigInt;

use crate::ty2::marks::*;
use crate::ty2::range::*;
use crate::ty2::types::*;
Expand Down
2 changes: 0 additions & 2 deletions src/vhdl/ty2/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use std::borrow::Borrow;
use std::fmt::{self, Debug, Display};

pub use num::BigInt;

use crate::ty2::access::*;
use crate::ty2::enums::*;
use crate::ty2::floats::*;
Expand Down
4 changes: 1 addition & 3 deletions src/vhdl/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,7 @@ macro_rules! impl_typeck_err {
($slf:tt, $id:ident: $id_ty:ty => $blk:block) => {
impl<'sbc, 'lazy, 'sb, 'ast, 'ctx> Typeck<$id_ty> for TypeckContext<'sbc, 'lazy, 'sb, 'ast, 'ctx> {
fn typeck(&$slf, $id: $id_ty) {
use std;
let res = (move || -> Result<()> { $blk })();
std::mem::forget(res);
let _ = (move || -> Result<()> { $blk })();
}
}
}
Expand Down
Loading