@@ -1,13 +1,33 @@
#include "macroassembler.h"
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include <stdlib.h> // NULL

#include "code-space.h" // CodeSpace
#include "heap.h" // HeapValue
#include "macroassembler.h"
#include "code-space.h" // CodeSpace
#include "heap.h" // HeapValue
#include "heap-inl.h"

#include "stubs.h"
#include "utils.h" // ComputeHash

#include <stdlib.h> // NULL
#include "utils.h" // ComputeHash

namespace candor {
namespace internal {
@@ -103,7 +123,7 @@ void Masm::Spill::SpillReg(Register src) {

src_ = src;
Operand slot(eax, 0);
masm()->SpillSlot(index(), slot);
masm()->SpillSlot(index(), &slot);
masm()->mov(slot, src);

if (masm()->spill_index_ > masm()->spills_) {
@@ -123,7 +143,7 @@ void Masm::Spill::Unspill(Register dst) {
assert(!is_empty());

Operand slot(eax, 0);
masm()->SpillSlot(index(), slot);
masm()->SpillSlot(index(), &slot);
masm()->mov(dst, slot);
}

@@ -135,7 +155,7 @@ void Masm::Spill::Unspill() {

Operand* Masm::Spill::GetOperand() {
Operand* r = new Operand(eax, 0);
masm()->SpillSlot(index(), *r);
masm()->SpillSlot(index(), r);
return r;
}

@@ -608,7 +628,7 @@ void Masm::Call(Register addr) {
}


void Masm::Call(Operand& addr) {
void Masm::Call(const Operand& addr) {
while ((offset() & 0x1) != 0x1) {
nop();
}
@@ -618,7 +638,7 @@ void Masm::Call(Operand& addr) {


void Masm::Call(char* stub) {
mov(scratch, reinterpret_cast<uint32_t>(stub));
mov(scratch, Immediate(reinterpret_cast<uint32_t>(stub)));

Call(scratch);
}
@@ -682,5 +702,5 @@ void Masm::ProbeCPU() {
ret(0);
}

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor
@@ -1,7 +1,29 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include "pic.h"
#include "code-space.h" // CodeSpace
#include "stubs.h" // Stubs
#include "macroassembler.h" // Masm
#include "code-space.h" // CodeSpace
#include "stubs.h" // Stubs
#include "macroassembler.h" // Masm

namespace candor {
namespace internal {
@@ -80,5 +102,5 @@ void PIC::Generate(Masm* masm) {
__ ret(0);
}

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor
@@ -1,8 +1,30 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include "stubs.h"
#include "code-space.h" // CodeSpace
#include "cpu.h" // CPU
#include "ast.h" // BinOp
#include "macroassembler.h" // Masm
#include "code-space.h" // CodeSpace
#include "cpu.h" // CPU
#include "ast.h" // BinOp
#include "macroassembler.h" // Masm
#include "runtime.h"
#include "pic.h"

@@ -212,7 +234,7 @@ void AllocateStub::Generate() {
__ mov(scratch, Immediate(*reinterpret_cast<intptr_t*>(&allocate)));

__ Call(scratch);
__ addlb(esp, 4 * 4);
__ addlb(esp, Immediate(4 * 4));
__ Popad(eax);
}

@@ -309,10 +331,10 @@ void CallBindingStub::Generate() {

Operand code(scratch, HFunction::kCodeOffset);

__ push(ebx); // align
__ push(ebx); //
__ push(ebx); // <- argv
__ push(eax); // <- argc
__ push(ebx); // align
__ push(ebx); //
__ push(ebx); // <- argv
__ push(eax); // <- argc
__ mov(scratch, fn);
__ Call(code);
__ addlb(esp, Immediate(4 * 4));
@@ -752,8 +774,8 @@ void CloneObjectStub::Generate() {
__ mov(ebx, edx);

// Get new object's map
qmap.base(ebx);
__ mov(ebx, qmap);
Operand qmap_ebx(ebx, HObject::kMapOffset);
__ mov(ebx, qmap_ebx);

// Set proto
Operand qproto(edx, HObject::kProtoOffset);
@@ -1153,10 +1175,10 @@ void BinOpStub::Generate() {
case BinOp::k##V: cb = &RuntimeBinOp<BinOp::k##V>; break;

switch (type()) {
BINARY_SUB_TYPES(BINARY_ENUM_CASES)
default:
UNEXPECTED
break;
BINARY_SUB_TYPES(BINARY_ENUM_CASES)
default:
UNEXPECTED
break;
}
#undef BINARY_ENUM_CASES

@@ -1263,7 +1285,7 @@ void LoadVarArgStub::Generate() {
offset_s.Unspill();
__ addlb(offset, Immediate(HNumber::Tag(2)));
__ addl(offset, ebx);
__ shl(offset, 1);
__ shl(offset, Immediate(1));
__ addl(offset, *ebp_s.GetOperand());
__ mov(offset, stack_slot);

@@ -1402,5 +1424,5 @@ void StoreVarArgStub::Generate() {
GenerateEpilogue();
}

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor
@@ -1,9 +1,31 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_IA32_STUBS_IA32_H_
#define _SRC_IA32_STUBS_IA32_H_

namespace candor {
namespace internal {
} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_IA32_STUBS_IA32_H_
#endif // _SRC_IA32_STUBS_IA32_H_
@@ -1,7 +1,29 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include "lexer.h"
#include <string.h> // strncmp
#include <stdlib.h> // NULL
#include "zone.h" // ZoneObject
#include <string.h> // strncmp
#include <stdlib.h> // NULL
#include "zone.h" // ZoneObject

#define LENGTH_CHECK\
if (offset_ == length_) return new Token(kEnd, offset_);
@@ -98,33 +120,31 @@ Lexer::Token* Lexer::Consume() {
LENGTH_CHECK

// One-char tokens
{
TokenType type = kEnd;
switch (get(0)) {
case '.':
TokenType type = kEnd;
switch (get(0)) {
case '.':
if (has(3) && get(1) == '.' && get(2) == '.') {
offset_ += 2;
type = kEllipsis;
} else {
type = kDot;
}
break;
case ',': type = kComma; break;
case ':': type = kColon; break;
case '(': type = kParenOpen; break;
case ')': type = kParenClose; break;
case '{': type = kBraceOpen; break;
case '}': type = kBraceClose; break;
case '[': type = kArrayOpen; break;
case ']': type = kArrayClose; break;
default:
break;
}
case ',': type = kComma; break;
case ':': type = kColon; break;
case '(': type = kParenOpen; break;
case ')': type = kParenClose; break;
case '{': type = kBraceOpen; break;
case '}': type = kBraceClose; break;
case '[': type = kArrayOpen; break;
case ']': type = kArrayClose; break;
default:
break;
}

if (type != kEnd) {
offset_++;
return new Token(type, offset_ - 1);
}
if (type != kEnd) {
offset_++;
return new Token(type, offset_ - 1);
}

// Number
@@ -154,7 +174,7 @@ Lexer::Token* Lexer::Consume() {

while (has(1)) {
if (get(0) == endchar) break;
if (get(0) == '\\' ) {
if (get(0) == '\\') {
// Skip escaped char
offset_++;
LENGTH_CHECK
@@ -243,5 +263,5 @@ Lexer::Token* Lexer::Consume() {
}
}

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor
@@ -1,10 +1,33 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_LEXER_H_
#define _SRC_LEXER_H_

#include "utils.h" // List
#include "zone.h" // ZoneObject
#include <stdint.h>

#include "utils.h" // List
#include "zone.h" // ZoneObject

namespace candor {
namespace internal {

@@ -159,7 +182,7 @@ class Lexer {
ZoneList<Token*> queue_;
};

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_LEXER_H_
#endif // _SRC_LEXER_H_
@@ -1,3 +1,25 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_LIR_INL_H_
#define _SRC_LIR_INL_H_

@@ -238,16 +260,18 @@ inline bool LInterval::IsEqual(LInterval* i) {

inline void LInterval::Print(PrintBuffer* p) {
switch (type_) {
case kVirtual: p->Print("v%d", id); break;
case kRegister:
p->Print("%s:%d", RegisterNameByIndex(index()), id);
if (register_hint != NULL) {
p->Print("(%s)", RegisterNameByIndex(register_hint->interval()->index()));
}
break;
case kStackSlot: p->Print("[%d]:%d", index(), id); break;
case kConst: p->Print("c%d", id); break;
default: UNEXPECTED
case kVirtual: p->Print("v%d", id); break;
case kRegister:
p->Print("%s:%d", RegisterNameByIndex(index()), id);
if (register_hint != NULL) {
int index = register_hint->interval()->index();
const char* name = RegisterNameByIndex(index);
p->Print("(%s)", name);
}
break;
case kStackSlot: p->Print("[%d]:%d", index(), id); break;
case kConst: p->Print("c%d", id); break;
default: UNEXPECTED
}
}

@@ -322,7 +346,7 @@ inline int LInterval::end() {
return ranges()->tail()->end();
}

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_LIR_INL_H_
#endif // _SRC_LIR_INL_H_
@@ -1,3 +1,25 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_LIR_INSTRUCTIONS_INL_H_
#define _SRC_LIR_INSTRUCTIONS_INL_H_

@@ -88,10 +110,10 @@ inline LInstruction* LInstruction::Propagate(HIRInstruction* res) {
inline const char* LInstruction::TypeToStr(LInstruction::Type type) {
const char* res = NULL;
switch (type) {
LIR_INSTRUCTION_TYPES(LIR_INSTRUCTION_TYPE_STR)
default:
UNEXPECTED
break;
LIR_INSTRUCTION_TYPES(LIR_INSTRUCTION_TYPE_STR)
default:
UNEXPECTED
break;
}

return res;
@@ -133,7 +155,7 @@ inline bool LAccessProperty::HasMonomorphicProperty() {
return monomorphic_prop_;
}

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_LIR_INSTRUCTIONS_INL_H_
#endif // _SRC_LIR_INSTRUCTIONS_INL_H_
@@ -1,3 +1,25 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include "lir.h"
#include "lir-inl.h"
#include "lir-instructions.h"
@@ -136,5 +158,5 @@ void LControlInstruction::Print(PrintBuffer* p) {
p->Print("\n");
}

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor
@@ -1,11 +1,33 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_LIR_INSTRUCTIONS_H_
#define _SRC_LIR_INSTRUCTIONS_H_

#include "lir.h"
#include "lir-inl.h"
#include "hir-instructions.h"
#include "hir-instructions-inl.h"
#include "macroassembler.h" // Label
#include "macroassembler.h" // Label
#include "zone.h"
#include "utils.h"

@@ -68,15 +90,15 @@ class LInstruction : public ZoneObject {
kNone
};

LInstruction(Type type) : id(-1),
type_(type),
input_count_(0),
scratch_count_(0),
has_call_(NULL),
block_(NULL),
slot_(NULL),
hir_(NULL),
propagated_(NULL) {
explicit LInstruction(Type type) : id(-1),
type_(type),
input_count_(0),
scratch_count_(0),
has_call_(NULL),
block_(NULL),
slot_(NULL),
hir_(NULL),
propagated_(NULL) {
inputs[0] = NULL;
inputs[1] = NULL;
scratches[0] = NULL;
@@ -99,7 +121,10 @@ class LInstruction : public ZoneObject {

inline LInstruction* SetSlot(ScopeSlot* slot);

inline LInstruction* MarkHasCall() { has_call_ = true; return this; }
inline LInstruction* MarkHasCall() {
has_call_ = true;
return this;
}
inline bool HasCall() { return has_call_; }

inline Type type() { return type_; }
@@ -116,7 +141,10 @@ class LInstruction : public ZoneObject {
int result_count() { return result != NULL; }
int scratch_count() { return scratch_count_; }

inline ScopeSlot* slot() { assert(slot_ != NULL); return slot_; }
inline ScopeSlot* slot() {
assert(slot_ != NULL);
return slot_;
}
inline HIRInstruction* hir() { return hir_; }
inline void hir(HIRInstruction* hir) { hir_ = hir; }

@@ -147,8 +175,8 @@ class LInstruction : public ZoneObject {

class LEntry : public LInstruction {
public:
LEntry(int context_slots) : LInstruction(kEntry),
context_slots_(context_slots) {
explicit LEntry(int context_slots) : LInstruction(kEntry),
context_slots_(context_slots) {
}

INSTRUCTION_METHODS(Entry)
@@ -194,7 +222,9 @@ class LGap : public LInstruction {

typedef ZoneList<Pair*> PairList;

LGap(LInterval* tmp) : LInstruction(kGap), tmp_(tmp->Use(LUse::kAny, this)) {}
explicit LGap(LInterval* tmp) : LInstruction(kGap),
tmp_(tmp->Use(LUse::kAny, this)) {
}

INSTRUCTION_METHODS(Gap)

@@ -213,7 +243,8 @@ class LGap : public LInstruction {

class LControlInstruction : public LInstruction {
public:
LControlInstruction(Type type) : LInstruction(type), target_count_(0) {
explicit LControlInstruction(Type type) : LInstruction(type),
target_count_(0) {
targets_[0] = NULL;
targets_[1] = NULL;
}
@@ -258,7 +289,8 @@ class LBranchNumber : public LControlInstruction {

class LAccessProperty : public LInstruction {
public:
LAccessProperty(Type type) : LInstruction(type), monomorphic_prop_(false) {
explicit LAccessProperty(Type type) : LInstruction(type),
monomorphic_prop_(false) {
}

inline void SetMonomorphicProperty();
@@ -302,7 +334,8 @@ class LFunction : public LInstruction {

class LLiteral : public LInstruction {
public:
LLiteral(ScopeSlot* slot) : LInstruction(kLiteral), root_slot_(slot) {
explicit LLiteral(ScopeSlot* slot) : LInstruction(kLiteral),
root_slot_(slot) {
assert(slot != NULL);
}

@@ -314,7 +347,8 @@ class LLiteral : public LInstruction {

class LAllocateObject : public LInstruction {
public:
LAllocateObject(int size) : LInstruction(kAllocateObject), size_(size) {
explicit LAllocateObject(int size) : LInstruction(kAllocateObject),
size_(size) {
}

INSTRUCTION_METHODS(AllocateObject)
@@ -325,7 +359,8 @@ class LAllocateObject : public LInstruction {

class LAllocateArray : public LInstruction {
public:
LAllocateArray(int size) : LInstruction(kAllocateArray), size_(size) {
explicit LAllocateArray(int size) : LInstruction(kAllocateArray),
size_(size) {
}

INSTRUCTION_METHODS(AllocateArray)
@@ -336,7 +371,7 @@ class LAllocateArray : public LInstruction {

#define DEFAULT_INSTR_IMPLEMENTATION(V) \
class L##V : public LInstruction { \
public: \
public: \
L##V() : LInstruction(k##V) {} \
INSTRUCTION_METHODS(V) \
};
@@ -346,7 +381,7 @@ LIR_INSTRUCTION_SIMPLE_TYPES(DEFAULT_INSTR_IMPLEMENTATION)
#undef DEFAULT_INSTR_IMPLEMENTATION
#undef INSTRUCTION_METHODS

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_LIR_INSTRUCTIONS_H_
#endif // _SRC_LIR_INSTRUCTIONS_H_
@@ -1,13 +1,37 @@
#include "hir.h"
#include "hir-inl.h"
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include "lir.h"

#define __STDC_LIMIT_MACROS
#include <limits.h> // INT_MAX
#include <string.h> // memset

#include "lir-inl.h"
#include "hir.h"
#include "hir-inl.h"
#include "lir-instructions.h"
#include "lir-instructions-inl.h"
#include "source-map.h" // SourceMap
#define __STDC_LIMIT_MACROS
#include <limits.h> // INT_MAX
#include <string.h> // memset
#include "source-map.h" // SourceMap

namespace candor {
namespace internal {
@@ -355,7 +379,7 @@ void LGen::ShuffleIntervals(LIntervalList* active,
// Interval has ended before current position
active->RemoveAt(i--);
if (handled != NULL) handled->Push(interval);
} else if (!interval->Covers(pos)){
} else if (!interval->Covers(pos)) {
// Interval isn't covering current position - move to ininterval
active->RemoveAt(i--);
inactive->Push(interval);
@@ -370,7 +394,7 @@ void LGen::ShuffleIntervals(LIntervalList* active,
// Interval has ended before current position
inactive->RemoveAt(i--);
if (handled != NULL) handled->Push(interval);
} else if (interval->Covers(pos)){
} else if (interval->Covers(pos)) {
// Interval is covering current position - move to active
inactive->RemoveAt(i--);
active->Push(interval);
@@ -908,7 +932,7 @@ void LGen::ResultFromFixed(LInstruction* instr, Register reg) {


LInterval* LGen::Split(LInterval* i, int pos) {
// TODO: Find optimal split position here
// TODO(indutny): Find optimal split position here
assert(!i->IsFixed());

assert(pos > i->start() && pos < i->end());
@@ -1135,5 +1159,5 @@ LBlock::LBlock(HIRBlock* hir) : start_id(-1),
hir->lir(this);
}

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor
@@ -1,3 +1,25 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_LIR_H_
#define _SRC_LIR_H_

@@ -9,9 +31,9 @@

#include "hir.h"
#include "hir-inl.h"
#include "macroassembler.h" // Register
#include "zone.h" // Zone
#include "utils.h" // Lists and etc
#include "macroassembler.h" // Register
#include "zone.h" // Zone
#include "utils.h" // Lists and etc
#include "list.h"

namespace candor {
@@ -169,7 +191,7 @@ class LInterval : public ZoneObject {

class LBlock : public ZoneObject {
public:
LBlock(HIRBlock* hir);
explicit LBlock(HIRBlock* hir);

inline void PrintHeader(PrintBuffer* p);

@@ -274,7 +296,7 @@ class LGen : public ZoneObject {

#undef LGEN_VISITOR

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_LIR_H_
#endif // _SRC_LIR_H_
@@ -1,15 +1,37 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_SORTED_LIST_H_
#define _SRC_SORTED_LIST_H_

#include <stdlib.h> // qsort
#include <stdlib.h> // qsort

namespace candor {
namespace internal {

template <class T, class Policy, class Allocator>
class SortableList {
public:
SortableList(int size) : map_(NULL), size_(0), grow_(size), len_(0) {
explicit SortableList(int size) : map_(NULL), size_(0), grow_(size), len_(0) {
Grow();
}

@@ -155,7 +177,7 @@ class SortableList {
int len_;
};

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_SORTED_LIST_H_
#endif // _SRC_SORTED_LIST_H_
@@ -1,8 +1,30 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_MARCOASSEMBLER_INL_H_
#define _SRC_MARCOASSEMBLER_INL_H_

#include "macroassembler.h"
#include "heap.h" // HValue
#include "heap.h" // HValue

namespace candor {
namespace internal {
@@ -39,7 +61,7 @@ inline void Masm::Untag(Register src) {


inline Operand& Masm::SpillToOperand(int index) {
spill_operand_.disp(- 8 * (index + 1));
spill_operand_.disp_ = - sizeof(this) * (index + 1);
return spill_operand_;
}

@@ -77,16 +99,16 @@ inline Condition Masm::BinOpToCondition(BinOp::BinOpType type,
}


inline void Masm::SpillSlot(uint32_t index, Operand& op) {
inline void Masm::SpillSlot(uint32_t index, Operand* op) {
#if CANDOR_ARCH_x64
op.base(rbp);
op->base_ = rbp;
#elif CANDOR_ARCH_ia32
op.base(ebp);
op->base_ = ebp;
#endif
op.disp(-spill_offset_ - HValue::kPointerSize * (index + 1));
op->disp_ = -spill_offset_ - HValue::kPointerSize * (index + 1);
}

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_MARCOASSEMBLER_INL_H_
#endif // _SRC_MARCOASSEMBLER_INL_H_
@@ -1,3 +1,25 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include "macroassembler.h"
#include "lir.h"
#include "lir-inl.h"
@@ -30,7 +52,7 @@ void Masm::Move(LUse* dst, Register src) {
}


void Masm::Move(LUse* dst, Operand& src) {
void Masm::Move(LUse* dst, const Operand& src) {
if (dst->is_register()) {
mov(dst->ToRegister(), src);
} else {
@@ -78,5 +100,5 @@ void AbsoluteAddress::NotifyGC() {
r_->notify_gc_ = true;
}

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor
@@ -1,11 +1,33 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_MARCOASSEMBLER_H_
#define _SRC_MARCOASSEMBLER_H_

#include "assembler.h"
#include "assembler-inl.h"
#include "ast.h" // AstNode
#include "code-space.h" // CodeSpace
#include "heap.h" // Heap::HeapTag and etc
#include "ast.h" // AstNode
#include "code-space.h" // CodeSpace
#include "heap.h" // Heap::HeapTag and etc
#include "heap-inl.h"

namespace candor {
@@ -17,15 +39,15 @@ class LUse;

class Masm : public Assembler {
public:
Masm(CodeSpace* space);
explicit Masm(CodeSpace* space);

// Save/restore all valuable register
void Pushad();
void Popad(Register preserve);

class Align {
public:
Align(Masm* masm);
explicit Align(Masm* masm);
~Align();
private:
Masm* masm_;
@@ -34,7 +56,7 @@ class Masm : public Assembler {

class Spill {
public:
Spill(Masm* masm);
explicit Spill(Masm* masm);
Spill(Masm* masm, Register src);
~Spill();

@@ -117,12 +139,12 @@ class Masm : public Assembler {
// Generic move, LIR augmentation
void Move(LUse* dst, LUse* src);
void Move(LUse* dst, Register src);
void Move(LUse* dst, Operand& src);
void Move(LUse* dst, const Operand& src);
void Move(LUse* dst, Immediate src);

// Sets correct environment and calls function
void Call(Register addr);
void Call(Operand& addr);
void Call(const Operand& addr);
void Call(char* stub);
void CallFunction(Register fn);
void ProbeCPU();
@@ -139,7 +161,7 @@ class Masm : public Assembler {
inline void Untag(Register src);
inline Operand& SpillToOperand(int index);
inline Condition BinOpToCondition(BinOp::BinOpType type, BinOpUsage usage);
inline void SpillSlot(uint32_t index, Operand& op);
inline void SpillSlot(uint32_t index, Operand* op);

inline Heap* heap() { return space_->heap(); }
inline Stubs* stubs() { return space_->stubs(); }
@@ -180,7 +202,7 @@ class AbsoluteAddress {
RelocationInfo* r_;
};

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_MARCOASSEMBLER_H_
#endif // _SRC_MARCOASSEMBLER_H_

Large diffs are not rendered by default.

@@ -1,13 +1,35 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_PARSER_H_
#define _SRC_PARSER_H_

#include <assert.h> // assert
#include <stdlib.h> // NULL

#include "lexer.h"
#include "ast.h"
#include "utils.h"

#include <assert.h> // assert
#include <stdlib.h> // NULL

namespace candor {
namespace internal {

@@ -39,7 +61,7 @@ class Parser : public Lexer, public ErrorHandler {
// Used to implement lookahead
class Position {
public:
Position(Lexer* lexer) : lexer_(lexer), committed_(false) {
explicit Position(Lexer* lexer) : lexer_(lexer), committed_(false) {
if (lexer_->queue()->length() == 0) {
offset_ = lexer_->offset_;
} else {
@@ -132,7 +154,7 @@ class Parser : public Lexer, public ErrorHandler {
int ast_id_;
};

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_PARSER_H_
#endif // _SRC_PARSER_H_
@@ -1,11 +1,35 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include "pic.h"
#include "heap.h" // HObject
#include "heap-inl.h"
#include "code-space.h" // CodeSpace
#include "stubs.h" // Stubs
#include "zone.h" // Zone

#include <string.h>

#include "heap.h" // HObject
#include "heap-inl.h"
#include "code-space.h" // CodeSpace
#include "stubs.h" // Stubs
#include "zone.h" // Zone

namespace candor {
namespace internal {

@@ -60,7 +84,7 @@ void PIC::Miss(char* object, intptr_t result, char* ip) {

char** call_ip = NULL;
// Search for correct IP to replace
for (size_t i = 3; i < 2 * sizeof(void*); i++) {
for (size_t i = 3; i < 2 * sizeof(ip); i++) {
char** iip = reinterpret_cast<char**>(ip - i);
if (*iip == chunk_->addr()) {
call_ip = iip;
@@ -109,5 +133,5 @@ void PIC::Miss(char* object, intptr_t result, char* ip) {
*call_ip = Generate();
}

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor
@@ -1,8 +1,30 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_PIC_H_
#define _SRC_PIC_H_

#include <unistd.h> // intptr_t
#include <stdint.h> // uint32_t
#include <unistd.h> // intptr_t
#include <stdint.h> // uint32_t

namespace candor {
namespace internal {
@@ -19,14 +41,13 @@ class PIC {
intptr_t result,
char* ip);

PIC(CodeSpace* space);
explicit PIC(CodeSpace* space);
~PIC();

char* Generate();
static void Miss(PIC* pic, char* object, intptr_t result, char* ip);

protected:

void Generate(Masm* masm);

void Miss(char* object, intptr_t result, char* ip);
@@ -41,7 +62,7 @@ class PIC {
int size_;
};

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_PIC_H_
#endif // _SRC_PIC_H_
@@ -1,9 +1,31 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include "root.h"
#include "scope.h" // ScopeSlot
#include "ast.h" // AstNode
#include "heap.h" // HContext
#include "scope.h" // ScopeSlot
#include "ast.h" // AstNode
#include "heap.h" // HContext
#include "heap-inl.h"
#include "utils.h" // List
#include "utils.h" // List

namespace candor {
namespace internal {
@@ -46,26 +68,26 @@ ScopeSlot* Root::Put(AstNode* node) {
char* value = HNil::New();

switch (node->type()) {
case AstNode::kNumber:
value = NumberToValue(node, &slot);
break;
case AstNode::kProperty:
case AstNode::kString:
value = StringToValue(node);
break;
case AstNode::kTrue:
value = heap()->CreateBoolean(true);
break;
case AstNode::kFalse:
value = heap()->CreateBoolean(false);
break;
case AstNode::kNil:
{
slot = new ScopeSlot(ScopeSlot::kContext, -2);
slot->type(ScopeSlot::kImmediate);
slot->value(HNil::New());
}
default: UNEXPECTED break;
case AstNode::kNumber:
value = NumberToValue(node, &slot);
break;
case AstNode::kProperty:
case AstNode::kString:
value = StringToValue(node);
break;
case AstNode::kTrue:
value = heap()->CreateBoolean(true);
break;
case AstNode::kFalse:
value = heap()->CreateBoolean(false);
break;
case AstNode::kNil:
{
slot = new ScopeSlot(ScopeSlot::kContext, -2);
slot->type(ScopeSlot::kImmediate);
slot->value(HNil::New());
}
default: UNEXPECTED break;
}

if (slot != NULL) return slot;
@@ -112,5 +134,5 @@ HContext* Root::Allocate() {
return HValue::As<HContext>(HContext::New(heap(), values()));
}

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor
@@ -1,8 +1,30 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_ROOT_H_
#define _SRC_ROOT_H_

#include "utils.h" // List
#include "zone.h" // ZoneObject
#include "utils.h" // List
#include "zone.h" // ZoneObject

namespace candor {
namespace internal {
@@ -17,7 +39,7 @@ class Root {
public:
typedef ZoneList<char*> HValueList;

Root(Heap* heap);
explicit Root(Heap* heap);

ScopeSlot* Put(AstNode* node);
HContext* Allocate();
@@ -35,7 +57,7 @@ class Root {
ZoneMap<NumberKey, ScopeSlot, ZoneObject> map_;
};

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_ROOT_H_
#endif // _SRC_ROOT_H_

Large diffs are not rendered by default.

@@ -1,13 +1,35 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_RUNTIME_H_
#define _SRC_RUNTIME_H_

#include "heap.h" // Heap, Heap::HeapTag
#include "heap-inl.h"
#include "ast.h" // BinOp
#include <stdint.h> // uint32_t
#include <unistd.h> // intptr_t
#include <sys/types.h> // size_t

#include <stdint.h> // uint32_t
#include <unistd.h> // intptr_t
#include <sys/types.h> // size_t
#include "heap.h" // Heap, Heap::HeapTag
#include "heap-inl.h"
#include "ast.h" // BinOp

namespace candor {
namespace internal {
@@ -75,7 +97,7 @@ void RuntimeDeleteProperty(Heap* heap, char* obj, char* property);
typedef char* (*RuntimeStackTraceCallback)(Heap* heap, char** frame, char* ip);
char* RuntimeStackTrace(Heap* heap, char** frame, char* ip);

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_RUNTIME_H_
#endif // _SRC_RUNTIME_H_
@@ -1,8 +1,31 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include "scope.h"
#include "ast.h" // AstNode, AstList

#include <assert.h>

#include "ast.h" // AstNode, AstList

namespace candor {
namespace internal {

@@ -278,5 +301,5 @@ void ScopeAnalyze::VisitChildren(AstNode* node) {
if (node->is(AstNode::kFunction)) queue_ = old;
}

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor
@@ -1,11 +1,33 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_SCOPE_H_
#define _SRC_SCOPE_H_

#include "utils.h" // HashMap
#include "zone.h" // HashMap
#include "visitor.h" // Visitor
#include <assert.h> // assert

#include <assert.h> // assert
#include "utils.h" // HashMap
#include "zone.h" // HashMap
#include "visitor.h" // Visitor

namespace candor {
namespace internal {
@@ -28,11 +50,11 @@ class ScopeSlot : public ZoneObject {
kImmediate
};

ScopeSlot(Type type) : type_(type),
value_(NULL),
index_(-1),
depth_(0),
use_count_(0) {
explicit ScopeSlot(Type type) : type_(type),
value_(NULL),
index_(-1),
depth_(0),
use_count_(0) {
}

ScopeSlot(Type type, int32_t depth) : type_(type),
@@ -55,8 +77,14 @@ class ScopeSlot : public ZoneObject {
}

// Register slots should have a value (unboxed nil or number)
inline char* value() { assert(is_immediate()); return value_; }
inline void value(char* value) { assert(is_immediate()); value_ = value; }
inline char* value() {
assert(is_immediate());
return value_;
}
inline void value(char* value) {
assert(is_immediate());
value_ = value;
}

inline int32_t index() { return index_; }
inline void index(int32_t index) { index_ = index; }
@@ -123,7 +151,7 @@ class Scope : public ZoneMap<StringKey<ZoneObject>, ScopeSlot, ZoneObject> {
// and put it either in stack or in some context
class ScopeAnalyze : public Visitor<AstNode> {
public:
ScopeAnalyze(AstNode* ast);
explicit ScopeAnalyze(AstNode* ast);

AstNode* VisitFunction(AstNode* node);
AstNode* VisitCall(AstNode* node);
@@ -139,7 +167,7 @@ class ScopeAnalyze : public Visitor<AstNode> {
friend class Scope;
};

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_SCOPE_H_
#endif // _SRC_SCOPE_H_
@@ -1,9 +1,32 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include "source-map.h"
#include "utils.h" // HashMap

#include <stdlib.h> // NULL
#include <unistd.h> // intptr_t
#include <stdint.h> // uint32_t
#include <stdlib.h> // NULL
#include <unistd.h> // intptr_t
#include <stdint.h> // uint32_t

#include "utils.h" // HashMap

namespace candor {
namespace internal {
@@ -38,5 +61,5 @@ SourceInfo* SourceMap::Get(char* addr) {
return SourceMapBase::Find(NumberKey::New(addr_o));
}

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor
@@ -1,8 +1,30 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_SOURCE_MAP_H_
#define _SRC_SOURCE_MAP_H_

#include "utils.h" // HashMap
#include "splay-tree.h" // HashMap
#include "utils.h" // HashMap
#include "splay-tree.h" // HashMap

namespace candor {
namespace internal {
@@ -62,7 +84,7 @@ class SourceInfo {
const uint32_t jit_offset_;
};

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_SOURCE_MAP_H_
#endif // _SRC_SOURCE_MAP_H_
@@ -1,3 +1,25 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_SPLAY_TREE_H_
#define _SRC_SPLAY_TREE_H_

@@ -201,7 +223,7 @@ class SplayTree {
Item* root_;
};

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_SPLAY_TREE_H_
#endif // _SRC_SPLAY_TREE_H_
@@ -1,15 +1,36 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_STUBS_H_
#define _SRC_STUBS_H_

#include "macroassembler.h" // Masm
#include "macroassembler-inl.h"

#include "code-space.h" // CodeSpace
#include "zone.h" // Zone
#include "ast.h" // BinOpType
#include <stdlib.h> // NULL
#include <stdint.h> // uint32_t

#include <stdlib.h> // NULL
#include <stdint.h> // uint32_t
#include "macroassembler.h" // Masm
#include "macroassembler-inl.h"
#include "code-space.h" // CodeSpace
#include "zone.h" // Zone
#include "ast.h" // BinOpType

namespace candor {
namespace internal {
@@ -71,6 +92,8 @@ class BaseStub {
};

BaseStub(CodeSpace* space, StubType type);
virtual ~BaseStub() {
}

void GeneratePrologue();
void GenerateEpilogue(int args = 0);
@@ -100,7 +123,7 @@ STUBS_LIST(STUB_CLASS_DECL)

class BinOpStub : public BaseStub {
public:
// TODO: Use some type instead of kNone
// TODO(indutny): Use some type instead of kNone
BinOpStub(CodeSpace* space, BinOp::BinOpType type) :
BaseStub(space, kNone), type_(type) {
}
@@ -143,7 +166,7 @@ BINARY_STUBS_LIST(BINARY_STUB_CLASS_DECL)

class Stubs {
public:
Stubs(CodeSpace* space) : space_(space) {
explicit Stubs(CodeSpace* space) : space_(space) {
STUBS_LIST(STUB_PROPERTY_INIT)
BINARY_STUBS_LIST(BINARY_STUB_PROPERTY_INIT)
}
@@ -170,7 +193,7 @@ class Stubs {
#undef STUBS_LIST
#undef BINARY_STUBS_LIST

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_STUBS_H_
#endif // _SRC_STUBS_H_
@@ -1,18 +1,43 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_UTILS_H_
#define _SRC_UTILS_H_

#include <stdlib.h> // NULL
#include <stdarg.h> // va_list
#include <stdint.h> // uint32_t
#include <stdio.h> // fprintf, vsnprintf
#include <string.h> // strncmp, memset
#include <unistd.h> // sysconf or getpagesize, intptr_t
#include <assert.h> // assert
#include <stdlib.h> // NULL
#include <stdarg.h> // va_list
#include <stdint.h> // uint32_t
#include <stdio.h> // fprintf, vsnprintf
#include <string.h> // strncmp, memset
#include <unistd.h> // sysconf or getpagesize, intptr_t
#include <assert.h> // assert

namespace candor {
namespace internal {

#define UNEXPECTED { assert(0 && "Unexpected"); abort(); }
#define UNEXPECTED { \
assert(0 && "Unexpected"); \
abort(); \
}

inline uint32_t ComputeHash(int64_t key) {
uint32_t hash = 0;
@@ -141,7 +166,7 @@ class GenericList {
public:
class Item : public ItemParent {
public:
Item(T value) : value_(value), prev_(NULL), next_(NULL) {
explicit Item(T value) : value_(value), prev_(NULL), next_(NULL) {
}

inline T value() { return value_; }
@@ -168,12 +193,10 @@ class GenericList {
GenericList() : head_(NULL), tail_(NULL), length_(0) {
}


~GenericList() {
while (length() > 0) Policy::Delete(Shift());
}


inline void Push(T item) {
Item* next = new Item(item);
next->prev_ = tail_;
@@ -188,7 +211,6 @@ class GenericList {
length_++;
}


inline void Remove(Item* item) {
if (tail_ == item) tail_ = item->prev_;
if (head_ == item) head_ = item->next_;
@@ -200,7 +222,6 @@ class GenericList {
length_--;
}


inline void Unshift(T item) {
Item* next = new Item(item);

@@ -214,7 +235,6 @@ class GenericList {
length_++;
}


inline void InsertBefore(Item* next, T value) {
Item* item = new Item(value);

@@ -230,7 +250,6 @@ class GenericList {
length_++;
}


// Sorted insertion
template <class Shape>
inline void InsertSorted(T value) {
@@ -250,7 +269,6 @@ class GenericList {
InsertBefore(insert_node, value);
}


inline T Pop() {
if (tail_ == NULL) return NULL;

@@ -267,7 +285,6 @@ class GenericList {
return value;
}


inline T Shift() {
if (head_ == NULL) return NULL;

@@ -284,7 +301,6 @@ class GenericList {
return value;
}


// Quicksort
template <class Shape>
inline void Sort() {
@@ -302,7 +318,6 @@ class GenericList {
}
}


inline Item* head() { return head_; }
inline Item* tail() { return tail_; }
inline int32_t length() { return length_; }
@@ -441,7 +456,6 @@ class GenericHashMap {
current_ = next;
}


inline Value* Get(Key* key) {
uint32_t index = Key::Hash(key) & mask_;
Item* i = map_[index];
@@ -456,7 +470,6 @@ class GenericHashMap {
return NULL;
}


inline void RemoveOne(Key* key) {
uint32_t index = Key::Hash(key) & mask_;
Item* i = map_[index];
@@ -494,7 +507,6 @@ class GenericHashMap {
}
}


inline void Enumerate(EnumerateCallback cb) {
Item* i = head_;

@@ -573,7 +585,7 @@ class FreeList {

inline void Remove(T value) {
for (int i = 0; i < length_; i++) {
// TODO: Use Shape class here
// TODO(indutny): Use Shape class here
if (list_[i] != value) continue;

// Shift all registers to the left
@@ -589,7 +601,7 @@ class FreeList {

inline bool Has(T value) {
for (int i = 0; i < length_; i++) {
// TODO: Use Shape class here
// TODO(indutny): Use Shape class here
if (list_[i] == value) return true;
}

@@ -604,7 +616,7 @@ class FreeList {
template <class Base>
class BitField : public Base {
public:
BitField(int size) : size_(size / 32) {
explicit BitField(int size) : size_(size / 32) {
space_ = new uint32_t[size_];
memset(space_, 0, sizeof(*space_) * size_);
}
@@ -697,7 +709,7 @@ class PrintBuffer {
total_(0) {
}

PrintBuffer(FILE* out) : out_(out) {
explicit PrintBuffer(FILE* out) : out_(out) {
}

bool Print(const char* format, ...) {
@@ -821,28 +833,28 @@ inline bool is_hex(const char c) {

inline int hex_to_num(const char c) {
switch (c) {
case '0': return 0;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
case 'a': return 10;
case 'b': return 11;
case 'c': return 12;
case 'd': return 13;
case 'e': return 14;
case 'f': return 15;
case 'A': return 10;
case 'B': return 11;
case 'C': return 12;
case 'D': return 13;
case 'E': return 14;
case 'F': return 15;
case '0': return 0;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
case 'a': return 10;
case 'b': return 11;
case 'c': return 12;
case 'd': return 13;
case 'e': return 14;
case 'f': return 15;
case 'A': return 10;
case 'B': return 11;
case 'C': return 12;
case 'D': return 13;
case 'E': return 14;
case 'F': return 15;
}
return 0;
}
@@ -965,7 +977,7 @@ inline uint32_t GetPageSize() {
#endif
}

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_UTILS_H_
#endif // _SRC_UTILS_H_
@@ -1,13 +1,35 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include "visitor.h"
#include "ast.h"
#include "hir.h"
#include "hir-instructions.h" // HIRInstruction
#include "hir-instructions-inl.h" // HIRInstruction
#include "hir-instructions.h" // HIRInstruction
#include "hir-instructions-inl.h" // HIRInstruction
#include "fullgen.h"
#include "fullgen-instructions.h" // FInstruction
#include "fullgen-instructions-inl.h" // FInstruction
#include "utils.h" // List
#include "zone.h" // ZoneObject
#include "fullgen-instructions.h" // FInstruction
#include "fullgen-instructions-inl.h" // FInstruction
#include "utils.h" // List
#include "zone.h" // ZoneObject

namespace candor {
namespace internal {
@@ -39,11 +61,11 @@ T* Visitor<T>::Visit(AstNode* node) {
current_node_ = node;

switch (node->type()) {
VISITOR_MAPPING_BLOCK(VISITOR_SWITCH, 0)
VISITOR_MAPPING_REGULAR(VISITOR_SWITCH, 0)
default:
VisitChildren(node);
return NULL;
VISITOR_MAPPING_BLOCK(VISITOR_SWITCH, 0)
VISITOR_MAPPING_REGULAR(VISITOR_SWITCH, 0)
default:
VisitChildren(node);
return NULL;
}
}

@@ -79,5 +101,5 @@ void Visitor<T>::VisitChildren(AstNode* node) {
VISITOR_MAPPING_BLOCK(VISITOR_BLOCK_STUB, 0)
VISITOR_MAPPING_REGULAR(VISITOR_REGULAR_STUB, 0)

} // namespace internal
} // namescape candor
} // namespace internal
} // namescape candor
@@ -1,8 +1,30 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_VISITOR_H_
#define _SRC_VISITOR_H_

#include "utils.h"
#include "zone.h" // ZoneList
#include "zone.h" // ZoneList

namespace candor {
namespace internal {
@@ -60,7 +82,9 @@ class Visitor {
kBreadthFirst
};

Visitor(Type type) : type_(type), queue_(NULL) {
explicit Visitor(Type type) : type_(type), queue_(NULL) {
}
virtual ~Visitor() {
}

virtual T* Visit(AstNode* node);
@@ -106,7 +130,7 @@ class Visitor {
ZoneList<ZoneList<AstNode*>::Item*>* queue_;
};

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_VISITOR_H_
#endif // _SRC_VISITOR_H_
@@ -1,11 +1,33 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_X64_ASSEMBLER_INL_H_
#define _SRC_X64_ASSEMBLER_INL_H_

#include "assembler.h"

#include <assert.h> // assert
#include <string.h> // memcpy, memset
#include <stdlib.h> // NULL
#include <assert.h> // assert
#include <string.h> // memcpy, memset
#include <stdlib.h> // NULL

namespace candor {
namespace internal {
@@ -20,7 +42,7 @@ inline void Assembler::emit_rexw(Register dst) {
}


inline void Assembler::emit_rexw(Operand& dst) {
inline void Assembler::emit_rexw(const Operand& dst) {
emitb(0x48 | dst.base().high() << 2);
}

@@ -30,12 +52,12 @@ inline void Assembler::emit_rexw(Register dst, Register src) {
}


inline void Assembler::emit_rexw(Register dst, Operand& src) {
inline void Assembler::emit_rexw(Register dst, const Operand& src) {
emitb(0x48 | dst.high() << 2 | src.base().high());
}


inline void Assembler::emit_rexw(Operand& dst, Register src) {
inline void Assembler::emit_rexw(const Operand& dst, Register src) {
emitb(0x48 | dst.base().high() << 2 | src.high());
}

@@ -55,7 +77,7 @@ inline void Assembler::emit_rexw(Register dst, DoubleRegister src) {
}


inline void Assembler::emit_rexw(DoubleRegister dst, Operand& src) {
inline void Assembler::emit_rexw(DoubleRegister dst, const Operand& src) {
emitb(0x48 | dst.high() << 2 | src.base().high());
}

@@ -65,7 +87,7 @@ inline void Assembler::emit_modrm(Register dst) {
}


inline void Assembler::emit_modrm(Operand &dst) {
inline void Assembler::emit_modrm(const Operand &dst) {
if (dst.scale() == Operand::one) {
if (dst.byte_disp()) {
emitb(0x40 | dst.base().low());
@@ -75,7 +97,7 @@ inline void Assembler::emit_modrm(Operand &dst) {
emitl(dst.disp());
}
} else {
// TODO: Support scales
// TODO(indutny): Support scales
}
}

@@ -85,7 +107,7 @@ inline void Assembler::emit_modrm(Register dst, Register src) {
}


inline void Assembler::emit_modrm(Register dst, Operand& src) {
inline void Assembler::emit_modrm(Register dst, const Operand& src) {
if (src.scale() == Operand::one) {
if (src.byte_disp()) {
emitb(0x40 | dst.low() << 3 | src.base().low());
@@ -104,7 +126,7 @@ inline void Assembler::emit_modrm(Register dst, uint32_t op) {
}


inline void Assembler::emit_modrm(Operand& dst, uint32_t op) {
inline void Assembler::emit_modrm(const Operand& dst, uint32_t op) {
if (dst.byte_disp()) {
emitb(0x40 | op << 3 | dst.base().low());
emitb(dst.disp());
@@ -130,7 +152,7 @@ inline void Assembler::emit_modrm(DoubleRegister dst, DoubleRegister src) {
}


inline void Assembler::emit_modrm(DoubleRegister dst, Operand& src) {
inline void Assembler::emit_modrm(DoubleRegister dst, const Operand& src) {
if (src.byte_disp()) {
emitb(0x40 | dst.low() << 3 | src.base().low());
emitb(src.disp());
@@ -141,7 +163,7 @@ inline void Assembler::emit_modrm(DoubleRegister dst, Operand& src) {
}


inline void Assembler::emit_modrm(Operand& dst, DoubleRegister src) {
inline void Assembler::emit_modrm(const Operand& dst, DoubleRegister src) {
if (dst.byte_disp()) {
emitb(0x40 | dst.base().low() | src.low() << 3);
emitb(dst.disp());
@@ -179,7 +201,7 @@ inline void Assembler::emitq(uint64_t v) {
Grow();
}

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_X64_ASSEMBLER_INL_H_
#endif // _SRC_X64_ASSEMBLER_INL_H_

Large diffs are not rendered by default.

@@ -1,18 +1,41 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_X64_ASSEMBLER_H_
#define _SRC_X64_ASSEMBLER_H_

#include <stdint.h> // uint32_t
#include <stdlib.h> // NULL
#include <string.h> // memset
#include <stdint.h> // uint32_t
#include <stdlib.h> // NULL
#include <string.h> // memset

#include "zone.h" // ZoneObject
#include "utils.h" // List
#include "zone.h" // ZoneObject
#include "utils.h" // List

namespace candor {
namespace internal {

// Forward declaration
class Assembler;
class Masm;
class Heap;
class Label;

@@ -71,53 +94,53 @@ const Register scratch = r14;
static inline Register RegisterByIndex(int index) {
// rsi, rdi, r14, r15 are reserved
switch (index) {
case 0: return rax;
case 1: return rbx;
case 2: return rcx;
case 3: return rdx;
case 4: return r8;
case 5: return r9;
case 6: return r10;
case 7: return r11;
case 8: return r12;
case 9: return r13;
default: UNEXPECTED return reg_nil;
case 0: return rax;
case 1: return rbx;
case 2: return rcx;
case 3: return rdx;
case 4: return r8;
case 5: return r9;
case 6: return r10;
case 7: return r11;
case 8: return r12;
case 9: return r13;
default: UNEXPECTED return reg_nil;
}
}


static inline const char* RegisterNameByIndex(int index) {
// rsi, rdi, r14, r15 are reserved
switch (index) {
case 0: return "rax";
case 1: return "rbx";
case 2: return "rcx";
case 3: return "rdx";
case 4: return "r8 ";
case 5: return "r9 ";
case 6: return "r10";
case 7: return "r11";
case 8: return "r12";
case 9: return "r13";
default: UNEXPECTED return "rnil";
case 0: return "rax";
case 1: return "rbx";
case 2: return "rcx";
case 3: return "rdx";
case 4: return "r8 ";
case 5: return "r9 ";
case 6: return "r10";
case 7: return "r11";
case 8: return "r12";
case 9: return "r13";
default: UNEXPECTED return "rnil";
}
}


static inline int IndexByRegister(Register reg) {
// rsi, rdi, r14, r15 are reserved
switch (reg.code()) {
case 0: return 0;
case 1: return 2;
case 2: return 3;
case 3: return 1;
case 8: return 4;
case 9: return 5;
case 10: return 6;
case 11: return 7;
case 12: return 8;
case 13: return 9;
default: UNEXPECTED return -1;
case 0: return 0;
case 1: return 2;
case 2: return 3;
case 3: return 1;
case 8: return 4;
case 9: return 5;
case 10: return 6;
case 11: return 7;
case 12: return 8;
case 13: return 9;
default: UNEXPECTED return -1;
}
}

@@ -171,16 +194,17 @@ const DoubleRegister fscratch = xmm11;

class Immediate : public ZoneObject {
public:
Immediate(uint64_t value) : value_(value) {
const Immediate(uint64_t value) : value_(value) {
}

inline uint64_t value() { return value_; }
inline bool is64() { return value_ > 0xffffffff; }
inline uint64_t value() const { return value_; }
inline bool is64() const { return value_ > 0xffffffff; }

private:
uint64_t value_;

friend class Assembler;
friend class Masm;
};

class Operand : public ZoneObject {
@@ -201,21 +225,19 @@ class Operand : public ZoneObject {
disp_(disp) {
}

inline Register base() { return base_; }
inline Scale scale() { return scale_; }
inline int32_t disp() { return disp_; }
inline Register base() const { return base_; }
inline Scale scale() const { return scale_; }
inline int32_t disp() const { return disp_; }

inline Register base(Register base) { return base_ = base; }
inline Scale scale(Scale scale) { return scale_ = scale; }
inline int32_t disp(int32_t disp) { return disp_ = disp; }
inline bool byte_disp() { return disp() > -128 && disp() < 128; }
inline bool byte_disp() const { return disp() > -128 && disp() < 128; }

private:
Register base_;
Scale scale_;
int32_t disp_;

friend class Assembler;
friend class Masm;
};

class RelocationInfo : public ZoneObject {
@@ -303,9 +325,9 @@ class Assembler {
void cpuid();

void push(Register src);
void push(Operand& src);
void push(Immediate imm);
void pushb(Immediate imm);
void push(const Operand& src);
void push(const Immediate imm);
void pushb(const Immediate imm);
void pop(Register dst);
void ret(uint16_t imm);

@@ -314,69 +336,69 @@ class Assembler {
void jmp(Condition cond, Label* label);

void cmpq(Register dst, Register src);
void cmpq(Register dst, Operand& src);
void cmpq(Register dst, Immediate src);
void cmpqb(Register dst, Immediate src);
void cmpq(Operand& dst, Immediate src);
void cmpb(Register dst, Operand& src);
void cmpb(Register dst, Immediate src);
void cmpb(Operand& dst, Immediate src);
void cmpq(Register dst, const Operand& src);
void cmpq(Register dst, const Immediate src);
void cmpqb(Register dst, const Immediate src);
void cmpq(const Operand& dst, const Immediate src);
void cmpb(Register dst, const Operand& src);
void cmpb(Register dst, const Immediate src);
void cmpb(const Operand& dst, const Immediate src);

void testb(Register dst, Immediate src);
void testl(Register dst, Immediate src);
void testb(Register dst, const Immediate src);
void testl(Register dst, const Immediate src);

void mov(Register dst, Register src);
void mov(Register dst, Operand& src);
void mov(Operand& dst, Register src);
void mov(Register dst, Immediate src);
void mov(Operand& dst, Immediate src);
void movl(Register dst, Immediate src);
void movl(Operand& dst, Immediate src);
void movb(Register dst, Immediate src);
void movb(Operand& dst, Immediate src);
void movb(Operand& dst, Register src);
void movzxb(Register dst, Operand& src);
void mov(Register dst, const Operand& src);
void mov(const Operand& dst, Register src);
void mov(Register dst, const Immediate src);
void mov(const Operand& dst, const Immediate src);
void movl(Register dst, const Immediate src);
void movl(const Operand& dst, const Immediate src);
void movb(Register dst, const Immediate src);
void movb(const Operand& dst, const Immediate src);
void movb(const Operand& dst, Register src);
void movzxb(Register dst, const Operand& src);

void xchg(Register dst, Register src);

void addq(Register dst, Register src);
void addl(Register dst, Register src);
void addq(Register dst, Operand& src);
void addq(Register dst, Immediate src);
void addqb(Register dst, Immediate src);
void addq(Register dst, const Operand& src);
void addq(Register dst, const Immediate src);
void addqb(Register dst, const Immediate src);
void subq(Register dst, Register src);
void subq(Register dst, Immediate src);
void subqb(Register dst, Immediate src);
void subq(Register dst, const Immediate src);
void subqb(Register dst, const Immediate src);
void imulq(Register src);
void idivq(Register src);

void andq(Register dst, Register src);
void orq(Register dst, Register src);
void orqb(Register dst, Immediate src);
void orqb(Register dst, const Immediate src);
void xorq(Register dst, Register src);
void xorl(Register dst, Register src);

void inc(Register dst);
void dec(Register dst);
void shl(Register dst, Immediate src);
void shr(Register dst, Immediate src);
void shll(Register dst, Immediate src);
void shrl(Register dst, Immediate src);
void shl(Register dst, const Immediate src);
void shr(Register dst, const Immediate src);
void shll(Register dst, const Immediate src);
void shrl(Register dst, const Immediate src);
void shl(Register dst);
void shr(Register dst);
void sal(Register dst, Immediate src);
void sar(Register dst, Immediate src);
void sal(Register dst, const Immediate src);
void sar(Register dst, const Immediate src);
void sal(Register dst);
void sar(Register dst);

void callq(Register dst);
void callq(Operand& dst);
void callq(const Operand& dst);

// Floating point instructions
void movd(DoubleRegister dst, Register src);
void movd(DoubleRegister dst, Operand& src);
void movd(DoubleRegister dst, const Operand& src);
void movd(Register dst, DoubleRegister src);
void movd(Operand& dst, DoubleRegister src);
void movd(const Operand& dst, DoubleRegister src);
void addqd(DoubleRegister dst, DoubleRegister src);
void subqd(DoubleRegister dst, DoubleRegister src);
void mulqd(DoubleRegister dst, DoubleRegister src);
@@ -387,31 +409,31 @@ class Assembler {
void cvttsd2si(Register dst, DoubleRegister src);
void roundsd(DoubleRegister dst, DoubleRegister src, RoundMode mode);
void ucomisd(DoubleRegister dst, DoubleRegister src);
void cmpd(DoubleRegister dst, Immediate src);
void cmpd(DoubleRegister dst, const Immediate src);

// Routines
inline void emit_rex_if_high(Register src);
inline void emit_rexw(Register dst);
inline void emit_rexw(Operand& dst);
inline void emit_rexw(const Operand& dst);
inline void emit_rexw(Register dst, Register src);
inline void emit_rexw(Register dst, Operand& src);
inline void emit_rexw(Operand& dst, Register src);
inline void emit_rexw(Register dst, const Operand& src);
inline void emit_rexw(const Operand& dst, Register src);
inline void emit_rexw(DoubleRegister dst, Register src);
inline void emit_rexw(DoubleRegister dst, DoubleRegister src);
inline void emit_rexw(Register dst, DoubleRegister src);
inline void emit_rexw(DoubleRegister dst, Operand& src);
inline void emit_rexw(DoubleRegister dst, const Operand& src);

inline void emit_modrm(Register dst);
inline void emit_modrm(Operand &dst);
inline void emit_modrm(const Operand &dst);
inline void emit_modrm(Register dst, Register src);
inline void emit_modrm(Register dst, Operand& src);
inline void emit_modrm(Register dst, const Operand& src);
inline void emit_modrm(Register dst, uint32_t op);
inline void emit_modrm(Operand& dst, uint32_t op);
inline void emit_modrm(const Operand& dst, uint32_t op);
inline void emit_modrm(DoubleRegister dst, Register src);
inline void emit_modrm(Register dst, DoubleRegister src);
inline void emit_modrm(DoubleRegister dst, DoubleRegister src);
inline void emit_modrm(DoubleRegister dst, Operand& src);
inline void emit_modrm(Operand& dst, DoubleRegister src);
inline void emit_modrm(DoubleRegister dst, const Operand& src);
inline void emit_modrm(const Operand& dst, DoubleRegister src);

inline void emitb(uint8_t v);
inline void emitw(uint16_t v);
@@ -434,7 +456,7 @@ class Assembler {
ZoneList<RelocationInfo*> gc_info_;
};

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_X64_ASSEMBLER_H_
#endif // _SRC_X64_ASSEMBLER_H_
@@ -1,3 +1,25 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include "fullgen.h"
#include "fullgen-inl.h"
#include "fullgen-instructions.h"
@@ -309,8 +331,8 @@ void FBinOp::Generate(Masm* masm) {
char* stub = NULL;

switch (sub_type_) {
BINARY_SUB_TYPES(BINARY_SUB_ENUM)
default: UNEXPECTED
BINARY_SUB_TYPES(BINARY_SUB_ENUM)
default: UNEXPECTED
}

assert(stub != NULL);
@@ -522,5 +544,5 @@ void FGetStackTrace::Generate(Masm* masm) {
__ mov(*result->ToOperand(), rax);
}

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor
@@ -1,3 +1,25 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include "lir.h"
#include "lir-inl.h"
#include "lir-instructions.h"
@@ -285,5 +307,5 @@ void LGen::VisitIf(HIRInstruction* instr) {
}


} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor
@@ -1,10 +1,33 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include <unistd.h> // intptr_t

#include "lir.h"
#include "lir-inl.h"
#include "lir-instructions.h"
#include "lir-instructions-inl.h"
#include "macroassembler.h"
#include "stubs.h" // Stubs
#include <unistd.h> // intptr_t
#include "stubs.h" // Stubs

namespace candor {
namespace internal {
@@ -251,8 +274,8 @@ void LBinOp::Generate(Masm* masm) {
char* stub = NULL;

switch (HIRBinOp::Cast(hir())->binop_type()) {
BINARY_SUB_TYPES(BINARY_SUB_ENUM)
default: UNEXPECTED
BINARY_SUB_TYPES(BINARY_SUB_ENUM)
default: UNEXPECTED
}

assert(stub != NULL);
@@ -279,18 +302,18 @@ void LBinOpNumber::Generate(Masm* masm) {
__ mov(scratch, left);

switch (type) {
case BinOp::kAdd:
__ addq(left, right);
break;
case BinOp::kSub:
__ subq(left, right);
break;
case BinOp::kMul:
__ Untag(left);
__ imulq(right);
break;
default:
UNEXPECTED
case BinOp::kAdd:
__ addq(left, right);
break;
case BinOp::kSub:
__ subq(left, right);
break;
case BinOp::kMul:
__ Untag(left);
__ imulq(right);
break;
default:
UNEXPECTED
}

__ jmp(kNoOverflow, &done);
@@ -302,8 +325,8 @@ void LBinOpNumber::Generate(Masm* masm) {

char* stub = NULL;
switch (type) {
BINARY_SUB_TYPES(BINARY_SUB_ENUM)
default: UNEXPECTED
BINARY_SUB_TYPES(BINARY_SUB_ENUM)
default: UNEXPECTED
}
assert(stub != NULL);

@@ -571,5 +594,5 @@ void LGetStackTrace::Generate(Masm* masm) {
__ Call(masm->stubs()->GetStackTraceStub());
}

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor
@@ -1,3 +1,25 @@
/**
* Copyright (c) 2012, Fedor Indutny.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _SRC_X64_LIR_X64_H_
#define _SRC_X64_LIR_X64_H_

@@ -9,7 +31,7 @@ namespace internal {

const int kLIRRegisterCount = 10;

} // namespace internal
} // namespace candor
} // namespace internal
} // namespace candor

#endif // _SRC_X64_LIR_X64_H_
#endif // _SRC_X64_LIR_X64_H_