From 1885da4f49cf32efde2d4c840365c4333a0c8579 Mon Sep 17 00:00:00 2001 From: "Vikram S. Adve" Date: Tue, 31 Jul 2001 21:49:28 +0000 Subject: [PATCH] Allow machine instructions with variable numbers of arguments. This is used only by Phi for now. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MachineInstr.h | 5 +++++ lib/CodeGen/MachineInstr.cpp | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/llvm/CodeGen/MachineInstr.h b/include/llvm/CodeGen/MachineInstr.h index a26c61accc2..79efe36fb4c 100644 --- a/include/llvm/CodeGen/MachineInstr.h +++ b/include/llvm/CodeGen/MachineInstr.h @@ -217,6 +217,9 @@ public: public: /*ctor*/ MachineInstr (MachineOpCode _opCode, OpCodeMask _opCodeMask = 0x0); + /*ctor*/ MachineInstr (MachineOpCode _opCode, + unsigned numOperands, + OpCodeMask _opCodeMask = 0x0); inline ~MachineInstr () {} const MachineOpCode getOpCode () const; @@ -260,12 +263,14 @@ MachineInstr::getNumOperands() const inline MachineOperand& MachineInstr::getOperand(unsigned int i) { + assert(i < operands.size() && "getOperand() out of range!"); return operands[i]; } inline const MachineOperand& MachineInstr::getOperand(unsigned int i) const { + assert(i < operands.size() && "getOperand() out of range!"); return operands[i]; } diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp index 64fcaa05771..d3e468cc2eb 100644 --- a/lib/CodeGen/MachineInstr.cpp +++ b/lib/CodeGen/MachineInstr.cpp @@ -19,12 +19,23 @@ //************************ Class Implementations **************************/ - +// Constructor for instructions with fixed #operands (nearly all) MachineInstr::MachineInstr(MachineOpCode _opCode, OpCodeMask _opCodeMask) : opCode(_opCode), opCodeMask(_opCodeMask), operands(TargetInstrDescriptors[_opCode].numOperands) +{ + assert(TargetInstrDescriptors[_opCode].numOperands >= 0); +} + +// Constructor for instructions with variable #operands +MachineInstr::MachineInstr(MachineOpCode _opCode, + unsigned numOperands, + OpCodeMask _opCodeMask) + : opCode(_opCode), + opCodeMask(_opCodeMask), + operands(numOperands) { }