加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
assem.ml 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
Your Name 提交于 2021-08-09 06:42 . 1
type reg = string
type temp = Temp.temp
type label = Temp.label
type oper_instr = {
assem: string;
dst: temp list;
src: temp list;
jump: label list option
}
type label_instr = {
assem: string;
lab: label
}
type move_instr = {
assem: string;
dst: temp;
src: temp
}
type instr = OPER of oper_instr
| LABEL of label_instr
| MOVE of move_instr
let placeholder_regexp = Str.regexp "'\\([dsj]\\)\\([0-9]+\\)"
let format format_temp instr =
let fill_placeholders assem src dst jump =
Str.global_substitute placeholder_regexp
(fun placeholder ->
let kind = Str.matched_group 1 placeholder in
let i = int_of_string (Str.matched_group 2 placeholder) in
match kind with
"s" -> format_temp (List.nth src i)
| "d" -> format_temp (List.nth dst i)
| "j" -> Temp.string_of_label (List.nth jump i))
assem in
match instr with
OPER {assem; src; dst; jump} ->
"\t" ^ fill_placeholders assem src dst (Option.default [] jump)
| LABEL {assem; _} ->
assem
| MOVE {assem; src; dst} ->
"\t" ^ fill_placeholders assem [src] [dst] []
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化