source: proto/s2k/trunk/framework/src/toolchain/b2k/lang/paramBuiltin/idisa/IDISABuiltinsTranslator.java @ 4109

Last change on this file since 4109 was 4109, checked in by ksherdy, 5 years ago

s2k sk to b2k IDISA translation support.

File size: 1.8 KB
Line 
1package toolchain.b2k.lang.paramBuiltin.idisa;
2
3import java.util.List;
4
5import toolchain.b2k.ast.Generators;
6import toolchain.b2k.lang.paramBuiltin.idisa.IDISABuiltin;
7import b2k.ast.ASTNode;
8import b2k.ast.FieldWidthNode;
9import b2k.inputHandler.Locator;
10
11
12//Translate s2k builtin calls from s2k to b2k.
13//Command Pattern implementation, with the benefit that the
14//client does not instantiate the commands.
15
16public enum IDISABuiltinsTranslator {
17 
18    PACK_TRANSLATION { 
19        public ASTNode translate(IDISABuiltin idisaBuiltin, s2k.ast.IdisaFuncCallNode snode, FieldWidthNode fieldWidth, List<ASTNode> args) {
20           
21            Locator locator = Generators.makeToken(snode.getToken());
22            ASTNode clone = args.get(0).deepCopy();
23            args.add(clone);
24            return Generators.makeIdisaFuncCallNode(locator, idisaBuiltin, fieldWidth, arrayFromList(args));
25        }
26    },
27
28    IDENTITY_TRANSLATION {
29        public ASTNode translate(IDISABuiltin idisaBuiltin, s2k.ast.IdisaFuncCallNode snode, FieldWidthNode fieldWidth, List<ASTNode> args) {
30           
31            Locator locator = Generators.makeToken(snode.getToken());
32            return Generators.makeIdisaFuncCallNode(locator, idisaBuiltin, fieldWidth, arrayFromList(args));
33        }
34    },
35
36    NULL_TRANSLATION {
37    @SuppressWarnings("unused")
38        public ASTNode translate() {
39            throw new RuntimeException("B2K builtin translation not unimplemented.");
40    }
41};
42 
43     // Interface
44    public ASTNode translate(IDISABuiltin idisaBuiltin, s2k.ast.IdisaFuncCallNode snode, FieldWidthNode fieldWidthNode, List<ASTNode> args) {
45        assert false : "Translation not implemented for: " + this.name();
46        return null;
47    }
48
49    private static ASTNode[] arrayFromList(List<ASTNode> list) {
50        return list.toArray(new ASTNode [list.size()]);
51    }
52}
53 
Note: See TracBrowser for help on using the repository browser.