Skip to content

Commit 02afbfd

Browse files
committed
refactored string output
1 parent a21a1b5 commit 02afbfd

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

backends/asm/outasm.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,16 @@ static int EmitLongPtr(IRList *irl, Operand *op)
999999
static int EmitStringNoTrailingZero(IRList *irl, AST *ast)
10001000
{
10011001
Operand *op;
1002+
int count = 0;
10021003
switch (ast->kind) {
1004+
case AST_EXPRLIST:
1005+
while (ast && ast->kind == AST_EXPRLIST) {
1006+
count += EmitStringNoTrailingZero(irl, ast->left);
1007+
ast = ast->right;
1008+
}
1009+
return count;
1010+
case AST_STRINGPTR:
1011+
return EmitStringNoTrailingZero(irl, ast->left);
10031012
case AST_STRING:
10041013
if (irl) {
10051014
op = NewOperand(IMM_STRING, ast->d.string, 0);
@@ -1012,6 +1021,22 @@ static int EmitStringNoTrailingZero(IRList *irl, AST *ast)
10121021
EmitOp1(irl, OPC_BYTE, op);
10131022
}
10141023
return 1;
1024+
case AST_IDENTIFIER:
1025+
case AST_LOCAL_IDENTIFIER:
1026+
{
1027+
const char *name = GetIdentifierName(ast);
1028+
Symbol *sym = LookupSymbol(name);
1029+
if (!sym) {
1030+
ERROR(ast, "Unknown identifier `%s'", name);
1031+
return 0;
1032+
}
1033+
if (sym->kind == SYM_CONSTANT || sym->kind == SYM_ALIAS) {
1034+
return EmitStringNoTrailingZero(irl, (AST *)sym->v.ptr);
1035+
} else {
1036+
ERROR(ast, "Expected a constant, found `%s'", name);
1037+
return 0;
1038+
}
1039+
}
10151040
default:
10161041
if (IsConstExpr(ast)) {
10171042
if (irl) {
@@ -1028,10 +1053,6 @@ static int EmitStringNoTrailingZero(IRList *irl, AST *ast)
10281053
int EmitString(IRList *irl, AST *ast)
10291054
{
10301055
int count = 0;
1031-
while (ast && ast->kind == AST_EXPRLIST) {
1032-
count += EmitStringNoTrailingZero(irl, ast->left);
1033-
ast = ast->right;
1034-
}
10351056
if (ast) {
10361057
count += EmitStringNoTrailingZero(irl, ast);
10371058
}
@@ -6386,12 +6407,16 @@ CompileConstant(IRList *irl, AST *ast, bool skip_clkfreq, bool skip_clkmode)
63866407
return;
63876408
}
63886409
expr = (AST *)sym->v.ptr;
6410+
if (!expr) return;
63896411
if (skip_clkfreq && !strcasecmp(name, "_clkfreq")) {
63906412
return;
63916413
}
63926414
if (skip_clkmode && !strcasecmp(name, "_clkmode")) {
63936415
return;
63946416
}
6417+
if (expr->kind == AST_STRING) {
6418+
return;
6419+
}
63956420
CompileConstOperand(irl, name, expr);
63966421
}
63976422

0 commit comments

Comments
 (0)