Change types for better OS compatibility
This commit is contained in:
parent
19c0d887b5
commit
38d14eec25
9 changed files with 60 additions and 50 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -57,6 +57,8 @@ dkms.conf
|
|||
*.eipa
|
||||
!test*.eipa
|
||||
*.eipaimg
|
||||
header/argp/*
|
||||
/argp-standalone/
|
||||
|
||||
#Code editor
|
||||
.vscode/*
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#! /bin/bash
|
||||
script_root=$(pwd)
|
||||
CC="clang"
|
||||
CC:="clang"
|
||||
|
||||
echo "Creating folder for libraries"
|
||||
mkdir lib
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
#define _IMAGE_SAVER_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// 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
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "../header/shash/shash.h"
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#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
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#ifndef _SHASH_H
|
||||
#define _SHASH_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -18,7 +19,6 @@
|
|||
#include <time.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
#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
|
|
@ -1,5 +1,6 @@
|
|||
#include "../header/common.h"
|
||||
#include "dyn_buf.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef _TAGET_CODE_GENERATOR_H_
|
||||
#define _TAGET_CODE_GENERATOR_H_
|
||||
|
@ -7,12 +8,12 @@
|
|||
#include <stdio.h>
|
||||
|
||||
// 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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
||||
|
|
13
src/main.c
13
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 <argp.h>
|
||||
#else
|
||||
#include "../header/argp/argp.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#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);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue