Skip to content

Instantly share code, notes, and snippets.

@mochja
Last active December 4, 2015 18:24
Show Gist options
  • Save mochja/eac408065eb34ee1793c to your computer and use it in GitHub Desktop.
Save mochja/eac408065eb34ee1793c to your computer and use it in GitHub Desktop.
Instruction generator
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;
}
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