Skip to content

Commit

Permalink
kernel: Avoid including files outside include guards
Browse files Browse the repository at this point in the history
This adjusts the way the headers kernel/{yosys,rtlil,register,log}.h
include each other to avoid the need of including headers outside of
include guards as well as avoiding the inclusion of rtlil.h in the
middle of yosys.h with rtlil.h depending on the prefix of yosys.h, and
the suffix of yosys.h depending on rtlil.h.

To do this I moved some of the declaration in yosys.h into a new header
yosys_common.h. I'm not sure if that is strictly necessary.

Including any of these files still results in the declarations of all
these headers being included, so this shouldn't be a breaking change for
any passes or external plugins.

My main motivation for this is that ccls's (clang based language server)
include guard handling gets confused by the previous way the includes
were done. It often ends up treating the include guard as a generic
disabled preprocessor conditional, breaking navigation and highlighting
for the core RTLIL data structures.

Additionally I think avoiding cyclic includes in the middle of header
files that depend on includes being outside of include guards will also
be less confusing for developers reading the code, not only for tools
like ccls.
  • Loading branch information
jix committed Apr 2, 2024
1 parent 9417038 commit d8687e8
Show file tree
Hide file tree
Showing 6 changed files with 391 additions and 351 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ $(eval $(call add_include_file,kernel/sigtools.h))
$(eval $(call add_include_file,kernel/timinginfo.h))
$(eval $(call add_include_file,kernel/utils.h))
$(eval $(call add_include_file,kernel/yosys.h))
$(eval $(call add_include_file,kernel/yosys_common.h))
$(eval $(call add_include_file,kernel/yw.h))
$(eval $(call add_include_file,libs/ezsat/ezsat.h))
$(eval $(call add_include_file,libs/ezsat/ezminisat.h))
Expand Down
6 changes: 4 additions & 2 deletions kernel/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
*
*/

#include "kernel/yosys.h"

#ifndef LOG_H
#define LOG_H

#include "kernel/yosys_common.h"

#include <time.h>

#include <regex>
Expand Down Expand Up @@ -449,4 +449,6 @@ void log_dump_args_worker(const char *p, T first, Args ... args)

YOSYS_NAMESPACE_END

#include "kernel/yosys.h"

#endif
5 changes: 3 additions & 2 deletions kernel/register.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
*
*/

#include "kernel/yosys.h"

#ifndef REGISTER_H
#define REGISTER_H

#include "kernel/yosys_common.h"
#include "kernel/yosys.h"

YOSYS_NAMESPACE_BEGIN

struct Pass
Expand Down
5 changes: 3 additions & 2 deletions kernel/rtlil.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
*
*/

#include "kernel/yosys.h"

#ifndef RTLIL_H
#define RTLIL_H

#include "kernel/yosys_common.h"
#include "kernel/yosys.h"

YOSYS_NAMESPACE_BEGIN

namespace RTLIL
Expand Down
Loading

0 comments on commit d8687e8

Please sign in to comment.