authorgravatar for der.teufel.mail@gmail.comKrzysztof Wolicki <der.teufel.mail@gmail.com> 2024-10-12 12:00:36+02:00
committergravatar for der.teufel.mail@gmail.comKrzysztof Wolicki <der.teufel.mail@gmail.com> 2024-10-12 12:00:36+02:00
log278eb06b988db69062d864632a24b444b2b45bc6
tree4ffae0f1ae75f0512043da6dcc6a1e9d57ecc109
parentce27ae1c68112dd5bc42356142a65a17278ac86c

Remove PackedIntArray usage from bundled Aro


1 files changed, 125 insertions(+), 22 deletions(-)

lib/compiler/aro/aro/Preprocessor.zig+125-22
......@@ -389,7 +389,8 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
389389 try pp.ensureTotalTokenCapacity(pp.tokens.len + estimated_token_count);
390390
391391 var if_level: u8 = 0;
392 var if_kind = std.PackedIntArray(u2, 256).init([1]u2{0} ** 256);
392 var if_kind: [64]u8 = .{0} ** 64;
393 const native_endian = @import("builtin").cpu.arch.endian();
393394 const until_else = 0;
394395 const until_endif = 1;
395396 const until_endif_seen_else = 2;
......@@ -430,12 +431,24 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
430431 if_level = sum;
431432
432433 if (try pp.expr(&tokenizer)) {
433 if_kind.set(if_level, until_endif);
434 std.mem.writePackedInt(
435 u2,
436 &if_kind,
437 if_level * 2,
438 until_endif,
439 native_endian,
440 );
434441 if (pp.verbose) {
435442 pp.verboseLog(directive, "entering then branch of #if", .{});
436443 }
437444 } else {
438 if_kind.set(if_level, until_else);
445 std.mem.writePackedInt(
446 u2,
447 &if_kind,
448 if_level * 2,
449 until_else,
450 native_endian,
451 );
439452 try pp.skip(&tokenizer, .until_else);
440453 if (pp.verbose) {
441454 pp.verboseLog(directive, "entering else branch of #if", .{});
......@@ -451,12 +464,24 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
451464 const macro_name = (try pp.expectMacroName(&tokenizer)) orelse continue;
452465 try pp.expectNl(&tokenizer);
453466 if (pp.defines.get(macro_name) != null) {
454 if_kind.set(if_level, until_endif);
467 std.mem.writePackedInt(
468 u2,
469 &if_kind,
470 if_level * 2,
471 until_endif,
472 native_endian,
473 );
455474 if (pp.verbose) {
456475 pp.verboseLog(directive, "entering then branch of #ifdef", .{});
457476 }
458477 } else {
459 if_kind.set(if_level, until_else);
478 std.mem.writePackedInt(
479 u2,
480 &if_kind,
481 if_level * 2,
482 until_else,
483 native_endian,
484 );
460485 try pp.skip(&tokenizer, .until_else);
461486 if (pp.verbose) {
462487 pp.verboseLog(directive, "entering else branch of #ifdef", .{});
......@@ -472,9 +497,21 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
472497 const macro_name = (try pp.expectMacroName(&tokenizer)) orelse continue;
473498 try pp.expectNl(&tokenizer);
474499 if (pp.defines.get(macro_name) == null) {
475 if_kind.set(if_level, until_endif);
500 std.mem.writePackedInt(
501 u2,
502 &if_kind,
503 if_level * 2,
504 until_endif,
505 native_endian,
506 );
476507 } else {
477 if_kind.set(if_level, until_else);
508 std.mem.writePackedInt(
509 u2,
510 &if_kind,
511 if_level * 2,
512 until_else,
513 native_endian,
514 );
478515 try pp.skip(&tokenizer, .until_else);
479516 }
480517 },
......@@ -482,13 +519,25 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
482519 if (if_level == 0) {
483520 try pp.err(directive, .elif_without_if);
484521 if_level += 1;
485 if_kind.set(if_level, until_else);
522 std.mem.writePackedInt(
523 u2,
524 &if_kind,
525 if_level * 2,
526 until_else,
527 native_endian,
528 );
486529 } else if (if_level == 1) {
487530 guard_name = null;
488531 }
489 switch (if_kind.get(if_level)) {
532 switch (std.mem.readPackedInt(u2, &if_kind, if_level * 2, native_endian)) {
490533 until_else => if (try pp.expr(&tokenizer)) {
491 if_kind.set(if_level, until_endif);
534 std.mem.writePackedInt(
535 u2,
536 &if_kind,
537 if_level * 2,
538 until_endif,
539 native_endian,
540 );
492541 if (pp.verbose) {
493542 pp.verboseLog(directive, "entering then branch of #elif", .{});
494543 }
......@@ -510,15 +559,27 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
510559 if (if_level == 0) {
511560 try pp.err(directive, .elifdef_without_if);
512561 if_level += 1;
513 if_kind.set(if_level, until_else);
562 std.mem.writePackedInt(
563 u2,
564 &if_kind,
565 if_level * 2,
566 until_else,
567 native_endian,
568 );
514569 } else if (if_level == 1) {
515570 guard_name = null;
516571 }
517 switch (if_kind.get(if_level)) {
572 switch (std.mem.readPackedInt(u2, &if_kind, if_level * 2, native_endian)) {
518573 until_else => {
519574 const macro_name = try pp.expectMacroName(&tokenizer);
520575 if (macro_name == null) {
521 if_kind.set(if_level, until_else);
576 std.mem.writePackedInt(
577 u2,
578 &if_kind,
579 if_level * 2,
580 until_else,
581 native_endian,
582 );
522583 try pp.skip(&tokenizer, .until_else);
523584 if (pp.verbose) {
524585 pp.verboseLog(directive, "entering else branch of #elifdef", .{});
......@@ -526,12 +587,24 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
526587 } else {
527588 try pp.expectNl(&tokenizer);
528589 if (pp.defines.get(macro_name.?) != null) {
529 if_kind.set(if_level, until_endif);
590 std.mem.writePackedInt(
591 u2,
592 &if_kind,
593 if_level * 2,
594 until_endif,
595 native_endian,
596 );
530597 if (pp.verbose) {
531598 pp.verboseLog(directive, "entering then branch of #elifdef", .{});
532599 }
533600 } else {
534 if_kind.set(if_level, until_else);
601 std.mem.writePackedInt(
602 u2,
603 &if_kind,
604 if_level * 2,
605 until_else,
606 native_endian,
607 );
535608 try pp.skip(&tokenizer, .until_else);
536609 if (pp.verbose) {
537610 pp.verboseLog(directive, "entering else branch of #elifdef", .{});
......@@ -551,15 +624,27 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
551624 if (if_level == 0) {
552625 try pp.err(directive, .elifdef_without_if);
553626 if_level += 1;
554 if_kind.set(if_level, until_else);
627 std.mem.writePackedInt(
628 u2,
629 &if_kind,
630 if_level * 2,
631 until_else,
632 native_endian,
633 );
555634 } else if (if_level == 1) {
556635 guard_name = null;
557636 }
558 switch (if_kind.get(if_level)) {
637 switch (std.mem.readPackedInt(u2, &if_kind, if_level * 2, native_endian)) {
559638 until_else => {
560639 const macro_name = try pp.expectMacroName(&tokenizer);
561640 if (macro_name == null) {
562 if_kind.set(if_level, until_else);
641 std.mem.writePackedInt(
642 u2,
643 &if_kind,
644 if_level * 2,
645 until_else,
646 native_endian,
647 );
563648 try pp.skip(&tokenizer, .until_else);
564649 if (pp.verbose) {
565650 pp.verboseLog(directive, "entering else branch of #elifndef", .{});
......@@ -567,12 +652,24 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
567652 } else {
568653 try pp.expectNl(&tokenizer);
569654 if (pp.defines.get(macro_name.?) == null) {
570 if_kind.set(if_level, until_endif);
655 std.mem.writePackedInt(
656 u2,
657 &if_kind,
658 if_level * 2,
659 until_endif,
660 native_endian,
661 );
571662 if (pp.verbose) {
572663 pp.verboseLog(directive, "entering then branch of #elifndef", .{});
573664 }
574665 } else {
575 if_kind.set(if_level, until_else);
666 std.mem.writePackedInt(
667 u2,
668 &if_kind,
669 if_level * 2,
670 until_else,
671 native_endian,
672 );
576673 try pp.skip(&tokenizer, .until_else);
577674 if (pp.verbose) {
578675 pp.verboseLog(directive, "entering else branch of #elifndef", .{});
......@@ -596,9 +693,15 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
596693 } else if (if_level == 1) {
597694 guard_name = null;
598695 }
599 switch (if_kind.get(if_level)) {
696 switch (std.mem.readPackedInt(u2, &if_kind, if_level * 2, native_endian)) {
600697 until_else => {
601 if_kind.set(if_level, until_endif_seen_else);
698 std.mem.writePackedInt(
699 u2,
700 &if_kind,
701 if_level * 2,
702 until_endif_seen_else,
703 native_endian,
704 );
602705 if (pp.verbose) {
603706 pp.verboseLog(directive, "#else branch here", .{});
604707 }