Last active
December 4, 2015 18:24
-
-
Save mochja/eac408065eb34ee1793c to your computer and use it in GitHub Desktop.
Instruction generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSTR_T create_{{ iname }}_{{ ptype }}_instr(const int a, const int b) { | |
instruction_t *i = calloc(1, sizeof(instruction_t)); | |
i->type = I_{{ iname }}; | |
ZVAL_INIT_INT(i->first, a); | |
ZVAL_INIT_INT(i->second, b); | |
return i; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from jinja2 import Template | |
f = open('templ.jinja', 'r') | |
template = Template(f.read()) | |
types = [['X'], ['X', 'X'], ['X', 'offset'], ['offset', 'X'], ['offset']] | |
t2 = ['I', 'D'] | |
instr = [ | |
['ADD', '+'], | |
['SUB', '-'], | |
['MUL', '*'], | |
['DIV', '/'] | |
] | |
for i in instr: | |
for t in t2: | |
for pt in types: | |
print template.render(iname = i[0] + t, iop = i[1], ptype = "_".join(pt.replace('X', t2 == 'I' ? 'int' : 'double'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment