Skip to content

Commit

Permalink
add skipStrictAliasingCheck to config
Browse files Browse the repository at this point in the history
  • Loading branch information
caipng committed Apr 25, 2024
1 parent 401c304 commit f82773b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ export interface MemoryConfig {

export type Endianness = "little" | "big";

export interface UBConfig {
skipStrictAliasingCheck: boolean;
}

export interface RuntimeConfig {
memory: MemoryConfig;
endianness: Endianness;
UB: UBConfig;
}

export const DEFAULT_CONFIG: RuntimeConfig = {
Expand All @@ -37,4 +42,7 @@ export const DEFAULT_CONFIG: RuntimeConfig = {
},
},
endianness: "little",
UB: {
skipStrictAliasingCheck: false,
},
};
6 changes: 5 additions & 1 deletion src/interpreter/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ export class Runtime {
this.symbolTable = new SymbolTable();
this.config = config;
this.effectiveTypeTable = new EffectiveTypeTable();
this.memory = new Memory(config.memory, this.effectiveTypeTable);
this.memory = new Memory(
config.memory,
this.effectiveTypeTable,
config.UB.skipStrictAliasingCheck,
);
this.stack = new RuntimeStack(config.memory.stack.baseAddress);
this.functionCalls = new Stack();
this.heap = new Heap(
Expand Down
9 changes: 8 additions & 1 deletion src/memory/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ export class Memory {
private readonly readonlyAddresses: Set<number>;
private readonly executableAddresses: Set<number>;
private readonly effectiveTypeTable: EffectiveTypeTable;
private readonly skipStrictAliasingCheck: boolean;

constructor(config: MemoryConfig, effectiveTypeTable: EffectiveTypeTable) {
constructor(
config: MemoryConfig,
effectiveTypeTable: EffectiveTypeTable,
skipStrictAliasingCheck: boolean = false,
) {
checkMemoryConfig(config);
this.segments = {
stack: new MemoryRegion(config.stack),
Expand All @@ -72,6 +77,7 @@ export class Memory {
this.readonlyAddresses = new Set();
this.executableAddresses = new Set();
this.effectiveTypeTable = effectiveTypeTable;
this.skipStrictAliasingCheck = skipStrictAliasingCheck;
}

private getMemoryRegion(address: number): MemoryRegion {
Expand Down Expand Up @@ -181,6 +187,7 @@ export class Memory {
throw new Error("no object allocated at " + decimalAddressToHex(address));
}

if (this.skipStrictAliasingCheck) return true;
if (et === NO_EFFECTIVE_TYPE) return true;
if (isChar(t) || isUnsignedChar(t) || isSignedChar(t)) return true;

Expand Down

0 comments on commit f82773b

Please sign in to comment.