
// Declarations for execute() methods.
def template BasicExecDeclare {{
        Fault execute(%(CPU_exec_context)s *, Trace::InstRecord *) const;
}};

// Basic instruction class declaration template.
def template BasicDeclare {{
        /**
         * Static instruction class for "%(mnemonic)s".
         */
        class %(class_name)s : public %(base_class)s
        {
          public:
            // Constructor.
            %(class_name)s(MachInst machInst);
            %(BasicExecDeclare)s
        };
}};

// Basic instruction class constructor template.
def template BasicConstructor {{
        inline %(class_name)s::%(class_name)s(MachInst machInst)
            : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s)
        {
                %(constructor)s;
        }
}};

// Basic instruction class execute method template.
def template BasicExecute {{
        Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
                Trace::InstRecord *traceData) const
        {
            Fault fault = NoFault;

            %(fp_enable_check)s;
            %(op_decl)s;
            %(op_rd)s;
            %(code)s;

            if(fault == NoFault)
            {
                %(op_wb)s;
            }
            return fault;
        }
}};

// Basic decode template.
def template BasicDecode {{
        return new %(class_name)s(machInst);
}};

// Basic decode template, passing mnemonic in as string arg to constructor.
def template BasicDecodeWithMnemonic {{
        return new %(class_name)s("%(mnemonic)s", machInst);
}};

// The most basic instruction format... used only for a few misc. insts
def format BasicOperate(code, *flags) {{
        iop = InstObjParams(name, Name, 'SparcStaticInst',
                CodeBlock(code), flags)
        header_output = BasicDeclare.subst(iop)
        decoder_output = BasicConstructor.subst(iop)
        decode_block = BasicDecode.subst(iop)
        exec_output = BasicExecute.subst(iop)
}};
