Beyond the EU: DORA and NIS 2 Directive's Global Impact
Cp0675 03 may-2012-rm04
1. Macro Processors
Chapter 4
System Software
An introduction to systems programming
Leland L. Beck
1
2. Introduction
q Concept
» A macro instruction is a notational convenience for the
programmer
» It allows the programmer to write shorthand version of a
program (module programming)
» The macro processor replaces each macro invocation with
the corresponding sequence of statements (expanding)
2
6. Macro vs. Subroutine
q Macro
» the statement of expansion are generated each time the
macro are invoked
q Subroutine
» the statement in a subroutine appears only once
6
9. One-Pass Macro Processor
q Prerequisite
» every macro must be defined before it is called
q Sub-procedures
» macro definition: DEFINE
» macro invocation: EXPAND
NAMTAB
MACRO DEFINE DEFTAB
PROCESSLINE
CALL EXPAND ARGTAB
9
10.
11. Data Structures -- Global Variables
q DEFTAB
q NAMTAB
q ARGTAB
EXPANDING
11
12. Nested Macros Definition
q Macro definition within macros
» process macro definition during expansion time
q Example 4.3
12
17. 1-Pass Macro Processor
D E F IN E
M ACR O
PR O C ESSO R
G E T L IN E
E X PA N D IN G = FA L SE
P R O C E S S L IN E
G E T L IN E EXPAND
P R O C E S S L IN E
E X PA N D IN G = T R U E
G E T L IN E
G E T L IN E
P R O C E S S L IN E
E X P A N D IN G FA L SE
TRUE
R EAD FRO M R EAD FR O M
D EFTAB IN P U T
17
18. Comparison of Macro Processors Design
q Single pass
» every macro must be defined before it is called
» one-pass processor can alternate between macro definition
and macro expansion
» nested macro definitions may be allowed but nested calls
are not
q Two pass algorithm
» Pass1: Recognize macro definitions
» Pass2: Recognize macro calls
» nested macro definitions are not allowed
18
23. Conditional Macro Expansion
q Macro-time conditional statements
» Example: Figure 4.8
» IF-ELSE-ENDIF
q Macro-time variables
» any symbol that begins with the character & and that is not a
macro parameter
» macro-time variables are initialized to 0
» macro-time variables can be changed with their values using
SET
– &EORCK SET 1
23
27. Conditional Macro Expansion (Cont.)
q Macro-time looping statement
» Example: Figure 4.9
» WHILE-ENDW
q Macro processor function
» %NITEMS: THE NUMBER OF MEMBERS IN AN
ARGUMENT LIST
27
28. Nested Macro Invocations
q Macro invocations within macros
» process macro invocation during expansion time
q Recursive macro expansion
» Example: Figure 4.11
» Problems:
– ARGTAB
– EXPANDING
» Solution
– Recursive call
– While loop with stack
28
30. 1-Pass Macro Processor
D E F IN E
M ACR O
PR O C ESSO R
G E T L IN E
E X PA N D IN G = FA L SE
P R O C E S S L IN E
G E T L IN E EXPAND
P R O C E S S L IN E
E X PA N D IN G = T R U E
G E T L IN E
G E T L IN E
P R O C E S S L IN E
E X P A N D IN G FA L SE
TRUE
R EAD FRO M R EAD FR O M
D EFTAB IN P U T
30
31. Allowing Nested Macro Invocation
D E F IN E (f)
M ACR O
PR O C ESSO R
G E T L IN E (f)
P R O C E S S L IN E (f)
G E T L IN E (0 )
P R O C E S S L IN E (0 ) EXPAND
G E T L IN E (1 )
G E T L IN E (f)
P R O C E S S L IN E (1 )
f FA L SE
TRUE
R EAD FRO M R EAD FR O M
D EFTAB IN P U T
31
32. Macro-Assembler
q Advantage
» reduce 1 pass
» share same data structure
q Disadvantage
» more complex
32
33. Pass 1 READ
Search Pass 2
R Type?
(Pseudo-Op Table)
Search NAMTAB MACRO Process
(Macro Name Table) Define pseudo-ops
Search R R
(Machine Op Table)
MACRO
Process Expand
machine
instruction
R
R
34. General Purpose Macro Processor
q ELENA
» Software: Practice and Experience, Vol. 14, pp. 519-531,
Jun. 1984
q Macro definition
» header:
– a sequence of keywords and parameter markers (%)
– at least one of the first two tokens in a macro header must be a
keyword, not a parameter marker
» body:
– the character & identifies a local label
– macro time instruction (.SET, .IF .JUMP, .E)
– macro time variables or labels (.)
34
35. ELENA (cont.)
q Macro invocation
» There is no single token that constitutes the macro “name”
» Constructing an index of all macro headers according to the
keywords in the first two tokens of the header
» Example
– DEFINITION:
q ADD %1 TO %2
q ADD %1 TO THE FIRST ELEMENT OF %2
– INVOCATION: DISPLAY %1
q DISPLAY TABLE
%1 TABLE
35