pascalkuthe / OpenVAF

An innovative Verilog-A compiler
https://openvaf.semimod.de/
GNU General Public License v3.0
113 stars 15 forks source link

Cannot compile if `.va` file does not have `parameter` #103

Open mfkasim1 opened 7 months ago

mfkasim1 commented 7 months ago

I tried compiling a simple Verilog-A for a capacitor. However, if the file does not have a parameter, it will raise an error. The error can be solved by simply adding a dummy parameter (even though the parameter is useless). Here's an example of the Verilog-A file:

`include "disciplines.vams"
`include "constants.vams"

module mycapacitor (p,n);
  electrical p, n;
  inout p, n;

  // parameter real D=1p from (0:inf);  // uncommenting this line would solve the error
  real Q;
  real C = 1p;

  analog
  begin
    Q = C * V(p, n);
    I(p, n) <+ ddt(Q);
  end
endmodule

And here's the content of the log file:

OpenVAF 23.5.0
Opts {
    defines: [],
    codegen_opts: [],
    lints: [],
    input: "02-mycap.va",
    output: Path {
        lib_file: "02-mycap.osdi",
    },
    include: [],
    opt_lvl: Aggressive,
    target: Target {
        llvm_target: "x86_64-unknown-linux-gnu",
        pointer_width: 64,
        arch: "x86_64",
        data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
        options: TargetOptions {
            is_builtin: true,
            cpu: "x86-64",
            features: "",
            linker_flavor: Ld,
            pre_link_args: {
                Ld: [
                    "--no-add-needed",
                    "--hash-style=gnu",
                    "-m",
                    "elf_x86_64",
                ],
            },
            post_link_args: {},
            import_lib: [],
            is_like_windows: false,
            is_like_osx: false,
        },
    },
    target_cpu: "native",
}
Panic occurred in file 'openvaf/mir_llvm/src/context.rs' at line 83
called `Option::unwrap()` on a `None` value
   0: 0x5574cdb423d9 - rust_begin_unwind
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:584
   0: 0x5574cdb65523 - core::panicking::panic_fmt::ha6dc7f2ab2479463
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panicking.rs:142
   0: 0x5574cdb6536d - core::panicking::panic::hb3ad04c589a0e3c8
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panicking.rs:48
   0..   2: 0x5574cba107c6 - core::option::Option<T>::unwrap::h47c9143d060d0350
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/option.rs:775
                 - mir_llvm::context::CodegenCx::const_str_uninterned::hcabc88e94ae421e5
                at /root/project/openvaf/mir_llvm/src/context.rs:83
   0..   5: 0x5574cb7df3c6 - osdi::metadata::osdi_0_3::OsdiNode::to_ll_val::h8dc42151ca46ac19
                at /root/project/openvaf/osdi/src/metadata/osdi_0_3.rs:216
                 - osdi::metadata::osdi_0_3::OsdiDescriptor::to_ll_val::{{closure}}::h50d02bee2d0f8caf
                at /root/project/openvaf/osdi/src/metadata/osdi_0_3.rs:335
                 - core::iter::adapters::map::map_fold::{{closure}}::h0d6aa070a80e4819
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/iter/adapters/map.rs:84
                 - core::iter::traits::iterator::Iterator::fold::h5fb564515f03fd2d
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/iter/traits/iterator.rs:2414
                 - <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold::he2deacfe4189ddc6
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/iter/adapters/map.rs:124
   0..   4: 0x5574cb7cba03 - core::iter::traits::iterator::Iterator::for_each::h848a69d586f32e23
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/iter/traits/iterator.rs:831
                 - <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend::hf8ff82acc6bde871
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/alloc/src/vec/spec_extend.rs:40
                 - <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter::h17d58025c611b0e1
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/alloc/src/vec/spec_from_iter_nested.rs:62
                 - <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter::he36f49a9fb932f2d
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/alloc/src/vec/spec_from_iter.rs:33
   0..   7: 0x5574cb7deb18 - <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter::he5e7135d37d83c93
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/alloc/src/vec/mod.rs:2648
                 - core::iter::traits::iterator::Iterator::collect::hdb4db2cd9b563194
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/iter/traits/iterator.rs:1836
                 - osdi::metadata::osdi_0_3::OsdiDescriptor::to_ll_val::h61cb5222e5d11904
                at /root/project/openvaf/osdi/src/metadata/osdi_0_3.rs:335
                 - osdi::compile::{{closure}}::{{closure}}::hedbdc66cc2f2040c
                at /root/project/openvaf/osdi/src/lib.rs:171
                 - core::iter::adapters::map::map_fold::{{closure}}::he6294f91e2e9775c
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/iter/adapters/map.rs:84
                 - core::iter::traits::iterator::Iterator::fold::ha95d92ce4cdc0cd8
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/iter/traits/iterator.rs:2414
                 - <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold::hd9dff5a0225336be
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/iter/adapters/map.rs:124
   0..   4: 0x5574cb7ca64d - core::iter::traits::iterator::Iterator::for_each::hbf505b049b535509
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/iter/traits/iterator.rs:831
                 - <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend::hf7dbafcec3b77463
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/alloc/src/vec/spec_extend.rs:40
                 - <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter::h88a58159089d095a
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/alloc/src/vec/spec_from_iter_nested.rs:62
                 - <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter::h8a92569f08192928
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/alloc/src/vec/spec_from_iter.rs:33
   0..   7: 0x5574cb7977e4 - <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter::h69e6599d5105b251
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/alloc/src/vec/mod.rs:2648
                 - core::iter::traits::iterator::Iterator::collect::hfbfc271b758eb0e7
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/iter/traits/iterator.rs:1836
                 - osdi::compile::{{closure}}::h12de1a1fc92fce45
                at /root/project/openvaf/osdi/src/lib.rs:166
                 - rayon_core::scope::scope::{{closure}}::{{closure}}::hc3d49eea6c6f2faa
                at /root/project/vendor/rayon-core/src/scope/mod.rs:311
                 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::hd255d3c8acff5a71
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panic/unwind_safe.rs:271
                 - std::panicking::try::do_call::hee3f8b894d7429ae
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:492
                 - std::panicking::try::he5591eee798bd1b9
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:456
   0: 0x5574cb79cdf6 - std::panic::catch_unwind::hdcc91608821df65b
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panic.rs:137
   0: 0x5574cb7bf3a6 - rayon_core::unwind::halt_unwinding::h0d5a2e4d10f9c196
                at /root/project/vendor/rayon-core/src/unwind.rs:17
   0..   2: 0x5574cb79c6e3 - rayon_core::scope::ScopeBase::execute_job_closure::h33ecc2e5ee9c55c1
                at /root/project/vendor/rayon-core/src/scope/mod.rs:713
                 - rayon_core::scope::ScopeBase::complete::h0e04d19fd631138a
                at /root/project/vendor/rayon-core/src/scope/mod.rs:691
   0: 0x5574cb795f10 - rayon_core::scope::scope::{{closure}}::h15634e8598fb387d
                at /root/project/vendor/rayon-core/src/scope/mod.rs:311
   0..   5: 0x5574cb796c70 - rayon_core::registry::Registry::in_worker_cold::{{closure}}::{{closure}}::hab310d4fff298dc6
                at /root/project/vendor/rayon-core/src/registry.rs:541
                 - rayon_core::job::JobResult<T>::call::{{closure}}::hd22fe81d645247aa
                at /root/project/vendor/rayon-core/src/job.rs:218
                 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::hfe8eeae5d465525d
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panic/unwind_safe.rs:271
                 - std::panicking::try::do_call::ha63cae3f2fed2601
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:492
                 - std::panicking::try::h2319df3cffae47b2
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:456
   0: 0x5574cb79cd84 - std::panic::catch_unwind::ha2733c84503a87ca
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panic.rs:137
   0: 0x5574cb7bf4c4 - rayon_core::unwind::halt_unwinding::h518e83fcc0f0f091
                at /root/project/vendor/rayon-core/src/unwind.rs:17
   0..   2: 0x5574cb79e4ab - rayon_core::job::JobResult<T>::call::h526ca128ef426e44
                at /root/project/vendor/rayon-core/src/job.rs:218
                 - <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute::hc5e53551636bbb56
                at /root/project/vendor/rayon-core/src/job.rs:120
   0..   3: 0x5574cb7f8df5 - rayon_core::job::JobRef::execute::hd11389873f126f2b
                at /root/project/vendor/rayon-core/src/job.rs:64
                 - rayon_core::registry::WorkerThread::execute::hd471ca85cef13df3
                at /root/project/vendor/rayon-core/src/registry.rs:874
                 - rayon_core::registry::WorkerThread::wait_until_cold::h7b7483b3044a671d
                at /root/project/vendor/rayon-core/src/registry.rs:820
   0..   3: 0x5574cb7f68e9 - rayon_core::registry::WorkerThread::wait_until::h738b3a6e29f6f187
                at /root/project/vendor/rayon-core/src/registry.rs:803
                 - rayon_core::registry::main_loop::h326959b63dfe9b95
                at /root/project/vendor/rayon-core/src/registry.rs:948
                 - rayon_core::registry::ThreadBuilder::run::he1cd9f5104020c8e
                at /root/project/vendor/rayon-core/src/registry.rs:54
   0: 0x5574cb80037a - <rayon_core::registry::DefaultSpawn as rayon_core::registry::ThreadSpawn>::spawn::{{closure}}::hcc83daca173cc139
                at /root/project/vendor/rayon-core/src/registry.rs:99
                 - std::sys_common::backtrace::__rust_begin_short_backtrace::h1c91c9e680a6d48d
                at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/sys_common/backtrace.rs:122
gjcoram commented 2 months ago

The Compact Model Coalition has a set of Verilog-A files for validating the compiler/simulator. About 40 of the 90 modules have no parameters declared, so OpenVAF crashes. It would be nice to get this fixed.

gjcoram commented 1 month ago

This is kind of weird. From the stack trace, the error seems to be coming from OsdiNode::to_ll_val

5: 0x5574cb7df3c6 - osdi::metadata::osdi_0_3::OsdiNode::to_ll_val::h8dc42151ca46ac19 at /root/project/openvaf/osdi/src/metadata/osdi_0_3.rs:216

Line 216 is converting the residual_units of the OsdiNode: ctx.const_str_uninternetd(&self.residual_units),

Why is this a problem when there is no parameter in the module?

gjcoram commented 1 month ago

% git diff openvaf/mir_llvm/src/context.rs diff --git a/openvaf/mir_llvm/src/context.rs b/openvaf/mir_llvm/src/context.rs index cf4f71f..953d825 100644 --- a/openvaf/mir_llvm/src/context.rs +++ b/openvaf/mir_llvm/src/context.rs @@ -80,7 +80,7 @@ impl<'a, 'll> CodegenCx<'a, 'll> { }

    pub fn const_str_uninterned(&self, lit: &str) -> &'ll Value {
-        let lit = self.literals.get(lit).unwrap();
+        let lit = self.literals.get(lit).unwrap_or_default();
         self.const_str(lit)
     }