Commit Graph

149 Commits

Author SHA1 Message Date
Thierry Treyer
c1f322dc42 Implement Container V2 for std::unordered_set 2023-08-30 18:45:00 +02:00
Jake Hillion
d009f02ecb name contained types properly in treebuilder v2
Types within containers were previously named TODO. This sorts it out so
they're named as their most resolved type. The current implementation
skips Typedef names.
2023-08-25 16:25:14 +01:00
Thierry Treyer
1459433a50 Implement Container V2 for std::multiset 2023-08-25 16:07:10 +02:00
Thierry Treyer
f9b4d65cd8 Implement Container V2 for std::multimap 2023-08-25 16:07:10 +02:00
Thierry Treyer
19222a4fe2 Implement Container V2 for std::map 2023-08-25 15:13:55 +02:00
Alastair Robertson
03429f3da9 TypeGraph: Remove NodeTracker from the TypeGraph class
The TypeGraph class should only be responsible for storing Type nodes.
Traversing the graph and tracking which nodes have been visited should
not be included there.

Passes now take a NodeTrackerHolder as an input parameter, which
provides access to a zeroed-out NodeTracker.
2023-08-24 15:01:45 +01:00
Thierry Treyer
b8cb81e366 std::set implementation for Container V2 2023-08-24 13:57:27 +02:00
Jake Hillion
5071519e45 oil v2 2023-08-23 15:59:53 +01:00
Jake Hillion
c62fbe371d type_graph: provide inputName for all types
Type Graph deduplicates and modifies names to better fit the generated
code, for example `int32_t[4]` becomes `OIArray<int32_t, 4>` and `struct
MyStruct` might become `struct MyStruct_0`.

Add an `inputName` which better represents the original input code which
can be used when building the tree.
2023-08-18 16:58:21 +01:00
Alastair Robertson
373dbe8f6c TypeGraph: Add option to record enumerator names 2023-08-17 15:47:23 +01:00
Jake Hillion
a2f7462a5d DrgnParser: store type of template param value 2023-08-17 15:40:34 +01:00
Alastair Robertson
ff31971bd3 Printer: Use NodeIds for stable IDs when printing graphs
This removes Printer's legacy behaviour of generating an ID for each
node as it gets printed. This old method meant that if new nodes were
added to or removed from a graph, every ID after the new/removed node
would change.

Now IDs are stable so it is easier to follow specific nodes through
multiple transformation passes in CodeGen.
2023-08-16 12:19:14 +01:00
Alastair Robertson
97ba03620a TypeGraph: Convert unit tests relying on Printer to use TypeGraphParser 2023-08-14 15:01:09 +01:00
Alastair Robertson
e5a83a3a37 TopoSorterTest: Add test for value template params 2023-08-11 10:50:33 +01:00
Alastair Robertson
d45c7f4931 Flattener: Handle incomplete parent types 2023-08-02 14:29:19 +01:00
Alastair Robertson
0612159121 AlignmentCalc: Mark as packed if members are not aligned
We previously only marked as packed if there was no tail padding, which
was not a sufficient condition.

The new AlignmentCalcTest.PackedMembers test case is an example which
would previously not have been marked as packed.
2023-08-02 12:07:52 +01:00
Alastair Robertson
e9975286b2 NameGen: Fix naming of const pointers 2023-08-01 17:53:39 +01:00
Alastair Robertson
6fbb60826f
EnforceCompatibility: Stub out void pointers
CodeGen v1 does not record anything for pointers to incomplete types.
Not even the address, as is done for other pointers.

Introduce a new Primitive type "Incomplete". This behaves identically to
"Void", but allows us to tell whether a type was defined as void or if
it ended up like that because of incomplete DWARF information.
2023-07-31 14:28:05 +01:00
Alastair Robertson
7bb6791af9 AddPadding: Insert padding at the beginning of structs if necessary
This is sometimes needed now that we're removing members before adding
padding.
2023-07-27 16:01:35 +01:00
Jake Hillion
d7cfcca30d move all internal logic to oi::detail namespace 2023-07-26 18:01:38 +01:00
Alastair Robertson
e19641efad EnforceCompatibility: Follow OICodeGen's typesToStub list 2023-07-26 17:31:35 +01:00
Alastair Robertson
8b7bfbe4c0 TypeGraph: Add EnforceCompatibility pass
This extracts the compatibility logic from AddPadding, which allows for it to be
simplified and will make it easier to extend and eventually remove in the
future. No functional changes.
2023-07-26 17:12:36 +01:00
Alastair Robertson
45c3697f6b TypeGraph: Add Prune pass
This lets us remove fields from types when they are no longer needed,
speeding up later passes.

A secondary benefit of pruning unused types means that we sometimes
remove types for which we can't generate correct C++ code. This can
allow us to CodeGen for complex types which reference these broken types
without actually requiring them (e.g. as template parameters).

Add a new feature flag "prune-type-graph" to control this pass. It makes
sense to prune most of the time, but for testing CodeGen functionality
on a wider range of types, it will be useful to have the option to not
prune.
2023-07-26 16:56:34 +01:00
Alastair Robertson
bc895dc9cc DrgnParser: Always stub function pointers
This makes CodeGen v2 behave the same as CodeGen v1, and there doesn't
seem much point in following function pointers either.
2023-07-26 11:30:01 +01:00
Alastair Robertson
884b9a6e95 CodeGen: Don't measure the sizes of union members
In general, we can't tell which member is active in a union so it is not
safe to try and measure any of them.

Explicitly set the alignment of unions (and structs/classes) in CodeGen
if it is available, as the C++ compiler can no longer infer it from the
members.
2023-07-26 11:16:30 +01:00
Alastair Robertson
2d1cc92bb4 Rename RemoveIgnored -> RemoveMembers
Also reshuffle CodeGen's passes to fix an alignment bug with removed
members.

Change RemoveMembers to actually remove members instead of replacing
them with padding. AddPadding must be run afterwards to fill in the
gaps.
2023-07-26 10:53:04 +01:00
Alastair Robertson
99462b2132 Types: Fix folly::small_vector and folly::sorted_vector_map
folly::sorted_vector_map's results are not completely accurate, but at
least CodeGen v2 matches CodeGen v1 for it now.
2023-07-26 10:07:30 +01:00
Alastair Robertson
e1496354de TopoSorter: Sort Typedefs before pointers
Also rename visitAfter() to acceptAfter() to match the previous renaming
of visit() to accept().
2023-07-25 15:31:35 +01:00
Alastair Robertson
df5ae4e34c AlignmentCalc: Array alignment should be based on elementType's alignment 2023-07-25 14:23:01 +01:00
Alastair Robertson
dfc0c62749 AlignmentCalc: Tests for bitfields
Extend TypeGraphParser to understand bitfields
2023-07-25 14:23:01 +01:00
Alastair Robertson
14d193df64 AlignmentCalc: Recurse into params,parents,members,children of Classes 2023-07-25 14:23:01 +01:00
Alastair Robertson
04ce7446b2 AddPadding: Always pad bitfields with "int8_t"s
The underlying type of bitfield is important to the size of a struct:

  struct Foo { int64_t bitfield : 1; };
  struct Bar { int8_t bitfield : 1; };

  sizeof(Foo) = 8;
  sizeof(Bar) = 1;
2023-07-24 16:55:26 +01:00
Jake Hillion
325837c61b test: cycles: add test where oid sees the initial raw pointer
OID hides the initial raw pointer in the `cycles.raw_ptr` test. Add a
second test which wraps this pointer so OID sees the entirety of the
cycle.
2023-07-24 15:32:38 +01:00
Alastair Robertson
6ca846232c RemoveIgnored: Recurse into params,parents,members,children of Classes
Previously this code would not have removed all members which it was
supposed to.

Also remove some now-redundant code from TypeIdentifier. RemoveIgnored
will take over the responsibility of removing members from classes.
2023-07-24 15:02:20 +01:00
Jake Hillion
323daed329 googletest: change to FetchContent 2023-07-21 17:18:06 +01:00
Alastair Robertson
fd54d0ea83 Integration tests: Add tests for alignment of unions 2023-07-19 16:29:05 +01:00
Alastair Robertson
ec9f98f0e1 AddPadding: Pad unions when necessary 2023-07-18 17:45:46 +01:00
Alastair Robertson
a0acaaea65 AddPadding: Pad classes with zero members 2023-07-18 17:45:46 +01:00
Alastair Robertson
3aa52deb71 AddPaddingTest: Tests for unions and memberless classes 2023-07-18 17:33:25 +01:00
Alastair Robertson
1e1b319a69 TypeIdentifier: Create custom visitor for Class types
This is just laying some foundations - it doesn't do anything useful
yet.
2023-07-18 17:33:25 +01:00
Alastair Robertson
b4b3e86c47 TypeGraphParser: Fix lifetimes of ContainerInfo objects
Containers store references to ContainerInfos, so the ContainerInfos
must live beyond the stack they were created on. Use static variables
for simplicity.
2023-07-18 17:18:28 +01:00
Alastair Robertson
4d96848bdb TypeGraphParser: Throw custom error types
We can catch these exceptions and print clearer failure messages.

Before:
  unknown file: Failure
  C++ exception with description "Invalid type for child" thrown in the test body.

After:
  ../test/type_graph_utils.cpp:44: Failure
  Failed
  Error parsing input graph: Invalid type for child
2023-07-18 17:18:28 +01:00
Alastair Robertson
c3fec2624b Integration tests: Add tests for unrestricted unions
i.e. unions with non-POD members

We can't examine untagged unions, but we should be able to support
looking inside tagged unions at some point in the future.
2023-07-14 15:48:01 +01:00
Alastair Robertson
30cd23fa53 TypeGraph: Introduce TypeGraphParser to simplify unit testing
TypeGraphParser parses a textual type graph, as emitted by Printer.

It also doubles as a way of ensuring that Printer displays all
information about a type graph, to aid with debugging.

Convert Flattener unit tests over to this new framework as a first step.
2023-07-13 17:38:49 +01:00
Jake Hillion
bd948152b7 add exporters::TypeCheckingWalker 2023-07-13 16:05:24 +01:00
Jake Hillion
032c28c0ea type checking: add description of data segment type 2023-07-13 16:05:24 +01:00
Alastair Robertson
9f9d1eb568 TypeGraph: Better handling for anonymous types
- Assign names to anonymous types
- Deduplicate all enums (anonymous or not)
- Add tests
2023-07-12 17:44:38 +01:00
Alastair Robertson
3e8464e691 RemoveIgnored: Set names for removed members to AddPadding::MemberPrefix
This means they will be treated as padding, so CodeGen will not try to
store any data for them.
2023-07-12 14:40:10 +01:00
Alastair Robertson
e7549db949 TypeGraph: Introduce NodeTracker for efficient cycle detection
Added to Flattener and TypeIdentifier passes for now as a
proof-of-concept. Other passes can come later.
2023-07-12 14:39:56 +01:00
arsarwade
28b813c6db
Stop stubbing tuple (#224)
Summary:

Stubbing tuple without alignment info can cause failures. I added a test
case for this which failed before this fix but works now.

Test Plan:

Ran the test.
2023-07-11 09:10:40 -07:00