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;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
using CommonUtil;
|
|
|
|
|
|
2019-07-20 20:28:10 +00:00
|
|
|
|
namespace SourceGen {
|
2019-05-02 22:45:40 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Loads and maintains a collection of platform-specific symbols from a ".sym65" file.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class PlatformSymbols : IEnumerable<Symbol> {
|
|
|
|
|
public const string FILENAME_EXT = ".sym65";
|
2019-10-27 17:54:42 +00:00
|
|
|
|
private const string ERASE_VALUE_STR = "ERASE";
|
|
|
|
|
public const int ERASE_VALUE = -1;
|
2019-05-02 22:45:40 +00:00
|
|
|
|
public static readonly string FILENAME_FILTER = Res.Strings.FILE_FILTER_SYM65;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-10-15 23:37:14 +00:00
|
|
|
|
/// Regex pattern for symbol definition in platform symbol file.
|
2019-05-02 22:45:40 +00:00
|
|
|
|
///
|
|
|
|
|
/// Alphanumeric ASCII + underscore for label, which must start at beginning of line.
|
Allow explicit widths in project/platform symbols, part 1
The ability to give explicit widths to local variables worked out
pretty well, so we're going to try adding the same thing to project
and platform symbols.
The first step is to allow widths to be specified in platform files,
and set with the project symbol editor. The DefSymbol editor is
also used for local variables, so a bit of dancing is required.
For platform/project symbols the width is optional, and is totally
ignored for constants. (For variables, constants are used for the
StackRel args, so the width is meaningful and required.)
We also now show the symbol's type (address or constant) and width
in the listing. This gets really distracting when overused, so we
only show it when the width is explicitly set. The default width
is 1, which most things will be, so users can make an aesthetic
choice there. (The place where widths make very little sense is when
the symbol represents a code entry point, rather than a data item.)
The maximum width of a local variable is now 256, but it's not
allowed to overlap with other variables or run of the end of the
direct page. The maximum width of a platform/project symbol is
65536, with bank-wrap behavior TBD.
The local variable table editor now refers to stack-relative
constants as such, rather than simply "constant", to make it clear
that it's not just defining an 8-bit constant.
Widths have been added to a handful of Apple II platform defs.
2019-10-01 21:58:24 +00:00
|
|
|
|
/// Value is somewhat arbitrary, but ends if we see a comment delimiter (semicolon) or
|
2019-10-15 23:37:14 +00:00
|
|
|
|
/// whitespace. Spaces are allowed between tokens, but not required. Value, width,
|
2019-10-28 04:29:44 +00:00
|
|
|
|
/// and mask may be hex, decimal, or binary; these are simply tokenized by regex.
|
2019-05-02 22:45:40 +00:00
|
|
|
|
///
|
2019-10-15 23:37:14 +00:00
|
|
|
|
/// Looks like:
|
|
|
|
|
/// NAME {@,=,<,>} VALUE [& MASK] [WIDTH] [;COMMENT]
|
|
|
|
|
///
|
|
|
|
|
/// Regex output groups are:
|
|
|
|
|
/// 1. NAME
|
|
|
|
|
/// 2. type/direction char
|
|
|
|
|
/// 3. VALUE (can be any non-whitespace)
|
|
|
|
|
/// 4. optional: WIDTH (can be any non-whitespace)
|
|
|
|
|
/// 5. optional: COMMENT with leading ';'
|
2019-05-02 22:45:40 +00:00
|
|
|
|
/// </summary>
|
Allow explicit widths in project/platform symbols, part 1
The ability to give explicit widths to local variables worked out
pretty well, so we're going to try adding the same thing to project
and platform symbols.
The first step is to allow widths to be specified in platform files,
and set with the project symbol editor. The DefSymbol editor is
also used for local variables, so a bit of dancing is required.
For platform/project symbols the width is optional, and is totally
ignored for constants. (For variables, constants are used for the
StackRel args, so the width is meaningful and required.)
We also now show the symbol's type (address or constant) and width
in the listing. This gets really distracting when overused, so we
only show it when the width is explicitly set. The default width
is 1, which most things will be, so users can make an aesthetic
choice there. (The place where widths make very little sense is when
the symbol represents a code entry point, rather than a data item.)
The maximum width of a local variable is now 256, but it's not
allowed to overlap with other variables or run of the end of the
direct page. The maximum width of a platform/project symbol is
65536, with bank-wrap behavior TBD.
The local variable table editor now refers to stack-relative
constants as such, rather than simply "constant", to make it clear
that it's not just defining an 8-bit constant.
Widths have been added to a handful of Apple II platform defs.
2019-10-01 21:58:24 +00:00
|
|
|
|
/// <remarks>
|
|
|
|
|
/// If you want to make sense of this, I highly recommend https://regex101.com/ .
|
|
|
|
|
/// </remarks>
|
2019-10-15 23:37:14 +00:00
|
|
|
|
private const string SYMBOL_PATTERN =
|
|
|
|
|
@"^([A-Za-z0-9_]+)\s*([@=<>])\s*([^\s;]+)\s*([^\s;]+)?\s*(;.*)?$";
|
|
|
|
|
private static Regex sNameValueRegex = new Regex(SYMBOL_PATTERN);
|
|
|
|
|
private const int GROUP_NAME = 1;
|
|
|
|
|
private const int GROUP_TYPE = 2;
|
|
|
|
|
private const int GROUP_VALUE = 3;
|
|
|
|
|
private const int GROUP_WIDTH = 4;
|
|
|
|
|
private const int GROUP_COMMENT = 5;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Regex pattern for mask definition in platform symbol file.
|
|
|
|
|
///
|
|
|
|
|
/// Looks like:
|
|
|
|
|
/// CMP_MASK CMP_VALUE ADDR_MASK [;COMMENT]
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const string MULTI_MASK_PATTERN =
|
|
|
|
|
@"^\s*([^\s]+)\s*([^\s]+)\s*([^\s;]+)\s*(;.*)?$";
|
|
|
|
|
private static Regex sMaskRegex = new Regex(MULTI_MASK_PATTERN);
|
2019-05-02 22:45:40 +00:00
|
|
|
|
|
2019-10-15 23:37:14 +00:00
|
|
|
|
private const string MULTI_MASK_CMD = "*MULTI_MASK";
|
2019-05-02 22:45:40 +00:00
|
|
|
|
private const string TAG_CMD = "*TAG";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// List of symbols. We keep them sorted by label because labels must be unique.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private SortedList<string, Symbol> mSymbols =
|
|
|
|
|
new SortedList<string, Symbol>(Asm65.Label.LABEL_COMPARER);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public PlatformSymbols() { }
|
|
|
|
|
|
|
|
|
|
// IEnumerable
|
|
|
|
|
public IEnumerator<Symbol> GetEnumerator() {
|
|
|
|
|
return mSymbols.Values.GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IEnumerable
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator() {
|
|
|
|
|
return mSymbols.Values.GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-13 22:53:46 +00:00
|
|
|
|
public bool ContainsKey(string label) {
|
|
|
|
|
return mSymbols.ContainsKey(label);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-02 22:45:40 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Loads platform symbols.
|
|
|
|
|
/// </summary>
|
Allow explicit widths in project/platform symbols, part 3
Implement multi-byte project/platform symbols by filling out a table
of addresses. Each symbol is "painted" into the table, replacing
an existing entry if the new entry has higher priority. This allows
us to handle overlapping entries, giving boosted priority to platform
symbols that are defined in .sym65 files loaded later.
The bounds on project/platform symbols are now rigidly defined. If
the "nearby" feature is enabled, references to SYM-1 will be picked
up, but we won't go hunting for SYM+1 unless the symbol is at least
two bytes wide.
The cost of adding a symbol to the symbol table is about the same,
but we don't have a quick way to remove a symbol.
Previously, if two platform symbols had the same value, the symbol
with the alphabetically lowest label would win. Now, the symbol
defined in the most-recently-loaded file wins. (If you define two
symbols with the same value in the same file, it's still resolved
alphabetically.) This allows the user to pick the winner by
arranging the load order of the platform symbol files.
Platform symbols now keep a reference to the file ident of the
symbol file that defined them, so we can show the symbols's source
in the Info panel.
These changes altered the behavior of test 2008-address-changes,
which includes some tests on external addresses that are close to
labeled internal addresses. The previous behavior essentially
treated user labels as being 3 bytes wide and extending outside the
file bounds, which was mildly convenient on occasion but felt a
little skanky. (We could do with a way to define external symbols
relative to internal symbols, for things like the source address of
code that gets relocated.)
Also, re-enabled some unit tests.
Also, added a bit of identifying stuff to CrashLog.txt.
2019-10-02 23:26:05 +00:00
|
|
|
|
/// <param name="fileIdent">External file identifier of symbol file.</param>
|
2019-05-02 22:45:40 +00:00
|
|
|
|
/// <param name="projectDir">Full path to project directory.</param>
|
Allow explicit widths in project/platform symbols, part 3
Implement multi-byte project/platform symbols by filling out a table
of addresses. Each symbol is "painted" into the table, replacing
an existing entry if the new entry has higher priority. This allows
us to handle overlapping entries, giving boosted priority to platform
symbols that are defined in .sym65 files loaded later.
The bounds on project/platform symbols are now rigidly defined. If
the "nearby" feature is enabled, references to SYM-1 will be picked
up, but we won't go hunting for SYM+1 unless the symbol is at least
two bytes wide.
The cost of adding a symbol to the symbol table is about the same,
but we don't have a quick way to remove a symbol.
Previously, if two platform symbols had the same value, the symbol
with the alphabetically lowest label would win. Now, the symbol
defined in the most-recently-loaded file wins. (If you define two
symbols with the same value in the same file, it's still resolved
alphabetically.) This allows the user to pick the winner by
arranging the load order of the platform symbol files.
Platform symbols now keep a reference to the file ident of the
symbol file that defined them, so we can show the symbols's source
in the Info panel.
These changes altered the behavior of test 2008-address-changes,
which includes some tests on external addresses that are close to
labeled internal addresses. The previous behavior essentially
treated user labels as being 3 bytes wide and extending outside the
file bounds, which was mildly convenient on occasion but felt a
little skanky. (We could do with a way to define external symbols
relative to internal symbols, for things like the source address of
code that gets relocated.)
Also, re-enabled some unit tests.
Also, added a bit of identifying stuff to CrashLog.txt.
2019-10-02 23:26:05 +00:00
|
|
|
|
/// <param name="loadOrdinal">Platform file load order.</param>
|
2019-05-02 22:45:40 +00:00
|
|
|
|
/// <param name="report">Report of warnings and errors.</param>
|
|
|
|
|
/// <returns>True on success (no errors), false on failure.</returns>
|
Allow explicit widths in project/platform symbols, part 3
Implement multi-byte project/platform symbols by filling out a table
of addresses. Each symbol is "painted" into the table, replacing
an existing entry if the new entry has higher priority. This allows
us to handle overlapping entries, giving boosted priority to platform
symbols that are defined in .sym65 files loaded later.
The bounds on project/platform symbols are now rigidly defined. If
the "nearby" feature is enabled, references to SYM-1 will be picked
up, but we won't go hunting for SYM+1 unless the symbol is at least
two bytes wide.
The cost of adding a symbol to the symbol table is about the same,
but we don't have a quick way to remove a symbol.
Previously, if two platform symbols had the same value, the symbol
with the alphabetically lowest label would win. Now, the symbol
defined in the most-recently-loaded file wins. (If you define two
symbols with the same value in the same file, it's still resolved
alphabetically.) This allows the user to pick the winner by
arranging the load order of the platform symbol files.
Platform symbols now keep a reference to the file ident of the
symbol file that defined them, so we can show the symbols's source
in the Info panel.
These changes altered the behavior of test 2008-address-changes,
which includes some tests on external addresses that are close to
labeled internal addresses. The previous behavior essentially
treated user labels as being 3 bytes wide and extending outside the
file bounds, which was mildly convenient on occasion but felt a
little skanky. (We could do with a way to define external symbols
relative to internal symbols, for things like the source address of
code that gets relocated.)
Also, re-enabled some unit tests.
Also, added a bit of identifying stuff to CrashLog.txt.
2019-10-02 23:26:05 +00:00
|
|
|
|
public bool LoadFromFile(string fileIdent, string projectDir, int loadOrdinal,
|
|
|
|
|
out FileLoadReport report) {
|
2019-05-02 22:45:40 +00:00
|
|
|
|
report = new FileLoadReport(fileIdent);
|
|
|
|
|
|
|
|
|
|
ExternalFile ef = ExternalFile.CreateFromIdent(fileIdent);
|
|
|
|
|
if (ef == null) {
|
|
|
|
|
report.Add(FileLoadItem.Type.Error,
|
|
|
|
|
CommonUtil.Properties.Resources.ERR_FILE_NOT_FOUND + ": " + fileIdent);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
string pathName = ef.GetPathName(projectDir);
|
|
|
|
|
if (pathName == null) {
|
|
|
|
|
report.Add(FileLoadItem.Type.Error,
|
|
|
|
|
Res.Strings.ERR_BAD_IDENT + ": " + fileIdent);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
Allow explicit widths in project/platform symbols, part 3
Implement multi-byte project/platform symbols by filling out a table
of addresses. Each symbol is "painted" into the table, replacing
an existing entry if the new entry has higher priority. This allows
us to handle overlapping entries, giving boosted priority to platform
symbols that are defined in .sym65 files loaded later.
The bounds on project/platform symbols are now rigidly defined. If
the "nearby" feature is enabled, references to SYM-1 will be picked
up, but we won't go hunting for SYM+1 unless the symbol is at least
two bytes wide.
The cost of adding a symbol to the symbol table is about the same,
but we don't have a quick way to remove a symbol.
Previously, if two platform symbols had the same value, the symbol
with the alphabetically lowest label would win. Now, the symbol
defined in the most-recently-loaded file wins. (If you define two
symbols with the same value in the same file, it's still resolved
alphabetically.) This allows the user to pick the winner by
arranging the load order of the platform symbol files.
Platform symbols now keep a reference to the file ident of the
symbol file that defined them, so we can show the symbols's source
in the Info panel.
These changes altered the behavior of test 2008-address-changes,
which includes some tests on external addresses that are close to
labeled internal addresses. The previous behavior essentially
treated user labels as being 3 bytes wide and extending outside the
file bounds, which was mildly convenient on occasion but felt a
little skanky. (We could do with a way to define external symbols
relative to internal symbols, for things like the source address of
code that gets relocated.)
Also, re-enabled some unit tests.
Also, added a bit of identifying stuff to CrashLog.txt.
2019-10-02 23:26:05 +00:00
|
|
|
|
|
|
|
|
|
// These files shouldn't be enormous. Just read the entire thing into a string array.
|
2019-05-02 22:45:40 +00:00
|
|
|
|
string[] lines;
|
|
|
|
|
try {
|
|
|
|
|
lines = File.ReadAllLines(pathName);
|
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
|
Debug.WriteLine("Platform symbol load failed: " + ioe);
|
|
|
|
|
report.Add(FileLoadItem.Type.Error,
|
|
|
|
|
CommonUtil.Properties.Resources.ERR_FILE_NOT_FOUND + ": " + pathName);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string tag = string.Empty;
|
2019-10-15 23:37:14 +00:00
|
|
|
|
DefSymbol.MultiAddressMask multiMask = null;
|
2019-05-02 22:45:40 +00:00
|
|
|
|
|
|
|
|
|
int lineNum = 0;
|
|
|
|
|
foreach (string line in lines) {
|
|
|
|
|
lineNum++; // first line is line 1, says Vim and VisualStudio
|
|
|
|
|
if (string.IsNullOrEmpty(line) || line[0] == ';') {
|
|
|
|
|
// ignore
|
|
|
|
|
} else if (line[0] == '*') {
|
|
|
|
|
if (line.StartsWith(TAG_CMD)) {
|
|
|
|
|
tag = ParseTag(line);
|
2019-10-15 23:37:14 +00:00
|
|
|
|
} else if (line.StartsWith(MULTI_MASK_CMD)) {
|
2019-10-17 00:32:30 +00:00
|
|
|
|
if (!ParseMask(line, out multiMask, out string badMaskMsg)) {
|
2019-10-15 23:37:14 +00:00
|
|
|
|
report.Add(lineNum, FileLoadItem.NO_COLUMN, FileLoadItem.Type.Warning,
|
2019-10-17 00:32:30 +00:00
|
|
|
|
badMaskMsg);
|
2019-10-15 23:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
//Debug.WriteLine("Mask is now " + mask.ToString("x6"));
|
2019-05-02 22:45:40 +00:00
|
|
|
|
} else {
|
|
|
|
|
// Do something clever with *SYNOPSIS?
|
2019-10-15 23:37:14 +00:00
|
|
|
|
Debug.WriteLine("Ignoring CMD: " + line);
|
2019-05-02 22:45:40 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
MatchCollection matches = sNameValueRegex.Matches(line);
|
|
|
|
|
if (matches.Count == 1) {
|
2019-10-15 23:37:14 +00:00
|
|
|
|
string label = matches[0].Groups[GROUP_NAME].Value;
|
|
|
|
|
char typeAndDir = matches[0].Groups[GROUP_TYPE].Value[0];
|
|
|
|
|
bool isConst = (typeAndDir == '=');
|
|
|
|
|
DefSymbol.DirectionFlags direction = DefSymbol.DirectionFlags.ReadWrite;
|
|
|
|
|
if (typeAndDir == '<') {
|
|
|
|
|
direction = DefSymbol.DirectionFlags.Read;
|
|
|
|
|
} else if (typeAndDir == '>') {
|
|
|
|
|
direction = DefSymbol.DirectionFlags.Write;
|
|
|
|
|
}
|
2019-10-27 17:54:42 +00:00
|
|
|
|
|
2019-05-02 22:45:40 +00:00
|
|
|
|
string badParseMsg;
|
|
|
|
|
int value, numBase;
|
|
|
|
|
bool parseOk;
|
2019-10-27 17:54:42 +00:00
|
|
|
|
string valueStr = matches[0].Groups[GROUP_VALUE].Value;
|
2019-05-02 22:45:40 +00:00
|
|
|
|
if (isConst) {
|
2019-10-27 19:26:34 +00:00
|
|
|
|
// Allow various numeric options, and preserve the value. We
|
|
|
|
|
// don't limit the value range.
|
2019-10-27 17:54:42 +00:00
|
|
|
|
parseOk = Asm65.Number.TryParseInt(valueStr, out value, out numBase);
|
2019-05-02 22:45:40 +00:00
|
|
|
|
badParseMsg =
|
|
|
|
|
CommonUtil.Properties.Resources.ERR_INVALID_NUMERIC_CONSTANT;
|
2019-10-27 17:54:42 +00:00
|
|
|
|
} else if (valueStr.ToUpperInvariant().Equals(ERASE_VALUE_STR)) {
|
|
|
|
|
parseOk = true;
|
|
|
|
|
value = ERASE_VALUE;
|
|
|
|
|
numBase = 10;
|
|
|
|
|
badParseMsg = CommonUtil.Properties.Resources.ERR_INVALID_ADDRESS;
|
2019-05-02 22:45:40 +00:00
|
|
|
|
} else {
|
|
|
|
|
// Allow things like "05/1000". Always hex.
|
|
|
|
|
numBase = 16;
|
2019-10-27 17:54:42 +00:00
|
|
|
|
parseOk = Asm65.Address.ParseAddress(valueStr, (1 << 24) - 1,
|
|
|
|
|
out value);
|
|
|
|
|
// limit to positive 24-bit values
|
|
|
|
|
parseOk &= (value >= 0 && value < 0x01000000);
|
2019-05-02 22:45:40 +00:00
|
|
|
|
badParseMsg = CommonUtil.Properties.Resources.ERR_INVALID_ADDRESS;
|
|
|
|
|
}
|
Allow explicit widths in project/platform symbols, part 1
The ability to give explicit widths to local variables worked out
pretty well, so we're going to try adding the same thing to project
and platform symbols.
The first step is to allow widths to be specified in platform files,
and set with the project symbol editor. The DefSymbol editor is
also used for local variables, so a bit of dancing is required.
For platform/project symbols the width is optional, and is totally
ignored for constants. (For variables, constants are used for the
StackRel args, so the width is meaningful and required.)
We also now show the symbol's type (address or constant) and width
in the listing. This gets really distracting when overused, so we
only show it when the width is explicitly set. The default width
is 1, which most things will be, so users can make an aesthetic
choice there. (The place where widths make very little sense is when
the symbol represents a code entry point, rather than a data item.)
The maximum width of a local variable is now 256, but it's not
allowed to overlap with other variables or run of the end of the
direct page. The maximum width of a platform/project symbol is
65536, with bank-wrap behavior TBD.
The local variable table editor now refers to stack-relative
constants as such, rather than simply "constant", to make it clear
that it's not just defining an 8-bit constant.
Widths have been added to a handful of Apple II platform defs.
2019-10-01 21:58:24 +00:00
|
|
|
|
|
|
|
|
|
int width = -1;
|
2019-10-15 23:37:14 +00:00
|
|
|
|
string widthStr = matches[0].Groups[GROUP_WIDTH].Value;
|
Allow explicit widths in project/platform symbols, part 1
The ability to give explicit widths to local variables worked out
pretty well, so we're going to try adding the same thing to project
and platform symbols.
The first step is to allow widths to be specified in platform files,
and set with the project symbol editor. The DefSymbol editor is
also used for local variables, so a bit of dancing is required.
For platform/project symbols the width is optional, and is totally
ignored for constants. (For variables, constants are used for the
StackRel args, so the width is meaningful and required.)
We also now show the symbol's type (address or constant) and width
in the listing. This gets really distracting when overused, so we
only show it when the width is explicitly set. The default width
is 1, which most things will be, so users can make an aesthetic
choice there. (The place where widths make very little sense is when
the symbol represents a code entry point, rather than a data item.)
The maximum width of a local variable is now 256, but it's not
allowed to overlap with other variables or run of the end of the
direct page. The maximum width of a platform/project symbol is
65536, with bank-wrap behavior TBD.
The local variable table editor now refers to stack-relative
constants as such, rather than simply "constant", to make it clear
that it's not just defining an 8-bit constant.
Widths have been added to a handful of Apple II platform defs.
2019-10-01 21:58:24 +00:00
|
|
|
|
if (parseOk && !string.IsNullOrEmpty(widthStr)) {
|
|
|
|
|
parseOk = Asm65.Number.TryParseInt(widthStr, out width,
|
|
|
|
|
out int ignoredBase);
|
|
|
|
|
if (parseOk) {
|
|
|
|
|
if (width < DefSymbol.MIN_WIDTH || width > DefSymbol.MAX_WIDTH) {
|
|
|
|
|
parseOk = false;
|
2019-10-15 23:37:14 +00:00
|
|
|
|
badParseMsg = Res.Strings.ERR_INVALID_WIDTH;
|
Allow explicit widths in project/platform symbols, part 1
The ability to give explicit widths to local variables worked out
pretty well, so we're going to try adding the same thing to project
and platform symbols.
The first step is to allow widths to be specified in platform files,
and set with the project symbol editor. The DefSymbol editor is
also used for local variables, so a bit of dancing is required.
For platform/project symbols the width is optional, and is totally
ignored for constants. (For variables, constants are used for the
StackRel args, so the width is meaningful and required.)
We also now show the symbol's type (address or constant) and width
in the listing. This gets really distracting when overused, so we
only show it when the width is explicitly set. The default width
is 1, which most things will be, so users can make an aesthetic
choice there. (The place where widths make very little sense is when
the symbol represents a code entry point, rather than a data item.)
The maximum width of a local variable is now 256, but it's not
allowed to overlap with other variables or run of the end of the
direct page. The maximum width of a platform/project symbol is
65536, with bank-wrap behavior TBD.
The local variable table editor now refers to stack-relative
constants as such, rather than simply "constant", to make it clear
that it's not just defining an 8-bit constant.
Widths have been added to a handful of Apple II platform defs.
2019-10-01 21:58:24 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
badParseMsg =
|
|
|
|
|
CommonUtil.Properties.Resources.ERR_INVALID_NUMERIC_CONSTANT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-18 23:19:42 +00:00
|
|
|
|
if (parseOk && multiMask != null && !isConst) {
|
2019-10-15 23:37:14 +00:00
|
|
|
|
// We need to ensure that all possible values fit within the mask.
|
|
|
|
|
// We don't test AddressValue here, because it's okay for the
|
|
|
|
|
// canonical value to be outside the masked range.
|
|
|
|
|
int testWidth = (width > 0) ? width : 1;
|
|
|
|
|
for (int testValue = value; testValue < value + testWidth; testValue++) {
|
|
|
|
|
if ((testValue & multiMask.CompareMask) != multiMask.CompareValue) {
|
|
|
|
|
parseOk = false;
|
|
|
|
|
badParseMsg = Res.Strings.ERR_VALUE_INCOMPATIBLE_WITH_MASK;
|
|
|
|
|
Debug.WriteLine("Mask FAIL: value=" + value.ToString("x6") +
|
|
|
|
|
" width=" + width +
|
|
|
|
|
" testValue=" + testValue.ToString("x6") +
|
|
|
|
|
" mask=" + multiMask);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-02 22:45:40 +00:00
|
|
|
|
if (!parseOk) {
|
|
|
|
|
report.Add(lineNum, FileLoadItem.NO_COLUMN, FileLoadItem.Type.Warning,
|
|
|
|
|
badParseMsg);
|
|
|
|
|
} else {
|
2019-10-15 23:37:14 +00:00
|
|
|
|
string comment = matches[0].Groups[GROUP_COMMENT].Value;
|
2019-05-02 22:45:40 +00:00
|
|
|
|
if (comment.Length > 0) {
|
|
|
|
|
// remove ';'
|
|
|
|
|
comment = comment.Substring(1);
|
|
|
|
|
}
|
|
|
|
|
FormatDescriptor.SubType subType =
|
|
|
|
|
FormatDescriptor.GetSubTypeForBase(numBase);
|
|
|
|
|
DefSymbol symDef = new DefSymbol(label, value, Symbol.Source.Platform,
|
|
|
|
|
isConst ? Symbol.Type.Constant : Symbol.Type.ExternalAddr,
|
2019-10-15 23:37:14 +00:00
|
|
|
|
subType, width, width > 0, comment, direction, multiMask,
|
|
|
|
|
tag, loadOrdinal, fileIdent);
|
2019-05-02 22:45:40 +00:00
|
|
|
|
if (mSymbols.ContainsKey(label)) {
|
|
|
|
|
// This is very easy to do -- just define the same symbol twice
|
|
|
|
|
// in the same file. We don't really need to do anything about
|
|
|
|
|
// it though.
|
|
|
|
|
Debug.WriteLine("NOTE: stomping previous definition of " + label);
|
|
|
|
|
}
|
|
|
|
|
mSymbols[label] = symDef;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
report.Add(lineNum, FileLoadItem.NO_COLUMN, FileLoadItem.Type.Warning,
|
|
|
|
|
CommonUtil.Properties.Resources.ERR_SYNTAX);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return !report.HasErrors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Parses the tag out of a tag command line. The tag is pretty much everything after
|
|
|
|
|
/// the "*TAG", with whitespace stripped off the start and end. The empty string
|
|
|
|
|
/// is valid.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="line">Line to parse.</param>
|
|
|
|
|
/// <returns>Tag string.</returns>
|
|
|
|
|
private string ParseTag(string line) {
|
|
|
|
|
Debug.Assert(line.StartsWith(TAG_CMD));
|
|
|
|
|
string tag = line.Substring(TAG_CMD.Length).Trim();
|
|
|
|
|
return tag;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-15 23:37:14 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Parses the mask value out of a mask command line.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="line">Line to parse.</param>
|
|
|
|
|
/// <param name="multiMask">Parsed mask value, or null if the line was empty.</param>
|
|
|
|
|
/// <returns>True if the mask was parsed successfully.</returns>
|
2019-10-17 00:32:30 +00:00
|
|
|
|
private bool ParseMask(string line, out DefSymbol.MultiAddressMask multiMask,
|
|
|
|
|
out string badMaskMsg) {
|
2019-10-15 23:37:14 +00:00
|
|
|
|
Debug.Assert(line.StartsWith(MULTI_MASK_CMD));
|
|
|
|
|
const int MIN = 0;
|
|
|
|
|
const int MAX = 0x00ffff;
|
|
|
|
|
|
2019-10-17 00:32:30 +00:00
|
|
|
|
badMaskMsg = Res.Strings.ERR_INVALID_MULTI_MASK;
|
2019-10-15 23:37:14 +00:00
|
|
|
|
multiMask = null;
|
2019-10-17 00:32:30 +00:00
|
|
|
|
|
2019-10-15 23:37:14 +00:00
|
|
|
|
string maskStr = line.Substring(MULTI_MASK_CMD.Length).Trim();
|
|
|
|
|
if (string.IsNullOrEmpty(maskStr)) {
|
|
|
|
|
// empty line, disable mask
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MatchCollection matches = sMaskRegex.Matches(maskStr);
|
|
|
|
|
if (matches.Count != 1) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string cmpMaskStr = matches[0].Groups[1].Value;
|
|
|
|
|
string cmpValueStr = matches[0].Groups[2].Value;
|
|
|
|
|
string addrMaskStr = matches[0].Groups[3].Value;
|
|
|
|
|
int cmpMask, cmpValue, addrMask, ignoredBase;
|
|
|
|
|
|
|
|
|
|
if (!Asm65.Number.TryParseInt(cmpMaskStr, out cmpMask, out ignoredBase) ||
|
|
|
|
|
cmpMask < MIN || cmpMask > MAX) {
|
|
|
|
|
Debug.WriteLine("Bad cmpMask: " + cmpMaskStr);
|
2019-10-17 00:32:30 +00:00
|
|
|
|
badMaskMsg = Res.Strings.ERR_INVALID_COMPARE_MASK;
|
2019-10-15 23:37:14 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!Asm65.Number.TryParseInt(cmpValueStr, out cmpValue, out ignoredBase) ||
|
|
|
|
|
cmpValue < MIN || cmpValue > MAX) {
|
|
|
|
|
Debug.WriteLine("Bad cmpValue: " + cmpValueStr);
|
2019-10-17 00:32:30 +00:00
|
|
|
|
badMaskMsg = Res.Strings.ERR_INVALID_COMPARE_VALUE;
|
2019-10-15 23:37:14 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!Asm65.Number.TryParseInt(addrMaskStr, out addrMask, out ignoredBase) ||
|
|
|
|
|
addrMask < MIN || addrMask > MAX) {
|
|
|
|
|
Debug.WriteLine("Bad addrMask: " + addrMaskStr);
|
2019-10-17 00:32:30 +00:00
|
|
|
|
badMaskMsg = Res.Strings.ERR_INVALID_ADDRESS_MASK;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The two masks should not overlap: one represents bits that must be in a
|
|
|
|
|
// specific state for a match to exist, the other indicates which bits are used
|
|
|
|
|
// to select a specific register. This should be a warning.
|
|
|
|
|
if ((cmpMask & ~addrMask) != cmpMask) {
|
|
|
|
|
Debug.WriteLine("Warning: cmpMask/addrMask overlap");
|
|
|
|
|
badMaskMsg = Res.Strings.ERR_INVALID_CMP_ADDR_OVERLAP;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// If cmpValue has bits set that aren't in cmpMask, we will never find a match.
|
|
|
|
|
if ((cmpValue & ~cmpMask) != 0) {
|
|
|
|
|
Debug.WriteLine("cmpValue has unexpected bits set");
|
|
|
|
|
badMaskMsg = Res.Strings.ERR_INVALID_CMP_EXTRA_BITS;
|
2019-10-15 23:37:14 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
multiMask = new DefSymbol.MultiAddressMask(cmpMask, cmpValue, addrMask);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-02 22:45:40 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// One-off function to convert the IIgs toolbox function info from NList.Data.TXT
|
|
|
|
|
/// to .sym65 format. Doesn't really belong in here, but I'm too lazy to put it
|
|
|
|
|
/// anywhere else.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void ConvertNiftyListToolboxFuncs(string inPath, string outPath) {
|
|
|
|
|
const string TOOL_START = "* System tools";
|
|
|
|
|
const string TOOL_END = "* User tools";
|
|
|
|
|
const string PATTERN = @"^([0-9a-fA-F]{4}) (\w+)(.*)";
|
|
|
|
|
Regex parseRegex = new Regex(PATTERN);
|
|
|
|
|
System.Text.StringBuilder sb = new System.Text.StringBuilder();
|
|
|
|
|
|
|
|
|
|
string[] lines = File.ReadAllLines(inPath);
|
|
|
|
|
List<String> outs = new List<string>();
|
|
|
|
|
|
|
|
|
|
bool inTools = false;
|
|
|
|
|
foreach (string line in lines) {
|
|
|
|
|
if (line == TOOL_START) {
|
|
|
|
|
inTools = true;
|
|
|
|
|
continue;
|
|
|
|
|
} else if (line == TOOL_END) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (!inTools) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (line.Substring(5, 4) == "=== ") {
|
|
|
|
|
// make this a comment
|
|
|
|
|
outs.Add("; " + line.Substring(5));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
MatchCollection matches = parseRegex.Matches(line);
|
|
|
|
|
if (matches.Count != 1) {
|
|
|
|
|
Debug.WriteLine("NConv: bad match on '" + line + "'");
|
|
|
|
|
outs.Add("; " + line);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GroupCollection group = matches[0].Groups;
|
|
|
|
|
string outStr;
|
|
|
|
|
if (matches[0].Groups.Count != 4) {
|
|
|
|
|
Debug.WriteLine("NConv: partial match (" + group.Count + ") on '" +
|
|
|
|
|
line + "'");
|
|
|
|
|
outStr = ";" + group[0];
|
|
|
|
|
} else {
|
|
|
|
|
sb.Clear();
|
|
|
|
|
sb.Append(group[2]);
|
|
|
|
|
while (sb.Length < 19) { // not really worried about speed
|
|
|
|
|
sb.Append(' ');
|
|
|
|
|
}
|
|
|
|
|
sb.Append(" = $");
|
|
|
|
|
sb.Append(group[1]);
|
|
|
|
|
while (sb.Length < 32) {
|
|
|
|
|
sb.Append(' ');
|
|
|
|
|
}
|
|
|
|
|
sb.Append(';');
|
|
|
|
|
sb.Append(group[3]);
|
|
|
|
|
outs.Add(sb.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
File.WriteAllLines(outPath, outs);
|
|
|
|
|
Debug.WriteLine("NConv complete (" + outs.Count + " lines)");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|