19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
let f=x=>{
if(x.startsWith("const standard_message_names=")) f=do_message_names;
};
names_file.forEach(x=>f(x)); // not .forEach(f); the function to use varies
let curnum=0;
const names=Object.create(null);
data_file.forEach((line,linenum)=>{
const reg=/^[ \t]*([-,=!+*#]*)[ \t]*([A-Za-z0-9_]+)?[ \t]*(?:"([^" \t]+)")?[ \t]*(?:\(([0-9A-Fa-f]+)\))?[ \t]*(?:;.*)?$/.exec(line);
if(!reg) throw "Syntax error on line "+(linenum+1);
let flags=0;
if(reg[1].includes(",")) flags|=1;
if(reg[1].includes("=")) flags|=2;
if(reg[1].includes("-")) flags|=4;
if(reg[1].includes("!")) flags|=8;
if(reg[1].includes("+")) flags|=16;
if(reg[4]) curnum=parseInt(reg[4],16);
if(reg[2] && !reg[1].includes("#")) {
console.log("#define OP_"+reg[2].toUpperCase()+" "+curnum);
if(flags&1) console.log("#define OP_"+reg[2].toUpperCase()+"_C "+(curnum+0x0800));
if(flags&2) console.log("#define OP_"+reg[2].toUpperCase()+"_E "+(curnum+0x1000));
if(3==(flags&3)) console.log("#define OP_"+reg[2].toUpperCase()+"_EC "+(curnum+0x1800));
if(10==(flags&10)) {
if(flags&1) console.log("#define OP_"+reg[2].toUpperCase()+"_EC16 "+(curnum+0x0801));
console.log("#define OP_"+reg[2].toUpperCase()+"_E16 "+(curnum+0x1001));
}
}
if(reg[2] && !reg[1].includes("*")) names[reg[3]||reg[2]]=curnum|(flags<<16);
if(reg[2]) ++curnum;
if(flags&8) ++curnum;
});
console.log("#ifdef HEROMESH_CLASS\nstatic const Op_Names op_names[]={");
Object.keys(names).sort().forEach(x=>console.log("{\""+x+"\","+names[x]+"},"));
|
|
|
>
>
>
>
>
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
let f=x=>{
if(x.startsWith("const standard_message_names=")) f=do_message_names;
};
names_file.forEach(x=>f(x)); // not .forEach(f); the function to use varies
let curnum=0;
const names=Object.create(null);
data_file.forEach((line,linenum)=>{
const reg=/^[ \t]*([-,=!+*#.]*)[ \t]*([A-Za-z0-9_]+)?[ \t]*(?:"([^" \t]+)")?[ \t]*(?:\(([0-9A-Fa-f]+)\))?[ \t]*(?:;.*)?$/.exec(line);
if(!reg) throw "Syntax error on line "+(linenum+1);
let flags=128;
if(reg[1].includes(",")) flags|=1;
if(reg[1].includes("=")) flags|=2;
if(reg[1].includes("-")) flags|=4;
if(reg[1].includes("!")) flags|=8;
if(reg[1].includes("+")) flags|=16;
if(reg[1].includes(".")) flags|=32;
if(reg[4]) curnum=parseInt(reg[4],16);
if(reg[2] && !reg[1].includes("#")) {
console.log("#define OP_"+reg[2].toUpperCase()+" "+curnum);
if(flags&1) console.log("#define OP_"+reg[2].toUpperCase()+"_C "+(curnum+0x0800));
if(flags&2) console.log("#define OP_"+reg[2].toUpperCase()+"_E "+(curnum+0x1000));
if(3==(flags&3)) console.log("#define OP_"+reg[2].toUpperCase()+"_EC "+(curnum+0x1800));
if(10==(flags&10)) {
if(flags&1) console.log("#define OP_"+reg[2].toUpperCase()+"_EC16 "+(curnum+0x0801));
console.log("#define OP_"+reg[2].toUpperCase()+"_E16 "+(curnum+0x1001));
}
if(flags&32) {
console.log("#define OP_"+reg[2].toUpperCase()+"_D "+(curnum+0x2000));
if(flags&1) console.log("#define OP_"+reg[2].toUpperCase()+"_CD "+(curnum+0x2800));
}
}
if(reg[2] && !reg[1].includes("*")) names[reg[3]||reg[2]]=curnum|(flags<<16);
if(reg[2]) ++curnum;
if(flags&8) ++curnum;
});
console.log("#ifdef HEROMESH_CLASS\nstatic const Op_Names op_names[]={");
Object.keys(names).sort().forEach(x=>console.log("{\""+x+"\","+names[x]+"},"));
|