commit 917ffe99af9830110b9e682f3cfe21690f17ea58
parent 5e1335de7713ff27ebff76c80bbff317a3ac306c
Author: Ryan Sepassi <rsepassi@gmail.com>
Date: Mon, 1 Jun 2026 19:16:32 -0700
cg: consume the public CfreeCgAsmDir directly (Track 2, asm-dir slice)
First slice of the op-enum unification (decision #2): delete the internal
AsmDir enum (identical 1:1 to CfreeCgAsmDir) and api_map_asm_dir; AsmConstraint.dir
now carries the public value straight through and the backends switch on
CFREE_CG_ASM_IN/OUT/INOUT. Value-preserving rename; no behavior change.
Diffstat:
7 files changed, 9 insertions(+), 23 deletions(-)
diff --git a/src/arch/aa64/native.c b/src/arch/aa64/native.c
@@ -4330,7 +4330,7 @@ static void aa_direct_asm_block(NativeDirectTarget* d, const char* tmpl,
Reg reg = aa_asm_alloc_reg(d, cls, &used_int, &used_fp);
CfreeCgTypeId type = outs[i].type ? outs[i].type : out_ops[i].type;
aa_asm_bound_reg(&bound_outs[i], type, cls, reg);
- if (outs[i].dir == ASM_INOUT) {
+ if (outs[i].dir == CFREE_CG_ASM_INOUT) {
NativeLoc loc = aa_reg_loc(type, cls, reg);
aa_direct_load_operand_to_reg(d, out_ops[i], loc);
}
diff --git a/src/arch/rv64/native.c b/src/arch/rv64/native.c
@@ -3560,7 +3560,7 @@ static void rv_direct_asm_block(NativeDirectTarget* d, const char* tmpl,
NativeAllocClass cls = rv_asm_constraint_class(d, body);
Reg reg = rv_asm_alloc_reg(d, cls, &used_int, &used_fp);
rv_asm_bound_reg(&bound_outs[i], type, cls, reg);
- if (outs[i].dir == ASM_INOUT)
+ if (outs[i].dir == CFREE_CG_ASM_INOUT)
rv_direct_load_operand_to_reg(d, out_ops[i], rv_reg_loc(type, cls, reg));
} else if (body[0] == 'm') {
Reg reg = rv_asm_alloc_reg(d, NATIVE_REG_INT, &used_int, &used_fp);
diff --git a/src/arch/x64/native.c b/src/arch/x64/native.c
@@ -4073,7 +4073,7 @@ static void x64_direct_asm_block(NativeDirectTarget* d, const char* tmpl,
NativeAllocClass cls = x64_asm_constraint_class(d, body);
Reg reg = x64_asm_alloc_reg(d, cls, &used_int, &used_fp);
x64_asm_bound_reg(&bound_outs[i], type, cls, reg);
- if (outs[i].dir == ASM_INOUT)
+ if (outs[i].dir == CFREE_CG_ASM_INOUT)
x64_direct_load_operand_to_reg(d, out_ops[i], x64_reg_loc(type, cls, reg));
} else if (body[0] == 'm') {
Reg reg = x64_asm_alloc_reg(d, NATIVE_REG_INT, &used_int, &used_fp);
diff --git a/src/cg/asm.c b/src/cg/asm.c
@@ -97,9 +97,9 @@ void cfree_cg_inline_asm(CfreeCg* g, CfreeCgInlineAsm asm_block) {
outs[i].str = api_sym_cstr(g, outputs[i].constraint);
outs[i].name = (Sym)outputs[i].name;
outs[i].type = resolve_type(g->c, outputs[i].type);
- outs[i].dir = (u8)api_map_asm_dir(outputs[i].dir);
+ outs[i].dir = (u8)outputs[i].dir;
if (!outs[i].type) outs[i].type = fallback_ty;
- if (outs[i].dir == ASM_INOUT) {
+ if (outs[i].dir == CFREE_CG_ASM_INOUT) {
if (i >= 10) {
compiler_panic(g->c, g->cur_loc,
"CfreeCg: asm inout output index exceeds matching "
@@ -130,15 +130,15 @@ void cfree_cg_inline_asm(CfreeCg* g, CfreeCgInlineAsm asm_block) {
ins[i].str = api_sym_cstr(g, inputs[i].constraint);
ins[i].name = (Sym)inputs[i].name;
ins[i].type = resolve_type(g->c, inputs[i].type);
- ins[i].dir = (u8)api_map_asm_dir(inputs[i].dir);
+ ins[i].dir = (u8)inputs[i].dir;
if (!ins[i].type) ins[i].type = fallback_ty;
}
inout_index = ninputs;
for (u32 i = 0; i < noutputs; ++i) {
- if (outs[i].dir != ASM_INOUT) continue;
+ if (outs[i].dir != CFREE_CG_ASM_INOUT) continue;
ins[inout_index].str = match_strs[i];
ins[inout_index].type = outs[i].type ? outs[i].type : fallback_ty;
- ins[inout_index].dir = ASM_IN;
+ ins[inout_index].dir = CFREE_CG_ASM_IN;
inout_index++;
}
for (u32 i = 0; i < total_inputs; ++i) {
diff --git a/src/cg/cgtarget.h b/src/cg/cgtarget.h
@@ -360,8 +360,6 @@ typedef struct CGScopeDesc {
CfreeCgTypeId result_type; /* reserved for structured expression results */
} CGScopeDesc;
-typedef enum AsmDir { ASM_IN, ASM_OUT, ASM_INOUT } AsmDir;
-
typedef struct AsmConstraint {
const char* str; /* GCC-style: "r", "=&r", "+m", "i", "0" ... */
Sym name; /* GCC `[name]` symbolic operand; 0 if absent */
@@ -369,7 +367,7 @@ typedef struct AsmConstraint {
input rvalue). Drives type width for the binder.
NULL only for hand-built test constraints (binder
falls back to a 64-bit int default). */
- u8 dir; /* AsmDir */
+ u8 dir; /* CfreeCgAsmDir */
u8 pad[3];
} AsmConstraint;
diff --git a/src/cg/internal.h b/src/cg/internal.h
@@ -430,7 +430,6 @@ CmpOp api_map_fp_cmp(CfreeCgFpCmpOp op);
CmpOp api_invert_cmp(CmpOp op);
AtomicOp api_map_atomic_op(CfreeCgAtomicOp op);
MemOrder api_map_mem_order(CfreeCgMemOrder order);
-AsmDir api_map_asm_dir(uint8_t dir);
u32 api_int_like_width(Compiler* c, CfreeCgTypeId id);
int api_type_is_bool(Compiler* c, CfreeCgTypeId id);
u64 api_width_mask(u32 width);
diff --git a/src/cg/value.c b/src/cg/value.c
@@ -739,17 +739,6 @@ MemOrder api_map_mem_order(CfreeCgMemOrder order) {
return MO_RELAXED;
}
-AsmDir api_map_asm_dir(uint8_t dir) {
- switch ((CfreeCgAsmDir)dir) {
- case CFREE_CG_ASM_IN:
- return ASM_IN;
- case CFREE_CG_ASM_OUT:
- return ASM_OUT;
- case CFREE_CG_ASM_INOUT:
- return ASM_INOUT;
- }
- return ASM_IN;
-}
/* ---- immediate integer folding ---- */