#include <instruction.h>
Inheritance diagram for Instruction:


Public Types | |
| enum | InstructionType { Assembly, Raw, Comment } |
| enum | AssemblyType { FileOriented, BitOriented, WorkingOriented, Other, None } |
Public Member Functions | |
| Instruction () | |
| virtual | ~Instruction () |
| void | setCode (Code *code) |
| virtual InstructionType | type () const |
| virtual AssemblyType | assemblyType () const=0 |
| virtual QString | code () const=0 |
| void | setInputState (const ProcessorState &processorState) |
| virtual void | generateLinksAndStates (Code::iterator instruction) |
| virtual ProcessorBehaviour | behaviour () const |
| void | addInputLink (Instruction *inputLink) |
| void | addOutputLink (Instruction *inputLink) |
| InstructionList | inputLinks () const |
| InstructionList | outputLinks () const |
| void | removeInputLink (Instruction *ins) |
| void | removeOutputLink (Instruction *ins) |
| void | clearLinks () |
| QStringList | labels () const |
| void | addLabels (const QStringList &labels) |
| void | setLabels (const QStringList &labels) |
| void | setUsed (bool used) |
| bool | isUsed () const |
| void | setRegisterDepends (uchar depends, const Register ®) |
| uchar | registerDepends (const Register ®) |
| void | resetRegisterDepends () |
| ProcessorState | inputState () const |
| ProcessorState | outputState () const |
| Register | file () const |
| RegisterBit | bit () const |
| uchar | literal () const |
| Register | outputReg () const |
| unsigned | dest () const |
Public Attributes | |
| QString | operand |
| QString | description |
| QString | opcode |
Protected Member Functions | |
| void | makeOutputLinks (Code::iterator current, bool firstOutput=true, bool secondOutput=false) |
| void | makeLabelOutputLink (const QString &label) |
Protected Attributes | |
| RegisterDepends | m_registerDepends |
| bool | m_bInputStateChanged |
| bool | m_bUsed |
| bool | m_bPositionAffectsBranching |
| InstructionList | m_inputLinks |
| InstructionList | m_outputLinks |
| QStringList | m_labels |
| Code * | m_pCode |
| Register | m_file |
| RegisterBit | m_bit |
| QString | m_raw |
| uchar | m_literal |
| unsigned | m_dest:1 |
| ProcessorState | m_inputState |
| ProcessorState | m_outputState |
Definition at line 631 of file instruction.h.
Used in optimization. Note that this follows roughly, but not exactly, the Microchip classifications of similar categories.
| FileOriented | Writes to a file (which can be obtained by calling outputReg(). |
| BitOriented | Writes to a file bit (so BCF or BSF). |
| WorkingOriented | Affects the working register via a literal operation, with no branching (so excludes retlw). |
| Other | Assembly instructions that don't come under the above categories (so control and branching instructions). |
| None | The Instruction is not of Assembly InstructionType. |
Definition at line 644 of file instruction.h.
| virtual InstructionType Instruction::type | ( | ) | const [inline, virtual] |
This is used to decide how to output the instruction, and which instructions to avoid while optimizing.
Reimplemented in Instr_sourceCode, Instr_asm, and Instr_raw.
Definition at line 682 of file instruction.h.
Referenced by Code::append().
| virtual AssemblyType Instruction::assemblyType | ( | ) | const [pure virtual] |
Implemented in Instr_addwf, Instr_andwf, Instr_clrf, Instr_decf, Instr_decfsz, Instr_incf, Instr_iorwf, Instr_movf, Instr_movwf, Instr_rlf, Instr_rrf, Instr_subwf, Instr_swapf, Instr_xorwf, Instr_bcf, Instr_bsf, Instr_btfsc, Instr_btfss, Instr_addlw, Instr_andlw, Instr_call, Instr_goto, Instr_iorlw, Instr_movlw, Instr_retfie, Instr_retlw, Instr_return, Instr_sleep, Instr_sublw, Instr_xorlw, Instr_sourceCode, Instr_asm, and Instr_raw.
| virtual QString Instruction::code | ( | ) | const [pure virtual] |
The text to output to the generated assembly.
Implemented in Instr_addwf, Instr_andwf, Instr_clrf, Instr_decf, Instr_decfsz, Instr_incf, Instr_iorwf, Instr_movf, Instr_movwf, Instr_rlf, Instr_rrf, Instr_subwf, Instr_swapf, Instr_xorwf, Instr_bcf, Instr_bsf, Instr_btfsc, Instr_btfss, Instr_addlw, Instr_andlw, Instr_call, Instr_goto, Instr_iorlw, Instr_movlw, Instr_retfie, Instr_retlw, Instr_return, Instr_sleep, Instr_sublw, Instr_xorlw, Instr_sourceCode, Instr_asm, and Instr_raw.
Referenced by setCode().
| void Instruction::setInputState | ( | const ProcessorState & | processorState | ) | [inline] |
The input processor state is used to generate the outputlinks and the output processor state.
Definition at line 695 of file instruction.h.
References m_inputState.
| void Instruction::generateLinksAndStates | ( | Code::iterator | instruction | ) | [virtual] |
By using the ProcessorState, the Instruction should: * Find all instructions that could be executed after this instruction. * Generate the output ProcessorState. The default behaviour of this function is to link to the next sequential instruction, and to generate an unknown ProcessorState.
| instruction | points at this instruction |
Reimplemented in Instr_addwf, Instr_andwf, Instr_clrf, Instr_decf, Instr_decfsz, Instr_incf, Instr_iorwf, Instr_movf, Instr_movwf, Instr_rlf, Instr_rrf, Instr_subwf, Instr_swapf, Instr_xorwf, Instr_bcf, Instr_bsf, Instr_btfsc, Instr_btfss, Instr_addlw, Instr_andlw, Instr_call, Instr_goto, Instr_iorlw, Instr_movlw, Instr_retfie, Instr_retlw, Instr_return, Instr_sleep, Instr_sublw, and Instr_xorlw.
Definition at line 1261 of file instruction.cpp.
References m_outputState, makeOutputLinks(), and ProcessorState::reset().
| ProcessorBehaviour Instruction::behaviour | ( | ) | const [virtual] |
Reimplemented in Instr_addwf, Instr_andwf, Instr_clrf, Instr_decf, Instr_decfsz, Instr_incf, Instr_iorwf, Instr_movf, Instr_movwf, Instr_rlf, Instr_rrf, Instr_subwf, Instr_swapf, Instr_xorwf, Instr_bcf, Instr_bsf, Instr_btfsc, Instr_btfss, Instr_addlw, Instr_andlw, Instr_call, Instr_goto, Instr_iorlw, Instr_movlw, Instr_retfie, Instr_retlw, Instr_return, Instr_sleep, Instr_sublw, and Instr_xorlw.
Definition at line 1268 of file instruction.cpp.
Referenced by Optimizer::registerDepends().
| void Instruction::addInputLink | ( | Instruction * | inputLink | ) |
An input link is an instruction that might be executed immediately before this Instruction.
Definition at line 1304 of file instruction.cpp.
References addOutputLink(), and m_inputLinks.
Referenced by addOutputLink(), Instr_call::linkReturns(), and makeLabelOutputLink().
| void Instruction::addOutputLink | ( | Instruction * | inputLink | ) |
An output link is an instruction that might be executed immediately after this Instruction.
Definition at line 1315 of file instruction.cpp.
References addInputLink(), and m_outputLinks.
Referenced by addInputLink().
| InstructionList Instruction::inputLinks | ( | ) | const [inline] |
The list of instructions that might be executed immediately before this instruction.
Definition at line 726 of file instruction.h.
References m_inputLinks.
Referenced by Optimizer::redirectGotos().
| InstructionList Instruction::outputLinks | ( | ) | const [inline] |
The list of instructions that might be executed immediately after this instruction. Instruction does not generate these links; instead the list is generated Code::generateLinksAndStates function.
Definition at line 732 of file instruction.h.
References m_outputLinks.
Referenced by Optimizer::generateRegisterDepends(), Optimizer::optimizeInstructions(), and Optimizer::registerDepends().
| void Instruction::removeInputLink | ( | Instruction * | ins | ) |
Remove the given input link from the instruction.
Definition at line 1326 of file instruction.cpp.
References m_inputLinks.
| void Instruction::removeOutputLink | ( | Instruction * | ins | ) |
Remove the given output link from the instruction.
Definition at line 1332 of file instruction.cpp.
References m_outputLinks.
| void Instruction::clearLinks | ( | ) |
Clears all input and output links from this instruction. This does not remove references to this instruction from other instructions.
Definition at line 1338 of file instruction.cpp.
References m_inputLinks, and m_outputLinks.
| QStringList Instruction::labels | ( | ) | const [inline] |
An instruction may have zero, or more than zero labels associated with it - these will be printed before the instruction in the assembly output.
Definition at line 751 of file instruction.h.
References m_labels.
Referenced by Code::removeInstruction().
| void Instruction::addLabels | ( | const QStringList & | labels | ) |
Definition at line 1249 of file instruction.cpp.
References m_labels.
Referenced by Code::append().
| void Instruction::setLabels | ( | const QStringList & | labels | ) |
| void Instruction::setUsed | ( | bool | used | ) | [inline] |
Definition at line 763 of file instruction.h.
References m_bUsed.
Referenced by Instr_call::linkReturns(), Optimizer::redirectGotos(), and Optimizer::registerDepends().
| bool Instruction::isUsed | ( | ) | const [inline] |
Used for optimization purposes in determining whether the instruction has been examined yet (to avoid infinite loops).
Definition at line 768 of file instruction.h.
References m_bUsed.
Referenced by Instr_call::linkReturns(), Optimizer::redirectGotos(), and Optimizer::registerDepends().
| void Instruction::setRegisterDepends | ( | uchar | depends, | |
| const Register & | reg | |||
| ) | [inline] |
Set by the optimizer to indicate whether this instruction or any of its outputs overwrite any of the bits of the given register.
Definition at line 773 of file instruction.h.
References m_registerDepends, and RegisterDepends::reg().
Referenced by Optimizer::registerDepends().
| uchar Instruction::registerDepends | ( | const Register & | reg | ) | [inline] |
Definition at line 777 of file instruction.h.
References m_registerDepends, and RegisterDepends::reg().
Referenced by Optimizer::registerDepends().
| void Instruction::resetRegisterDepends | ( | ) | [inline] |
Resets the overwrites.
Definition at line 781 of file instruction.h.
References m_registerDepends, and RegisterDepends::reset().
| ProcessorState Instruction::inputState | ( | ) | const [inline] |
Definition at line 786 of file instruction.h.
References m_inputState.
Referenced by Optimizer::canRemove().
| ProcessorState Instruction::outputState | ( | ) | const [inline] |
Definition at line 791 of file instruction.h.
References m_outputState.
Referenced by Optimizer::canRemove().
| Register Instruction::file | ( | ) | const [inline] |
Only applicable to Instructions that refer to a file.
Definition at line 795 of file instruction.h.
References m_file.
Referenced by Instr_addwf::Instr_addwf(), Instr_andwf::Instr_andwf(), Instr_bcf::Instr_bcf(), Instr_bsf::Instr_bsf(), Instr_btfsc::Instr_btfsc(), Instr_btfss::Instr_btfss(), Instr_clrf::Instr_clrf(), Instr_decf::Instr_decf(), Instr_decfsz::Instr_decfsz(), Instr_incf::Instr_incf(), Instr_iorwf::Instr_iorwf(), Instr_movf::Instr_movf(), Instr_movwf::Instr_movwf(), Instr_rlf::Instr_rlf(), Instr_rrf::Instr_rrf(), Instr_subwf::Instr_subwf(), Instr_swapf::Instr_swapf(), and Instr_xorwf::Instr_xorwf().
| RegisterBit Instruction::bit | ( | ) | const [inline] |
Only applicable to Instructions that refer to a bit (such as BCF).
Definition at line 799 of file instruction.h.
References m_bit.
Referenced by Instr_btfss::generateLinksAndStates(), Instr_btfsc::generateLinksAndStates(), Instr_bcf::Instr_bcf(), Instr_bsf::Instr_bsf(), Instr_btfsc::Instr_btfsc(), and Instr_btfss::Instr_btfss().
| uchar Instruction::literal | ( | ) | const [inline] |
Only applicable to instructions that refer to a literal (such as XORLW).
Definition at line 804 of file instruction.h.
References m_literal.
| Register Instruction::outputReg | ( | ) | const [inline] |
Applicable only to instructions that save a result to working or file depending on the destination bit.
Definition at line 809 of file instruction.h.
References m_dest, and m_file.
Referenced by Instr_xorwf::generateLinksAndStates(), Instr_subwf::generateLinksAndStates(), Instr_rrf::generateLinksAndStates(), Instr_rlf::generateLinksAndStates(), Instr_iorwf::generateLinksAndStates(), Instr_incf::generateLinksAndStates(), Instr_decfsz::generateLinksAndStates(), Instr_decf::generateLinksAndStates(), Instr_andwf::generateLinksAndStates(), and Instr_addwf::generateLinksAndStates().
| unsigned Instruction::dest | ( | ) | const [inline] |
Applicable only to instructions that use the destination flag.
Definition at line 813 of file instruction.h.
References m_dest.
| void Instruction::makeOutputLinks | ( | Code::iterator | current, | |
| bool | firstOutput = true, |
|||
| bool | secondOutput = false | |||
| ) | [protected] |
This function is provided for convenience; it creates links to the first or second instructions after this one, depending on the value of firstOutput and secondOutput.
Definition at line 1274 of file instruction.cpp.
Referenced by Instr_xorlw::generateLinksAndStates(), Instr_sublw::generateLinksAndStates(), Instr_movlw::generateLinksAndStates(), Instr_iorlw::generateLinksAndStates(), Instr_andlw::generateLinksAndStates(), Instr_addlw::generateLinksAndStates(), Instr_btfss::generateLinksAndStates(), Instr_btfsc::generateLinksAndStates(), Instr_bsf::generateLinksAndStates(), Instr_bcf::generateLinksAndStates(), Instr_xorwf::generateLinksAndStates(), Instr_swapf::generateLinksAndStates(), Instr_subwf::generateLinksAndStates(), Instr_rrf::generateLinksAndStates(), Instr_rlf::generateLinksAndStates(), Instr_movwf::generateLinksAndStates(), Instr_movf::generateLinksAndStates(), Instr_iorwf::generateLinksAndStates(), Instr_incf::generateLinksAndStates(), Instr_decfsz::generateLinksAndStates(), Instr_decf::generateLinksAndStates(), Instr_clrf::generateLinksAndStates(), Instr_andwf::generateLinksAndStates(), Instr_addwf::generateLinksAndStates(), and generateLinksAndStates().
| void Instruction::makeLabelOutputLink | ( | const QString & | label | ) | [protected] |
This function is provided for instructions that jump to a label (i.e. call and goto).
Definition at line 1296 of file instruction.cpp.
References addInputLink(), Code::instruction(), and m_pCode.
Referenced by Instr_goto::generateLinksAndStates(), and Instr_call::generateLinksAndStates().
1.5.1