~ppsspp/ppsspp/ppsspp_1.3.0

« back to all changes in this revision

Viewing changes to ext/armips/Commands/CDirectiveConditional.cpp

  • Committer: Sérgio Benjamim
  • Date: 2017-01-02 00:12:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20170102001205-cxbta9za203nmjwm
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "stdafx.h"
 
2
#include "Commands/CDirectiveConditional.h"
 
3
#include "Core/Common.h"
 
4
#include "Archs/ARM/Arm.h"
 
5
#include "Util/Util.h"
 
6
 
 
7
extern CArmArchitecture Arm;
 
8
 
 
9
CDirectiveConditional::CDirectiveConditional(ConditionType type)
 
10
{
 
11
        this->type = type;
 
12
 
 
13
        ifBlock = nullptr;
 
14
        elseBlock = nullptr;
 
15
        previousResult = false;
 
16
}
 
17
 
 
18
CDirectiveConditional::CDirectiveConditional(ConditionType type, const std::wstring& name)
 
19
        : CDirectiveConditional(type)
 
20
{
 
21
        label = Global.symbolTable.getLabel(name,Global.FileInfo.FileNum,Global.Section);
 
22
        if (label == NULL)
 
23
                Logger::printError(Logger::Error,L"Invalid label name \"%s\"",name);
 
24
}
 
25
 
 
26
CDirectiveConditional::CDirectiveConditional(ConditionType type, const Expression& exp)
 
27
        : CDirectiveConditional(type)
 
28
{
 
29
        this->expression = exp;
 
30
}
 
31
 
 
32
CDirectiveConditional::~CDirectiveConditional()
 
33
{
 
34
        delete ifBlock;
 
35
        delete elseBlock;
 
36
}
 
37
 
 
38
void CDirectiveConditional::setContent(CAssemblerCommand* ifBlock, CAssemblerCommand* elseBlock)
 
39
{
 
40
        this->ifBlock = ifBlock;
 
41
        this->elseBlock = elseBlock;
 
42
}
 
43
 
 
44
bool CDirectiveConditional::evaluate()
 
45
{
 
46
        u64 value;
 
47
        if (expression.isLoaded())
 
48
        {
 
49
                if (expression.evaluateInteger(value) == false)
 
50
                {
 
51
                        Logger::queueError(Logger::Error,L"Invalid conditional expression");
 
52
                        return false;
 
53
                }
 
54
        }
 
55
 
 
56
        switch (type)
 
57
        {
 
58
        case ConditionType::IF:
 
59
                return value != 0;
 
60
        case ConditionType::IFDEF:
 
61
                return label->isDefined();
 
62
        case ConditionType::IFNDEF:
 
63
                return !label->isDefined();
 
64
        }
 
65
                        
 
66
        Logger::queueError(Logger::Error,L"Invalid conditional type");
 
67
        return false;
 
68
}
 
69
 
 
70
bool CDirectiveConditional::Validate()
 
71
{
 
72
        bool result = evaluate();
 
73
        bool returnValue = result != previousResult;
 
74
        previousResult = result;
 
75
 
 
76
        if (result)
 
77
        {
 
78
                ifBlock->applyFileInfo();
 
79
                if (ifBlock->Validate())
 
80
                        returnValue = true;
 
81
        } else if (elseBlock != NULL)
 
82
        {
 
83
                elseBlock->applyFileInfo();
 
84
                if (elseBlock->Validate())
 
85
                        returnValue = true;
 
86
        }
 
87
 
 
88
        return returnValue;
 
89
}
 
90
 
 
91
void CDirectiveConditional::Encode() const
 
92
{
 
93
        if (previousResult)
 
94
        {
 
95
                ifBlock->Encode();
 
96
        } else if (elseBlock != NULL)
 
97
        {
 
98
                elseBlock->Encode();
 
99
        }
 
100
}
 
101
 
 
102
void CDirectiveConditional::writeTempData(TempData& tempData) const
 
103
{
 
104
        if (previousResult)
 
105
        {
 
106
                ifBlock->applyFileInfo();
 
107
                ifBlock->writeTempData(tempData);
 
108
        } else if (elseBlock != NULL)
 
109
        {
 
110
                elseBlock->applyFileInfo();
 
111
                elseBlock->writeTempData(tempData);
 
112
        }
 
113
}
 
114
 
 
115
void CDirectiveConditional::writeSymData(SymbolData& symData) const
 
116
{
 
117
        if (previousResult)
 
118
        {
 
119
                ifBlock->writeSymData(symData);
 
120
        } else if (elseBlock != NULL)
 
121
        {
 
122
                elseBlock->writeSymData(symData);
 
123
        }
 
124
}