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
62static void asm_unary_opcode(TCCState *s1, int token);62static void asm_unary_opcode(TCCState *s1, int token);
63ST_FUNC void gen_expr32(ExprValue *pe);63ST_FUNC void gen_expr32(ExprValue *pe);
64static void parse_operand(TCCState *s1, Operand *op);64static void parse_operand(TCCState *s1, Operand *op);
65static void parse_operands(TCCState *s1, Operand *ops, int count);
65ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier);66ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier);
66/* C extension */67/* C extension */
67static void asm_emit_ca(int token, uint16_t opcode, const Operand *rd, const Operand *rs2);68static 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
209 }210 }
210}211}
211 212
213static 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
212static void asm_unary_opcode(TCCState *s1, int token)226static void asm_unary_opcode(TCCState *s1, int token)
213{227{
214 uint32_t opcode = (0x1C << 2) | 3 | (2 << 12);228 uint32_t opcode = (0x1C << 2) | 3 | (2 << 12);
215 Operand op;229 Operand op;
216 static const Operand nil = {.type = OP_REG};230 static const Operand nil = {.type = OP_REG};
217 231
218 parse_operand(s1, &op);232 parse_operands(s1, &op, 1);
219 /* Note: Those all map to CSR--so they are pseudo-instructions. */233 /* Note: Those all map to CSR--so they are pseudo-instructions. */
220 opcode |= ENCODE_RD(op.reg);234 opcode |= ENCODE_RD(op.reg);
221 235
@@ -280,12 +294,7 @@ static void asm_emit_u(int token, uint32_t opcode, const Operand* rd, const Oper · 58 unmodified lines
280static void asm_binary_opcode(TCCState* s1, int token)294static void asm_binary_opcode(TCCState* s1, int token)
281{295{
282 Operand ops[2];296 Operand ops[2];
283 parse_operand(s1, &ops[0]);297 parse_operands(s1, &ops[0], 2);
284 if (tok == ',')
285 next();
286 else
287 expect("','");
288 parse_operand(s1, &ops[1]);
289 298
290 switch (token) {299 switch (token) {
291 case TOK_ASM_lui:300 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
499static void asm_ternary_opcode(TCCState *s1, int token)508static void asm_ternary_opcode(TCCState *s1, int token)
500{509{
501 Operand ops[3];510 Operand ops[3];
502 parse_operand(s1, &ops[0]);511 parse_operands(s1, &ops[0], 3);
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]);
513 512
514 switch (token) {513 switch (token) {
515 case TOK_ASM_sll:514 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