From bc0efebb3e6988de1657da4e3254b21b68819354 Mon Sep 17 00:00:00 2001 From: marcobaye Date: Wed, 6 May 2020 11:40:06 +0000 Subject: [PATCH] cleanup git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@138 4df02467-bbd4-4a76-a152-e7ce94205b78 --- src/cpu.c | 4 ++-- src/cpu.h | 6 +++--- src/input.c | 8 ++++---- src/input.h | 6 +++--- src/mnemo.c | 18 +++++++++--------- src/mnemo.h | 23 +++++++++++++---------- src/output.h | 4 ++-- src/pseudoopcodes.c | 19 ++++++++++--------- src/symbol.c | 12 ++++++------ src/symbol.h | 4 ++-- src/tree.c | 6 +++--- src/tree.h | 5 +++-- 12 files changed, 60 insertions(+), 55 deletions(-) diff --git a/src/cpu.c b/src/cpu.c index 41afad5..74a1385 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -1,5 +1,5 @@ // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code. -// Copyright (C) 1998-2016 Marco Baye +// Copyright (C) 1998-2020 Marco Baye // Have a look at "acme.c" for further info // // CPU type stuff @@ -102,7 +102,7 @@ const struct cpu_type *cputype_find(void) // if cpu type and value don't match, complain instead. // FIXME - error message might be confusing if it is thrown not because of // initial change, but because of reverting back to old cpu type after "{}" block! -void vcpu_check_and_set_reg_length(int *var, int make_long) +void vcpu_check_and_set_reg_length(boolean *var, boolean make_long) { if (((CPU_state.type->flags & CPUFLAG_SUPPORTSLONGREGS) == 0) && make_long) Throw_error("Chosen CPU does not support long registers."); diff --git a/src/cpu.h b/src/cpu.h index cbfce00..cb4b28d 100644 --- a/src/cpu.h +++ b/src/cpu.h @@ -1,5 +1,5 @@ // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code. -// Copyright (C) 1998-2016 Marco Baye +// Copyright (C) 1998-2020 Marco Baye // Have a look at "acme.c" for further info // // CPU type stuff @@ -14,7 +14,7 @@ struct cpu_type { // This function is not allowed to change GlobalDynaBuf // because that's where the mnemonic is stored! - int (*keyword_is_mnemonic)(int); + boolean (*keyword_is_mnemonic)(int); int flags; // see below for bit meanings char default_align_value; }; @@ -27,7 +27,7 @@ struct cpu_type { // if cpu type and value match, set register length variable to value. // if cpu type and value don't match, complain instead. -extern void vcpu_check_and_set_reg_length(int *var, int make_long); +extern void vcpu_check_and_set_reg_length(boolean *var, boolean make_long); // set default value for pass extern void cputype_passinit(const struct cpu_type *cpu_type); // lookup cpu type held in DynaBuf and return its struct pointer (or NULL on failure) diff --git a/src/input.c b/src/input.c index 9959cc0..cbfb09f 100644 --- a/src/input.c +++ b/src/input.c @@ -490,7 +490,7 @@ int Input_read_and_lower_keyword(void) // Returns whether error occurred (TRUE on error). Filename in GlobalDynaBuf. // Errors are handled and reported, but caller should call // Input_skip_remainder() then. -int Input_read_filename(int allow_library, int *uses_lib) +int Input_read_filename(boolean allow_library, boolean *uses_lib) { char *lib_prefix, end_quote; @@ -500,9 +500,9 @@ int Input_read_filename(int allow_library, int *uses_lib) // check for library access if (GotByte == '<') { if (uses_lib) - *uses_lib = 1; + *uses_lib = TRUE; // if library access forbidden, complain - if (allow_library == FALSE) { + if (!allow_library) { Throw_error("Writing to library not supported."); return TRUE; } @@ -521,7 +521,7 @@ int Input_read_filename(int allow_library, int *uses_lib) end_quote = '>'; } else { if (uses_lib) - *uses_lib = 0; + *uses_lib = FALSE; if (GotByte == '"') { end_quote = '"'; } else { diff --git a/src/input.h b/src/input.h index dd7b4a4..69bb690 100644 --- a/src/input.h +++ b/src/input.h @@ -27,8 +27,8 @@ enum inputstate { }; struct input { const char *original_filename; // during RAM reads, too - int line_number, // in file (on RAM reads, too) - source_is_ram; // TRUE if RAM, FALSE if file + int line_number; // in file (on RAM reads, too) + boolean source_is_ram; // TRUE if RAM, FALSE if file (TODO - change to enum) enum inputstate state; // state of input union { FILE *fd; // file descriptor @@ -108,7 +108,7 @@ extern int Input_read_and_lower_keyword(void); // Returns whether error occurred (TRUE on error). Filename in GlobalDynaBuf. // Errors are handled and reported, but caller should call // Input_skip_remainder() then. -extern int Input_read_filename(int library_allowed, int *uses_lib); +extern int Input_read_filename(boolean library_allowed, boolean *uses_lib); // Try to read a comma, skipping spaces before and after. Return TRUE if comma // found, otherwise FALSE. extern int Input_accept_comma(void); diff --git a/src/mnemo.c b/src/mnemo.c index 464d017..2ec550c 100644 --- a/src/mnemo.c +++ b/src/mnemo.c @@ -1074,7 +1074,7 @@ static int check_mnemo_tree(struct ronode *tree, struct dynabuf *dyna_buf) } // check whether mnemonic in GlobalDynaBuf is supported by 6502 cpu. -int keyword_is_6502_mnemo(int length) +boolean keyword_is_6502_mnemo(int length) { if (length != 3) return FALSE; @@ -1085,7 +1085,7 @@ int keyword_is_6502_mnemo(int length) } // check whether mnemonic in GlobalDynaBuf is supported by 6510 cpu. -int keyword_is_6510_mnemo(int length) +boolean keyword_is_6510_mnemo(int length) { if (length != 3) return FALSE; @@ -1105,7 +1105,7 @@ int keyword_is_6510_mnemo(int length) } // check whether mnemonic in GlobalDynaBuf is supported by C64DTV2 cpu. -int keyword_is_c64dtv2_mnemo(int length) +boolean keyword_is_c64dtv2_mnemo(int length) { if (length != 3) return FALSE; @@ -1125,7 +1125,7 @@ int keyword_is_c64dtv2_mnemo(int length) } // check whether mnemonic in GlobalDynaBuf is supported by 65c02 cpu. -int keyword_is_65c02_mnemo(int length) +boolean keyword_is_65c02_mnemo(int length) { if (length != 3) return FALSE; @@ -1141,7 +1141,7 @@ int keyword_is_65c02_mnemo(int length) } // check whether mnemonic in GlobalDynaBuf is supported by Rockwell 65c02 cpu. -int keyword_is_r65c02_mnemo(int length) +boolean keyword_is_r65c02_mnemo(int length) { if ((length != 3) && (length != 4)) return FALSE; @@ -1161,7 +1161,7 @@ int keyword_is_r65c02_mnemo(int length) } // check whether mnemonic in GlobalDynaBuf is supported by WDC w65c02 cpu. -int keyword_is_w65c02_mnemo(int length) +boolean keyword_is_w65c02_mnemo(int length) { if ((length != 3) && (length != 4)) return FALSE; @@ -1185,7 +1185,7 @@ int keyword_is_w65c02_mnemo(int length) } // check whether mnemonic in GlobalDynaBuf is supported by CSG 65CE02 cpu. -int keyword_is_65ce02_mnemo(int length) +boolean keyword_is_65ce02_mnemo(int length) { if ((length != 3) && (length != 4)) return FALSE; @@ -1213,7 +1213,7 @@ int keyword_is_65ce02_mnemo(int length) } // check whether mnemonic in GlobalDynaBuf is supported by CSG 4502 cpu. -int keyword_is_4502_mnemo(int length) +boolean keyword_is_4502_mnemo(int length) { if ((length != 3) && (length != 4)) return FALSE; @@ -1241,7 +1241,7 @@ int keyword_is_4502_mnemo(int length) } // check whether mnemonic in GlobalDynaBuf is supported by 65816 cpu. -int keyword_is_65816_mnemo(int length) +boolean keyword_is_65816_mnemo(int length) { if (length != 3) return FALSE; diff --git a/src/mnemo.h b/src/mnemo.h index 5abb7b1..cf68007 100644 --- a/src/mnemo.h +++ b/src/mnemo.h @@ -1,5 +1,5 @@ // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code. -// Copyright (C) 1998-2016 Marco Baye +// Copyright (C) 1998-2020 Marco Baye // Have a look at "acme.c" for further info // // mnemonic definitions @@ -7,26 +7,29 @@ #define mnemo_H +#include "config.h" + + // create dynamic buffer, build keyword trees extern void Mnemo_init(void); // check whether mnemonic in GlobalDynaBuf is supported by 6502 cpu. -extern int keyword_is_6502_mnemo(int length); +extern boolean keyword_is_6502_mnemo(int length); // check whether mnemonic in GlobalDynaBuf is supported by 6510 cpu. -extern int keyword_is_6510_mnemo(int length); +extern boolean keyword_is_6510_mnemo(int length); // check whether mnemonic in GlobalDynaBuf is supported by C64DTV2 cpu. -extern int keyword_is_c64dtv2_mnemo(int length); +extern boolean keyword_is_c64dtv2_mnemo(int length); // check whether mnemonic in GlobalDynaBuf is supported by 65c02 cpu. -extern int keyword_is_65c02_mnemo(int length); +extern boolean keyword_is_65c02_mnemo(int length); // check whether mnemonic in GlobalDynaBuf is supported by Rockwell 65c02 cpu. -extern int keyword_is_r65c02_mnemo(int length); +extern boolean keyword_is_r65c02_mnemo(int length); // check whether mnemonic in GlobalDynaBuf is supported by WDC 65c02 cpu. -extern int keyword_is_w65c02_mnemo(int length); +extern boolean keyword_is_w65c02_mnemo(int length); // check whether mnemonic in GlobalDynaBuf is supported by 65816 cpu. -extern int keyword_is_65816_mnemo(int length); +extern boolean keyword_is_65816_mnemo(int length); // check whether mnemonic in GlobalDynaBuf is supported by CSG 65ce02 cpu. -extern int keyword_is_65ce02_mnemo(int length); +extern boolean keyword_is_65ce02_mnemo(int length); // check whether mnemonic in GlobalDynaBuf is supported by CSG 4502 cpu. -extern int keyword_is_4502_mnemo(int length); +extern boolean keyword_is_4502_mnemo(int length); #endif diff --git a/src/output.h b/src/output.h index 2f46d7d..cbdc11d 100644 --- a/src/output.h +++ b/src/output.h @@ -24,8 +24,8 @@ struct vcpu { const struct cpu_type *type; // current CPU type (default 6502) (FIXME - move out of struct again?) struct number pc; // current program counter (pseudo value) int add_to_pc; // add to PC after statement - int a_is_long; - int xy_are_long; + boolean a_is_long; + boolean xy_are_long; }; diff --git a/src/pseudoopcodes.c b/src/pseudoopcodes.c index bf3346d..00fe88a 100644 --- a/src/pseudoopcodes.c +++ b/src/pseudoopcodes.c @@ -36,6 +36,7 @@ static const char s_08[] = "08"; #define s_8 (s_08 + 1) // Yes, I know I'm sick #define s_sl (s_asl + 1) // Yes, I know I'm sick #define s_rl (s_brl + 1) // Yes, I know I'm sick +static const char exception_unknown_pseudo_opcode[] = "Unknown pseudo opcode."; // variables @@ -335,7 +336,7 @@ static enum eos predefined_encoding(void) // set current encoding ("!convtab" pseudo opcode) static enum eos po_convtab(void) { - int uses_lib; + boolean uses_lib; FILE *stream; if ((GotByte == '<') || (GotByte == '"')) { @@ -416,7 +417,7 @@ static enum eos po_scrxor(void) // FIXME - split this into "parser" and "worker" fn and move worker fn somewhere else. static enum eos po_binary(void) { - int uses_lib; + boolean uses_lib; FILE *stream; int byte; intval_t size = -1, // means "not given" => "until EOF" @@ -501,7 +502,7 @@ static enum eos po_skip(void) // now GotByte = illegal char ALU_defined_int(&amount); // FIXME - forbid addresses! if (amount.val.intval < 0) - Throw_serious_error(exception_negative_size); + Throw_serious_error(exception_negative_size); // TODO - allow this? else output_skip(amount.val.intval); return ENSURE_EOS; @@ -602,7 +603,7 @@ static enum eos po_cpu(void) // set register length, block-wise if needed. -static enum eos set_register_length(int *var, int make_long) +static enum eos set_register_length(boolean *var, boolean make_long) { int old_size = *var; @@ -771,7 +772,7 @@ static enum eos obsolete_po_subzone(void) // include source file ("!source" or "!src"). has to be re-entrant. static enum eos po_source(void) // now GotByte = illegal char { - int uses_lib; + boolean uses_lib; FILE *stream; char local_gotbyte; struct input new_input, @@ -825,7 +826,7 @@ static enum eos po_if(void) // now GotByte = illegal char // conditional assembly ("!ifdef" and "!ifndef"). has to be re-entrant. -static enum eos ifdef_ifndef(int is_ifndef) // now GotByte = illegal char +static enum eos ifdef_ifndef(boolean invert) // now GotByte = illegal char { struct rwnode *node; struct symbol *symbol; @@ -846,7 +847,7 @@ static enum eos ifdef_ifndef(int is_ifndef) // now GotByte = illegal char } SKIPSPACE(); // if "ifndef", invert condition - if (is_ifndef) + if (invert) defined = !defined; if (GotByte != CHAR_SOB) return defined ? PARSE_REMAINDER : SKIP_REMAINDER; @@ -969,7 +970,7 @@ static enum eos po_while(void) // now GotByte = illegal char struct do_while loop; if (!config.test_new_features) { - Throw_error("Unknown pseudo opcode."); + Throw_error(exception_unknown_pseudo_opcode); return SKIP_REMAINDER; } // read condition to buffer @@ -1223,7 +1224,7 @@ void pseudoopcode_parse(void) // now GotByte = "!" // call function then = fn(); } else { - Throw_error("Unknown pseudo opcode."); + Throw_error(exception_unknown_pseudo_opcode); } } if (then == SKIP_REMAINDER) diff --git a/src/symbol.c b/src/symbol.c index 98a7689..591ea95 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -104,8 +104,8 @@ struct symbol *symbol_find(scope_t scope, int flags) { struct rwnode *node; struct symbol *symbol; - int node_created, - force_bits = flags & NUMBER_FORCEBITS; + boolean node_created; + int force_bits = flags & NUMBER_FORCEBITS; node_created = Tree_hard_scan(&node, symbols_forest, scope, TRUE); // if node has just been created, create symbol as well @@ -127,7 +127,7 @@ struct symbol *symbol_find(scope_t scope, int flags) symbol = node->body; } // make sure the force bits don't clash - if ((node_created == FALSE) && force_bits) + if ((!node_created) && force_bits) if ((symbol->result.flags & NUMBER_FORCEBITS) != force_bits) Throw_error("Too late for postfix."); return symbol; @@ -136,12 +136,12 @@ struct symbol *symbol_find(scope_t scope, int flags) // assign value to symbol. the function acts upon the symbol's flag bits and // produces an error if needed. -void symbol_set_value(struct symbol *symbol, struct number *new_value, int change_allowed) +void symbol_set_value(struct symbol *symbol, struct number *new_value, boolean change_allowed) { int oldflags = symbol->result.flags; // value stuff - if ((oldflags & NUMBER_IS_DEFINED) && (change_allowed == FALSE)) { + if ((oldflags & NUMBER_IS_DEFINED) && !change_allowed) { // symbol is already defined, so compare new and old values // if different type OR same type but different value, complain if (((oldflags ^ new_value->flags) & NUMBER_IS_FLOAT) @@ -169,7 +169,7 @@ void symbol_set_value(struct symbol *symbol, struct number *new_value, int chang // parse label definition (can be either global or local). // name must be held in GlobalDynaBuf. -void symbol_set_label(scope_t scope, int stat_flags, int force_bit, int change_allowed) +void symbol_set_label(scope_t scope, int stat_flags, int force_bit, boolean change_allowed) { struct number pc, result; diff --git a/src/symbol.h b/src/symbol.h index 2249d9c..694d12c 100644 --- a/src/symbol.h +++ b/src/symbol.h @@ -29,10 +29,10 @@ extern struct rwnode *symbols_forest[]; // trees (because of 8-bit hash) // function acts upon the symbol's flag bits and produces an error if needed. -extern void symbol_set_value(struct symbol *symbol, struct number *new_value, int change_allowed); +extern void symbol_set_value(struct symbol *symbol, struct number *new_value, boolean change_allowed); // parse label definition (can be either global or local). // name must be held in GlobalDynaBuf. -extern void symbol_set_label(scope_t scope, int stat_flags, int force_bit, int change_allowed); +extern void symbol_set_label(scope_t scope, int stat_flags, int force_bit, boolean change_allowed); // parse symbol definition (can be either global or local, may turn out to be a label). // name must be held in GlobalDynaBuf. extern void symbol_parse_definition(scope_t scope, int stat_flags); diff --git a/src/tree.c b/src/tree.c index adf65b9..9396098 100644 --- a/src/tree.c +++ b/src/tree.c @@ -1,5 +1,5 @@ // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code. -// Copyright (C) 1998-2016 Marco Baye +// Copyright (C) 1998-2020 Marco Baye // Have a look at "acme.c" for further info // // tree stuff @@ -110,7 +110,7 @@ int Tree_easy_scan(struct ronode *tree, void **node_body, struct dynabuf *dyna_b // a new tree item, link to tree, fill with data and store its pointer. If the // "create" flag is zero, store NULL as result. // Returns whether item was created. -int Tree_hard_scan(struct rwnode **result, struct rwnode **forest, int id_number, int create) +int Tree_hard_scan(struct rwnode **result, struct rwnode **forest, int id_number, boolean create) { struct ronode wanted; // temporary storage struct rwnode **current_node; @@ -158,7 +158,7 @@ int Tree_hard_scan(struct rwnode **result, struct rwnode **forest, int id_number current_node = &((*current_node)->less_than_or_equal); } // node wasn't found. Check whether to create it - if (create == FALSE) { + if (!create) { *result = NULL; // indicate failure return FALSE; // return FALSE because node was not created } diff --git a/src/tree.h b/src/tree.h index d4290da..1322406 100644 --- a/src/tree.h +++ b/src/tree.h @@ -1,5 +1,5 @@ // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code. -// Copyright (C) 1998-2016 Marco Baye +// Copyright (C) 1998-2020 Marco Baye // Have a look at "acme.c" for further info // // tree stuff @@ -7,6 +7,7 @@ #define tree_H +#include "config.h" #include // for FILE @@ -51,7 +52,7 @@ extern int Tree_easy_scan(struct ronode *tree, void **node_body, struct dynabuf // location. If no matching item is found, check the "create" flag: If set, // create new tree item, link to tree, fill with data and store its pointer. // If "create" is zero, store NULL. Returns whether item was created. -extern int Tree_hard_scan(struct rwnode **result, struct rwnode **forest, int id_number, int create); +extern int Tree_hard_scan(struct rwnode **result, struct rwnode **forest, int id_number, boolean create); // Calls given function for each node of each tree of given forest. extern void Tree_dump_forest(struct rwnode **, int, void (*)(struct rwnode *, FILE *), FILE *);