Package mars.assembler
Class MacroPool
java.lang.Object
mars.assembler.MacroPool
Stores information of macros defined by now.
Will be used in first pass of assembling MIPS source code. Upon reaching
Each
NOTE: Forward referencing macros (macro expansion before its definition in source code) and Nested macro definition (defining a macro inside other macro definition) are not supported.
Will be used in first pass of assembling MIPS source code. Upon reaching
.macro
directive, parser calls
beginMacro(Token)
and skips source code lines until it reaches
.end_macro
directive. Then calls
commitMacro(Token)
and the macro information stored in a
Macro
instance will be added to macroList
. Each
MIPSprogram
will have one MacroPool
NOTE: Forward referencing macros (macro expansion before its definition in source code) and Nested macro definition (defining a macro inside other macro definition) are not supported.
- Author:
- M.H.Sekhavat <sekhavat17@gmail.com>
-
Constructor Summary
ConstructorsConstructorDescriptionMacroPool(MIPSprogram mipsProgram)
Create an empty MacroPool for given program -
Method Summary
Modifier and TypeMethodDescriptionvoid
beginMacro(Token nameToken)
Called by parser upon reaching.macro
directive.
Instantiates a newMacro
object and stores it incurrent
.void
commitMacro(Token endToken)
Called by parser upon reaching.end_macro
directive.getMatchingMacro(TokenList tokens, int callerLine)
Called by parser upon reaching a macro expansion callint
counter
will be set to 0 on construction of this class and will be incremented by each call. parser calls this method once for every expansion.boolean
matchesAnyMacroName(String value)
void
boolean
pushOnCallStack(Token token)
Adds the token's source line to the call stackvoid
setCurrent(Macro current)
-
Constructor Details
-
MacroPool
Create an empty MacroPool for given program- Parameters:
mipsProgram
- associated MIPS program
-
-
Method Details
-
beginMacro
Called by parser upon reaching.macro
directive.
Instantiates a newMacro
object and stores it incurrent
.current
will be added tomacroList
bycommitMacro(Token)
- Parameters:
nameToken
- Token containing name of macro after.macro
directive
-
commitMacro
Called by parser upon reaching.end_macro
directive.
Adds/Replacescurrent
macro into themacroList
.- Parameters:
endToken
- Token containing.end_macro
directive in source code
-
getMatchingMacro
Called by parser upon reaching a macro expansion call- Parameters:
tokens
- tokens passed to macro expansion call- Returns:
Macro
object matching the name and argument count of tokens passed
-
matchesAnyMacroName
- Parameters:
value
-- Returns:
- true if any macros have been defined with name
value
by now, not concerning arguments count.
-
getCurrent
-
setCurrent
-
getNextCounter
public int getNextCounter()counter
will be set to 0 on construction of this class and will be incremented by each call. parser calls this method once for every expansion. it will be a unique id for each macro expansion in a file- Returns:
- counter value
-
getCallStack
-
pushOnCallStack
Adds the token's source line to the call stack- Parameters:
token
-- Returns:
- true if expansion loop is detected
-
popFromCallStack
public void popFromCallStack() -
getExpansionHistory
-