mirror of
https://github.com/cc65/cc65.git
synced 2025-01-14 00:32:08 +00:00
Improvements by Piotr Fusik
git-svn-id: svn://svn.cc65.org/cc65/trunk@2578 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
6d8cdae722
commit
2ec21187ca
@ -8,7 +8,7 @@
|
|||||||
# #
|
# #
|
||||||
# #
|
# #
|
||||||
# (C) 2000-2003 Ullrich von Bassewitz #
|
# (C) 2000-2003 Ullrich von Bassewitz #
|
||||||
# Römerstrasse 52 #
|
# R÷merstrasse 52 #
|
||||||
# D-70794 Filderstadt #
|
# D-70794 Filderstadt #
|
||||||
# EMail: uz@cc65.org #
|
# EMail: uz@cc65.org #
|
||||||
# #
|
# #
|
||||||
@ -230,7 +230,7 @@ sub DocFooter {
|
|||||||
|
|
||||||
|
|
||||||
sub ColorizeComment {
|
sub ColorizeComment {
|
||||||
if ($Colorize) {
|
if ($Colorize && $_[0] ne "") {
|
||||||
return "<font color=\"$CommentColor\">$_[0]</font>";
|
return "<font color=\"$CommentColor\">$_[0]</font>";
|
||||||
} else {
|
} else {
|
||||||
return $_[0];
|
return $_[0];
|
||||||
@ -291,10 +291,10 @@ sub AddFile {
|
|||||||
|
|
||||||
# Check with the full pathname. If we don't find it, search in the current
|
# Check with the full pathname. If we don't find it, search in the current
|
||||||
# directory
|
# directory
|
||||||
if (-f $FileName && -r $FileName) {
|
if (-f $FileName && -r _) {
|
||||||
$Files{$Name} = $FileName;
|
$Files{$Name} = $FileName;
|
||||||
$FileCount++;
|
$FileCount++;
|
||||||
} elsif (-f $Name && -r $Name) {
|
} elsif (-f $Name && -r _) {
|
||||||
$Files{$Name} = $Name;
|
$Files{$Name} = $Name;
|
||||||
$FileCount++;
|
$FileCount++;
|
||||||
} else {
|
} else {
|
||||||
@ -388,7 +388,7 @@ sub Process1 {
|
|||||||
chop ($Line);
|
chop ($Line);
|
||||||
|
|
||||||
# Check for a label
|
# Check for a label
|
||||||
if ($Line =~ /^\s*(\@?)([_a-zA-Z][_\w]*)\s*(:|=)/) {
|
if ($Line =~ /^\s*(\@?)([_a-zA-Z]\w*)\s*(:|=)/) {
|
||||||
|
|
||||||
# Is this a local label?
|
# Is this a local label?
|
||||||
if ($1 eq "\@") {
|
if ($1 eq "\@") {
|
||||||
@ -423,7 +423,7 @@ sub Process1 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Check for a .proc statement
|
# Check for a .proc statement
|
||||||
} elsif ($Line =~ /^\s*\.proc\s+([_a-zA-Z][_\w]*)?.*$/) {
|
} elsif ($Line =~ /^\s*\.proc\s+([_a-zA-Z]\w*)?.*$/) {
|
||||||
|
|
||||||
# Do we have an id?
|
# Do we have an id?
|
||||||
$Id = $1;
|
$Id = $1;
|
||||||
@ -497,12 +497,12 @@ sub Process2 {
|
|||||||
Gabble ("$FileName => $OutName");
|
Gabble ("$FileName => $OutName");
|
||||||
|
|
||||||
# The instructions that will have hyperlinks if a label is used
|
# The instructions that will have hyperlinks if a label is used
|
||||||
my $LabelIns = "adc|add|and|asl|bcc|bcs|beq|bit|bmi|bne|bpl|bcv|bra|bvs|".
|
my $LabelIns = "adc|add|and|asl|bcc|bcs|beq|bit|bmi|bne|bpl|bra|bvc|bvs|".
|
||||||
"cmp|cpx|cpy|dec|eor|inc|jmp|jsr|lda|ldx|ldy|lsr|ora|rol|".
|
"cmp|cpx|cpy|dec|eor|inc|jmp|jsr|lda|ldx|ldy|lsr|ora|rol|".
|
||||||
"sbc|sta|stx|sty|sub|";
|
"ror|sbc|sta|stx|sty|stz|sub|";
|
||||||
|
|
||||||
# The instructions that will have hyperlinks if a label is used
|
# The instructions that will have hyperlinks if a label is used
|
||||||
my $AllIns = "adc|add|and|asl|bcc|bcs|beq|bge|bit|blt|bmi|bne|bpl|bcv|".
|
my $AllIns = "adc|add|and|asl|bcc|bcs|beq|bge|bit|blt|bmi|bne|bpl|bvc|".
|
||||||
"bra|brk|brl|bvs|clc|cld|cli|clv|cmp|cop|cpa|cpx|cpy|dea|".
|
"bra|brk|brl|bvs|clc|cld|cli|clv|cmp|cop|cpa|cpx|cpy|dea|".
|
||||||
"dec|dex|dey|eor|ina|inc|inx|iny|jml|jmp|jsl|jsr|lda|ldx|".
|
"dec|dex|dey|eor|ina|inc|inx|iny|jml|jmp|jsl|jsr|lda|ldx|".
|
||||||
"ldy|lsr|mvn|mvp|nop|ora|pea|pei|per|pha|phb|phd|phk|php|".
|
"ldy|lsr|mvn|mvp|nop|ora|pea|pei|per|pha|phb|phd|phk|php|".
|
||||||
@ -544,48 +544,25 @@ sub Process2 {
|
|||||||
|
|
||||||
# Cut off a comment from the input line. Beware: We have to check for
|
# Cut off a comment from the input line. Beware: We have to check for
|
||||||
# strings, since these may contain a semicolon that is no comment
|
# strings, since these may contain a semicolon that is no comment
|
||||||
# start. A perl guru would probably write all this in one line...
|
# start.
|
||||||
my $L = $Line;
|
($Line, $Comment) = $Line =~ /^((?:[^"';]+|".*?"|'.*?')*)(.*)$/;
|
||||||
$Line = "";
|
if ($Comment =~ /^["']/) {
|
||||||
$Comment = "";
|
# Line with invalid syntax - there's a string start but
|
||||||
while ($L ne "") {
|
# no string end.
|
||||||
if ($L =~ /^([^\"\';]+)(.*)$/) {
|
Abort (sprintf ("Invalid input at %s(%d)", $FileName, $LineNo));
|
||||||
$Line .= $1;
|
|
||||||
$L = $2;
|
|
||||||
}
|
|
||||||
if ($L =~ /^;/) {
|
|
||||||
# The remainder is a comment
|
|
||||||
$Comment = $L;
|
|
||||||
last;
|
|
||||||
} elsif ($L =~ /^(\"[^\"]*\")(.*)$/) {
|
|
||||||
$Line .= $1;
|
|
||||||
$L = $2;
|
|
||||||
} elsif ($L =~ /^(\'[^\']*\')(.*)$/) {
|
|
||||||
$Line .= $1;
|
|
||||||
$L = $2;
|
|
||||||
} elsif ($L =~ /^[\"\']/) {
|
|
||||||
# Line with invalid syntax - there's a string start but
|
|
||||||
# no string end.
|
|
||||||
Abort (sprintf ("Invalid input at %s(%d)", $FileName, $LineNo));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove trailing whitespace and move it together with the comment
|
# Remove trailing whitespace and move it together with the comment
|
||||||
# into the $Trailer variable.
|
# into the $Trailer variable.
|
||||||
if ($Line =~ /^(.*?)(\s*)$/) {
|
$Line =~ s/\s*$//;
|
||||||
$Line = $1;
|
$Trailer = $& . ColorizeComment (Cleanup ($Comment));
|
||||||
$Trailer = $2;
|
|
||||||
} else {
|
|
||||||
$Trailer = "";
|
|
||||||
}
|
|
||||||
$Trailer .= ColorizeComment (Cleanup ($Comment));
|
|
||||||
|
|
||||||
# Check for a label at the start of the line. If we have one, process
|
# Check for a label at the start of the line. If we have one, process
|
||||||
# it and remove it from the line
|
# it and remove it from the line
|
||||||
if ($Line =~ /^\s*?(\@?)([_a-zA-Z][_\w]*)(\s*)(:|=)(.*)$/) {
|
if ($Line =~ s/^\s*?(\@?)([_a-zA-Z]\w*)(\s*)(:|=)//) {
|
||||||
|
|
||||||
# Is this a local label?
|
# Is this a local label?
|
||||||
if ("$1" eq "\@") {
|
if ($1 eq "\@") {
|
||||||
# Use the prefix
|
# Use the prefix
|
||||||
$Id = "$CheapPrefix$1$2";
|
$Id = "$CheapPrefix$1$2";
|
||||||
} else {
|
} else {
|
||||||
@ -600,38 +577,32 @@ sub Process2 {
|
|||||||
|
|
||||||
# Print the label with a tag
|
# Print the label with a tag
|
||||||
$OutLine .= sprintf ("<a name=\"%s\">%s%s</a>%s%s", $Label, $1, $2, $3, $4);
|
$OutLine .= sprintf ("<a name=\"%s\">%s%s</a>%s%s", $Label, $1, $2, $3, $4);
|
||||||
|
|
||||||
# Use the remainder for line
|
|
||||||
$Line = $5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Print any leading whitespace and remove it, so we don't have to
|
# Print any leading whitespace and remove it, so we don't have to
|
||||||
# care about whitespace below.
|
# care about whitespace below.
|
||||||
if ($Line =~ /^(\s+)(.*)$/) {
|
if ($Line =~ s/^\s+//) {
|
||||||
$OutLine .= "$1";
|
$OutLine .= $&;
|
||||||
$Line = $2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Handle the import statements
|
# Handle the import statements
|
||||||
if ($Line =~ /^(\.import|\.importzp)(\s+)(.*)$/) {
|
if ($Line =~ s/^(\.import|\.importzp)\s+//) {
|
||||||
|
|
||||||
# Print any fixed stuff from the line and remove it
|
# Print any fixed stuff from the line and remove it
|
||||||
$OutLine .= $1 . $2;
|
$OutLine .= $&;
|
||||||
$Line = $3;
|
|
||||||
|
|
||||||
# Print all identifiers if there are any
|
# Print all identifiers if there are any
|
||||||
while ($Line =~ /^([_a-zA-Z][_\w]*)(.*)$/) {
|
while ($Line =~ s/^[_a-zA-Z]\w*//) {
|
||||||
|
|
||||||
# Identifier is $1, remainder is $2
|
# Remember the identifier
|
||||||
$Id = $1;
|
my $Id = $&;
|
||||||
$Line = $2;
|
|
||||||
|
|
||||||
# Variable to assemble HTML representation
|
# Variable to assemble HTML representation
|
||||||
my $Contents = "";
|
my $Contents = "";
|
||||||
|
|
||||||
# Make this import a link target
|
# Make this import a link target
|
||||||
if (exists ($Imports{$OutName}{$Id})) {
|
if (exists ($Imports{$OutName}{$Id})) {
|
||||||
$Label = $Imports{$OutName}{$1};
|
$Label = $Imports{$OutName}{$Id};
|
||||||
$Contents .= sprintf (" name=\"%s\"", $Label);
|
$Contents .= sprintf (" name=\"%s\"", $Label);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -650,9 +621,8 @@ sub Process2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Check if another identifier follows
|
# Check if another identifier follows
|
||||||
if ($Line =~ /^(\s*),(\s*)(.*)$/) {
|
if ($Line =~ s/^\s*,\s*//) {
|
||||||
$OutLine .= "$1,$2";
|
$OutLine .= $&;
|
||||||
$Line = $3;
|
|
||||||
} else {
|
} else {
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
@ -662,26 +632,24 @@ sub Process2 {
|
|||||||
$OutLine .= Cleanup ($Line);
|
$OutLine .= Cleanup ($Line);
|
||||||
|
|
||||||
# Handle export statements
|
# Handle export statements
|
||||||
} elsif ($Line =~ /^(\.export|\.exportzp)(\s+)(.*)$/) {
|
} elsif ($Line =~ s/^(\.export|\.exportzp)\s+//) {
|
||||||
|
|
||||||
# Print the command the and white space
|
# Print the command the and white space
|
||||||
$OutLine .= $1 . $2;
|
$OutLine .= $&;
|
||||||
$Line = $3;
|
|
||||||
|
|
||||||
# Print all identifiers if there are any
|
# Print all identifiers if there are any
|
||||||
while ($Line =~ /^([_a-zA-Z][_\w]*)(.*)$/) {
|
while ($Line =~ s/^[_a-zA-Z]\w*//) {
|
||||||
|
|
||||||
# Identifier is $1, remainder is $2
|
# Remember the identifier
|
||||||
$Id = $1;
|
my $Id = $&;
|
||||||
$Line = $2;
|
|
||||||
|
|
||||||
# Variable to assemble HTML representation
|
# Variable to assemble HTML representation
|
||||||
my $Contents = "";
|
my $Contents = "";
|
||||||
|
|
||||||
# If we have a definition for this export in this file, add
|
# If we have a definition for this export in this file, add
|
||||||
# a link to the definition.
|
# a link to the definition.
|
||||||
if (exists ($Labels{$OutName}{$1})) {
|
if (exists ($Labels{$OutName}{$Id})) {
|
||||||
$Label = $Labels{$OutName}{$1};
|
$Label = $Labels{$OutName}{$Id};
|
||||||
$Contents = sprintf (" href=\"#%s\"", $Label);
|
$Contents = sprintf (" href=\"#%s\"", $Label);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -690,7 +658,7 @@ sub Process2 {
|
|||||||
if (exists ($Exports{$Id})) {
|
if (exists ($Exports{$Id})) {
|
||||||
$Label = $Exports{$Id};
|
$Label = $Exports{$Id};
|
||||||
# Be sure to use only the label part
|
# Be sure to use only the label part
|
||||||
$Label =~ s/^(.*#)(.*)$/$2/; # ##FIXME: Expensive
|
$Label =~ s/^.*#//;
|
||||||
$Contents .= sprintf (" name=\"%s\"", $Label);
|
$Contents .= sprintf (" name=\"%s\"", $Label);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -702,9 +670,8 @@ sub Process2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Check if another identifier follows
|
# Check if another identifier follows
|
||||||
if ($Line =~ /^(\s*),(\s*)(.*)$/) {
|
if ($Line =~ s/^\s*,\s*//) {
|
||||||
$OutLine .= "$1,$2";
|
$OutLine .= $&;
|
||||||
$Line = $3;
|
|
||||||
} else {
|
} else {
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
@ -714,24 +681,22 @@ sub Process2 {
|
|||||||
$OutLine .= Cleanup ($Line);
|
$OutLine .= Cleanup ($Line);
|
||||||
|
|
||||||
# Check for .addr and .word
|
# Check for .addr and .word
|
||||||
} elsif ($Line =~ /^(\.addr|\.word)(\s+)(.*)$/) {
|
} elsif ($Line =~ s/^(\.addr|\.word)\s+//) {
|
||||||
|
|
||||||
# Print the command the and white space
|
# Print the command and the white space
|
||||||
$OutLine .= "$1$2";
|
$OutLine .= $&;
|
||||||
$Line = $3;
|
|
||||||
|
|
||||||
# Print all identifiers if there are any
|
# Print all identifiers if there are any
|
||||||
while ($Line =~ /^([_a-zA-Z][_\w]*)(.*)$/) {
|
while ($Line =~ /^([_a-zA-Z]\w*)(.*)$/) {
|
||||||
if (exists ($Labels{$OutName}{$1})) {
|
if (exists ($Labels{$OutName}{$1})) {
|
||||||
$Label = $Labels{$OutName}{$1};
|
$Label = $Labels{$OutName}{$1};
|
||||||
$OutLine .= sprintf ("<a href=\"#%s\">%s</a>", $Label, $1);
|
$OutLine .= sprintf ("<a href=\"#%s\">%s</a>", $Label, $1);
|
||||||
} else {
|
} else {
|
||||||
$OutLine .= "$1";
|
$OutLine .= $1;
|
||||||
}
|
}
|
||||||
$Line = $2;
|
$Line = $2;
|
||||||
if ($Line =~ /^(\s*),(\s*)(.*)$/) {
|
if ($Line =~ s/^\s*,\s*//) {
|
||||||
$OutLine .= "$1,$2";
|
$OutLine .= $&;
|
||||||
$Line = $3;
|
|
||||||
} else {
|
} else {
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
@ -741,7 +706,7 @@ sub Process2 {
|
|||||||
$OutLine .= Cleanup ($Line);
|
$OutLine .= Cleanup ($Line);
|
||||||
|
|
||||||
# Handle .proc
|
# Handle .proc
|
||||||
} elsif ($Line =~ /^(\.proc)(\s+)([_a-zA-Z][_\w]*)?(.*)$/) {
|
} elsif ($Line =~ /^(\.proc)(\s+)([_a-zA-Z]\w*)?(.*)$/) {
|
||||||
|
|
||||||
# Do we have an identifier?
|
# Do we have an identifier?
|
||||||
if ($3 ne "") {
|
if ($3 ne "") {
|
||||||
@ -785,13 +750,10 @@ sub Process2 {
|
|||||||
$OutLine .= Cleanup ($4);
|
$OutLine .= Cleanup ($4);
|
||||||
|
|
||||||
# Handle .dbg line
|
# Handle .dbg line
|
||||||
} elsif ($CRefs && $Line =~ /^(\.dbg)(\s+)(.*)$/) {
|
} elsif ($CRefs && $Line =~ s/^\.dbg\s+//) {
|
||||||
|
|
||||||
# Add the fixed stuff to the output line
|
# Add the fixed stuff to the output line
|
||||||
$OutLine .= "$1$2";
|
$OutLine .= $&;
|
||||||
|
|
||||||
# Remember the remainder
|
|
||||||
$Line = $3;
|
|
||||||
|
|
||||||
# Check for the type of the .dbg directive
|
# Check for the type of the .dbg directive
|
||||||
if ($Line =~ /^(line,\s*)\"((?:[^\"]+?|\\\")+)\"(,\s*)(\d+)(.*)$/) {
|
if ($Line =~ /^(line,\s*)\"((?:[^\"]+?|\\\")+)\"(,\s*)(\d+)(.*)$/) {
|
||||||
@ -818,7 +780,7 @@ sub Process2 {
|
|||||||
# Add the remainder
|
# Add the remainder
|
||||||
$OutLine .= Cleanup ($Line);
|
$OutLine .= Cleanup ($Line);
|
||||||
|
|
||||||
} elsif ($Line =~ /^(file,\s*)\"((?:[^\"]+?|\\\")+)\"(.*)$/) {
|
} elsif ($Line =~ /^(file,\s*)\"((?:[^\"]+?|\\\")+)\"(.*)$/) { #pf FIXME: doesn't handle \" correctly!
|
||||||
|
|
||||||
# Get the filename into a named variables
|
# Get the filename into a named variables
|
||||||
my $DbgFile = Cleanup ($2);
|
my $DbgFile = Cleanup ($2);
|
||||||
@ -872,10 +834,10 @@ sub Process2 {
|
|||||||
|
|
||||||
# Check for the first identifier in the operand and replace it
|
# Check for the first identifier in the operand and replace it
|
||||||
# by a hyperlink
|
# by a hyperlink
|
||||||
if ($Operand =~ /^([^_a-zA-Z]*?)(\@?)([_a-zA-Z][_\w]*)(.*)$/) {
|
if ($Operand =~ /^([^_a-zA-Z]*?)(\@?)([_a-zA-Z]\w*)(.*)$/) {
|
||||||
|
|
||||||
# Is this a local label?
|
# Is this a local label?
|
||||||
if ("$2" eq "\@") {
|
if ($2 eq "\@") {
|
||||||
# Use the prefix
|
# Use the prefix
|
||||||
$Id = "$CheapPrefix$2$3";
|
$Id = "$CheapPrefix$2$3";
|
||||||
} else {
|
} else {
|
||||||
@ -904,7 +866,7 @@ sub Process2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Colorize all keywords
|
# Colorize all keywords
|
||||||
$OutLine =~ s/(?<![\w;])\.[_a-zA-Z][_\w]*/ColorizeCtrl ($&)/ge;
|
$OutLine =~ s/(?<![\w;])\.[_a-zA-Z]\w*/ColorizeCtrl ($&)/ge;
|
||||||
|
|
||||||
# Add the trailer
|
# Add the trailer
|
||||||
$OutLine .= $Trailer;
|
$OutLine .= $Trailer;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user