Commit 278eb06b98
Changed files (1)
lib
compiler
aro
lib/compiler/aro/aro/Preprocessor.zig
@@ -389,7 +389,8 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
try pp.ensureTotalTokenCapacity(pp.tokens.len + estimated_token_count);
var if_level: u8 = 0;
- var if_kind = std.PackedIntArray(u2, 256).init([1]u2{0} ** 256);
+ var if_kind: [64]u8 = .{0} ** 64;
+ const native_endian = @import("builtin").cpu.arch.endian();
const until_else = 0;
const until_endif = 1;
const until_endif_seen_else = 2;
@@ -430,12 +431,24 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
if_level = sum;
if (try pp.expr(&tokenizer)) {
- if_kind.set(if_level, until_endif);
+ std.mem.writePackedInt(
+ u2,
+ &if_kind,
+ if_level * 2,
+ until_endif,
+ native_endian,
+ );
if (pp.verbose) {
pp.verboseLog(directive, "entering then branch of #if", .{});
}
} else {
- if_kind.set(if_level, until_else);
+ std.mem.writePackedInt(
+ u2,
+ &if_kind,
+ if_level * 2,
+ until_else,
+ native_endian,
+ );
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #if", .{});
@@ -451,12 +464,24 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
const macro_name = (try pp.expectMacroName(&tokenizer)) orelse continue;
try pp.expectNl(&tokenizer);
if (pp.defines.get(macro_name) != null) {
- if_kind.set(if_level, until_endif);
+ std.mem.writePackedInt(
+ u2,
+ &if_kind,
+ if_level * 2,
+ until_endif,
+ native_endian,
+ );
if (pp.verbose) {
pp.verboseLog(directive, "entering then branch of #ifdef", .{});
}
} else {
- if_kind.set(if_level, until_else);
+ std.mem.writePackedInt(
+ u2,
+ &if_kind,
+ if_level * 2,
+ until_else,
+ native_endian,
+ );
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #ifdef", .{});
@@ -472,9 +497,21 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
const macro_name = (try pp.expectMacroName(&tokenizer)) orelse continue;
try pp.expectNl(&tokenizer);
if (pp.defines.get(macro_name) == null) {
- if_kind.set(if_level, until_endif);
+ std.mem.writePackedInt(
+ u2,
+ &if_kind,
+ if_level * 2,
+ until_endif,
+ native_endian,
+ );
} else {
- if_kind.set(if_level, until_else);
+ std.mem.writePackedInt(
+ u2,
+ &if_kind,
+ if_level * 2,
+ until_else,
+ native_endian,
+ );
try pp.skip(&tokenizer, .until_else);
}
},
@@ -482,13 +519,25 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
if (if_level == 0) {
try pp.err(directive, .elif_without_if);
if_level += 1;
- if_kind.set(if_level, until_else);
+ std.mem.writePackedInt(
+ u2,
+ &if_kind,
+ if_level * 2,
+ until_else,
+ native_endian,
+ );
} else if (if_level == 1) {
guard_name = null;
}
- switch (if_kind.get(if_level)) {
+ switch (std.mem.readPackedInt(u2, &if_kind, if_level * 2, native_endian)) {
until_else => if (try pp.expr(&tokenizer)) {
- if_kind.set(if_level, until_endif);
+ std.mem.writePackedInt(
+ u2,
+ &if_kind,
+ if_level * 2,
+ until_endif,
+ native_endian,
+ );
if (pp.verbose) {
pp.verboseLog(directive, "entering then branch of #elif", .{});
}
@@ -510,15 +559,27 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
if (if_level == 0) {
try pp.err(directive, .elifdef_without_if);
if_level += 1;
- if_kind.set(if_level, until_else);
+ std.mem.writePackedInt(
+ u2,
+ &if_kind,
+ if_level * 2,
+ until_else,
+ native_endian,
+ );
} else if (if_level == 1) {
guard_name = null;
}
- switch (if_kind.get(if_level)) {
+ switch (std.mem.readPackedInt(u2, &if_kind, if_level * 2, native_endian)) {
until_else => {
const macro_name = try pp.expectMacroName(&tokenizer);
if (macro_name == null) {
- if_kind.set(if_level, until_else);
+ std.mem.writePackedInt(
+ u2,
+ &if_kind,
+ if_level * 2,
+ until_else,
+ native_endian,
+ );
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #elifdef", .{});
@@ -526,12 +587,24 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
} else {
try pp.expectNl(&tokenizer);
if (pp.defines.get(macro_name.?) != null) {
- if_kind.set(if_level, until_endif);
+ std.mem.writePackedInt(
+ u2,
+ &if_kind,
+ if_level * 2,
+ until_endif,
+ native_endian,
+ );
if (pp.verbose) {
pp.verboseLog(directive, "entering then branch of #elifdef", .{});
}
} else {
- if_kind.set(if_level, until_else);
+ std.mem.writePackedInt(
+ u2,
+ &if_kind,
+ if_level * 2,
+ until_else,
+ native_endian,
+ );
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #elifdef", .{});
@@ -551,15 +624,27 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
if (if_level == 0) {
try pp.err(directive, .elifdef_without_if);
if_level += 1;
- if_kind.set(if_level, until_else);
+ std.mem.writePackedInt(
+ u2,
+ &if_kind,
+ if_level * 2,
+ until_else,
+ native_endian,
+ );
} else if (if_level == 1) {
guard_name = null;
}
- switch (if_kind.get(if_level)) {
+ switch (std.mem.readPackedInt(u2, &if_kind, if_level * 2, native_endian)) {
until_else => {
const macro_name = try pp.expectMacroName(&tokenizer);
if (macro_name == null) {
- if_kind.set(if_level, until_else);
+ std.mem.writePackedInt(
+ u2,
+ &if_kind,
+ if_level * 2,
+ until_else,
+ native_endian,
+ );
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #elifndef", .{});
@@ -567,12 +652,24 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
} else {
try pp.expectNl(&tokenizer);
if (pp.defines.get(macro_name.?) == null) {
- if_kind.set(if_level, until_endif);
+ std.mem.writePackedInt(
+ u2,
+ &if_kind,
+ if_level * 2,
+ until_endif,
+ native_endian,
+ );
if (pp.verbose) {
pp.verboseLog(directive, "entering then branch of #elifndef", .{});
}
} else {
- if_kind.set(if_level, until_else);
+ std.mem.writePackedInt(
+ u2,
+ &if_kind,
+ if_level * 2,
+ until_else,
+ native_endian,
+ );
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #elifndef", .{});
@@ -596,9 +693,15 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
} else if (if_level == 1) {
guard_name = null;
}
- switch (if_kind.get(if_level)) {
+ switch (std.mem.readPackedInt(u2, &if_kind, if_level * 2, native_endian)) {
until_else => {
- if_kind.set(if_level, until_endif_seen_else);
+ std.mem.writePackedInt(
+ u2,
+ &if_kind,
+ if_level * 2,
+ until_endif_seen_else,
+ native_endian,
+ );
if (pp.verbose) {
pp.verboseLog(directive, "#else branch here", .{});
}