mars.assembler
Class MacroPool

java.lang.Object
  extended by mars.assembler.MacroPool

public class MacroPool
extends Object

Stores information of macros defined by now.
Will be used in first pass of assembling MIPS source code. When reached .macro directive, parser calls MacroPool#BeginMacro(String, int) and skips source code lines until reaches .end_macro directive. then calls MacroPool#CommitMacro(int) 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

Constructor Summary
MacroPool(MIPSprogram mipsProgram)
          Create an empty MacroPool for given program
 
Method Summary
 void beginMacro(Token nameToken)
          This method will be called by parser when reached .macro directive.
Instantiates a new Macro object and stores it in current .
 void commitMacro(Token endToken)
          This method will be called by parser when reached .end_macro directive.
 ArrayList<Integer> getCallStack()
           
 Macro getCurrent()
           
 String getExpansionHistory()
           
 Macro getMatchingMacro(TokenList tokens, int callerLine)
          Will be called by parser when reaches a macro expansion call
 int getNextCounter()
          counter will be set to 0 on construction of this class and will be incremented by each call.
 boolean matchesAnyMacroName(String value)
           
 void popFromCallStack()
           
 boolean pushOnCallStack(Token token)
           
 void setCurrent(Macro current)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MacroPool

public MacroPool(MIPSprogram mipsProgram)
Create an empty MacroPool for given program

Parameters:
mipsProgram - associated MIPS program
Method Detail

beginMacro

public void beginMacro(Token nameToken)
This method will be called by parser when reached .macro directive.
Instantiates a new Macro object and stores it in current . current will be added to macroList by #CommitMacro(int)

Parameters:
nameToken - Token containing name of macro after .macro directive

commitMacro

public void commitMacro(Token endToken)
This method will be called by parser when reached .end_macro directive.
Adds/Replaces current macro into the macroList.

Parameters:
endToken - Token containing .end_macro directive in source code

getMatchingMacro

public Macro getMatchingMacro(TokenList tokens,
                              int callerLine)
Will be called by parser when reaches 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

public boolean matchesAnyMacroName(String value)
Parameters:
value -
Returns:
true if any macros have been defined with name value by now, not concerning arguments count.

getCurrent

public Macro getCurrent()

setCurrent

public void setCurrent(Macro current)

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 expansions. it will be a unique id for each expansion of macro in a file

Returns:
counter value

getCallStack

public ArrayList<Integer> getCallStack()

pushOnCallStack

public boolean pushOnCallStack(Token token)

popFromCallStack

public void popFromCallStack()

getExpansionHistory

public String getExpansionHistory()