File indexing completed on 2024-12-08 08:10:34

0001 /***************************************************************************
0002  *   Copyright (C) 2003-2005 by David Saxton                               *
0003  *   david@bluehaze.org                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #ifndef ASMFORMATTER_H
0012 #define ASMFORMATTER_H
0013 
0014 #include <QStringList>
0015 
0016 /**
0017 @author David Saxton
0018  */
0019 class InstructionParts
0020 {
0021 public:
0022     /**
0023      * Breaks up the line into parts.
0024      */
0025     InstructionParts(QString line);
0026 
0027     QString label() const
0028     {
0029         return m_label;
0030     }
0031     QString operand() const
0032     {
0033         return m_operand;
0034     }
0035     QString operandData() const
0036     {
0037         return m_operandData;
0038     }
0039     QString comment() const
0040     {
0041         return m_comment;
0042     }
0043 
0044 protected:
0045     QString m_label;
0046     QString m_operand;
0047     QString m_operandData;
0048     QString m_comment; ///< includes the ";" part
0049 };
0050 
0051 /**
0052 @author David Saxton
0053 */
0054 class AsmFormatter
0055 {
0056 public:
0057     AsmFormatter();
0058     ~AsmFormatter();
0059 
0060     enum LineType {
0061         Equ,
0062         Instruction, // could include label
0063         Other        // eg comments, __config
0064     };
0065 
0066     QString tidyAsm(QStringList lines);
0067 
0068     static LineType lineType(QString line);
0069 
0070 protected:
0071     QString tidyInstruction(const QString &line);
0072     QString tidyEqu(const QString &line);
0073     /**
0074      * Appends spaces to the end of text until it is greater or equakl to
0075      * length.
0076      */
0077     static void pad(QString &text, int length);
0078 
0079     int m_indentAsmName;
0080     int m_indentAsmData;
0081     int m_indentEqu;
0082     int m_indentEquValue;
0083     int m_indentEquComment;
0084     int m_indentComment;
0085 };
0086 
0087 #endif