Compare commits
7 commits
Author | SHA1 | Date | |
---|---|---|---|
8587d61aa9 | |||
12f70b1a88 | |||
44beccfd06 | |||
26095748df | |||
edf807a5b3 | |||
38d14eec25 | |||
19c0d887b5 |
12 changed files with 111 additions and 62 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -57,9 +57,12 @@ dkms.conf
|
||||||
*.eipa
|
*.eipa
|
||||||
!test*.eipa
|
!test*.eipa
|
||||||
*.eipaimg
|
*.eipaimg
|
||||||
|
header/argp/*
|
||||||
|
/argp-standalone/
|
||||||
|
|
||||||
#Code editor
|
#Code editor
|
||||||
.vscode/*
|
.vscode/*
|
||||||
|
.idea/*
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
.cache/*
|
.cache/*
|
||||||
.#*
|
.#*
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
script_root=$(pwd)
|
script_root=$(pwd)
|
||||||
CC="clang"
|
|
||||||
|
|
||||||
echo "Creating folder for libraries"
|
echo "Creating folder for libraries"
|
||||||
mkdir lib
|
mkdir lib
|
||||||
|
@ -12,7 +11,7 @@ git clone https://h2939863.stratoserver.net/git/XOR/simple_hashtable.git
|
||||||
cd simple_hashtable
|
cd simple_hashtable
|
||||||
|
|
||||||
echo "Building simple_hashtable library"
|
echo "Building simple_hashtable library"
|
||||||
$CC -c shash.c -o $script_root/lib/shash.o
|
${CC:=clang} -c shash.c -o $script_root/lib/shash.o
|
||||||
|
|
||||||
echo "Delete source files"
|
echo "Delete source files"
|
||||||
cd $script_root
|
cd $script_root
|
||||||
|
|
|
@ -25,7 +25,7 @@ Here, common macros are specified
|
||||||
|
|
||||||
#define VER_MAJOR "0"
|
#define VER_MAJOR "0"
|
||||||
#define VER_MINOR "2"
|
#define VER_MINOR "2"
|
||||||
#define VER_PATCH "0"
|
#define VER_PATCH "1"
|
||||||
|
|
||||||
// alpha, beta or stable
|
// alpha, beta or stable
|
||||||
#define TAG "beta"
|
#define TAG "beta"
|
||||||
|
@ -33,6 +33,7 @@ Here, common macros are specified
|
||||||
#define ASCII_TAB 9
|
#define ASCII_TAB 9
|
||||||
#define ASCII_SPACE 32
|
#define ASCII_SPACE 32
|
||||||
#define ASCII_NEWLINE 10
|
#define ASCII_NEWLINE 10
|
||||||
|
#define ASCII_CARRIAGE_RETURN 13
|
||||||
|
|
||||||
#define INSTR_INP 0b0001
|
#define INSTR_INP 0b0001
|
||||||
#define INSTR_OUT 0b0010
|
#define INSTR_OUT 0b0010
|
||||||
|
@ -46,9 +47,6 @@ Here, common macros are specified
|
||||||
#define INSTR_JPU 0b1010
|
#define INSTR_JPU 0b1010
|
||||||
#define INSTR_EOJ 0b1011
|
#define INSTR_EOJ 0b1011
|
||||||
|
|
||||||
// get the character which the next fgetc() call would return
|
|
||||||
#define PREFGETC(file) *file->_IO_read_ptr
|
|
||||||
|
|
||||||
// const char *argp_program_bug_address = "eipabugs@outlook.com";
|
// const char *argp_program_bug_address = "eipabugs@outlook.com";
|
||||||
#define EIPA_BUG_ADRESS "eipabugs@outlook.com"
|
#define EIPA_BUG_ADRESS "eipabugs@outlook.com"
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
#define _IMAGE_SAVER_H_
|
#define _IMAGE_SAVER_H_
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
// Save machine code from target_code to file at out_path. Returns 0 on success
|
// 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
|
#endif
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "../header/shash/shash.h"
|
#include "../header/shash/shash.h"
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#define MAX_INSTRUCTION_COUNT 16
|
#define MAX_INSTRUCTION_COUNT 16
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@ typedef struct
|
||||||
{
|
{
|
||||||
unsigned int requires_adress;
|
unsigned int requires_adress;
|
||||||
unsigned int supports_adress_label;
|
unsigned int supports_adress_label;
|
||||||
u_int8_t opcode;
|
uint8_t opcode;
|
||||||
} instruction_information_t;
|
} instruction_information_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -25,7 +26,7 @@ typedef struct
|
||||||
unsigned int name_length;
|
unsigned int name_length;
|
||||||
unsigned int requires_adress;
|
unsigned int requires_adress;
|
||||||
unsigned int supports_adress_label;
|
unsigned int supports_adress_label;
|
||||||
u_int8_t opcode;
|
uint8_t opcode;
|
||||||
} instruction_information_config_t;
|
} instruction_information_config_t;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#ifndef _SHASH_H
|
#ifndef _SHASH_H
|
||||||
#define _SHASH_H
|
#define _SHASH_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -18,7 +19,6 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
|
||||||
#define WORD 32
|
#define WORD 32
|
||||||
#define TRANSFORM_TABLE_MAX_RAND 4294967296
|
#define TRANSFORM_TABLE_MAX_RAND 4294967296
|
||||||
#define DELTA 1
|
#define DELTA 1
|
||||||
|
@ -42,7 +42,7 @@ typedef struct
|
||||||
void *data;
|
void *data;
|
||||||
|
|
||||||
// gets set to 1 if another key, collides with this elemnts location
|
// 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
|
// On collision, this field stores where in the hash table array the second key (with the same hash) is located
|
||||||
int next_key_location;
|
int next_key_location;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "../header/common.h"
|
#include "../header/common.h"
|
||||||
#include "dyn_buf.h"
|
#include "dyn_buf.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifndef _TAGET_CODE_GENERATOR_H_
|
#ifndef _TAGET_CODE_GENERATOR_H_
|
||||||
#define _TAGET_CODE_GENERATOR_H_
|
#define _TAGET_CODE_GENERATOR_H_
|
||||||
|
@ -7,12 +8,12 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
// Get a machine code instruction from opcode and and optional adress. Returns 0 if the provides adress is too big
|
// 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
|
// 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);
|
int gen_target_code(char tokens[][MAX_TOKEN_SIZE], dynamic_buffer_t *target_code);
|
||||||
|
|
||||||
//Print out the machine code in 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
|
#endif
|
||||||
|
|
|
@ -44,6 +44,7 @@ unsigned int check_token_errors(char tokens[][MAX_TOKEN_SIZE], shash_hashtable_t
|
||||||
if(label_addr == NULL)
|
if(label_addr == NULL)
|
||||||
{
|
{
|
||||||
printf("ERROR: Label %s has not been defined (Used at token %d)\n", tokens[i], i);
|
printf("ERROR: Label %s has not been defined (Used at token %d)\n", tokens[i], i);
|
||||||
|
error_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the next token is a ;
|
// Check that the next token is a ;
|
||||||
|
@ -60,10 +61,12 @@ unsigned int check_token_errors(char tokens[][MAX_TOKEN_SIZE], shash_hashtable_t
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Do not fall through
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// fall through
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
// Check the adress stored at the next token
|
// Check the adress stored at the next token
|
||||||
|
|
|
@ -11,7 +11,7 @@ This code contains the implementations of all functions related to saving EIPA t
|
||||||
#include "../header/image_saver.h"
|
#include "../header/image_saver.h"
|
||||||
|
|
||||||
// Count how many instruction a target_code array contains
|
// 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;
|
unsigned int count = 0;
|
||||||
while(target_code[count]!=0)
|
while(target_code[count]!=0)
|
||||||
|
@ -21,7 +21,7 @@ static unsigned int get_instruction_count(__uint32_t *target_code)
|
||||||
return count;
|
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);
|
unsigned int count = get_instruction_count(target_code);
|
||||||
|
|
||||||
|
|
||||||
|
|
39
src/lexer.c
39
src/lexer.c
|
@ -10,6 +10,15 @@ This code contains the implementations of all functions related to the lexical a
|
||||||
#include "../header/common.h"
|
#include "../header/common.h"
|
||||||
#include "../header/lexer.h"
|
#include "../header/lexer.h"
|
||||||
|
|
||||||
|
// get the character which the next fgetc() call would return
|
||||||
|
static int prefgetc(FILE *fp)
|
||||||
|
{
|
||||||
|
long origin = ftell(fp);
|
||||||
|
int read = fgetc(fp);
|
||||||
|
fseek(fp, origin, SEEK_SET);
|
||||||
|
return read;
|
||||||
|
}
|
||||||
|
|
||||||
void lexer(FILE *input_file, dynamic_buffer_t *tokens)
|
void lexer(FILE *input_file, dynamic_buffer_t *tokens)
|
||||||
{
|
{
|
||||||
// Stores the current character we are examining
|
// Stores the current character we are examining
|
||||||
|
@ -53,7 +62,7 @@ void lexer(FILE *input_file, dynamic_buffer_t *tokens)
|
||||||
// This is an indice of a new token begining, so we probably need to increase token_index
|
// This is an indice of a new token begining, so we probably need to increase token_index
|
||||||
|
|
||||||
// Loop to the characters until the next character fgetc() would read is not space or tab
|
// Loop to the characters until the next character fgetc() would read is not space or tab
|
||||||
while (PREFGETC(input_file) == ASCII_SPACE || PREFGETC(input_file) == ASCII_TAB)
|
while (prefgetc(input_file) == ASCII_SPACE || prefgetc(input_file) == ASCII_TAB)
|
||||||
{
|
{
|
||||||
current_char = (char)fgetc(input_file);
|
current_char = (char)fgetc(input_file);
|
||||||
}
|
}
|
||||||
|
@ -63,7 +72,7 @@ void lexer(FILE *input_file, dynamic_buffer_t *tokens)
|
||||||
However, there can also be a space between the Adress and the newline.
|
However, there can also be a space between the Adress and the newline.
|
||||||
To not increase the token_index 2 times, we need to not increase it here if the next character is a \n
|
To not increase the token_index 2 times, we need to not increase it here if the next character is a \n
|
||||||
*/
|
*/
|
||||||
if (PREFGETC(input_file) != ';' && PREFGETC(input_file) != ASCII_NEWLINE)
|
if (prefgetc(input_file) != ';' && prefgetc(input_file) != ASCII_NEWLINE)
|
||||||
{
|
{
|
||||||
token_index++;
|
token_index++;
|
||||||
}
|
}
|
||||||
|
@ -82,9 +91,33 @@ void lexer(FILE *input_file, dynamic_buffer_t *tokens)
|
||||||
|
|
||||||
is_pos_line_start = 1;
|
is_pos_line_start = 1;
|
||||||
break;
|
break;
|
||||||
|
case ASCII_CARRIAGE_RETURN:
|
||||||
|
// Some operating systems use \r\n or just \r for newlines in texts.
|
||||||
|
|
||||||
|
// This is a indice of a new token -> increase token_index
|
||||||
|
token_index++;
|
||||||
|
|
||||||
|
// This also is a indice of a new instruction beginning
|
||||||
|
// in the tokens array, instructions are seperated by semicolons
|
||||||
|
((char (*)[MAX_TOKEN_SIZE]) tokens->buffer)[token_index][0] = ';';
|
||||||
|
tokens->used += MAX_TOKEN_SIZE;
|
||||||
|
|
||||||
|
// Since the Instruction seperator (';') is also a token, we need to increase token_index again
|
||||||
|
token_index++;
|
||||||
|
|
||||||
|
// Check for \r\n
|
||||||
|
if((char) prefgetc(input_file) == ASCII_NEWLINE)
|
||||||
|
{
|
||||||
|
// Skip over this \n
|
||||||
|
current_char = fgetc(input_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
is_pos_line_start = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
case ';':
|
case ';':
|
||||||
// Loop over the comment
|
// Loop over the comment
|
||||||
while (PREFGETC(input_file) != ASCII_NEWLINE && PREFGETC(input_file) != '\0')
|
while (prefgetc(input_file) != ASCII_NEWLINE && prefgetc(input_file) != '\0')
|
||||||
{
|
{
|
||||||
current_char = (char)fgetc(input_file);
|
current_char = (char)fgetc(input_file);
|
||||||
}
|
}
|
||||||
|
|
22
src/main.c
22
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
|
It also is responsible for Argument Parsing
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef WIN_COMPILE
|
||||||
#include <argp.h>
|
#include <argp.h>
|
||||||
|
#else
|
||||||
|
#include "../header/argp/argp.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "../header/argp_commons.h"
|
#include "../header/argp_commons.h"
|
||||||
#include "../header/common.h"
|
#include "../header/common.h"
|
||||||
|
@ -121,7 +127,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
// Tokenize the EIPA Assembly
|
// Tokenize the EIPA Assembly
|
||||||
FILE *assembly_file;
|
FILE *assembly_file;
|
||||||
assembly_file = fopen(arguments.input_file, "r");
|
assembly_file = fopen(arguments.input_file, "rb");
|
||||||
if (assembly_file == NULL)
|
if (assembly_file == NULL)
|
||||||
{
|
{
|
||||||
printf("Error: Couldn't open input file\n");
|
printf("Error: Couldn't open input file\n");
|
||||||
|
@ -144,7 +150,6 @@ int main(int argc, char **argv)
|
||||||
shash_init_hashtable(&label_table, LABEL_TABLE_SIZE);
|
shash_init_hashtable(&label_table, LABEL_TABLE_SIZE);
|
||||||
build_label_table((char (*)[MAX_TOKEN_SIZE]) label_tokens.buffer, &label_table);
|
build_label_table((char (*)[MAX_TOKEN_SIZE]) label_tokens.buffer, &label_table);
|
||||||
|
|
||||||
|
|
||||||
dynamic_buffer_t no_label_definition_tokens;
|
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);
|
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)
|
if (no_label_definition_tokens.buffer == NULL)
|
||||||
|
@ -158,7 +163,12 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
// Check if the EIPA Assembly contains errors with the no_label_definition_tokens array
|
// Check if the EIPA Assembly contains errors with the no_label_definition_tokens array
|
||||||
shash_hashtable_t instruction_informations = create_instruction_information_hastable();
|
shash_hashtable_t instruction_informations = create_instruction_information_hastable();
|
||||||
printf("Found %d errors\n", check_token_errors((char (*)[MAX_TOKEN_SIZE]) no_label_definition_tokens.buffer, instruction_informations, label_table));
|
unsigned int error_c = check_token_errors((char (*)[MAX_TOKEN_SIZE]) no_label_definition_tokens.buffer, instruction_informations, label_table);
|
||||||
|
printf("Found %d errors\n", error_c);
|
||||||
|
if(error_c > 0)
|
||||||
|
{
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
// Part II of processing labels
|
// Part II of processing labels
|
||||||
dynamic_buffer_t tokens;
|
dynamic_buffer_t tokens;
|
||||||
|
@ -173,7 +183,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
// Generate the target code
|
// Generate the target code
|
||||||
dynamic_buffer_t 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)
|
if (target_code.buffer == NULL)
|
||||||
{
|
{
|
||||||
printf("Error: Could not allocate memory for the target code\n");
|
printf("Error: Could not allocate memory for the target code\n");
|
||||||
|
@ -188,7 +198,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the target code to a file
|
// 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");
|
printf("Couldn't save the output file\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -198,7 +208,7 @@ int main(int argc, char **argv)
|
||||||
if (arguments.print_tokens)
|
if (arguments.print_tokens)
|
||||||
print_tokens((char (*)[MAX_TOKEN_SIZE])tokens.buffer);
|
print_tokens((char (*)[MAX_TOKEN_SIZE])tokens.buffer);
|
||||||
if (arguments.print_target_code)
|
if (arguments.print_target_code)
|
||||||
print_target_code((__uint32_t *)target_code.buffer);
|
print_target_code((uint32_t *)target_code.buffer);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
destroy_instruction_information_hashtable(&instruction_informations);
|
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/common.h"
|
||||||
#include "../header/target_code_generator.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
|
// stores the value of the instructions
|
||||||
__uint32_t instruction = 0;
|
uint32_t instruction = 0;
|
||||||
|
|
||||||
// move the opcode bytes to the left of the instruction
|
// move the opcode bytes to the left of the instruction
|
||||||
instruction = instruction | (unsigned)opcode << (28);
|
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)
|
else if (strcmp(tokens[token_index], "INP") == 0)
|
||||||
{
|
{
|
||||||
// Stores the Adress accociated with this operation
|
// 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
|
// The address of the instructon is stored at the next token. Read that
|
||||||
token_index++;
|
token_index++;
|
||||||
sscanf(tokens[token_index], "%d", &adress);
|
sscanf(tokens[token_index], "%d", &adress);
|
||||||
|
|
||||||
((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_INP, 1, adress);
|
((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_INP, 1, adress);
|
||||||
if (((__uint32_t *) target_code->buffer)[instruction_index] == 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);
|
printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS);
|
||||||
return EOVERFLOW;
|
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)
|
else if (strcmp(tokens[token_index], "OUT") == 0)
|
||||||
{
|
{
|
||||||
// Stores the Adress accociated with this operation
|
// 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
|
// The address of the instructon is stored at the next token. Read that
|
||||||
token_index++;
|
token_index++;
|
||||||
sscanf(tokens[token_index], "%d", &adress);
|
sscanf(tokens[token_index], "%d", &adress);
|
||||||
|
|
||||||
((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_OUT, 1, adress);
|
((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_OUT, 1, adress);
|
||||||
if (((__uint32_t *) target_code->buffer)[instruction_index] == 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);
|
printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS);
|
||||||
return EOVERFLOW;
|
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)
|
else if (strcmp(tokens[token_index], "LDA") == 0)
|
||||||
{
|
{
|
||||||
// Stores the Adress accociated with this operation
|
// 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
|
// The address of the instructon is stored at the next token. Read that
|
||||||
token_index++;
|
token_index++;
|
||||||
sscanf(tokens[token_index], "%d", &adress);
|
sscanf(tokens[token_index], "%d", &adress);
|
||||||
|
|
||||||
((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_LDA, 1, adress);
|
((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_LDA, 1, adress);
|
||||||
if (((__uint32_t *) target_code->buffer)[instruction_index] == 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);
|
printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS);
|
||||||
return EOVERFLOW;
|
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)
|
else if (strcmp(tokens[token_index], "STA") == 0)
|
||||||
{
|
{
|
||||||
// Stores the Adress accociated with this operation
|
// 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
|
// The address of the instructon is stored at the next token. Read that
|
||||||
token_index++;
|
token_index++;
|
||||||
sscanf(tokens[token_index], "%d", &adress);
|
sscanf(tokens[token_index], "%d", &adress);
|
||||||
|
|
||||||
((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_STA, 1, adress);
|
((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_STA, 1, adress);
|
||||||
if (((__uint32_t *) target_code->buffer)[instruction_index] == 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);
|
printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS);
|
||||||
return EOVERFLOW;
|
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)
|
else if (strcmp(tokens[token_index], "INC") == 0)
|
||||||
{
|
{
|
||||||
((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_INC, 0, 0);
|
((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_INC, 0, 0);
|
||||||
if (((__uint32_t *) target_code->buffer)[instruction_index] == 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);
|
printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS);
|
||||||
return EOVERFLOW;
|
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)
|
else if (strcmp(tokens[token_index], "DEC") == 0)
|
||||||
{
|
{
|
||||||
((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_DEC, 0, 0);
|
((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_DEC, 0, 0);
|
||||||
if (((__uint32_t *) target_code->buffer)[instruction_index] == 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);
|
printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS);
|
||||||
return EOVERFLOW;
|
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
|
// 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
|
// The address of the instructon is stored at the next token. Read that
|
||||||
token_index++;
|
token_index++;
|
||||||
sscanf(tokens[token_index], "%d", &adress);
|
sscanf(tokens[token_index], "%d", &adress);
|
||||||
|
|
||||||
((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_JPP, 1, adress);
|
((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_JPP, 1, adress);
|
||||||
if (((__uint32_t *) target_code->buffer)[instruction_index] == 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);
|
printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS);
|
||||||
return EOVERFLOW;
|
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)
|
else if (strcmp(tokens[token_index], "JPZ") == 0)
|
||||||
{
|
{
|
||||||
// Stores the Adress accociated with this operation
|
// 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
|
// The address of the instructon is stored at the next token. Read that
|
||||||
token_index++;
|
token_index++;
|
||||||
sscanf(tokens[token_index], "%d", &adress);
|
sscanf(tokens[token_index], "%d", &adress);
|
||||||
|
|
||||||
((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_JPZ, 1, adress);
|
((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_JPZ, 1, adress);
|
||||||
if (((__uint32_t *) target_code->buffer)[instruction_index] == 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);
|
printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS);
|
||||||
return EOVERFLOW;
|
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)
|
else if (strcmp(tokens[token_index], "JPN") == 0)
|
||||||
{
|
{
|
||||||
// Stores the Adress accociated with this operation
|
// 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
|
// The address of the instructon is stored at the next token. Read that
|
||||||
token_index++;
|
token_index++;
|
||||||
sscanf(tokens[token_index], "%d", &adress);
|
sscanf(tokens[token_index], "%d", &adress);
|
||||||
|
|
||||||
((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_JPN, 1, adress);
|
((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_JPN, 1, adress);
|
||||||
if ( ((__uint32_t *) target_code->buffer)[instruction_index] == 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);
|
printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS);
|
||||||
return EOVERFLOW;
|
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)
|
else if (strcmp(tokens[token_index], "JPU") == 0)
|
||||||
{
|
{
|
||||||
// Stores the Adress accociated with this operation
|
// 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
|
// The address of the instructon is stored at the next token. Read that
|
||||||
token_index++;
|
token_index++;
|
||||||
sscanf(tokens[token_index], "%d", &adress);
|
sscanf(tokens[token_index], "%d", &adress);
|
||||||
|
|
||||||
((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_JPU, 1, adress);
|
((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_JPU, 1, adress);
|
||||||
if ( ((__uint32_t *) target_code->buffer)[instruction_index] == 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);
|
printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS);
|
||||||
return EOVERFLOW;
|
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)
|
else if (strcmp(tokens[token_index], "EOJ") == 0)
|
||||||
{
|
{
|
||||||
((__uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_EOJ, 0, 0);
|
((uint32_t *) target_code->buffer)[instruction_index] = get_target_instruction(INSTR_EOJ, 0, 0);
|
||||||
if ( ((__uint32_t *) target_code->buffer)[instruction_index] == 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);
|
printf("Error: Received andress bigger than %d\nThis error shoudn't occur! Please report at %s\n", MAX_MEMORY, EIPA_BUG_ADRESS);
|
||||||
return EOVERFLOW;
|
return EOVERFLOW;
|
||||||
|
@ -216,7 +216,7 @@ int gen_target_code(char tokens[][MAX_TOKEN_SIZE], dynamic_buffer_t *target_code
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_target_code(__uint32_t *target_code)
|
void print_target_code(uint32_t *target_code)
|
||||||
{
|
{
|
||||||
int instruction_index = 0;
|
int instruction_index = 0;
|
||||||
while (target_code[instruction_index] != 0)
|
while (target_code[instruction_index] != 0)
|
||||||
|
|
Loading…
Reference in a new issue