Skip to content

Commit 14a04e4

Browse files
committed
[assembler] Emit a pipe after an origin specification in the listing.
1 parent 6fe12a9 commit 14a04e4

File tree

6 files changed

+41
-12
lines changed

6 files changed

+41
-12
lines changed

assembler/src/asmlib/ast.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,14 @@ impl Ord for Origin {
777777
(Origin::Literal(_, _), Origin::Symbolic(_, _)) => Ordering::Less,
778778
(Origin::Symbolic(_, _), Origin::Literal(_, _)) => Ordering::Greater,
779779
}
780+
.then_with(|| {
781+
let my_span = self.span();
782+
let their_span = other.span();
783+
my_span
784+
.start
785+
.cmp(&their_span.start)
786+
.then_with(|| my_span.end.cmp(&their_span.end))
787+
})
780788
}
781789
}
782790

assembler/src/asmlib/driver.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ fn assemble_pass3(
473473
// tag (6-2.2).
474474
let span = origin.span();
475475
listing.push_line(ListingLine {
476-
origin: Some(origin),
477476
span: Some(span),
478477
rc_source: None,
479478
content: None,
@@ -511,7 +510,6 @@ fn assemble_pass3(
511510
);
512511

513512
listing.push_rc_line(ListingLine {
514-
origin: None,
515513
span: None,
516514
rc_source: Some(rc_source.clone()),
517515
content: Some((address, *word)),

assembler/src/asmlib/eval.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,6 @@ impl InstructionSequence {
752752
match instruction.evaluate(&here, symtab, rc_updater, &mut op) {
753753
Ok(word) => {
754754
listing.push_line(ListingLine {
755-
origin: None,
756755
span: Some(instruction.span),
757756
rc_source: None,
758757
content: Some((address, word)),

assembler/src/asmlib/listing.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::fmt::Display;
22

3-
use super::ast::Origin;
43
use super::span::Span;
54
use super::span::{extract_prefix, extract_span};
65
use super::symtab::FinalSymbolTable;
@@ -34,7 +33,6 @@ impl Listing {
3433

3534
#[derive(Debug)]
3635
pub(super) struct ListingLine {
37-
pub(super) origin: Option<Origin>,
3836
pub(super) span: Option<Span>,
3937
pub(super) rc_source: Option<RcWordSource>,
4038
pub(super) content: Option<(Address, Unsigned36Bit)>,
@@ -56,10 +54,6 @@ fn write_address(f: &mut std::fmt::Formatter<'_>, addr: &Address) -> std::fmt::R
5654

5755
impl Display for ListingLineWithBody<'_> {
5856
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
59-
if let Some(origin) = self.line.origin.as_ref() {
60-
writeln!(f, "{origin}| ** origin")?;
61-
}
62-
6357
match self.line.rc_source.as_ref() {
6458
Some(RcWordSource::DefaultAssignment(_, name)) => {
6559
write!(f, "{name:10}-> ")?;

assembler/src/asmlib/parser.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,7 @@ where
12461246
I: Input<'a, Token = Tok, Span = Span> + ValueInput<'a>,
12471247
{
12481248
literal(Script::Normal)
1249+
.then_ignore(just(Tok::Pipe(Script::Normal)))
12491250
.try_map(|lit, span| match Address::try_from(lit.value()) {
12501251
Ok(addr) => Ok(Origin::Literal(span, addr)),
12511252
Err(e) => Err(Rich::custom(span, format!("not a valid address: {e}"))),
@@ -1259,14 +1260,14 @@ where
12591260
I: Input<'a, Token = Tok, Span = Span> + ValueInput<'a>,
12601261
{
12611262
named_symbol(SymexSyllableRule::Multiple, Script::Normal)
1263+
.then_ignore(just(Tok::Pipe(Script::Normal)))
12621264
.map_with(|name, extra| Origin::Symbolic(extra.span(), name))
12631265
.labelled("symbolic address expression")
12641266
}
12651267

12661268
// An origin specification is an expression followed by a
12671269
// (normal-case) pipe symbol.
12681270
choice((literal_address_expression(), symbolic_address_expression()))
1269-
.then_ignore(just(Tok::Pipe(Script::Normal)))
12701271
.labelled("origin specification")
12711272
}
12721273

assembler/src/asmlib/parser/tests.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ fn test_manuscript_with_origin() {
790790
SourceFile {
791791
punch: None,
792792
blocks: vec![ManuscriptBlock {
793-
origin: Some(Origin::Literal(span(0..3), Address::new(u18!(0o100)))),
793+
origin: Some(Origin::Literal(span(0..5), Address::new(u18!(0o100)))),
794794
statements: vec![TaggedProgramInstruction::single(
795795
notags(),
796796
HoldBit::Unspecified,
@@ -1172,7 +1172,7 @@ fn test_assignment_origin() {
11721172
SourceFile {
11731173
punch: None,
11741174
blocks: vec![ManuscriptBlock {
1175-
origin: Some(Origin::Literal(span(9..13), Address::new(u18!(0o1000)))),
1175+
origin: Some(Origin::Literal(span(9..14), Address::new(u18!(0o1000)))),
11761176
statements: vec![TaggedProgramInstruction::single(
11771177
Vec::new(),
11781178
HoldBit::Unspecified,
@@ -1192,6 +1192,35 @@ fn test_assignment_origin() {
11921192
);
11931193
}
11941194

1195+
#[test]
1196+
fn test_symbolic_origin() {
1197+
const INPUT: &str = concat!("BEGIN|2\n",);
1198+
let tree = parse_successfully_with(INPUT, source_file(), no_state_setup);
1199+
assert_eq!(
1200+
tree,
1201+
SourceFile {
1202+
punch: None,
1203+
blocks: vec![ManuscriptBlock {
1204+
// One of the key things to check here is that the pipe
1205+
// symbol is included in the origin's span. We do
1206+
// this in order to include the pipe symbol in the
1207+
// output listing.
1208+
origin: Some(Origin::Symbolic(span(0..6), SymbolName::from("BEGIN"))),
1209+
statements: vec![TaggedProgramInstruction::single(
1210+
Vec::new(),
1211+
HoldBit::Unspecified,
1212+
span(6..7),
1213+
span(6..7),
1214+
InstructionFragment::from((span(6..7), Script::Normal, u36!(2),))
1215+
)]
1216+
.into(),
1217+
}],
1218+
equalities: Default::default(),
1219+
macros: Default::default(),
1220+
}
1221+
);
1222+
}
1223+
11951224
#[test]
11961225
fn test_metacommand_decimal() {
11971226
assert_eq!(

0 commit comments

Comments
 (0)