Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for crash when compiling module with no parameters. #128

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
99c2677
Fix for crash when compiling module with no parameters.
gjcoram May 31, 2024
fdf0473
Fix for crash when compiling module with no parameters.
gjcoram Jun 19, 2024
bf3432f
fix typo (modulle->module)
gjcoram Jun 21, 2024
67c3644
fix typo
gjcoram Jun 21, 2024
2b5ed2a
remove obsolete comment
gjcoram Jun 21, 2024
b5bfc0e
ensure mfactor isn't optimized away
gjcoram Jun 21, 2024
88b8856
Update README.md to point to this repository instead of pascalkuthe
gjcoram Jun 21, 2024
a1cf7cd
support 'ceil' ($ceil, floor, and $floor are already supported)
gjcoram Jun 21, 2024
ed5641e
Merge branch 'master' of https://github.com/gjcoram/OpenVAF
gjcoram Jun 21, 2024
9b0c59b
fix crash for $limit() with 1 arg
gjcoram Jun 22, 2024
c78eac3
Work-around for singular matrix issue with single-node voltage contri…
gjcoram Jul 5, 2024
1efe329
parse '{} for string parameter ranges
gjcoram Jul 6, 2024
1dcfe1d
Pull cdc66d8fb2a3bcb735dedb8e273490afeadda4f0 from https://github.com…
gjcoram Jul 8, 2024
477e71c
Fix $mfactor scaling for potential noise contributions
gjcoram Jul 8, 2024
cce826c
Fix is_zero() for Ieee64; note 1.0 has a zero mantissa!
gjcoram Jul 9, 2024
457ee3f
Fix issue with $limit and user-defined functions
gjcoram Jul 9, 2024
a8108a5
Fix typos
gjcoram Jul 9, 2024
eba9808
Remove unused code and unused imports
gjcoram Jul 10, 2024
04cb1fb
Support `undef
gjcoram Jul 11, 2024
47df3de
Ignore `resetall (rather than erroring out)
gjcoram Jul 11, 2024
f170b6e
Fix macro call argument issue
gjcoram Jul 14, 2024
ddfb16c
fix typos (Optimiziation -> Optimization)
gjcoram Sep 30, 2024
be547cd
arpadbuermen's fix for psp glitch problem, see https://github.com/pas…
gjcoram Sep 30, 2024
9fdd191
merge commit from arpadbuermen for noise mfactor issue https://github…
gjcoram Oct 28, 2024
061fc50
fix glitch in last commit
gjcoram Oct 30, 2024
634f8d2
fix typos
gjcoram Oct 30, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Some working minimal examples (in rust) can be found in `melange/core/test.rs`.
The official docker image contains everything required for compiling OpenVAF. To build OpenVAF using the official docker containers, simply run the following commands:

``` shell
git clone https://github.com/pascalkuthe/OpenVAF.git && cd OpenVAF
git clone https://github.com/gjcoram/OpenVAF.git && cd OpenVAF
# On REHL distros and fedora replace docker with podman
# on all commands below.
docker pull ghcr.io/pascalkuthe/ferris_ci_build_x86_64-unknown-linux-gnu:latest
Expand Down
6 changes: 3 additions & 3 deletions lib/stdx/src/ieee64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,9 @@ impl Ieee64 {
f64::from_bits(self.0).is_finite()
}

/// Get the bitwise representation.
/// Check if the value is +0.0 or -0.0
/// (note that other values have a 0 mantissa!)
pub fn is_zero(self) -> bool {
// IEEE number is zero if mantissa is zero
(self.0 & 0x000FFFFFFFFFFFFF) == 0
self.0 == 0x0000000000000000 || self.0 == 0x8000000000000000
}
}
2 changes: 1 addition & 1 deletion openvaf/basedb/src/ast_id_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl AstIdMap {
// Compared to rust analyzer the parent mapping was added here for lint attribute
// resolution
// TODO does this hurt caching in any way. Probably not:
// if the parent changes then something before changed aswell and the item is moved anyway)
// if the parent changes then something before changed as well and the item is moved anyway)
bdfs(node, |it, parent| has_id_map_entry(it.kind()).then(|| res.alloc(it, parent)));
res
}
Expand Down
20 changes: 20 additions & 0 deletions openvaf/basedb/src/diagnostics/preprocessor_error.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,27 @@ impl Diagnostic for PreprocessorDiagnostic {
message: "macro not found here".to_owned(),
}])
}
PreprocessorDiagnostic::MacroNotDefined { span, .. } => {
let span = span.to_file_span(&sm);

Report::warning().with_labels(vec![Label {
style: LabelStyle::Primary,
file_id: span.file,
range: span.range.into(),
message: "macro not defined here".to_owned(),
}])
}
PreprocessorDiagnostic::MacroRecursion { .. } => todo!(),
PreprocessorDiagnostic::UnsupportedCompDir { span, .. } => {
let span = span.to_file_span(&sm);

Report::warning().with_labels(vec![Label {
style: LabelStyle::Primary,
file_id: span.file,
range: span.range.into(),
message: "directive ignored".to_owned(),
}])
}
PreprocessorDiagnostic::FileNotFound { span, .. } => {
let labels = if let Some(span) = span {
let span = span.to_file_span(&sm);
Expand Down
4 changes: 2 additions & 2 deletions openvaf/basedb/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use vfs::FileId;

use crate::{BaseDB, ErasedAstId};

/// Lints can be set to different levls
/// This enum represents these levls
/// Lints can be set to different levels
/// This enum represents these levels
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum LintLevel {
/// Lints set to allow will not be displayed
Expand Down
2 changes: 1 addition & 1 deletion openvaf/hir/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl AstCache {
/// # Returns
///
/// The (unescaped) string literal assigned to `attribute`. If `attribute`
/// doesn't exits or is not a string literal `None` is returned instead
/// doesn't exist or is not a string literal `None` is returned instead
pub(crate) fn resolve_attribute(&self, attribute: &str, id: ErasedAstId) -> Option<ast::Attr> {
let idx = self.id_map.get_attr(id, attribute)?;
let ast = self.id_map.get_syntax(id).to_node(self.ast.syntax());
Expand Down
3 changes: 1 addition & 2 deletions openvaf/hir/src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use hir_ty::db::HirTyDB;
use hir_ty::inference;
use hir_ty::types::{Signature, Ty};

pub use hir_def::expr::Event;
pub use hir_def::{expr::CaseCond, BuiltIn, Case, ExprId, Literal, ParamSysFun, StmtId, Type};
pub use hir_def::{expr::Event, BuiltIn, Case, ExprId, Literal, ParamSysFun, StmtId, Type};
pub use syntax::ast::{BinaryOp, UnaryOp};

use crate::{Branch, CompilationDB, Node};
Expand Down
2 changes: 1 addition & 1 deletion openvaf/hir/src/declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct Scope {
}
impl Scope {
fn new(def_map: Arc<DefMap>, scope: LocalScopeId, block: Option<(Name, ScopeDef)>) -> Scope {
// safety: def_map is a immultable/an arc that will live atleast as long as the scop
// safety: def_map is a immutable/an arc that will live at least as long as the scope
let iter = unsafe { transmute(def_map[scope].declarations.iter()) };
Scope { _def_map: def_map, iter, def: block }
}
Expand Down
2 changes: 1 addition & 1 deletion openvaf/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl Function {
}

pub fn arg(self, idx: usize, db: &CompilationDB) -> FunctionArg {
debug_assert!(db.function_data(self.id).args.len() <= idx);
debug_assert!(idx < db.function_data(self.id).args.len());
FunctionArg { fun_id: self.id, arg_id: idx.into() }
}
pub fn args(self, db: &CompilationDB) -> impl Iterator<Item = FunctionArg> + Clone {
Expand Down
2 changes: 1 addition & 1 deletion openvaf/hir/src/rec_declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct Scope {
}
impl Scope {
fn new(def_map: Arc<DefMap>, scope: LocalScopeId, block: Option<(Name, ScopeDef)>) -> Scope {
// safety: def_map is a immultable/an arc that will live atleast as long as the scop
// safety: def_map is a immutable/an arc that will live at least as long as the scope
let iter: indexmap::map::Iter<'_, Name, nameres::ScopeDefItem> =
def_map[scope].declarations.iter();
let iter = unsafe { transmute(iter) };
Expand Down
3 changes: 2 additions & 1 deletion openvaf/hir_def/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ pub fn insert_builtin_scope(dst: &mut IndexMap<Name, ScopeDefItem, RandomState>)
dst.insert(kw::atan, BuiltIn::atan.into());
dst.insert(kw::atan2, BuiltIn::atan2.into());
dst.insert(kw::atanh, BuiltIn::atanh.into());
dst.insert(kw::ceil, BuiltIn::ceil.into());
dst.insert(kw::cos, BuiltIn::cos.into());
dst.insert(kw::cosh, BuiltIn::cosh.into());
dst.insert(kw::exp, BuiltIn::exp.into());
Expand Down Expand Up @@ -370,7 +371,7 @@ pub fn insert_builtin_scope(dst: &mut IndexMap<Name, ScopeDefItem, RandomState>)
dst.insert(kw::slew, BuiltIn::slew.into());
dst.insert(kw::transition, BuiltIn::transition.into());
}
pub fn insert_modulle_builtin_scope(dst: &mut IndexMap<Name, ScopeDefItem, RandomState>) {
pub fn insert_module_builtin_scope(dst: &mut IndexMap<Name, ScopeDefItem, RandomState>) {
dst.insert(sysfun::mfactor, ParamSysFun::mfactor.into());
dst.insert(sysfun::xposition, ParamSysFun::xposition.into());
dst.insert(sysfun::yposition, ParamSysFun::yposition.into());
Expand Down
2 changes: 1 addition & 1 deletion openvaf/hir_def/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl BlockLoc {
tree.block_scope(self.ast)
.name
.clone()
.expect("BlockLocs are only cerated for named Blocks")
.expect("BlockLocs are only created for named Blocks")
}
}

Expand Down
4 changes: 2 additions & 2 deletions openvaf/hir_def/src/nameres/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use syntax::name::Name;

use super::diagnostics::DefDiagnostic;
use super::{DefMap, DefMapSource, LocalScopeId, Scope, ScopeDefItem, ScopeOrigin};
use crate::builtin::insert_modulle_builtin_scope;
use crate::builtin::insert_module_builtin_scope;
use crate::db::HirDefDB;
use crate::item_tree::{
BlockScopeItem, Function, FunctionItem, ItemTree, ItemTreeId, ItemTreeNode, Module, ModuleItem,
Expand Down Expand Up @@ -256,7 +256,7 @@ impl DefCollector<'_> {
let module = &self.tree[item_tree];

self.insert_scope(parent_scope, scope, module.name.clone(), module_id);
insert_modulle_builtin_scope(&mut self.map.scopes[scope].declarations);
insert_module_builtin_scope(&mut self.map.scopes[scope].declarations);

for item in &module.items {
match *item {
Expand Down
2 changes: 1 addition & 1 deletion openvaf/hir_lower/src/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl CallBackKind {
has_sideeffects: false,
},
CallBackKind::FlickerNoise { name, .. } => FunctionSignature {
name: format!("flickr_noise({name:?})"),
name: format!("flicker_noise({name:?})"),
params: 2,
returns: 1,
has_sideeffects: false,
Expand Down
2 changes: 1 addition & 1 deletion openvaf/hir_lower/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl<'a, 'c> LoweringCtx<'a, 'c> {
val
}

pub fn implicit_eqation(&mut self, kind: ImplicitEquationKind) -> (ImplicitEquation, Value) {
pub fn implicit_equation(&mut self, kind: ImplicitEquationKind) -> (ImplicitEquation, Value) {
let equation = self.intern.implicit_equations.push_and_get_key(kind);
let place = self.dec_place(PlaceKind::CollapseImplicitEquation(equation));
self.func.def_var(place, FALSE);
Expand Down
15 changes: 8 additions & 7 deletions openvaf/hir_lower/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use hir::signatures::{
NATURE_ACCESS_NODE_GND, NATURE_ACCESS_PORT_FLOW, REAL_EQ, REAL_OP, SIMPARAM_DEFAULT,
SIMPARAM_NO_DEFAULT, STR_EQ,
};
use hir::{Body, BuiltIn, Expr, ExprId, Literal, ParamSysFun, Ref, ResolvedFun, Type};
use hir::{Body, BuiltIn, Expr, ExprId, Literal, Ref, ResolvedFun, Type};
use mir::builder::InstBuilder;
use mir::{Opcode, Value, FALSE, F_ZERO, GRAVESTONE, INFINITY, TRUE, ZERO};
use mir_build::RetBuilder;
Expand Down Expand Up @@ -564,8 +564,9 @@ impl BodyLoweringCtx<'_, '_, '_> {
CurrentKind::Port(self.body.into_port_flow(args[0]))
))
};
let mfactor = self.ctx.use_param(ParamKind::ParamSysFun(ParamSysFun::mfactor));
return self.ctx.ins().fdiv(res, mfactor);
//let mfactor = self.ctx.use_param(ParamKind::ParamSysFun(ParamSysFun::mfactor));
//return self.ctx.ins().fdiv(res, mfactor);
return res;
}
BuiltIn::potential => {
match_signature! {
Expand Down Expand Up @@ -663,12 +664,12 @@ impl BodyLoweringCtx<'_, '_, '_> {
}
BuiltIn::finish | BuiltIn::stop => GRAVESTONE,

/* TODO: absdealy
/* TODO: absdelay
BuiltIn::absdelay => {
let arg = self.lower_expr(args[0]);
let mut delay = self.lower_expr(args[1]);
let (eq1, res) = self.ctx.implicit_eqation(ImplicitEquationKind::Absdelay);
let (eq2, intermediate) = self.ctx.implicit_eqation(ImplicitEquationKind::Absdelay);
let (eq1, res) = self.ctx.implicit_equation(ImplicitEquationKind::Absdelay);
let (eq2, intermediate) = self.ctx.implicit_equation(ImplicitEquationKind::Absdelay);
if signature == ABSDELAY_MAX {
let max_delay = self.lower_expr(args[2]);
let use_delay = self.ctx.ins().fle(delay, max_delay);
Expand Down Expand Up @@ -699,7 +700,7 @@ impl BodyLoweringCtx<'_, '_, '_> {
}

fn lower_integral(&mut self, kind: IdtKind, args: &[ExprId]) -> Value {
let (equation, val) = self.ctx.implicit_eqation(ImplicitEquationKind::Idt(kind));
let (equation, val) = self.ctx.implicit_equation(ImplicitEquationKind::Idt(kind));

let mut enable_integral = self.ctx.use_param(ParamKind::EnableIntegration);
let residual = if kind.has_ic() {
Expand Down
10 changes: 7 additions & 3 deletions openvaf/hir_ty/src/inference.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,9 @@ impl Ctx<'_> {
}

BuiltIn::limit => {
infere_args = &args[0..2];
if args.len() >= 2 {
infere_args = &args[0..2];
}
Cow::Borrowed(TiSlice::from_ref(info.signatures))
}

Expand Down Expand Up @@ -787,11 +789,13 @@ impl Ctx<'_> {
self.result.diagnostics.push(InferenceDiagnostic::ExpectedProbe { e: probe })
}

if let Some(Ty::UserFunction(func)) = self.result.expr_types.get(args[1]).cloned() {
if args.len() == 1 {
// only one argument (no limit function specified)
} else if let Some(Ty::UserFunction(func)) = self.result.expr_types.get(args[1]).cloned() {
debug_assert_eq!(sig, LIMIT_USER_FUNCTION);
let fun_info = self.db.function_data(func);

// user-function needs two extra arguments but $limit also accepts two accepts that are
// user-function needs two extra arguments but $limit also accepts two arguments that are
// not passed directly to the function so these must just be equal
if fun_info.args.len() != args.len() {
self.result.diagnostics.push(InferenceDiagnostic::ArgCntMismatch {
Expand Down
10 changes: 0 additions & 10 deletions openvaf/mir/src/dominators.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ use bitset::SparseBitMatrix;
use stdx::packed_option::PackedOption;
use typed_index_collections::{TiSlice, TiVec};

trait CfgREVERSE {
type Successors;
type Predecessors;

fn successors(cfg: &ControlFlowGraph, bb: Block) -> Self::Successors;
fn predecessors(cfg: &ControlFlowGraph, bb: Block) -> Self::Successors;
}

trait ToIter {}

#[derive(Debug, Clone, PartialEq, Eq)]
struct DomTreeNode {
/// Number of this node in a (reverse) post-order traversal of the CFG, starting from 1.
Expand Down
15 changes: 0 additions & 15 deletions openvaf/mir/src/write.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -345,21 +345,6 @@ impl<'a> fmt::Display for DisplayValues<'a> {
}
}

struct DisplayValuesWithDelimiter<'a>(&'a [Value], char);

impl<'a> fmt::Display for DisplayValuesWithDelimiter<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for (i, val) in self.0.iter().enumerate() {
if i == 0 {
write!(f, "{}", val)?;
} else {
write!(f, "{}{}", self.1, val)?;
}
}
Ok(())
}
}

/// A lasso resolver that always returns `"<DUMMY>"`.
/// Mainly useful for debugging
pub struct DummyResolver;
Expand Down
3 changes: 2 additions & 1 deletion openvaf/mir_autodiff/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,8 @@ impl<'a, 'u> DerivativeBuilder<'a, 'u> {

// Technically not required but makes code look nicer..
// exp(x) -> exp(x)
Opcode::Exp => res,
//Opcode::Exp => res,
Opcode::Exp => self.ins().exp(arg0),

// hypot(x,y) -> (x' + y')/2hypot(x,y)
// sqrt(x) -> 1/2sqrt(x)
Expand Down
21 changes: 1 addition & 20 deletions openvaf/mir_opt/src/simplify_cfg.rs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::hash::{Hash, Hasher};
use std::iter::repeat;

use bitset::BitSet;
use mir::{Block, ControlFlowGraph, Function, InstructionData, Value, ValueDef, FALSE, TRUE};
use mir::{Block, ControlFlowGraph, Function, InstructionData, ValueDef, FALSE, TRUE};

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -634,21 +633,3 @@ impl<'a> SimplifyCfg<'a> {
}
}
}

#[derive(Clone)]
struct ResolvedPhi<I> {
vals: I,
}
impl<I: Iterator<Item = Value> + Clone> Hash for ResolvedPhi<I> {
fn hash<H: Hasher>(&self, state: &mut H) {
for val in self.vals.clone() {
val.hash(state)
}
}
}
impl<I: Iterator<Item = Value> + Clone> PartialEq for ResolvedPhi<I> {
fn eq(&self, other: &Self) -> bool {
self.vals.clone().eq(other.vals.clone())
}
}
impl<I: Iterator<Item = Value> + Clone> Eq for ResolvedPhi<I> {}
2 changes: 1 addition & 1 deletion openvaf/osdi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn tracked_env_var_os<K: AsRef<OsStr> + Display>(key: K) -> Option<OsString> {

fn main() {
// If we're just running `check`, there's no need to actually compute the stdlib just
// popualte dummys
// populate dummies
let no_gen = tracked_env_var_os("RUST_CHECK").is_some();
let sh = Shell::new().unwrap();
let osdi_dir = stdx::project_root().join("openvaf").join("osdi");
Expand Down
1 change: 0 additions & 1 deletion openvaf/osdi/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ impl<'ll> OsdiCompilationUnit<'_, '_, 'll> {
hi
}
}
// TODO support abstime
ParamKind::Current(CurrentKind::Port(_)) => cx.const_real(0.0),
ParamKind::Abstime => {
let loc = MemLoc::struct_gep(
Expand Down
3 changes: 2 additions & 1 deletion openvaf/osdi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn compile(
mir
})
.collect();
let name = dst.file_stem().expect("destition is a file").to_owned();
let name = dst.file_stem().expect("destination is a file").to_owned();

let mut paths: Vec<Utf8PathBuf> = (0..modules.len() * 4)
.map(|i| {
Expand Down Expand Up @@ -240,6 +240,7 @@ impl OsdiModule<'_> {
literals.get_or_intern_static("Multiplier (Verilog-A $mfactor)");
literals.get_or_intern_static("deg");
literals.get_or_intern_static("m");
literals.get_or_intern_static("");

for param in self.info.params.values() {
for alias in &param.alias {
Expand Down
11 changes: 10 additions & 1 deletion openvaf/parser/src/grammar/items.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,16 @@ fn constraint(p: &mut Parser) {
m.abandon(p);
return;
}
range_or_expr(p);
if p.eat(T!["'{"]) || p.eat(T!['{']) {
// array range (for string parameters)
expr(p);
while p.eat(T![,]) {
expr(p);
}
p.expect(T!['}']);
} else {
range_or_expr(p);
}
m.complete(p, CONSTRAINT);
}

Expand Down
Loading