// http://llvm.org/docs/LangRef.html#zext-to-instr
// keywords: conversion; unary; instr

.type ZExtInstruction <: symbol
.decl zext_instr(instr:ZExtInstruction)

instr(v) :- zext_instr(v).

.decl zext_instr_from_operand(instr:ZExtInstruction, val:Operand)
.decl zext_instr_to_type(instr:ZExtInstruction, type:Type)


// Helper predicate

.decl zext_instr_from_type(instr:ZExtInstruction, type:Type)

zext_instr_from_type(Instr, Type) :-
   zext_instr_from_operand(Instr, Operand),
   operand_has_type(Operand, Type).


//------------------------------------------------------------------------------
// [Constraints]
//
// 1) The ‘zext‘ instr takes:
//      (i)  a value to cast,
//      (ii) and a type to cast it to.
//
// 2) Both source and destination types must be:
//      (i)  integers or
//      (ii) vectors of the same number of integers.
//
// 3) The source type must be smaller than the destination type.
//------------------------------------------------------------------------------

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
   schema_sanity(),
   zext_instr(Instr),
   !zext_instr_from_operand(Instr, _).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
   schema_sanity(),
   zext_instr(Instr),
   !zext_instr_to_type(Instr, _).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
   schema_sanity(),
   zext_instr(Instr),
   zext_instr_to_type(Instr, Type),
   !instr_returns_type(Instr, Type).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
   schema_sanity(),
   zext_instr(Instr),
   zext_instr_from_type(Instr, Type),
   !integer_type(Type),
   !integer_vector_type(Type).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
   schema_sanity(),
   zext_instr(Instr),
   zext_instr_to_type(Instr, Type),
   !integer_type(Type),
   !integer_vector_type(Type).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
   schema_sanity(),
   zext_instr(Instr),
   zext_instr_from_type(Instr, FromType),
   zext_instr_to_type(Instr, ToType),
   !vector_compatible_types(FromType, ToType).
