1245803Stheraven$FreeBSD: releng/11.0/usr.bin/dtc/HACKING 289996 2015-10-26 11:02:57Z theraven $
2245803Stheraven
3245803StheravenNotes for people hacking on dtc
4245803Stheraven===============================
5245803Stheraven
6245803StheravenThis file contains some notes for people wishing to hack on dtc.
7245803Stheraven
8245803StheravenUpstreaming
9245803Stheraven-----------
10245803Stheraven
11245803StheravenThis code is developed in the FreeBSD svn repository:
12245803Stheraven
13245803Stheravenhttps://svn.freebsd.org/base/head/usr.bin/dtc
14245803Stheraven
15245803StheravenIf you got the source from anywhere else and wish to make changes, please
16245803Stheravenensure that you are working against the latest version, or you may end up
17245803Stheravenfixing bugs that are already fixed upstream.  Although the license makes no
18245803Stheravenrequirement that you share any improvements that you make, patches are very
19245803Stheravenwelcome.
20245803Stheraven
21245803StheravenC++11
22245803Stheraven-----
23245803Stheraven
24289996StheravenThis project uses C++11, as the goal for FreeBSD 11 is to require C/C++11 as a
25289996Stheravenminimum, either from clang or an external toolchain.  In particular, it uses
26289996Stheraven`std::unique_ptr` extensively for memory management within the tree.  Unique
27289996Stheravenpointers are also used in several other places to track ownership.
28245803Stheraven
29289996StheravenMost iterator loops use the new loop syntax and the `auto` type for type
30289996Stheravendeduction.  Range-based `for` loops generally improve the readability of the
31289996Stheravencode, though `auto` should only be used in places where the type can be deduced
32289996Stheravenas easily by the reader as by the compiler.
33245803Stheraven
34289996StheravenThe code also makes use of `static_assert()` to track compile-time invariants.
35245803Stheraven
36245803StheravenAdding New Checks
37245803Stheraven-----------------
38245803Stheraven
39245803StheravenCurrently, the biggest weakness of this version of the tool is that it lacks
40245803Stheravenmost of the semantic checkers that can be implemented by simply reading the
41245803StheravenePAPR spec.  The `checker` class provides a simple superclass for implementing
42245803Stheraventhese quite easily.  There are also helper methods on `device_tree` for finding
43245803Stheravenspecific nodes, for checks that require some understanding of the structure of
44245803Stheraventhe tree.
45245803Stheraven
46245803StheravenWe should probably add a parent pointer to the `node` class for easily walking
47245803Stheravenup the tree.
48245803Stheraven
49245803StheravenAdding Direct C Output
50245803Stheraven----------------------
51245803Stheraven
52245803StheravenThe FreeBSD build system currently uses dtc to generate a blob and then
53245803Stheravenconverts this to C source code.  A new `output_writer` subclass could easily
54245803Stheravengenerate the C directly.
55245803Stheraven
56245803StheravenParser Improvements
57245803Stheraven-------------------
58245803Stheraven
59245803StheravenThere are a few FIXME lines in the parser for some corner cases that are not
60245803Stheravencurrently used by FreeBSD.  These are mainly related to labels in the middle of
61245803Stheravenvalues.  These can be fixed by creating a new `property_value` with the
62245803Stheravenspecified label, starting at the location of the label.  Don't forget to remove
63245803Stheraventhe associated comments from the BUGS section of the man page if you fix this.
64