12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package IntermediaryCode;
- import java.util.HashMap;
- import templates.FunctionInterface;
- /**
- *
- * @author EUGENIO CARVALHO
- */
- public class IRTemplate implements templates.TemplateDescription {
- public HashMap<String, String> Formats() throws Exception {
- return new HashMap<String, String>() {
- {
- String base = "{[PAD(global.position,G.addressLen,' ')]':'}"
- + "{[T(1)]}"
- + "{[PAD(block.position,G.addressLen,' ')]':'}"
- + "{[T(2)]}";
- String end = " {' --'[comment]}"
- + "{[T(2)]}"
- + "{' T< '[type]' >'} "
- + "{[T(2)]}"
- + "{[basicBlock]}";
- put("label", "{[PAD(global.position,G.addressLen,' ')]':'}{[T(2)]}{'<'[label]'>'}':'");
- put("assign", base + "{[dst]}' := '{[TYPE('p1')]' '}{[p1]' '}{[op]' '}{[TYPE('p2')]' '}{[p2]}" + end);
- put("pointer_assign", base + "{[dst.pointer]}{[dst]' := '}{[op]' '}{[TYPE('p1')]' '}{[p1]}" + end);
- put("unary", base + " {[dst]} ' := '{[op]' '}{[TYPE('p1')]' '}{[p1]}" + end);
- put("copy", base + " {[dst]} ' := '{[TYPE('p1')]' '}{[p1]}" + end);
- put("memory", base + " {[type]' '}{[TYPE('p1')]' '}{[p1]}" + end);
- put("jump", base + " 'goto ' {'<'[label]'>'}" + end);
- put("branch", base + " 'if '{[TYPE('p1')]' '}{[p1]} {' '[op]' '}{[TYPE('p2')]' '}{[p2]} ' goto ' {'<'[label]'>'}" + end);
- // put("call", base + " {[dst]' := '} 'call <' {[funcname]} '>, ' {[nump]}" + end);
- put("call", base + "'call <' {[funcname]} '>, ' {[nump]}" + end);
- put("return", base + " 'return '{[TYPE('p1')]' '}{[p1]}" + end);
- put("push_param", base + " 'push_param '{[TYPE('p1')]' '}{[p1]}" + end);
- put("push_return", base + " 'push_return '{[TYPE('p1')]' '}{[p1]}" + end);
- put("pop_param", base + " 'pop_param '{[TYPE('p1')]' '}{[p1]}" + end);
- put("pop_return", base + " 'pop_return '{[TYPE('p1')]' '}{[p1]}" + end);
- }
- };
- }
- public HashMap<String, String> aliases = new HashMap<String, String>() {
- {
- put("char", "i8");
- put("bool", "i8");
- put("byte", "i8");
- put("int8", "i8");
- put("int16", "i16");
- put("int32", "i32");
- put("int64", "i64");
- put("float32", "f32");
- put("float64", "f64");
- }
- };
- public HashMap<String, FunctionInterface> Functions() throws Exception {
- return new HashMap<String, FunctionInterface>() {
- {
- put("TYPE", (ctx, args) -> {
- String attr = args.get(0) + ".type";
- if (!ctx.Has(attr)) {
- return "";
- }
- String type = ctx.Get(attr);
- if (!aliases.containsKey(type)) {
- throw new Exception(String.format("Nenhum alias foi definido para o tipo '%s'", type));
- }
- return "(" + aliases.get(type) + ")";
- });
- }
- };
- }
- }
|