Add asm directive #align N

This commit is contained in:
gingerBill
2026-08-17 13:32:28 +01:00
parent 55377f71ef
commit bd95d2ae66
2 changed files with 40 additions and 0 deletions

View File

@@ -1515,7 +1515,38 @@ gb_internal void check_asm_template(AsmCtx *asm_ctx, CheckerContext *ctx, Entity
continue;
}
}
} else if (name == "align") {
if (dir->operands.count != 1) {
error(dir->name, "Expected 1 integer 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 a power-of-two 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 a power-of-two integer for the asm directive #%.*s", LIT(name));
continue;
}
i64 i = exact_value_to_i64(ev);
if (i < 0 || !is_power_of_two(i)) {
error(op.expr, "Expected a power-of-two integer for the asm directive #%.*s, got %lld", LIT(name), cast(long long)i);
continue;
}
}
} else {
error(dir->name, "Unknown asm directive: #%.*s", LIT(name));
}
case_end;
default: