Skip to content

Commit 4653ac9

Browse files
committed
Add implementation for ubin in printf debug
1 parent 5b03c11 commit 4653ac9

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

frontends/basic/basiclang.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,22 @@ addPrintHex(AST *seq, AST *handle, AST *func, AST *expr, AST *fmtAst)
128128
return ast;
129129
}
130130

131+
// create a hex print integer call
132+
static AST *
133+
addPrintBinary(AST *seq, AST *handle, AST *func, AST *expr, AST *fmtAst)
134+
{
135+
AST *ast;
136+
AST *params;
137+
138+
params = NewAST(AST_EXPRLIST, handle,
139+
NewAST(AST_EXPRLIST, expr,
140+
NewAST(AST_EXPRLIST, fmtAst,
141+
NewAST(AST_EXPRLIST, AstInteger(2), NULL))));
142+
ast = NewAST(AST_FUNCCALL, func, params);
143+
ast = addToPrintSeq(seq, ast);
144+
return ast;
145+
}
146+
131147
// create a decimal print integer call
132148
static AST *
133149
addPrintDec(AST *seq, AST *handle, AST *func, AST *expr, AST *fmtAst)
@@ -518,6 +534,13 @@ genPrintf(AST *ast)
518534
seq = addPrintHex(seq, Handle, basic_print_unsigned, thisarg, AstInteger(fmt));
519535
}
520536
break;
537+
case 'b':
538+
if (longflag > 1) {
539+
seq = addPrintBinary(seq, Handle, basic_print_longunsigned, thisarg, AstInteger(fmt));
540+
} else {
541+
seq = addPrintBinary(seq, Handle, basic_print_unsigned, thisarg, AstInteger(fmt));
542+
}
543+
break;
521544
case 's':
522545
seq = addPrintCall(seq, Handle, basic_print_string, thisarg, AstInteger(fmt));
523546
break;

frontends/printdebug.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ static struct s_dbgfmt {
3232
{ "uhex_byte", "$%02x", 8 },
3333
{ "uhex_word", "$%04x", 16 },
3434
{ "uhex_long", "$%08x", 0 },
35+
{ "ubin", "%%%b", 0 },
36+
{ "ubin_byte", "%%%08b", 8 },
37+
{ "ubin_word", "%%%016b", 16 },
38+
{ "ubin_long", "%%%032b", 0 },
3539
{ "dly", "%.0s", DBG_BITS_DELAY },
3640
{ 0, 0, 0 }
3741
};

0 commit comments

Comments
 (0)