diff --git a/.gitignore b/.gitignore index c155c8d..32111e8 100755 --- a/.gitignore +++ b/.gitignore @@ -57,6 +57,8 @@ dkms.conf *.eipa !test*.eipa *.eipaimg +header/argp/* +/argp-standalone/ #Code editor .vscode/* diff --git a/dependency_setup.sh b/dependency_setup.sh index ddaedc3..da98f9a 100755 --- a/dependency_setup.sh +++ b/dependency_setup.sh @@ -1,6 +1,6 @@ #! /bin/bash script_root=$(pwd) -CC="clang" +CC:="clang" echo "Creating folder for libraries" mkdir lib diff --git a/header/image_saver.h b/header/image_saver.h index ff41abe..4d4642c 100755 --- a/header/image_saver.h +++ b/header/image_saver.h @@ -2,8 +2,9 @@ #define _IMAGE_SAVER_H_ #include +#include // Save machine code from target_code to file at out_path. Returns 0 on success -int save_img(char *out_path, __uint32_t *target_code); +int save_img(char *out_path, uint32_t *target_code); #endif diff --git a/header/instruction_table.h b/header/instruction_table.h index 0d5e361..16fa31d 100644 --- a/header/instruction_table.h +++ b/header/instruction_table.h @@ -3,6 +3,7 @@ #include "../header/shash/shash.h" #include +#include #define MAX_INSTRUCTION_COUNT 16 @@ -16,7 +17,7 @@ typedef struct { unsigned int requires_adress; unsigned int supports_adress_label; - u_int8_t opcode; + uint8_t opcode; } instruction_information_t; typedef struct @@ -25,7 +26,7 @@ typedef struct unsigned int name_length; unsigned int requires_adress; unsigned int supports_adress_label; - u_int8_t opcode; + uint8_t opcode; } instruction_information_config_t; #endif diff --git a/header/shash/shash.h b/header/shash/shash.h index cf51f79..1fcc78e 100644 --- a/header/shash/shash.h +++ b/header/shash/shash.h @@ -10,6 +10,7 @@ #ifndef _SHASH_H #define _SHASH_H +#include #include #include #include @@ -18,7 +19,6 @@ #include #include - #define WORD 32 #define TRANSFORM_TABLE_MAX_RAND 4294967296 #define DELTA 1 @@ -38,11 +38,11 @@ typedef struct { char *key; unsigned int keylen; - + void *data; // gets set to 1 if another key, collides with this elemnts location - u_int8_t encountered_collision; + uint8_t encountered_collision; // On collision, this field stores where in the hash table array the second key (with the same hash) is located int next_key_location; @@ -68,10 +68,10 @@ unsigned int shash_hash(char *key, unsigned int len, shash_hashtable_t *hashtabl int shash_set(char *key, unsigned int len, void *data, shash_hashtable_t *hashtable); /* Returns the pointer stored at the key key of length len in hashtable. - Returns ptr to NULL when the key is not found */ + Returns ptr to NULL when the key is not found */ void *shash_get(char *key, unsigned int len, shash_hashtable_t *hashtable); // Free up the space allocated for hashtable. Data inside the hastable is NOT freed void shash_destroy_hashtable(shash_hashtable_t *hashtable); -#endif +#endif \ No newline at end of file diff --git a/header/target_code_generator.h b/header/target_code_generator.h index 84bb873..a94d0ec 100755 --- a/header/target_code_generator.h +++ b/header/target_code_generator.h @@ -1,5 +1,6 @@ #include "../header/common.h" #include "dyn_buf.h" +#include #ifndef _TAGET_CODE_GENERATOR_H_ #define _TAGET_CODE_GENERATOR_H_ @@ -7,12 +8,12 @@ #include // Get a machine code instruction from opcode and and optional adress. Returns 0 if the provides adress is too big -__uint32_t get_target_instruction(__uint8_t opcode, __uint8_t use_adress, __uint32_t adress); +uint32_t get_target_instruction(uint8_t opcode, uint8_t use_adress, uint32_t adress); // Generate the machine code from tokens into target_code. Returns 0 on success, errno integer on failure int gen_target_code(char tokens[][MAX_TOKEN_SIZE], dynamic_buffer_t *target_code); //Print out the machine code in target_code -void print_target_code(__uint32_t *target_code); +void print_target_code(uint32_t *target_code); #endif diff --git a/src/image_saver.c b/src/image_saver.c index 130b0b4..55b79d6 100755 --- a/src/image_saver.c +++ b/src/image_saver.c @@ -11,7 +11,7 @@ This code contains the implementations of all functions related to saving EIPA t #include "../header/image_saver.h" // Count how many instruction a target_code array contains -static unsigned int get_instruction_count(__uint32_t *target_code) +static unsigned int get_instruction_count(uint32_t *target_code) { unsigned int count = 0; while(target_code[count]!=0) @@ -21,7 +21,7 @@ static unsigned int get_instruction_count(__uint32_t *target_code) return count; } -int save_img(char *out_path, __uint32_t *target_code){ +int save_img(char *out_path, uint32_t *target_code){ unsigned int count = get_instruction_count(target_code); diff --git a/src/main.c b/src/main.c index 14f93b2..dc77423 100755 --- a/src/main.c +++ b/src/main.c @@ -5,10 +5,16 @@ This code is the entry point of the EIPA Assembler and calls the needed function It also is responsible for Argument Parsing */ +#ifndef WIN_COMPILE #include +#else +#include "../header/argp/argp.h" +#endif + #include #include #include +#include #include "../header/argp_commons.h" #include "../header/common.h" @@ -144,7 +150,6 @@ int main(int argc, char **argv) shash_init_hashtable(&label_table, LABEL_TABLE_SIZE); build_label_table((char (*)[MAX_TOKEN_SIZE]) label_tokens.buffer, &label_table); - dynamic_buffer_t no_label_definition_tokens; init_dynamic_buffer(&no_label_definition_tokens, TABLE_INIT_SIZE * MAX_TOKEN_SIZE, TABLE_GROW_SIZE * MAX_TOKEN_SIZE); if (no_label_definition_tokens.buffer == NULL) @@ -173,7 +178,7 @@ int main(int argc, char **argv) // Generate the target code dynamic_buffer_t target_code; - init_dynamic_buffer(&target_code, TARGET_CODE_INIT * sizeof(__uint32_t), TARGET_CODE_GROW * sizeof(__uint32_t)); + init_dynamic_buffer(&target_code, TARGET_CODE_INIT * sizeof(uint32_t), TARGET_CODE_GROW * sizeof(uint32_t)); if (target_code.buffer == NULL) { printf("Error: Could not allocate memory for the target code\n"); @@ -188,7 +193,7 @@ int main(int argc, char **argv) } // Save the target code to a file - if (save_img(arguments.output_file, (__uint32_t *)target_code.buffer) != 0) + if (save_img(arguments.output_file, (uint32_t *)target_code.buffer) != 0) { printf("Couldn't save the output file\n"); exit(EXIT_FAILURE); @@ -198,7 +203,7 @@ int main(int argc, char **argv) if (arguments.print_tokens) print_tokens((char (*)[MAX_TOKEN_SIZE])tokens.buffer); if (arguments.print_target_code) - print_target_code((__uint32_t *)target_code.buffer); + print_target_code((uint32_t *)target_code.buffer); // Cleanup destroy_instruction_information_hashtable(&instruction_informations); diff --git a/src/target_code_generator.c b/src/target_code_generator.c index 4ff6374..f037700 100755 --- a/src/target_code_generator.c +++ b/src/target_code_generator.c @@ -12,10 +12,10 @@ This code contains the implementations for all the functions related to the targ #include "../header/common.h" #include "../header/target_code_generator.h" -__uint32_t get_target_instruction(__uint8_t opcode, __uint8_t use_adress, __uint32_t adress) +uint32_t get_target_instruction(uint8_t opcode, uint8_t use_adress, uint32_t adress) { // stores the value of the instructions - __uint32_t instruction = 0; + uint32_t instruction = 0; // move the opcode bytes to the left of the instruction instruction = instruction | (unsigned)opcode << (28); @@ -57,14 +57,14 @@ int gen_target_code(char tokens[][MAX_TOKEN_SIZE], dynamic_buffer_t *target_code else if (strcmp(tokens[token_index], "INP") == 0) { // Stores the Adress accociated with this operation - __uint32_t adress; + uint32_t adress; // The address of the instructon is stored at the next token. Read that token_index++; sscanf(tokens[token_index], "%d", &adress); - ((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_INP, 1, adress); - if (((__uint32_t *) target_code->buffer)[instruction_index] == 0) + ((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_INP, 1, adress); + if (((uint32_t *) target_code->buffer)[instruction_index] == 0) { printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS); return EOVERFLOW; @@ -73,14 +73,14 @@ int gen_target_code(char tokens[][MAX_TOKEN_SIZE], dynamic_buffer_t *target_code else if (strcmp(tokens[token_index], "OUT") == 0) { // Stores the Adress accociated with this operation - __uint32_t adress; + uint32_t adress; // The address of the instructon is stored at the next token. Read that token_index++; sscanf(tokens[token_index], "%d", &adress); - ((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_OUT, 1, adress); - if (((__uint32_t *) target_code->buffer)[instruction_index] == 0) + ((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_OUT, 1, adress); + if (((uint32_t *) target_code->buffer)[instruction_index] == 0) { printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS); return EOVERFLOW; @@ -89,14 +89,14 @@ int gen_target_code(char tokens[][MAX_TOKEN_SIZE], dynamic_buffer_t *target_code else if (strcmp(tokens[token_index], "LDA") == 0) { // Stores the Adress accociated with this operation - __uint32_t adress; + uint32_t adress; // The address of the instructon is stored at the next token. Read that token_index++; sscanf(tokens[token_index], "%d", &adress); - ((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_LDA, 1, adress); - if (((__uint32_t *) target_code->buffer)[instruction_index] == 0) + ((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_LDA, 1, adress); + if (((uint32_t *) target_code->buffer)[instruction_index] == 0) { printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS); return EOVERFLOW; @@ -105,14 +105,14 @@ int gen_target_code(char tokens[][MAX_TOKEN_SIZE], dynamic_buffer_t *target_code else if (strcmp(tokens[token_index], "STA") == 0) { // Stores the Adress accociated with this operation - __uint32_t adress; + uint32_t adress; // The address of the instructon is stored at the next token. Read that token_index++; sscanf(tokens[token_index], "%d", &adress); - ((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_STA, 1, adress); - if (((__uint32_t *) target_code->buffer)[instruction_index] == 0) + ((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_STA, 1, adress); + if (((uint32_t *) target_code->buffer)[instruction_index] == 0) { printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS); return EOVERFLOW; @@ -120,8 +120,8 @@ int gen_target_code(char tokens[][MAX_TOKEN_SIZE], dynamic_buffer_t *target_code } else if (strcmp(tokens[token_index], "INC") == 0) { - ((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_INC, 0, 0); - if (((__uint32_t *) target_code->buffer)[instruction_index] == 0) + ((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_INC, 0, 0); + if (((uint32_t *) target_code->buffer)[instruction_index] == 0) { printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS); return EOVERFLOW; @@ -129,8 +129,8 @@ int gen_target_code(char tokens[][MAX_TOKEN_SIZE], dynamic_buffer_t *target_code } else if (strcmp(tokens[token_index], "DEC") == 0) { - ((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_DEC, 0, 0); - if (((__uint32_t *) target_code->buffer)[instruction_index] == 0) + ((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_DEC, 0, 0); + if (((uint32_t *) target_code->buffer)[instruction_index] == 0) { printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS); return EOVERFLOW; @@ -140,14 +140,14 @@ int gen_target_code(char tokens[][MAX_TOKEN_SIZE], dynamic_buffer_t *target_code { // Stores the Adress accociated with this operation - __uint32_t adress; + uint32_t adress; // The address of the instructon is stored at the next token. Read that token_index++; sscanf(tokens[token_index], "%d", &adress); - ((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_JPP, 1, adress); - if (((__uint32_t *) target_code->buffer)[instruction_index] == 0) + ((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_JPP, 1, adress); + if (((uint32_t *) target_code->buffer)[instruction_index] == 0) { printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS); return EOVERFLOW; @@ -156,14 +156,14 @@ int gen_target_code(char tokens[][MAX_TOKEN_SIZE], dynamic_buffer_t *target_code else if (strcmp(tokens[token_index], "JPZ") == 0) { // Stores the Adress accociated with this operation - __uint32_t adress; + uint32_t adress; // The address of the instructon is stored at the next token. Read that token_index++; sscanf(tokens[token_index], "%d", &adress); - ((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_JPZ, 1, adress); - if (((__uint32_t *) target_code->buffer)[instruction_index] == 0) + ((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_JPZ, 1, adress); + if (((uint32_t *) target_code->buffer)[instruction_index] == 0) { printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS); return EOVERFLOW; @@ -172,14 +172,14 @@ int gen_target_code(char tokens[][MAX_TOKEN_SIZE], dynamic_buffer_t *target_code else if (strcmp(tokens[token_index], "JPN") == 0) { // Stores the Adress accociated with this operation - __uint32_t adress; + uint32_t adress; // The address of the instructon is stored at the next token. Read that token_index++; sscanf(tokens[token_index], "%d", &adress); - ((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_JPN, 1, adress); - if ( ((__uint32_t *) target_code->buffer)[instruction_index] == 0) + ((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_JPN, 1, adress); + if ( ((uint32_t *) target_code->buffer)[instruction_index] == 0) { printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS); return EOVERFLOW; @@ -188,14 +188,14 @@ int gen_target_code(char tokens[][MAX_TOKEN_SIZE], dynamic_buffer_t *target_code else if (strcmp(tokens[token_index], "JPU") == 0) { // Stores the Adress accociated with this operation - __uint32_t adress; + uint32_t adress; // The address of the instructon is stored at the next token. Read that token_index++; sscanf(tokens[token_index], "%d", &adress); - ((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_JPU, 1, adress); - if ( ((__uint32_t *) target_code->buffer)[instruction_index] == 0) + ((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_JPU, 1, adress); + if ( ((uint32_t *) target_code->buffer)[instruction_index] == 0) { printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS); return EOVERFLOW; @@ -203,8 +203,8 @@ int gen_target_code(char tokens[][MAX_TOKEN_SIZE], dynamic_buffer_t *target_code } else if (strcmp(tokens[token_index], "EOJ") == 0) { - ((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_EOJ, 0, 0); - if ( ((__uint32_t *) target_code->buffer)[instruction_index] == 0) + ((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_EOJ, 0, 0); + if ( ((uint32_t *) target_code->buffer)[instruction_index] == 0) { printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS); return EOVERFLOW; @@ -216,7 +216,7 @@ int gen_target_code(char tokens[][MAX_TOKEN_SIZE], dynamic_buffer_t *target_code return EXIT_SUCCESS; } -void print_target_code(__uint32_t *target_code) +void print_target_code(uint32_t *target_code) { int instruction_index = 0; while (target_code[instruction_index] != 0)