"Go to label definition" now works fully for instructions with inline arguments.

This commit is contained in:
Daan Vanden Bosch 2019-10-02 23:59:24 +02:00
parent 90f0e0f7bd
commit f67752e277
3 changed files with 35 additions and 10 deletions

View File

@ -200,6 +200,9 @@ class Assembler {
labels: [],
type: SegmentType.Instructions,
instructions: [],
asm: {
labels: [],
},
};
this.segment = instruction_segment;
@ -224,6 +227,9 @@ class Assembler {
labels: [],
type: SegmentType.Data,
data: new Uint8Array(bytes).buffer,
asm: {
labels: [],
},
};
this.segment = data_segment;
@ -248,6 +254,9 @@ class Assembler {
labels: [],
type: SegmentType.String,
value: str,
asm: {
labels: [],
},
};
this.segment = string_segment;
@ -306,8 +315,12 @@ class Assembler {
const next_token = this.tokens.shift();
const asm = { line_no: this.line_no, col, len };
if (this.prev_line_had_label) {
this.object_code[this.object_code.length - 1].labels.push(label);
const segment = this.object_code[this.object_code.length - 1];
segment.labels.push(label);
segment.asm.labels.push(asm);
}
switch (this.section) {
@ -317,6 +330,7 @@ class Assembler {
type: SegmentType.Instructions,
labels: [label],
instructions: [],
asm: { labels: [asm] },
};
this.object_code.push(this.segment);
}
@ -334,12 +348,16 @@ class Assembler {
}
break;
case SegmentType.Data:
if (!this.prev_line_had_label) {
this.segment = {
type: SegmentType.Data,
labels: [label],
data: new ArrayBuffer(0),
asm: {
labels: [asm],
},
};
this.object_code.push(this.segment);
}
@ -357,12 +375,16 @@ class Assembler {
}
break;
case SegmentType.String:
if (!this.prev_line_had_label) {
this.segment = {
type: SegmentType.String,
labels: [label],
value: "",
asm: {
labels: [asm],
},
};
this.object_code.push(this.segment);
}

View File

@ -153,14 +153,8 @@ function definition(message: DefinitionInput): void {
if (label != undefined) {
const segment = get_segment_by_label(label);
// TODO: use actual label position instead of position of first instruction.
if (segment && segment.type === SegmentType.Instructions) {
for (const ins of segment.instructions) {
if (ins.asm) {
asm = ins.asm;
break;
}
}
if (segment && segment.asm.labels.length) {
asm = segment.asm.labels[0];
}
}
@ -299,7 +293,7 @@ function find_label_reference_at(line_no: number, col: number): number | undefin
const params = ins.opcode.params;
for (let i = 0; i < ins.args.length; i++) {
const param = i < params.length ? params[i] : params[params.length];
const param = i < params.length ? params[i] : params[params.length - 1];
const arg = ins.args[i];
if (

View File

@ -114,18 +114,27 @@ export type InstructionSegment = {
type: SegmentType.Instructions;
labels: number[];
instructions: Instruction[];
asm: {
labels: AsmToken[];
};
};
export type DataSegment = {
type: SegmentType.Data;
labels: number[];
data: ArrayBuffer;
asm: {
labels: AsmToken[];
};
};
export type StringSegment = {
type: SegmentType.String;
labels: number[];
value: string;
asm: {
labels: AsmToken[];
};
};
function segments_equal(a: Segment, b: Segment): boolean {