Generation Error Mitigation #4

Merged
aCompetentBean merged 3 commits from ayrton/generation-errors into main 2023-11-24 15:47:48 -07:00
5 changed files with 66 additions and 11 deletions
Showing only changes of commit 1c91f6ac86 - Show all commits

View file

@ -156,6 +156,8 @@ class AstGenerator:
self.generate_return(return_type=return_type, return_value=return_value)
if self.settings['generation-options']['generate-dead-code']:
self.generate_statements(exclude='declaration')
self.print_all_current_scope_vars()
self.pop_scope()
self.current_ast_element = parent
@ -643,7 +645,7 @@ class AstGenerator:
self.comp_op_numline,
self.comp_op_cutoffs,
self.comp_op_options,
comparison=True)
comparison=True) #, evals=self.get_truth())
def push_scope(self, xml_element: ET.Element = None):
scope = Scope(self.current_scope)
@ -899,3 +901,25 @@ class AstGenerator:
self.generate_binary(op, random.choice([GAZ_INT_KEY, GAZ_FLOAT_KEY]))
else:
self.generate_binary(op, random.choice(expr_type))
def print_all_current_scope_vars(self):
for key, value in self.current_scope.symbols.items():
if isinstance(value, Variable):
self.print_variable(value)
def print_variable(self, var: Variable):
"""
@brief generate an outstream for a variable
@param var: the variable to print
@return:
"""
parent = self.current_ast_element
args = [
("type", GAZ_OUT_STREAM),
]
self.make_element(GAZ_STREAM_TAG, args)
self.current_ast_element.append(var.xml)
self.current_ast_element = parent

View file

@ -9,7 +9,7 @@ generation-options:
max-globals: 5 # maximum number of global variables
properties:
max-range-length: 5 # maximum length of ranges, vectors and tuples, (AxA matrices can exist)
use-english-words: True # use english words instead of random names (this may limit the maximum number of names)
use-english-words: True # use english words instead of random names (if we run out, we switch to random)
id-length: # length of identifiers
min: 1
max: 5
@ -68,12 +68,12 @@ statement-weights: # set to 0 for any statements y
in-stream: 5
type-weights:
value-types:
integer: 50
real: 50
boolean: 50
character: 50
void: 10
atomic-types:
int: 50 # TODO change these to the gaz types
float: 50
bool: 50
char: 50
void: 0 # TODO add support for void
composite-types:
vector: 20
tuple: 5
@ -90,6 +90,9 @@ misc-weights:
type-qualifier-weights:
const: 10
var: 60
conditional-eval:
true: 50
false: 50
block-termination-probability: 0.2 # probability for a block to terminate

View file

@ -309,6 +309,22 @@ class TestGeneration(unittest.TestCase):
return res
def test_print_all_current_scope_vars(self):
self.ast_gen.ast = ET.Element("block")
self.ast_gen.current_ast_element = self.ast_gen.ast
self.ast_gen.generate_declaration(mut='var')
self.ast_gen.generate_declaration(mut='var')
self.ast_gen.generate_declaration(mut='var')
self.ast_gen.generate_declaration(mut='var')
self.ast_gen.print_all_current_scope_vars()
print(ET.tostring(self.ast_gen.ast))
streams = self.ast_gen.ast.findall("stream")
self.assertEqual(4, len(streams))
def write_ast(self):
dom = xml.dom.minidom.parseString(ET.tostring(self.ast_gen.ast).decode('utf-8'))
pretty: str = dom.toprettyxml()

View file

@ -28,6 +28,11 @@ class GazpreaFuzzer:
self.ground_truth = None
self.out = None
try:
os.makedirs('debug/ast')
except FileExistsError:
pass
def fuzz(self):
self.generator.generate_ast()
self.write_ast() # FIXME sometimes this is none

View file

@ -61,6 +61,7 @@ class Fuzzer():
pass
i = 0
min_i = 0
while i < self.batch:
try:
self.fuzzer.fuzz()
@ -71,8 +72,10 @@ class Fuzzer():
"".format(r))
with open(f"{fuzzer_asterr}/{r}.xml", 'w') as f:
f.write(xml.dom.minidom.parseString(ET.tostring(self.fuzzer.ast).decode('utf-8')).toprettyxml())
i -= 1
if i - 1 >= min_i:
i -= 1
else:
i = min_i
continue
dom = xml.dom.minidom.parseString(ET.tostring(self.fuzzer.ast).decode('utf-8'))
pretty: str = dom.toprettyxml()
@ -89,7 +92,10 @@ class Fuzzer():
os.system("rm -f {}/{}_{}.py".format(fuzzer_ground_truth, self.file_name, i))
os.system("rm -f {}/{}_{}.py".format(fuzzer_outputs, self.file_name, i))
warnings.warn("Runtime error encountered, retrying")
i -= 1
if i - 1 >= min_i:
i -= 1
else:
i = min_i
continue
except KeyboardInterrupt:
r = random.randint(0, 1000000)
@ -109,6 +115,7 @@ class Fuzzer():
# with open("fuzzer/outputs/{}.out".format(i), 'w') as f:
# f.write(self.fuzzer.out)
i += 1
min_i = i
if __name__ == '__main__':