12#include <unordered_map>
13#include <unordered_set>
77 std::unordered_map<std::string, std::unordered_set<std::string>>
function_vars;
102 const std::string &op,
103 const std::vector<ParsedOp> &ops,
104 const std::unordered_map<std::string, Variable> &vars,
105 const std::unordered_map<std::string, std::string> &labels,
106 const std::unordered_set<std::string> &objects,
107 std::vector<UseVar> &usedVarsRef,
108 std::vector<UseLabel> &usedLabelsRef);
115 bool validate(
const std::string &name);
117 bool match(
const std::string &m);
119 void require(
const std::string &r);
127 bool peekIs(
const std::string &s);
133 void collect_labels(std::unordered_map<std::string, std::string> &labels);
135 void collect_objects(std::unordered_set<std::string> &objects,
size_t start_index,
size_t end_index);
const scan::TToken * token
std::vector< ParsedOp > parseOperandList()
Parse a comma-separated list of operands.
ParsedOp parseOperand()
Parse a single instruction operand from the token stream.
bool match(const std::string &m)
Check if the current token value matches and advance.
void require(const std::string &r)
Require the current token value to match, or report an error.
bool validate(const std::string &name)
Run full validation on the source program.
bool peekIs(const std::string &s)
Check if the current token value matches without consuming.
Validator(const std::string &source)
Construct a validator from MXVM source code.
bool next()
Advance to the next token; returns false at end.
std::vector< VarNamePair > var_names
std::string tokenTypeToString(types::TokenType t)
Convert a TokenType to its display string.
std::unordered_map< std::string, std::unordered_set< std::string > > function_vars
void collect_objects(std::unordered_set< std::string > &objects, size_t start_index, size_t end_index)
Collect all object names declared between token indices.
std::string current_function
void collect_labels(std::unordered_map< std::string, std::string > &labels)
Pre-collect all label declarations and map them to function names.
void validateAgainstSpec(const std::string &op, const std::vector< ParsedOp > &ops, const std::unordered_map< std::string, Variable > &vars, const std::unordered_map< std::string, std::string > &labels, const std::unordered_set< std::string > &objects, std::vector< UseVar > &usedVarsRef, std::vector< UseLabel > &usedLabelsRef)
Validate an instruction's operands against the spec table.
Lexical scanner that tokenizes source text.
Instruction set enum, operand/instruction structs, variable types, and Variable/Variable_Value defini...
VArity
Variadic arity policy for instruction operand specs.
@ None
exact fixed operand count required
@ ArgsTail
fixed operands followed by argument-typed trailing operands
@ AnyTail
fixed operands followed by any number of trailing operands
OpKind
Classification of operand kinds for validation.
token::Token< char > TToken
Default token type.
TokenType
Classification of scanned tokens.
Lexical scanner that tokenizes source text into typed tokens.
Specification of valid operand patterns for an instruction.
std::string name
instruction mnemonic
std::vector< OpKind > fixed
required fixed operand kinds
A parsed operand with its kind, text, and source location.
const scan::TToken * at
token at the operand's source position
Records a label usage site for validation.
Records a variable usage site for validation.
A variable name paired with its declaration token.
const scan::TToken * second
token at the declaration
std::string first
variable name