aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/rust-backend.h
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-12-14 18:10:42 +0000
committerPhilip Herron <philip.herron@embecosm.com>2021-12-16 10:17:08 +0000
commite0588300adc00872b0e818477dba614348d2cb02 (patch)
treea696b3458140310c223e519b0b53d4481dc2c1de /gcc/rust/rust-backend.h
parent3629645386ad503606f29f95c2e16d0600df6e20 (diff)
downloadgcc-e0588300adc00872b0e818477dba614348d2cb02.zip
gcc-e0588300adc00872b0e818477dba614348d2cb02.tar.gz
gcc-e0588300adc00872b0e818477dba614348d2cb02.tar.bz2
Add enum code generation
This adds a naieve first pass approach to enum type code generation. The original idea was to use GCC's QUAL_UNION_TYPE but I have ran into issues with the DECL_QUALIFIER as my understanding of how this works is incorrect. This takes an enum such as: ```rust enum AnEnum { A, B, C (char), D (x: i64, y: i64), } ``` And turns this into one big union consisting of all fields as RECORD_TYPES. ```c union AnEnum { record A { RUST$ENUM$DISR }; record B { RUST$ENUM$DISR }; record C { RUST$ENUM$DISR, char }; record D { RUST$ENUM$DISR, i64, i64}; } ``` see: https://github.com/bminor/binutils-gdb/blob/527b8861cd472385fa9160a91dd6d65a25c41987/gdb/dwarf2/read.c#L9010-L9241 With the RUST$ENUM$DISR being the first field in all of the records this means the alignment allows for indirect memory access of the struct to use it as a qualifier field to figure out which variant is currently in use. The data-less varients use their generated discriminat value during type-checking the data variants use their HIR ID for their discriminant. This will likely get redone to get improved GDB integration/updated to use the QUAL_UNION_TYPE when we learn how to do this properly. Fixes #79
Diffstat (limited to 'gcc/rust/rust-backend.h')
-rw-r--r--gcc/rust/rust-backend.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/gcc/rust/rust-backend.h b/gcc/rust/rust-backend.h
index 64144bc..43a81f2 100644
--- a/gcc/rust/rust-backend.h
+++ b/gcc/rust/rust-backend.h
@@ -122,6 +122,8 @@ public:
return "unknown";
}
+ virtual tree get_identifier_node (const std::string &str) = 0;
+
// Types.
// Produce an error type. Actually the backend could probably just
@@ -348,7 +350,7 @@ public:
// Return an expression that constructs BTYPE with VALS. BTYPE must be the
// backend representation a of struct. VALS must be in the same order as the
// corresponding fields in BTYPE.
- virtual tree constructor_expression (tree btype,
+ virtual tree constructor_expression (tree btype, bool is_variant,
const std::vector<tree> &vals, int,
Location)
= 0;