CIRCT  19.0.0git
Engine.h
Go to the documentation of this file.
1 //===- Engine.h - LLHD simulaton engine -------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the main Engine class of the LLHD simulator.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef CIRCT_DIALECT_LLHD_SIMULATOR_ENGINE_H
14 #define CIRCT_DIALECT_LLHD_SIMULATOR_ENGINE_H
15 
16 #include "State.h"
17 #include "Trace.h"
18 
20 #include "mlir/IR/BuiltinOps.h"
21 
22 namespace mlir {
23 class ExecutionEngine;
24 } // namespace mlir
25 
26 namespace llvm {
27 class Error;
28 class Module;
29 } // namespace llvm
30 
31 namespace circt {
32 namespace llhd {
33 namespace sim {
34 
35 class Engine {
36 public:
37  /// Initialize an LLHD simulation engine. This initializes the state, as well
38  /// as the mlir::ExecutionEngine with the given module.
39  Engine(
40  llvm::raw_ostream &out, ModuleOp module,
41  llvm::function_ref<mlir::LogicalResult(mlir::ModuleOp)> mlirTransformer,
42  llvm::function_ref<llvm::Error(llvm::Module *)> llvmTransformer,
43  std::string root, TraceMode tm, ArrayRef<StringRef> sharedLibPaths);
44 
45  /// Default destructor
47 
48  /// Run simulation up to n steps or maxTime picoseconds of simulation time.
49  /// n=0 and T=0 make the simulation run indefinitely.
50  int simulate(int n, uint64_t maxTime);
51 
52  /// Build the instance layout of the design.
53  void buildLayout(ModuleOp module);
54 
55  /// Get the MLIR module.
56  const ModuleOp getModule() const { return module; }
57 
58  /// Get the simulation state.
59  const State *getState() const { return state.get(); }
60 
61  /// Dump the instance layout stored in the State.
62  void dumpStateLayout();
63 
64  /// Dump the instances each signal triggers.
66 
67 private:
68  void walkEntity(EntityOp entity, Instance &child);
69 
70  llvm::raw_ostream &out;
71  std::string root;
72  std::unique_ptr<State> state;
73  std::unique_ptr<mlir::ExecutionEngine> engine;
74  ModuleOp module;
76 };
77 
78 } // namespace sim
79 } // namespace llhd
80 } // namespace circt
81 
82 #endif // CIRCT_DIALECT_LLHD_SIMULATOR_ENGINE_H
void dumpStateLayout()
Dump the instance layout stored in the State.
Definition: Engine.cpp:63
void walkEntity(EntityOp entity, Instance &child)
Definition: Engine.cpp:245
const State * getState() const
Get the simulation state.
Definition: Engine.h:59
Engine(llvm::raw_ostream &out, ModuleOp module, llvm::function_ref< mlir::LogicalResult(mlir::ModuleOp)> mlirTransformer, llvm::function_ref< llvm::Error(llvm::Module *)> llvmTransformer, std::string root, TraceMode tm, ArrayRef< StringRef > sharedLibPaths)
Initialize an LLHD simulation engine.
Definition: Engine.cpp:23
std::string root
Definition: Engine.h:71
TraceMode traceMode
Definition: Engine.h:75
llvm::raw_ostream & out
Definition: Engine.h:70
const ModuleOp getModule() const
Get the MLIR module.
Definition: Engine.h:56
~Engine()
Default destructor.
void buildLayout(ModuleOp module)
Build the instance layout of the design.
Definition: Engine.cpp:217
std::unique_ptr< mlir::ExecutionEngine > engine
Definition: Engine.h:73
std::unique_ptr< State > state
Definition: Engine.h:72
int simulate(int n, uint64_t maxTime)
Run simulation up to n steps or maxTime picoseconds of simulation time.
Definition: Engine.cpp:67
void dumpStateSignalTriggers()
Dump the instances each signal triggers.
Definition: Engine.cpp:65
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
Definition: DebugAnalysis.h:21
The simulator internal representation of an instance.
Definition: State.h:277
The simulator's state.
Definition: State.h:306