Services and Modeling for Embedded Software Development
Embecosm divider strip
Prev  Next

3.4. Matching and Emitting Instructions

With the OR1KOperand structure defined, the main MatchAndEmitInstruction can be implemented, calling on the MatchInstructionImpl generated by TableGen to do the hard work.

When called, MatchInstructionImpl will use a given MCInst to store details on the instruction if possible, returning an error value. If the instruction was successfully parsed, the value Match_Success is returned and the instruction can be simply emitted via the provided MCStreamer.

If however there is a problem parsing the instruction, the return code will be different and set depending on where the problem occurred. For example Match_MissingFeature is returned if a required target feature is not enabled and Match_MnemonicFail is returned if the instruction mnemonic is not recognized.

These return codes can be used to generate a useful error message, though the simplest case would be just to state than an error occurred and then return. This case is demonstrated below.

bool OR1KAsmParser::
MatchAndEmitInstruction(SMLoc IDLoc,
                        SmallVectorImpl<MCParsedAsmOperand*> &Operands,
                        MCStreamer &Out) {
  MCInst Inst;
  SMLoc ErrorLoc;
  unsigned ErrorInfo;

  if (MatchInstructionImpl(Operands, Inst, ErrorInfo)) {
    return false;
    return Error(IDLoc, "Error parsing instruction");
Embecosm divider strip