Added translation registers

This commit is contained in:
alejeune 2023-05-12 15:37:57 +02:00
parent 88cc4fe7e7
commit 360f3d29eb
10 changed files with 2050 additions and 0 deletions

0
LinkedList.h Normal file
View file

0
asm Normal file
View file

BIN
asmTable.o Normal file

Binary file not shown.

BIN
blocs.o Normal file

Binary file not shown.

1941
lex.yy.c Normal file

File diff suppressed because it is too large Load diff

BIN
lex.yy.o Normal file

Binary file not shown.

109
linkedList.c Normal file
View file

@ -0,0 +1,109 @@
#include "LinkedList.h"
#include "table.h"
/*Add element in linked lis*/
llist addElementLinkedList(char *label, int numLine){
element* newElement = malloc(sizeof(element));
strcpy(newElement->val, label);
newElement->numLine = numLine;
newElement->nxt = NULL;
if (list == NULL) {
return newElement;
}
else {
element* temp=list;
while (temp->nxt != NULL) {
temp = temp->nxt;
}
temp->nxt = newElement;
return list;
}
}
/* Find the numero of the lines with a specific label*/
int findLineElement(char *label){
element *tmp=list;
while (tmp != NULL){
if (strcmp(tmp->val, label)){
return tmp->numLine;
}
tmp = tmp->nxt;
}
error("Label doesn't exist");
return NULL;
}
// TODO : ne pas incrementer les lignes avec LABEL
/* Count Lines and suppress Label */
void countLines(char *s){
FILE *fptr;
char * line = NULL;
size_t len = 0;
ssize_t read;
fptr = fopen(s, "r");
FILE* fOut;
fOut = fopen("asm2", "a");
if(fptr == NULL) {
error("Empty file.");
}
while ((read = getline(&line, &len, fptr)) != -1) {
if (IsInt(line[0])){
char label[LABEL_SIZE];
sprintf(label, "%d_LABEL", numberLines);
addElementLinkedList(label, numberLines);
}
else {
fputs(line, fOut);
numberLines ++;
}
printf("%s", line);
}
fclose(fptr);
fclose(fOut);
}
/* Replace label */
bool IsInt(char c){
for(int i = 0; i < 10; i ++){
if (c == i){
return true;
}
}
return false;
}
void detectLabel(char* s){
char label[LABEL_SIZE];
char numLabel[2];
if (s[0] == 'J'){
if (s[1] == 'M'){
int i = 4;
while (s[i] != '_'){
sprintf(numLabel, "%d", s[i]);
strcat(label, numLabel);
fputs(line, fp); // ajout de ce qu'il y a avant
i++;
}
}
else {
int i = 4 ;
while (s[i] != ' '){
NULL;
i ++;
} i ++;
while (s[i] != '_'){
sprintf(numLabel, "%d", s[i]);
strcat(label, numLabel);
fputs(line, fp); // ajout de ce qu'il y a avant
i++;
}
}
// ajout dans le table
}
} //JMP 12_LABEL
//JMF @cdcjdjk 12_LABEL

BIN
operations.o Normal file

Binary file not shown.

BIN
table.o Normal file

Binary file not shown.

BIN
yacc.tab.o Normal file

Binary file not shown.