ELF format now supports 32-bit. Added ability to add instructions to a respective architecture that stores the op code.
This commit is contained in:
93
src/compiler/Architecture.cpp
Normal file
93
src/compiler/Architecture.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
#include "arctyx/compiler/Architecture.h"
|
||||
|
||||
Architecture::Architecture()
|
||||
: id(0)
|
||||
{
|
||||
}
|
||||
|
||||
Architecture::Architecture(ehs::Str_8 name)
|
||||
: id(name.Hash_64()), name((ehs::Str_8 &&)name)
|
||||
{
|
||||
}
|
||||
|
||||
Architecture::Architecture(Architecture &&arch) noexcept
|
||||
: id(arch.id), name((ehs::Str_8 &&)arch.name)
|
||||
{
|
||||
}
|
||||
|
||||
Architecture::Architecture(const Architecture &arc)
|
||||
: id(arc.id), name(arc.name)
|
||||
{
|
||||
}
|
||||
|
||||
Architecture & Architecture::operator=(Architecture &&arc) noexcept
|
||||
{
|
||||
if (this == &arc)
|
||||
return *this;
|
||||
|
||||
id = arc.id;
|
||||
name = (ehs::Str_8 &&)arc.name;
|
||||
|
||||
arc.id = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Architecture & Architecture::operator=(const Architecture &arc)
|
||||
{
|
||||
if (this == &arc)
|
||||
return *this;
|
||||
|
||||
id = arc.id;
|
||||
name = arc.name;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ehs::UInt_64 Architecture::Id() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
ehs::Str_8 Architecture::GetName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
bool Architecture::HasInstruction(const ehs::UInt_64 &id) const
|
||||
{
|
||||
for (ehs::UInt_64 i = 0; i < instructions.Size(); ++i)
|
||||
if (instructions[i].GetId() == id)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Architecture::HasInstruction(const ehs::Str_8 &name) const
|
||||
{
|
||||
return HasInstruction(name.Hash_64());
|
||||
}
|
||||
|
||||
const Instruction *Architecture::GetInstruction(const ehs::UInt_64 &id) const
|
||||
{
|
||||
for (ehs::UInt_64 i = 0; i < instructions.Size(); ++i)
|
||||
if (instructions[i].GetId() == id)
|
||||
return &instructions[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const Instruction *Architecture::GetInstruction(const ehs::Str_8 &name) const
|
||||
{
|
||||
return GetInstruction(name.Hash_64());
|
||||
}
|
||||
|
||||
bool Architecture::AddInstruction(Instruction ins)
|
||||
{
|
||||
if (HasInstruction(ins.GetId()))
|
||||
return false;
|
||||
|
||||
instructions.Push((Instruction &&)ins);
|
||||
|
||||
return true;
|
||||
}
|
1
src/compiler/Compiler.cpp
Normal file
1
src/compiler/Compiler.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include "arctyx/compiler/Compiler.h"
|
106
src/compiler/Instruction.cpp
Normal file
106
src/compiler/Instruction.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
#include "arctyx/compiler/Instruction.h"
|
||||
|
||||
Instruction::~Instruction()
|
||||
{
|
||||
delete code;
|
||||
}
|
||||
|
||||
Instruction::Instruction()
|
||||
: id(0), size(0), code(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
Instruction::Instruction(ehs::Str_8 name, const ehs::UInt_8 &size, ehs::Byte *code)
|
||||
: id(name.Hash_64()), name((ehs::Str_8 &&)name), size(size), code(code)
|
||||
{
|
||||
}
|
||||
|
||||
Instruction::Instruction(ehs::Str_8 name, const ehs::UInt_64 &code)
|
||||
: id(name.Hash_64()), name((ehs::Str_8 &&)name), size(sizeof(code)), code(new ehs::Byte[size])
|
||||
{
|
||||
*(ehs::UInt_64 *)this->code = code;
|
||||
}
|
||||
|
||||
Instruction::Instruction(ehs::Str_8 name, const ehs::UInt_32 &code)
|
||||
: id(name.Hash_64()), name((ehs::Str_8 &&)name), size(sizeof(code)), code(new ehs::Byte[size])
|
||||
{
|
||||
*(ehs::UInt_32 *)this->code = code;
|
||||
}
|
||||
|
||||
Instruction::Instruction(ehs::Str_8 name, const ehs::UInt_16 &code)
|
||||
: id(name.Hash_64()), name((ehs::Str_8 &&)name), size(sizeof(code)), code(new ehs::Byte[size])
|
||||
{
|
||||
*(ehs::UInt_16 *)this->code = code;
|
||||
}
|
||||
|
||||
Instruction::Instruction(ehs::Str_8 name, const ehs::UInt_8 &code)
|
||||
: id(name.Hash_64()), name((ehs::Str_8 &&)name), size(sizeof(code)), code(new ehs::Byte[size])
|
||||
{
|
||||
*this->code = code;
|
||||
}
|
||||
|
||||
Instruction::Instruction(Instruction &&ins) noexcept
|
||||
: id(ins.id), name((ehs::Str_8 &&)ins.name), size(ins.size), code(ins.code)
|
||||
{
|
||||
ins.id = 0;
|
||||
ins.size = 0;
|
||||
ins.code = nullptr;
|
||||
}
|
||||
|
||||
Instruction::Instruction(const Instruction &ins)
|
||||
: id(ins.id), name(ins.name), size(ins.size), code(new ehs::Byte[size])
|
||||
{
|
||||
ehs::Util::Copy(code, ins.code, size);
|
||||
}
|
||||
|
||||
Instruction &Instruction::operator=(Instruction &&ins) noexcept
|
||||
{
|
||||
if (this == &ins)
|
||||
return *this;
|
||||
|
||||
id = ins.id;
|
||||
name = (ehs::Str_8 &&)ins.name;
|
||||
size = ins.size;
|
||||
code = ins.code;
|
||||
|
||||
ins.id = 0;
|
||||
ins.size = 0;
|
||||
ins.code = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Instruction &Instruction::operator=(const Instruction &ins)
|
||||
{
|
||||
if (this == &ins)
|
||||
return *this;
|
||||
|
||||
id = ins.id;
|
||||
name = ins.name;
|
||||
size = ins.size;
|
||||
code = new ehs::Byte[size];
|
||||
|
||||
ehs::Util::Copy(code, ins.code, size);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ehs::UInt_64 Instruction::GetId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
ehs::Str_8 Instruction::GetName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
ehs::UInt_8 Instruction::GetSize() const
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
ehs::Byte *Instruction::GetCode() const
|
||||
{
|
||||
return code;
|
||||
}
|
Reference in New Issue
Block a user