Token导航 LogoToken导航TokenDH.com
开发只读github未标认证来源可访问许可证需确认审计通过

add-ir-instruction添加红外指令

Agent Skill

用于辅助提示词、系统指令、Agent 行为约束和工作流模板的整理。它适合让 Agent 规范任务边界、统一输出格式、拆分操作步骤或优化提示词可复用性。使用时需要保留真实业务约束,不要把示例当硬规则;涉及自动执行、外部工具或高风险操作时,应在提示词中明确确认步骤、权限边界和失败处理方式。

总安装

447

周安装

19

GitHub Stars

10,997

下载量

157
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:add-ir-instruction(添加红外指令)
来源仓库:https://github.com/facebook/hermes
仓库路径:skills/add-ir-instruction
安装命令:
npx skills add https://github.com/facebook/hermes --skill add-ir-instruction
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/facebook/hermes --skill add-ir-instruction

简介

add-ir-instruction 用于向 Hermes 编译器添加新的中间表示(IR)指令,遵循严格的开发规范。

  • 适用于扩展编译器功能、优化代码生成或支持新语言特性的底层开发场景。
  • 必须修改多个核心文件包括文档、头文件和实现代码,并保持类型推断与验证逻辑一致。
  • 涉及编译器内部结构和构建流程改动,需确认开发环境与测试套件执行权限。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Adding a New IR Instruction to Hermes

When adding a new IR instruction, you must touch a specific set of files. This skill describes each file, the pattern to follow, and important conventions.

Checklist of Files to Modify

  1. doc/IR.md — Documentation (the only place for doc-comments)
  2. include/hermes/IR/Instrs.def — Instruction registration
  3. include/hermes/IR/Instrs.h — Class definition (NO doc-comments here)
  4. include/hermes/IR/IRBuilder.h — Builder declaration
  5. lib/IR/IRBuilder.cpp — Builder implementation
  6. lib/IR/IRVerifier.cpp — Verification logic
  7. lib/Optimizer/Scalar/TypeInference.cpp — Type inference stub
  8. lib/BCGen/HBC/ISel.cpp — HBC instruction selection (stub or implementation)
  9. lib/BCGen/SH/SH.cpp — Static Hermes codegen (stub or implementation)
  10. lib/BCGen/facebook/Mins/Mins.cpp — Mins codegen (stub or implementation)
  11. Tests — At minimum, update or add tests in test/

If the instruction needs lowering (i.e., it does not map directly to a bytecode opcode), you also need:

  1. include/hermes/BCGen/Lowering.h — Lowering pass declaration
  2. lib/BCGen/Lowering.cpp — Lowering pass implementation
  3. lib/BCGen/HBC/LoweringPipelines.cpp — Register pass in HBC pipeline
  4. lib/BCGen/SH/SH.cpp (in lowerModuleIR) — Register pass in SH pipeline

Step-by-Step Guide

1. Document in doc/IR.md

This is the ONLY place to put documentation for the instruction. Do NOT add doc-comments to Instrs.h.

Add a markdown table entry in the appropriate section:

### MyNewInst

MyNewInst | _
--- | --- |
Description | Brief description of what the instruction does.
Example |   `MyNewInst %arg1, %arg2 : type`
Arguments | *%arg1* is ... *%arg2* is ...
Semantics | Describe the semantics, referencing the spec where appropriate.
Effects | Describe side effects (e.g., "May read and write memory.", "May read memory and throw.", "Does not read or write memory.").

2. Register in Instrs.def

Add a DEF_VALUE entry. Place it near related instructions:

DEF_VALUE(MyNewInst, Instruction)

If it's a subclass of another instruction, use the parent as the second argument. If it's a terminator, use TERMINATOR instead of DEF_VALUE.

3. Define the class in Instrs.h

Do NOT add doc-comments to this file. Documentation belongs in doc/IR.md.

Follow this exact pattern:

class MyNewInst : public Instruction {
  MyNewInst(const MyNewInst &) = delete;
  void operator=(const MyNewInst &) = delete;

 public:
  enum { Arg1Idx, Arg2Idx };
  explicit MyNewInst(Value *arg1, Value *arg2)
      : Instruction(ValueKind::MyNewInstKind) {
    // Optional assertions on operand types:
    // assert(arg2->getType().isSomeType() && "message");

    // Set the result type:
    setType(Type::createNoType());  // for instructions with no output
    // or: setType(Type::createFoo()); for typed instructions

    pushOperand(arg1);
    pushOperand(arg2);
  }

  explicit MyNewInst(
      const MyNewInst *src,
      llvh::ArrayRef<Value *> operands)
      : Instruction(src, operands) {}

  Value *getArg1() const {
    return getOperand(Arg1Idx);
  }
  Value *getArg2() const {
    return getOperand(Arg2Idx);
  }

  static bool hasOutput() {
    return false;  // true if the instruction produces a value
  }
  static bool isTyped() {
    return false;  // true if the output type is meaningful
  }

  SideEffect getSideEffectImpl() const {
    // Compose side effects. Common patterns:
    //   return {};                                          // pure
    //   return SideEffect{}.setReadHeap();                  // reads memory
    //   return SideEffect{}.setReadHeap().setWriteHeap();   // reads+writes
    //   return SideEffect{}.setThrow().setReadHeap();       // may throw + read
    return SideEffect{}.setThrow().setReadHeap();
  }

  static bool classof(const Value *V) {
    ValueKind kind = V->getKind();
    return kind == ValueKind::MyNewInstKind;
  }
};

4. Add IRBuilder declaration in IRBuilder.h

MyNewInst *createMyNewInst(Value *arg1, Value *arg2);

5. Add IRBuilder implementation in IRBuilder.cpp

MyNewInst *IRBuilder::createMyNewInst(Value *arg1, Value *arg2) {
  auto *inst = new MyNewInst(arg1, arg2);
  insert(inst);
  return inst;
}

6. Add verification in IRVerifier.cpp

Add a visit method that checks invariants:

bool Verifier::visitMyNewInst(const MyNewInst &Inst) {
  AssertIWithMsg(
      Inst,
      Inst.getArg2()->getType().isSomeType(),
      "MyNewInst::Arg2 must be of SomeType");
  return true;
}

7. Add type inference in TypeInference.cpp

Add an infer method. For instructions without output, return createNoType():

Type inferMyNewInst(MyNewInst *inst) {
  return Type::createNoType();
}

8. Add code generation stubs

If the instruction is lowered before codegen, add fatal stubs. Otherwise, implement the actual code generation.

HBC ISel (lib/BCGen/HBC/ISel.cpp):

void HBCISel::generateMyNewInst(MyNewInst *Inst, BasicBlock *next) {
  hermes_fatal("MyNewInst should have been lowered.");
}

SH (lib/BCGen/SH/SH.cpp):

void generateMyNewInst(MyNewInst &inst) {
  hermes_fatal("MyNewInst should have been lowered");
}

Mins (lib/BCGen/facebook/Mins/Mins.cpp): Unless asked to, do not implement Mins codegen for new instructions. Leave it as a stub.

void generateMyNewInst(MyNewInst &inst) {
  unimplemented(inst);
}

9. (If needed) Add a lowering pass

Declare in Lowering.h:

/// Brief description of what the lowering does.
Pass *createLowerMyNewInst();

Implement in Lowering.cpp:

Pass *hermes::createLowerMyNewInst() {
  class ThisPass : public FunctionPass {
   public:
    explicit ThisPass() : FunctionPass("LowerMyNewInst") {}

    bool runOnFunction(Function *F) override {
      IRBuilder builder{F};
      bool changed = false;

      // Collect instructions first to avoid iterator invalidation.
      llvh::SmallVector<MyNewInst *, 4> insts;
      for (auto &BB : *F) {
        for (auto &I : BB) {
          if (auto *MNI = llvh::dyn_cast<MyNewInst>(&I))
            insts.push_back(MNI);
        }
      }

      for (auto *MNI : insts) {
        // Replace MNI with lowered IR...
        MNI->eraseFromParent();
        changed = true;
      }

      return changed;
    }
  };
  return new ThisPass();
}

Register in pipelines:

In lib/BCGen/HBC/LoweringPipelines.cpp and in lib/BCGen/SH/SH.cpp (lowerModuleIR), add PM.addPass(createLowerMyNewInst()); at the appropriate point (before any pass that would need to process instructions introduced by the lowering).

10. Add or update tests

Add lit tests in the appropriate test/ subdirectory. Use %FileCheck or %FileCheckOrRegen to verify the IR output. If existing tests cover the feature, update their expected output to reflect the new instruction.

Which subdirectory to use depends on how the instruction interacts with the compiler pipeline — not every instruction needs tests in every directory:

  • test/IRGen/ — When the instruction is generated directly from JavaScript source. Tests here verify that IRGen produces the expected IR.
  • test/Optimizer/ — When the instruction affects or interacts with optimization passes.
  • test/BCGen/ — Not used as often, but if this IR instruction is used in combination with new bytecode instructions, then place bytecode gen tests here.

Key Conventions

  • No doc-comments in Instrs.h. All documentation goes in doc/IR.md. The class in Instrs.h should have no /// or /** */ comments describing what the instruction does. Brief inline comments explaining non-obvious implementation details (like side effects) are fine.
  • Placement matters. Place the new instruction near related instructions in every file (e.g., private field instructions are grouped together).
  • Consistent naming. The instruction name (e.g., FooBarInst) must be consistent across all files: Instrs.def, Instrs.h, IRBuilder.h/cpp, IRVerifier.cpp, TypeInference.cpp, and all codegen files.
  • The ValueKind is derived automatically. When you add DEF_VALUE(MyNewInst, Instruction) to Instrs.def, the enum value ValueKind::MyNewInstKind is generated automatically.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.96%
按下载量换算56

Claude

31.45%
按下载量换算49

Cursor

18.24%
按下载量换算29

Gemini CLI

8.98%
按下载量换算14

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills