History

riscv: Move operand parsing to a separate function

Ekaitz Zarraga committed 2 years ago

Commit 019d10f1 parent 2b0a6631 file · +17 −18Browse files

Unified · Split

riscv64-asm.c+17−18
@@ -62,6 +62,7 @@ static void asm_ternary_opcode(TCCState *s1, int token); · 61 unmodified lines
6262 static void asm_unary_opcode(TCCState *s1, int token);
6363 ST_FUNC void gen_expr32(ExprValue *pe);
6464 static void parse_operand(TCCState *s1, Operand *op);
65+static void parse_operands(TCCState *s1, Operand *ops, int count);
6566 ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier);
6667 /* C extension */
6768 static void asm_emit_ca(int token, uint16_t opcode, const Operand *rd, const Operand *rs2);
@@ -209,13 +210,26 @@ static void parse_operand(TCCState *s1, Operand *op) · 141 unmodified lines
209210 }
210211 }
211212
213+static void parse_operands(TCCState *s1, Operand* ops, int count){
214+ int i;
215+ for (i = 0; i < count; i++) {
216+ if ( i != 0 ) {
217+ if ( tok == ',')
218+ next();
219+ else
220+ expect("','");
221+ }
222+ parse_operand(s1, &ops[i]);
223+ }
224+}
225+
212226 static void asm_unary_opcode(TCCState *s1, int token)
213227 {
214228 uint32_t opcode = (0x1C << 2) | 3 | (2 << 12);
215229 Operand op;
216230 static const Operand nil = {.type = OP_REG};
217231
218− parse_operand(s1, &op);
232+ parse_operands(s1, &op, 1);
219233 /* Note: Those all map to CSR--so they are pseudo-instructions. */
220234 opcode |= ENCODE_RD(op.reg);
221235
@@ -280,12 +294,7 @@ static void asm_emit_u(int token, uint32_t opcode, const Operand* rd, const Oper · 58 unmodified lines
280294 static void asm_binary_opcode(TCCState* s1, int token)
281295 {
282296 Operand ops[2];
283− parse_operand(s1, &ops[0]);
284− if (tok == ',')
285− next();
286− else
287− expect("','");
288− parse_operand(s1, &ops[1]);
297+ parse_operands(s1, &ops[0], 2);
289298
290299 switch (token) {
291300 case TOK_ASM_lui:
@@ -499,17 +508,7 @@ static void asm_emit_j(int token, uint32_t opcode, const Operand* rd, const Oper · 207 unmodified lines
499508 static void asm_ternary_opcode(TCCState *s1, int token)
500509 {
501510 Operand ops[3];
502− parse_operand(s1, &ops[0]);
503− if (tok == ',')
504− next();
505− else
506− expect("','");
507− parse_operand(s1, &ops[1]);
508− if (tok == ',')
509− next();
510− else
511− expect("','");
512− parse_operand(s1, &ops[2]);
511+ parse_operands(s1, &ops[0], 3);
513512
514513 switch (token) {
515514 case TOK_ASM_sll:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t