Book Image

LLVM Cookbook

Book Image

LLVM Cookbook

Overview of this book

Table of Contents (16 chapters)
LLVM Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Registering a target


For running the llc tool in the TOY target architecture, it has to be registered with the llc tool. This recipe demonstrates which configuration files need to be modified to register a target. The build files are modified in this recipe.

How to do it…

To register a target with a static compiler, follow these steps:

  1. First, add the entry of the TOY backend to llvm_root_dir/CMakeLists.txt:

    set(LLVM_ALL_TARGETS
      AArch64
      ARM
      …
      …
      TOY
      )
  2. Then add the toy entry to llvm_root_dir/include/llvm/ADT/Triple.h:

    class Triple {
    public:
      enum ArchType {
        UnknownArch,
    
        arm,        // ARM (little endian): arm, armv.*, xscale
        armeb,      // ARM (big endian): armeb
        aarch64,    // AArch64 (little endian): aarch64
        …
       …
    
    toy     // TOY: toy
    };
  3. Add the toy entry to llvm_root_dir/include/llvm/ MC/MCExpr.h:

    class MCSymbolRefExpr : public MCExpr {
    public:
    enum VariantKind {
    ...
    VK_TOY_LO,
    VK_TOY_HI,
    };
  4. Add the toy entry to llvm_root_dir/include/llvm/ Support/ELF.h:

    enum {
    ...