From dd5e69d2f7b191ee93e137708feeed74d321b069 Mon Sep 17 00:00:00 2001 From: chentianya Date: Tue, 25 Aug 2026 19:59:24 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B6=E6=AE=B52-1=EF=BC=9Amachine.toml=20?= =?UTF-8?q?=E9=87=8D=E5=86=99=E4=B8=BA=20V2=20schema=EF=BC=8819=20type=20+?= =?UTF-8?q?=2068=20op=20+=2014=20fb=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - type 表:19 条 IEC 类型(base 基元 + kind 语义 + func 映射,TOD=func4 修正) - op 表:prefix+op 分区编码(4B RR 21 条/NONE 2 条、8B RRR 26 条/010 区 8 条、 16B SLOT+off 8 条/IMM64 1 条、32B 预留 6 条)+ fmt + func 类别 (none/width/uint/full/float/dst)+ params 互锁 - fb 表:14 条(fb_id 0..14,含 SR/RS/PWM/RTC 字段,字段类型命中 type 表) - 注:MachineConfig 仍为 V1 解析,下一步同步(machine_test 暂红预期内) --- compiler/machine.toml | 948 ++++++++++++++++++++++++++++++++---------- 1 file changed, 737 insertions(+), 211 deletions(-) diff --git a/compiler/machine.toml b/compiler/machine.toml index 1145146..a6dd199 100644 --- a/compiler/machine.toml +++ b/compiler/machine.toml @@ -1,342 +1,868 @@ -# 机器定义:指令集与类型的唯一事实来源(只给编译器) -# 格式见 Doc/isa/指令配置.md;全属性必填,与代码强校验一致。 +# 机器定义:指令集与类型的唯一事实来源(V2,STATOR2) +# schema 见 Doc/isa/指令配置.md;全属性必填,与代码强校验一致。 +# V2 变更:op 用 prefix+op(分区内编号);func 类别表达数据语义; +# 类型 19 条(base 基元 + kind 语义 + func 映射);FB 14 条(fb_id 0..14)。 [meta] name = "STATOR" # 型号名(参与 .stb 型号标识[32]) -version = 1 # 指令集版本(参与 .stb 型号标识[32]) +version = 2 # 格式版本(型号标识 = "STATOR2";V1 = 1) -# ---- 类型:编译器内建基元(bit/int8/int16/int32/int64/uint8/uint16/uint32/uint64/float32/float64) -# 配置类型 = 基元别名(+ 值域约束 + .stb 契约 tag) +# ---- 类型:19 种 IEC 类型(V2) +# base = 编译器内建基元(bit/int8/int16/int32/int64/uint8/uint16/uint32/uint64/float32/float64) +# kind = 语言语义(bool/bit/int/uint/float/time/date)——同 func 不同 kind 区分 +# func = type 位段值(0..9),与 base 的 (width, signed) 互锁强校验 [[type]] name = "BOOL" base = "uint8" -range = [0, 1] # 值域约束:只允许 0/1 -tag = 0 +kind = "bool" +func = 0 + +[[type]] +name = "BYTE" +base = "uint8" +kind = "bit" +func = 0 + +[[type]] +name = "WORD" +base = "uint16" +kind = "bit" +func = 2 + +[[type]] +name = "DWORD" +base = "uint32" +kind = "bit" +func = 4 + +[[type]] +name = "LWORD" +base = "uint64" +kind = "bit" +func = 6 + +[[type]] +name = "SINT" +base = "int8" +kind = "int" +func = 1 [[type]] name = "INT" base = "int16" -tag = 1 +kind = "int" +func = 3 + +[[type]] +name = "DINT" +base = "int32" +kind = "int" +func = 5 + +[[type]] +name = "LINT" +base = "int64" +kind = "int" +func = 7 + +[[type]] +name = "USINT" +base = "uint8" +kind = "uint" +func = 0 + +[[type]] +name = "UINT" +base = "uint16" +kind = "uint" +func = 2 + +[[type]] +name = "UDINT" +base = "uint32" +kind = "uint" +func = 4 + +[[type]] +name = "ULINT" +base = "uint64" +kind = "uint" +func = 6 [[type]] name = "TIME" base = "int64" -tag = 2 +kind = "time" +func = 7 -# ---- 指令(全属性必填;class: plain/instance;format: RR/RRR/IMM/SLOT/JMP/JC/CALL/CAL/NONE) +[[type]] +name = "REAL" +base = "float32" +kind = "float" +func = 8 +[[type]] +name = "LREAL" +base = "float64" +kind = "float" +func = 9 + +[[type]] +name = "DATE" +base = "uint32" +kind = "date" +func = 4 + +[[type]] +name = "TOD" +base = "uint32" +kind = "date" +func = 4 + +[[type]] +name = "DT" +base = "uint64" +kind = "date" +func = 6 + +# ---- 指令(V2:prefix + op + fmt + func 类别,全属性必填) +# prefix:形态前缀(11/10/011/010000..010101/0010/0011/0001) +# op:分区内编号(0 起);fmt:操作数形态;func:数据语义类别 +# (none=无类型 / width=宽度 0..3 / uint=无符号宽度 0/2/4/6 / +# full=全矩阵 0..9 / float=浮点 8/9 / dst=目标类型 0..9) +# params:参数名(与 fmt 互锁,见指令配置.md 强校验) + +# ---- 4B RR(前缀 11,op 6 位) [[op]] name = "MOVE" -opcode = 0 -class = "plain" -format = "RR" +prefix = "11" +op = 0 +fmt = "RR" +func = "width" params = ["rd", "rs"] enabled = true -[[op]] -name = "LOADK" -opcode = 1 -class = "plain" -format = "IMM" -params = ["rd", "const_id"] -enabled = true - [[op]] name = "NOT" -opcode = 2 -class = "plain" -format = "RR" +prefix = "11" +op = 1 +fmt = "RR" +func = "uint" params = ["rd", "rs"] enabled = true [[op]] -name = "AND" -opcode = 3 -class = "plain" -format = "RRR" -params = ["rd", "ra", "rb"] +name = "NEG" +prefix = "11" +op = 2 +fmt = "RR" +func = "full" +params = ["rd", "rs"] enabled = true [[op]] -name = "OR" -opcode = 4 -class = "plain" -format = "RRR" -params = ["rd", "ra", "rb"] +name = "ABS" +prefix = "11" +op = 3 +fmt = "RR" +func = "full" +params = ["rd", "rs"] enabled = true +[[op]] +name = "INC" +prefix = "11" +op = 4 +fmt = "RR" +func = "full" +params = ["rd", "rs"] +enabled = true + +[[op]] +name = "DEC" +prefix = "11" +op = 5 +fmt = "RR" +func = "full" +params = ["rd", "rs"] +enabled = true + +[[op]] +name = "SQRT" +prefix = "11" +op = 6 +fmt = "RR" +func = "float" +params = ["rd", "rs"] +enabled = true + +[[op]] +name = "SIN" +prefix = "11" +op = 7 +fmt = "RR" +func = "float" +params = ["rd", "rs"] +enabled = true + +[[op]] +name = "COS" +prefix = "11" +op = 8 +fmt = "RR" +func = "float" +params = ["rd", "rs"] +enabled = true + +[[op]] +name = "TAN" +prefix = "11" +op = 9 +fmt = "RR" +func = "float" +params = ["rd", "rs"] +enabled = true + +[[op]] +name = "ASIN" +prefix = "11" +op = 10 +fmt = "RR" +func = "float" +params = ["rd", "rs"] +enabled = true + +[[op]] +name = "ACOS" +prefix = "11" +op = 11 +fmt = "RR" +func = "float" +params = ["rd", "rs"] +enabled = true + +[[op]] +name = "ATAN" +prefix = "11" +op = 12 +fmt = "RR" +func = "float" +params = ["rd", "rs"] +enabled = true + +[[op]] +name = "LN" +prefix = "11" +op = 13 +fmt = "RR" +func = "float" +params = ["rd", "rs"] +enabled = true + +[[op]] +name = "LOG" +prefix = "11" +op = 14 +fmt = "RR" +func = "float" +params = ["rd", "rs"] +enabled = true + +[[op]] +name = "EXP" +prefix = "11" +op = 15 +fmt = "RR" +func = "float" +params = ["rd", "rs"] +enabled = true + +[[op]] +name = "ROUND" +prefix = "11" +op = 16 +fmt = "RR" +func = "float" +params = ["rd", "rs"] +enabled = true + +[[op]] +name = "TRUNC" +prefix = "11" +op = 17 +fmt = "RR" +func = "float" +params = ["rd", "rs"] +enabled = true + +[[op]] +name = "FLOOR" +prefix = "11" +op = 18 +fmt = "RR" +func = "float" +params = ["rd", "rs"] +enabled = true + +[[op]] +name = "CEIL" +prefix = "11" +op = 19 +fmt = "RR" +func = "float" +params = ["rd", "rs"] +enabled = true + +[[op]] +name = "CONV" +prefix = "11" +op = 20 +fmt = "RR" +func = "dst" +params = ["rd", "rs"] +enabled = true + +# ---- 4B NONE(前缀 10,op 6 位) +[[op]] +name = "NOP" +prefix = "10" +op = 0 +fmt = "NONE" +func = "none" +params = [] +enabled = true + +[[op]] +name = "RET" +prefix = "10" +op = 1 +fmt = "NONE" +func = "none" +params = [] +enabled = true + +# ---- 8B RRR(前缀 011,op 5 位) [[op]] name = "ADD" -opcode = 5 -class = "plain" -format = "RRR" +prefix = "011" +op = 0 +fmt = "RRR" +func = "full" params = ["rd", "ra", "rb"] enabled = true [[op]] name = "SUB" -opcode = 6 -class = "plain" -format = "RRR" +prefix = "011" +op = 1 +fmt = "RRR" +func = "full" params = ["rd", "ra", "rb"] enabled = true [[op]] name = "MUL" -opcode = 7 -class = "plain" -format = "RRR" +prefix = "011" +op = 2 +fmt = "RRR" +func = "full" params = ["rd", "ra", "rb"] enabled = true [[op]] name = "DIV" -opcode = 8 -class = "plain" -format = "RRR" +prefix = "011" +op = 3 +fmt = "RRR" +func = "full" params = ["rd", "ra", "rb"] enabled = true +[[op]] +name = "MOD" +prefix = "011" +op = 4 +fmt = "RRR" +func = "full" +params = ["rd", "ra", "rb"] +enabled = true + +[[op]] +name = "EXPT" +prefix = "011" +op = 5 +fmt = "RRR" +func = "full" +params = ["rd", "ra", "rb"] +enabled = true + +[[op]] +name = "AND" +prefix = "011" +op = 6 +fmt = "RRR" +func = "uint" +params = ["rd", "ra", "rb"] +enabled = true + +[[op]] +name = "OR" +prefix = "011" +op = 7 +fmt = "RRR" +func = "uint" +params = ["rd", "ra", "rb"] +enabled = true + +[[op]] +name = "XOR" +prefix = "011" +op = 8 +fmt = "RRR" +func = "uint" +params = ["rd", "ra", "rb"] +enabled = true + +[[op]] +name = "NAND" +prefix = "011" +op = 9 +fmt = "RRR" +func = "uint" +params = ["rd", "ra", "rb"] +enabled = true + +[[op]] +name = "NOR" +prefix = "011" +op = 10 +fmt = "RRR" +func = "uint" +params = ["rd", "ra", "rb"] +enabled = true + +[[op]] +name = "XNOR" +prefix = "011" +op = 11 +fmt = "RRR" +func = "uint" +params = ["rd", "ra", "rb"] +enabled = true + +[[op]] +name = "SHL" +prefix = "011" +op = 12 +fmt = "RRR" +func = "uint" +params = ["rd", "rs", "n"] +enabled = true + +[[op]] +name = "SHR" +prefix = "011" +op = 13 +fmt = "RRR" +func = "full" +params = ["rd", "rs", "n"] +enabled = true + +[[op]] +name = "ROL" +prefix = "011" +op = 14 +fmt = "RRR" +func = "uint" +params = ["rd", "rs", "n"] +enabled = true + +[[op]] +name = "ROR" +prefix = "011" +op = 15 +fmt = "RRR" +func = "uint" +params = ["rd", "rs", "n"] +enabled = true + [[op]] name = "CMP_EQ" -opcode = 9 -class = "plain" -format = "RRR" +prefix = "011" +op = 16 +fmt = "RRR" +func = "full" params = ["rd", "ra", "rb"] enabled = true [[op]] name = "CMP_NE" -opcode = 10 -class = "plain" -format = "RRR" +prefix = "011" +op = 17 +fmt = "RRR" +func = "full" params = ["rd", "ra", "rb"] enabled = true [[op]] name = "CMP_LT" -opcode = 11 -class = "plain" -format = "RRR" +prefix = "011" +op = 18 +fmt = "RRR" +func = "full" params = ["rd", "ra", "rb"] enabled = true [[op]] name = "CMP_LE" -opcode = 12 -class = "plain" -format = "RRR" +prefix = "011" +op = 19 +fmt = "RRR" +func = "full" params = ["rd", "ra", "rb"] enabled = true [[op]] name = "CMP_GT" -opcode = 13 -class = "plain" -format = "RRR" +prefix = "011" +op = 20 +fmt = "RRR" +func = "full" params = ["rd", "ra", "rb"] enabled = true [[op]] name = "CMP_GE" -opcode = 14 -class = "plain" -format = "RRR" +prefix = "011" +op = 21 +fmt = "RRR" +func = "full" params = ["rd", "ra", "rb"] enabled = true +[[op]] +name = "GETBIT" +prefix = "011" +op = 22 +fmt = "RRR" +func = "none" +params = ["rd", "rs", "bit"] +enabled = true + +[[op]] +name = "SETBIT" +prefix = "011" +op = 23 +fmt = "RRR" +func = "none" +params = ["rd", "rs", "bit"] +enabled = true + +[[op]] +name = "CLRBIT" +prefix = "011" +op = 24 +fmt = "RRR" +func = "none" +params = ["rd", "rs", "bit"] +enabled = true + +[[op]] +name = "TOGBIT" +prefix = "011" +op = 25 +fmt = "RRR" +func = "none" +params = ["rd", "rs", "bit"] +enabled = true + +# ---- 8B 010 区(形态位 3 位 + 子 op 2 位) +[[op]] +name = "LOADK" +prefix = "010000" +op = 0 +fmt = "IMM" +func = "full" +params = ["rd", "const_id"] +enabled = true + +[[op]] +name = "LOAD" +prefix = "010001" +op = 0 +fmt = "SLOT" +func = "full" +params = ["rd", "slot"] +enabled = true + +[[op]] +name = "STORE" +prefix = "010001" +op = 1 +fmt = "SLOT" +func = "full" +params = ["slot", "rs"] +enabled = true + [[op]] name = "JMP" -opcode = 15 -class = "plain" -format = "JMP" +prefix = "010010" +op = 0 +fmt = "JMP" +func = "none" params = ["off"] enabled = true [[op]] name = "JT" -opcode = 16 -class = "plain" -format = "JC" -params = ["r", "off"] +prefix = "010011" +op = 0 +fmt = "JC" +func = "none" +params = ["rd", "off"] enabled = true [[op]] name = "JF" -opcode = 17 -class = "plain" -format = "JC" -params = ["r", "off"] -enabled = true - -[[op]] -name = "LOAD_I" -opcode = 18 -class = "plain" -format = "SLOT" -params = ["rd", "slot"] -enabled = true - -[[op]] -name = "STORE_Q" -opcode = 19 -class = "plain" -format = "SLOT" -params = ["rs", "slot"] -enabled = true - -[[op]] -name = "LOAD_M" -opcode = 20 -class = "plain" -format = "SLOT" -params = ["rd", "slot"] -enabled = true - -[[op]] -name = "STORE_M" -opcode = 21 -class = "plain" -format = "SLOT" -params = ["rs", "slot"] -enabled = true - -[[op]] -name = "LOAD_GLOBAL" -opcode = 22 -class = "plain" -format = "SLOT" -params = ["rd", "slot"] -enabled = true - -[[op]] -name = "STORE_GLOBAL" -opcode = 23 -class = "plain" -format = "SLOT" -params = ["rs", "slot"] -enabled = true - -[[op]] -name = "CAL_TON" -opcode = 24 -class = "instance" -format = "CAL" -params = ["instance"] -enabled = true - -[[op]] -name = "CAL_TOF" -opcode = 25 -class = "instance" -format = "CAL" -params = ["instance"] -enabled = true - -[[op]] -name = "CAL_TP" -opcode = 26 -class = "instance" -format = "CAL" -params = ["instance"] -enabled = true - -[[op]] -name = "CAL_CTU" -opcode = 27 -class = "instance" -format = "CAL" -params = ["instance"] -enabled = true - -[[op]] -name = "CAL_CTD" -opcode = 28 -class = "instance" -format = "CAL" -params = ["instance"] -enabled = true - -[[op]] -name = "CAL_CTUD" -opcode = 29 -class = "instance" -format = "CAL" -params = ["instance"] -enabled = true - -[[op]] -name = "CAL_R_TRIG" -opcode = 30 -class = "instance" -format = "CAL" -params = ["instance"] -enabled = true - -[[op]] -name = "CAL_F_TRIG" -opcode = 31 -class = "instance" -format = "CAL" -params = ["instance"] +prefix = "010011" +op = 1 +fmt = "JC" +func = "none" +params = ["rd", "off"] enabled = true [[op]] name = "CALL" -opcode = 32 -class = "plain" -format = "CALL" +prefix = "010100" +op = 0 +fmt = "CALL" +func = "none" params = ["fn_id"] enabled = true [[op]] -name = "RET" -opcode = 33 -class = "plain" -format = "NONE" +name = "CAL" +prefix = "010101" +op = 0 +fmt = "CAL" +func = "none" +params = ["fb_id", "slot"] +enabled = true + +# ---- 16B SLOT+off(前缀 0010,op 4 位) +[[op]] +name = "LOAD_OFF" +prefix = "0010" +op = 0 +fmt = "SLOT+off" +func = "full" +params = ["rd", "slot", "off"] +enabled = true + +[[op]] +name = "STORE_OFF" +prefix = "0010" +op = 1 +fmt = "SLOT+off" +func = "full" +params = ["slot", "off", "rs"] +enabled = true + +[[op]] +name = "STR_LEN" +prefix = "0010" +op = 2 +fmt = "SLOT+off" +func = "none" +params = ["rd", "slot", "off"] +enabled = true + +[[op]] +name = "STR_CMP" +prefix = "0010" +op = 3 +fmt = "SLOT+off" +func = "none" +params = ["rd", "slot", "off"] +enabled = true + +[[op]] +name = "STR_EQ" +prefix = "0010" +op = 4 +fmt = "SLOT+off" +func = "none" +params = ["rd", "slot", "off"] +enabled = true + +[[op]] +name = "STR_MID" +prefix = "0010" +op = 5 +fmt = "SLOT+off" +func = "none" +params = ["rd", "slot", "off"] +enabled = true + +[[op]] +name = "STR_LEFT" +prefix = "0010" +op = 6 +fmt = "SLOT+off" +func = "none" +params = ["rd", "slot", "off"] +enabled = true + +[[op]] +name = "STR_RIGHT" +prefix = "0010" +op = 7 +fmt = "SLOT+off" +func = "none" +params = ["rd", "slot", "off"] +enabled = true + +# ---- 16B IMM64(前缀 0011,op 4 位;预留不发射) +[[op]] +name = "LOADK64" +prefix = "0011" +op = 0 +fmt = "IMM64" +func = "full" +params = ["rd", "imm64"] +enabled = true + +# ---- 32B 预留(前缀 0001,op 4 位;形态待定,预留不发射) +[[op]] +name = "JTBL" +prefix = "0001" +op = 0 +fmt = "预留" +func = "none" params = [] enabled = true -# ---- 内建 FB(布局登记;opcode 与 op 行强校验一致;字段类型命中 type 表) +[[op]] +name = "STR_CONCAT" +prefix = "0001" +op = 1 +fmt = "预留" +func = "none" +params = [] +enabled = true +[[op]] +name = "STR_FIND" +prefix = "0001" +op = 2 +fmt = "预留" +func = "none" +params = [] +enabled = true + +[[op]] +name = "STR_REPLACE" +prefix = "0001" +op = 3 +fmt = "预留" +func = "none" +params = [] +enabled = true + +[[op]] +name = "ARR_LOAD" +prefix = "0001" +op = 4 +fmt = "预留" +func = "none" +params = [] +enabled = true + +[[op]] +name = "ARR_STORE" +prefix = "0001" +op = 5 +fmt = "预留" +func = "none" +params = [] +enabled = true + +# ---- 内建 FB(14 条;fb_id 唯一 0..14;字段类型命中 type 表; +# 布局偏移编译期按 1/2/4/8 对齐计算,见指令集清单 §8.1) [[fb]] -name = "ton" -opcode = 24 +name = "TON" +fb_id = 0 fields = [["in", "BOOL"], ["pt", "TIME"], ["q", "BOOL"], ["et", "TIME"]] [[fb]] -name = "tof" -opcode = 25 +name = "TOF" +fb_id = 1 fields = [["in", "BOOL"], ["pt", "TIME"], ["q", "BOOL"], ["et", "TIME"]] [[fb]] -name = "tp" -opcode = 26 +name = "TP" +fb_id = 2 fields = [["in", "BOOL"], ["pt", "TIME"], ["q", "BOOL"], ["et", "TIME"]] [[fb]] -name = "ctu" -opcode = 27 +name = "CTU" +fb_id = 3 fields = [["cu", "BOOL"], ["r", "BOOL"], ["pv", "INT"], ["q", "BOOL"], ["cv", "INT"]] [[fb]] -name = "ctd" -opcode = 28 +name = "DCTU" +fb_id = 4 +fields = [["cu", "BOOL"], ["r", "BOOL"], ["pv", "DINT"], ["q", "BOOL"], ["cv", "DINT"]] + +[[fb]] +name = "CTD" +fb_id = 5 fields = [["cd", "BOOL"], ["ld", "BOOL"], ["pv", "INT"], ["q", "BOOL"], ["cv", "INT"]] [[fb]] -name = "ctud" -opcode = 29 +name = "DCTD" +fb_id = 6 +fields = [["cd", "BOOL"], ["ld", "BOOL"], ["pv", "DINT"], ["q", "BOOL"], ["cv", "DINT"]] + +[[fb]] +name = "CTUD" +fb_id = 7 fields = [["cu", "BOOL"], ["cd", "BOOL"], ["r", "BOOL"], ["lu", "BOOL"], ["pv", "INT"], ["qu", "BOOL"], ["qd", "BOOL"], ["cv", "INT"]] [[fb]] -name = "r_trig" -opcode = 30 +name = "DCTUD" +fb_id = 8 +fields = [["cu", "BOOL"], ["cd", "BOOL"], ["r", "BOOL"], ["lu", "BOOL"], + ["pv", "DINT"], ["qu", "BOOL"], ["qd", "BOOL"], ["cv", "DINT"]] + +[[fb]] +name = "R_TRIG" +fb_id = 9 fields = [["clk", "BOOL"], ["q", "BOOL"]] [[fb]] -name = "f_trig" -opcode = 31 +name = "F_TRIG" +fb_id = 10 fields = [["clk", "BOOL"], ["q", "BOOL"]] + +[[fb]] +name = "SR" +fb_id = 11 +fields = [["S1", "BOOL"], ["R", "BOOL"], ["Q1", "BOOL"]] + +[[fb]] +name = "RS" +fb_id = 12 +fields = [["SET", "BOOL"], ["RESET1", "BOOL"], ["Q1", "BOOL"]] + +[[fb]] +name = "PWM" +fb_id = 13 +fields = [["in", "BOOL"], ["pt", "TIME"], ["duty", "REAL"], ["q", "BOOL"], ["et", "TIME"]] + +[[fb]] +name = "RTC" +fb_id = 14 +fields = [["enable", "BOOL"], ["date", "DATE"], ["tod", "TOD"]]