@@ -251,21 +251,21 @@ private Constant emitLayoutField(String javaName, MemoryLayout layout) {
251
251
incrAlign ();
252
252
indent ();
253
253
append (memberMods () + "MemoryLayout " + fieldName + " = " );
254
- emitLayoutString (layout );
254
+ emitLayoutString (layout , false );
255
255
append (";\n " );
256
256
decrAlign ();
257
257
return new Constant (className (), javaName , Constant .Kind .LAYOUT );
258
258
}
259
259
260
- private void emitLayoutString (MemoryLayout l ) {
260
+ private void emitLayoutString (MemoryLayout l , boolean inBitfield ) {
261
261
if (l instanceof ValueLayout val ) {
262
- append (typeToLayoutName (val ));
262
+ append (typeToLayoutName (val , inBitfield ));
263
263
} else if (l instanceof SequenceLayout seq ) {
264
264
append ("MemoryLayout.ofSequence(" );
265
265
if (seq .elementCount ().isPresent ()) {
266
266
append (seq .elementCount ().getAsLong () + ", " );
267
267
}
268
- emitLayoutString (seq .elementLayout ());
268
+ emitLayoutString (seq .elementLayout (), false );
269
269
append (")" );
270
270
} else if (l instanceof GroupLayout group ) {
271
271
if (group .isStruct ()) {
@@ -275,10 +275,11 @@ private void emitLayoutString(MemoryLayout l) {
275
275
}
276
276
incrAlign ();
277
277
String delim = "" ;
278
+ boolean isBitfield = LayoutUtils .isBitfields (group );
278
279
for (MemoryLayout e : group .memberLayouts ()) {
279
280
append (delim );
280
281
indent ();
281
- emitLayoutString (e );
282
+ emitLayoutString (e , isBitfield );
282
283
delim = ",\n " ;
283
284
}
284
285
append ("\n " );
@@ -305,7 +306,7 @@ private Constant emitFunctionDescField(String javaName, FunctionDescriptor desc)
305
306
append (" = " );
306
307
if (desc .returnLayout ().isPresent ()) {
307
308
append ("FunctionDescriptor.of(" );
308
- emitLayoutString (desc .returnLayout ().get ());
309
+ emitLayoutString (desc .returnLayout ().get (), false );
309
310
if (!noArgs ) {
310
311
append ("," );
311
312
}
@@ -319,7 +320,7 @@ private Constant emitFunctionDescField(String javaName, FunctionDescriptor desc)
319
320
for (MemoryLayout e : desc .argumentLayouts ()) {
320
321
append (delim );
321
322
indent ();
322
- emitLayoutString (e );
323
+ emitLayoutString (e , false );
323
324
delim = ",\n " ;
324
325
}
325
326
append ("\n " );
@@ -359,23 +360,25 @@ private Constant emitConstantAddress(String javaName, Object value) {
359
360
return new Constant (className (), javaName , Constant .Kind .ADDRESS );
360
361
}
361
362
362
- private static String typeToLayoutName (ValueLayout vl ) {
363
+ private static String typeToLayoutName (ValueLayout vl , boolean inBitfields ) {
363
364
if (UnsupportedLayouts .isUnsupported (vl )) {
364
365
return "MemoryLayout.ofPaddingBits(" + vl .bitSize () + ")" ;
366
+ } else if (inBitfields ) {
367
+ return "MemoryLayout.ofValueBits(" + vl .bitSize () + ", ByteOrder.nativeOrder())" ;
368
+ } else {
369
+ CLinker .TypeKind kind = (CLinker .TypeKind ) vl .attribute (CLinker .TypeKind .ATTR_NAME ).orElseThrow (
370
+ () -> new IllegalStateException ("Unexpected value layout: could not determine ABI class" ));
371
+ return switch (kind ) {
372
+ case CHAR -> "C_CHAR" ;
373
+ case SHORT -> "C_SHORT" ;
374
+ case INT -> "C_INT" ;
375
+ case LONG -> "C_LONG" ;
376
+ case LONG_LONG -> "C_LONG_LONG" ;
377
+ case FLOAT -> "C_FLOAT" ;
378
+ case DOUBLE -> "C_DOUBLE" ;
379
+ case POINTER -> "C_POINTER" ;
380
+ };
365
381
}
366
-
367
- CLinker .TypeKind kind = (CLinker .TypeKind )vl .attribute (CLinker .TypeKind .ATTR_NAME ).orElseThrow (
368
- () -> new IllegalStateException ("Unexpected value layout: could not determine ABI class" ));
369
- return switch (kind ) {
370
- case CHAR -> "C_CHAR" ;
371
- case SHORT -> "C_SHORT" ;
372
- case INT -> "C_INT" ;
373
- case LONG -> "C_LONG" ;
374
- case LONG_LONG -> "C_LONG_LONG" ;
375
- case FLOAT -> "C_FLOAT" ;
376
- case DOUBLE -> "C_DOUBLE" ;
377
- case POINTER -> "C_POINTER" ;
378
- };
379
382
}
380
383
381
384
private Constant emitSegmentField (String javaName , String nativeName , MemoryLayout layout ) {
0 commit comments