2019-05-02 22:45:40 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright 2019 faddenSoft
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
2019-07-20 20:28:10 +00:00
|
|
|
|
namespace SourceGen {
|
2019-05-02 22:45:40 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tracks a set of offsets that reference a single address or label.
|
|
|
|
|
///
|
|
|
|
|
/// This is used internally, when refactoring labels, as well as for the "references"
|
|
|
|
|
/// UI panel and label localizer.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class XrefSet : IEnumerable<XrefSet.Xref> {
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reference type. This is mostly useful for display to the user.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public enum XrefType {
|
|
|
|
|
Unknown = 0,
|
|
|
|
|
SubCallOp, // subroutine call
|
|
|
|
|
BranchOp, // branch instruction
|
|
|
|
|
RefFromData, // reference in data area, e.g. ".dd2 <address>"
|
|
|
|
|
MemAccessOp, // instruction that accesses memory, or refers to an address
|
|
|
|
|
// TODO(someday): track 16-bit vs. 24-bit addressing, so we can show whether
|
|
|
|
|
// something is a "far" reference (and maybe carry this into auto-label annotation)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Cross-reference descriptor. Instances are immutable.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class Xref {
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Offset of start of instruction or data that refers to the target offset.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Offset { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// True if this reference is by name.
|
|
|
|
|
/// </summary>
|
Instruction operand editor rework, part 2
Implemented local variable editing. Operands that have a local
variable reference, or are eligible to have one, can now be edited
directly from the instruction operand edit dialog.
Also, updated the code list double-click handler so that, if you
double-click on the opcode of an instruction that uses a local
variable reference, the selection and view will jump to the place
where that variable was defined.
Also, tweaked the way the References window refers to references
to an address that didn't use a symbol at that address. Updated
the explanation in the manual, which was a bit confusing.
Also, fixed some odds and ends in the manual.
Also, fixed a nasty infinite recursion bug (issue #47).
2019-09-08 01:57:22 +00:00
|
|
|
|
/// <remarks>
|
|
|
|
|
/// The time this is of use is when determining the set of project/platform symbols
|
|
|
|
|
/// that are actually used. If we have FOO1=$101 and FOO2=$102, and we LDA FOO1
|
|
|
|
|
/// and LDA FOO1+1, we only want to output an equate for FOO1 even though FOO2's
|
|
|
|
|
/// address was referenced.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public bool IsByName { get; private set; }
|
2019-05-02 22:45:40 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Type of reference.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public XrefType Type { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// For Type==MemAccessOp, what type of memory access is performed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Asm65.OpDef.MemoryEffect AccType { get; private set; }
|
|
|
|
|
|
2020-09-04 20:26:41 +00:00
|
|
|
|
[Flags]
|
|
|
|
|
public enum AccessFlags {
|
|
|
|
|
None = 0,
|
|
|
|
|
Indexed = 1 << 0,
|
|
|
|
|
Pointer = 1 << 1
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-02 21:09:53 +00:00
|
|
|
|
/// <summary>
|
2020-09-04 20:26:41 +00:00
|
|
|
|
/// For Type==MemAccessOp, true if the instruction applies an index offset to
|
2020-05-02 21:09:53 +00:00
|
|
|
|
/// the operand, meaning the referenced address might not actually be accessed.
|
|
|
|
|
/// </summary>
|
2020-09-04 20:26:41 +00:00
|
|
|
|
public AccessFlags Flags { get; private set; }
|
|
|
|
|
public bool IsIndexedAccess {
|
|
|
|
|
get { return (Flags & AccessFlags.Indexed) != 0; }
|
|
|
|
|
}
|
|
|
|
|
public bool IsPointerAccess {
|
|
|
|
|
get { return (Flags & AccessFlags.Pointer) != 0; }
|
|
|
|
|
}
|
2020-05-02 21:09:53 +00:00
|
|
|
|
|
2019-05-02 22:45:40 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adjustment to symbol. For example, "LDA label+2" adds an xref entry to
|
|
|
|
|
/// "label", with an adjustment of +2.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Adjustment { get; private set; }
|
|
|
|
|
|
Instruction operand editor rework, part 2
Implemented local variable editing. Operands that have a local
variable reference, or are eligible to have one, can now be edited
directly from the instruction operand edit dialog.
Also, updated the code list double-click handler so that, if you
double-click on the opcode of an instruction that uses a local
variable reference, the selection and view will jump to the place
where that variable was defined.
Also, tweaked the way the References window refers to references
to an address that didn't use a symbol at that address. Updated
the explanation in the manual, which was a bit confusing.
Also, fixed some odds and ends in the manual.
Also, fixed a nasty infinite recursion bug (issue #47).
2019-09-08 01:57:22 +00:00
|
|
|
|
public Xref(int offset, bool isByName, XrefType type,
|
2020-09-04 20:26:41 +00:00
|
|
|
|
Asm65.OpDef.MemoryEffect accType, AccessFlags accessFlags, int adjustment) {
|
2019-05-02 22:45:40 +00:00
|
|
|
|
Offset = offset;
|
Instruction operand editor rework, part 2
Implemented local variable editing. Operands that have a local
variable reference, or are eligible to have one, can now be edited
directly from the instruction operand edit dialog.
Also, updated the code list double-click handler so that, if you
double-click on the opcode of an instruction that uses a local
variable reference, the selection and view will jump to the place
where that variable was defined.
Also, tweaked the way the References window refers to references
to an address that didn't use a symbol at that address. Updated
the explanation in the manual, which was a bit confusing.
Also, fixed some odds and ends in the manual.
Also, fixed a nasty infinite recursion bug (issue #47).
2019-09-08 01:57:22 +00:00
|
|
|
|
IsByName = isByName;
|
2019-05-02 22:45:40 +00:00
|
|
|
|
Type = type;
|
|
|
|
|
AccType = accType;
|
2020-09-04 20:26:41 +00:00
|
|
|
|
Flags = accessFlags;
|
2019-05-02 22:45:40 +00:00
|
|
|
|
Adjustment = adjustment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString() {
|
Instruction operand editor rework, part 2
Implemented local variable editing. Operands that have a local
variable reference, or are eligible to have one, can now be edited
directly from the instruction operand edit dialog.
Also, updated the code list double-click handler so that, if you
double-click on the opcode of an instruction that uses a local
variable reference, the selection and view will jump to the place
where that variable was defined.
Also, tweaked the way the References window refers to references
to an address that didn't use a symbol at that address. Updated
the explanation in the manual, which was a bit confusing.
Also, fixed some odds and ends in the manual.
Also, fixed a nasty infinite recursion bug (issue #47).
2019-09-08 01:57:22 +00:00
|
|
|
|
return "Xref off=+" + Offset.ToString("x6") + " sym=" + IsByName +
|
2024-05-22 21:01:02 +00:00
|
|
|
|
" type=" + Type + " accType=" + AccType + " flags=" + Flags +
|
2020-05-02 21:09:53 +00:00
|
|
|
|
" adj=" + Adjustment;
|
2019-05-02 22:45:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Internal storage for xrefs.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private List<Xref> mRefs = new List<Xref>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructs an empty set.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public XrefSet() { }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the number of cross-references in the set.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Count { get { return mRefs.Count; } }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes all entries from the set.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Clear() {
|
|
|
|
|
mRefs.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the Nth entry in the set.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Xref this[int index] {
|
|
|
|
|
get {
|
|
|
|
|
return mRefs[index];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds an xref to the set.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Add(Xref xref) {
|
|
|
|
|
// TODO(someday): not currently enforcing set behavior; start by adding .equals to
|
|
|
|
|
// Xref, then check Contains before allowing Add. (Should probably complain
|
|
|
|
|
// loudly if item already exists, since we're not expecting that.)
|
|
|
|
|
mRefs.Add(xref);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IEnumerable
|
|
|
|
|
public IEnumerator GetEnumerator() {
|
|
|
|
|
return ((IEnumerable)mRefs).GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IEnumerable, generic
|
|
|
|
|
IEnumerator<Xref> IEnumerable<Xref>.GetEnumerator() {
|
|
|
|
|
return ((IEnumerable<Xref>)mRefs).GetEnumerator();
|
|
|
|
|
}
|
Fix various local variable de-duplication bugs
In 1.5.0-dev1, as part of changes to the way label localization
works, the local variable de-duplicator started checking against a
filtered copy of the symbol table. Unfortunately it never
re-generated the table, so a long-lived LocalVariableLookup (like
the one used by LineListGen) would set up the dup map wrong and
be inconsistent with other parts of the program.
We now regenerate the table on every Reset().
The de-duplication stuff also had problems when opcodes and
operands were double-clicked on. When the opcode is clicked, the
selection should jump to the appropriate variable declaration, but
it wasn't being found because the label generated in the list was
in its original form. Fixed.
When an instruction operand is double-clicked, the instruction operand
editor opens with an "edit variable" shortcut. This was showing
the de-duplicated name, which isn't necessarily a bad thing, but it
was passing that value on to the DefSymbol editor, which thought it
was being asked to create a new entry. Fixed. (Entering the editor
through the LvTable editor works correctly, with nary a de-duplicated
name in sight. You'll be forced to rename it because it'll fail the
uniqueness test.)
References to de-duplicated local variables were getting lost when
the symbol's label was replaced (due largely to a convenient but
flawed shortcut: xrefs are attached to DefSymbol objects). Fixed by
linking the XrefSets.
Given the many issues and their relative subtlety, I decided to make
the modified names more obvious, and went back to the "_DUPn" naming
strategy. (I'm also considering just making it an error and
discarding conflicting entries during analysis... this is much more
complicated than I expected it to be.)
Quick tests can be performed in 2019-local-variables:
- go to +000026, double-click on the opcode, confirm sel change
- go to +000026, double-click on the operand, confirm orig name
shown in shortcut and that shortcut opens editor with orig name
- go to +00001a, down a line, click on PROJ_ZERO_DUP1 and confirm
that it has a single reference (from +000026)
- double-click on var table and confirm editing entry
2020-01-14 01:54:47 +00:00
|
|
|
|
|
|
|
|
|
public override string ToString() {
|
|
|
|
|
return "[XrefSet count=" + Count + "]";
|
|
|
|
|
}
|
2019-05-02 22:45:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|