Whoopsie, found segfault
This commit is contained in:
parent
e1f2ff1824
commit
d2cad703b1
3
.gitignore
vendored
3
.gitignore
vendored
@ -13,4 +13,5 @@ vgcore.*
|
||||
*_TEMPLATE.png
|
||||
/out
|
||||
GRAPH*.gv
|
||||
GRAPH*.png
|
||||
GRAPH*.png
|
||||
SICK_JOKE*
|
||||
|
||||
2
Makefile
2
Makefile
@ -10,7 +10,7 @@ HEADERS_src_l2 := $(HEADERS_gen_l1_5) $(call find_headers,l2)
|
||||
HEADERS_gen_l2 := $(HEADERS_src_l2) gen/l2/dorothy.txt
|
||||
|
||||
cflags := -Wall -Wextra -Werror=implicit-function-declaration -Werror=return-type -Wno-unused-parameter \
|
||||
--std=c99 -g -ggdb -O0 \
|
||||
--std=c99 -g -ggdb -O3 \
|
||||
-fno-trapping-math -D_POSIX_C_SOURCE=200112L -D_GNU_SOURCE
|
||||
cc := gcc
|
||||
|
||||
|
||||
@ -108,7 +108,7 @@ def parse_second_quoted_path(s):
|
||||
|
||||
return s[start:p.index]
|
||||
|
||||
def analyze_file(lines_dirty) -> List[LineToken]:
|
||||
def analyze_file(lines_dirty, alien_headers: Set[str]) -> List[LineToken]:
|
||||
lines = list(map(lambda x: x.rstrip(), lines_dirty))
|
||||
i = 0
|
||||
tokens = []
|
||||
@ -130,7 +130,7 @@ def analyze_file(lines_dirty) -> List[LineToken]:
|
||||
|
||||
if directive == 'include':
|
||||
local_file = parse_second_quoted_path(line)
|
||||
if local_file is not None:
|
||||
if (local_file is not None) and (local_file not in alien_headers):
|
||||
tokens.append(LineToken(type = token_type_include_local, filepath=local_file,
|
||||
original=original_lines))
|
||||
else:
|
||||
@ -165,7 +165,7 @@ def analyze_file(lines_dirty) -> List[LineToken]:
|
||||
|
||||
# Returns new_i, block (text + new_symbol_set)
|
||||
def process_part_of_file(tokens: List[LineToken], defined_symbols_outside: Set[str], i: int, input_dir,
|
||||
take_seriously: bool) -> Tuple[int, IfDirBlock]:
|
||||
take_seriously: bool, alien_headers: Set[str]) -> Tuple[int, IfDirBlock]:
|
||||
output = ""
|
||||
symbols_here = defined_symbols_outside.copy()
|
||||
|
||||
@ -212,7 +212,8 @@ def process_part_of_file(tokens: List[LineToken], defined_symbols_outside: Set[s
|
||||
token_type_elif, token_type_elifdef, token_type_elifndef, token_type_else]:
|
||||
i, block_in_front = process_part_of_file(tokens, symbols_here, i, input_dir,
|
||||
(saw_match == len(in_if) or (t in [token_type_if, token_type_elif]) or
|
||||
(t == token_type_else and saw_unevaluatable_condition)) and take_seriously)
|
||||
(t == token_type_else and saw_unevaluatable_condition)) and take_seriously,
|
||||
alien_headers)
|
||||
in_if.append(IfDirCondAndBlock(cond=token, inside=block_in_front))
|
||||
|
||||
if t == token_type_endif:
|
||||
@ -239,7 +240,7 @@ def process_part_of_file(tokens: List[LineToken], defined_symbols_outside: Set[s
|
||||
include_path = os.path.join(input_dir, token.filepath)
|
||||
if not os.path.isfile(include_path):
|
||||
raise ValueError(f"No such file {include_path}")
|
||||
included_output = process_file(include_path, symbols_here)
|
||||
included_output = process_file(include_path, symbols_here, alien_headers)
|
||||
output += included_output.text
|
||||
symbols_here = included_output.new_symbol_set
|
||||
else:
|
||||
@ -252,12 +253,12 @@ def process_part_of_file(tokens: List[LineToken], defined_symbols_outside: Set[s
|
||||
return i, IfDirBlock(text=output, new_symbol_set=symbols_here)
|
||||
|
||||
# Returns block (text + new_symbols)
|
||||
def process_file(file_path, symbols_here) -> IfDirBlock:
|
||||
def process_file(file_path, symbols_here: Set[str], alien_headers: Set[str]) -> IfDirBlock:
|
||||
input_dir = os.path.dirname(os.path.abspath(file_path))
|
||||
with open(file_path, 'r') as f:
|
||||
lines = f.readlines()
|
||||
tokens = analyze_file(lines)
|
||||
end_i, block = process_part_of_file(tokens, symbols_here, 0, input_dir, True)
|
||||
tokens = analyze_file(lines, alien_headers)
|
||||
end_i, block = process_part_of_file(tokens, symbols_here, 0, input_dir, True, alien_headers)
|
||||
assert end_i == len(tokens)
|
||||
return block
|
||||
|
||||
@ -267,14 +268,15 @@ def main():
|
||||
parser.add_argument('input_file', type=str, help="Input C file path")
|
||||
parser.add_argument('output_file', type=str, help="Output C file path")
|
||||
parser.add_argument('-D', action='append', default=[], help="Define symbols")
|
||||
parser.add_argument('-I', action='append', default=[], help="Imaginary headers from the other side")
|
||||
|
||||
args = parser.parse_args()
|
||||
defined_symbols = set(args.D)
|
||||
alien_headers = set(args.I)
|
||||
|
||||
entire_program = process_file(args.input_file, defined_symbols)
|
||||
entire_program = process_file(args.input_file, defined_symbols, alien_headers)
|
||||
with open(args.output_file, 'w') as f:
|
||||
f.write(entire_program.text)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
#define PROTOTYPE1_SRC_L2_MARIE_GRAPHICS_GEOM_H
|
||||
|
||||
#include "../../../gen/l1/geom.h"
|
||||
#include "math.h"
|
||||
#include <math.h>
|
||||
|
||||
mat4 marie_translation_mat4(vec3 vec) {
|
||||
return mat4_new(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user