InstructionFactory Class Reference

Dynamically create Instruction objects given an InstructionDescription description of the desired Instruction. More...

#include <InstructionFactory.h>

List of all members.

Public Member Functions

 InstructionFactory ()

Static Public Member Functions

static InstructioncreateInstruction (string const &name, vector< RegisterReference * > const &operands)
static InstructioncreateInstruction (string const &name, TProgramCounter pc, RegisterReference *operand)
static InstructioncreateInstruction (string const &name, string const &function, vector< RegisterReference * > const &operands)
static string signatures ()
static string extendedSignatures ()
static void registerInstructions ()
static StringToCreateFngetInstructionTable ()
static ExtendedInstructionTablegetExtendedInstructionTable ()

Static Private Member Functions

static InstructioncreateInstructionHelper (InstructionSignature const &sig)

Static Private Attributes

static StringToCreateFn instructionTable
 A map to hold regular instructions.
static ExtendedInstructionTable extendedTable
 A map to hold extended instructions.


Detailed Description

Dynamically create Instruction objects given an InstructionDescription description of the desired Instruction.

Definition at line 40 of file InstructionFactory.h.


Constructor & Destructor Documentation

InstructionFactory::InstructionFactory (  )  [inline, explicit]

Definition at line 44 of file InstructionFactory.h.

00044 {}


Member Function Documentation

Instruction * InstructionFactory::createInstruction ( string const &  name,
vector< RegisterReference * > const &  operands 
) [static]

Definition at line 33 of file InstructionFactory.cpp.

References createInstructionHelper().

Referenced by CalcAssembler::createInstruction().

00036 {
00037     InstructionSignature signature(name, operands);
00038     return createInstructionHelper(signature);
00039 }

Instruction * InstructionFactory::createInstruction ( string const &  name,
TProgramCounter  pc,
RegisterReference operand 
) [static]

Definition at line 43 of file InstructionFactory.cpp.

References createInstructionHelper().

00047 {
00048     vector<RegisterReference*> v;
00049     if (operand) {
00050         v.push_back(operand);
00051     }
00052 
00053     InstructionSignature signature(name, pc, v);
00054     return createInstructionHelper(signature);
00055 }

Instruction * InstructionFactory::createInstruction ( string const &  name,
string const &  function,
vector< RegisterReference * > const &  operands 
) [static]

Definition at line 71 of file InstructionFactory.cpp.

References InstructionSignature::compute(), ExtendedInstructionDef::createInstruction(), and extendedTable.

00075 {
00076     InstructionSignature signature(function, operands);
00077     ExtendedInstructionDef* instDef = extendedTable[signature.compute()];
00078     if (instDef == NULL) {
00079         return NULL;
00080     }
00081     return instDef->createInstruction(operands);
00082 }

string InstructionFactory::signatures (  )  [static]

Definition at line 85 of file InstructionFactory.cpp.

References instructionTable.

Referenced by Calculator::assemble().

00086 {
00087     ostringstream s("");
00088 
00089     StringToCreateFnIter i = instructionTable.begin();
00090     StringToCreateFnIter end = instructionTable.end();
00091 
00092     while (i != end) {
00093         s << (*i).first << endl;
00094         i++;
00095     }
00096     return s.str();
00097 }

string InstructionFactory::extendedSignatures (  )  [static]

Definition at line 100 of file InstructionFactory.cpp.

References extendedTable, and ExtendedInstructionTable::signatures().

Referenced by Calculator::assemble().

00101 {
00102     return extendedTable.signatures();
00103 }

void InstructionFactory::registerInstructions (  )  [static]

Definition at line 106 of file InstructionFactory.cpp.

References ReturnInstructionRegister::registerInstructions(), PointerPointerInstructionRegister::registerInstructions(), PointerIntegralInstructionRegister::registerInstructions(), NativeNativeInstructionRegister::registerInstructions(), JumpInstructionRegister::registerInstructions(), IntegralPointerInstructionRegister::registerInstructions(), IntegralNativeInstructionRegister::registerInstructions(), CastInstructionRegister::registerInstructions(), BoolPointerInstructionRegister::registerInstructions(), BoolNativeInstructionRegister::registerInstructions(), and BoolInstructionRegister::registerInstructions().

Referenced by CalcInit::instance(), and main().

static StringToCreateFn* InstructionFactory::getInstructionTable (  )  [inline, static]

Definition at line 78 of file InstructionFactory.h.

Referenced by InstructionRegister::registerInstance(), InstructionRegister::registerInstance2(), and ReturnInstructionRegister::registerInstructions().

00079     {
00080         return &instructionTable;
00081     }

static ExtendedInstructionTable* InstructionFactory::getExtendedInstructionTable (  )  [inline, static]

Definition at line 85 of file InstructionFactory.h.

Referenced by CalcInit::instance(), CalcExtContextTest::setupExtendedTestInstructions(), and CalcAssemblerTest::testExtended().

00086     {
00087         return &extendedTable;
00088     }

Instruction * InstructionFactory::createInstructionHelper ( InstructionSignature const &  sig  )  [static, private]

Definition at line 58 of file InstructionFactory.cpp.

References InstructionSignature::compute(), and instructionTable.

Referenced by createInstruction().

00059 {
00060     InstructionCreateFunction createFn = instructionTable[sig.compute()];
00061 
00062     if (createFn) {
00063         return createFn(sig);
00064     } else {
00065         throw FennelExcn(sig.compute() + " is not a registered instruction");
00066     }
00067 }


Member Data Documentation

StringToCreateFn InstructionFactory::instructionTable [static, private]

A map to hold regular instructions.

Definition at line 95 of file InstructionFactory.h.

Referenced by createInstructionHelper(), and signatures().

ExtendedInstructionTable InstructionFactory::extendedTable [static, private]

A map to hold extended instructions.

Definition at line 97 of file InstructionFactory.h.

Referenced by createInstruction(), and extendedSignatures().


The documentation for this class was generated from the following files:
Generated on Mon Jun 22 04:00:32 2009 for Fennel by  doxygen 1.5.1