xref: /freebsd/usr.bin/dtc/HACKING (revision 29a55fd09b0a3cc4c888f7a630fde41694699343)
1af0dd31fSDavid ChisnallNotes for people hacking on dtc
2af0dd31fSDavid Chisnall===============================
3af0dd31fSDavid Chisnall
4af0dd31fSDavid ChisnallThis file contains some notes for people wishing to hack on dtc.
5af0dd31fSDavid Chisnall
6af0dd31fSDavid ChisnallUpstreaming
7af0dd31fSDavid Chisnall-----------
8af0dd31fSDavid Chisnall
9*67b60a1bSKyle EvansThis code is developed in the git repository:
10af0dd31fSDavid Chisnall
11*67b60a1bSKyle Evanshttps://github.com/davidchisnall/dtc
12af0dd31fSDavid Chisnall
13af0dd31fSDavid ChisnallIf you got the source from anywhere else and wish to make changes, please
14af0dd31fSDavid Chisnallensure that you are working against the latest version, or you may end up
15af0dd31fSDavid Chisnallfixing bugs that are already fixed upstream.  Although the license makes no
16af0dd31fSDavid Chisnallrequirement that you share any improvements that you make, patches are very
17af0dd31fSDavid Chisnallwelcome.
18af0dd31fSDavid Chisnall
19af0dd31fSDavid ChisnallC++11
20af0dd31fSDavid Chisnall-----
21af0dd31fSDavid Chisnall
2270d7ec67SDavid ChisnallThis project uses C++11, as the goal for FreeBSD 11 is to require C/C++11 as a
2370d7ec67SDavid Chisnallminimum, either from clang or an external toolchain.  In particular, it uses
2470d7ec67SDavid Chisnall`std::unique_ptr` extensively for memory management within the tree.  Unique
2570d7ec67SDavid Chisnallpointers are also used in several other places to track ownership.
26af0dd31fSDavid Chisnall
2770d7ec67SDavid ChisnallMost iterator loops use the new loop syntax and the `auto` type for type
2870d7ec67SDavid Chisnalldeduction.  Range-based `for` loops generally improve the readability of the
2970d7ec67SDavid Chisnallcode, though `auto` should only be used in places where the type can be deduced
3070d7ec67SDavid Chisnallas easily by the reader as by the compiler.
31af0dd31fSDavid Chisnall
3270d7ec67SDavid ChisnallThe code also makes use of `static_assert()` to track compile-time invariants.
33af0dd31fSDavid Chisnall
34af0dd31fSDavid ChisnallAdding New Checks
35af0dd31fSDavid Chisnall-----------------
36af0dd31fSDavid Chisnall
37af0dd31fSDavid ChisnallCurrently, the biggest weakness of this version of the tool is that it lacks
38af0dd31fSDavid Chisnallmost of the semantic checkers that can be implemented by simply reading the
39af0dd31fSDavid ChisnallePAPR spec.  The `checker` class provides a simple superclass for implementing
40af0dd31fSDavid Chisnallthese quite easily.  There are also helper methods on `device_tree` for finding
41af0dd31fSDavid Chisnallspecific nodes, for checks that require some understanding of the structure of
42af0dd31fSDavid Chisnallthe tree.
43af0dd31fSDavid Chisnall
44af0dd31fSDavid ChisnallWe should probably add a parent pointer to the `node` class for easily walking
45af0dd31fSDavid Chisnallup the tree.
46af0dd31fSDavid Chisnall
47af0dd31fSDavid ChisnallAdding Direct C Output
48af0dd31fSDavid Chisnall----------------------
49af0dd31fSDavid Chisnall
50af0dd31fSDavid ChisnallThe FreeBSD build system currently uses dtc to generate a blob and then
51af0dd31fSDavid Chisnallconverts this to C source code.  A new `output_writer` subclass could easily
52af0dd31fSDavid Chisnallgenerate the C directly.
53af0dd31fSDavid Chisnall
54af0dd31fSDavid ChisnallParser Improvements
55af0dd31fSDavid Chisnall-------------------
56af0dd31fSDavid Chisnall
57af0dd31fSDavid ChisnallThere are a few FIXME lines in the parser for some corner cases that are not
58af0dd31fSDavid Chisnallcurrently used by FreeBSD.  These are mainly related to labels in the middle of
59af0dd31fSDavid Chisnallvalues.  These can be fixed by creating a new `property_value` with the
60af0dd31fSDavid Chisnallspecified label, starting at the location of the label.  Don't forget to remove
61af0dd31fSDavid Chisnallthe associated comments from the BUGS section of the man page if you fix this.
62