ASMInstruction.hpp 666 Bytes
Newer Older
jhe's avatar
lab3  
jhe committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#pragma once

#include <cassert>
#include <string>

struct ASMInstruction {
    enum InstType { Instruction, Atrribute, Label, Comment } type;
    std::string content;

    explicit ASMInstruction(std::string s, InstType ty = Instruction)
        : type(ty), content(s) {}

    std::string format() const {
        switch (type) {
        case ASMInstruction::Instruction:
        case ASMInstruction::Atrribute:
            return "\t" + content + "\n";
        case ASMInstruction::Label:
            return content + ":\n";
        case ASMInstruction::Comment:
            return "# " + content + "\n";
        }
        assert(false && "unreachable");
    }
};