mirror of
https://github.com/odin-lang/Odin.git
synced 2026-08-21 04:30:50 +00:00
Support #byte directive for asm templates
This commit is contained in:
@@ -1486,6 +1486,38 @@ gb_internal void check_asm_template(AsmCtx *asm_ctx, CheckerContext *ctx, Entity
|
||||
}
|
||||
case_end;
|
||||
|
||||
case_ast_node(dir, AsmDirective, instruction_);
|
||||
String name = dir->name.string;
|
||||
if (name == "byte") {
|
||||
if (dir->operands.count == 0) {
|
||||
error(dir->name, "Expected 1 or more integers for the asm directive #%.*s", LIT(name));
|
||||
break;
|
||||
}
|
||||
array_clear(&operands);
|
||||
for (Ast *expr : dir->operands) {
|
||||
Operand operand = {};
|
||||
check_asm_instruction_operand(asm_ctx, ctx, entity, &operand, expr, /*allow_memory_operands*/true);
|
||||
array_add(&operands, operand);
|
||||
}
|
||||
for (auto const &op : operands) {
|
||||
if (op.mode != Addressing_Constant) {
|
||||
error(op.expr, "Expected an integer for the asm directive #%.*s", LIT(name));
|
||||
continue;
|
||||
}
|
||||
ExactValue ev = exact_value_to_integer(op.value);
|
||||
if (ev.kind != ExactValue_Integer) {
|
||||
error(op.expr, "Expected an integer for the asm directive #%.*s", LIT(name));
|
||||
continue;
|
||||
}
|
||||
i64 i = exact_value_to_i64(ev);
|
||||
if (i < 0 || i > 255) {
|
||||
error(op.expr, "Expected an integer within 0..<256 for the asm directive #%.*s, got %lld", LIT(name), cast(long long)i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
case_end;
|
||||
|
||||
default:
|
||||
error(instruction_, "Unexpected instruction in asm template");
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user