Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Noam Preil committed Jul 1, 2020
1 parent c72726f commit 7460231
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 166 deletions.
30 changes: 15 additions & 15 deletions assembler/assembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ void transform_relative_labels(tokenized_expression_t *expression, int last_rela
free(token->symbol);
token->symbol = malloc(size);
if (snprintf(token->symbol, size, fmtstring, relative_label) != size - 1) {
scas_log(L_ERROR, "UNREACHABLE");
exit(1);
scas_log(L_ERROR, "UNREACHABLE");
exit(1);
}

scas_log(L_DEBUG, "Transformed relative label with offset %d to %s, %d - %d", offset, token->symbol, i, j);
Expand Down Expand Up @@ -245,8 +245,8 @@ int try_expand_macro(struct assembler_state *state, char **line) {
for (k = 0; k < macro->parameters->length; ++k) {
char *p = macro->parameters->items[k];
if (!strcmp(p, "")) {
scas_log(L_ERROR, "Attempt to insert '%s' where no parameter is expected...", (char*)userparams->items[k]);
break;
scas_log(L_ERROR, "Attempt to insert '%s' where no parameter is expected...", (char*)userparams->items[k]);
break;
}
scas_log(L_DEBUG, "Replacing '%s' with '%s' for line '%s'",
p, (char *)userparams->items[k], (char *)newlines->items[j]);
Expand Down Expand Up @@ -453,7 +453,7 @@ int try_match_instruction(struct assembler_state *state, char **_line) {
late_imm->expression = expression;
list_add(state->current_area->late_immediates, late_imm);
} else {
free_expression(expression);
free_expression(expression);
if (imm->type == IMM_TYPE_RELATIVE) {
result = result - ((state->PC + scas_runtime.options.origin)
+ (match->instruction->width / 8));
Expand Down Expand Up @@ -619,8 +619,8 @@ object_t *assemble(FILE *file, const char *file_name, assembler_settings_t *sett
source_map_entry_t *entry = map->entries->items[map->entries->length - 1];
entry->length = state.PC - entry->address;
if (entry->length == 0) {
free(entry->source_code);
free(entry);
free(entry->source_code);
free(entry);
list_del(map->entries, map->entries->length - 1);
}
}
Expand Down Expand Up @@ -694,17 +694,17 @@ object_t *assemble(FILE *file, const char *file_name, assembler_settings_t *sett
stack_free(state.line_number_stack);
list_free(state.extra_lines);
for (int i = 0; i < state.macros->length; i += 1) {
macro_t *macro = state.macros->items[i];
list_free(macro->parameters);
free_flat_list(macro->macro_lines);
free(macro->name);
free(macro);
macro_t *macro = state.macros->items[i];
list_free(macro->parameters);
free_flat_list(macro->macro_lines);
free(macro->name);
free(macro);
}
list_free(state.macros);
for (int i = 0; i < state.equates->length; i += 1) {
symbol_t *sym = (symbol_t*)state.equates->items[i];
free(sym->name);
free(sym);
symbol_t *sym = (symbol_t*)state.equates->items[i];
free(sym->name);
free(sym);
}
list_free(state.equates);
stack_free(state.source_map_stack);
Expand Down
12 changes: 6 additions & 6 deletions assembler/directives.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ int handle_db(struct assembler_state *state, char **argv, int argc) {
append_to_area(state->current_area, state->instruction_buffer, 1);
++state->PC;
if (!keep) {
free_expression(expression);
free_expression(expression);
}
}
}
Expand Down Expand Up @@ -560,7 +560,7 @@ int handle_dw(struct assembler_state *state, char **argv, int argc) {
}
}
if (!keep) {
free_expression(expression);
free_expression(expression);
}
append_to_area(state->current_area, state->instruction_buffer, 2);
state->PC += 2;
Expand Down Expand Up @@ -1146,7 +1146,7 @@ int handle_macro(struct assembler_state *state, char **argv, int argc) {
return 1;
}
char *location = strchr(argv[0], '(');

if (location == argv[0]) {
ERROR(ERROR_INVALID_DIRECTIVE, state->column, "macro without a name");
return 1;
Expand Down Expand Up @@ -1179,8 +1179,8 @@ int handle_macro(struct assembler_state *state, char **argv, int argc) {
// TODO: Free everything
}
else if (end == location && *end == ')') {
// No parameters
break;
// No parameters
break;
}
char *parameter = malloc(end - location + 1);
strncpy(parameter, location, end - location);
Expand Down Expand Up @@ -1478,7 +1478,7 @@ int try_handle_directive(struct assembler_state *state, char **line) {
int ret = d->function(state, argv, argc);
deindent_log();
for (int i = 0; i < argc; i += 1) {
free(argv[i]);
free(argv[i]);
}
free(argv);
return ret;
Expand Down
16 changes: 8 additions & 8 deletions common/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,14 @@ enum {
};

void free_expression(tokenized_expression_t *expression) {
for (int i = 0; i < expression->tokens->length; i += 1) {
free_expression_token((expression_token_t*)expression->tokens->items[i]);
}
list_free(expression->tokens);
if (expression->symbols) {
free_flat_list(expression->symbols);
}
free(expression);
for (int i = 0; i < expression->tokens->length; i += 1) {
free_expression_token((expression_token_t*)expression->tokens->items[i]);
}
list_free(expression->tokens);
if (expression->symbols) {
free_flat_list(expression->symbols);
}
free(expression);
}

// Based on shunting-yard
Expand Down
22 changes: 11 additions & 11 deletions common/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void remove_unused_functions(object_t *object) {
area_t *area = object->areas->items[i];
metadata_t *meta = get_area_metadata(area, "scas.functions");
if (meta) {
list_t *decoded = decode_function_metadata(area, meta->value);
list_t *decoded = decode_function_metadata(area, meta->value);
list_cat(functions, decoded);
list_free(decoded);
}
Expand All @@ -115,11 +115,11 @@ void remove_unused_functions(object_t *object) {
symbol_t *end = get_symbol_by_name(meta->area, meta->end_symbol);
if (!start || !end) {
scas_log(L_ERROR, "Warning: function %s has unknown start and end symbols", meta->name);
function_metadata_t *func = functions->items[i];
free(func->name);
free(func->start_symbol);
free(func->end_symbol);
free(func);
function_metadata_t *func = functions->items[i];
free(func->name);
free(func->start_symbol);
free(func->end_symbol);
free(func);
list_del(functions, i);
--i;
} else {
Expand Down Expand Up @@ -198,11 +198,11 @@ void remove_unused_functions(object_t *object) {
}
}
for (int i = 0; i < functions->length; i++) {
function_metadata_t *func = functions->items[i];
free(func->name);
free(func->start_symbol);
free(func->end_symbol);
free(func);
function_metadata_t *func = functions->items[i];
free(func->name);
free(func->start_symbol);
free(func->end_symbol);
free(func);
}
list_free(functions);
}
Expand Down
2 changes: 1 addition & 1 deletion common/match.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ char *get_operand_string(instruction_t *inst, int *i, const char *code, int j) {
}
}
if (delimiter == '\0') {
return strdup(code + j);
return strdup(code + j);
}
const char *significant_delimiters = "%@&^";
if (strchr(significant_delimiters, delimiter)) {
Expand Down
18 changes: 9 additions & 9 deletions common/objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ void set_area_metadata(area_t *area, const char *key, char *value, uint64_t valu
for (int i = 0; i < area->metadata->length; ++i) {
metadata_t *meta = area->metadata->items[i];
if (strcmp(meta->key, key) == 0) {
free(meta->key);
if (meta->value != value) {
free(meta->value);
}
else {
dupe = false;
}
free(meta);
free(meta->key);
if (meta->value != value) {
free(meta->value);
}
else {
dupe = false;
}
free(meta);
list_del(area->metadata, i);
break;
}
Expand All @@ -137,7 +137,7 @@ void set_area_metadata(area_t *area, const char *key, char *value, uint64_t valu
newmeta->value = strdup(value);
}
else {
newmeta->value = value;
newmeta->value = value;
}
scas_log(L_DEBUG, "Set area metadata '%s' to new value with length %d", newmeta->key, newmeta->value_length);
list_add(area->metadata, newmeta);
Expand Down
10 changes: 5 additions & 5 deletions linker/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ bool merge_areas(object_t *merged, object_t *source) {
uint64_t len;
char *merged_metadata = encode_function_metadata(merged, &len);
for (int i = 0; i < merged->length; i++) {
function_metadata_t *func = merged->items[i];
free(func->name);
free(func->start_symbol);
free(func->end_symbol);
function_metadata_t *func = merged->items[i];
free(func->name);
free(func->start_symbol);
free(func->end_symbol);
}
free_flat_list(merged);
free_flat_list(merged);
set_area_metadata(merged_area, "scas.functions", merged_metadata, len);
free(merged_metadata);
}
Expand Down
12 changes: 6 additions & 6 deletions scas/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ int main(int argc, char **argv) {
validate_scas_runtime();
instruction_set_t *instruction_set = find_inst();
if (instruction_set == NULL) {
fprintf(stderr, "Failed to load instruction set definition, unable to continue!\n");
return 1;
fprintf(stderr, "Failed to load instruction set definition, unable to continue!\n");
return 1;
}
scas_log(L_INFO, "Loaded instruction set: %s", instruction_set->arch);
list_t *include_path = split_include_path();
Expand Down Expand Up @@ -312,8 +312,8 @@ int main(int argc, char **argv) {
else {
scas_log(L_ERROR, "Failed to merge");
if (out != stdout) {
remove(scas_runtime.output_file);
}
remove(scas_runtime.output_file);
}
}
fclose(out);
}
Expand All @@ -337,7 +337,7 @@ int main(int argc, char **argv) {
fprintf(stderr, "\n");
}
if (error->line) {
free (error->line);
free (error->line);
}
free(error->file_name);
free(error->message);
Expand Down Expand Up @@ -368,7 +368,7 @@ int main(int argc, char **argv) {
list_free(scas_runtime.input_files);
free_flat_list(include_path);
for (int i = 0; i < objects->length; i += 1) {
object_free((object_t*)objects->items[i]);
object_free((object_t*)objects->items[i]);
}
list_free(objects);
list_free(errors);
Expand Down
Loading

0 comments on commit 7460231

Please sign in to comment.