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 MacroPoolNOTE: 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 TypeMethodDescriptionvoidbeginMacro(Token nameToken)Called by parser upon reaching.macrodirective.
Instantiates a newMacroobject and stores it incurrent.voidcommitMacro(Token endToken)Called by parser upon reaching.end_macrodirective.getMatchingMacro(TokenList tokens, int callerLine)Called by parser upon reaching a macro expansion callintcounterwill be set to 0 on construction of this class and will be incremented by each call. parser calls this method once for every expansion.booleanmatchesAnyMacroName(String value)voidbooleanpushOnCallStack(Token token)Adds the token's source line to the call stackvoidsetCurrent(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.macrodirective.
Instantiates a newMacroobject and stores it incurrent.currentwill be added tomacroListbycommitMacro(Token)- Parameters:
nameToken- Token containing name of macro after.macrodirective
-
commitMacro
Called by parser upon reaching.end_macrodirective.
Adds/Replacescurrentmacro into themacroList.- Parameters:
endToken- Token containing.end_macrodirective in source code
-
getMatchingMacro
Called by parser upon reaching a macro expansion call- Parameters:
tokens- tokens passed to macro expansion call- Returns:
Macroobject matching the name and argument count of tokens passed
-
matchesAnyMacroName
- Parameters:
value-- Returns:
- true if any macros have been defined with name
valueby now, not concerning arguments count.
-
getCurrent
-
setCurrent
-
getNextCounter
public int getNextCounter()counterwill 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
-