0

I'm using m4 preprocessor with the command line option --synclines. This option emits #line <nn> lines after each expanded multi line.

Example:

; sr0(<register>, <count>) unrolls the sr0 statement for <register> <count> times.
sr0(reg_0, 3)
sr1 reg_1

Result:

#line 1 "test.psm"
; sr0(<register>, <count>) unrolls the sr0 statement for <register> <count> times.
sr0 reg_0
#line 2
sr0 reg_0
#line 2
sr0 reg_0
#line 2
sr1 reg_1

Because sr0(reg_0, 3) was originated in line 2, m4 adds #line 2 after each expansion.

How can I change the comment sign # to ;?, because the assembler does not support # as a comment sign.

Paebbels
  • 15,573
  • 13
  • 70
  • 139

1 Answers1

0

If you don't mind using sed, assuming the code produced by m4 is in test.psm:

$ sed 's/^#/;/' <test.psm
;line 1 "test.psm"
; sr0(<register>, <count>) unrolls the sr0 statement for <register> <count> times.
sr0 reg_0
;line 2
sr0 reg_0
;line 2
sr0 reg_0
;line 2
sr1 reg_1
Simon
  • 10,679
  • 1
  • 30
  • 44
  • I would like to get a m4-only solution. Running a second processing step with sed or other tools is possible, but this is not the wished solution, because it involves a second tool, temp files or stdin/stdout pipelining. – Paebbels May 05 '15 at 11:27
  • An `m4`-only solution would be possible by using `m4` to replace `#line` with `;line`, but that would require a) using `changeword` to allow the use of macros that include `#` in their names (which is experimental and so not always available, and it is subject to change if it is available), and b) it would require piping the output from `m4` into a second instance of `m4` to change `#line` to `;line` (which involves using pipelining, which you would like to avoid). – Simon May 05 '15 at 20:41
  • I see no way to change the synclines output using `m4`'s command line parameters but given that `m4` is free software, you could modify the source and re-compile a custom version of `m4` that output `;line` rather than `#line` for the synclines. Unless using a pipeline is simply impossible in your context, I wouldn't recommend this approach and would recommend using a pipeline instead. – Simon May 05 '15 at 20:46
  • `changecom(;)` is already active, but has no effect on synclines. Is this a bug? – Paebbels May 06 '15 at 07:01
  • 1
    Using `changecom` will change the comment character for input to `m4` but not output, unfortunately. – Simon May 06 '15 at 10:24