DataHoarder
38ba3ceb45
Some checks reported errors
continuous-integration/drone/push Build was killed
86 lines
3.3 KiB
C++
86 lines
3.3 KiB
C++
/*****************************************************************************
|
|
* Copyright (c) 2020, rrcc FM10K-Documentation Contributors
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are met:
|
|
*
|
|
* * Redistributions of source code must retain the above copyright notice,
|
|
* this list of conditions and the following disclaimer.
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* * Neither the name of the copyright holder nor the names of its contributors
|
|
* may be used to endorse or promote products derived from this software
|
|
* without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*****************************************************************************/
|
|
|
|
#pragma once
|
|
|
|
#include <stdexcept>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
class Token {
|
|
public:
|
|
|
|
enum class Type {
|
|
// (LocalLabel:) Operator(.Flags) (RegisterLabel,RegisterLocation,CodeLabel,CodeLocation,Immediate)
|
|
Directive,
|
|
BareValue,
|
|
Label, // {label}: can't start with a number. Can contain a-zA-Z0-9_. Example: label:
|
|
LocalLabel, // .{label}
|
|
|
|
Operator, // Operator string. Can contain {a-zA-Z0-9_~}
|
|
|
|
RegisterLocation, // %{32-bit unsigned integer} , example: %0, %1234, %0x1234
|
|
|
|
CodeLabel, // @{label} or @{.label}, example: @__test, @.loop
|
|
CodeLocation, // @{32-bit unsigned integer} , example: @0, @1234, @0x1234
|
|
|
|
Immediate, // {32-bit unsigned integer} , example: 0, 1234, 0x1234
|
|
|
|
Offset, // {+-<}{32-bit unsigned integer}, will apply to previous value
|
|
|
|
AsValue, // &
|
|
AsIndirect, // *
|
|
|
|
// A comment is ;{....} anything that starts with ; . Reads until \n
|
|
|
|
//End of Token: \n\t[space],;
|
|
};
|
|
|
|
Token(const Token &) = default;
|
|
|
|
Token(Type type, std::string valueString, uint32_t valueImmediate = 0) : type(type), valueImmediate(valueImmediate),
|
|
valueString(std::move(valueString)) {
|
|
|
|
}
|
|
|
|
Type type;
|
|
uint32_t valueImmediate;
|
|
std::string valueString;
|
|
|
|
Type getType() const {
|
|
return type;
|
|
}
|
|
|
|
const std::string &getTextValue() const {
|
|
return valueString;
|
|
}
|
|
|
|
uint32_t getNumericValue() const {
|
|
return valueImmediate;
|
|
}
|
|
}; |