1 #include "stdafx.h"
2 #include "Core/Common.h"
3 #include <sys/stat.h>
4 #include "Assembler.h"
5 #include "Commands/CAssemblerLabel.h"
6 #include "Util/Util.h"
7 #include "Core/FileManager.h"
8 
9 FileManager fileManager;
10 FileManager* g_fileManager = &fileManager;
11 
12 tGlobal Global;
13 CArchitecture* Arch;
14 
getFolderNameFromPath(const std::wstring & src)15 std::wstring getFolderNameFromPath(const std::wstring& src)
16 {
17 #ifdef _WIN32
18 	size_t s = src.find_last_of(L"\\/");
19 #else
20 	size_t s = src.rfind(L"/");
21 #endif
22 	if (s == std::wstring::npos)
23 	{
24 		return L".";
25 	}
26 
27 	return src.substr(0,s);
28 }
29 
getFullPathName(const std::wstring & path)30 std::wstring getFullPathName(const std::wstring& path)
31 {
32 	if (Global.relativeInclude == true)
33 	{
34 		if (isAbsolutePath(path))
35 		{
36 			return path;
37 		} else {
38 			std::wstring source = Global.FileInfo.FileList[Global.FileInfo.FileNum];
39 			return getFolderNameFromPath(source) + L"/" + path;
40 		}
41 	} else {
42 		return path;
43 	}
44 }
45 
checkLabelDefined(const std::wstring & labelName,int section)46 bool checkLabelDefined(const std::wstring& labelName, int section)
47 {
48 	std::shared_ptr<Label> label = Global.symbolTable.getLabel(labelName,Global.FileInfo.FileNum,section);
49 	return label->isDefined();
50 }
51 
checkValidLabelName(const std::wstring & labelName)52 bool checkValidLabelName(const std::wstring& labelName)
53 {
54 	return Global.symbolTable.isValidSymbolName(labelName);
55 }
56 
isPowerOfTwo(int64_t n)57 bool isPowerOfTwo(int64_t n)
58 {
59 	if (n == 0) return false;
60 	return !(n & (n - 1));
61 }
62