Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

Fix issue #428: add blackbox sources to argument of icarus-verilog and vcs #429

Merged
merged 1 commit into from
Nov 1, 2021

Conversation

jiegec
Copy link
Contributor

@jiegec jiegec commented Oct 28, 2021

No description provided.

@jiegec
Copy link
Contributor Author

jiegec commented Oct 28, 2021

It seems that the vcs executable is ran under the project root directory.

Update: FIXED now.

Copy link
Collaborator

@ekiwi ekiwi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for improving the VCS backend. I am looking forward to your responses.

@@ -7,6 +7,7 @@ import firrtl.options.Dependency
import firrtl.stage.RunFirrtlTransformAnnotation
import firrtl.transforms.formal.RemoveVerificationStatements
import firrtl.{AnnotationSeq, CircuitState}
import scala.io.Source
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this import needed for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@@ -120,7 +121,8 @@ private object IcarusSimulator extends Simulator {
val simBinary = relTargetDir / "icarus" / topName
val cmd = List("iverilog") ++ flags ++ List(
"-o",
simBinary.toString(),
simBinary.toString()
) ++ BlackBox.blackBoxSources(targetDir) ++ List(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Icarus supports .f files with the -f option. I would prefer if you could use that to keep things more uniform to how the Verilator backend works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, it is not working. Let me investigate.

Copy link
Contributor Author

@jiegec jiegec Oct 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, the -f option of icarus does not work as expected. The problem is that iverilog expect .f to end with endline. In iverilog 11.0, it silently fails and ignores the file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wow, that sucks

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I submitted a PR to firrtl: chipsalliance/firrtl#2405

@@ -111,7 +111,8 @@ private object VcsSimulator extends Simulator {
annos: AnnotationSeq
): Seq[String] = {
val flags = generateFlags(topName, targetDir, annos)
val cmd = List("vcs") ++ flags ++ List("-o", topName, s"$topName.sv", verilogHarness, "vpi.cpp")
val cmd = List("vcs") ++ flags ++ List("-o", topName) ++
BlackBox.blackBoxSources(targetDir) ++ List(s"$topName.sv", verilogHarness, "vpi.cpp")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does VCS support .f files with the -f flag? If so, please use that approach to stay as close as possible to what we do in the Verilator backend.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes:

-f filename
Specify a file that contains a list of source files and compile-time
options, including C source files and object files.

}

/** finds paths to blackbox sources */
private[chiseltest] def blackBoxSources(targetDir: os.Path): Seq[String] = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this function will not be needed (see comments below)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.


import scala.io.Source

object BlackBox {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please mark this object private

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -90,7 +90,7 @@ private object VcsSimulator extends Simulator {
waveformFlags(toplevel.name, state.annotations)

// the binary we created communicates using our standard IPC interface
new IPCSimulatorContext(simCmd, toplevel, VcsSimulator)
new IPCSimulatorContext(simCmd, targetDir, toplevel, VcsSimulator)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elaborate on why you need VCS to run in the targetDir instead of the os.pwd? The problem here is that the Verilator simulation will always run in os.pwd and thus I would prefer to keep that the same for all simulators to ensure uniform behavior.

Copy link
Contributor Author

@jiegec jiegec Oct 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VCS writes vcd file and ucli.key to cwd, and these files should be put under targetDir.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current master, VCS backend fails with ./topLevel executable not found.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there might be a different solution to this problem. Would you mind putting your second commit in a separate PR? It would be convenient if we could review the two issues separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See pr #430.

@ekiwi
Copy link
Collaborator

ekiwi commented Oct 28, 2021

To elaborate on the issue of where the simulator is run (i.e. what working directory it uses):

  • the Verilator backend will always have the current working directory set to be os.pwd since the simulation is linked into the JVM process
  • for IVerilog and VCS, we could change the current working directory to instead be the target directory
  • however, if depending on the backend, the working directory changes, then a test relying on plusargs and Verilog black boxes might only work with VCS and not with Verilator or vice versa
  • that would defeat the purpose of chiseltest which should allow you to write backend agnostic tests

@jiegec jiegec force-pushed the blackbox-vcs-icarus branch 2 times, most recently from c0a49d6 to a081428 Compare October 29, 2021 00:51
@ekiwi ekiwi added this to the 0.5.0 milestone Oct 29, 2021
@jiegec
Copy link
Contributor Author

jiegec commented Oct 29, 2021

Regarding the icarus issue, possible fixes are:

  1. Append EOL to firrtl_black_box_resource_files.f and pass -f firrtl_black_box_resource_files.f to iverilog
  2. Read firrtl_black_box_resource_f line by line and append blackbox sources to command line

@ekiwi
Copy link
Collaborator

ekiwi commented Oct 29, 2021

Thanks for debugging. I will try address this upstream.

Copy link
Collaborator

@ekiwi ekiwi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get this in and then fix the issue in upstream firrtl.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants