var_desc, test with valgrind
This commit is contained in:
parent
6947204eea
commit
5230e7f4e1
20
Makefile
20
Makefile
@ -1,13 +1,14 @@
|
||||
#
|
||||
# VARIABLES/MACROS
|
||||
#
|
||||
CFLAGS= -Wfatal-errors -Wall -Wextra
|
||||
LDFLAGS= -s -no-pie -z noexecstack
|
||||
NASMFLAGS=-Fdwarf -felf64
|
||||
OBJS= str.o tok.o vec.o lex.o pnode.o reg.o mem.o state.o err.o x86_64.o run.o ir.o gen.o
|
||||
LIB= libpar.a
|
||||
CFLAGS= -Wfatal-errors -Wall -Wextra
|
||||
LDFLAGS= -g -no-pie -z noexecstack -lm
|
||||
NASMFLAGS= -Fdwarf -felf64
|
||||
OBJS= str.o tok.o vec.o lex.o pnode.o reg.o mem.o state.o err.o x86_64.o run.o ir.o gen.o
|
||||
LIB= libpar.a
|
||||
TESTS_x86_64= $(notdir $(basename $(shell find tests/x86_64/ -name '*.par')))
|
||||
PAR= ./par
|
||||
PAR= ./par
|
||||
VALGRIND= valgrind --log-file=$(@D)/valgrind.$*
|
||||
|
||||
#
|
||||
# MAIN TARGETS
|
||||
@ -20,7 +21,7 @@ version.h:
|
||||
./update_ver.sh
|
||||
par: version.h main.o libpar.a
|
||||
$(CC) $(filter-out %.h, $^) -o $@ $(LDFLAGS)
|
||||
tests: $(addprefix tests/bin/, $(TESTS_x86_64)) FORCE
|
||||
tests: $(addprefix tests/bin/, $(TESTS_x86_64)) tests/bin FORCE
|
||||
./tests/dotests.sh tests
|
||||
|
||||
#
|
||||
@ -28,9 +29,10 @@ tests: $(addprefix tests/bin/, $(TESTS_x86_64)) FORCE
|
||||
#
|
||||
%.o: %.c %.h
|
||||
$(CC) $< -c $(CFLAGS)
|
||||
tests/bin:
|
||||
@mkdir tests/bin
|
||||
tests/bin/%.asm: tests/x86_64/%.par
|
||||
@[ -d tests/bin ] || mkdir tests/bin
|
||||
$(PAR) -m x86_64 -o $@ $^
|
||||
$(VALGRIND) $(PAR) -m x86_64 -o $@ $<
|
||||
%.asm: %.par
|
||||
$(PAR) $<
|
||||
%.o: %.asm
|
||||
|
4
gen.c
4
gen.c
@ -4,11 +4,11 @@ Gen gen_new(void)
|
||||
{
|
||||
Gen gen;
|
||||
gen.labelno=0;
|
||||
gen.vars=vec_new(sizeof(Var));
|
||||
gen.var_desc=vec_new(sizeof(Var));
|
||||
return gen;
|
||||
}
|
||||
|
||||
void gen_free(Gen*gen)
|
||||
{
|
||||
vec_free(&gen->vars);
|
||||
vec_free(&gen->var_desc);
|
||||
}
|
||||
|
2
gen.h
2
gen.h
@ -10,7 +10,7 @@
|
||||
typedef struct Gen
|
||||
{
|
||||
size_t labelno;
|
||||
Vec vars; //Vec<Var>
|
||||
Vec var_desc;
|
||||
} Gen;
|
||||
|
||||
Gen gen_new(void);
|
||||
|
8
main.c
8
main.c
@ -27,7 +27,7 @@ int main(int argc,char**argv)
|
||||
// Ensure cleanup is called
|
||||
signal(SIGINT,sighandle);
|
||||
|
||||
// Determine string to lex/parse
|
||||
// Parse arguments
|
||||
for(int i=1;i<argc;i+=1+skip_arg)
|
||||
{
|
||||
if(!argv[i][0])continue;
|
||||
@ -136,7 +136,7 @@ int main(int argc,char**argv)
|
||||
vec_push(&args,argv+i);
|
||||
}
|
||||
|
||||
// Each file in vector
|
||||
// Iterate over input files
|
||||
for(size_t i=0;i<args.size;++i)
|
||||
{
|
||||
state=state_new();
|
||||
@ -164,7 +164,7 @@ int main(int argc,char**argv)
|
||||
fclose(state.infile);
|
||||
}
|
||||
|
||||
// Lex --> Parse --> Print
|
||||
// Lex, Parse
|
||||
if(state.input_buffer.buffer)
|
||||
{
|
||||
lex_string(&state.lexer,state.input_buffer.buffer);
|
||||
@ -183,7 +183,7 @@ int main(int argc,char**argv)
|
||||
}
|
||||
}
|
||||
|
||||
// Code generator
|
||||
// Generate code
|
||||
if(generate)
|
||||
{
|
||||
state_set_outfile(&state,((char**)args.buffer)[i],setoutfile,setoutfile_name,buildarch);
|
||||
|
6
state.c
6
state.c
@ -3,9 +3,13 @@
|
||||
#include"state.h"
|
||||
#include"err.h"
|
||||
|
||||
// State is global precisely because
|
||||
// signal() cannot pass user data,
|
||||
// and we need it to abort/quit
|
||||
// cleanly.
|
||||
State state;
|
||||
|
||||
void cleanquit(int exitval)
|
||||
inline void cleanquit(int exitval)
|
||||
{
|
||||
state_free(&state);
|
||||
exit(exitval);
|
||||
|
Loading…
Reference in New Issue
Block a user