Compare commits

...

5 Commits

Author SHA1 Message Date
Augusto Gunsch 12d39043ec
Ignore Makefile at statistics 2020-11-21 11:02:55 -03:00
Augusto Gunsch dfd8a85a5d
Add .gitattributes 2020-11-21 11:01:10 -03:00
Augusto Gunsch 2cb621f6ea
Remove undefined function 2020-11-21 10:49:37 -03:00
Augusto Gunsch c8dabe7abc
Fix memory leaks 2020-11-21 10:44:52 -03:00
Augusto Gunsch e456ace07b
Move LINELIST to util.c 2020-11-20 20:31:31 -03:00
7 changed files with 36 additions and 13 deletions

3
.gitattributes vendored Normal file
View File

@ -0,0 +1,3 @@
*.h linguist-language=C
*.c linguist-language=C
Makefile -linguist-detectable

View File

@ -238,6 +238,7 @@ void striplabels(ASSEMBLER* a) {
a->lns = curln->next;
LINELIST* tmp = curln;
curln = curln->next;
free(tmp->content);
free(tmp);
}
else {
@ -372,8 +373,17 @@ void translate(ASSEMBLER* a) {
}
}
void freelns(LINELIST* lns) {
LINELIST* next = lns->next;
free(lns->content);
free(lns);
if(next != NULL)
freelns(next);
}
void freeassembler(ASSEMBLER* a) {
freesymbols(a->vars);
freesymbols(a->labels);
freelns(a->lns);
free(a);
}

9
main.c
View File

@ -12,14 +12,6 @@ char* getoutname(char* fname, int fnamelen) {
return outf;
}
void printlns(LINELIST* lns, FILE* stream) {
LINELIST* curln = lns;
while(curln != NULL) {
fprintf(stream, "%s\n", curln->content);
curln = curln->next;
}
}
int main(int argc, char* argv[]) {
if(argc < 2) {
printf("Usage: %s {input}\n", argv[0]);
@ -43,6 +35,7 @@ int main(int argc, char* argv[]) {
parse(p);
ASSEMBLER* a = mkassembler(p->output);
free(p);
// variable substitution
preprocess(a);

View File

@ -4,6 +4,7 @@
#include <stdlib.h>
#include <ctype.h>
#include "parser.h"
#include "util.h"
void pushln(LINELIST** curln, char* tmpln, int lnind, int truen) {
int size = (lnind+1)*sizeof(char);

View File

@ -1,14 +1,11 @@
#ifndef PARSER_H
#define PARSER_H
#include <stdio.h>
#include "util.h"
#define INST_LIMIT 1<<15
typedef struct lnls {
char* content;
int truen;
struct lnls* next;
} LINELIST;
typedef struct {
FILE* input;

8
util.c
View File

@ -22,3 +22,11 @@ int countplaces(int n) {
}
return places;
}
void printlns(LINELIST* lns, FILE* stream) {
LINELIST* curln = lns;
while(curln != NULL) {
fprintf(stream, "%s\n", curln->content);
curln = curln->next;
}
}

11
util.h
View File

@ -1,5 +1,16 @@
#ifndef UTIL_H
#define UTIL_H
#include <stdio.h>
char* heapstr(const char* str, int len);
int countplaces(int n);
typedef struct lnls {
char* content;
int truen;
struct lnls* next;
} LINELIST;
void printlns(LINELIST* lns, FILE* stream);
#endif