// http://llvm.org/docs/LangRef.html#sdiv-instr
// keywords: arithmetic; binary; instr

.type SDivInstruction <: symbol
.decl sdiv_instr(instr:SDivInstruction)

instr(v) :- sdiv_instr(v).

.decl sdiv_instr_first_operand(instr:SDivInstruction, op:Operand)
.decl sdiv_instr_second_operand(instr:SDivInstruction, op:Operand)


//------------------------------------------------------------------------------
// [Constraints]
//
// 1) The two arguments to the ‘sdiv‘ instr must be:
//      (i)  integer or
//      (ii) vector of integer values.
//
// 2) Both arguments must have identical types.
//
// 3) The resulting value is the same type as its operands.
//------------------------------------------------------------------------------

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
   schema_sanity(),
   sdiv_instr(Instr),
   !sdiv_instr_first_operand(Instr, _).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
   schema_sanity(),
   sdiv_instr(Instr),
   !sdiv_instr_second_operand(Instr, _).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
   schema_sanity(),
   sdiv_instr(Instr),
   instr_returns_type(Instr, Type),
   !integer_type(Type),
   !integer_vector_type(Type).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
   schema_sanity(),
   instr_returns_type(Instr, Type),
   sdiv_instr_first_operand(Instr, LeftOp),
   !operand_has_type(LeftOp, Type).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
   schema_sanity(),
   instr_returns_type(Instr, Type),
   sdiv_instr_second_operand(Instr, RightOp),
   !operand_has_type(RightOp, Type).
