summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2023-04-12 21:42:07 +0300
committerSebastian Dröge <sebastian@centricular.com>2023-04-12 21:42:07 +0300
commit6819f1b8397548c78c06be2be960369bdc2c0606 (patch)
treec9b9ae7abf74e56a025730d390e8965b721241ce
parentb1d2bec7ccb21dca6cb13954da39c42b060dfb61 (diff)
downloadorc-6819f1b8397548c78c06be2be960369bdc2c0606.tar.gz
Simplify opcode handling by adding an early return
Part-of: <https://gitlab.freedesktop.org/gstreamer/orc/-/merge_requests/30>
-rw-r--r--orc/orcparse.c75
1 files changed, 39 insertions, 36 deletions
diff --git a/orc/orcparse.c b/orc/orcparse.c
index fa471bc..455ccc9 100644
--- a/orc/orcparse.c
+++ b/orc/orcparse.c
@@ -778,6 +778,9 @@ orc_parse_handle_opcode (OrcParser *parser, const OrcLine *line)
unsigned int flags = 0;
int offset = 0;
int error = 0;
+ int n_args;
+ int i, j;
+ const char *args[6] = { NULL };
if (strcmp (line->tokens[0], "x4") == 0) {
flags |= ORC_INSTRUCTION_FLAG_X4;
@@ -789,49 +792,49 @@ orc_parse_handle_opcode (OrcParser *parser, const OrcLine *line)
o = orc_parse_find_opcode (parser, line->tokens[offset]);
- if (o) {
- int n_args = opcode_n_args (o);
- int i, j;
- const char *args[6] = { NULL };
-
- if (line->n_tokens != 1 + offset + n_args) {
- orc_parse_add_error (parser, "too %s arguments for %s (expected %d)",
- (line->n_tokens < 1+offset+n_args) ? "few" : "many",
- line->tokens[offset], n_args);
- }
-
- for(i=offset+1,j=0;i<line->n_tokens;i++,j++){
- char *end;
- double unused ORC_GNUC_UNUSED;
+ if (!o) {
+ orc_parse_add_error (parser, "unknown opcode: %s", line->tokens[offset]);
+ return 0;
+ }
- args[j] = line->tokens[i];
+ n_args = opcode_n_args (o);
- unused = strtod (line->tokens[i], &end);
- if (end != line->tokens[i]) {
- char varname[80];
- int id;
+ if (line->n_tokens != 1 + offset + n_args) {
+ orc_parse_add_error (parser, "too %s arguments for %s (expected %d)",
+ (line->n_tokens < 1+offset+n_args) ? "few" : "many",
+ line->tokens[offset], n_args);
+ }
- /* make a unique name based on value and size */
- snprintf (varname, sizeof (varname), "_%d.%s", opcode_arg_size(o, j), line->tokens[i]);
- id = orc_program_add_constant_str (parser->program, opcode_arg_size(o, j),
- line->tokens[i], varname);
- /* it's possible we reused an existing variable, get its name so
- * that we can refer to it in the opcode */
- args[j] = parser->program->vars[id].name;
- }
+ for(i=offset+1,j=0;i<line->n_tokens;i++,j++){
+ char *end;
+ double unused ORC_GNUC_UNUSED;
+
+ args[j] = line->tokens[i];
+
+ unused = strtod (line->tokens[i], &end);
+ if (end != line->tokens[i]) {
+ char varname[80];
+ int id;
+
+ /* make a unique name based on value and size */
+ snprintf (varname, sizeof (varname), "_%d.%s", opcode_arg_size(o, j), line->tokens[i]);
+ id = orc_program_add_constant_str (parser->program, opcode_arg_size(o, j),
+ line->tokens[i], varname);
+ /* it's possible we reused an existing variable, get its name so
+ * that we can refer to it in the opcode */
+ args[j] = parser->program->vars[id].name;
}
+ }
- error = orc_program_append_str_n (parser->program, line->tokens[offset], flags,
- n_args, args);
+ error = orc_program_append_str_n (parser->program, line->tokens[offset], flags,
+ n_args, args);
- if (error > 0) {
- orc_parse_add_error (parser, "bad operand \"%s\" in position %d",
- line->tokens[offset + error], error);
- }
- return 1;
+ if (error > 0) {
+ orc_parse_add_error (parser, "bad operand \"%s\" in position %d",
+ line->tokens[offset + error], error);
}
- orc_parse_add_error (parser, "unknown opcode: %s", line->tokens[offset]);
- return 0;
+
+ return 1;
}
static void