ethers.js/packages/asm/lib.esm/assembler.d.ts

174 lines
6.1 KiB
TypeScript
Raw Permalink Normal View History

2020-03-12 19:14:50 +01:00
import { ethers } from "ethers";
2020-02-04 01:06:47 -05:00
import { Opcode } from "./opcodes";
export declare type Location = {
offset: number;
2020-02-06 18:21:34 -05:00
line: number;
2020-02-04 01:06:47 -05:00
length: number;
source: string;
2020-02-06 18:21:34 -05:00
statement: boolean;
2020-02-04 01:06:47 -05:00
};
export declare type AssembleVisitFunc = (node: Node, bytecode: string) => void;
export declare type VisitFunc = (node: Node) => void;
export declare abstract class Node {
readonly tag: string;
readonly location: Location;
constructor(guard: any, location: Location, options: {
[key: string]: any;
});
assemble(assembler: Assembler, visit: AssembleVisitFunc): Promise<void>;
children(): Array<Node>;
visit(visit: VisitFunc): void;
static from(options: any): Node;
}
export declare abstract class ValueNode extends Node {
constructor(guard: any, location: Location, options: {
[key: string]: any;
});
2020-03-12 19:14:50 +01:00
getPushLiteral(value: ethers.utils.BytesLike | ethers.utils.Hexable | number): string;
2020-02-04 01:06:47 -05:00
}
export declare class LiteralNode extends ValueNode {
readonly value: string;
readonly verbatim: boolean;
constructor(guard: any, location: Location, value: string, verbatim: boolean);
assemble(assembler: Assembler, visit: AssembleVisitFunc): Promise<void>;
static from(options: any): LiteralNode;
}
2020-02-06 18:21:34 -05:00
export declare class PopNode extends ValueNode {
readonly index: number;
constructor(guard: any, location: Location, index: number);
get placeholder(): string;
2020-02-06 18:21:34 -05:00
static from(options: any): PopNode;
}
2020-02-04 01:06:47 -05:00
export declare class LinkNode extends ValueNode {
readonly type: string;
readonly label: string;
constructor(guard: any, location: Location, type: string, label: string);
assemble(assembler: Assembler, visit: AssembleVisitFunc): Promise<void>;
static from(options: any): LinkNode;
}
export declare class OpcodeNode extends ValueNode {
readonly opcode: Opcode;
readonly operands: Array<ValueNode>;
2020-02-06 18:21:34 -05:00
readonly instructional: boolean;
constructor(guard: any, location: Location, opcode: Opcode, operands: Array<ValueNode>, instructional: boolean);
2020-02-04 01:06:47 -05:00
assemble(assembler: Assembler, visit: AssembleVisitFunc): Promise<void>;
children(): Array<Node>;
visit(visit: VisitFunc): void;
static from(options: any): OpcodeNode;
}
export declare abstract class LabelledNode extends Node {
readonly name: string;
constructor(guard: any, location: Location, name: string, values?: {
[key: string]: any;
});
}
export declare class LabelNode extends LabelledNode {
assemble(assembler: Assembler, visit: AssembleVisitFunc): Promise<void>;
static from(options: any): LabelNode;
}
2020-03-12 19:14:50 +01:00
export declare class PaddingNode extends ValueNode {
_length: number;
constructor(guard: any, location: Location);
setLength(length: number): void;
assemble(assembler: Assembler, visit: AssembleVisitFunc): Promise<void>;
}
2020-02-04 01:06:47 -05:00
export declare class DataNode extends LabelledNode {
readonly data: Array<ValueNode>;
2020-03-12 19:14:50 +01:00
readonly padding: PaddingNode;
2020-02-04 01:06:47 -05:00
constructor(guard: any, location: Location, name: string, data: string);
assemble(assembler: Assembler, visit: AssembleVisitFunc): Promise<void>;
children(): Array<Node>;
static from(options: any): DataNode;
}
export declare class EvaluationNode extends ValueNode {
readonly script: string;
readonly verbatim: boolean;
constructor(guard: any, location: Location, script: string, verbatim: boolean);
assemble(assembler: Assembler, visit: AssembleVisitFunc): Promise<void>;
static from(options: any): EvaluationNode;
}
export declare class ExecutionNode extends Node {
readonly script: string;
constructor(guard: any, location: Location, script: string);
assemble(assembler: Assembler, visit: AssembleVisitFunc): Promise<void>;
static from(options: any): ExecutionNode;
}
export declare class ScopeNode extends LabelledNode {
readonly statements: Array<Node>;
constructor(guard: any, location: Location, name: string, statements: Array<Node>);
assemble(assembler: Assembler, visit: AssembleVisitFunc): Promise<void>;
children(): Array<Node>;
static from(options: any): ScopeNode;
}
export declare type Operation = {
opcode: Opcode;
offset: number;
pushValue?: string;
};
export interface Bytecode extends Array<Operation> {
getOperation(offset: number): Operation;
}
export declare function disassemble(bytecode: string): Bytecode;
export declare function formatBytecode(bytecode: Array<Operation>): string;
2020-02-06 18:21:34 -05:00
export interface DataSource extends Array<number> {
offset: number;
ast: Node;
source: string;
2020-03-12 19:14:50 +01:00
_freeze?: () => void;
2020-02-04 01:06:47 -05:00
}
2020-02-06 18:21:34 -05:00
export declare type NodeState = {
2020-02-04 01:06:47 -05:00
node: Node;
offset: number;
bytecode: string;
};
export declare type AssemblerOptions = {
filename?: string;
retry?: number;
positionIndependentCode?: boolean;
defines?: {
[name: string]: any;
};
2020-02-06 18:21:34 -05:00
target?: string;
};
export declare type ParserOptions = {
ignoreWarnings?: boolean;
2020-02-04 01:06:47 -05:00
};
declare class Assembler {
readonly root: Node;
2020-02-06 18:21:34 -05:00
readonly positionIndependentCode: boolean;
2020-02-04 01:06:47 -05:00
readonly nodes: {
[tag: string]: NodeState;
};
readonly labels: {
[name: string]: LabelledNode;
};
2020-02-06 18:21:34 -05:00
_parents: {
[tag: string]: Node;
2020-02-04 01:06:47 -05:00
};
2020-02-06 18:21:34 -05:00
constructor(root: Node, positionIndependentCode?: boolean);
getTarget(label: string): LabelledNode;
2020-02-04 01:06:47 -05:00
evaluate(script: string, source: Node): Promise<any>;
getAncestor<T = Node>(node: Node, cls: {
new (...args: any[]): T;
}): T;
2020-02-06 18:21:34 -05:00
getOffset(node: Node, source?: Node): number;
setOffset(node: Node, offset: number): void;
getBytecode(node: Node): string;
setBytecode(node: Node, bytecode: string): void;
2020-02-04 01:06:47 -05:00
getLinkValue(target: LabelledNode, source: Node): number | DataSource;
2020-02-06 18:21:34 -05:00
start(node: Node): void;
end(node: Node): void;
}
export declare enum SemanticErrorSeverity {
error = "error",
warning = "warning"
2020-02-04 01:06:47 -05:00
}
2020-02-06 18:21:34 -05:00
export declare type SemanticError = {
readonly message: string;
readonly severity: SemanticErrorSeverity;
readonly node: Node;
};
export declare function parse(code: string, options?: ParserOptions): Node;
2020-02-04 01:06:47 -05:00
export declare function assemble(ast: Node, options?: AssemblerOptions): Promise<string>;
export {};