Advertisement
Enderlook

IL Function Errors

Oct 7th, 2022
1,796
0
9 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 3.19 KB | None | 0 0
  1. /// Stores errors produced during the validation of an instruction.
  2. #[derive(Clone, Debug, Hash, PartialEq)]
  3. pub enum InstructionError {
  4.     /// Represent a non-termination instruction of a block.
  5.     NonTermination {
  6.         /// Index of the instruction.
  7.         /* Users can't actually read the instructions of a method once appended, however, this number is in the same order they appended them
  8.          so a user can infer which instruction caused error by counting the instructions they added.*/
  9.         index: usize,
  10.         /// Error of the instruction.
  11.         error: NonTerminalInstructionError,
  12.         /// Provides an IR text representation of the instruction which produced the error.
  13.         /* Useful for easier understanding of the instruction which causes the error?. */
  14.         text: String,
  15.     },
  16.     /// Represent the last instruction of a block.
  17.     Termination {
  18.         /* Termination instruction doesn't have index because they are the last instruction of a block. */
  19.        
  20.         /// Error of the instruction.
  21.         error: TerminalInstructionError,
  22.         /// Provides an IR text representation of the instruction which produced the error.
  23.         text: String,
  24.     },
  25. }
  26.  
  27. /// Represent an erreore ofe a non-terminal instruction.
  28. #[derive(Clone, Debug, Hash, PartialEq)]
  29. pub enum NonTerminalInstructionError {
  30.     /// The instruction accepts two arguments whose type must be the same but different types where provided for each argument.
  31.     Arguments2MustBeOfSameType([InstructionTypedArgument; 2]),
  32.     /// The instruction was provided with an argument of wrong type.
  33.     InvalidArgumentType {
  34.         /// Argument provided.
  35.         argument: InstructionTypedArgument,
  36.         /// Expected type.
  37.         expected: InstructionParameterType,
  38.     }
  39.     // [...] TODO: Add more errors.
  40.     InvalidArgumentForCalledFunction {
  41.         /// Function called.
  42.         function: FuncDec,
  43.         /// Index of parameter.
  44.         index: usize,
  45.         /// Expected type of the parameter.
  46.         expectedType: Type,
  47.         /// Type of argument passed.
  48.         passedType: Type,
  49.     } // The instruction is a function call, but wrong argument was supplied.
  50.     InvalidArgumentsCountForCalledFunctionn {
  51.         /// Function called.
  52.         function: FuncDec,
  53.         /// Number of arguments expected.
  54.         expected: usize,
  55.         /// Number of arguments found.
  56.         found: usize,
  57.     }
  58. }
  59.  
  60. #[derive(Clone, Debug, Hash, PartialEq)]
  61. /// Represent a typed argument passed to a parameter.
  62. pub struct InstructionTypedArgument {
  63.     /// Name of the parameter.
  64.     pub name: InstructionParameterName,
  65.     /// Type of the argument passed.
  66.     pub type_: Type,
  67. }
  68.  
  69.  
  70.  
  71. #[derive(Clone, Debug, Hash, PartialEq)]
  72. /// Represent the name of a parameter.
  73. pub enum InstructionParameterName {
  74.     Op1,
  75.     Op2,
  76.     /// [...] TODO: Some instructions can have different parameter names
  77. }
  78.  
  79. #[derive(Clone, Debug, Hash, PartialEq)]
  80. /// Represent the expected type of an argument that are allowed to pass to an specific parameter.
  81. pub enum InstructionParameterType {
  82.     /// Accepts any integer type or scalar of integers.
  83.     ScalarOrArrayOfIntegers,
  84.     /// Accepts any floating point type or scalar of floating points.
  85.     ScalarOrArrayOfFloatingPoints,
  86.     /// Accepts an specific type.
  87.     OfType(Type),
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement