Skip to content

Commit

Permalink
ensure meta datas are alignment in linear memory
Browse files Browse the repository at this point in the history
  • Loading branch information
kylo5aby committed Sep 27, 2023
1 parent da83064 commit 28f759c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/backend/binaryen/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function initGlobalOffset(module: binaryen.Module) {
);
}

export const LinearMemoryAlign = 4;
export const memoryAlignment = 4;

export function initDefaultMemory(
module: binaryen.Module,
Expand Down
4 changes: 2 additions & 2 deletions src/backend/binaryen/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
} from '../../semantics/value.js';
import { ObjectDescriptionType } from '../../semantics/runtime.js';
import { getConfig } from '../../../config/config_mgr.js';
import { LinearMemoryAlign } from './memory.js';
import { memoryAlignment } from './memory.js';

/** typeof an any type object */
export const enum DynType {
Expand Down Expand Up @@ -1634,7 +1634,7 @@ export function getFieldFromMetaByOffset(
meta: binaryen.ExpressionRef,
offset: number,
) {
return module.i32.load(offset, LinearMemoryAlign, meta);
return module.i32.load(offset, memoryAlignment, meta);
}

export interface SourceMapLoc {
Expand Down
2 changes: 2 additions & 0 deletions src/backend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { ParserContext } from '../frontend.js';
import { memoryAlignment } from './binaryen/memory.js';
import { utf16ToUtf8 } from './binaryen/utils.js';
export { ParserContext } from '../frontend.js';

Expand Down Expand Up @@ -38,6 +39,7 @@ export class DataSegmentContext {
}

addData(data: Uint8Array) {
this.currentOffset += (memoryAlignment - 1) & ~(memoryAlignment - 1);
/* there is no efficient approach to cache the data buffer,
currently we don't cache it */
const offset = this.currentOffset;
Expand Down

0 comments on commit 28f759c

Please sign in to comment.