Skip to content

Commit

Permalink
Polished project code to reduce warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
linguini1 committed Jan 8, 2024
1 parent 176b21b commit 84ad2f9
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 17 deletions.
6 changes: 3 additions & 3 deletions assembler/src/conversion/analyzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static void analyzer_fatal_error(Analyzer *analyzer, const char *err_msg) {
}

static const operator_t *_get_op_by_name(char *operator) {
for (int i = 0; i < NUM_OPERATORS; i++) {
for (unsigned int i = 0; i < NUM_OPERATORS; i++) {
if (!strcmp(OPERATORS[i].name, operator)) {
return &OPERATORS[i];
}
Expand Down Expand Up @@ -319,8 +319,8 @@ static uint16_t _analyzer_convert_form3(Analyzer *analyzer, const unsigned short

// Argument was an immediate
if (imm) {
inst = inst << 7; // Move over register bits to make room for immediate
inst = inst | (opcodes[0] << 11); // Add the opcode
inst = inst << 7; // Move over register bits to make room for immediate
inst = inst | (opcodes[0] << 11); // Add the opcode
inst = inst | (immediate & 0x1FF); // Add the immediate to the end

// Check that instruction closes with ]
Expand Down
2 changes: 1 addition & 1 deletion assembler/src/conversion/analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/* Register bit fields */
typedef struct ASMRegister {
char *name;
const char *name;
unsigned int bitfield;
} asm_register;

Expand Down
2 changes: 1 addition & 1 deletion assembler/src/conversion/identifiers.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void lookup_tree_destruct(ident_node_t *root) {
ident_node_t *lookup_tree_construct(TokenList *list) {
ident_node_t *root = NULL;
unsigned long current_pos = 0;
for (int i = 0; i < list->length; i++) {
for (unsigned int i = 0; i < list->length; i++) {
Token *t = list->tokens[i];

switch (t->type) {
Expand Down
4 changes: 2 additions & 2 deletions assembler/src/conversion/instructions.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void instruction_list_append(InstructionList *list, uint16_t instruction) {
uint16_t *new_arr = malloc(sizeof(uint16_t) * list->__capacity);

// Copy over tokens
for (int i = 0; i < list->length; i++) {
for (unsigned int i = 0; i < list->length; i++) {
new_arr[i] = list->instructions[i];
}

Expand All @@ -56,7 +56,7 @@ uint16_t instruction_list_get(InstructionList *list, int index) {
index = list->length + index;
}

if (!(index < list->length) || index < 0) {
if (!((unsigned)index < list->length) || index < 0) {
return -1;
}
return list->instructions[index];
Expand Down
4 changes: 2 additions & 2 deletions assembler/src/conversion/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static bool is_operator(char *ident) {
bool lexer_eof(Lexer *lexer) { return lexer->character == EOF; }

static void lexer_fatal_error(Lexer *lexer, const char *err_msg) {
char *format_string = "%s:%lu:%lu: error: %s\n\tcharacter: '%c'\n";
const char *format_string = "%s:%lu:%lu: error: %s\n\tcharacter: '%c'\n";
if (lexer->character > ' ' || lexer->character < '~') {
format_string = "%s:%lu:%lu: error: %s\n\tcharacter: 0x%x (ascii)\n";
}
Expand Down Expand Up @@ -202,7 +202,7 @@ static char *_lexer_read_decimal_literal(Lexer *lexer) {
}

static char *_lexer_read_numeric_literal(Lexer *lexer, token_t *type) {
// Initial read to determine literal type
// Initial read to determine literal type
_lexer_read_char(lexer);

if (lexer->character == '0' && _lexer_peek(lexer) == 'b') {
Expand Down
8 changes: 4 additions & 4 deletions assembler/src/conversion/tokens.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ TokenList *token_list_construct(unsigned long length) {
}

void token_list_destruct(TokenList *list) {
for (int i = 0; i < list->length; i++) {
for (unsigned int i = 0; i < list->length; i++) {
free(list->tokens[i]);
}
free(list);
Expand All @@ -75,7 +75,7 @@ void token_list_append(TokenList *list, Token *token) {
Token **new_arr = malloc(sizeof(Token *) * list->__capacity);

// Copy over tokens
for (int i = 0; i < list->length; i++) {
for (unsigned int i = 0; i < list->length; i++) {
new_arr[i] = list->tokens[i];
}

Expand All @@ -98,7 +98,7 @@ Token *token_list_get(TokenList *list, int index) {
index = list->length + index;
}

if (!(index < list->length) || index < 0) {
if (!((unsigned int)index < list->length) || index < 0) {
return NULL;
}
return list->tokens[index];
Expand Down Expand Up @@ -165,7 +165,7 @@ bool is_conditional(char *ident) {
return false;
}

unsigned int _condition_code(char *cc) {
unsigned int _condition_code(const char *cc) {
for (unsigned int i = 0; i < NUM_CONDITION_CODES; i++) {
if (!strcmp(cc, CONDITION_CODES[i])) {
return i;
Expand Down
4 changes: 2 additions & 2 deletions assembler/src/conversion/tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
typedef enum OperatorForm { Form1, Form2, Form3, Form4, Form5, FormStack, FormEquiv } form_t;

typedef struct Operator {
char *name;
const char *name;
unsigned short int raw[3];
form_t form;
} operator_t;
Expand Down Expand Up @@ -66,5 +66,5 @@ void string_to_uppercase(char *string);

/* Operator classification */
bool is_conditional(char *ident);
unsigned int _condition_code(char *cc);
unsigned int _condition_code(const char *cc);
#endif // _TOKENS_H_
1 change: 0 additions & 1 deletion assembler/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "conversion/analyzer.h"
#include "conversion/instructions.h"
#include "conversion/lexer.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

Expand Down
2 changes: 1 addition & 1 deletion assembler/tests/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int main(int argc, char *argv[]) {
pass_count += result.success;
test_result_display(result);
}
printf("\nTESTS PASSED: %d/%lld\n", pass_count, array_len(TEST_CASES));
printf("\nTESTS PASSED: %d/%ld\n", pass_count, array_len(TEST_CASES));

if (pass_count != array_len(TEST_CASES)) return EXIT_FAILURE;

Expand Down

0 comments on commit 84ad2f9

Please sign in to comment.