yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
proc_init.cc File Reference
#include "kernel/register.h"
#include "kernel/sigtools.h"
#include "kernel/log.h"
#include <stdlib.h>
#include <stdio.h>
+ Include dependency graph for proc_init.cc:

Go to the source code of this file.

Data Structures

struct  ProcInitPass
 

Functions

USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN void 
proc_get_const (RTLIL::SigSpec &sig, RTLIL::CaseRule &rule)
 
void proc_init (RTLIL::Module *mod, RTLIL::Process *proc)
 

Variables

ProcInitPass ProcInitPass
 

Function Documentation

USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN void proc_get_const ( RTLIL::SigSpec sig,
RTLIL::CaseRule rule 
)

Definition at line 29 of file proc_init.cc.

30 {
31  log_assert(rule.compare.size() == 0);
32 
33  while (1) {
34  RTLIL::SigSpec tmp = sig;
35  for (auto &it : rule.actions)
36  tmp.replace(it.first, it.second);
37  if (tmp == sig)
38  break;
39  sig = tmp;
40  }
41 }
std::vector< RTLIL::SigSpec > compare
Definition: rtlil.h:1119
#define log_assert(_assert_expr_)
Definition: log.h:85
void replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with)
Definition: rtlil.cc:2297
std::vector< RTLIL::SigSig > actions
Definition: rtlil.h:1120

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void proc_init ( RTLIL::Module mod,
RTLIL::Process proc 
)

Definition at line 43 of file proc_init.cc.

44 {
45  bool found_init = false;
46 
47  for (auto &sync : proc->syncs)
48  if (sync->type == RTLIL::SyncType::STi)
49  {
50  found_init = true;
51  log("Found init rule in `%s.%s'.\n", mod->name.c_str(), proc->name.c_str());
52 
53  for (auto &action : sync->actions)
54  {
55  RTLIL::SigSpec lhs = action.first;
56  RTLIL::SigSpec rhs = action.second;
57 
58  proc_get_const(rhs, proc->root_case);
59 
60  if (!rhs.is_fully_const())
61  log_cmd_error("Failed to get a constant init value for %s: %s\n", log_signal(lhs), log_signal(rhs));
62 
63  int offset = 0;
64  for (auto &lhs_c : lhs.chunks()) {
65  if (lhs_c.wire != NULL) {
66  RTLIL::SigSpec value = rhs.extract(offset, lhs_c.width);
67  if (value.size() != lhs_c.wire->width)
68  log_cmd_error("Init value is not for the entire wire: %s = %s\n", log_signal(lhs_c), log_signal(value));
69  log(" Setting init value: %s = %s\n", log_signal(lhs_c.wire), log_signal(value));
70  lhs_c.wire->attributes["\\init"] = value.as_const();
71  }
72  offset += lhs_c.width;
73  }
74  }
75  }
76 
77  if (found_init) {
78  std::vector<RTLIL::SyncRule*> new_syncs;
79  for (auto &sync : proc->syncs)
80  if (sync->type == RTLIL::SyncType::STi)
81  delete sync;
82  else
83  new_syncs.push_back(sync);
84  proc->syncs.swap(new_syncs);
85  }
86 }
const char * c_str() const
Definition: rtlil.h:178
RTLIL::Const as_const() const
Definition: rtlil.cc:2857
const char * log_signal(const RTLIL::SigSpec &sig, bool autoint)
Definition: log.cc:269
int size() const
Definition: rtlil.h:1019
USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN void proc_get_const(RTLIL::SigSpec &sig, RTLIL::CaseRule &rule)
Definition: proc_init.cc:29
bool is_fully_const() const
Definition: rtlil.cc:2763
RTLIL::IdString name
Definition: rtlil.h:599
void log_cmd_error(const char *format,...)
Definition: log.cc:211
RTLIL::IdString name
Definition: rtlil.h:1154
#define NULL
void log(const char *format,...)
Definition: log.cc:180
std::vector< RTLIL::SyncRule * > syncs
Definition: rtlil.h:1157
RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other=NULL) const
Definition: rtlil.cc:2414
const std::vector< RTLIL::SigChunk > & chunks() const
Definition: rtlil.h:1016
RTLIL_ATTRIBUTE_MEMBERS RTLIL::CaseRule root_case
Definition: rtlil.h:1156

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation