Compare commits

..

6 Commits

Author SHA1 Message Date
warren%netscape.com
1cee4e9073 Fixed up whitespace.
git-svn-id: svn://10.0.0.236/branches/OJINetworkChanges_BRANCH@11636 18797224-902f-48f8-a5cc-f745e15eee43
1998-10-01 02:55:46 +00:00
(no author)
93a3bbce56 This commit was manufactured by cvs2svn to create branch
'OJINetworkChanges_BRANCH'.

git-svn-id: svn://10.0.0.236/branches/OJINetworkChanges_BRANCH@11594 18797224-902f-48f8-a5cc-f745e15eee43
1998-09-30 20:55:14 +00:00
warren%netscape.com
e0dd53369a Broke out LiveConnect callbacks into separate file.
git-svn-id: svn://10.0.0.236/branches/OJINetworkChanges_BRANCH@11592 18797224-902f-48f8-a5cc-f745e15eee43
1998-09-30 20:55:12 +00:00
warren%netscape.com
6c8b3ae9ee Removed accessor ifdefs
git-svn-id: svn://10.0.0.236/branches/OJINetworkChanges_BRANCH@11537 18797224-902f-48f8-a5cc-f745e15eee43
1998-09-30 05:35:58 +00:00
warren%netscape.com
283fb8c0df OJI Networking changes.
git-svn-id: svn://10.0.0.236/branches/OJINetworkChanges_BRANCH@11536 18797224-902f-48f8-a5cc-f745e15eee43
1998-09-30 05:32:57 +00:00
(no author)
9348bf6f5d This commit was manufactured by cvs2svn to create branch
'OJINetworkChanges_BRANCH'.

git-svn-id: svn://10.0.0.236/branches/OJINetworkChanges_BRANCH@11534 18797224-902f-48f8-a5cc-f745e15eee43
1998-09-30 05:29:49 +00:00
201 changed files with 36288 additions and 5166 deletions

View File

@@ -1,134 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "Fundamentals.h"
#include "BitSet.h"
// Return the next bit after index set to true or -1 if none.
//
Int32 BitSet::nextOne(Int32 pos) const
{
++pos;
if (pos < 0 || Uint32(pos) >= universeSize)
return -1;
Uint32 offset = getWordOffset(pos);
Uint8 index = getBitOffset(pos);
Word* ptr = &word[offset];
Word currentWord = *ptr++ >> index;
if (currentWord != Word(0)) {
while ((currentWord & Word(1)) == 0) {
++index;
currentWord >>= 1;
}
return (offset << nBitsInWordLog2) + index;
}
Word* limit = &word[getSizeInWords(universeSize)];
while (ptr < limit) {
++offset;
currentWord = *ptr++;
if (currentWord != Word(0)) {
index = 0;
while ((currentWord & Word(1)) == 0) {
++index;
currentWord >>= 1;
}
return (offset << nBitsInWordLog2) + index;
}
}
return -1;
}
// Return the next bit after index set to false or -1 if none.
//
Int32 BitSet::nextZero(Int32 pos) const
{
++pos;
if (pos < 0 || Uint32(pos) >= universeSize)
return -1;
Uint32 offset = getWordOffset(pos);
Uint8 index = getBitOffset(pos);
Word* ptr = &word[offset];
Word currentWord = *ptr++ >> index;
if (currentWord != Word(~0)) {
for (; index < nBitsInWord; ++index) {
if ((currentWord & Word(1)) == 0) {
Int32 ret = (offset << nBitsInWordLog2) + index;
return (Uint32(ret) < universeSize) ? ret : -1;
}
currentWord >>= 1;
}
}
Word* limit = &word[getSizeInWords(universeSize)];
while (ptr < limit) {
++offset;
currentWord = *ptr++;
if (currentWord != Word(~0)) {
for (index = 0; index < nBitsInWord; ++index) {
if ((currentWord & Word(1)) == 0) {
Int32 ret = (offset << nBitsInWordLog2) + index;
return (Uint32(ret) < universeSize) ? ret : -1;
}
currentWord >>= 1;
}
}
}
return -1;
}
#ifdef DEBUG_LOG
// Print the set.
//
void BitSet::printPretty(LogModuleObject log)
{
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("[ "));
for (Int32 i = firstOne(); i != -1; i = nextOne(i)) {
Int32 currentBit = i;
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("%d", currentBit));
Int32 nextBit = nextOne(currentBit);
if (nextBit != currentBit + 1) {
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (" "));
continue;
}
while ((nextBit != -1) && (nextBit == (currentBit + 1))) {
currentBit = nextBit;
nextBit = nextOne(nextBit);
}
if (currentBit > (i+1))
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("-%d ", currentBit));
else
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (" %d ", currentBit));
i = currentBit;
}
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("]\n"));
}
#endif // DEBUG_LOG

View File

@@ -1,195 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _BITSET_H_
#define _BITSET_H_
#include "Fundamentals.h"
#include "LogModule.h"
#include "Pool.h"
#include <string.h>
//------------------------------------------------------------------------------
// BitSet -
class BitSet
{
private:
#if (PR_BITS_PER_WORD == 64)
typedef Uint64 Word;
#elif (PR_BITS_PER_WORD == 32)
typedef Uint32 Word;
#endif
static const nBitsInWord = PR_BITS_PER_WORD;
static const nBytesInWord = PR_BYTES_PER_WORD;
static const nBitsInWordLog2 = PR_BITS_PER_WORD_LOG2;
static const nBytesInWordLog2 = PR_BYTES_PER_WORD_LOG2;
// Return the number of Word need to store the universe.
static Uint32 getSizeInWords(Uint32 sizeOfUniverse) {return (sizeOfUniverse + (nBitsInWord - 1)) >> nBitsInWordLog2;}
// Return the given element offset in its containing Word.
static Uint32 getBitOffset(Uint32 element) {return element & (nBitsInWord - 1);}
// Return the Word offset for the given element int the universe.
static Uint32 getWordOffset(Uint32 element) {return element >> nBitsInWordLog2;}
// Return the mask for the given bit index.
static Word getMask(Uint8 index) {return Word(1) << index;}
private:
Uint32 universeSize; // Size of the universe
Word* word; // universe memory.
private:
// No copy constructor.
BitSet(const BitSet&);
// Check if the given set's universe is of the same size than this universe.
void checkUniverseCompatibility(const BitSet& set) const {assert(set.universeSize == universeSize);}
// Check if pos is valid for this set's universe.
void checkMember(Int32 pos) const {assert(pos >=0 && Uint32(pos) < universeSize);}
public:
// Create a bitset of universeSize bits.
BitSet(Pool& pool, Uint32 universeSize) : universeSize(universeSize) {word = new(pool) Word[getSizeInWords(universeSize)]; clear();}
// Return the size of this bitset.
Uint32 getSize() const {return universeSize;}
// Clear the bitset.
void clear() {memset(word, 0x00, getSizeInWords(universeSize) << nBytesInWordLog2);}
// Clear the bit at index.
void clear(Uint32 index) {checkMember(index); word[getWordOffset(index)] &= ~getMask(index);}
// Set the bitset.
void set() {memset(word, 0xFF, getSizeInWords(universeSize) << nBytesInWordLog2);}
// Set the bit at index.
void set(Uint32 index) {checkMember(index); word[getWordOffset(index)] |= getMask(index);}
// Return true if the bit at index is set.
bool test(Uint32 index) const {checkMember(index); return (word[getWordOffset(index)] & getMask(index)) != 0;}
// Union with the given bitset.
inline void or(const BitSet& set);
// Intersection with the given bitset.
inline void and(const BitSet& set);
// Difference with the given bitset.
inline void difference(const BitSet& set);
// Copy set.
inline BitSet& operator = (const BitSet& set);
// Return true if the bitset are identical.
friend bool operator == (const BitSet& set1, const BitSet& set2);
// Return true if the bitset are different.
friend bool operator != (const BitSet& set1, const BitSet& set2);
// Logical operators.
BitSet& operator |= (const BitSet& set) {or(set); return *this;}
BitSet& operator &= (const BitSet& set) {and(set); return *this;}
BitSet& operator -= (const BitSet& set) {difference(set); return *this;}
// Return the first bit at set to true or -1 if none.
Int32 firstOne() const {return nextOne(-1);}
// Return the next bit after index set to true or -1 if none.
Int32 nextOne(Int32 pos) const;
// Return the first bit at set to false or -1 if none.
Int32 firstZero() const {return nextZero(-1);}
// Return the next bit after index set to false or -1 if none.
Int32 nextZero(Int32 pos) const;
// Iterator to conform with the set API.
typedef Int32 iterator;
// Return true if the walk is ordered.
static bool isOrdered() {return true;}
// Return the iterator for the first element of this set.
iterator begin() const {return firstOne();}
// Return the next iterator.
iterator advance(iterator pos) const {return nextOne(pos);}
// Return true if the iterator is at the end of the set.
bool done(iterator pos) const {return pos == -1;}
// Return the element corresponding to the given iterator.
Uint32 get(iterator pos) const {return pos;}
#ifdef DEBUG_LOG
// Print the set.
void printPretty(LogModuleObject log);
#endif // DEBUG_LOG
};
// Union with the given bitset.
//
inline void BitSet::or(const BitSet& set)
{
checkUniverseCompatibility(set);
Word* src = set.word;
Word* dst = word;
Word* limit = &src[getSizeInWords(universeSize)];
while (src < limit)
*dst++ |= *src++;
}
// Intersection with the given bitset.
//
inline void BitSet::and(const BitSet& set)
{
checkUniverseCompatibility(set);
Word* src = set.word;
Word* dst = word;
Word* limit = &src[getSizeInWords(universeSize)];
while (src < limit)
*dst++ &= *src++;
}
// Difference with the given bitset.
//
inline void BitSet::difference(const BitSet& set)
{
checkUniverseCompatibility(set);
Word* src = set.word;
Word* dst = word;
Word* limit = &src[getSizeInWords(universeSize)];
while (src < limit)
*dst++ &= ~*src++;
}
// Copy the given set into this set.
//
inline BitSet& BitSet::operator = (const BitSet& set)
{
checkUniverseCompatibility(set);
if (this != &set)
memcpy(word, set.word, getSizeInWords(universeSize) << nBytesInWordLog2);
return *this;
}
// Return true if the given set is identical to this set.
inline bool operator == (const BitSet& set1, const BitSet& set2)
{
set1.checkUniverseCompatibility(set2);
if (&set1 == &set2)
return true;
return memcmp(set1.word, set2.word, BitSet::getSizeInWords(set1.universeSize) << BitSet::nBytesInWordLog2) == 0;
}
inline bool operator != (const BitSet& set1, const BitSet& set2) {return !(set1 == set2);}
#endif // _BITSET_H

View File

@@ -1,159 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _COALESCING_H_
#define _COALESCING_H_
#include "Fundamentals.h"
#include "Pool.h"
#include "RegisterPressure.h"
#include "InterferenceGraph.h"
#include "ControlGraph.h"
#include "ControlNodes.h"
#include "Instruction.h"
#include "SparseSet.h"
#include "RegisterAllocator.h"
#include "RegisterAllocatorTools.h"
#if 1
// Performing an ultra conservative coalescing meens that when we look at
// candidates (source,destination) for coalescing we need to make sure
// that the combined interference of the source and destination register
// will not exceed the total number of register available for the register
// class.
#define ULTRA_CONSERVATIVE_COALESCING
#else
// If we are not doing an ultra conservative coalescing we have to make sure
// that the total number of neighbor whose degree is greater than the total
// number of register is not greater than the total number of register.
#undef ULTRA_CONSERVATIVE_COALESCING
#endif
template <class RegisterPressure>
struct Coalescing
{
static bool coalesce(RegisterAllocator& registerAllocator);
};
template <class RegisterPressure>
bool Coalescing<RegisterPressure>::coalesce(RegisterAllocator& registerAllocator)
{
Pool& pool = registerAllocator.pool;
// Initialize the lookup table
//
Uint32 rangeCount = registerAllocator.rangeCount;
RegisterName* newRange = new RegisterName[2 * rangeCount];
RegisterName* coalescedRange = &newRange[rangeCount];
RegisterName* name2range = registerAllocator.name2range;
init(coalescedRange, rangeCount);
SparseSet interferences(pool, rangeCount);
InterferenceGraph<RegisterPressure>& iGraph = registerAllocator.iGraph;
bool removedInstructions = false;
ControlGraph& controlGraph = registerAllocator.controlGraph;
ControlNode** nodes = controlGraph.lndList;
Uint32 nNodes = controlGraph.nNodes;
// Walk the nodes in the loop nesting depth list.
for (Int32 n = nNodes - 1; n >= 0; n--) {
InstructionList& instructions = nodes[n]->getInstructions();
InstructionList::iterator it = instructions.begin();
while (!instructions.done(it)) {
Instruction& instruction = instructions.get(it);
it = instructions.advance(it);
if ((instruction.getFlags() & ifCopy) != 0) {
assert(instruction.getInstructionUseBegin() != instruction.getInstructionUseEnd() && instruction.getInstructionUseBegin()[0].isRegister());
assert(instruction.getInstructionDefineBegin() != instruction.getInstructionDefineEnd() && instruction.getInstructionDefineBegin()[0].isRegister());
RegisterName source = findRoot(name2range[instruction.getInstructionUseBegin()[0].getRegisterName()], coalescedRange);
RegisterName destination = findRoot(name2range[instruction.getInstructionDefineBegin()[0].getRegisterName()], coalescedRange);
if (source == destination) {
instruction.remove();
} else if (!iGraph.interfere(source, destination)) {
InterferenceVector* sourceVector = iGraph.getInterferenceVector(source);
InterferenceVector* destinationVector = iGraph.getInterferenceVector(destination);
#ifdef ULTRA_CONSERVATIVE_COALESCING
interferences.clear();
InterferenceVector* vector;
for (vector = sourceVector; vector != NULL; vector = vector->next) {
RegisterName* neighbors = vector->neighbors;
for (Uint32 i = 0; i < vector->count; i++)
interferences.set(findRoot(neighbors[i], coalescedRange));
}
for (vector = destinationVector; vector != NULL; vector = vector->next) {
RegisterName* neighbors = vector->neighbors;
for (Uint32 i = 0; i < vector->count; i++)
interferences.set(findRoot(neighbors[i], coalescedRange));
}
Uint32 count = interferences.getSize();
#else // ULTRA_CONSERVATIVE_COALESCING
trespass("not implemented");
Uint32 count = 0;
#endif // ULTRA_CONSERVATIVE_COALESCING
if (count < 6 /* FIX: should get the number from the class */) {
// Update the interferences vector.
if (sourceVector == NULL) {
iGraph.setInterferenceVector(source, destinationVector);
sourceVector = destinationVector;
} else if (destinationVector == NULL)
iGraph.setInterferenceVector(destination, sourceVector);
else {
InterferenceVector* last = NULL;
for (InterferenceVector* v = sourceVector; v != NULL; v = v->next)
last = v;
assert(last);
last->next = destinationVector;
iGraph.setInterferenceVector(destination, sourceVector);
}
// Update the interference matrix.
for (InterferenceVector* v = sourceVector; v != NULL; v = v->next) {
RegisterName* neighbors = v->neighbors;
for (Uint32 i = 0; i < v->count; i++) {
RegisterName neighbor = findRoot(neighbors[i], coalescedRange);
iGraph.setInterference(neighbor, source);
iGraph.setInterference(neighbor, destination);
}
}
instruction.remove();
coalescedRange[source] = destination;
removedInstructions = true;
}
}
}
}
}
registerAllocator.rangeCount = compress(registerAllocator.name2range, coalescedRange, registerAllocator.nameCount, rangeCount);
delete newRange;
return removedInstructions;
}
#endif // _COALESCING_H_

View File

@@ -1,283 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef NEW_LAURENTM_CODE
#include "Coloring.h"
#include "VirtualRegister.h"
#include "FastBitSet.h"
#include "FastBitMatrix.h"
#include "CpuInfo.h"
bool Coloring::
assignRegisters(FastBitMatrix& interferenceMatrix)
{
PRUint32 *stackPtr = new(pool) PRUint32[vRegManager.count()];
return select(interferenceMatrix, stackPtr, simplify(interferenceMatrix, stackPtr));
}
PRInt32 Coloring::
getLowestSpillCostRegister(FastBitSet& bitset)
{
PRInt32 lowest = bitset.firstOne();
if (lowest != -1)
{
Flt32 cost = vRegManager.getVirtualRegister(lowest).spillInfo.spillCost;
for (PRInt32 r = bitset.nextOne(lowest); r != -1; r = bitset.nextOne(r))
{
VirtualRegister& vReg = vRegManager.getVirtualRegister(r);
if (!vReg.spillInfo.infiniteSpillCost && (vReg.spillInfo.spillCost < cost))
{
cost = vReg.spillInfo.spillCost;
lowest = r;
}
}
}
return lowest;
}
PRUint32* Coloring::
simplify(FastBitMatrix interferenceMatrix, PRUint32* stackPtr)
{
// first we construct the sets low and high. low contains all nodes of degree
// inferior to the number of register available on the processor. All the
// nodes with an high degree and a finite spill cost are placed in high.
// Nodes of high degree and infinite spill cost are not included in either sets.
PRUint32 nRegisters = vRegManager.count();
FastBitSet low(pool, nRegisters);
FastBitSet high(pool, nRegisters);
FastBitSet stack(pool, nRegisters);
for (VirtualRegisterManager::iterator i = vRegManager.begin(); !vRegManager.done(i); i = vRegManager.advance(i))
{
VirtualRegister& vReg = vRegManager.getVirtualRegister(i);
if (vReg.getClass() == vrcStackSlot)
{
stack.set(i);
vReg.colorRegister(nRegisters);
}
else
{
if (vReg.colorInfo.interferenceDegree < NUMBER_OF_REGISTERS)
low.set(i);
else // if (!vReg.spillInfo.infiniteSpillCost)
high.set(i);
// Set coloring info.
vReg.spillInfo.willSpill = false;
switch(vReg.getClass())
{
case vrcInteger:
vReg.colorRegister(LAST_GREGISTER + 1);
break;
case vrcFloatingPoint:
case vrcFixedPoint:
vReg.colorRegister(LAST_FPREGISTER + 1);
break;
default:
PR_ASSERT(false); // Cannot happen.
}
}
}
// push the stack registers
PRInt32 j;
for (j = stack.firstOne(); j != -1; j = stack.nextOne(j))
*stackPtr++ = j;
// simplify
while (true)
{
PRInt32 r;
while ((r = getLowestSpillCostRegister(low)) != -1)
{
VirtualRegister& vReg = vRegManager.getVirtualRegister(r);
/* update low and high */
FastBitSet inter(interferenceMatrix.getRow(r), nRegisters);
for (j = inter.firstOne(); j != -1; j = inter.nextOne(j))
{
VirtualRegister& neighbor = vRegManager.getVirtualRegister(j);
// if the new interference degree of one of his neighbor becomes
// NUMBER_OF_REGISTERS - 1 then it is added to the set 'low'.
PRUint32 maxInterference = 0;
switch (neighbor.getClass())
{
case vrcInteger:
maxInterference = NUMBER_OF_GREGISTERS;
break;
case vrcFloatingPoint:
case vrcFixedPoint:
maxInterference = NUMBER_OF_FPREGISTERS;
break;
default:
PR_ASSERT(false);
}
if ((vRegManager.getVirtualRegister(j).colorInfo.interferenceDegree-- == maxInterference))
{
high.clear(j);
low.set(j);
}
vReg.colorInfo.interferenceDegree--;
interferenceMatrix.clear(r, j);
interferenceMatrix.clear(j, r);
}
low.clear(r);
// Push this register.
*stackPtr++ = r;
}
if ((r = getLowestSpillCostRegister(high)) != -1)
{
high.clear(r);
low.set(r);
}
else
break;
}
return stackPtr;
}
bool Coloring::
select(FastBitMatrix& interferenceMatrix, PRUint32* stackBase, PRUint32* stackPtr)
{
PRUint32 nRegisters = vRegManager.count();
FastBitSet usedRegisters(NUMBER_OF_REGISTERS + 1); // usedRegisters if used for both GR & FPR.
FastBitSet preColoredRegisters(NUMBER_OF_REGISTERS + 1);
FastBitSet usedStack(nRegisters + 1);
bool success = true;
Int32 lastUsedSSR = -1;
// select
while (stackPtr != stackBase)
{
// Pop one register.
PRUint32 r = *--stackPtr;
VirtualRegister& vReg = vRegManager.getVirtualRegister(r);
FastBitSet neighbors(interferenceMatrix.getRow(r), nRegisters);
if (vReg.getClass() == vrcStackSlot)
// Stack slots coloring.
{
usedStack.clear();
for (PRInt32 i = neighbors.firstOne(); i != -1; i = neighbors.nextOne(i))
usedStack.set(vRegManager.getVirtualRegister(i).getColor());
Int32 color = usedStack.firstZero();
vReg.colorRegister(color);
if (color > lastUsedSSR)
lastUsedSSR = color;
}
else
// Integer & Floating point register coloring.
{
usedRegisters.clear();
preColoredRegisters.clear();
for (PRInt32 i = neighbors.firstOne(); i != -1; i = neighbors.nextOne(i))
{
VirtualRegister& nvReg = vRegManager.getVirtualRegister(i);
usedRegisters.set(nvReg.getColor());
if (nvReg.isPreColored())
preColoredRegisters.set(nvReg.getPreColor());
}
if (vReg.hasSpecialInterference)
usedRegisters |= vReg.specialInterference;
PRInt8 c = -1;
PRInt8 maxColor = 0;
PRInt8 firstColor = 0;
switch (vReg.getClass())
{
case vrcInteger:
firstColor = FIRST_GREGISTER;
maxColor = LAST_GREGISTER;
break;
case vrcFloatingPoint:
case vrcFixedPoint:
firstColor = FIRST_FPREGISTER;
maxColor = LAST_FPREGISTER;
break;
default:
PR_ASSERT(false);
}
if (vReg.isPreColored())
{
c = vReg.getPreColor();
if (usedRegisters.test(c))
c = -1;
}
else
{
for (c = usedRegisters.nextZero(firstColor - 1); (c >= 0) && (c <= maxColor) && (preColoredRegisters.test(c));
c = usedRegisters.nextZero(c)) {}
}
if ((c >= 0) && (c <= maxColor))
{
vReg.colorRegister(c);
}
else
{
VirtualRegister& stackRegister = vRegManager.newVirtualRegister(vrcStackSlot);
vReg.equivalentRegister[vrcStackSlot] = &stackRegister;
vReg.spillInfo.willSpill = true;
success = false;
}
}
}
#ifdef DEBUG
if (success)
{
for (VirtualRegisterManager::iterator i = vRegManager.begin(); !vRegManager.done(i); i = vRegManager.advance(i))
{
VirtualRegister& vReg = vRegManager.getVirtualRegister(i);
switch (vReg.getClass())
{
case vrcInteger:
if (vReg.getColor() > LAST_GREGISTER)
PR_ASSERT(false);
break;
case vrcFloatingPoint:
case vrcFixedPoint:
#if NUMBER_OF_FPREGISTERS != 0
if (vReg.getColor() > LAST_FPREGISTER)
PR_ASSERT(false);
#endif
break;
default:
break;
}
}
}
#endif
vRegManager.nUsedStackSlots = lastUsedSSR + 1;
return success;
}
#endif // NEW_LAURENTM_CODE

View File

@@ -1,284 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "Fundamentals.h"
#include "ControlGraph.h"
#include "ControlNodes.h"
#include "Instruction.h"
#include "RegisterAllocator.h"
#include "VirtualRegister.h"
#include "InterferenceGraph.h"
#include "SparseSet.h"
#include "Spilling.h"
#include "Splits.h"
UT_EXTERN_LOG_MODULE(RegAlloc);
template <class RegisterPressure>
class Coloring
{
private:
static RegisterName* simplify(RegisterAllocator& registerAllocator, RegisterName* coloringStack);
static bool select(RegisterAllocator& registerAllocator, RegisterName* coloringStack, RegisterName* coloringStackPtr);
public:
static bool color(RegisterAllocator& registerAllocator);
static void finalColoring(RegisterAllocator& registerAllocator);
};
template <class RegisterPressure>
void Coloring<RegisterPressure>::finalColoring(RegisterAllocator& registerAllocator)
{
RegisterName* color = registerAllocator.color;
RegisterName* name2range = registerAllocator.name2range;
ControlGraph& controlGraph = registerAllocator.controlGraph;
ControlNode** nodes = controlGraph.dfsList;
Uint32 nNodes = controlGraph.nNodes;
for (Uint32 n = 0; n < nNodes; n++) {
InstructionList& instructions = nodes[n]->getInstructions();
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
Instruction& instruction = instructions.get(i);
InstructionUse* useEnd = instruction.getInstructionUseEnd();
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
if (usePtr->isRegister()) {
usePtr->setRegisterName(color[name2range[usePtr->getRegisterName()]]);
#ifdef DEBUG
RegisterID rid = usePtr->getRegisterID();
setColoredRegister(rid);
usePtr->setRegisterID(rid);
#endif // DEBUG
}
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
if (definePtr->isRegister()) {
definePtr->setRegisterName(color[name2range[definePtr->getRegisterName()]]);
#ifdef DEBUG
RegisterID rid = definePtr->getRegisterID();
setColoredRegister(rid);
definePtr->setRegisterID(rid);
#endif // DEBUG
}
}
}
}
template <class RegisterPressure>
bool Coloring<RegisterPressure>::select(RegisterAllocator& registerAllocator, RegisterName* coloringStack, RegisterName* coloringStackPtr)
{
Uint32 rangeCount = registerAllocator.rangeCount;
RegisterName* color = new RegisterName[rangeCount];
registerAllocator.color = color;
for (Uint32 r = 1; r < rangeCount; r++)
color[r] = RegisterName(6); // FIX;
// Color the preColored registers.
//
VirtualRegisterManager& vrManager = registerAllocator.vrManager;
RegisterName* name2range = registerAllocator.name2range;
PreColoredRegister* machineEnd = vrManager.getMachineRegistersEnd();
for (PreColoredRegister* machinePtr = vrManager.getMachineRegistersBegin(); machinePtr < machineEnd; machinePtr++)
if (machinePtr->id != invalidID) {
color[name2range[getName(machinePtr->id)]] = machinePtr->color;
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\twill preColor range %d as %d\n", name2range[getName(machinePtr->id)], machinePtr->color));
}
SpillCost* cost = registerAllocator.spillCost;
Pool& pool = registerAllocator.pool;
SparseSet& spill = *new(pool) SparseSet(pool, rangeCount);
registerAllocator.willSpill = &spill;
SparseSet neighborColors(pool, 6); // FIX
InterferenceGraph<RegisterPressure>& iGraph = registerAllocator.iGraph;
bool coloringFailed = false;
while (coloringStackPtr > coloringStack) {
RegisterName range = *--coloringStackPtr;
if (!cost[range].infinite && cost[range].cost < 0) {
coloringFailed = true;
spill.set(range);
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\tfailed to color %d, will spill.\n", range));
} else {
neighborColors.clear();
for (InterferenceVector* vector = iGraph.getInterferenceVector(range); vector != NULL; vector = vector->next)
for (Int32 i = vector->count - 1; i >= 0; --i) {
RegisterName neighborColor = color[vector->neighbors[i]];
if (neighborColor < 6) // FIX
neighborColors.set(neighborColor);
}
if (neighborColors.getSize() == 6) { // FIX
coloringFailed = true;
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\tfailed to color %d, ", range));
if (!Splits<RegisterPressure>::findSplit(registerAllocator, color, range)) {
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("will spill.\n"));
spill.set(range);
} else
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("will split.\n"));
} else {
for (Uint32 i = 0; i < 6; i++) // FIX
if (!neighborColors.test(i)) {
fprintf(stdout, "\twill color %d as %d\n", range, i);
color[range] = RegisterName(i);
break;
}
}
}
}
#ifdef DEBUG_LOG
if (coloringFailed) {
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("Coloring failed:\n"));
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\twill spill: "));
spill.printPretty(UT_LOG_MODULE(RegAlloc));
} else {
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("Coloring succeeded:\n"));
for (Uint32 i = 1; i < rangeCount; i++)
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\trange %d colored as %d\n", i, color[i]));
}
#endif
return !coloringFailed;
}
template <class RegisterPressure>
RegisterName* Coloring<RegisterPressure>::simplify(RegisterAllocator& registerAllocator, RegisterName* coloringStack)
{
InterferenceGraph<RegisterPressure>& iGraph = registerAllocator.iGraph;
SpillCost* spillCost = registerAllocator.spillCost;
Uint32 rangeCount = registerAllocator.rangeCount;
Uint32* degree = new Uint32[rangeCount];
for (RegisterName i = RegisterName(1); i < rangeCount; i = RegisterName(i + 1)) {
InterferenceVector* vector = iGraph.getInterferenceVector(i);
degree[i] = (vector != NULL) ? vector->count : 0;
}
Pool& pool = registerAllocator.pool;
SparseSet low(pool, rangeCount);
SparseSet high(pool, rangeCount);
SparseSet highInfinite(pool, rangeCount);
SparseSet preColored(pool, rangeCount);
// Get the precolored registers.
//
VirtualRegisterManager& vrManager = registerAllocator.vrManager;
RegisterName* name2range = registerAllocator.name2range;
PreColoredRegister* machineEnd = vrManager.getMachineRegistersEnd();
for (PreColoredRegister* machinePtr = vrManager.getMachineRegistersBegin(); machinePtr < machineEnd; machinePtr++)
if (machinePtr->id != invalidID)
preColored.set(name2range[getName(machinePtr->id)]);
// Insert the live ranges in the sets.
//
for (Uint32 range = 1; range < rangeCount; range++)
if (!preColored.test(range))
if (degree[range] < 6) // FIX
low.set(range);
else if (!spillCost[range].infinite)
high.set(range);
else
highInfinite.set(range);
#ifdef DEBUG_LOG
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("Coloring sets:\n\tlow = "));
low.printPretty(UT_LOG_MODULE(RegAlloc));
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\thigh = "));
high.printPretty(UT_LOG_MODULE(RegAlloc));
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\thighInfinite = "));
highInfinite.printPretty(UT_LOG_MODULE(RegAlloc));
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\tpreColored = "));
preColored.printPretty(UT_LOG_MODULE(RegAlloc));
#endif // DEBUG_LOG
RegisterName* coloringStackPtr = coloringStack;
while (low.getSize() != 0 || high.getSize() != 0) {
while (low.getSize() != 0) {
RegisterName range = RegisterName(low.getOne());
low.clear(range);
*coloringStackPtr++ = range;
for (InterferenceVector* vector = iGraph.getInterferenceVector(range); vector != NULL; vector = vector->next)
for (Int32 i = (vector->count - 1); i >= 0; --i) {
RegisterName neighbor = vector->neighbors[i];
degree[neighbor]--;
if (degree[neighbor] < 6) // FIX
if (high.test(neighbor)) {
high.clear(neighbor);
low.set(neighbor);
} else if (highInfinite.test(neighbor)) {
highInfinite.clear(neighbor);
low.set(neighbor);
}
}
}
if (high.getSize() != 0) {
RegisterName best = RegisterName(high.getOne());
double bestCost = spillCost[best].cost;
double bestDegree = degree[best];
// Choose the next best candidate.
//
for (SparseSet::iterator i = high.begin(); !high.done(i); i = high.advance(i)) {
RegisterName range = RegisterName(high.get(i));
double thisCost = spillCost[range].cost;
double thisDegree = degree[range];
if (thisCost * bestDegree < bestCost * thisDegree) {
best = range;
bestCost = thisCost;
bestDegree = thisDegree;
}
}
high.clear(best);
low.set(best);
}
}
assert(highInfinite.getSize() == 0);
delete degree;
#ifdef DEBUG_LOG
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("Coloring stack:\n\t"));
for (RegisterName* sp = coloringStack; sp < coloringStackPtr; ++sp)
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("%d ", *sp));
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\n"));
#endif // DEBUG_LOG
return coloringStackPtr;
}
template <class RegisterPressure>
bool Coloring<RegisterPressure>::color(RegisterAllocator& registerAllocator)
{
RegisterName* coloringStack = new RegisterName[registerAllocator.rangeCount];
return select(registerAllocator, coloringStack, simplify(registerAllocator, coloringStack));
}

View File

@@ -1,212 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "Fundamentals.h"
#include <string.h>
#include "ControlGraph.h"
#include "ControlNodes.h"
#include "DominatorGraph.h"
DominatorGraph::DominatorGraph(ControlGraph& controlGraph) : controlGraph(controlGraph)
{
Uint32 nNodes = controlGraph.nNodes;
GtoV = new Uint32[nNodes + 1];
VtoG = new Uint32[nNodes + 1];
Uint32 v = 1;
for (Uint32 n = 0; n < nNodes; n++) {
VtoG[v] = n;
GtoV[n] = v++;
}
// Initialize all the 1-based arrays.
//
parent = new Uint32[v];
semi = new Uint32[v];
vertex = new Uint32[v];
label = new Uint32[v];
size = new Uint32[v];
ancestor = new Uint32[v];
child = new Uint32[v];
dom = new Uint32[v];
bucket = new DGLinkedList*[v];
memset(semi, '\0', v * sizeof(Uint32));
memset(bucket, '\0', v * sizeof(DGLinkedList*));
vCount = v;
build();
delete parent;
delete semi;
delete vertex;
delete label;
delete size;
delete ancestor;
delete child;
delete dom;
delete bucket;
}
Uint32 DominatorGraph::DFS(Uint32 vx, Uint32 n)
{
semi[vx] = ++n;
vertex[n] = label[vx] = vx;
ancestor[vx] = child[vx] = 0;
size[vx] = 1;
ControlNode& node = *controlGraph.dfsList[VtoG[vx]];
ControlEdge* successorEnd = node.getSuccessorsEnd();
for (ControlEdge* successorPtr = node.getSuccessorsBegin(); successorPtr < successorEnd; successorPtr++) {
Uint32 w = GtoV[successorPtr->getTarget().dfsNum];
if (semi[w] == 0) {
parent[w] = vx;
n = DFS(w, n);
}
}
return n;
}
void DominatorGraph::LINK(Uint32 vx, Uint32 w)
{
Uint32 s = w;
while (semi[label[w]] < semi[label[child[s]]]) {
if (size[s] + size[child[child[s]]] >= (size[child[s]] << 1)) {
ancestor[child[s]] = s;
child[s] = child[child[s]];
} else {
size[child[s]] = size[s];
s = ancestor[s] = child[s];
}
}
label[s] = label[w];
size[vx] += size[w];
if(size[vx] < (size[w] << 1)) {
Uint32 t = s;
s = child[vx];
child[vx] = t;
}
while( s != 0 ) {
ancestor[s] = vx;
s = child[s];
}
}
void DominatorGraph::COMPRESS(Uint32 vx)
{
if(ancestor[ancestor[vx]] != 0) {
COMPRESS(ancestor[vx]);
if(semi[label[ancestor[vx]]] < semi[label[vx]])
label[vx] = label[ancestor[vx]];
ancestor[vx] = ancestor[ancestor[vx]];
}
}
Uint32 DominatorGraph::EVAL(Uint32 vx)
{
if(ancestor[vx] == 0)
return label[vx];
COMPRESS(vx);
return (semi[label[ancestor[vx]]] >= semi[label[vx]]) ? label[vx] : label[ancestor[vx]];
}
void DominatorGraph::build()
{
Uint32 n = DFS(GtoV[0], 0);
size[0] = label[0] = semi[0];
for (Uint32 i = n; i >= 2; i--) {
Uint32 w = vertex[i];
ControlNode& node = *controlGraph.dfsList[VtoG[w]];
const DoublyLinkedList<ControlEdge>& predecessors = node.getPredecessors();
for (DoublyLinkedList<ControlEdge>::iterator p = predecessors.begin(); !predecessors.done(p); p = predecessors.advance(p)) {
Uint32 vx = GtoV[predecessors.get(p).getSource().dfsNum];
Uint32 u = EVAL(vx);
if(semi[u] < semi[w])
semi[w] = semi[u];
}
DGLinkedList* elem = new DGLinkedList();
elem->next = bucket[vertex[semi[w]]];
elem->index = w;
bucket[vertex[semi[w]]] = elem;
LINK(parent[w], w);
elem = bucket[parent[w]];
while(elem != NULL) {
Uint32 vx = elem->index;
Uint32 u = EVAL(vx);
dom[vx] = (semi[u] < semi[vx]) ? u : parent[w];
elem = elem->next;
}
}
memset(size, '\0', n * sizeof(Uint32));
Pool& pool = controlGraph.pool;
nodes = new(pool) DGNode[n];
for(Uint32 j = 2; j <= n; j++) {
Uint32 w = vertex[j];
Uint32 d = dom[w];
if(d != vertex[semi[w]]) {
d = dom[d];
dom[w] = d;
}
size[d]++;
}
dom[GtoV[0]] = 0;
for (Uint32 k = 1; k <= n; k++) {
DGNode& node = nodes[VtoG[k]];
Uint32 count = size[k];
node.successorsEnd = node.successorsBegin = (count) ? new(pool) Uint32[count] : (Uint32*) 0;
}
for (Uint32 l = 2; l <= n; l++)
*(nodes[VtoG[dom[l]]].successorsEnd)++ = VtoG[l];
}
#ifdef DEBUG_LOG
void DominatorGraph::printPretty(LogModuleObject log)
{
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Dominator Graph:\n"));
Uint32 nNodes = controlGraph.nNodes;
for (Uint32 i = 0; i < nNodes; i++) {
DGNode& node = nodes[i];
if (node.successorsBegin != node.successorsEnd) {
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\tN%d dominates ", i));
for (Uint32* successorsPtr = node.successorsBegin; successorsPtr < node.successorsEnd; successorsPtr++)
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("N%d ", *successorsPtr));
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
}
}
}
#endif // DEBUG_LOG

View File

@@ -1,80 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _DOMINATOR_GRAPH_H_
#define _DOMINATOR_GRAPH_H_
#include "LogModule.h"
class ControlGraph;
struct DGNode
{
Uint32* successorsBegin;
Uint32* successorsEnd;
};
struct DGLinkedList
{
DGLinkedList* next;
Uint32 index;
};
class DominatorGraph
{
private:
ControlGraph& controlGraph;
Uint32 vCount;
Uint32* VtoG;
Uint32* GtoV;
Uint32* parent;
Uint32* semi;
Uint32* vertex;
Uint32* label;
Uint32* size;
Uint32* ancestor;
Uint32* child;
Uint32* dom;
DGLinkedList** bucket;
DGNode* nodes;
private:
void build();
Uint32 DFS(Uint32 vx, Uint32 n);
void LINK(Uint32 vx, Uint32 w);
void COMPRESS(Uint32 vx);
Uint32 EVAL(Uint32 vx);
public:
DominatorGraph(ControlGraph& controlGraph);
Uint32* getSuccessorsBegin(Uint32 n) const {return nodes[n].successorsBegin;}
Uint32* getSuccessorsEnd(Uint32 n) const {return nodes[n].successorsEnd;}
#ifdef DEBUG_LOG
void printPretty(LogModuleObject log);
#endif // DEBUG_LOG
};
#endif // _DOMINATOR_GRAPH_H_

View File

@@ -1,97 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _HASH_SET_H_
#define _HASH_SET_H_
#include "Fundamentals.h"
#include "Pool.h"
#include <string.h>
struct HashSetElement
{
Uint32 index;
HashSetElement* next;
};
class HashSet
{
private:
static const hashSize = 64;
// Return the hash code for the given element index.
static Uint32 getHashCode(Uint32 index) {return index & (hashSize - 1);} // Could be better !
private:
Pool& allocationPool;
HashSetElement** bucket;
HashSetElement* free;
private:
// No copy constructor.
HashSet(const HashSet&);
// No copy operator.
void operator = (const HashSet&);
public:
// Create a new HashSet.
inline HashSet(Pool& pool, Uint32 universeSize);
// Clear the hashset.
void clear();
// Clear the element for the given index.
void clear(Uint32 index);
// Set the element for the given index.
void set(Uint32 index);
// Return true if the element at index is a member.
bool test(Uint32 index) const;
// Union with the given hashset.
inline void or(const HashSet& set);
// Intersection with the given hashset.
inline void and(const HashSet& set);
// Difference with the given hashset.
inline void difference(const HashSet& set);
// Logical operators.
HashSet& operator |= (const HashSet& set) {or(set); return *this;}
HashSet& operator &= (const HashSet& set) {and(set); return *this;}
HashSet& operator -= (const HashSet& set) {difference(set); return *this;}
// Iterator to conform with the set API.
typedef HashSetElement* iterator;
// Return the iterator for the first element of this set.
iterator begin() const;
// Return the next iterator.
iterator advance(iterator pos) const;
// Return true if the iterator is at the end of the set.
bool done(iterator pos) const {return pos == NULL;}
};
inline HashSet::HashSet(Pool& pool, Uint32 /*universeSize*/)
: allocationPool(pool), free(NULL)
{
bucket = new(pool) HashSetElement*[hashSize];
memset(bucket, '\0', sizeof(HashSetElement*));
}
#endif // _HASH_SET_H_

View File

@@ -1,213 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _INDEXED_POOL_H_
#define _INDEXED_POOL_H_
#include "Fundamentals.h"
#include <string.h>
#include <stdlib.h>
//------------------------------------------------------------------------------
// IndexedPool<IndexedObjectSubclass> is an indexed pool of objects. The
// template parameter 'IndexedObjectSubclass' must be a subclass of the struct
// IndexedObject.
//
// When the indexed pool is ask to allocate and initialize a new object (using
// the operator new(anIndexedPool) it will zero the memory used to store the
// object and initialize the field 'index' of this object to its position in
// the pool.
//
// An object allocated by the indexed pool can be freed by calling the method
// IndexedPool::release(IndexedElement& objectIndex).
//
// example:
//
// IndexedPool<IndexedElement> elementPool;
//
// IndexedElement& element1 = *new(elementPool) IndexedElement();
// IndexedElement& element2 = *new(elementPool) IndexedElement();
//
// indexedPool.release(element1);
// IndexedElement& element3 = *new(elementPool) IndexedElement();
//
// At this point element1 is no longer a valid object, element2 is at
// index 2 and element3 is at index 1.
//
//------------------------------------------------------------------------------
// IndexedObject -
//
template<class Object>
struct IndexedObject
{
Uint32 index; // Index in the pool.
Object* next; // Used to link IndexedObject together.
Uint32 getIndex() {return index;}
};
//------------------------------------------------------------------------------
// IndexedPool<IndexedObject> -
//
template <class IndexedObject>
class IndexedPool
{
private:
static const blockSize = 4; // Size of one block.
Uint32 nBlocks; // Number of blocks in the pool.
IndexedObject** block; // Array of block pointers.
IndexedObject* freeObjects; // Chained list of free IndexedObjects.
Uint32 nextIndex; // Index of the next free object in the last block.
private:
void allocateAnotherBlock();
IndexedObject& newObject();
public:
IndexedPool() : nBlocks(0), block(NULL), freeObjects(NULL), nextIndex(1) {}
~IndexedPool();
IndexedObject& get(Uint32 index) const;
void release(IndexedObject& object);
void setSize(Uint32 size) {assert(size < nextIndex); nextIndex = size;}
// Return the universe size.
Uint32 getSize() {return nextIndex;}
friend void* operator new(size_t, IndexedPool<IndexedObject>& pool); // Needs to call newObject().
};
// Free all the memory allocated for this object.
//
template <class IndexedObject>
IndexedPool<IndexedObject>::~IndexedPool()
{
for (Uint32 n = 0; n < nBlocks; n++)
free(&((IndexedObject **) &block[n][n*blockSize])[-(n + 1)]);
}
// Release the given. This object will be iserted in the chained
// list of free IndexedObjects. To minimize the fragmentation the chained list
// is ordered by ascending indexes.
//
template <class IndexedObject>
void IndexedPool<IndexedObject>::release(IndexedObject& object)
{
Uint32 index = object.index;
IndexedObject* list = freeObjects;
assert(&object == &get(index)); // Make sure that object is owned by this pool.
if (list == NULL) { // The list is empty.
freeObjects = &object;
object.next = NULL;
} else { // The list contains at least 1 element.
if (index < list->index) { // insert as first element.
freeObjects = &object;
object.next = list;
} else { // Find this object's place.
while ((list->next) != NULL && (list->next->index < index))
list = list->next;
object.next = list->next;
list->next = &object;
}
}
#ifdef DEBUG
// Sanity check to be sure that the list is correctly ordered.
for (IndexedObject* obj = freeObjects; obj != NULL; obj = obj->next)
if (obj->next != NULL)
assert(obj->index < obj->next->index);
#endif
}
// Create a new block of IndexedObjects. We will allocate the memory to
// store IndexedPool::blockSize IndexedObject and the new Array of block
// pointers.
// The newly created IndexedObjects will not be initialized.
//
template <class IndexedObject>
void IndexedPool<IndexedObject>::allocateAnotherBlock()
{
void* memory = (void *) malloc((nBlocks + 1) * sizeof(Uint32) + blockSize * sizeof(IndexedObject));
memcpy(memory, block, nBlocks * sizeof(Uint32));
block = (IndexedObject **) memory;
IndexedObject* objects = (IndexedObject *) &block[nBlocks + 1];
block[nBlocks] = &objects[-(nBlocks * blockSize)];
nBlocks++;
}
// Return the IndexedObject at the position 'index' in the pool.
//
template <class IndexedObject>
IndexedObject& IndexedPool<IndexedObject>::get(Uint32 index) const
{
Uint32 blockIndex = index / blockSize;
assert(blockIndex < nBlocks);
return block[blockIndex][index];
}
// Return the reference of an unused object in the pool.
//
template <class IndexedObject>
IndexedObject& IndexedPool<IndexedObject>::newObject()
{
if (freeObjects != NULL) {
IndexedObject& newObject = *freeObjects;
freeObjects = newObject.next;
return newObject;
}
Uint32 nextIndex = this->nextIndex++;
Uint32 blockIndex = nextIndex / blockSize;
while (blockIndex >= nBlocks)
allocateAnotherBlock();
IndexedObject& newObject = block[blockIndex][nextIndex];
newObject.index = nextIndex;
return newObject;
}
// Return the address of the next unsused object in the given
// indexed pool. The field index of the newly allocated object
// will be initialized to the corresponding index of this object
// in the pool.
//
template <class IndexedObject>
void* operator new(size_t size, IndexedPool<IndexedObject>& pool)
{
assert(size == sizeof(IndexedObject));
return (void *) &pool.newObject();
}
#endif // _INDEXED_POOL_H_

View File

@@ -1,258 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _INTERFERENCE_GRAPH_H_
#define _INTERFERENCE_GRAPH_H_
#include "Fundamentals.h"
#include "ControlGraph.h"
#include "Primitives.h"
#include "Instruction.h"
#include "VirtualRegister.h"
#include "RegisterPressure.h"
#include "SparseSet.h"
#include <string.h>
struct InterferenceVector
{
Uint32 count;
InterferenceVector* next;
RegisterName* neighbors;
InterferenceVector() : count(0), next(NULL) {}
};
class RegisterAllocator;
template <class RegisterPressure>
class InterferenceGraph
{
private:
RegisterAllocator& registerAllocator;
RegisterPressure::Set* interferences;
InterferenceVector** vector;
Uint32* offset;
Uint32 rangeCount;
private:
// No copy constructor.
InterferenceGraph(const InterferenceGraph&);
// No copy operator.
void operator = (const InterferenceGraph&);
// Check if reg is a member of the universe.
void checkMember(RegisterName name) {assert(name < rangeCount);}
// Return the edge index for the interference between name1 and name2.
Uint32 getEdgeIndex(RegisterName name1, RegisterName name2);
public:
InterferenceGraph(RegisterAllocator& registerAllocator) : registerAllocator(registerAllocator) {}
// Calculate the interferences.
void build();
// Return true if reg1 and reg2 interfere.
bool interfere(RegisterName name1, RegisterName name2);
// Return the interference vector for the given register or NULL if there is none.
InterferenceVector* getInterferenceVector(RegisterName name) {return vector[name];}
// Set the interference between name1 and name2.
void setInterference(RegisterName name1, RegisterName name2);
// Set the interference vector for the given register.
void setInterferenceVector(RegisterName name, InterferenceVector* v) {vector[name] = v;}
#ifdef DEBUG_LOG
// Print the interferences.
void printPretty(LogModuleObject log);
#endif // DEBUG_LOG
};
template <class RegisterPressure>
void InterferenceGraph<RegisterPressure>::build()
{
Pool& pool = registerAllocator.pool;
Uint32 rangeCount = registerAllocator.rangeCount;
this->rangeCount = rangeCount;
// Initialize the structures.
//
offset = new(pool) Uint32[rangeCount + 1];
vector = new(pool) InterferenceVector*[rangeCount];
memset(vector, '\0', sizeof(InterferenceVector*) * rangeCount);
Uint32 o = 0;
offset[0] = 0;
for (Uint32 i = 1; i <= rangeCount; ++i) {
offset[i] = o;
o += i;
}
interferences = new(pool) RegisterPressure::Set(pool, (rangeCount * rangeCount) / 2);
ControlGraph& controlGraph = registerAllocator.controlGraph;
ControlNode** nodes = controlGraph.dfsList;
Uint32 nNodes = controlGraph.nNodes;
RegisterName* name2range = registerAllocator.name2range;
LivenessInfo<RegisterPressure> liveness = Liveness<RegisterPressure>::analysis(controlGraph, rangeCount, name2range);
registerAllocator.liveness = liveness;
SparseSet currentLive(pool, rangeCount);
for (Uint32 n = 0; n < nNodes; n++) {
ControlNode& node = *nodes[n];
currentLive = liveness.liveOut[n];
InstructionList& instructions = node.getInstructions();
for (InstructionList::iterator i = instructions.end(); !instructions.done(i); i = instructions.retreat(i)) {
Instruction& instruction = instructions.get(i);
InstructionUse* useBegin = instruction.getInstructionUseBegin();
InstructionUse* useEnd = instruction.getInstructionUseEnd();
InstructionUse* usePtr;
InstructionDefine* defineBegin = instruction.getInstructionDefineBegin();
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
InstructionDefine* definePtr;
// Handle the copy instruction to avoid unnecessary interference between the 2 registers.
if ((instruction.getFlags() & ifCopy) != 0) {
assert(useBegin != useEnd && useBegin[0].isRegister());
currentLive.clear(name2range[useBegin[0].getRegisterName()]);
}
// Create the interferences.
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
if (definePtr->isRegister()) {
RegisterName define = name2range[definePtr->getRegisterName()];
for (SparseSet::iterator e = currentLive.begin(); !currentLive.done(e); e = currentLive.advance(e)) {
RegisterName live = RegisterName(currentLive.get(e));
if ((live != define) && !interfere(live, define) && registerAllocator.canInterfere(live, define)) {
if (vector[define] == NULL)
vector[define] = new(pool) InterferenceVector();
vector[define]->count++;
if (vector[live] == NULL)
vector[live] = new(pool) InterferenceVector();
vector[live]->count++;
setInterference(live, define);
}
}
}
// Now update the liveness.
//
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
if (definePtr->isRegister())
currentLive.clear(name2range[definePtr->getRegisterName()]);
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
if (usePtr->isRegister())
currentLive.set(name2range[usePtr->getRegisterName()]);
}
}
// Allocate the memory to store the interferences.
//
for (Uint32 e = 0; e < rangeCount; e++)
if (vector[e] != NULL) {
InterferenceVector& v = *vector[e];
v.neighbors = new(pool) RegisterName[v.count];
v.count = 0;
}
// Initialize the edges.
//
if (RegisterPressure::Set::isOrdered()) {
RegisterName name1 = RegisterName(0);
for (RegisterPressure::Set::iterator i = interferences->begin(); !interferences->done(i); i = interferences->advance(i)) {
Uint32 interferenceIndex = interferences->get(i);
while(interferenceIndex >= offset[name1 + 1])
name1 = RegisterName(name1 + 1);
assert((interferenceIndex >= offset[name1]) && (interferenceIndex < offset[name1 + 1]));
RegisterName name2 = RegisterName(interferenceIndex - offset[name1]);
assert(interfere(name1, name2));
InterferenceVector& vector1 = *vector[name1];
vector1.neighbors[vector1.count++] = name2;
InterferenceVector& vector2 = *vector[name2];
vector2.neighbors[vector2.count++] = name1;
}
} else {
trespass("not Implemented"); // FIX: need one more pass to initialize the vectors.
}
}
template <class RegisterPressure>
Uint32 InterferenceGraph<RegisterPressure>::getEdgeIndex(RegisterName name1, RegisterName name2)
{
checkMember(name1); checkMember(name2);
assert(name1 != name2); // This is not possible.
return (name1 < name2) ? offset[name2] + name1 : offset[name1] + name2;
}
template <class RegisterPressure>
void InterferenceGraph<RegisterPressure>::setInterference(RegisterName name1, RegisterName name2)
{
interferences->set(getEdgeIndex(name1, name2));
}
template <class RegisterPressure>
bool InterferenceGraph<RegisterPressure>::interfere(RegisterName name1, RegisterName name2)
{
return interferences->test(getEdgeIndex(name1, name2));
}
#ifdef DEBUG_LOG
template <class RegisterPressure>
void InterferenceGraph<RegisterPressure>::printPretty(LogModuleObject log)
{
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Interference Vectors:\n"));
for (Uint32 i = 1; i < rangeCount; i++) {
if (vector[i] != NULL) {
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\tvr%d: (", i));
for (InterferenceVector* v = vector[i]; v != NULL; v = v->next)
for (Uint32 j = 0; j < v->count; j++) {
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("%d", v->neighbors[j]));
if (v->next != NULL || j != (v->count - 1))
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (","));
}
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (")\n"));
}
}
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Interference Matrix:\n"));
for (RegisterName name1 = RegisterName(1); name1 < rangeCount; name1 = RegisterName(name1 + 1)) {
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\t%d:\t", name1));
for (RegisterName name2 = RegisterName(1); name2 < rangeCount; name2 = RegisterName(name2 + 1))
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("%c", ((name1 != name2) && interfere(name1, name2)) ? '1' : '0'));
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
}
}
#endif // DEBUG_LOG
#endif // _INTERFERENCE_GRAPH_H_

View File

@@ -1,87 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _LIVE_RANGE_H_
#define _LIVE_RANGE_H_
#include "Fundamentals.h"
#include "ControlGraph.h"
#include "ControlNodes.h"
#include "Primitives.h"
#include "Instruction.h"
#include "RegisterAllocator.h"
#include "RegisterAllocatorTools.h"
template <class RegisterPressure>
struct LiveRange
{
static void build(RegisterAllocator& registerAllocator);
};
template <class RegisterPressure>
void LiveRange<RegisterPressure>::build(RegisterAllocator& registerAllocator)
{
// Intialize the lookup table.
//
Uint32 nameCount = registerAllocator.nameCount;
RegisterName* nameTable = new(registerAllocator.pool) RegisterName[2*nameCount];
RegisterName* rangeName = &nameTable[nameCount];
init(rangeName, nameCount);
// Walk the graph.
//
ControlGraph& controlGraph = registerAllocator.controlGraph;
ControlNode** nodes = controlGraph.dfsList;
Uint32 nNodes = controlGraph.nNodes;
SparseSet destination(registerAllocator.pool, nameCount);
for (Uint32 n = 0; n < nNodes; n++) {
InstructionList& phiNodes = nodes[n]->getPhiNodeInstructions();
destination.clear();
for (InstructionList::iterator i = phiNodes.begin(); !phiNodes.done(i); i = phiNodes.advance(i)) {
Instruction& phiNode = phiNodes.get(i);
assert(phiNode.getInstructionDefineBegin() != phiNode.getInstructionDefineEnd() && phiNode.getInstructionDefineBegin()[0].isRegister());
destination.set(findRoot(phiNode.getInstructionDefineBegin()[0].getRegisterName(), rangeName));
}
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
Instruction& phiNode = phiNodes.get(p);
assert(phiNode.getInstructionDefineBegin() != phiNode.getInstructionDefineEnd() && phiNode.getInstructionDefineBegin()[0].isRegister());
RegisterName destinationName = phiNode.getInstructionDefineBegin()[0].getRegisterName();
RegisterName destinationRoot = findRoot(destinationName, rangeName);
InstructionUse* useEnd = phiNode.getInstructionUseEnd();
for (InstructionUse* usePtr = phiNode.getInstructionUseBegin(); usePtr < useEnd; usePtr++) {
assert(usePtr->isRegister());
RegisterName sourceName = usePtr->getRegisterName();
RegisterName sourceRoot = findRoot(sourceName, rangeName);
if (sourceRoot != destinationRoot && !destination.test(sourceRoot))
rangeName[sourceRoot] = destinationRoot;
}
}
}
registerAllocator.rangeCount = compress(registerAllocator.name2range, rangeName, nameCount, nameCount);
}
#endif // _LIVE_RANGE_H_

View File

@@ -1,163 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _LIVE_RANGE_GRAPH_
#define _LIVE_RANGE_GRAPH_
#include "Fundamentals.h"
#include "Pool.h"
#include "ControlGraph.h"
#include "ControlNodes.h"
#include "Instruction.h"
#include "RegisterTypes.h"
class RegisterAllocator;
template <class RegisterPressure>
class LiveRangeGraph
{
private:
RegisterAllocator& registerAllocator;
RegisterPressure::Set* edges;
Uint32 rangeCount;
public:
//
//
LiveRangeGraph(RegisterAllocator& registerAllocator) : registerAllocator(registerAllocator) {}
//
//
void build();
//
//
void addEdge(RegisterName name1, RegisterName name2);
//
//
bool haveEdge(RegisterName name1, RegisterName name2);
#ifdef DEBUG_LOG
//
//
void printPretty(LogModuleObject log);
#endif // DEBUG_LOG
};
template <class RegisterPressure>
void LiveRangeGraph<RegisterPressure>::build()
{
Pool& pool = registerAllocator.pool;
Uint32 rangeCount = registerAllocator.rangeCount;
this->rangeCount = rangeCount;
edges = new(pool) RegisterPressure::Set(pool, rangeCount * rangeCount);
ControlGraph& controlGraph = registerAllocator.controlGraph;
ControlNode** nodes = controlGraph.dfsList;
Uint32 nNodes = controlGraph.nNodes;
RegisterName* name2range = registerAllocator.name2range;
LivenessInfo<RegisterPressure>& liveness = registerAllocator.liveness;
SparseSet currentLive(pool, rangeCount);
for (Uint32 n = 0; n < nNodes; n++) {
ControlNode& node = *nodes[n];
currentLive = liveness.liveOut[n];
InstructionList& instructions = node.getInstructions();
for (InstructionList::iterator i = instructions.end(); !instructions.done(i); i = instructions.retreat(i)) {
Instruction& instruction = instructions.get(i);
InstructionUse* useBegin = instruction.getInstructionUseBegin();
InstructionUse* useEnd = instruction.getInstructionUseEnd();
InstructionUse* usePtr;
InstructionDefine* defineBegin = instruction.getInstructionDefineBegin();
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
InstructionDefine* definePtr;
if ((instruction.getFlags() & ifCopy) != 0) {
assert(useBegin != useEnd && useBegin[0].isRegister());
currentLive.clear(name2range[useBegin[0].getRegisterName()]);
}
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
if (definePtr->isRegister()) {
RegisterName define = name2range[definePtr->getRegisterName()];
for (SparseSet::iterator l = currentLive.begin(); !currentLive.done(l); l = currentLive.advance(l)) {
RegisterName live = RegisterName(currentLive.get(l));
if (define != live && registerAllocator.canInterfere(define, live))
addEdge(define, live);
}
}
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
if (definePtr->isRegister())
currentLive.clear(name2range[definePtr->getRegisterName()]);
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
if (usePtr->isRegister())
currentLive.set(name2range[usePtr->getRegisterName()]);
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
if (usePtr->isRegister()) {
RegisterName use = name2range[usePtr->getRegisterName()];
for (SparseSet::iterator l = currentLive.begin(); !currentLive.done(l); l = currentLive.advance(l)) {
RegisterName live = RegisterName(currentLive.get(l));
if (use != live && registerAllocator.canInterfere(use, live))
addEdge(use, live);
}
}
}
}
}
template <class RegisterPressure>
void LiveRangeGraph<RegisterPressure>::addEdge(RegisterName name1, RegisterName name2)
{
assert(name1 != name2);
edges->set(name1 * rangeCount + name2);
}
template <class RegisterPressure>
bool LiveRangeGraph<RegisterPressure>::haveEdge(RegisterName name1, RegisterName name2)
{
assert(name1 != name2);
return edges->test(name1 * rangeCount + name2);
}
#ifdef DEBUG_LOG
template <class RegisterPressure>
void LiveRangeGraph<RegisterPressure>::printPretty(LogModuleObject log)
{
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Live ranges graph:\n"));
for (RegisterName name1 = RegisterName(1); name1 < rangeCount; name1 = RegisterName(name1 + 1)) {
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\t%d:\t", name1));
for (RegisterName name2 = RegisterName(1); name2 < rangeCount; name2 = RegisterName(name2 + 1))
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("%c", ((name1 != name2) && haveEdge(name1, name2)) ? '1' : '0'));
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
}
}
#endif // DEBUG_LOG
#endif // _LIVE_RANGE_GRAPH_

View File

@@ -1,301 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _LIVENESS_H_
#define _LIVENESS_H_
#include "Fundamentals.h"
#include "ControlGraph.h"
#include "ControlNodes.h"
#include "Instruction.h"
#include "RegisterTypes.h"
// ----------------------------------------------------------------------------
// LivenessInfo -
template <class RegisterPressure>
struct LivenessInfo
{
RegisterPressure::Set* liveIn;
RegisterPressure::Set* liveOut;
DEBUG_LOG_ONLY(Uint32 size);
#ifdef DEBUG_LOG
void printPretty(LogModuleObject log);
#endif // DEBUG_LOG
};
// ----------------------------------------------------------------------------
// Liveness
//
// The liveness is defined by the following data-flow equations:
//
// LiveIn(n) = LocalLive(n) U (LiveOut(n) - Killed(n)).
// LiveOut(n) = U LiveIn(s) (s a successor of n).
//
// where LocalLive(n) is the set of used registers in the block n, Killed(n)
// is the set of defined registers in the block n, LiveIn(n) is the set of
// live registers at the begining of the block n and LiveOut(n) is the set
// of live registers at the end of the block n.
//
//
// We will compute the liveness analysis in two stages:
//
// 1- Build LocalLive(n) (wich is an approximation of LiveIn(n)) and Killed(n)
// for each block n.
// 2- Perform a backward data-flow analysis to propagate the liveness information
// through the entire control-flow graph.
//
template <class RegisterPressure>
struct Liveness
{
static LivenessInfo<RegisterPressure> analysis(ControlGraph& controlGraph, Uint32 rangeCount, const RegisterName* name2range);
static LivenessInfo<RegisterPressure> analysis(ControlGraph& controlGraph, Uint32 nameCount);
};
template <class RegisterPressure>
LivenessInfo<RegisterPressure> Liveness<RegisterPressure>::analysis(ControlGraph& controlGraph, Uint32 rangeCount, const RegisterName* name2range)
{
Pool& pool = controlGraph.pool;
ControlNode** nodes = controlGraph.dfsList;
Uint32 nNodes = controlGraph.nNodes;
// Allocate the temporary sets.
RegisterPressure::Set* killed = new(pool) RegisterPressure::Set[nNodes](pool, rangeCount);
// Allocate the globals sets.
RegisterPressure::Set* liveIn = new(pool) RegisterPressure::Set[nNodes](pool, rangeCount);
RegisterPressure::Set* liveOut = new(pool) RegisterPressure::Set[nNodes](pool, rangeCount);
// First stage of the liveness analysis: Compute the sets LocalLive(stored in LiveIn) and Killed.
//
for (Uint32 n = 0; n < (nNodes - 1); n++) {
ControlNode& node = *nodes[n];
RegisterPressure::Set& currentLocalLive = liveIn[n];
RegisterPressure::Set& currentKilled = killed[n];
// Find the instructions contributions to the sets LocalLive and Killed.
//
InstructionList& instructions = node.getInstructions();
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
Instruction& instruction = instructions.get(i);
// If a VirtualRegister is 'used' before being 'defined' then we add it to set LocalLive.
InstructionUse* useEnd = instruction.getInstructionUseEnd();
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
if (usePtr->isRegister()) {
Uint32 index = name2range[usePtr->getRegisterName()];
if (!currentKilled.test(index))
currentLocalLive.set(index);
}
// If a Virtualregister is 'defined' then we add it to the set Killed.
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
if (definePtr->isRegister())
currentKilled.set(name2range[definePtr->getRegisterName()]);
}
}
// Second stage of the liveness analysis: We propagate the LiveIn & LiveOut through the entire
// control-flow graph.
//
RegisterPressure::Set temp(pool, rangeCount);
bool changed;
do {
changed = false;
// For all nodes is this graph except the endNode.
for (Int32 n = (nNodes - 2); n >= 0; n--) {
ControlNode& node = *nodes[n];
RegisterPressure::Set& currentLiveIn = liveIn[n];
RegisterPressure::Set& currentLiveOut = liveOut[n];
// Compute temp = Union of LiveIn(s) (s a successor of this node) | usedByPhiNodes(n).
// temp will be the new LiveOut(n).
Uint32 nSuccessors = node.nSuccessors();
if (nSuccessors != 0) {
temp = liveIn[node.nthSuccessor(0).getTarget().dfsNum];
for (Uint32 s = 1; s < nSuccessors; s++)
temp |= liveIn[node.nthSuccessor(s).getTarget().dfsNum];
} else
temp.clear();
// If temp and LiveOut(n) differ then set LiveOut(n) = temp and recalculate the
// new LiveIn(n).
if (currentLiveOut != temp) {
currentLiveOut = temp;
temp -= killed[n]; // FIX: could be optimized with one call to unionDiff !
temp |= currentLiveIn;
if (currentLiveIn != temp) {
currentLiveIn = temp;
changed = true;
}
}
}
} while(changed);
LivenessInfo<RegisterPressure> liveness;
liveness.liveIn = liveIn;
liveness.liveOut = liveOut;
DEBUG_LOG_ONLY(liveness.size = nNodes);
return liveness;
}
template <class RegisterPressure>
LivenessInfo<RegisterPressure> Liveness<RegisterPressure>::analysis(ControlGraph& controlGraph, Uint32 nameCount)
{
Pool& pool = controlGraph.pool;
ControlNode** nodes = controlGraph.dfsList;
Uint32 nNodes = controlGraph.nNodes;
// Allocate the temporary sets.
RegisterPressure::Set* killed = new(pool) RegisterPressure::Set[nNodes](pool, nameCount);
RegisterPressure::Set* usedByPhiNodes = NULL;
// Allocate the globals sets.
RegisterPressure::Set* liveIn = new(pool) RegisterPressure::Set[nNodes](pool, nameCount);
RegisterPressure::Set* liveOut = new(pool) RegisterPressure::Set[nNodes](pool, nameCount);
// First stage of the liveness analysis: Compute the sets LocalLive(stored in LiveIn) and Killed.
//
for (Uint32 n = 0; n < (nNodes - 1); n++) {
ControlNode& node = *nodes[n];
RegisterPressure::Set& currentLocalLive = liveIn[n];
RegisterPressure::Set& currentKilled = killed[n];
InstructionList& phiNodes = node.getPhiNodeInstructions();
if ((usedByPhiNodes == NULL) && !phiNodes.empty())
usedByPhiNodes = new(pool) RegisterPressure::Set[nNodes](pool, nameCount);
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
Instruction& phiNode = phiNodes.get(p);
InstructionDefine& define = phiNode.getInstructionDefineBegin()[0];
currentKilled.set(define.getRegisterName());
typedef DoublyLinkedList<ControlEdge> ControlEdgeList;
const ControlEdgeList& predecessors = node.getPredecessors();
ControlEdgeList::iterator p = predecessors.begin();
InstructionUse* useEnd = phiNode.getInstructionUseEnd();
for (InstructionUse* usePtr = phiNode.getInstructionUseBegin(); usePtr < useEnd; usePtr++, p = predecessors.advance(p))
if (usePtr->isRegister())
usedByPhiNodes[predecessors.get(p).getSource().dfsNum].set(usePtr->getRegisterName());
}
// Find the instructions contributions to the sets LocalLive and Killed.
//
InstructionList& instructions = node.getInstructions();
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
Instruction& instruction = instructions.get(i);
// If a VirtualRegister is 'used' before being 'defined' then we add it to set LocalLive.
InstructionUse* useEnd = instruction.getInstructionUseEnd();
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
if (usePtr->isRegister()) {
Uint32 index = usePtr->getRegisterName();
if (!currentKilled.test(index))
currentLocalLive.set(index);
}
// If a Virtualregister is 'defined' then we add it to the set Killed.
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
if (definePtr->isRegister())
currentKilled.set(definePtr->getRegisterName());
}
}
// Second stage of the liveness analysis: We propagate the LiveIn & LiveOut through the entire
// control-flow graph.
//
RegisterPressure::Set temp(pool, nameCount);
bool changed;
do {
changed = false;
// For all nodes is this graph except the endNode.
for (Int32 n = (nNodes - 2); n >= 0; n--) {
ControlNode& node = *nodes[n];
RegisterPressure::Set& currentLiveIn = liveIn[n];
RegisterPressure::Set& currentLiveOut = liveOut[n];
// Compute temp = Union of LiveIn(s) (s a successor of this node) | usedByPhiNodes(n).
// temp will be the new LiveOut(n).
Uint32 nSuccessors = node.nSuccessors();
if (nSuccessors != 0) {
temp = liveIn[node.nthSuccessor(0).getTarget().dfsNum];
for (Uint32 s = 1; s < nSuccessors; s++)
temp |= liveIn[node.nthSuccessor(s).getTarget().dfsNum];
} else
temp.clear();
// Insert the phiNodes contribution.
if (usedByPhiNodes != NULL)
temp |= usedByPhiNodes[n];
// If temp and LiveOut(n) differ then set LiveOut(n) = temp and recalculate the
// new LiveIn(n).
if (currentLiveOut != temp) {
currentLiveOut = temp;
temp -= killed[n]; // FIX: could be optimized with one call to unionDiff !
temp |= currentLiveIn;
if (currentLiveIn != temp) {
currentLiveIn = temp;
changed = true;
}
}
}
} while(changed);
LivenessInfo<RegisterPressure> liveness;
liveness.liveIn = liveIn;
liveness.liveOut = liveOut;
DEBUG_LOG_ONLY(liveness.size = nNodes);
return liveness;
}
#ifdef DEBUG_LOG
template <class RegisterPressure>
void LivenessInfo<RegisterPressure>::printPretty(LogModuleObject log)
{
for (Uint32 n = 0; n < size; n++) {
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Node N%d:\n\tliveIn = ", n));
liveIn[n].printPretty(log);
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\tliveOut = "));
liveOut[n].printPretty(log);
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
}
}
#endif // DEBUG_LOG
#endif // _LIVENESS_H_

View File

@@ -1,40 +0,0 @@
#! gmake
DEPTH = ../..
MODULE_NAME = RegisterAllocator
include $(DEPTH)/config/config.mk
INCLUDES += \
-I$(DEPTH)/Utilities/General \
-I$(DEPTH)/Utilities/zlib \
-I$(DEPTH)/Runtime/ClassReader \
-I$(DEPTH)/Runtime/NativeMethods \
-I$(DEPTH)/Runtime/System \
-I$(DEPTH)/Runtime/ClassInfo \
-I$(DEPTH)/Runtime/FileReader \
-I$(DEPTH)/Compiler/PrimitiveGraph \
-I$(DEPTH)/Compiler/FrontEnd \
-I$(DEPTH)/Compiler/Optimizer \
-I$(DEPTH)/Compiler/CodeGenerator \
-I$(DEPTH)/Compiler/CodeGenerator/md \
-I$(DEPTH)/Compiler/CodeGenerator/md/$(CPU_ARCH) \
-I$(DEPTH)/Compiler/RegisterAllocator \
-I$(DEPTH)/Driver/StandAloneJava \
-I$(DEPTH)/Debugger \
$(NULL)
CXXSRCS = \
RegisterAllocator.cpp \
RegisterAllocatorTools.cpp \
DominatorGraph.cpp \
VirtualRegister.cpp \
BitSet.cpp \
SparseSet.cpp \
$(NULL)
include $(DEPTH)/config/rules.mk
libs:: $(MODULE)

View File

@@ -1,392 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _PHI_NODE_REMOVER_H_
#define _PHI_NODE_REMOVER_H_
#include "Fundamentals.h"
#include "Pool.h"
#include "ControlGraph.h"
#include "DominatorGraph.h"
#include "VirtualRegister.h"
#include "RegisterPressure.h"
#include "Liveness.h"
#include "Instruction.h"
#include "InstructionEmitter.h"
#include "SparseSet.h"
#include <string.h>
//------------------------------------------------------------------------------
// RegisterNameNode -
struct RegisterNameNode
{
RegisterNameNode* next;
RegisterName newName;
Uint32 nextPushed;
};
//------------------------------------------------------------------------------
// CopyData -
struct CopyData
{
RegisterName source;
RegisterClassKind classKind;
Uint32 useCount;
bool isLiveOut;
RegisterName sourceNameToUse;
RegisterName temporaryName;
RegisterNameNode* newName;
};
//------------------------------------------------------------------------------
// PhiNodeRemover<RegisterPressure> -
template <class RegisterPressure>
struct PhiNodeRemover
{
// Replace the phi nodes by copy instructions.
static void replacePhiNodes(ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter);
};
// Split some of the critical edges and return true if there are still some
// in the graph after that.
//
static bool splitCriticalEdges(ControlGraph& /*cg*/)
{
// FIX: not implemented.
return true;
}
inline void pushName(Pool& pool, RegisterNameNode** stack, SparseSet& pushed, Uint32* nodeListPointer, RegisterName oldName, RegisterName newName)
{
RegisterNameNode& newNode = *new(pool) RegisterNameNode();
if (pushed.test(oldName))
(*stack)->newName = newName;
else {
newNode.newName = newName;
newNode.nextPushed = *nodeListPointer;
*nodeListPointer = oldName;
newNode.next = *stack;
*stack = &newNode;
pushed.set(oldName);
}
}
template <class RegisterPressure>
void PhiNodeRemover<RegisterPressure>::replacePhiNodes(ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter)
{
Pool& pool = controlGraph.pool;
ControlNode** nodes = controlGraph.dfsList;
Uint32 nNodes = controlGraph.nNodes;
// Initialize the local variables.
//
// When we insert the copies we will also need to create new VirtualRegisters for
// the insertion of temporaries. The maximum number of temporary register will not
// exceed the number of phiNodes in the primitive graph.
Uint32 nameCount = vrManager.getSize();
Uint32 maxNameCount = nameCount;
for (Uint32 n = 0; n < nNodes; n++)
maxNameCount += nodes[n]->getPhiNodes().length();
// If the CFG contains some critical edges (backward edge which source has more than one
// outgoing edge and destination has more than one incomimg edge) then we need the liveness
// information to be able to insert temporary copies.
RegisterPressure::Set* liveOut = NULL;
if (splitCriticalEdges(controlGraph))
liveOut = Liveness<LowRegisterPressure>::analysis(controlGraph, nameCount).liveOut;
DominatorGraph dGraph(controlGraph);
SparseSet pushed(pool, maxNameCount);
SparseSet destinationList(pool, maxNameCount);
SparseSet workList(pool, maxNameCount);
CopyData* copyStats = new(pool) CopyData[maxNameCount];
memset(copyStats, '\0', maxNameCount*sizeof(CopyData));
struct NodeStack {
Uint32* next;
Uint32* limit;
Uint32 pushedList;
};
// Allocate the node stack and initialize the node stack pointer.
NodeStack* nodeStack = new(pool) NodeStack[nNodes + 1];
NodeStack* nodeStackPtr = nodeStack;
// We start by the begin node.
Uint32 startNode = 0;
Uint32* next = &startNode;
Uint32* limit = &startNode + 1;
while (true) {
if (next == limit) {
// If there are no more node in the sibling, we have to pop the current
// frame from the stack and update the copyStats of the pushed nodes.
//
if (nodeStackPtr == nodeStack)
// We are at the bottom of the stack and there are no more nodes
// to look at. We are done !
break;
--nodeStackPtr;
// We are done with all the children of this node in the dominator tree.
// We need to update the copy information of all the new names pushed
// during the walk over this node.
Uint32 pushedList = nodeStackPtr->pushedList;
while (pushedList != 0) {
Uint32 nextName = copyStats[pushedList].newName->nextPushed;
copyStats[pushedList].newName = copyStats[pushedList].newName->next;
pushedList = nextName;
}
// restore the previous frame.
next = nodeStackPtr->next;
limit = nodeStackPtr->limit;
} else {
Uint32 currentNode = *next++;
Uint32 pushedList = 0;
// Initialize the sets.
pushed.clear();
destinationList.clear();
// STEP1:
// Walk the instruction list and to replace all the instruction uses with their new name.
// If the instruction is a phi node and its defined register is alive at the end of this
// block then we push the defined register into the stack.
//
ControlNode& node = *nodes[currentNode];
RegisterPressure::Set* currentLiveOut = (liveOut != NULL) ? &liveOut[currentNode] : (RegisterPressure::Set*) 0;
InstructionList& phiNodes = node.getPhiNodeInstructions();
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
Instruction& phiNode = phiNodes.get(p);
InstructionUse* useEnd = phiNode.getInstructionUseEnd();
for (InstructionUse* usePtr = phiNode.getInstructionUseBegin(); usePtr < useEnd; usePtr++) {
assert(usePtr->isRegister());
RegisterName name = usePtr->getRegisterName();
if (copyStats[name].newName != NULL && copyStats[name].newName->newName != name)
usePtr->setRegisterName(copyStats[name].newName->newName);
}
if (currentLiveOut != NULL) {
// This is a phi node and we have to push its defined name if it is live
// at the end of the node. We only need to do this if the CFG has critical edges.
assert(phiNode.getInstructionDefineBegin() != phiNode.getInstructionDefineEnd() && phiNode.getInstructionDefineBegin()[0].isRegister());
RegisterName name = phiNode.getInstructionDefineBegin()[0].getRegisterName();
if (currentLiveOut->test(name))
pushName(pool, &(copyStats[name].newName), pushed, &pushedList, name, name);
}
}
InstructionList& instructions = node.getInstructions();
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
Instruction& instruction = instructions.get(i);
InstructionUse* useEnd = instruction.getInstructionUseEnd();
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
if (usePtr->isRegister()) {
RegisterName name = usePtr->getRegisterName();
if (copyStats[name].newName != NULL && copyStats[name].newName->newName != name)
usePtr->setRegisterName(copyStats[name].newName->newName);
}
}
// STEP2:
// Look at this node's successors' phiNodes. We keep track of the number of time
// a VR will be used by another copy instruction and insert each definition into the
// destinationList. This is the only pass over this node's successors as we will
// get all the information we need in the CopyData structures.
//
ControlEdge* successorEdgeEnd = node.getSuccessorsEnd();
for (ControlEdge* successorEdgePtr = node.getSuccessorsBegin(); successorEdgePtr < successorEdgeEnd; successorEdgePtr++) {
Uint32 useIndex = successorEdgePtr->getIndex();
ControlNode& successor = successorEdgePtr->getTarget();
// Look at its phi nodes. The phi nodes are at the top of the instruction list. We exit
// as soon as we find an instruction which is not a phi node
InstructionList& phiNodes = successor.getPhiNodeInstructions();
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
Instruction& phiNode = phiNodes.get(p);
assert((phiNode.getInstructionUseBegin() + useIndex) < phiNode.getInstructionUseEnd());
assert(phiNode.getInstructionDefineBegin() != phiNode.getInstructionDefineEnd());
InstructionUse& source = phiNode.getInstructionUseBegin()[useIndex];
InstructionDefine& destination = phiNode.getInstructionDefineBegin()[0];
assert(source.isRegister() && destination.isRegister());
RegisterName sourceName = source.getRegisterName();
RegisterName destinationName = destination.getRegisterName();
// Get the correct name for the source.
if (copyStats[sourceName].newName != NULL)
sourceName = copyStats[sourceName].newName->newName;
// Update the CopyData structures.
if ((sourceName != rnInvalid) && (sourceName != destinationName)) {
copyStats[destinationName].source = sourceName;
copyStats[destinationName].classKind = destination.getRegisterClass();
copyStats[destinationName].isLiveOut = (currentLiveOut != NULL) ? currentLiveOut->test(destinationName) : false;
copyStats[destinationName].sourceNameToUse = destinationName;
copyStats[sourceName].sourceNameToUse = sourceName;
copyStats[sourceName].useCount++;
destinationList.set(destinationName);
}
}
}
// STEP3:
// Insert into the worklist only the destination registers that will be not used in
// another copy instruction in this block.
//
assert(workList.getSize() == 0);
for (SparseSet::iterator d = destinationList.begin(); !destinationList.done(d); d = destinationList.advance(d)) {
Uint32 dest = destinationList.get(d);
if (copyStats[dest].useCount == 0)
workList.set(dest);
}
// STEP4:
// Insert the copy instructions.
//
Uint32 destinationListSize = destinationList.getSize();
InstructionList::iterator endOfTheNode = instructions.end();
// Find the right place to insert the copy instructions.
if (destinationListSize != 0)
while (instructions.get(endOfTheNode).getFlags() & ifControl)
endOfTheNode = instructions.retreat(endOfTheNode);
while (destinationListSize != 0) {
while(workList.getSize()) {
RegisterName destinationName = RegisterName(workList.getOne());
RegisterName sourceName = copyStats[destinationName].source;
workList.clear(destinationName);
if (copyStats[destinationName].isLiveOut && !copyStats[destinationName].temporaryName) {
// Lost copy problem.
copyStats[destinationName].isLiveOut = false;
RegisterName sourceName = destinationName;
RegisterClassKind classKind = copyStats[sourceName].classKind;
RegisterName destinationName = getName(vrManager.newVirtualRegister(classKind));
assert(destinationName < maxNameCount);
copyStats[destinationName].classKind = classKind;
copyStats[sourceName].useCount = 0;
// We need to insert a copy to a temporary register to keep the
// source register valid at the end of the node defining it.
// This copy will be inserted right after the phi node defining it.
RegisterName from = copyStats[sourceName].sourceNameToUse;
Instruction* definingPhiNode = vrManager.getVirtualRegister(from).getDefiningInstruction();
assert(definingPhiNode && (definingPhiNode->getFlags() & ifPhiNode) != 0);
RegisterID fromID = buildRegisterID(from, classKind);
RegisterID toID = buildRegisterID(destinationName, classKind);
Instruction& copy = emitter.newCopy(*definingPhiNode->getPrimitive(), fromID, toID);
vrManager.getVirtualRegister(destinationName).setDefiningInstruction(copy);
definingPhiNode->getPrimitive()->getContainer()->getInstructions().addFirst(copy);
copyStats[sourceName].temporaryName = destinationName;
copyStats[sourceName].sourceNameToUse = destinationName;
pushName(pool, &(copyStats[sourceName].newName), pushed, &pushedList, sourceName, destinationName);
}
// Insert the copy instruction at the end of the current node.
RegisterName from = copyStats[sourceName].sourceNameToUse;
RegisterClassKind classKind = copyStats[destinationName].classKind;
RegisterID fromID = buildRegisterID(from, classKind);
RegisterID toID = buildRegisterID(destinationName, classKind);
Instruction& copy = emitter.newCopy(*vrManager.getVirtualRegister(from).getDefiningInstruction()->getPrimitive(), fromID, toID);
instructions.insertAfter(copy, endOfTheNode);
endOfTheNode = instructions.advance(endOfTheNode);
copyStats[sourceName].useCount = 0;
if (destinationList.test(sourceName) && copyStats[sourceName].isLiveOut)
pushName(pool, &(copyStats[sourceName].newName), pushed, &pushedList, sourceName, destinationName);
copyStats[sourceName].isLiveOut = false;
copyStats[sourceName].sourceNameToUse = destinationName;
if (destinationList.test(sourceName))
workList.set(sourceName);
destinationList.clear(destinationName);
}
destinationListSize = destinationList.getSize();
if (destinationListSize != 0) {
RegisterName sourceName = RegisterName(destinationList.getOne());
RegisterName destinationName;
if (!copyStats[sourceName].temporaryName) {
// Cycle problem.
RegisterClassKind classKind = copyStats[sourceName].classKind;
destinationName = getName(vrManager.newVirtualRegister(classKind));
assert(destinationName < maxNameCount);
copyStats[destinationName].classKind = classKind;
copyStats[sourceName].temporaryName = destinationName;
// Insert the copy instruction at the end of the current node.
RegisterName from = copyStats[sourceName].sourceNameToUse;
RegisterID fromID = buildRegisterID(from, classKind);
RegisterID toID = buildRegisterID(destinationName, classKind);
Instruction& copy = emitter.newCopy(*vrManager.getVirtualRegister(from).getDefiningInstruction()->getPrimitive(), fromID, toID);
vrManager.getVirtualRegister(destinationName).setDefiningInstruction(copy);
instructions.insertAfter(copy, endOfTheNode);
endOfTheNode = instructions.advance(endOfTheNode);
} else
destinationName = copyStats[sourceName].temporaryName;
copyStats[sourceName].useCount = 0;
copyStats[sourceName].isLiveOut = false;
copyStats[sourceName].sourceNameToUse = destinationName;
pushName(pool, &(copyStats[sourceName].newName), pushed, &pushedList, sourceName, destinationName);
workList.set(sourceName);
}
}
nodeStackPtr->pushedList = pushedList;
nodeStackPtr->next = next;
nodeStackPtr->limit = limit;
++nodeStackPtr;
next = dGraph.getSuccessorsBegin(currentNode);
limit = dGraph.getSuccessorsEnd(currentNode);
}
}
}
#endif // _PHI_NODE_REMOVER_H_

View File

@@ -1,155 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "Fundamentals.h"
#include "LogModule.h"
#include "RegisterAllocator.h"
#include "RegisterPressure.h"
#include "RegisterAllocatorTools.h"
#include "PhiNodeRemover.h"
#include "LiveRange.h"
#include "Liveness.h"
#include "InterferenceGraph.h"
#include "LiveRangeGraph.h"
#include "Coalescing.h"
#include "Spilling.h"
#include "Coloring.h"
#include "Splits.h"
class Pool;
class ControlGraph;
class VirtualRegisterManager;
class InstructionEmitter;
UT_DEFINE_LOG_MODULE(RegAlloc);
void RegisterAllocator::allocateRegisters(Pool& pool, ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter)
{
// Insert the phi node instructions. We want to do this to have a single defined register per instruction.
// If we keep the PhiNode (as a DataNode) and a PhiNode is of DoubleWordKind then we have to execute
// some special code for the high word annotation.
//
RegisterAllocatorTools::insertPhiNodeInstructions(controlGraph, emitter);
// Perform some tests on the instruction graph.
//
DEBUG_ONLY(RegisterAllocatorTools::testTheInstructionGraph(controlGraph, vrManager));
// Replace the phi node instructions by their equivalent copy instructions.
//
PhiNodeRemover<LowRegisterPressure>::replacePhiNodes(controlGraph, vrManager, emitter);
// Do the register allocation.
//
RegisterAllocator registerAllocator(pool, controlGraph, vrManager, emitter);
registerAllocator.doGraphColoring();
}
void RegisterAllocator::doGraphColoring()
{
// Initialize the liverange map.
//
initLiveRanges();
// Build the live ranges. We do this to compress the number of RegisterNames
// used in the insterference graph.
//
LiveRange<LowRegisterPressure>::build(*this);
// Remove unnecessary copies.
//
RegisterAllocatorTools::removeUnnecessaryCopies(*this);
for (Uint8 loop = 0; loop < 10; loop++) {
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("********* RegisterAllocator loop %d *********\n", loop));
while(true) {
// Build the interference graph.
//
iGraph.build();
// Coalesce the copy instructions.
//
if (!Coalescing<LowRegisterPressure>::coalesce(*this))
break;
}
// Print the interference graph.
//
DEBUG_LOG_ONLY(iGraph.printPretty(UT_LOG_MODULE(RegAlloc)));
// Calculate the spill costs.
//
Spilling<LowRegisterPressure>::calculateSpillCosts(*this);
DEBUG_LOG_ONLY(RegisterAllocatorTools::printSpillCosts(*this));
// Calculate the split costs.
//
Splits<LowRegisterPressure>::calculateSplitCosts(*this);
DEBUG_LOG_ONLY(RegisterAllocatorTools::printSplitCosts(*this));
// Build the live range graph.
//
lGraph.build();
DEBUG_LOG_ONLY(lGraph.printPretty(UT_LOG_MODULE(RegAlloc)));
// Color the graph. If it succeeds then we're done with the
// register allocation.
//
if (Coloring<LowRegisterPressure>::color(*this)) {
// Write the final colors in the instruction graph.
//
Coloring<LowRegisterPressure>::finalColoring(*this);
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("********** RegisterAllocator done **********\n"));
DEBUG_LOG_ONLY(RegisterAllocatorTools::printInstructions(*this));
return;
}
// We need to spill some registers.
//
Spilling<LowRegisterPressure>::insertSpillCode(*this);
// Insert the split instructions.
//
Splits<LowRegisterPressure>::insertSplitCode(*this);
// Update the live ranges.
//
// FIX
}
#ifdef DEBUG_LOG
RegisterAllocatorTools::updateInstructionGraph(*this);
RegisterAllocatorTools::printInstructions(*this);
#endif
fprintf(stderr, "!!! Coloring failed after 10 loops !!!\n");
abort();
}
void RegisterAllocator::initLiveRanges()
{
Uint32 count = this->nameCount;
RegisterName* name2range = new(pool) RegisterName[nameCount];
for (RegisterName r = RegisterName(1); r < count; r = RegisterName(r + 1))
name2range[r] = r;
this->name2range = name2range;
rangeCount = count;
}

View File

@@ -1,88 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _REGISTER_ALLOCATOR_H_
#define _REGISTER_ALLOCATOR_H_
class Pool;
class ControlGraph;
class InstructionEmitter;
struct SpillCost;
struct SplitCost;
#include "Liveness.h"
#include "VirtualRegister.h"
#include "RegisterPressure.h" // This should included by Backend.cpp
#include "InterferenceGraph.h"
#include "LiveRangeGraph.h"
//template <class RegisterPressure>
class RegisterAllocator
{
public:
Pool& pool; //
ControlGraph& controlGraph; //
VirtualRegisterManager& vrManager; //
InstructionEmitter& emitter; //
RegisterName* name2range; //
RegisterName* color; //
SpillCost* spillCost; //
SparseSet* willSpill; //
SplitCost* splitCost; //
NameLinkedList** splitAround; //
InterferenceGraph<LowRegisterPressure> iGraph; //
LiveRangeGraph<LowRegisterPressure> lGraph; //
LivenessInfo<LowRegisterPressure> liveness; //
Uint32 nameCount; //
Uint32 rangeCount; //
bool splitFound; //
private:
//
//
void doGraphColoring();
public:
//
//
inline RegisterAllocator(Pool& pool, ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter);
//
//
bool canInterfere(RegisterName /*name1*/, RegisterName /*name2*/) const {return true;}
//
//
void initLiveRanges();
//
//
static void allocateRegisters(Pool& pool, ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter);
};
//
//
inline RegisterAllocator::RegisterAllocator(Pool& pool, ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter)
: pool(pool), controlGraph(controlGraph), vrManager(vrManager), emitter(emitter), iGraph(*this), lGraph(*this), nameCount(vrManager.getSize()) {}
#endif // _REGISTER_ALLOCATOR_H_

View File

@@ -1,355 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "Fundamentals.h"
#include "LogModule.h"
#include "RegisterAllocatorTools.h"
#include "Pool.h"
#include "ControlGraph.h"
#include "ControlNodes.h"
#include "Primitives.h"
#include "InstructionEmitter.h"
#include "Instruction.h"
#include "RegisterAllocator.h"
#include "Spilling.h"
#include "Splits.h"
#include "BitSet.h"
UT_EXTERN_LOG_MODULE(RegAlloc);
#ifdef DEBUG
void RegisterAllocatorTools::testTheInstructionGraph(ControlGraph& controlGraph, VirtualRegisterManager& vrManager)
{
// Test the declared VirtualRegisters. The register allocator tries to condense the register universe.
// Any gap in the VirtualRegister names will be a loss of efficiency !!!!
Uint32 nameCount = vrManager.getSize();
BitSet registerSeen(controlGraph.pool, nameCount);
ControlNode** nodes = controlGraph.dfsList;
Uint32 nNodes = controlGraph.nNodes;
for (Uint32 n = 0; n < nNodes; n++) {
InstructionList& instructions = nodes[n]->getInstructions();
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
Instruction& instruction = instructions.get(i);
InstructionUse* useEnd = instruction.getInstructionUseEnd();
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
if (usePtr->isRegister())
registerSeen.set(usePtr->getRegisterName());
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
if (definePtr->isRegister())
registerSeen.set(definePtr->getRegisterName());
}
InstructionList& phiNodes = nodes[n]->getPhiNodeInstructions();
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
Instruction& instruction = phiNodes.get(p);
InstructionUse* useEnd = instruction.getInstructionUseEnd();
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
if (usePtr->isRegister())
registerSeen.set(usePtr->getRegisterName());
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
if (definePtr->isRegister())
registerSeen.set(definePtr->getRegisterName());
}
}
bool renameRegisters = false;
for (BitSet::iterator i = registerSeen.nextZero(0); !registerSeen.done(i); i = registerSeen.nextZero(i)) {
renameRegisters = true;
fprintf(stderr,
"WARNING: The VirtualRegister vr%d has been allocated during CodeGeneration but\n"
" is never used nor defined by any instruction in the instruction graph\n"
" PLEASE FIX \n",
i);
}
if (renameRegisters) {
Instruction** definingInstruction = new Instruction*[nameCount];
memset(definingInstruction, '\0', nameCount * sizeof(Instruction*));
RegisterName* newName = new RegisterName[nameCount];
memset(newName, '\0', nameCount * sizeof(RegisterName));
RegisterName nextName = RegisterName(1);
for (Uint32 n = 0; n < nNodes; n++) {
InstructionList& instructions = nodes[n]->getInstructions();
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
Instruction& instruction = instructions.get(i);
InstructionUse* useEnd = instruction.getInstructionUseEnd();
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
if (usePtr->isRegister()) {
RegisterName name = usePtr->getRegisterName();
if (newName[name] == rnInvalid) {
newName[name] = nextName;
definingInstruction[nextName] = vrManager.getVirtualRegister(name).getDefiningInstruction();
nextName = RegisterName(nextName + 1);
}
usePtr->setRegisterName(newName[name]);
}
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
if (definePtr->isRegister()) {
RegisterName name = definePtr->getRegisterName();
if (newName[name] == rnInvalid) {
newName[name] = nextName;
definingInstruction[nextName] = vrManager.getVirtualRegister(name).getDefiningInstruction();
nextName = RegisterName(nextName + 1);
}
definePtr->setRegisterName(newName[name]);
}
}
InstructionList& phiNodes = nodes[n]->getPhiNodeInstructions();
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
Instruction& instruction = phiNodes.get(p);
InstructionUse* useEnd = instruction.getInstructionUseEnd();
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
if (usePtr->isRegister()) {
RegisterName name = usePtr->getRegisterName();
if (newName[name] == rnInvalid) {
newName[name] = nextName;
definingInstruction[nextName] = vrManager.getVirtualRegister(name).getDefiningInstruction();
nextName = RegisterName(nextName + 1);
}
usePtr->setRegisterName(newName[name]);
}
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
if (definePtr->isRegister()) {
RegisterName name = definePtr->getRegisterName();
if (newName[name] == rnInvalid) {
newName[name] = nextName;
definingInstruction[nextName] = vrManager.getVirtualRegister(name).getDefiningInstruction();
nextName = RegisterName(nextName + 1);
}
definePtr->setRegisterName(newName[name]);
}
}
}
vrManager.setSize(nextName);
for (RegisterName r = RegisterName(1); r < nextName; r = RegisterName(r + 1))
vrManager.getVirtualRegister(r).definingInstruction = definingInstruction[r];
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("RegisterMap:\n"));
for (Uint32 i = 1; i < nameCount; i++)
if (newName[i] != 0)
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\tvr%d becomes vr%d.\n", i, newName[i]));
else
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\tvr%d is dead.\n", i));
delete newName;
delete definingInstruction;
}
}
#endif // DEBUG
void RegisterAllocatorTools::removeUnnecessaryCopies(RegisterAllocator& registerAllocator)
{
ControlGraph& controlGraph = registerAllocator.controlGraph;
ControlNode** nodes = controlGraph.dfsList;
Uint32 nNodes = controlGraph.nNodes;
RegisterName* name2range = registerAllocator.name2range;
for (Uint32 n = 0; n < nNodes; n++) {
InstructionList& instructions = nodes[n]->getInstructions();
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i);) {
Instruction& instruction = instructions.get(i);
i = instructions.advance(i);
if (instruction.getFlags() & ifCopy) {
assert(instruction.getInstructionUseBegin() != instruction.getInstructionUseEnd() && instruction.getInstructionUseBegin()[0].isRegister());
assert(instruction.getInstructionDefineBegin() != instruction.getInstructionDefineEnd() && instruction.getInstructionDefineBegin()[0].isRegister());
RegisterName source = name2range[instruction.getInstructionUseBegin()[0].getRegisterName()];
RegisterName destination = name2range[instruction.getInstructionDefineBegin()[0].getRegisterName()];
if (source == destination)
instruction.remove();
}
}
}
}
void RegisterAllocatorTools::updateInstructionGraph(RegisterAllocator& registerAllocator)
{
ControlGraph& controlGraph = registerAllocator.controlGraph;
ControlNode** nodes = controlGraph.dfsList;
Uint32 nNodes = controlGraph.nNodes;
RegisterName* name2range = registerAllocator.name2range;
for (Uint32 n = 0; n < nNodes; n++) {
InstructionList& instructions = nodes[n]->getInstructions();
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
Instruction& instruction = instructions.get(i);
InstructionUse* useEnd = instruction.getInstructionUseEnd();
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
if (usePtr->isRegister())
usePtr->setRegisterName(name2range[usePtr->getRegisterName()]);
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
if (definePtr->isRegister())
definePtr->setRegisterName(name2range[definePtr->getRegisterName()]);
}
InstructionList& phiNodes = nodes[n]->getPhiNodeInstructions();
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
Instruction& instruction = phiNodes.get(p);
InstructionUse* useEnd = instruction.getInstructionUseEnd();
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
if (usePtr->isRegister())
usePtr->setRegisterName(name2range[usePtr->getRegisterName()]);
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
if (definePtr->isRegister())
definePtr->setRegisterName(name2range[definePtr->getRegisterName()]);
}
}
}
void RegisterAllocatorTools::insertPhiNodeInstructions(ControlGraph& controlGraph, InstructionEmitter& emitter)
{
Pool& pool = controlGraph.pool;
ControlNode** nodes = controlGraph.dfsList;
Uint32 nNodes = controlGraph.nNodes;
for (Uint32 n = 0; n < nNodes; n++) {
ControlNode& node = *nodes[n];
DoublyLinkedList<PhiNode>& phiNodes = node.getPhiNodes();
if (!phiNodes.empty()) {
// Set the index of the incoming edges.
Uint32 index = 0;
const DoublyLinkedList<ControlEdge>& predecessors = node.getPredecessors();
for (DoublyLinkedList<ControlEdge>::iterator p = predecessors.begin(); !predecessors.done(p); p = predecessors.advance(p))
predecessors.get(p).setIndex(index++);
// Insert the phi node instruction in the instruction list.
for (DoublyLinkedList<PhiNode>::iterator i = phiNodes.begin(); !phiNodes.done(i); i = phiNodes.advance(i)) {
PhiNode& phiNode = phiNodes.get(i);
ValueKind kind = phiNode.getKind();
if (!isStorableKind(kind))
continue;
RegisterClassKind classKind = rckGeneral; // FIX: get class kind from phi node kind.
Uint32 nInputs = phiNode.nInputs();
PhiNodeInstruction& phiNodeInstruction = *new(pool) PhiNodeInstruction(&phiNode, pool, nInputs);
emitter.defineProducer(phiNode, phiNodeInstruction, 0, classKind, drLow);
for (Uint32 whichInput = 0; whichInput < nInputs; whichInput++)
emitter.useProducer(phiNode.nthInputVariable(whichInput), phiNodeInstruction, whichInput, classKind, drLow);
node.addPhiNodeInstruction(phiNodeInstruction);
if (isDoublewordKind(kind)) {
PhiNodeInstruction& phiNodeInstruction = *new(pool) PhiNodeInstruction(&phiNode, pool, nInputs);
emitter.defineProducer(phiNode, phiNodeInstruction, 0, classKind, drHigh);
for (Uint32 whichInput = 0; whichInput < nInputs; whichInput++)
emitter.useProducer(phiNode.nthInputVariable(whichInput), phiNodeInstruction, whichInput, classKind, drHigh);
node.addPhiNodeInstruction(phiNodeInstruction);
}
}
}
}
}
#ifdef DEBUG_LOG
void RegisterAllocatorTools::printSpillCosts(RegisterAllocator& registerAllocator)
{
LogModuleObject log = UT_LOG_MODULE(RegAlloc);
Uint32 rangeCount = registerAllocator.rangeCount;
SpillCost* cost = registerAllocator.spillCost;
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Spill costs:\n"));
for (Uint32 i = 1; i < rangeCount; i++) {
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\trange %d : ", i));
if (cost[i].infinite)
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("infinite\n"));
else
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("%f\n", cost[i].cost));
}
}
void RegisterAllocatorTools::printSplitCosts(RegisterAllocator& registerAllocator)
{
LogModuleObject log = UT_LOG_MODULE(RegAlloc);
Uint32 rangeCount = registerAllocator.rangeCount;
SplitCost* cost = registerAllocator.splitCost;
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Split costs:\n"));
for (Uint32 i = 1; i < rangeCount; i++) {
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\trange %d : loads = %f stores = %f\n", i, cost[i].loads, cost[i].stores));
}
}
void RegisterAllocatorTools::printInstructions(RegisterAllocator& registerAllocator)
{
LogModuleObject log = UT_LOG_MODULE(RegAlloc);
ControlNode** nodes = registerAllocator.controlGraph.dfsList;
Uint32 nNodes = registerAllocator.controlGraph.nNodes;
for (Uint32 n = 0; n < nNodes; n++) {
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("N%d:\n", n));
InstructionList& phiNodes = nodes[n]->getPhiNodeInstructions();
InstructionList& instructions = nodes[n]->getInstructions();
if (!phiNodes.empty()) {
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (" PhiNodes:\n", n));
for(InstructionList::iterator i = phiNodes.begin(); !phiNodes.done(i); i = phiNodes.advance(i)) {
phiNodes.get(i).printPretty(log);
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
}
if (!instructions.empty())
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (" Instructions:\n", n));
}
for(InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
instructions.get(i).printPretty(log);
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
}
}
}
#endif // DEBUG_LOG

View File

@@ -1,117 +0,0 @@
// -*- mode:C++; tab-width:4; truncate-lines:t -*-
//
// CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
// NETSCAPE COMMUNICATIONS CORPORATION
// Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
// Reserved. Use of this Source Code is subject to the terms of the
// applicable license agreement from Netscape Communications Corporation.
// The copyright notice(s) in this Source Code does not indicate actual or
// intended publication of this Source Code.
//
// $Id: RegisterAllocatorTools.h,v 1.1.2.1 1999-03-02 16:12:05 fur%netscape.com Exp $
//
#ifndef _REGISTER_ALLOCATOR_TOOLS_H_
#define _REGISTER_ALLOCATOR_TOOLS_H_
#include "LogModule.h"
#include "RegisterTypes.h"
#include <string.h>
class RegisterAllocator;
class ControlGraph;
class InstructionEmitter;
class VirtualRegisterManager;
struct RegisterAllocatorTools
{
//
//
static void insertPhiNodeInstructions(ControlGraph& controlGraph, InstructionEmitter& emitter);
//
//
static void updateInstructionGraph(RegisterAllocator& registerAllocator);
//
//
static void removeUnnecessaryCopies(RegisterAllocator& registerAllocator);
#ifdef DEBUG
//
//
static void testTheInstructionGraph(ControlGraph& controlGraph, VirtualRegisterManager& vrManager);
#endif // DEBUG
#ifdef DEBUG_LOG
//
//
static void printInstructions(RegisterAllocator& registerAllocator);
//
//
static void printSpillCosts(RegisterAllocator& registerAllocator);
//
//
static void printSplitCosts(RegisterAllocator& registerAllocator);
#endif // DEBUG_LOG
};
//
// FIX: this should go in a class (LookupTable ?)
//
inline RegisterName findRoot(RegisterName name, RegisterName* table)
{
RegisterName* stack = table;
RegisterName* stackPtr = stack;
RegisterName newName;
while((newName = table[name]) != name) {
*--stackPtr = name;
name = newName;
}
while (stackPtr != stack)
table[*stackPtr++] = name;
return name;
}
inline void init(RegisterName* table, Uint32 nameCount)
{
for (RegisterName r = RegisterName(0); r < nameCount; r = RegisterName(r + 1))
table[r] = r;
}
inline Uint32 compress(RegisterName* name2range, RegisterName* table, Uint32 nameCount, Uint32 tableSize)
{
RegisterName* liveRange = new RegisterName[tableSize];
memset(liveRange, '\0', tableSize * sizeof(RegisterName));
// Update the lookup table.
for (RegisterName r = RegisterName(1); r < tableSize; r = RegisterName(r + 1))
findRoot(r, table);
// Count the liveranges.
Uint32 liveRangeCount = 1;
for (RegisterName s = RegisterName(1); s < tableSize; s = RegisterName(s + 1))
if (table[s] == s)
liveRange[s] = RegisterName(liveRangeCount++);
for (RegisterName t = RegisterName(1); t < nameCount; t = RegisterName(t + 1))
name2range[t] = liveRange[table[name2range[t]]];
return liveRangeCount;
}
inline double doLog10(Uint32 power)
{
double log = 1.0;
while (power--)
log *= 10.0;
return log;
}
#endif // _REGISTER_ALLOCATOR_TOOLS_H_

View File

@@ -1,38 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _REGISTER_ASSIGNER_H_
#define _REGISTER_ASSIGNER_H_
#include "Fundamentals.h"
#include "VirtualRegister.h"
class FastBitMatrix;
class RegisterAssigner
{
protected:
VirtualRegisterManager& vRegManager;
public:
RegisterAssigner(VirtualRegisterManager& vrMan) : vRegManager(vrMan) {}
virtual bool assignRegisters(FastBitMatrix& interferenceMatrix) = 0;
};
#endif /* _REGISTER_ASSIGNER_H_ */

View File

@@ -1,104 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _REGISTER_TYPES_H_
#define _REGISTER_TYPES_H_
#include "Fundamentals.h"
//------------------------------------------------------------------------------
// RegisterName -
//
enum RegisterName {
rnInvalid = 0,
};
//------------------------------------------------------------------------------
// RegisterClassKind -
//
enum RegisterClassKind {
rckInvalid = 0,
rckGeneral,
rckStackSlot,
nRegisterClassKind
};
//------------------------------------------------------------------------------
// RegisterID -
//
enum RegisterID {
invalidID = 0
};
//------------------------------------------------------------------------------
// RegisterKind -
//
enum RegisterKind {
rkCallerSave = 0,
rkCalleeSave,
};
struct NameLinkedList {
RegisterName name;
NameLinkedList* next;
};
#ifdef DEBUG
const registerNameMask = 0x03ffffff;
const coloredRegisterMask = 0x04000000;
const machineRegisterMask = 0x08000000;
const registerClassMask = 0xf0000000;
const registerNameShift = 0;
const coloredRegisterShift = 26;
const machineRegisterShift = 27;
const registerClassShift = 28;
#else // DEBUG
const registerNameMask = 0x0fffffff;
const registerClassMask = 0xf0000000;
const registerNameShift = 0;
const registerClassShift = 28;
#endif // DEBUG
inline RegisterClassKind getClass(RegisterID registerID) {return RegisterClassKind((registerID & registerClassMask) >> registerClassShift);}
inline RegisterName getName(RegisterID registerID) {return RegisterName((registerID & registerNameMask) >> registerNameShift);}
inline void setClass(RegisterID& registerID, RegisterClassKind classKind) {registerID = RegisterID((registerID & ~registerClassMask) | ((classKind << registerClassShift) & registerClassMask));}
inline void setName(RegisterID& registerID, RegisterName name) {assert((name & ~registerNameMask) == 0); registerID = RegisterID((registerID & ~registerNameMask) | ((name << registerNameShift) & registerNameMask));}
inline RegisterID buildRegisterID(RegisterName name, RegisterClassKind classKind) {return RegisterID(((classKind << registerClassShift) & registerClassMask) | ((name << registerNameShift) & registerNameMask));}
#ifdef DEBUG
inline bool isMachineRegister(RegisterID rid) {return (rid & machineRegisterMask) != 0;}
inline void setMachineRegister(RegisterID& rid) {rid = RegisterID(rid | machineRegisterMask);}
inline bool isColoredRegister(RegisterID rid) {return (rid & coloredRegisterMask) != 0;}
inline void setColoredRegister(RegisterID& rid) {rid = RegisterID(rid | coloredRegisterMask);}
#endif // DEBUG
#endif // _REGISTER_TYPES_H_

View File

@@ -1,168 +0,0 @@
// -*- mode:C++; tab-width:4; truncate-lines:t -*-
//
// CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
// NETSCAPE COMMUNICATIONS CORPORATION
// Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
// Reserved. Use of this Source Code is subject to the terms of the
// applicable license agreement from Netscape Communications Corporation.
// The copyright notice(s) in this Source Code does not indicate actual or
// intended publication of this Source Code.
//
// $Id: SparseSet.h,v 1.1.2.1 1999-03-02 16:12:07 fur%netscape.com Exp $
//
#ifndef _SPARSE_SET_H_
#define _SPARSE_SET_H_
#include "Fundamentals.h"
#include "Pool.h"
#include "LogModule.h"
#include "BitSet.h"
class SparseSet
{
private:
struct Node {
Uint32 element;
Uint32 stackIndex;
};
Node* node;
Uint32 count;
Uint32 universeSize;
private:
// No copy constructor.
SparseSet(const SparseSet&);
// Check if the given set's universe is of the same size than this universe.
void checkUniverseCompatibility(const SparseSet& set) const {assert(set.universeSize == universeSize);}
// Check if pos is valid for this set's universe.
void checkMember(Int32 pos) const {assert(pos >=0 && Uint32(pos) < universeSize);}
public:
SparseSet(Pool& pool, Uint32 universeSize) : universeSize(universeSize) {node = new(pool) Node[universeSize]; clear();}
// Clear the sparse set.
void clear() {count = 0;}
// Clear the element at index.
inline void clear(Uint32 index);
// Set the element at index.
inline void set(Uint32 index);
// Return true if the element at index is set.
inline bool test(Uint32 index) const;
// Union with the given sparse set.
inline void or(const SparseSet& set);
// Intersection with the given sparse set.
inline void and(const SparseSet& set);
// Difference with the given sparse set.
inline void difference(const SparseSet& set);
// Copy set.
inline SparseSet& operator = (const SparseSet& set);
inline SparseSet& operator = (const BitSet& set);
// Return true if the sparse sets are identical.
friend bool operator == (const SparseSet& set1, const SparseSet& set2);
// Return true if the sparse sets are different.
friend bool operator != (const SparseSet& set1, const SparseSet& set2);
// Logical operators.
SparseSet& operator |= (const SparseSet& set) {or(set); return *this;}
SparseSet& operator &= (const SparseSet& set) {and(set); return *this;}
SparseSet& operator -= (const SparseSet& set) {difference(set); return *this;}
// Iterator to conform with the set API.
typedef Int32 iterator;
// Return the iterator for the first element of this set.
iterator begin() const {return count - 1;}
// Return the next iterator.
iterator advance(iterator pos) const {return --pos;}
// Return true if the iterator is at the end of the set.
bool done(iterator pos) const {return pos < 0;}
// Return the element for the given iterator;
Uint32 get(iterator pos) const {return node[pos].element;}
// Return one element of this set.
Uint32 getOne() const {assert(count > 0); return node[0].element;}
// Return the size of this set.
Uint32 getSize() const {return count;}
#ifdef DEBUG_LOG
// Print the set.
void printPretty(LogModuleObject log);
#endif // DEBUG_LOG
};
inline void SparseSet::clear(Uint32 element)
{
checkMember(element);
Uint32 count = this->count;
Node* node = this->node;
Uint32 stackIndex = node[element].stackIndex;
if ((stackIndex < count) && (node[stackIndex].element == element)) {
Uint32 stackTop = node[count - 1].element;
node[stackIndex].element = stackTop;
node[stackTop].stackIndex = stackIndex;
this->count = count - 1;
}
}
inline void SparseSet::set(Uint32 element)
{
checkMember(element);
Uint32 count = this->count;
Node* node = this->node;
Uint32 stackIndex = node[element].stackIndex;
if ((stackIndex >= count) || (node[stackIndex].element != element)) {
node[count].element = element;
node[element].stackIndex = count;
this->count = count + 1;
}
}
inline bool SparseSet::test(Uint32 element) const
{
checkMember(element);
Node* node = this->node;
Uint32 stackIndex = node[element].stackIndex;
return ((stackIndex < count) && (node[stackIndex].element == element));
}
inline SparseSet& SparseSet::operator = (const SparseSet& set)
{
checkUniverseCompatibility(set);
Uint32 sourceCount = set.getSize();
Node* node = this->node;
memcpy(node, set.node, sourceCount * sizeof(Node));
for (Uint32 i = 0; i < sourceCount; i++) {
Uint32 element = node[i].element;
node[element].stackIndex = i;
}
count = sourceCount;
return *this;
}
inline SparseSet& SparseSet::operator = (const BitSet& set)
{
// FIX: there's room for optimization here.
assert(universeSize == set.getSize());
clear();
for (Int32 i = set.firstOne(); i != -1; i = set.nextOne(i))
this->set(i);
return *this;
}
#endif // _SPARSE_SET_H_

View File

@@ -1,270 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef NEW_LAURENTM_CODE
#define INCLUDE_EMITTER
#include "CpuInfo.h"
#include "Fundamentals.h"
#include "ControlNodes.h"
#include "Instruction.h"
#include "InstructionEmitter.h"
#include "Spilling.h"
void Spilling::
insertSpillCode(ControlNode** dfsList, Uint32 nNodes)
{
PRUint32 nVirtualRegisters = vRegManager.count();
FastBitSet currentLive(vRegManager.pool, nVirtualRegisters);
FastBitSet usedInThisInstruction(vRegManager.pool, nVirtualRegisters);
RegisterFifo grNeedLoad(nVirtualRegisters);
RegisterFifo fpNeedLoad(nVirtualRegisters);
for (PRInt32 n = nNodes - 1; n >= 0; n--)
{
PR_ASSERT(grNeedLoad.empty() & fpNeedLoad.empty());
ControlNode& node = *dfsList[n];
currentLive = node.liveAtEnd;
PRUint32 nGeneralAlive = 0;
PRUint32 nFloatingPointAlive = 0;
// Get the number of registers alive at the end of this node.
for (PRInt32 j = currentLive.firstOne(); j != -1; j = currentLive.nextOne(j))
{
VirtualRegister& vReg = vRegManager.getVirtualRegister(j);
if (vReg.spillInfo.willSpill)
{
currentLive.clear(j);
}
else
{
switch (vReg.getClass())
{
case vrcInteger:
nGeneralAlive++;
break;
case vrcFloatingPoint:
case vrcFixedPoint:
nFloatingPointAlive++;
break;
default:
break;
}
}
}
// if(node.dfsNum == 8) printf("\n________Begin Node %d________\n", node.dfsNum);
InstructionList& instructions = node.getInstructions();
for (InstructionList::iterator i = instructions.end(); !instructions.done(i); i = instructions.retreat(i))
{
Instruction& instruction = instructions.get(i);
InstructionUse* useBegin = instruction.getInstructionUseBegin();
InstructionUse* useEnd = instruction.getInstructionUseEnd();
InstructionUse* usePtr;
InstructionDefine* defBegin = instruction.getInstructionDefineBegin();
InstructionDefine* defEnd = instruction.getInstructionDefineEnd();
InstructionDefine* defPtr;
// if(node.dfsNum == 8) { printf("\n");
// instruction.printPretty(stdout);
// printf("\n"); }
// Handle definitions
for (defPtr = defBegin; defPtr < defEnd; defPtr++)
if (defPtr->isVirtualRegister())
{
VirtualRegister& vReg = defPtr->getVirtualRegister();
currentLive.clear(vReg.getRegisterIndex());
switch (vReg.getClass())
{
case vrcInteger:
nGeneralAlive--;
break;
case vrcFloatingPoint:
case vrcFixedPoint:
nFloatingPointAlive--;
break;
default:
break;
}
}
// Check for deaths
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
if (usePtr->isVirtualRegister())
{
VirtualRegister& vReg = usePtr->getVirtualRegister();
if (!currentLive.test(vReg.getRegisterIndex()))
// This is the last use of this register.
{
currentLive.set(vReg.getRegisterIndex());
switch (vReg.getClass())
{
case vrcInteger:
nGeneralAlive++;
while (/*(nGeneralAlive > NUMBER_OF_GREGISTERS) &&*/ !grNeedLoad.empty())
{
PRUint32 toLoad = grNeedLoad.get();
currentLive.clear(toLoad);
nGeneralAlive--;
VirtualRegister& nReg = vRegManager.getVirtualRegister(toLoad);
Instruction& lastUsingInstruction = *nReg.spillInfo.lastUsingInstruction;
emitter.emitLoadAfter(*lastUsingInstruction.getPrimitive(), lastUsingInstruction.getLinks().prev,
nReg.getAlias(), *nReg.equivalentRegister[vrcStackSlot]);
nReg.releaseSelf();
}
break;
case vrcFloatingPoint:
case vrcFixedPoint:
nFloatingPointAlive++;
while (/*(nFloatingPointAlive > NUMBER_OF_FPREGISTERS) &&*/ !fpNeedLoad.empty())
{
PRUint32 toLoad = fpNeedLoad.get();
currentLive.clear(toLoad);
nFloatingPointAlive--;
VirtualRegister& nReg = vRegManager.getVirtualRegister(toLoad);
Instruction& lastUsingInstruction = *nReg.spillInfo.lastUsingInstruction;
emitter.emitLoadAfter(*lastUsingInstruction.getPrimitive(), lastUsingInstruction.getLinks().prev,
nReg.getAlias(), *nReg.equivalentRegister[vrcStackSlot]);
nReg.releaseSelf();
}
break;
default:
break;
}
}
}
// Handle uses
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
if (usePtr->isVirtualRegister())
{
VirtualRegister& vReg = usePtr->getVirtualRegister();
PRUint32 registerIndex = vReg.getRegisterIndex();
if (vReg.spillInfo.willSpill) {
#if defined(GENERATE_FOR_X86)
if (!instruction.switchUseToSpill((usePtr - useBegin), *vReg.equivalentRegister[vrcStackSlot]))
#endif
{
switch (vReg.getClass())
{
case vrcInteger:
if (!grNeedLoad.test(registerIndex))
{
grNeedLoad.put(registerIndex);
VirtualRegister& alias = vRegManager.newVirtualRegister(vrcInteger);
if (vReg.isPreColored())
alias.preColorRegister(vReg.getPreColor());
/* if (vReg.hasSpecialInterference) {
alias.specialInterference.sizeTo(NUMBER_OF_REGISTERS);
alias.specialInterference = vReg.specialInterference;
alias.hasSpecialInterference = true;
} */
vReg.setAlias(alias);
vReg.retainSelf();
}
break;
case vrcFloatingPoint:
case vrcFixedPoint:
if (!fpNeedLoad.test(registerIndex))
{
fpNeedLoad.put(registerIndex);
VirtualRegister& alias = vRegManager.newVirtualRegister(vReg.getClass());
if (vReg.isPreColored())
alias.preColorRegister(vReg.getPreColor());
/*if (vReg.hasSpecialInterference) {
alias.specialInterference.sizeTo(NUMBER_OF_REGISTERS);
alias.specialInterference = vReg.specialInterference;
alias.hasSpecialInterference = true;
} */
vReg.setAlias(alias);
vReg.retainSelf();
}
break;
default:
break;
}
usePtr->getVirtualRegisterPtr().initialize(vReg.getAlias());
usedInThisInstruction.set(registerIndex);
vReg.spillInfo.lastUsingInstruction = &instruction;
}
currentLive.clear(registerIndex);
} else { // will not spill
currentLive.set(registerIndex);
}
}
// Handle definitions
for (defPtr = defBegin; defPtr < defEnd; defPtr++)
if (defPtr->isVirtualRegister())
{
VirtualRegister& vReg = defPtr->getVirtualRegister();
if (vReg.spillInfo.willSpill)
#if defined(GENERATE_FOR_X86)
if (!instruction.switchDefineToSpill((defPtr - defBegin), *vReg.equivalentRegister[vrcStackSlot]))
#endif
{
if (usedInThisInstruction.test(vReg.getRegisterIndex()))
// this virtualRegister was used in this instruction and is also defined. We need to move
// this virtual register to its alias first and then save it to memory.
{
emitter.emitStoreAfter(*instruction.getPrimitive(), &instruction.getLinks(),
vReg.getAlias(), *vReg.equivalentRegister[vrcStackSlot]);
defPtr->getVirtualRegisterPtr().initialize(vReg.getAlias());
}
else
{
emitter.emitStoreAfter(*instruction.getPrimitive(), &instruction.getLinks(),
vReg, *vReg.equivalentRegister[vrcStackSlot]);
}
}
}
}
while (!grNeedLoad.empty())
{
PRUint32 nl = grNeedLoad.get();
VirtualRegister& nlReg = vRegManager.getVirtualRegister(nl);
Instruction& lastUse = *nlReg.spillInfo.lastUsingInstruction;
emitter.emitLoadAfter(*lastUse.getPrimitive(), lastUse.getLinks().prev,
nlReg.getAlias(), *nlReg.equivalentRegister[vrcStackSlot]);
nlReg.releaseSelf();
}
while (!fpNeedLoad.empty())
{
PRUint32 nl = fpNeedLoad.get();
VirtualRegister& nlReg = vRegManager.getVirtualRegister(nl);
Instruction& lastUse = *nlReg.spillInfo.lastUsingInstruction;
emitter.emitLoadAfter(*lastUse.getPrimitive(), lastUse.getLinks().prev,
nlReg.getAlias(), *nlReg.equivalentRegister[vrcStackSlot]);
nlReg.releaseSelf();
}
// if(node.dfsNum == 8) printf("\n________End Node %d________\n", node.dfsNum);
}
}
#endif

View File

@@ -1,269 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _SPILLING_H_
#define _SPILLING_H_
#include "Fundamentals.h"
#include <string.h>
#include "RegisterAllocator.h"
#include "RegisterAllocatorTools.h"
#include "ControlGraph.h"
#include "ControlNodes.h"
#include "Instruction.h"
#include "SparseSet.h"
template <class RegisterPressure>
class Spilling
{
private:
static void insertStoreAfter(Instruction& instruction, RegisterName name);
static void insertLoadBefore(Instruction& instruction, RegisterName name);
public:
static void calculateSpillCosts(RegisterAllocator& registerAllocator);
static void insertSpillCode(RegisterAllocator& registerAllocator);
};
struct SpillCost
{
double loads;
double stores;
double copies;
double cost;
bool infinite;
};
template <class RegisterPressure>
void Spilling<RegisterPressure>::insertSpillCode(RegisterAllocator& registerAllocator)
{
Uint32 rangeCount = registerAllocator.rangeCount;
RegisterName* name2range = registerAllocator.name2range;
Pool& pool = registerAllocator.pool;
SparseSet currentLive(pool, rangeCount);
SparseSet needLoad(pool, rangeCount);
SparseSet mustSpill(pool, rangeCount);
SparseSet& willSpill = *registerAllocator.willSpill;
ControlGraph& controlGraph = registerAllocator.controlGraph;
RegisterPressure::Set* liveOut = registerAllocator.liveness.liveOut;
ControlNode** nodes = controlGraph.dfsList;
Uint32 nNodes = controlGraph.nNodes;
for (Uint32 n = 0; n < nNodes; n++) {
needLoad.clear();
currentLive = liveOut[n];
mustSpill = currentLive;
InstructionList& instructions = nodes[n]->getInstructions();
for (InstructionList::iterator i = instructions.end(); !instructions.done(i);) {
Instruction& instruction = instructions.get(i);
i = instructions.retreat(i);
InstructionUse* useBegin = instruction.getInstructionUseBegin();
InstructionUse* useEnd = instruction.getInstructionUseEnd();
InstructionUse* usePtr;
InstructionDefine* defineBegin = instruction.getInstructionDefineBegin();
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
InstructionDefine* definePtr;
bool foundLiveDefine = false;
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
if (definePtr->isRegister()) {
if (currentLive.test(name2range[definePtr->getRegisterName()])) {
foundLiveDefine = true;
break;
}
} else {
foundLiveDefine = true;
break;
}
if (defineBegin != defineEnd && !foundLiveDefine) {
fprintf(stderr, "!!! Removed instruction because it was only defining unused registers !!!\n");
instruction.remove();
}
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
if (definePtr->isRegister()) {
RegisterName range = name2range[definePtr->getRegisterName()];
#ifdef DEBUG
if (needLoad.test(range))
if (!mustSpill.test(range) && registerAllocator.spillCost[range].infinite && willSpill.test(range)) {
fprintf(stderr, "Tried to spill a register with infinite spill cost\n");
abort();
}
#endif // DEBUG
if (willSpill.test(range))
insertStoreAfter(instruction, range);
needLoad.clear(range);
}
if (instruction.getFlags() & ifCopy)
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
if (usePtr->isRegister()) {
RegisterName range = name2range[usePtr->getRegisterName()];
if (!currentLive.test(range))
for (SparseSet::iterator r = needLoad.begin(); !needLoad.done(r); r = needLoad.advance(r)) {
RegisterName load = RegisterName(needLoad.get(r));
if (willSpill.test(load))
insertLoadBefore(instruction, load);
mustSpill.set(load);
}
needLoad.clear();
}
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
if (definePtr->isRegister())
currentLive.clear(name2range[definePtr->getRegisterName()]);
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
if (usePtr->isRegister()) {
RegisterName range = name2range[usePtr->getRegisterName()];
currentLive.set(range);
needLoad.set(range);
}
}
for (SparseSet::iterator l = needLoad.begin(); !needLoad.done(l); l = needLoad.advance(l)) {
RegisterName load = RegisterName(needLoad.get(l));
if (willSpill.test(load))
insertLoadBefore(instructions.first(), load);
}
}
}
template <class RegisterPressure>
void Spilling<RegisterPressure>::insertLoadBefore(Instruction& /*instruction*/, RegisterName name)
{
fprintf(stdout, "will insert load for range %d\n", name);
}
template <class RegisterPressure>
void Spilling<RegisterPressure>::insertStoreAfter(Instruction& /*instruction*/, RegisterName name)
{
fprintf(stdout, "will insert store for range %d\n", name);
}
template <class RegisterPressure>
void Spilling<RegisterPressure>::calculateSpillCosts(RegisterAllocator& registerAllocator)
{
Uint32 rangeCount = registerAllocator.rangeCount;
RegisterName* name2range = registerAllocator.name2range;
Pool& pool = registerAllocator.pool;
SparseSet live(pool, rangeCount);
SparseSet needLoad(pool, rangeCount);
SparseSet mustSpill(pool, rangeCount);
SparseSet alreadyStored(pool, rangeCount); // FIX: should get this from previous spilling.
SpillCost* cost = new SpillCost[rangeCount];
memset(cost, '\0', rangeCount * sizeof(SpillCost));
ControlGraph& controlGraph = registerAllocator.controlGraph;
RegisterPressure::Set* liveOut = registerAllocator.liveness.liveOut;
ControlNode** nodes = controlGraph.dfsList;
Uint32 nNodes = controlGraph.nNodes;
for (Uint32 n = 0; n < nNodes; n++) {
ControlNode& node = *nodes[n];
double weight = doLog10(node.loopDepth);
needLoad.clear();
live = liveOut[n];
mustSpill = live;
InstructionList& instructions = nodes[n]->getInstructions();
for (InstructionList::iterator i = instructions.end(); !instructions.done(i); i = instructions.retreat(i)) {
Instruction& instruction = instructions.get(i);
InstructionUse* useBegin = instruction.getInstructionUseBegin();
InstructionUse* useEnd = instruction.getInstructionUseEnd();
InstructionUse* usePtr;
InstructionDefine* defineBegin = instruction.getInstructionDefineBegin();
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
InstructionDefine* definePtr;
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
if (definePtr->isRegister()) {
RegisterName range = name2range[definePtr->getRegisterName()];
if (needLoad.test(range))
if (!mustSpill.test(range))
cost[range].infinite = true;
if ((false /* !rematerializable(range) */ || !needLoad.test(range)) && !alreadyStored.test(range))
cost[range].stores += weight;
needLoad.clear(range);
}
if (instruction.getFlags() & ifCopy)
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
if (usePtr->isRegister())
if (!live.test(name2range[usePtr->getRegisterName()])) {
for (SparseSet::iterator l = needLoad.begin(); !needLoad.done(l); l = needLoad.advance(l)) {
Uint32 range = needLoad.get(l);
cost[range].loads += weight;
mustSpill.set(range);
}
needLoad.clear();
}
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
if (definePtr->isRegister())
live.clear(name2range[definePtr->getRegisterName()]);
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
if (usePtr->isRegister()) {
RegisterName range = name2range[usePtr->getRegisterName()];
live.set(range);
needLoad.set(range);
}
if (instruction.getFlags() & ifCopy) {
assert(useBegin != useEnd && useBegin[0].isRegister());
assert(defineBegin != defineEnd && defineBegin[0].isRegister());
RegisterName source = name2range[useBegin[0].getRegisterName()];
RegisterName destination = name2range[defineBegin[0].getRegisterName()];
cost[source].copies += weight;
cost[destination].copies += weight;
}
}
for (SparseSet::iterator s = needLoad.begin(); !needLoad.done(s); s = needLoad.advance(s))
cost[needLoad.get(s)].loads += weight;
}
for (Uint32 r = 0; r < rangeCount; r++) {
SpillCost& c = cost[r];
c.cost = 2 * (c.loads + c.stores) - c.copies;
}
registerAllocator.spillCost = cost;
}
#endif // _SPILLING_H_

View File

@@ -1,239 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _SPLITS_H_
#define _SPLITS_H_
#include "Fundamentals.h"
#include <string.h>
#include "Pool.h"
#include "ControlGraph.h"
#include "ControlNodes.h"
#include "Instruction.h"
#include "RegisterAllocator.h"
#include "RegisterAllocatorTools.h"
UT_EXTERN_LOG_MODULE(RegAlloc);
template <class RegisterPressure>
struct Splits
{
static void calculateSplitCosts(RegisterAllocator& registerAllocator);
static bool findSplit(RegisterAllocator& registerAllocator, RegisterName* color, RegisterName range);
static void insertSplitCode(RegisterAllocator& registerAllocator);
};
struct SplitCost
{
double loads;
double stores;
};
template <class RegisterPressure>
void Splits<RegisterPressure>::insertSplitCode(RegisterAllocator& /*registerAllocator*/)
{
// FIX
}
template <class RegisterPressure>
bool Splits<RegisterPressure>::findSplit(RegisterAllocator& registerAllocator, RegisterName* color, RegisterName range)
{
Pool& pool = registerAllocator.pool;
NameLinkedList** neighborsWithColor = new(pool) NameLinkedList*[6]; // FIX
memset(neighborsWithColor, '\0', 6 * sizeof(NameLinkedList*));
InterferenceGraph<RegisterPressure>& iGraph = registerAllocator.iGraph;
for (InterferenceVector* vector = iGraph.getInterferenceVector(range); vector != NULL; vector = vector->next)
for (Int32 i = vector->count - 1; i >=0; --i) {
RegisterName neighbor = vector->neighbors[i];
RegisterName c = color[neighbor];
if (c < 6) { // FIX
NameLinkedList* node = new(pool) NameLinkedList();
node->name = neighbor;
node->next = neighborsWithColor[c];
neighborsWithColor[c] = node;
}
}
bool splitAroundName = true;
LiveRangeGraph<RegisterPressure>& lGraph = registerAllocator.lGraph;
RegisterName bestColor = RegisterName(6); // FIX
double bestCost = registerAllocator.spillCost[range].cost;
SplitCost* splitCost = registerAllocator.splitCost;
for (RegisterName i = RegisterName(0); i < 6; i = RegisterName(i + 1)) { // FIX
double splitAroundNameCost = 0.0;
bool canSplitAroundName = true;
SplitCost& sCost = splitCost[range];
double addedCost = 2.0 * (sCost.stores + sCost.loads);
for (NameLinkedList* node = neighborsWithColor[i]; node != NULL; node = node->next) {
RegisterName neighbor = node->name;
if (lGraph.haveEdge(neighbor, range)) {
canSplitAroundName = false;
break;
} else
splitAroundNameCost += addedCost;
}
if (canSplitAroundName && splitAroundNameCost < bestCost) {
bestCost = splitAroundNameCost;
bestColor = i;
splitAroundName = true;
}
double splitAroundColorCost = 0.0;
bool canSplitAroundColor = true;
for (NameLinkedList* node = neighborsWithColor[i]; node != NULL; node = node->next) {
RegisterName neighbor = node->name;
if (lGraph.haveEdge(range, neighbor)) {
canSplitAroundColor = false;
break;
} else {
SplitCost& sCost = splitCost[neighbor];
double addedCost = 2.0 * (sCost.stores + sCost.loads);
splitAroundColorCost += addedCost;
}
}
if (canSplitAroundColor && splitAroundColorCost < bestCost) {
bestCost = splitAroundColorCost;
bestColor = i;
splitAroundName = false;
}
}
if (bestColor < RegisterName(6)) {
color[range] = bestColor;
registerAllocator.splitFound = true;
NameLinkedList** splitAround = registerAllocator.splitAround;
if (splitAroundName)
for (NameLinkedList* node = neighborsWithColor[bestColor]; node != NULL; node = node->next) {
NameLinkedList* newNode = new(pool) NameLinkedList();
newNode->name = node->name;
newNode->next = splitAround[range];
splitAround[range] = newNode;
}
else
for (NameLinkedList* node = neighborsWithColor[bestColor]; node != NULL; node = node->next) {
NameLinkedList* newNode = new(pool) NameLinkedList();
RegisterName neighbor = node->name;
newNode->name = range;
newNode->next = splitAround[neighbor];
splitAround[neighbor] = newNode;
}
trespass("Found a split");
return true;
}
return false;
}
template <class RegisterPressure>
void Splits<RegisterPressure>::calculateSplitCosts(RegisterAllocator& registerAllocator)
{
Pool& pool = registerAllocator.pool;
Uint32 rangeCount = registerAllocator.rangeCount;
RegisterName* name2range = registerAllocator.name2range;
SplitCost* splitCost = new(pool) SplitCost[rangeCount];
memset(splitCost, '\0', rangeCount * sizeof(SplitCost));
SparseSet live(pool, rangeCount);
RegisterPressure::Set* liveIn = registerAllocator.liveness.liveIn;
RegisterPressure::Set* liveOut = registerAllocator.liveness.liveOut;
ControlGraph& controlGraph = registerAllocator.controlGraph;
ControlNode** nodes = controlGraph.dfsList;
Uint32 nNodes = controlGraph.nNodes;
for (Uint32 n = 0; n < nNodes; n++) {
ControlNode& node = *nodes[n];
double weight = doLog10(node.loopDepth);
live = liveOut[n];
ControlEdge* successorsEnd = node.getSuccessorsEnd();
for (ControlEdge* successorsPtr = node.getSuccessorsBegin(); successorsPtr < successorsEnd; successorsPtr++) {
ControlNode& successor = successorsPtr->getTarget();
if (successor.getControlKind() != ckEnd) {
RegisterPressure::Set& successorLiveIn = liveIn[successor.dfsNum];
for (SparseSet::iterator i = live.begin(); !live.done(i); i = live.advance(i)) {
RegisterName name = RegisterName(live.get(i));
if (!successorLiveIn.test(name))
splitCost[name].loads += doLog10(successor.loopDepth);
}
}
}
InstructionList& instructions = node.getInstructions();
for (InstructionList::iterator i = instructions.end(); !instructions.done(i); i = instructions.retreat(i)) {
Instruction& instruction = instructions.get(i);
InstructionUse* useBegin = instruction.getInstructionUseBegin();
InstructionUse* useEnd = instruction.getInstructionUseEnd();
InstructionUse* usePtr;
InstructionDefine* defineBegin = instruction.getInstructionDefineBegin();
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
InstructionDefine* definePtr;
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
if (definePtr->isRegister())
splitCost[name2range[definePtr->getRegisterName()]].stores += weight;
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
if (usePtr->isRegister()) {
RegisterName range = name2range[usePtr->getRegisterName()];
if (!live.test(range)) {
if (&instruction != &instructions.last())
splitCost[range].loads += weight;
else {
ControlEdge* successorsEnd = node.getSuccessorsEnd();
for (ControlEdge* successorsPtr = node.getSuccessorsBegin(); successorsPtr < successorsEnd; successorsPtr++)
splitCost[range].loads += doLog10(successorsPtr->getTarget().loopDepth);
}
}
}
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
if (definePtr->isRegister())
live.clear(name2range[definePtr->getRegisterName()]);
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
if (usePtr->isRegister())
live.set(name2range[usePtr->getRegisterName()]);
}
}
NameLinkedList** splitAround = new(pool) NameLinkedList*[rangeCount];
memset(splitAround, '\0', rangeCount * sizeof(NameLinkedList*));
registerAllocator.splitAround = splitAround;
registerAllocator.splitCost = splitCost;
registerAllocator.splitFound = false;
}
#endif // _SPLITS_H_

View File

@@ -1,186 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "Fundamentals.h"
#include "HashTable.h"
#include "Timer.h"
#include "Pool.h"
static Pool pool; // Pool for the Timer class.
static HashTable<TimerEntry*> timerEntries(pool); // Timers hashtable.
const nTimersInABlock = 128; // Number of timers in a block.
static PRTime *timers = new(pool) PRTime[nTimersInABlock]; // A block of timers.
static Uint8 nextTimer = 0; // nextAvailableTimer.
//
// Calibrate the call to PR_Now().
//
static PRTime calibrate()
{
PRTime t = PR_Now();
PRTime& a = *new(pool) PRTime();
// Call 10 times the PR_Now() function.
a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now();
a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now();
t = (PR_Now() - t + 9) / 10;
return t;
}
static PRTime adjust = calibrate();
//
// Return the named timer..
//
TimerEntry& Timer::getTimerEntry(const char* name)
{
if (!timerEntries.exists(name)) {
TimerEntry* newEntry = new(pool) TimerEntry();
newEntry->accumulator = 0;
newEntry->running = false;
timerEntries.add(name, newEntry);
}
return *timerEntries[name];
}
//
// Return a reference to a new timer.
//
PRTime& Timer::getNewTimer()
{
if (nextTimer >= nTimersInABlock) {
timers = new(pool) PRTime[nTimersInABlock];
nextTimer = 0;
}
return timers[nextTimer++];
}
static Uint32 timersAreFrozen = 0;
//
// Start the named timer.
//
void Timer::start(const char* name)
{
if (timersAreFrozen)
return;
freezeTimers();
TimerEntry& timer = getTimerEntry(name);
PR_ASSERT(!timer.running);
timer.accumulator = 0;
timer.running = true;
timer.done = false;
unfreezeTimers();
}
//
// Stop the named timer.
//
void Timer::stop(const char* name)
{
if (timersAreFrozen)
return;
freezeTimers();
TimerEntry& timer = getTimerEntry(name);
PR_ASSERT(timer.running);
timer.running = false;
timer.done = true;
unfreezeTimers();
}
//
// Freeze all the running timers.
//
void Timer::freezeTimers()
{
PRTime when = PR_Now() - adjust;
if (timersAreFrozen == 0) {
Vector<TimerEntry*> entries = timerEntries;
Uint32 count = entries.size();
for (Uint32 i = 0; i < count; i++) {
TimerEntry& entry = *entries[i];
if (entry.running) {
entry.accumulator += (when - *entry.startTime);
}
}
}
timersAreFrozen++;
}
//
// Unfreeze all the running timers.
//
void Timer::unfreezeTimers()
{
PR_ASSERT(timersAreFrozen != 0);
timersAreFrozen--;
if (timersAreFrozen == 0) {
Vector<TimerEntry *> entries = timerEntries;
Uint32 count = entries.size();
PRTime& newStart = getNewTimer();
for (Uint32 i = 0; i < count; i++) {
TimerEntry& entry = *entries[i];
if (entry.running) {
entry.startTime = &newStart;
}
}
newStart = PR_Now();
}
}
//
// Print the named timer in the file f.
//
void Timer::print(FILE* f, const char *name)
{
if (timersAreFrozen)
return;
freezeTimers();
TimerEntry& timer = getTimerEntry(name);
PR_ASSERT(timer.done);
PRTime elapsed = timer.accumulator;
if (elapsed >> 32) {
fprintf(f, "[timer %s out of range]\n", name);
} else {
fprintf(f, "[%dus in %s]\n", Uint32(elapsed), name);
}
fflush(f);
unfreezeTimers();
}

View File

@@ -1,80 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _TIMER_H_
#define _TIMER_H_
#include "Fundamentals.h"
#include "HashTable.h"
#include "prtime.h"
//
// Naming convention:
// As the class Timer contains only static methods, the timer's name should start with the
// module name. Otherwise starting 2 timers with the same name will assert.
//
#ifndef NO_TIMER
struct TimerEntry
{
PRTime *startTime; // Current time when we start the timer.
PRTime accumulator; // Time spent in this timer.
bool running; // True if the timer is running.
bool done; // True if the timer was running and was stopped.
};
class Timer
{
private:
// Return the named timer.
static TimerEntry& getTimerEntry(const char* name);
// Return a reference to a new Timer.
static PRTime& getNewTimer();
public:
// Start the timer.
static void start(const char* name);
// Stop the timer.
static void stop(const char* name);
// Freeze all the running timers.
static void freezeTimers();
// Unfreeze all the running timers.
static void unfreezeTimers();
// Print the timer.
static void print(FILE* f, const char *name);
};
inline void startTimer(const char* name) {Timer::start(name);}
inline void stopTimer(const char* name) {Timer::stop(name); Timer::print(stdout, name);}
#define START_TIMER_SAFE Timer::freezeTimers();
#define END_TIMER_SAFE Timer::unfreezeTimers();
#define TIMER_SAFE(x) START_TIMER_SAFE x; END_TIMER_SAFE
#else /* NO_TIMER */
inline void startTimer(const char* /*name*/) {}
inline void stopTimer(const char* /*name*/) {}
#define START_TIMER_SAFE
#define END_TIMER_SAFE
#define TIMER_SAFE(x) x;
#endif /* NO_TIMER */
#endif /* _TIMER_H_ */

View File

@@ -1,116 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _VIRTUAL_REGISTER_H_
#define _VIRTUAL_REGISTER_H_
#include "Fundamentals.h"
#include "IndexedPool.h"
#include <string.h>
#include "RegisterTypes.h"
#include "RegisterClass.h"
//------------------------------------------------------------------------------
// VirtualRegister - 24b
class Instruction;
class VirtualRegister : public IndexedObject<VirtualRegister>
{
public:
Instruction* definingInstruction; // Instruction defining this VR.
// Initialize a VR of the given classKind.
VirtualRegister(RegisterClassKind /*classKind*/) : definingInstruction(NULL) {}
// Return the defining instruction for this VR.
Instruction* getDefiningInstruction() const {return definingInstruction;}
// Set the defining instruction.
void setDefiningInstruction(Instruction& insn);
};
// Return true if the VirtualRegisters are equals. The only way 2 VRs can be equal is if
// they have the same index. If they have the same index then they are at the same
// address in the indexed pool.
//
inline bool operator == (const VirtualRegister& regA, const VirtualRegister& regB) {return &regA == &regB;}
//------------------------------------------------------------------------------
// VirtualRegisterManager -
struct PreColoredRegister
{
RegisterID id;
RegisterName color;
};
class VirtualRegisterManager
{
private:
IndexedPool<VirtualRegister> registerPool;
PreColoredRegister machineRegister[6];
public:
VirtualRegisterManager()
{
for (Uint32 i = 0; i < 6; i++)
machineRegister[i].id = invalidID;
}
// Return the VirtualRegister at the given index.
VirtualRegister& getVirtualRegister(RegisterName name) const {return registerPool.get(name);}
// Return a new VirtualRegister.
RegisterID newVirtualRegister(RegisterClassKind classKind)
{
VirtualRegister& vReg = *new(registerPool) VirtualRegister(classKind);
RegisterID rid;
setName(rid, RegisterName(vReg.getIndex()));
setClass(rid, classKind);
return rid;
}
RegisterID newMachineRegister(RegisterName name, RegisterClassKind classKind)
{
RegisterID rid = machineRegister[name].id;
if (rid == invalidID) {
rid = newVirtualRegister(classKind);
DEBUG_ONLY(setMachineRegister(rid));
machineRegister[name].id = rid;
machineRegister[name].color = name;
}
return rid;
}
PreColoredRegister* getMachineRegistersBegin() const {return (PreColoredRegister*) machineRegister;} // FIX
PreColoredRegister* getMachineRegistersEnd() const {return (PreColoredRegister*) &machineRegister[6];} // FIX
// Return the VirtualRegister universe size.
Uint32 getSize() {return registerPool.getSize();}
void setSize(Uint32 size) {registerPool.setSize(size);}
};
#endif // _VIRTUAL_REGISTER_H_

View File

@@ -0,0 +1,31 @@
#//------------------------------------------------------------------------
#//
#// Makefile to build the MODULES/OJI tree
#//
#//------------------------------------------------------------------------
#//------------------------------------------------------------------------
#//
#// Specify the depth of the current directory relative to the
#// root of NS
#//
#//------------------------------------------------------------------------
DEPTH=../..
#//------------------------------------------------------------------------
#//
#// Specify any "command" targets. (ie. DIRS, INSTALL_FILES, ...)
#// (these must come before the common makefiles are included)
#//
#// DIRS - There are subdirectories to process
#//
#//------------------------------------------------------------------------
DIRS= public src
#//------------------------------------------------------------------------
#//
#// Include the common makefile rules
#//
#//------------------------------------------------------------------------
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,36 @@
#//------------------------------------------------------------------------
#//
#// Makefile to build the MODULES/OJI tree
#//
#//------------------------------------------------------------------------
#//------------------------------------------------------------------------
#//
#// Specify the depth of the current directory relative to the
#// root of NS
#//
#//------------------------------------------------------------------------
DEPTH=../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
#//------------------------------------------------------------------------
#//
#// Specify any "command" targets. (ie. DIRS, INSTALL_FILES, ...)
#// (these must come before the common makefiles are included)
#//
#// DIRS - There are subdirectories to process
#//
#//------------------------------------------------------------------------
DIRS= public src
#//------------------------------------------------------------------------
#//
#// Include the common makefile rules
#//
#//------------------------------------------------------------------------
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,9 @@
//
// oji.Prefix
//
// Global prefix file for the oji.shlb target.
//
//
#include "MacPrefix.h"
#include "ojiConfig.h"

Binary file not shown.

View File

@@ -0,0 +1,9 @@
/* #define EDITOR 1
#include "NSCrossProductDefines.h"
#include "IDE_Options.h"
#define JAVA
#define MOZILLA_CLIENT 1 */

View File

@@ -0,0 +1,8 @@
//
// ojiDebug.Prefix
//
// Global prefix file for the ojiDebug.shlb target.
//
#include "MacPrefix_debug.h"
#include "ojiConfig.h"

View File

@@ -0,0 +1,30 @@
#//------------------------------------------------------------------------
#//
#// Makefile to build the MODULES\APPLET tree
#//
#//------------------------------------------------------------------------
#//------------------------------------------------------------------------
#//
#// Specify the depth of the current directory relative to the
#// root of NS
#//
#//------------------------------------------------------------------------
DEPTH=..\..
#//------------------------------------------------------------------------
#//
#// Specify any "command" targets. (ie. DIRS, INSTALL_FILES, ...)
#// (these must come before the common makefiles are included)
#//
#// DIRS - There are subdirectories to process
#//
#//------------------------------------------------------------------------
DIRS= public src
#//------------------------------------------------------------------------
#//
#// Include the common makefile rules
#//
#//------------------------------------------------------------------------
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,30 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
#
# This is a list of local files which get copied to the mozilla:dist directory
#
nsIJRIPlugin.h
nsIJVMConsole.h
nsIJVMManager.h
nsIJVMPlugin.h
nsIJVMPluginInstance.h
nsIJVMPluginTagInfo.h
nsISymantecDebugger.h
nsISymantecDebugManager.h
nsjvm.h

View File

@@ -0,0 +1,33 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH = ../../..
MODULE = oji
EXPORTS = \
nsjvm.h \
nsIJRIPlugin.h \
nsIJVMConsole.h \
nsIJVMManager.h \
nsIJVMPlugin.h \
nsIJVMPluginInstance.h \
nsIJVMPluginTagInfo.h \
nsISymantecDebugManager.h \
nsISymantecDebugger.h
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,40 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = oji
EXPORTS = \
nsjvm.h \
nsIJRIPlugin.h \
nsIJVMConsole.h \
nsIJVMManager.h \
nsIJVMPlugin.h \
nsIJVMPluginInstance.h \
nsIJVMPluginTagInfo.h \
nsISymantecDebugManager.h \
nsISymantecDebugger.h
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,36 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
IGNORE_MANIFEST=1
DEPTH = ..\..\..
MODULE = oji
EXPORTS = \
nsjvm.h \
nsIJRIPlugin.h \
nsIJVMConsole.h \
nsIJVMManager.h \
nsIJVMPlugin.h \
nsIJVMPluginInstance.h \
nsIJVMPluginTagInfo.h \
nsISymantecDebugManager.h \
nsISymantecDebugger.h
include <$(DEPTH)/config/rules.mak>

View File

@@ -0,0 +1,66 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
// NETSCAPE JAVA VM PLUGIN EXTENSIONS
//
// This interface allows a Java virtual machine to be plugged into
// Communicator to implement the APPLET tag and host applets.
//
// Note that this is the C++ interface that the plugin sees. The browser
// uses a specific implementation of this, nsJVMPlugin, found in jvmmgr.h.
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIJRIPlugin_h___
#define nsIJRIPlugin_h___
#include "nsISupports.h"
#include "jri.h"
////////////////////////////////////////////////////////////////////////////////
// JRI Plugin Class Interface
// This interface is provided for backward compatibility for the Netscape JVM.
class nsIJRIPlugin : public nsISupports {
public:
// QueryInterface on nsIJVMPlugin to get this.
// Find or create a JRIEnv for the current thread.
// Returns NULL if an error occurs.
NS_IMETHOD_(nsrefcnt)
GetJRIEnv(JRIEnv* *result) = 0;
// This method must be called when the caller is done using the JRIEnv.
// This decrements a refcount associated with it may free it.
NS_IMETHOD_(nsrefcnt)
ReleaseJRIEnv(JRIEnv* env) = 0;
};
#define NS_IJRIPLUGIN_IID \
{ /* bfe2d7d0-0164-11d2-815b-006008119d7a */ \
0xbfe2d7d0, \
0x0164, \
0x11d2, \
{0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIJRIPlugin_h___ */

View File

@@ -0,0 +1,71 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
// NETSCAPE JAVA VM PLUGIN EXTENSIONS
//
// This interface allows a Java virtual machine to be plugged into
// Communicator to implement the APPLET tag and host applets.
//
// Note that this is the C++ interface that the plugin sees. The browser
// uses a specific implementation of this, nsJVMPlugin, found in jvmmgr.h.
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIJVMConsole_h___
#define nsIJVMConsole_h___
#include "nsISupports.h"
////////////////////////////////////////////////////////////////////////////////
// JVM Console Interface
// This interface defines the API the browser needs to show and hide the JVM's
// Java console, and to send text to it.
class nsIJVMConsole : public nsISupports {
public:
// QueryInterface on nsIJVMPlugin to get this.
NS_IMETHOD
ShowConsole(void) = 0;
NS_IMETHOD
HideConsole(void) = 0;
NS_IMETHOD
IsConsoleVisible(PRBool *result) = 0;
// Prints a message to the Java console. The encodingName specifies the
// encoding of the message, and if NULL, specifies the default platform
// encoding.
NS_IMETHOD
Print(const char* msg, const char* encodingName = NULL) = 0;
};
#define NS_IJVMCONSOLE_IID \
{ /* 85344580-01c1-11d2-815b-006008119d7a */ \
0x85344580, \
0x01c1, \
0x11d2, \
{0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIJVMConsole_h___ */

View File

@@ -0,0 +1,68 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
// NETSCAPE JAVA VM PLUGIN EXTENSIONS
//
// This interface allows a Java virtual machine to be plugged into
// Communicator to implement the APPLET tag and host applets.
//
// Note that this is the C++ interface that the plugin sees. The browser
// uses a specific implementation of this, nsJVMPlugin, found in jvmmgr.h.
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIJVMManager_h___
#define nsIJVMManager_h___
#include "nsISupports.h"
////////////////////////////////////////////////////////////////////////////////
#define NPJVM_MIME_TYPE "application/x-java-vm" // XXX application/java
enum {
NS_JVM_ERROR_BASE = NS_ERROR_BASE + 0x10000,
NS_JVM_ERROR_NO_CLASSES,
NS_JVM_ERROR_WRONG_CLASSES,
NS_JVM_ERROR_JAVA_ERROR,
NS_JVM_ERROR_NO_DEBUGGER
};
////////////////////////////////////////////////////////////////////////////////
// Java VM Plugin Manager
// This interface defines additional entry points that are available
// to JVM plugins for browsers that support JVM plugins.
class nsIJVMPlugin;
class nsIJVMManager : public nsISupports {
public:
};
#define NS_IJVMMANAGER_IID \
{ /* a1e5ed50-aa4a-11d1-85b2-00805f0e4dfe */ \
0xa1e5ed50, \
0xaa4a, \
0x11d1, \
{0x85, 0xb2, 0x00, 0x80, 0x5f, 0x0e, 0x4d, 0xfe} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIJVMManager_h___ */

View File

@@ -0,0 +1,128 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
// NETSCAPE JAVA VM PLUGIN EXTENSIONS
//
// This interface allows a Java virtual machine to be plugged into
// Communicator to implement the APPLET tag and host applets.
//
// Note that this is the C++ interface that the plugin sees. The browser
// uses a specific implementation of this, nsJVMPlugin, found in jvmmgr.h.
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIJVMPlugin_h___
#define nsIJVMPlugin_h___
#include "nsIPlugin.h"
#include "nsIPrincipal.h"
#include "jni.h"
////////////////////////////////////////////////////////////////////////////////
// Java VM Plugin Interface
// This interface defines additional entry points that a plugin developer needs
// to implement in order to implement a Java virtual machine plugin.
struct nsJVMInitArgs {
PRUint32 version;
const char* classpathAdditions; // appended to the JVM's classpath
// other fields may be added here for version numbers beyond 0x00010000
};
/**
* nsJVMInitArgs_Version is the current version number for the nsJVMInitArgs
* struct specified above. The nsVersionOk macro should be used when comparing
* a supplied nsJVMInitArgs struct against this version.
*/
#define nsJVMInitArgs_Version 0x00010000L
class nsIJVMPlugin : public nsIPlugin {
public:
// This method us used to start the Java virtual machine.
// It sets up any global state necessary to host Java programs.
// Note that calling this method is distinctly separate from
// initializing the nsIJVMPlugin object (done by the Initialize
// method).
NS_IMETHOD
StartupJVM(nsJVMInitArgs* initargs) = 0;
// This method us used to stop the Java virtual machine.
// It tears down any global state necessary to host Java programs.
// The fullShutdown flag specifies whether the browser is quitting
// (PR_TRUE) or simply whether the JVM is being shut down (PR_FALSE).
NS_IMETHOD
ShutdownJVM(PRBool fullShutdown = PR_FALSE) = 0;
// Causes the JVM to append a new directory to its classpath.
// If the JVM doesn't support this operation, an error is returned.
NS_IMETHOD
AddToClassPath(const char* dirPath) = 0;
// Causes the JVM to remove a directory from its classpath.
// If the JVM doesn't support this operation, an error is returned.
NS_IMETHOD
RemoveFromClassPath(const char* dirPath) = 0;
// Returns the current classpath in use by the JVM.
NS_IMETHOD
GetClassPath(const char* *result) = 0;
NS_IMETHOD
GetJavaWrapper(JNIEnv* jenv, jint obj, jobject *jobj) = 0;
#if 0 // still trying to decide on this
// nsIPrincipals is a array of pointers to principals associated with this
// java object trying to run a JS script.
NS_IMETHOD
GetPrincipalArray(JNIEnv *pJNIEnv, PRInt32 frameIndex, nsIPrincipal ***principalArray, PRInt32 *length) = 0;
#endif
// Find or create a JNIEnv for the current thread.
// Returns NULL if an error occurs.
NS_IMETHOD_(nsrefcnt)
GetJNIEnv(JNIEnv* *result) = 0;
// This method must be called when the caller is done using the JNIEnv.
// This decrements a refcount associated with it may free it.
NS_IMETHOD_(nsrefcnt)
ReleaseJNIEnv(JNIEnv* env) = 0;
#ifdef XP_MAC
// beard: since only my plugin has implemented this so far, I'll leave it conditional for now.
/**
* Gives time to the JVM from the main event loop of the browser. This is
* necessary when there aren't any plugin instances around, but Java threads exist.
*/
NS_IMETHOD
SpendTime(PRUint32 timeMillis) = 0;
#endif
};
#define NS_IJVMPLUGIN_IID \
{ /* da6f3bc0-a1bc-11d1-85b1-00805f0e4dfe */ \
0xda6f3bc0, \
0xa1bc, \
0x11d1, \
{0x85, 0xb1, 0x00, 0x80, 0x5f, 0x0e, 0x4d, 0xfe} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIJVMPlugin_h___ */

View File

@@ -0,0 +1,59 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
// NETSCAPE JAVA VM PLUGIN EXTENSIONS
//
// This interface allows a Java virtual machine to be plugged into
// Communicator to implement the APPLET tag and host applets.
//
// Note that this is the C++ interface that the plugin sees. The browser
// uses a specific implementation of this, nsJVMPlugin, found in jvmmgr.h.
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIJVMPluginInstance_h___
#define nsIJVMPluginInstance_h___
#include "nsIPluginInstance.h"
////////////////////////////////////////////////////////////////////////////////
// Java VM Plugin Instance Interface
class nsIJVMPluginInstance : public nsIPluginInstance {
public:
// This method is called when LiveConnect wants to find the Java object
// associated with this plugin instance, e.g. the Applet or JavaBean object.
NS_IMETHOD
GetJavaObject(jobject *result) = 0;
NS_IMETHOD
GetText(const char* *result) = 0;
};
#define NS_IJVMPLUGININSTANCE_IID \
{ /* a0c057d0-01c1-11d2-815b-006008119d7a */ \
0xa0c057d0, \
0x01c1, \
0x11d2, \
{0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIJVMPluginInstance_h___ */

View File

@@ -0,0 +1,69 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
// NETSCAPE JAVA VM PLUGIN EXTENSIONS
//
// This interface allows a Java virtual machine to be plugged into
// Communicator to implement the APPLET tag and host applets.
//
// Note that this is the C++ interface that the plugin sees. The browser
// uses a specific implementation of this, nsJVMPlugin, found in jvmmgr.h.
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIJVMPluginTagInfo_h___
#define nsIJVMPluginTagInfo_h___
#include "nsISupports.h"
////////////////////////////////////////////////////////////////////////////////
// Java VM Plugin Instance Peer Interface
// This interface provides additional hooks into the plugin manager that allow
// a plugin to implement the plugin manager's Java virtual machine.
class nsIJVMPluginTagInfo : public nsISupports {
public:
NS_IMETHOD
GetCode(const char* *result) = 0;
NS_IMETHOD
GetCodeBase(const char* *result) = 0;
NS_IMETHOD
GetArchive(const char* *result) = 0;
NS_IMETHOD
GetName(const char* *result) = 0;
NS_IMETHOD
GetMayScript(PRBool *result) = 0;
};
#define NS_IJVMPLUGINTAGINFO_IID \
{ /* 27b42df0-a1bd-11d1-85b1-00805f0e4dfe */ \
0x27b42df0, \
0xa1bd, \
0x11d1, \
{0x85, 0xb1, 0x00, 0x80, 0x5f, 0x0e, 0x4d, 0xfe} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIJVMPluginTagInfo_h___ */

View File

@@ -0,0 +1,56 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
// NETSCAPE JAVA VM PLUGIN EXTENSIONS FOR SYMANTEC DEBUGGER
//
// This interface allows the browser to initialize a JVM that supports a
// debugger. It's called the "Symantec Debugger Interface" because it currently
// provides access to the Symantec Cafe or Visual Cafe debugger in the Netscape
// JVM. It is not meant to be the be-all-to-end-all of debugger interfaces.
////////////////////////////////////////////////////////////////////////////////
#ifndef nsISymantecDebugManager_h___
#define nsISymantecDebugManager_h___
#include "nsISupports.h"
////////////////////////////////////////////////////////////////////////////////
// Symantec Debug Manager Interface
//
// Implemented by the browser that supports the Symantec debugger.
class nsISymantecDebugManager : public nsISupports {
public:
NS_IMETHOD
SetDebugAgentPassword(PRInt32 pwd) = 0;
};
#define NS_ISYMANTECDEBUGMANAGER_IID \
{ /* 131362e0-d985-11d1-8155-006008119d7a */ \
0x131362e0, \
0xd985, \
0x11d1, \
{0x81, 0x55, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsISymantecDebugManager_h___ */

View File

@@ -0,0 +1,62 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
// NETSCAPE JAVA VM PLUGIN EXTENSIONS FOR SYMANTEC DEBUGGER
//
// This interface allows the browser to initialize a JVM that supports a
// debugger. It's called the "Symantec Debugger Interface" because it currently
// provides access to the Symantec Cafe or Visual Cafe debugger in the Netscape
// JVM. It is not meant to be the be-all-to-end-all of debugger interfaces.
////////////////////////////////////////////////////////////////////////////////
#ifndef nsISymantecDebugger_h___
#define nsISymantecDebugger_h___
#include "nsISupports.h"
////////////////////////////////////////////////////////////////////////////////
// Symantec Debugger Interface
//
// Implemented by the JVM plugin that supports the Symantec debugger.
enum nsSymantecDebugPort {
nsSymantecDebugPort_None = 0,
nsSymantecDebugPort_SharedMemory = -1
// anything else is a port number
};
class nsISymantecDebugger : public nsISupports {
public:
NS_IMETHOD
StartDebugger(nsSymantecDebugPort port) = 0;
};
#define NS_ISYMANTECDEBUGGER_IID \
{ /* 954399f0-d980-11d1-8155-006008119d7a */ \
0x954399f0, \
0xd980, \
0x11d1, \
{0x81, 0x55, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsISymantecDebugger_h___ */

View File

@@ -0,0 +1,46 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
// NETSCAPE JAVA VM PLUGIN EXTENSIONS
//
// This interface allows a Java virtual machine to be plugged into
// Communicator to implement the APPLET tag and host applets.
//
// Note that this is the C++ interface that the plugin sees. The browser
// uses a specific implementation of this, nsJVMPlugin, found in jvmmgr.h.
////////////////////////////////////////////////////////////////////////////////
#ifndef nsjvm_h___
#define nsjvm_h___
#include "nsplugin.h"
#include "nsIJRIPlugin.h"
#include "nsIJVMConsole.h"
#include "nsIJVMManager.h"
#include "nsIJVMPlugin.h"
#include "nsIJVMPluginInstance.h"
#include "nsIJVMPluginTagInfo.h"
#include "nsISymantecDebugManager.h"
#include "nsISymantecDebugger.h"
#include "nsICapsManager.h"
#include "nsILiveconnect.h"
////////////////////////////////////////////////////////////////////////////////
#endif /* nsjvm_h___ */

View File

@@ -0,0 +1,5 @@
#
# This is a list of local files which get copied to the mozilla:dist directory
#
jvmmgr.h

View File

@@ -0,0 +1,29 @@
#//------------------------------------------------------------------------
#//
#// Makefile to build OJI
#//
#//------------------------------------------------------------------------
DEPTH = ../../..
include $(DEPTH)/config/config.mk
MODULE = ojiimpl
ifdef MOZ_OJI
LIBRARY_NAME = oji
CPPSRCS = jvmmgr.cpp \
lcglue.cpp \
scd.cpp
REQUIRES = img java js lay layer plugin plugimpl pref style util xpcom raptor oji caps
LCFLAGS += -DJSJDLL=\"$(JSJDLL)\"
INCLUDES += -I$(DIST)/include/private
endif # MOZ_OJI
EXPORTS = jvmmgr.h
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,35 @@
#//------------------------------------------------------------------------
#//
#// Makefile to build OJI
#//
#//------------------------------------------------------------------------
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
MODULE = ojiimpl
ifdef MOZ_OJI
LIBRARY_NAME = oji
CPPSRCS = jvmmgr.cpp \
lcglue.cpp \
scd.cpp
REQUIRES = img java js lay layer plugin plugimpl pref style util xpcom raptor oji caps
LCFLAGS += -DJSJDLL=\"$(JSJDLL)\"
INCLUDES += -I$(DIST)/include/private
endif # MOZ_OJI
EXPORTS = jvmmgr.h
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,7 @@
#
# This is a list of files to be copied to the mozilla:dist directory
#
nsjvm.h
nsscd.h
jvmmgr.h

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,241 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef jvmmgr_h___
#define jvmmgr_h___
#include "xp_core.h" /* include first because of Bool problem */
#include "prtypes.h"
#include "nsCom.h"
#include "nsError.h" /* for nsresult */
#include "jni.h"
struct nsJVMMgr;
typedef enum nsJVMStatus {
nsJVMStatus_Enabled, /* but not Running */
nsJVMStatus_Disabled, /* explicitly disabled */
nsJVMStatus_Running, /* enabled and started */
nsJVMStatus_Failed /* enabled but failed to start */
} nsJVMStatus;
#ifdef __cplusplus
#include "nsjvm.h"
#include "nsAgg.h"
#include "jsjava.h"
#include "nsVector.h"
class nsIPluginTagInfo2;
class nsSymantecDebugManager;
struct ThreadLocalStorageAtIndex0 {
PRUint32 refcount;
};
typedef struct ThreadLocalStorageAtIndex0 ThreadLocalStorageAtIndex0;
/*******************************************************************************
* JVMMgr is the interface to the JVM manager that the browser sees. All
* files that want to include java services should include this header file.
* nsIJVMManager is the more limited interface what the JVM plugin sees.
******************************************************************************/
struct nsJVMMgr : public nsIJVMManager {
public:
NS_DECL_AGGREGATED
/* from nsIJVMManager: */
/* JVMMgr specific methods: */
/* ====> From here on are things only called by the browser, not the plugin... */
static NS_METHOD
Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
nsIJVMPlugin* GetJVMPlugin(void) { return fJVM; }
/* Unlike the nsIJVMPlugin::StartupJVM, this version handles putting
* up any error dialog: */
nsJVMStatus StartupJVM(void);
nsJVMStatus ShutdownJVM(PRBool fullShutdown = PR_FALSE);
nsJVMStatus GetJVMStatus(void);
void SetJVMEnabled(PRBool enabled);
void ReportJVMError(nsresult err);
const char* GetJavaErrorString(JNIEnv* env);
nsresult AddToClassPath(const char* dirPath);
PRBool MaybeStartupLiveConnect(void);
PRBool MaybeShutdownLiveConnect(void);
PRBool IsLiveConnectEnabled(void);
JSJavaVM* GetJSJavaVM() { return fJSJavaVM; }
protected:
nsJVMMgr(nsISupports* outer);
virtual ~nsJVMMgr(void);
void EnsurePrefCallbackRegistered(void);
const char* GetJavaErrorString(JRIEnv* env);
nsIJVMPlugin* fJVM;
nsJVMStatus fStatus;
PRBool fRegisteredJavaPrefChanged;
nsISupports* fDebugManager;
JSJavaVM * fJSJavaVM;
nsVector* fClassPathAdditions;
};
/*******************************************************************************
* Symantec Debugger Stuff
******************************************************************************/
class nsSymantecDebugManager : public nsISymantecDebugManager {
public:
NS_DECL_AGGREGATED
NS_IMETHOD
SetDebugAgentPassword(PRInt32 pwd);
static NS_METHOD
Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr,
nsJVMMgr* jvmMgr);
protected:
nsSymantecDebugManager(nsISupports* outer, nsJVMMgr* jvmMgr);
virtual ~nsSymantecDebugManager(void);
nsJVMMgr* fJVMMgr;
};
/*******************************************************************************
* nsJVMPluginTagInfo: The browser makes one of these when it sees an APPLET or
* appropriate OBJECT tag.
******************************************************************************/
class nsJVMPluginTagInfo : public nsIJVMPluginTagInfo {
public:
NS_DECL_AGGREGATED
/* from nsIJVMPluginTagInfo: */
/* ====> These are usually only called by the plugin, not the browser... */
NS_IMETHOD
GetCode(const char* *result);
NS_IMETHOD
GetCodeBase(const char* *result);
NS_IMETHOD
GetArchive(const char* *result);
NS_IMETHOD
GetName(const char* *result);
NS_IMETHOD
GetMayScript(PRBool *result);
/* Methods specific to nsJVMPluginInstancePeer: */
/* ====> From here on are things only called by the browser, not the plugin... */
static NS_METHOD
Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr,
nsIPluginTagInfo2* info);
protected:
nsJVMPluginTagInfo(nsISupports* outer, nsIPluginTagInfo2* info);
virtual ~nsJVMPluginTagInfo(void);
/* Instance Variables: */
nsIPluginTagInfo2* fPluginTagInfo;
char* fSimulatedCodebase;
char* fSimulatedCode;
};
#endif /* __cplusplus */
/*******************************************************************************
* Convenience Routines
******************************************************************************/
PR_BEGIN_EXTERN_C
/* Returns the JVM manager. You must do a Release on the pointer returned when
you're done with it. */
PR_EXTERN(struct nsJVMMgr*)
JVM_GetJVMMgr(void);
PR_EXTERN(nsJVMStatus)
JVM_StartupJVM(void);
PR_EXTERN(nsJVMStatus)
JVM_ShutdownJVM(void);
PR_EXTERN(nsJVMStatus)
JVM_GetJVMStatus(void);
PR_EXTERN(PRBool)
JVM_AddToClassPath(const char* dirPath);
PR_EXTERN(void)
JVM_ShowConsole(void);
PR_EXTERN(void)
JVM_HideConsole(void);
PR_EXTERN(PRBool)
JVM_IsConsoleVisible(void);
PR_EXTERN(void)
JVM_ToggleConsole(void);
PR_EXTERN(void)
JVM_PrintToConsole(const char* msg);
PR_EXTERN(void)
JVM_StartDebugger(void);
PR_EXTERN(JNIEnv*)
JVM_GetJNIEnv(void);
PR_IMPLEMENT(void)
JVM_ReleaseJNIEnv(JNIEnv *pJNIEnv);
PR_EXTERN(nsresult)
JVM_SpendTime(PRUint32 timeMillis);
PR_EXTERN(PRBool)
JVM_MaybeStartupLiveConnect(void);
PR_EXTERN(PRBool)
JVM_MaybeShutdownLiveConnect(void);
PR_EXTERN(PRBool)
JVM_IsLiveConnectEnabled(void);
PR_END_EXTERN_C
#endif /* jvmmgr_h___ */

View File

@@ -0,0 +1,468 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "prthread.h"
#include "pprthred.h"
#include "jsjava.h"
#ifdef MOCHA
#include "libmocha.h"
#include "libevent.h"
#endif
#include "jvmmgr.h"
#include "npglue.h"
static NS_DEFINE_IID(kIJVMPluginInstanceIID, NS_IJVMPLUGININSTANCE_IID);
static NS_DEFINE_IID(kIJVMPluginTagInfoIID, NS_IJVMPLUGINTAGINFO_IID);
static PRUintn tlsIndex_g = 0;
////////////////////////////////////////////////////////////////////////////////
// LiveConnect callbacks
////////////////////////////////////////////////////////////////////////////////
template <class T>
class ThreadLocalStorage {
public:
ThreadLocalStorage(PRThreadPrivateDTOR dtor) : mIndex(0), mValid(PR_FALSE)
{
mValid = (PR_NewThreadPrivateIndex(&mIndex, dtor) == PR_SUCCESS);
}
void set(T value)
{
if (mValid) PR_SetThreadPrivate(mIndex, value);
}
T get()
{
return (T) (mValid ? PR_GetThreadPrivate(mIndex) : 0);
}
private:
PRUintn mIndex;
PRBool mValid;
};
PR_BEGIN_EXTERN_C
#include "jscntxt.h"
#ifdef MOCHA
static JSContext* PR_CALLBACK
map_jsj_thread_to_js_context_impl(JSJavaThreadState *jsj_env, JNIEnv *env, char **errp)
{
JSContext *cx = LM_GetCrippledContext();
PRBool jvmMochaPrefsEnabled = PR_FALSE;
*errp = NULL;
#if 0
nsJVMMgr* pJVMMgr = JVM_GetJVMMgr();
if (pJVMMgr != NULL) {
nsIJVMPlugin* pJVMPI = pJVMMgr->GetJVMPlugin();
jvmMochaPrefsEnabled = LM_GetMochaEnabled();
if (pJVMPI != NULL) {
nsIPluginInstance* pPIT;
nsresult err = pJVMPI->GetPluginInstance(env, &pPIT);
if ( (err == NS_OK) && (pPIT != NULL) ) {
nsIJVMPluginInstance* pJVMPIT;
if (pPIT->QueryInterface(kIJVMPluginInstanceIID,
(void**)&pJVMPIT) == NS_OK) {
nsPluginInstancePeer* pPITP;
err = pJVMPIT->GetPeer((nsIPluginInstancePeer**)&pPITP);
if ( (err == NS_OK) &&(pPITP != NULL) ) {
cx = pPITP->GetJSContext();
pPITP->Release();
}
pJVMPIT->Release();
}
pPIT->Release();
}
// pJVMPI->Release(); // GetJVMPlugin no longer calls AddRef
}
pJVMMgr->Release();
}
if (jvmMochaPrefsEnabled == PR_FALSE)
{
*errp = strdup("Java preference is disabled");
return NULL;
}
if ( cx == NULL )
{
*errp = strdup("Java thread could not be associated with a JSContext");
return NULL;
}
#endif
return cx;
}
static void PR_CALLBACK detach_jsjava_thread_state(void* env)
{
JSJavaThreadState *jsj_env = (JSJavaThreadState*)env;
JSJ_DetachCurrentThreadFromJava(jsj_env);
}
/*
** This callback is called to map a JSContext to a JSJavaThreadState which
** is a wrapper around JNIEnv. Hence this callback essentially maps a JSContext
** to a java thread. JSJ_AttachCurrentThreadToJava just calls AttachCurrentThread
** on the java vm.
*/
static JSJavaThreadState* PR_CALLBACK
map_js_context_to_jsj_thread_impl(JSContext *cx, char **errp)
{
*errp = NULL;
static ThreadLocalStorage<JSJavaThreadState*> localThreadState(&detach_jsjava_thread_state);
JSJavaThreadState* jsj_env = localThreadState.get();
if (jsj_env != NULL)
return jsj_env;
if (ET_InitMoja(0) != LM_MOJA_OK) {
*errp = strdup("LiveConnect initialization failed.");
return NULL;
}
JSJavaVM* js_jvm = NULL;
nsJVMMgr* pJVMMgr = JVM_GetJVMMgr();
if (pJVMMgr != NULL) {
js_jvm = pJVMMgr->GetJSJavaVM();
pJVMMgr->Release();
if (js_jvm == NULL) {
*errp = strdup("Failed to attach to a Java VM.");
return NULL;
}
}
jsj_env = JSJ_AttachCurrentThreadToJava(js_jvm, NULL, NULL);
localThreadState.set(jsj_env);
return jsj_env;
}
/*
** This callback is called to map a applet,bean to its corresponding JSObject
** created on javascript side and then map that to a java wrapper JSObject class.
** This callback is called in JSObject.getWindow implementation to get
** a java wrapper JSObject class for a applet only once.
** Note that once a mapping between applet -> javascript JSObject -> Java wrapper JSObject
** is made, all subsequent method calls via JSObject use the internal field
** to get to the javascript JSObject.
*/
static JSObject* PR_CALLBACK
map_java_object_to_js_object_impl(JNIEnv *env, void *pNSIPluginInstanceIn, char **errp)
{
MWContext *cx;
JSObject *window;
MochaDecoder *decoder;
PRBool mayscript = PR_FALSE;
PRBool jvmMochaPrefsEnabled = PR_FALSE;
nsresult err = NS_OK;
*errp = NULL;
/* XXX assert JS is locked */
if (!pNSIPluginInstanceIn) {
env->ThrowNew(env->FindClass("java/lang/NullPointerException"),0);
return 0;
}
nsJVMMgr* pJVMMgr = JVM_GetJVMMgr();
if (pJVMMgr != NULL) {
nsIJVMPlugin* pJVMPI = pJVMMgr->GetJVMPlugin();
jvmMochaPrefsEnabled = LM_GetMochaEnabled();
if (pJVMPI != NULL) {
//jobject javaObject = applet;
nsIPluginInstance* pPIT;
//nsresult err = pJVMPI->GetPluginInstance(javaObject, &pPIT);
pPIT = (nsIPluginInstance*)pNSIPluginInstanceIn;
if ( (err == NS_OK) && (pPIT != NULL) ) {
nsIJVMPluginInstance* pJVMPIT;
if (pPIT->QueryInterface(kIJVMPluginInstanceIID,
(void**)&pJVMPIT) == NS_OK) {
nsPluginInstancePeer* pPITP;
err = pJVMPIT->GetPeer((nsIPluginInstancePeer**)&pPITP);
if ( (err == NS_OK) &&(pPITP != NULL) ) {
nsIJVMPluginTagInfo* pJVMTagInfo;
if (pPITP->QueryInterface(kIJVMPluginTagInfoIID,
(void**)&pJVMTagInfo) == NS_OK) {
err = pJVMTagInfo->GetMayScript(&mayscript);
PR_ASSERT(err != NS_OK ? mayscript == PR_FALSE : PR_TRUE);
pJVMTagInfo->Release();
}
cx = pPITP->GetMWContext();
pPITP->Release();
}
pJVMPIT->Release();
}
pPIT->Release();
}
// pJVMPI->Release(); // GetJVMPlugin no longer calls AddRef
}
pJVMMgr->Release();
}
if ( (mayscript == PR_FALSE)
||(jvmMochaPrefsEnabled == PR_FALSE)
)
{
*errp = strdup("JSObject.getWindow() requires mayscript attribute on this Applet or java preference is disabled");
goto except;
}
if (!cx || (cx->type != MWContextBrowser && cx->type != MWContextPane))
{
*errp = strdup("JSObject.getWindow() can only be called in MWContextBrowser or MWContextPane");
return 0;
}
decoder = LM_GetMochaDecoder(cx);
/* if there is a decoder now, reflect the window */
if (decoder && (jvmMochaPrefsEnabled == PR_TRUE)) {
window = decoder->window_object;
}
LM_PutMochaDecoder(decoder);
return window;
except:
return 0;
}
#if 0
static JavaVM* PR_CALLBACK
get_java_vm_impl(char **errp)
{
*errp = NULL;
JavaVM *pJavaVM = NULL;
nsJVMMgr* pJVMMgr = JVM_GetJVMMgr();
if (pJVMMgr != NULL) {
nsIJVMPlugin* pJVMPI = pJVMMgr->GetJVMPlugin();
if (pJVMPI != NULL) {
nsresult err = pJVMPI->GetJavaVM(&pJavaVM);
PR_ASSERT(err != NS_OK ? pJavaVM == NULL : PR_TRUE);
// pJVMPI->Release(); // GetJVMPlugin no longer calls AddRef
}
pJVMMgr->Release();
}
if ( pJavaVM == NULL )
{
*errp = strdup("Could not find a JavaVM to attach to.");
}
return pJavaVM;
}
#endif
static JSPrincipals* PR_CALLBACK
get_JSPrincipals_from_java_caller_impl(JNIEnv *pJNIEnv, JSContext *pJSContext)
{
nsIPrincipal **ppNSIPrincipalArray = NULL;
PRInt32 length = 0;
nsresult err = NS_OK;
void *pNSPrincipalArray = NULL;
#if 0 // TODO: =-= sudu: fix it.
nsJVMMgr* pJVMMgr = JVM_GetJVMMgr();
if (pJVMMgr != NULL) {
nsIJVMPlugin* pJVMPI = pJVMMgr->GetJVMPlugin();
if (pJVMPI != NULL) {
err = pJVMPI->GetPrincipalArray(pJNIEnv, 0, &ppNSIPrincipalArray, &length);
if ((err == NS_OK) && (ppNSIPrincipalArray != NULL)) {
nsIPluginManager *pNSIPluginManager = NULL;
NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID);
err = pJVMMgr->QueryInterface(kIPluginManagerIID,
(void**)&pNSIPluginManager);
if( (err == NS_OK)
&& (pNSIPluginManager != NULL )
)
{
nsCCapsManager *pNSCCapsManager = NULL;
NS_DEFINE_IID(kICapsManagerIID, NS_ICAPSMANAGER_IID);
err = pNSIPluginManager->QueryInterface(kICapsManagerIID, (void**)&pNSCCapsManager);
if( (err == NS_OK)
&& (pNSCCapsManager != NULL)
)
{
PRInt32 i=0;
nsPrincipal *pNSPrincipal = NULL;
pNSPrincipalArray = nsCapsNewPrincipalArray(length);
if (pNSPrincipalArray != NULL)
{
while( i<length )
{
err = pNSCCapsManager->GetNSPrincipal(ppNSIPrincipalArray[i], &pNSPrincipal);
nsCapsSetPrincipalArrayElement(pNSPrincipalArray, i, pNSPrincipal);
i++;
}
}
pNSCCapsManager->Release();
}
pNSIPluginManager->Release();
}
}
//pJVMPI->Release();
}
pJVMMgr->Release();
}
#endif
if ( (pNSPrincipalArray != NULL)
&&(length != 0)
)
{
return LM_GetJSPrincipalsFromJavaCaller(pJSContext, pNSPrincipalArray);
}
return NULL;
}
static jobject PR_CALLBACK
get_java_wrapper_impl(JNIEnv *pJNIEnv, jint jsobject)
{
nsresult err = NS_OK;
jobject pJSObjectWrapper = NULL;
nsJVMMgr* pJVMMgr = JVM_GetJVMMgr();
if (pJVMMgr != NULL) {
nsIJVMPlugin* pJVMPI = pJVMMgr->GetJVMPlugin();
if (pJVMPI != NULL) {
err = pJVMPI->GetJavaWrapper(pJNIEnv, jsobject, &pJSObjectWrapper);
//pJVMPI->Release();
}
pJVMMgr->Release();
}
if ( err != NS_OK )
{
return NULL;
}
return pJSObjectWrapper;
}
static JSBool PR_CALLBACK
enter_js_from_java_impl(JNIEnv *jEnv, char **errp)
{
#ifdef OJI
ThreadLocalStorageAtIndex0 *priv = NULL;
if ( PR_GetCurrentThread() == NULL )
{
PR_AttachThread(PR_USER_THREAD, PR_PRIORITY_NORMAL, NULL);
priv = (ThreadLocalStorageAtIndex0 *)malloc(sizeof(ThreadLocalStorageAtIndex0));
priv->refcount=1;
PR_SetThreadPrivate(tlsIndex_g, (void *)priv);
}
else
{
priv = (ThreadLocalStorageAtIndex0 *)PR_GetThreadPrivate(tlsIndex_g);
if(priv != NULL)
{
priv->refcount++;
}
}
return LM_LockJS(errp);
#else
return JS_TRUE;
#endif
}
static void PR_CALLBACK
exit_js_impl(JNIEnv *jEnv)
{
ThreadLocalStorageAtIndex0 *priv = NULL;
LM_UnlockJS();
if ( (PR_GetCurrentThread() != NULL )
&& ((priv = (ThreadLocalStorageAtIndex0 *)PR_GetThreadPrivate(tlsIndex_g)) != NULL)
)
{
priv->refcount--;
if(priv->refcount == 0)
{
PR_SetThreadPrivate(tlsIndex_g, NULL);
PR_DetachThread();
free(priv);
}
}
return;
}
static PRBool PR_CALLBACK
create_java_vm_impl(SystemJavaVM* *jvm, JNIEnv* *initialEnv, void* initargs)
{
const char* classpath = (const char*)initargs; // unused (should it be?)
*jvm = (SystemJavaVM*)JVM_GetJVMMgr(); // unused in the browser
*initialEnv = JVM_GetJNIEnv();
return (*jvm != NULL && *initialEnv != NULL);
}
static PRBool PR_CALLBACK
destroy_java_vm_impl(SystemJavaVM* jvm, JNIEnv* initialEnv)
{
JVM_ReleaseJNIEnv(initialEnv);
// need to release jvm
return PR_TRUE;
}
static JNIEnv* PR_CALLBACK
attach_current_thread_impl(SystemJavaVM* jvm)
{
return JVM_GetJNIEnv();
}
static PRBool PR_CALLBACK
detach_current_thread_impl(SystemJavaVM* jvm, JNIEnv* env)
{
JVM_ReleaseJNIEnv(env);
return PR_TRUE;
}
static SystemJavaVM* PR_CALLBACK
get_java_vm_impl(JNIEnv* env)
{
// only one SystemJavaVM for the whole browser, so it doesn't depend on env
return (SystemJavaVM*)JVM_GetJVMMgr();
}
#endif /* MOCHA */
PR_END_EXTERN_C
/*
* Callbacks for client-specific jsjava glue
*/
JSJCallbacks jsj_callbacks = {
map_jsj_thread_to_js_context_impl,
map_js_context_to_jsj_thread_impl,
map_java_object_to_js_object_impl,
get_JSPrincipals_from_java_caller_impl,
enter_js_from_java_impl,
exit_js_impl,
NULL, // error_print
get_java_wrapper_impl,
create_java_vm_impl,
destroy_java_vm_impl,
attach_current_thread_impl,
detach_current_thread_impl,
get_java_vm_impl
};
////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,119 @@
IGNORE_MANIFEST=1
#//------------------------------------------------------------------------
#//
#// Makefile to build
#//
#//------------------------------------------------------------------------
#//------------------------------------------------------------------------
#//
#// Specify the depth of the current directory relative to the
#// root of NS
#//
#//------------------------------------------------------------------------
DEPTH= ..\..\..
include <$(DEPTH)/config/config.mak>
!ifdef MOZ_OJI
!ifndef MAKE_OBJ_TYPE
MAKE_OBJ_TYPE=EXE
!endif
#//------------------------------------------------------------------------
#//
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
#//
#//------------------------------------------------------------------------
LIBNAME=oji$(MOZ_BITS)
PDBFILE=$(LIBNAME).pdb
#//------------------------------------------------------------------------
#//
#// Define the files necessary to build the target (ie. OBJS)
#//
#//------------------------------------------------------------------------
OBJS = .\$(OBJDIR)\jvmmgr.obj \
.\$(OBJDIR)\lcglue.obj \
.\$(OBJDIR)\scd.obj
#//------------------------------------------------------------------------
#//
#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...)
#// (these must be defined before the common makefiles are included)
#//
#//------------------------------------------------------------------------
LIBRARY= .\$(OBJDIR)\$(LIBNAME).lib
#//------------------------------------------------------------------------
#//
#// Define any local options for the make tools
#// (ie. LCFLAGS, LLFLAGS, LLIBS, LINCS)
#//
#//------------------------------------------------------------------------
LINCS= $(LINCS) -I_jri \
#
# For Win16 the following include directories are copied into
# ns/dist/public/win16
#
!if "$(MOZ_BITS)" == "32"
-I$(PUBLIC)/caps \
-I$(PUBLIC)/js \
-I$(PUBLIC)/java \
-I$(PUBLIC)/libimg \
-I$(PUBLIC)/nspr \
-I$(PUBLIC)/dbm \
-I$(PUBLIC)/security \
-I$(PUBLIC)/pref \
-I$(PUBLIC)/xpcom \
-I$(PUBLIC)/raptor \
-I$(PUBLIC)/plugin \
-I$(PUBLIC)/oji \
-I$(PUBLIC)/plugimpl \
!endif
-I$(DIST)/include/private \
-I$(DEPTH)/lib/layout \
-I$(DEPTH)/lib/libstyle \
-I$(DEPTH)/lib/libjar \
$(NULL)
CSRCS = jvmmgr.cpp \
scd.cpp
!endif # MOZ_OJI
MODULE = ojiimpl
EXPORTS = jvmmgr.h
#//------------------------------------------------------------------------
#//
#// Include the common makefile rules
#//
#//------------------------------------------------------------------------
include <$(DEPTH)/config/rules.mak>
LCFLAGS=$(LCFLAGS) ^
$(JAVA_DEFINES)
!if "$(MOZ_BITS)" == "32"
PUBLIC_HEADER_DIR=$(PUBLIC)\ojiimpl
!else
PUBLIC_HEADER_DIR=$(PUBLIC)\win16
!endif
export::
$(MAKE_INSTALL) jvmmgr.h $(PUBLIC_HEADER_DIR)
!ifdef MOZ_OJI
install:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
$(RM_R) _jri
!endif # MOZ_OJI

View File

@@ -0,0 +1,82 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
// NETSCAPE JAVA VM PLUGIN EXTENSIONS FOR SYMANTEC DEBUGGER
//
// This interface allows the browser to initialize a JVM that supports a
// debugger. It's called the "Symantec Debugger Interface" because it currently
// provides access to the Symantec Cafe or Visual Cafe debugger in the Netscape
// JVM. It is not meant to be the be-all-to-end-all of debugger interfaces.
////////////////////////////////////////////////////////////////////////////////
#ifndef nsscd_h___
#define nsscd_h___
#include "nsjvm.h"
////////////////////////////////////////////////////////////////////////////////
// Symantec Debug Manager Interface
//
// Implemented by the browser that supports the Symantec debugger.
class NPISymantecDebugManager : public nsISupports {
public:
NS_IMETHOD_(PRBool)
SetDebugAgentPassword(PRInt32 pwd) = 0;
};
#define NP_ISYMANTECDEBUGMANAGER_IID \
{ /* 131362e0-d985-11d1-8155-006008119d7a */ \
0x131362e0, \
0xd985, \
0x11d1, \
{0x81, 0x55, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
// Symantec Debugger Interface
//
// Implemented by the JVM plugin that supports the Symantec debugger.
enum NPSymantecDebugPort {
NPSymantecDebugPort_None = 0,
NPSymantecDebugPort_SharedMemory = -1
// anything else is a port number
};
class NPISymantecDebugger : public nsISupports {
public:
NS_IMETHOD_(JVMError)
StartDebugger(NPSymantecDebugPort port) = 0;
};
#define NP_ISYMANTECDEBUGGER_IID \
{ /* 954399f0-d980-11d1-8155-006008119d7a */ \
0x954399f0, \
0xd980, \
0x11d1, \
{0x81, 0x55, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsscd_h___ */

View File

@@ -0,0 +1,95 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
// Plugin Manager Methods to support the JVM Plugin API
////////////////////////////////////////////////////////////////////////////////
#include "jvmmgr.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kISymantecDebugManagerIID, NS_ISYMANTECDEBUGMANAGER_IID);
NS_IMPL_AGGREGATED(nsSymantecDebugManager);
nsSymantecDebugManager::nsSymantecDebugManager(nsISupports* outer, nsJVMMgr* jvmMgr)
: fJVMMgr(jvmMgr)
{
NS_INIT_AGGREGATED(outer);
}
nsSymantecDebugManager::~nsSymantecDebugManager()
{
}
NS_METHOD
nsSymantecDebugManager::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (aIID.Equals(kISymantecDebugManagerIID)) {
*aInstancePtr = this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_METHOD
nsSymantecDebugManager::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr,
nsJVMMgr* jvmMgr)
{
if (outer && !aIID.Equals(kISupportsIID))
return NS_NOINTERFACE; // XXX right error?
nsSymantecDebugManager* dbgr = new nsSymantecDebugManager(outer, jvmMgr);
if (dbgr == NULL)
return NS_ERROR_OUT_OF_MEMORY;
dbgr->AddRef();
*aInstancePtr = dbgr->GetInner();
return NS_OK;
}
#if defined(XP_PC) && defined(_WIN32)
extern "C" HWND FindNavigatorHiddenWindow(void);
#endif
NS_METHOD
nsSymantecDebugManager::SetDebugAgentPassword(PRInt32 pwd)
{
#if defined(XP_PC) && defined(_WIN32)
HWND win = FindNavigatorHiddenWindow();
HANDLE sem;
long err;
/* set up by aHiddenFrameClass in CNetscapeApp::InitInstance */
err = SetWindowLong(win, 0, pwd);
if (err == 0) {
// PR_LOG(NSJAVA, PR_LOG_ALWAYS,
// ("SetWindowLong returned %ld (err=%d)\n", err, GetLastError()));
/* continue so that we try to wake up the DebugManager */
}
sem = OpenSemaphore(SEMAPHORE_MODIFY_STATE, FALSE, "Netscape-Symantec Debugger");
if (sem) {
ReleaseSemaphore(sem, 1, NULL);
CloseHandle(sem);
}
return NS_OK;
#else
return NS_ERROR_FAILURE;
#endif
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,35 @@
#//------------------------------------------------------------------------
#//
#// Makefile to build the MODULES/OJI tree
#//
#//------------------------------------------------------------------------
#//------------------------------------------------------------------------
#//
#// Specify the depth of the current directory relative to the
#// root of NS
#//
#//------------------------------------------------------------------------
DEPTH=../..
#//------------------------------------------------------------------------
#//
#// Specify any "command" targets. (ie. DIRS, INSTALL_FILES, ...)
#// (these must come before the common makefiles are included)
#//
#// DIRS - There are subdirectories to process
#//
#//------------------------------------------------------------------------
ifndef NGLAYOUT_PLUGINS
DIRS= public src
else
DIRS= public nglsrc
endif
#//------------------------------------------------------------------------
#//
#// Include the common makefile rules
#//
#//------------------------------------------------------------------------
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,40 @@
#//------------------------------------------------------------------------
#//
#// Makefile to build the MODULES/OJI tree
#//
#//------------------------------------------------------------------------
#//------------------------------------------------------------------------
#//
#// Specify the depth of the current directory relative to the
#// root of NS
#//
#//------------------------------------------------------------------------
DEPTH=../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
#//------------------------------------------------------------------------
#//
#// Specify any "command" targets. (ie. DIRS, INSTALL_FILES, ...)
#// (these must come before the common makefiles are included)
#//
#// DIRS - There are subdirectories to process
#//
#//------------------------------------------------------------------------
ifndef NGLAYOUT_PLUGINS
DIRS= public src
else
DIRS= public nglsrc
endif
#//------------------------------------------------------------------------
#//
#// Include the common makefile rules
#//
#//------------------------------------------------------------------------
include $(topsrcdir)/config/rules.mk

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,42 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
#
# This is a list of local files which get copied to the mozilla:dist directory
#
nsIEventHandler.h
nsIFileUtilities.h
nsIJRILiveConnectPlugin.h
nsIJRILiveConnectPlugInstPeer.h
nsILiveConnectPlugin.h
nsILiveConnectPlugInstPeer.h
nsIMalloc.h
nsIPlugin.h
nsIPluginInstance.h
nsIPluginInstancePeer.h
nsIPluginManager.h
nsIPluginManager2.h
nsIPluginStream.h
nsIPluginStreamPeer.h
nsIPluginStreamPeer2.h
nsIPluginTagInfo.h
nsIPluginTagInfo2.h
nsISeekablePluginStreamPeer.h
nsIWindowlessPlugInstPeer.h
nsplugin.h
nsplugindefs.h

View File

@@ -0,0 +1,52 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH = ../../..
MODULE = plugin
EXPORTS = \
nsIEventHandler.h \
nsIFileUtilities.h \
nsIJRILiveConnectPlugin.h \
nsIJRILiveConnectPlugInstPeer.h \
nsILiveConnectPlugin.h \
nsILiveConnectPlugInstPeer.h \
nsIMalloc.h \
nsIPlugin.h \
nsIPluginInstance.h \
nsIPluginInstancePeer.h \
nsIPluginManager.h \
nsIPluginManager2.h \
nsIPluginStream.h \
nsIPluginTagInfo.h \
nsIPluginTagInfo2.h \
nsIWindowlessPlugInstPeer.h \
nsIPluginInputStream.h \
nsIPluginInputStream2.h \
nsIPluginStreamListener.h \
nsplugin.h \
nsplugindefs.h
# DEPRECATED -- remove before we ship 5.0
EXPORTS += \
nsIPluginStream.h \
nsIPluginStreamPeer.h \
nsIPluginStreamPeer2.h \
nsISeekablePluginStreamPeer.h \
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,59 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = plugin
EXPORTS = \
nsIEventHandler.h \
nsIFileUtilities.h \
nsIJRILiveConnectPlugin.h \
nsIJRILiveConnectPlugInstPeer.h \
nsILiveConnectPlugin.h \
nsILiveConnectPlugInstPeer.h \
nsIMalloc.h \
nsIPlugin.h \
nsIPluginInstance.h \
nsIPluginInstancePeer.h \
nsIPluginManager.h \
nsIPluginManager2.h \
nsIPluginStream.h \
nsIPluginTagInfo.h \
nsIPluginTagInfo2.h \
nsIWindowlessPlugInstPeer.h \
nsIPluginInputStream.h \
nsIPluginInputStream2.h \
nsIPluginStreamListener.h \
nsplugin.h \
nsplugindefs.h
# DEPRECATED -- remove before we ship 5.0
EXPORTS += \
nsIPluginStream.h \
nsIPluginStreamPeer.h \
nsIPluginStreamPeer2.h \
nsISeekablePluginStreamPeer.h \
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,54 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
IGNORE_MANIFEST=1
DEPTH = ..\..\..
MODULE = plugin
EXPORTS = \
nsIEventHandler.h \
nsIFileUtilities.h \
nsIJRILiveConnectPlugin.h \
nsIJRILiveConnectPlugInstPeer.h \
nsILiveConnectPlugin.h \
nsILiveConnectPlugInstPeer.h \
nsIMalloc.h \
nsIPlugin.h \
nsIPluginInstance.h \
nsIPluginInstancePeer.h \
nsIPluginManager.h \
nsIPluginManager2.h \
nsIPluginTagInfo.h \
nsIPluginTagInfo2.h \
nsIWindowlessPlugInstPeer.h \
nsIPluginInputStream.h \
nsIPluginInputStream2.h \
nsIPluginStreamListener.h \
nsplugin.h \
nsplugindefs.h
# DEPRECATED -- remove before we ship 5.0
EXPORTS = $(EXPORTS) \
nsIPluginStream.h \
nsIPluginStreamPeer.h \
nsIPluginStreamPeer2.h \
nsISeekablePluginStreamPeer.h \
include <$(DEPTH)/config/rules.mak>

View File

@@ -0,0 +1,81 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIEventHandler_h___
#define nsIEventHandler_h___
#include "nsplugindefs.h"
////////////////////////////////////////////////////////////////////////////////
// Plugin Instance Interface
/**
* The nsIEventHandler interface provides the callback to handle events.
* It is implemented by the plugin, and is the superclass for nsIPluginInstance.
*/
class nsIEventHandler : public nsISupports {
public:
/**
* Handles an event. An nsIEventHandler can also get registered with with
* nsIPluginManager2::RegisterWindow and will be called whenever an event
* comes in for that window.
*
* Note that for Unix and Mac the nsPluginEvent structure is different
* from the old NPEvent structure -- it's no longer the native event
* record, but is instead a struct. This was done for future extensibility,
* and so that the Mac could receive the window argument too. For Windows
* and OS2, it's always been a struct, so there's no change for them.
*
* (Corresponds to NPP_HandleEvent.)
*
* @param event - the event to be handled
* @param handled - set to PR_TRUE if event was handled
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
HandleEvent(nsPluginEvent* event, PRBool* handled) = 0;
};
#define NS_IEVENTHANDLER_IID \
{ /* a447ddf0-1a99-11d2-815f-006008119d7a */ \
0xa447ddf0, \
0x1a99, \
0x11d2, \
{0x81, 0x5f, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIEventHandler_h___ */

View File

@@ -0,0 +1,92 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIFileUtilities_h___
#define nsIFileUtilities_h___
#include "nsplugindefs.h"
#include "nsISupports.h"
////////////////////////////////////////////////////////////////////////////////
// File Utilities Interface
// This interface reflects operations only available in Communicator 5.0.
/**
* The nsIFileUtilities interface provides access to random file operations.
* To obtain: QueryInterface on nsIPluginManager.
*/
class nsIFileUtilities : public nsISupports {
public:
/**
* Returns the name of the browser executable program.
*
* @param result - the returned path to the program
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
GetProgramPath(const char* *result) = 0;
/**
* Returns the name of the temporary directory.
*
* @param result - the returned path to the temp directory
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
GetTempDirPath(const char* *result) = 0;
/**
* Returns a unique temporary file name.
*
* @param prefix - a string to prefix to the temporary file name
* @param bufLen - the length of the resultBuf to receive the data
* @param resultBuf - the returned temp file name
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
NewTempFileName(const char* prefix, PRUint32 bufLen, char* resultBuf) = 0;
};
#define NS_IFILEUTILITIES_IID \
{ /* 89a31ce0-019a-11d2-815b-006008119d7a */ \
0x89a31ce0, \
0x019a, \
0x11d2, \
{0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIFileUtilities_h___ */

View File

@@ -0,0 +1,98 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIJRILiveConnectPluginInstancePeer_h__
#define nsIJRILiveConnectPluginInstancePeer_h__
#include "nsplugindefs.h"
#include "nsISupports.h"
////////////////////////////////////////////////////////////////////////////////
// JRI-Based LiveConnect Classes
////////////////////////////////////////////////////////////////////////////////
//
// This stuff is here so that the browser can support older JRI-based
// LiveConnected plugins (when using old plugin to new C++-style plugin
// adapter code).
//
// Warning: Don't use this anymore, unless you're sure that you have to!
////////////////////////////////////////////////////////////////////////////////
#include "jri.h"
/**
* The nsIJRILiveConnectPluginInstancePeer interface is implemented by browsers
* that support JRI-based LiveConnect. Note that for 5.0, LiveConnect support
* has become JNI-based, so this interface is effectively deprecated.
*
* To obtain: QueryInterface on nsIPluginInstancePeer
*/
class nsIJRILiveConnectPluginInstancePeer : public nsISupports {
public:
/**
* Returns a JRI reference to the Java peer object associated with the
* plugin instance. This object is an instance of the class specified
* by nsIJRILiveConnectPlugin::GetJavaClass.
*
* (Corresponds to NPN_GetJavaPeer.)
*
* @param resultingJavaPeer - a resulting reference to the Java instance
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
GetJavaPeer(jref *resultingJavaPeer) = 0;
};
#define NS_IJRILIVECONNECTPLUGININSTANCEPEER_IID \
{ /* 25b63f40-f773-11d1-815b-006008119d7a */ \
0x25b63f40, \
0xf773, \
0x11d1, \
{0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
// QueryInterface for this IID on nsIPluginManager to get a JRIEnv
// XXX change this
#define NS_IJRIENV_IID \
{ /* f9d4ea00-a1bc-11d1-85b1-00805f0e4dfe */ \
0xf9d4ea00, \
0xa1bc, \
0x11d1, \
{0x85, 0xb1, 0x00, 0x80, 0x5f, 0x0e, 0x4d, 0xfe} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIJRILiveConnectPluginInstancePeer_h__ */

View File

@@ -0,0 +1,88 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIJRILiveConnectPlugin_h__
#define nsIJRILiveConnectPlugin_h__
#include "nsIPlugin.h"
////////////////////////////////////////////////////////////////////////////////
// JRI-Based LiveConnect Classes
////////////////////////////////////////////////////////////////////////////////
//
// This stuff is here so that the browser can support older JRI-based
// LiveConnected plugins (when using old plugin to new C++-style plugin
// adapter code).
//
// Warning: Don't use this anymore, unless you're sure that you have to!
////////////////////////////////////////////////////////////////////////////////
#include "jri.h"
/**
* The nsIJRILiveConnectPlugin interface defines additional entry points that a
* plugin developer needs to implement in order for the plugin to support
* JRI-based LiveConnect, as opposed to the standard JNI-based LiveConnect
* (which new in 5.0).
*
* Plugin developers requiring this capability should implement this interface
* in addition to the basic nsIPlugin interface.
*/
class nsIJRILiveConnectPlugin : public nsIPlugin {
public:
/**
* Returns the class of the Java instance to be associated with the
* plugin.
*
* (Corresponds to NPP_GetJavaClass.)
*
* @param resultingClass - a resulting reference to the Java class
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
GetJavaClass(jref *resultingClass) = 0;
};
#define NS_IJRILIVECONNECTPLUGIN_IID \
{ /* c94058e0-f772-11d1-815b-006008119d7a */ \
0xc94058e0, \
0xf772, \
0x11d1, \
{0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIJRILiveConnectPlugin_h__ */

View File

@@ -0,0 +1,86 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIJRILiveConnectPluginInstancePeer_h__
#define nsIJRILiveConnectPluginInstancePeer_h__
#include "nsplugindefs.h"
////////////////////////////////////////////////////////////////////////////////
// JRI-Based LiveConnect Classes
////////////////////////////////////////////////////////////////////////////////
//
// This stuff is here so that the browser can support older JRI-based
// LiveConnected plugins (when using old plugin to new C++-style plugin
// adapter code).
//
// Warning: Don't use this anymore, unless you're sure that you have to!
////////////////////////////////////////////////////////////////////////////////
#include "jri.h" // ancient
////////////////////////////////////////////////////////////////////////////////
// JRILiveConnect Plugin Instance Peer Interface
// Browsers that support JRI-based LiveConnect implement this subclass of
// plugin instance peer.
class nsIJRILiveConnectPluginInstancePeer : public nsISupports {
public:
// (Corresponds to NPN_GetJavaPeer.)
NS_IMETHOD_(jref)
GetJavaPeer(void) = 0;
};
#define NS_IJRILIVECONNECTPLUGININSTANCEPEER_IID \
{ /* 25b63f40-f773-11d1-815b-006008119d7a */ \
0x25b63f40, \
0xf773, \
0x11d1, \
{0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
// QueryInterface for this IID on nsIPluginManager to get a JRIEnv
// XXX change this
#define NS_IJRIENV_IID \
{ /* f9d4ea00-a1bc-11d1-85b1-00805f0e4dfe */ \
0xf9d4ea00, \
0xa1bc, \
0x11d1, \
{0x85, 0xb1, 0x00, 0x80, 0x5f, 0x0e, 0x4d, 0xfe} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIJRILiveConnectPluginInstancePeer_h__ */

View File

@@ -0,0 +1,86 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsILiveConnectPluginInstancePeer_h___
#define nsILiveConnectPluginInstancePeer_h___
#include "nsplugindefs.h"
#include "nsISupports.h"
#include "jni.h" // standard JVM API
/**
* The nsILiveConnectPluginInstancePeer interface is implemented by browsers
* that support LiveConnect, i.e. scriptability via JavaScript. Note that this
* LiveConnect interface is now JNI-based (since 5.0).
*
* To obtain: QueryInterface on nsIPluginInstancePeer
*/
class nsILiveConnectPluginInstancePeer : public nsISupports {
public:
/**
* Returns a JNI reference to the Java peer object associated with the
* plugin instance. This object is an instance of the class specified
* by nsIJRILiveConnectPlugin::GetJavaClass.
*
* (New JNI-based entry point, roughly corresponds to NPN_GetJavaPeer.)
*
* @param resultingJavaPeer - a resulting reference to the Java instance
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
GetJavaPeer(jobject *resultingJavaPeer) = 0;
};
#define NS_ILIVECONNECTPLUGININSTANCEPEER_IID \
{ /* 1e3502a0-a1bd-11d1-85b1-00805f0e4dfe */ \
0x1e3502a0, \
0xa1bd, \
0x11d1, \
{0x85, 0xb1, 0x00, 0x80, 0x5f, 0x0e, 0x4d, 0xfe} \
}
// QueryInterface for this IID on nsIPluginManager to get a JNIEnv
// XXX change this
#define NS_IJNIENV_IID \
{ /* 04610650-a1bd-11d1-85b1-00805f0e4dfe */ \
0x04610650, \
0xa1bd, \
0x11d1, \
{0x85, 0xb1, 0x00, 0x80, 0x5f, 0x0e, 0x4d, 0xfe} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsILiveConnectPluginInstancePeer_h___ */

View File

@@ -0,0 +1,75 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsILiveConnectPlugin_h__
#define nsILiveConnectPlugin_h__
#include "nsIPlugin.h"
#include "jni.h" // standard JVM API
/**
* The nsILiveConnectPlugin interface defines additional entry points that a
* plugin developer needs to implement in order for the plugin to support
* JNI-based LiveConnect (new in 5.0).
*
* Plugin developers requiring this capability should implement this interface
* in addition to the basic nsIPlugin interface.
*/
class nsILiveConnectPlugin : public nsIPlugin {
public:
/**
* Returns the class of the Java instance to be associated with the
* plugin.
*
* (New JNI-based entry point, roughly corresponds to NPP_GetJavaClass.)
*
* @param resultingClass - a resulting reference to the Java class
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
GetJavaClass(jclass *resultingClass) = 0;
};
#define NS_ILIVECONNECTPLUGIN_IID \
{ /* cf134df0-a1bc-11d1-85b1-00805f0e4dfe */ \
0xcf134df0, \
0xa1bc, \
0x11d1, \
{0x85, 0xb1, 0x00, 0x80, 0x5f, 0x0e, 0x4d, 0xfe} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsILiveConnectPlugin_h__ */

View File

@@ -0,0 +1,74 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsILiveConnectPluginInstancePeer_h___
#define nsILiveConnectPluginInstancePeer_h___
#include "nsplugindefs.h"
#include "jni.h" // standard JVM API
////////////////////////////////////////////////////////////////////////////////
// LiveConnect Plugin Instance Peer Interface
// Browsers that support JNI-based LiveConnect implement this subclass of
// plugin instance peer.
class nsILiveConnectPluginInstancePeer : public nsISupports {
public:
// (New JNI-based entry point, roughly corresponds to NPN_GetJavaPeer.)
NS_IMETHOD_(jobject)
GetJavaPeer(void) = 0;
};
#define NS_ILIVECONNECTPLUGININSTANCEPEER_IID \
{ /* 1e3502a0-a1bd-11d1-85b1-00805f0e4dfe */ \
0x1e3502a0, \
0xa1bd, \
0x11d1, \
{0x85, 0xb1, 0x00, 0x80, 0x5f, 0x0e, 0x4d, 0xfe} \
}
// QueryInterface for this IID on nsIPluginManager to get a JNIEnv
// XXX change this
#define NS_IJNIENV_IID \
{ /* 04610650-a1bd-11d1-85b1-00805f0e4dfe */ \
0x04610650, \
0xa1bd, \
0x11d1, \
{0x85, 0xb1, 0x00, 0x80, 0x5f, 0x0e, 0x4d, 0xfe} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsILiveConnectPluginInstancePeer_h___ */

View File

@@ -0,0 +1,94 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIMalloc_h___
#define nsIMalloc_h___
#include "nsISupports.h"
class nsIMalloc : public nsISupports {
public:
/**
* Allocates a block of memory of a particular size.
*
* @param size - the size of the block to allocate
* @result the block of memory
*/
NS_IMETHOD_(void*)
Alloc(PRUint32 size) = 0;
/**
* Reallocates a block of memory to a new size.
*
* @param ptr - the block of memory to reallocate
* @param size - the new size
* @result the rellocated block of memory
*/
NS_IMETHOD_(void*)
Realloc(void* ptr, PRUint32 size) = 0;
/**
* Frees a block of memory.
*
* @param ptr - the block of memory to free
*/
NS_IMETHOD_(void)
Free(void* ptr) = 0;
/**
* Returns the size of a block of memory. Returns -1
* if the size is not available.
*
* @param ptr - the block of memory
* @result the size or -1 if not available
*/
NS_IMETHOD_(PRInt32)
GetSize(void* ptr) = 0;
/**
* Returns whether the block of memory was allocated by this
* memory allocator. Returns PR_FALSE if this information is
* not available.
*
* @param ptr - the block of memory
* @result true if allocated by this nsIMalloc, false if not or
* if it can't be determined
*/
NS_IMETHOD_(PRBool)
DidAlloc(void* ptr) = 0;
/**
* Attempts to shrink the heap.
*/
NS_IMETHOD_(void)
HeapMinimize(void) = 0;
};
#define NS_IMALLOC_IID \
{ /* c4744e60-1875-11d2-815f-006008119d7a */ \
0xc4744e60, \
0x1875, \
0x11d2, \
{0x81, 0x5f, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIMalloc_h___ */

View File

@@ -0,0 +1,121 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIPlugin_h___
#define nsIPlugin_h___
#include "nsplugindefs.h"
#include "nsIFactory.h"
/**
* The nsIPlugin interface is the minimum interface plugin developers need to
* support in order to implement a plugin. The plugin manager may QueryInterface
* for more specific plugin types, e.g. nsILiveConnectPlugin.
*
* The old NPP_New plugin operation is now subsumed by two operations:
*
* CreateInstance -- called once, after the plugin instance is created. This
* method is used to initialize the new plugin instance (although the actual
* plugin instance object will be created by the plugin manager).
*
* nsIPluginInstance::Start -- called when the plugin instance is to be
* started. This happens in two circumstances: (1) after the plugin instance
* is first initialized, and (2) after a plugin instance is returned to
* (e.g. by going back in the window history) after previously being stopped
* by the Stop method.
*/
struct nsIPlugin : public nsIFactory {
public:
/**
* Initializes the plugin and will be called before any new instances are
* created. It is passed browserInterfaces on which QueryInterface
* may be used to obtain an nsIPluginManager, and other interfaces.
*
* @param browserInterfaces - an object that allows access to other browser
* interfaces via QueryInterface
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
Initialize(nsISupports* browserInterfaces) = 0;
/**
* Called when the browser is done with the plugin factory, or when
* the plugin is disabled by the user.
*
* (Corresponds to NPP_Shutdown.)
*
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
Shutdown(void) = 0;
/**
* Returns the MIME description for the plugin. The MIME description
* is a colon-separated string containg the plugin MIME type, plugin
* data file extension, and plugin name, e.g.:
*
* "application/x-simple-plugin:smp:Simple LiveConnect Sample Plug-in"
*
* (Corresponds to NPP_GetMIMEDescription.)
*
* @param resultingDesc - the resulting MIME description
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
GetMIMEDescription(const char* *resultingDesc) = 0;
/**
* Returns the value of a variable associated with the plugin.
*
* (Corresponds to NPP_GetValue.)
*
* @param variable - the plugin variable to get
* @param value - the address of where to store the resulting value
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
GetValue(nsPluginVariable variable, void *value) = 0;
};
#define NS_IPLUGIN_IID \
{ /* df773070-0199-11d2-815b-006008119d7a */ \
0xdf773070, \
0x0199, \
0x11d2, \
{0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIPlugin_h___ */

View File

@@ -0,0 +1,65 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIPluginInputStream_h___
#define nsIPluginInputStream_h___
#include "nsplugindefs.h"
#include "nsIInputStream.h"
/**
* The nsIPluginInputStream interface ...
*/
class nsIPluginInputStream : public nsIInputStream {
public:
// (Corresponds to NPStream's lastmodified field.)
NS_IMETHOD
GetLastModified(PRUint32 *result) = 0;
NS_IMETHOD
RequestRead(nsByteRange* rangeList) = 0;
};
#define NS_IPLUGININPUTSTREAM_IID \
{ /* af160530-542a-11d2-8164-006008119d7a */ \
0xaf160530, \
0x542a, \
0x11d2, \
{0x81, 0x64, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIPluginInputStream_h___ */

View File

@@ -0,0 +1,66 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIPluginInputStream2_h___
#define nsIPluginInputStream2_h___
#include "nsIPluginInputStream.h"
/**
* The nsIPluginInputStream2 interface ...
*/
class nsIPluginInputStream2 : public nsIPluginInputStream {
public:
NS_IMETHOD
GetContentLength(PRUint32 *result) = 0;
NS_IMETHOD
GetHeaderFields(PRUint16& n, const char*const*& names, const char*const*& values) = 0;
NS_IMETHOD
GetHeaderField(const char* name, const char* *result) = 0;
};
#define NS_IPLUGININPUTSTREAM2_IID \
{ /* cfb36db0-542a-11d2-8164-006008119d7a */ \
0xcfb36db0, \
0x542a, \
0x11d2, \
{0x81, 0x64, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIPluginInputStream2_h___ */

View File

@@ -0,0 +1,196 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIPluginInstance_h___
#define nsIPluginInstance_h___
#include "nsplugindefs.h"
#include "nsIEventHandler.h"
////////////////////////////////////////////////////////////////////////////////
// Plugin Instance Interface
/**
* The nsIPluginInstance interface is the minimum interface plugin developers
* need to support in order to implement a plugin instance. The plugin manager
* may QueryInterface for more specific types, e.g. nsILiveConnectPluginInstance.
*
* (Corresponds to NPP object.)
*
* The old NPP_Destroy call has been factored into two plugin instance
* methods:
*
* Stop -- called when the plugin instance is to be stopped (e.g. by
* displaying another plugin manager window, causing the page containing
* the plugin to become removed from the display).
*
* Destroy -- called once, before the plugin instance peer is to be
* destroyed. This method is used to destroy the plugin instance.
*/
class nsIPluginInstance : public nsIEventHandler {
public:
/**
* Initializes a newly created plugin instance, passing to it the plugin
* instance peer which it should use for all communication back to the browser.
*
* @param peer - the corresponding plugin instance peer
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
Initialize(nsIPluginInstancePeer* peer) = 0;
/**
* Returns a reference back to the plugin instance peer. This method is
* used whenever the browser needs to obtain the peer back from a plugin
* instance. The implementation of this method should be sure to increment
* the reference count on the peer by calling AddRef.
*
* @param resultingPeer - the resulting plugin instance peer
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
GetPeer(nsIPluginInstancePeer* *resultingPeer) = 0;
/**
* Called to instruct the plugin instance to start. This will be called after
* the plugin is first created and initialized, and may be called after the
* plugin is stopped (via the Stop method) if the plugin instance is returned
* to in the browser window's history.
*
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
Start(void) = 0;
/**
* Called to instruct the plugin instance to stop, thereby suspending its state.
* This method will be called whenever the browser window goes on to display
* another page and the page containing the plugin goes into the window's history
* list.
*
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
Stop(void) = 0;
/**
* Called to instruct the plugin instance to destroy itself. This is called when
* it become no longer possible to return to the plugin instance, either because
* the browser window's history list of pages is being trimmed, or because the
* window containing this page in the history is being closed.
*
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
Destroy(void) = 0;
/**
* Called when the window containing the plugin instance changes.
*
* (Corresponds to NPP_SetWindow.)
*
* @param window - the plugin window structure
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
SetWindow(nsPluginWindow* window) = 0;
#ifndef NEW_PLUGIN_STREAM_API
/**
* Called when a new plugin stream must be constructed in order for the plugin
* instance to receive a stream of data from the browser.
*
* (Corresponds to NPP_NewStream.)
*
* @param peer - the plugin stream peer, representing information about the
* incoming stream, and stream-specific callbacks into the browser
* @param result - the resulting plugin stream
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
NewStream(nsIPluginStreamPeer* peer, nsIPluginStream* *result) = 0;
#endif
/**
* Called to instruct the plugin instance to print itself to a printer.
*
* (Corresponds to NPP_Print.)
*
* @param platformPrint - platform-specific printing information
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
Print(nsPluginPrint* platformPrint) = 0;
#ifndef NEW_PLUGIN_STREAM_API
/**
* Called to notify the plugin instance that a URL request has been
* completed. (See nsIPluginManager::GetURL and nsIPluginManager::PostURL).
*
* (Corresponds to NPP_URLNotify.)
*
* @param url - the requested URL
* @param target - the target window name
* @param reason - the reason for completion
* @param notifyData - the notify data supplied to GetURL or PostURL
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
URLNotify(const char* url, const char* target,
nsPluginReason reason, void* notifyData) = 0;
#endif
/**
* Returns the value of a variable associated with the plugin instance.
*
* @param variable - the plugin instance variable to get
* @param value - the address of where to store the resulting value
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
GetValue(nsPluginInstanceVariable variable, void *value) = 0;
};
#define NS_IPLUGININSTANCE_IID \
{ /* ebe00f40-0199-11d2-815b-006008119d7a */ \
0xebe00f40, \
0x0199, \
0x11d2, \
{0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIPluginInstance_h___ */

View File

@@ -0,0 +1,142 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIPluginInstancePeer_h___
#define nsIPluginInstancePeer_h___
#include "nsplugindefs.h"
#include "nsISupports.h"
class nsIOutputStream;
////////////////////////////////////////////////////////////////////////////////
// Plugin Instance Peer Interface
/**
* The nsIPluginInstancePeer interface is the set of operations implemented
* by the browser to support a plugin instance. When a plugin instance is
* constructed, a nsIPluginInstancePeer is passed to its initializer
* representing the instantiation of the plugin on the page.
*
* Other interfaces may be obtained from nsIPluginInstancePeer by calling
* QueryInterface, e.g. nsIPluginTagInfo.
*/
class nsIPluginInstancePeer : public nsISupports {
public:
/**
* Returns the value of a variable associated with the plugin manager.
*
* (Corresponds to NPN_GetValue.)
*
* @param variable - the plugin manager variable to get
* @param value - the address of where to store the resulting value
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
GetValue(nsPluginInstancePeerVariable variable, void *value) = 0;
/**
* Returns the MIME type of the plugin instance.
*
* (Corresponds to NPP_New's MIMEType argument.)
*
* @param result - resulting MIME type
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
GetMIMEType(nsMIMEType *result) = 0;
/**
* Returns the mode of the plugin instance, i.e. whether the plugin is
* embedded in the html, or full page.
*
* (Corresponds to NPP_New's mode argument.)
*
* @param result - the resulting mode
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
GetMode(nsPluginMode *result) = 0;
/**
* This operation is called by the plugin instance when it wishes to send
* a stream of data to the browser. It constructs a new output stream to which
* the plugin may send the data. When complete, the Close and Release methods
* should be called on the output stream.
*
* (Corresponds to NPN_NewStream.)
*
* @param type - type MIME type of the stream to create
* @param target - the target window name to receive the data
* @param result - the resulting output stream
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
NewStream(nsMIMEType type, const char* target, nsIOutputStream* *result) = 0;
/**
* This operation causes status information to be displayed on the window
* associated with the plugin instance.
*
* (Corresponds to NPN_Status.)
*
* @param message - the status message to display
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
ShowStatus(const char* message) = 0;
/**
* Set the desired size of the window in which the plugin instance lives.
*
* @param width - new window width
* @param height - new window height
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
SetWindowSize(PRUint32 width, PRUint32 height) = 0;
};
#define NS_IPLUGININSTANCEPEER_IID \
{ /* 4b7cea20-019b-11d2-815b-006008119d7a */ \
0x4b7cea20, \
0x019b, \
0x11d2, \
{0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIPluginInstancePeer_h___ */

View File

@@ -0,0 +1,191 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIPluginManager_h___
#define nsIPluginManager_h___
#include "nsplugindefs.h"
#include "nsISupports.h"
class nsIPluginStreamListener;
/**
* The nsIPluginManager interface defines the minimum set of functionality that
* the browser will support if it allows plugins. Plugins can call QueryInterface
* to determine if a plugin manager implements more specific APIs or other
* browser interfaces for the plugin to use (e.g. nsINetworkManager).
*/
class nsIPluginManager : public nsISupports {
public:
/**
* Returns the value of a variable associated with the plugin manager.
*
* (Corresponds to NPN_GetValue.)
*
* @param variable - the plugin manager variable to get
* @param value - the address of where to store the resulting value
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
GetValue(nsPluginManagerVariable variable, void *value) = 0;
/**
* Causes the plugins directory to be searched again for new plugin
* libraries.
*
* (Corresponds to NPN_ReloadPlugins.)
*
* @param reloadPages - indicates whether currently visible pages should
* also be reloaded
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
ReloadPlugins(PRBool reloadPages) = 0;
/**
* Returns the user agent string for the browser.
*
* (Corresponds to NPN_UserAgent.)
*
* @param resultingAgentString - the resulting user agent string
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
UserAgent(const char* *resultingAgentString) = 0;
#ifdef NEW_PLUGIN_STREAM_API
NS_IMETHOD
GetURL(nsISupports* pluginInst,
const char* url,
const char* target = NULL,
nsIPluginStreamListener* streamListener = NULL,
nsPluginStreamType streamType = nsPluginStreamType_Normal,
const char* altHost = NULL,
const char* referrer = NULL,
PRBool forceJSEnabled = PR_FALSE) = 0;
NS_IMETHOD
PostURL(nsISupports* pluginInst,
const char* url,
PRUint32 postDataLen,
const char* postData,
PRBool isFile = PR_FALSE,
const char* target = NULL,
nsIPluginStreamListener* streamListener = NULL,
nsPluginStreamType streamType = nsPluginStreamType_Normal,
const char* altHost = NULL,
const char* referrer = NULL,
PRBool forceJSEnabled = PR_FALSE,
PRUint32 postHeadersLength = 0,
const char* postHeaders = NULL) = 0;
#else // !NEW_PLUGIN_STREAM_API
/**
* Fetches a URL.
*
* (Corresponds to NPN_GetURL and NPN_GetURLNotify.)
*
* @param pluginInst - the plugin making the request. If NULL, the URL
* is fetched in the background.
* @param url - the URL to fetch
* @param target - the target window into which to load the URL
* @param notifyData - when present, URLNotify is called passing the
* notifyData back to the client. When NULL, this call behaves like
* NPN_GetURL.
* @param altHost - an IP-address string that will be used instead of the
* host specified in the URL. This is used to prevent DNS-spoofing
* attacks. Can be defaulted to NULL meaning use the host in the URL.
* @param referrer - the referring URL (may be NULL)
* @param forceJSEnabled - forces JavaScript to be enabled for 'javascript:'
* URLs, even if the user currently has JavaScript disabled (usually
* specify PR_FALSE)
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
GetURL(nsISupports* pluginInst, const char* url, const char* target,
void* notifyData = NULL, const char* altHost = NULL,
const char* referrer = NULL, PRBool forceJSEnabled = PR_FALSE) = 0;
/**
* Posts to a URL with post data and/or post headers.
*
* (Corresponds to NPN_PostURL and NPN_PostURLNotify.)
*
* @param pluginInst - the plugin making the request. If NULL, the URL
* is fetched in the background.
* @param url - the URL to fetch
* @param target - the target window into which to load the URL
* @param postDataLength - the length of postData (if non-NULL)
* @param postData - the data to POST. NULL specifies that there is not post
* data
* @param isFile - whether the postData specifies the name of a file to
* post instead of data. The file will be deleted afterwards.
* @param notifyData - when present, URLNotify is called passing the
* notifyData back to the client. When NULL, this call behaves like
* NPN_GetURL.
* @param altHost - an IP-address string that will be used instead of the
* host specified in the URL. This is used to prevent DNS-spoofing
* attacks. Can be defaulted to NULL meaning use the host in the URL.
* @param referrer - the referring URL (may be NULL)
* @param forceJSEnabled - forces JavaScript to be enabled for 'javascript:'
* URLs, even if the user currently has JavaScript disabled (usually
* specify PR_FALSE)
* @param postHeadersLength - the length of postHeaders (if non-NULL)
* @param postHeaders - the headers to POST. NULL specifies that there
* are no post headers
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
PostURL(nsISupports* pluginInst, const char* url, const char* target,
PRUint32 postDataLen, const char* postData,
PRBool isFile = PR_FALSE, void* notifyData = NULL,
const char* altHost = NULL, const char* referrer = NULL,
PRBool forceJSEnabled = PR_FALSE,
PRUint32 postHeadersLength = 0, const char* postHeaders = NULL) = 0;
#endif // !NEW_PLUGIN_STREAM_API
};
#define NS_IPLUGINMANAGER_IID \
{ /* da58ad80-4eb6-11d2-8164-006008119d7a */ \
0xda58ad80, \
0x4eb6, \
0x11d2, \
{0x81, 0x64, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIPluginManager_h___ */

View File

@@ -0,0 +1,188 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIPluginManager2_h___
#define nsIPluginManager2_h___
#include "nsIPluginManager.h"
////////////////////////////////////////////////////////////////////////////////
// Plugin Manager 2 Interface
// These extensions to nsIPluginManager are only available in Communicator 5.0.
class nsIPluginManager2 : public nsIPluginManager {
public:
/**
* Puts up a wait cursor.
*
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
BeginWaitCursor(void) = 0;
/**
* Restores the previous (non-wait) cursor.
*
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
EndWaitCursor(void) = 0;
/**
* Returns true if a URL protocol (e.g. "http") is supported.
*
* @param protocol - the protocol name
* @param result - true if the protocol is supported
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
SupportsURLProtocol(const char* protocol, PRBool *result) = 0;
/**
* This method may be called by the plugin to indicate that an error
* has occurred, e.g. that the plugin has failed or is shutting down
* spontaneously. This allows the browser to clean up any plugin-specific
* state.
*
* @param plugin - the plugin whose status is changing
* @param errorStatus - the the error status value
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
NotifyStatusChange(nsIPlugin* plugin, nsresult errorStatus) = 0;
/**
* Returns the proxy info for a given URL. The caller is required to
* free the resulting memory with nsIMalloc::Free. The result will be in the
* following format
*
* i) "DIRECT" -- no proxy
* ii) "PROXY xxx.xxx.xxx.xxx" -- use proxy
* iii) "SOCKS xxx.xxx.xxx.xxx" -- use SOCKS
* iv) Mixed. e.g. "PROXY 111.111.111.111;PROXY 112.112.112.112",
* "PROXY 111.111.111.111;SOCKS 112.112.112.112"....
*
* Which proxy/SOCKS to use is determined by the plugin.
*/
NS_IMETHOD
FindProxyForURL(const char* url, char* *result) = 0;
////////////////////////////////////////////////////////////////////////////
// New top-level window handling calls for Mac:
/**
* Registers a top-level window with the browser. Events received by that
* window will be dispatched to the event handler specified.
*
* @param handler - the event handler for the window
* @param window - the platform window reference
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
RegisterWindow(nsIEventHandler* handler, nsPluginPlatformWindowRef window) = 0;
/**
* Unregisters a top-level window with the browser. The handler and window pair
* should be the same as that specified to RegisterWindow.
*
* @param handler - the event handler for the window
* @param window - the platform window reference
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
UnregisterWindow(nsIEventHandler* handler, nsPluginPlatformWindowRef window) = 0;
/**
* Allocates a new menu ID (for the Mac).
*
* @param handler - the event handler for the window
* @param isSubmenu - whether this is a sub-menu ID or not
* @param result - the resulting menu ID
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
AllocateMenuID(nsIEventHandler* handler, PRBool isSubmenu, PRInt16 *result) = 0;
/**
* Deallocates a menu ID (for the Mac).
*
* @param handler - the event handler for the window
* @param menuID - the menu ID
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
DeallocateMenuID(nsIEventHandler* handler, PRInt16 menuID) = 0;
/**
* Indicates whether this event handler has allocated the given menu ID.
*
* @param handler - the event handler for the window
* @param menuID - the menu ID
* @param result - returns PR_TRUE if the menu ID is allocated
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
HasAllocatedMenuID(nsIEventHandler* handler, PRInt16 menuID, PRBool *result) = 0;
#if 0 // problematic
/**
* This operation causes the next browser event to be processed. This is
* handy for implement nested event loops where some other activity must
* be performed each time around the loop.
*
* On the Mac (and most likely on Win16), network activity can only occur on
* the main thread. Therefore, we provide a hook here for the case that the
* main thread needs to process events while waiting for network activity to
* complete.
*
* @param bEventHandled - a boolean indicating whether an event was processed on the
* main thread. If not on the main browser thread, PR_FALSE is returned.
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
ProcessNextEvent(PRBool *bEventHandled) = 0;
#endif
};
#define NS_IPLUGINMANAGER2_IID \
{ /* d2962dc0-4eb6-11d2-8164-006008119d7a */ \
0xd2962dc0, \
0x4eb6, \
0x11d2, \
{0x81, 0x64, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIPluginManager2_h___ */

View File

@@ -0,0 +1,89 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIPluginStream_h___
#define nsIPluginStream_h___
#ifndef NEW_PLUGIN_STREAM_API
#include "nsplugindefs.h"
#include "nsIOutputStream.h"
/**
* The nsIPluginStream interface specifies the minimal set of operations that
* must be implemented by a plugin stream in order to receive data from the
* browser. When a nsIPluginManager::GetURL request is made, a subsequent
* nsIPluginInstance::NewStream request will be made to instruct the plugin
* instance to construct a new stream to receive the data.
*/
class nsIPluginStream : public nsIOutputStream {
public:
/**
* Returns the stream type of a stream.
*
* (Corresponds to NPP_NewStream's stype return parameter.)
*
* @param result - the resulting stream type
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
GetStreamType(nsPluginStreamType *result) = 0;
/**
* This operation passes to the plugin the name of the file which
* contains the stream data.
*
* (Corresponds to NPP_StreamAsFile.)
*
* @param fname - the file name
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD
AsFile(const char* fname) = 0;
};
#define NS_IPLUGINSTREAM_IID \
{ /* f287dd50-0199-11d2-815b-006008119d7a */ \
0xf287dd50, \
0x0199, \
0x11d2, \
{0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
#endif // !NEW_PLUGIN_STREAM_API
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIPluginStream_h___ */

View File

@@ -0,0 +1,110 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIPluginStreamListener_h___
#define nsIPluginStreamListener_h___
#include "nsplugindefs.h"
#include "nsISupports.h"
class nsIPluginInputStream;
struct nsPluginStreamInfo {
nsMIMEType contentType;
PRBool seekable;
// more...
};
/**
* The nsIPluginStreamListener interface defines the minimum set of functionality that
* the browser will support if it allows plugins. Plugins can call QueryInterface
* to determine if a plugin manager implements more specific APIs or other
* browser interfaces for the plugin to use (e.g. nsINetworkManager).
*/
class nsIPluginStreamListener : public nsISupports {
public:
/**
* Notify the observer that the URL has started to load. This method is
* called only once, at the beginning of a URL load.<BR><BR>
*
* @return The return value is currently ignored. In the future it may be
* used to cancel the URL load..
*/
NS_IMETHOD
OnStartBinding(const char* url, const nsPluginStreamInfo* info) = 0;
/**
* Notify the client that data is available in the input stream. This
* method is called whenver data is written into the input stream by the
* networking library...<BR><BR>
*
* @param aIStream The input stream containing the data. This stream can
* be either a blocking or non-blocking stream.
* @param length The amount of data that was just pushed into the stream.
* @return The return value is currently ignored.
*/
NS_IMETHOD
OnDataAvailable(const char* url, nsIPluginInputStream* input,
PRUint32 offset, PRUint32 length) = 0;
NS_IMETHOD
OnFileAvailable(const char* url, const char* fileName) = 0;
/**
* Notify the observer that the URL has finished loading. This method is
* called once when the networking library has finished processing the
* URL transaction initiatied via the nsINetService::Open(...) call.<BR><BR>
*
* This method is called regardless of whether the URL loaded successfully.<BR><BR>
*
* @param status Status code for the URL load.
* @param msg A text string describing the error.
* @return The return value is currently ignored.
*/
NS_IMETHOD
OnStopBinding(const char* url, nsresult status) = 0;
};
#define NS_IPLUGINSTREAMLISTENER_IID \
{ /* df055770-5448-11d2-8164-006008119d7a */ \
0xdf055770, \
0x5448, \
0x11d2, \
{0x81, 0x64, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIPluginStreamListener_h___ */

View File

@@ -0,0 +1,89 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIPluginStreamPeer_h___
#define nsIPluginStreamPeer_h___
#ifndef NEW_PLUGIN_STREAM_API
#include "nsplugindefs.h"
#include "nsISupports.h"
////////////////////////////////////////////////////////////////////////////////
// Plugin Stream Peer Interface
// A plugin stream peer is passed to a plugin instance's NewStream call in
// order to indicate that a new stream is to be created and be read by the
// plugin instance.
class nsIPluginStreamPeer : public nsISupports {
public:
// (Corresponds to NPStream's url field.)
NS_IMETHOD
GetURL(const char* *result) = 0;
// (Corresponds to NPStream's end field.)
NS_IMETHOD
GetEnd(PRUint32 *result) = 0;
// (Corresponds to NPStream's lastmodified field.)
NS_IMETHOD
GetLastModified(PRUint32 *result) = 0;
// (Corresponds to NPStream's notifyData field.)
NS_IMETHOD
GetNotifyData(void* *result) = 0;
// (Corresponds to NPP_DestroyStream's reason argument.)
NS_IMETHOD
GetReason(nsPluginReason *result) = 0;
// (Corresponds to NPP_NewStream's MIMEType argument.)
NS_IMETHOD
GetMIMEType(nsMIMEType *result) = 0;
};
#define NS_IPLUGINSTREAMPEER_IID \
{ /* 717b1e90-019b-11d2-815b-006008119d7a */ \
0x717b1e90, \
0x019b, \
0x11d2, \
{0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
#endif // !NEW_PLUGIN_STREAM_API
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIPluginStreamPeer_h___ */

View File

@@ -0,0 +1,74 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIPluginStreamPeer2_h___
#define nsIPluginStreamPeer2_h___
#ifndef NEW_PLUGIN_STREAM_API
#include "nsIPluginStreamPeer.h"
////////////////////////////////////////////////////////////////////////////////
// Plugin Stream Peer Interface
// These extensions to nsIPluginStreamPeer are only available in Communicator 5.0.
class nsIPluginStreamPeer2 : public nsIPluginStreamPeer {
public:
NS_IMETHOD
GetContentLength(PRUint32 *result) = 0;
NS_IMETHOD
GetHeaderFieldCount(PRUint32 *result) = 0;
NS_IMETHOD
GetHeaderFieldKey(PRUint32 index, const char* *result) = 0;
NS_IMETHOD
GetHeaderField(PRUint32 index, const char* *result) = 0;
};
#define NS_IPLUGINSTREAMPEER2_IID \
{ /* 77083af0-019b-11d2-815b-006008119d7a */ \
0x77083af0, \
0x019b, \
0x11d2, \
{0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
#endif // !NEW_PLUGIN_STREAM_API
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIPluginStreamPeer2_h___ */

View File

@@ -0,0 +1,82 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIPluginTagInfo_h___
#define nsIPluginTagInfo_h___
#include "nsplugindefs.h"
#include "nsISupports.h"
////////////////////////////////////////////////////////////////////////////////
// Plugin Tag Info Interface
// This interface provides information about the HTML tag on the page.
// Some day this might get superseded by a DOM API.
class nsIPluginTagInfo : public nsISupports {
public:
// QueryInterface on nsIPluginInstancePeer to get this.
// (Corresponds to NPP_New's argc, argn, and argv arguments.)
// Get a ptr to the paired list of attribute names and values,
// returns the length of the array.
//
// Each name or value is a null-terminated string.
NS_IMETHOD
GetAttributes(PRUint16& n, const char*const*& names, const char*const*& values) = 0;
/**
* Gets the value for the named attribute.
*
* @param name - the name of the attribute to find
* @param result - the resulting attribute
* @result - NS_OK if this operation was successful, NS_ERROR_FAILURE if
* this operation failed. result is set to NULL if the attribute is not found
* else to the found value.
*/
NS_IMETHOD
GetAttribute(const char* name, const char* *result) = 0;
};
#define NS_IPLUGINTAGINFO_IID \
{ /* 5f1ec1d0-019b-11d2-815b-006008119d7a */ \
0x5f1ec1d0, \
0x019b, \
0x11d2, \
{0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIPluginTagInfo_h___ */

View File

@@ -0,0 +1,120 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIPluginTagInfo2_h___
#define nsIPluginTagInfo2_h___
#include "nsIPluginTagInfo.h"
////////////////////////////////////////////////////////////////////////////////
// Plugin Tag Info Interface
// These extensions to nsIPluginTagInfo are only available in Communicator 5.0.
enum nsPluginTagType {
nsPluginTagType_Unknown,
nsPluginTagType_Embed,
nsPluginTagType_Object,
nsPluginTagType_Applet
};
class nsIPluginTagInfo2 : public nsIPluginTagInfo {
public:
// QueryInterface on nsIPluginInstancePeer to get this.
// Get the type of the HTML tag that was used ot instantiate this
// plugin. Currently supported tags are EMBED, OBJECT and APPLET.
NS_IMETHOD
GetTagType(nsPluginTagType *result) = 0;
// Get the complete text of the HTML tag that was
// used to instantiate this plugin
NS_IMETHOD
GetTagText(const char* *result) = 0;
// Get a ptr to the paired list of parameter names and values,
// returns the length of the array.
//
// Each name or value is a null-terminated string.
NS_IMETHOD
GetParameters(PRUint16& n, const char*const*& names, const char*const*& values) = 0;
// Get the value for the named parameter. Returns null
// if the parameter was not set.
// @result - NS_OK if this operation was successful, NS_ERROR_FAILURE if
// this operation failed. result is set to NULL if the attribute is not found
// else to the found value.
NS_IMETHOD
GetParameter(const char* name, const char* *result) = 0;
NS_IMETHOD
GetDocumentBase(const char* *result) = 0;
// Return an encoding whose name is specified in:
// http://java.sun.com/products/jdk/1.1/docs/guide/intl/intl.doc.html#25303
NS_IMETHOD
GetDocumentEncoding(const char* *result) = 0;
NS_IMETHOD
GetAlignment(const char* *result) = 0;
NS_IMETHOD
GetWidth(PRUint32 *result) = 0;
NS_IMETHOD
GetHeight(PRUint32 *result) = 0;
NS_IMETHOD
GetBorderVertSpace(PRUint32 *result) = 0;
NS_IMETHOD
GetBorderHorizSpace(PRUint32 *result) = 0;
// Returns a unique id for the current document on which the
// plugin is displayed.
NS_IMETHOD
GetUniqueID(PRUint32 *result) = 0;
};
#define NS_IPLUGINTAGINFO2_IID \
{ /* 6a49c9a0-019b-11d2-815b-006008119d7a */ \
0x6a49c9a0, \
0x019b, \
0x11d2, \
{0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIPluginTagInfo2_h___ */

View File

@@ -0,0 +1,72 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsISeekablePluginStreamPeer_h___
#define nsISeekablePluginStreamPeer_h___
#ifndef NEW_PLUGIN_STREAM_API
#include "nsplugindefs.h"
#include "nsISupports.h"
////////////////////////////////////////////////////////////////////////////////
// Seekable Plugin Stream Peer Interface
// The browser implements this subclass of plugin stream peer if a stream
// is seekable. Plugins can query interface for this type, and call the
// RequestRead method to seek to a particular position in the stream.
class nsISeekablePluginStreamPeer : public nsISupports {
public:
// QueryInterface for this class corresponds to NPP_NewStream's
// seekable argument.
// (Corresponds to NPN_RequestRead.)
NS_IMETHOD
RequestRead(nsByteRange* rangeList) = 0;
};
#define NS_ISEEKABLEPLUGINSTREAMPEER_IID \
{ /* 7e028d20-019b-11d2-815b-006008119d7a */ \
0x7e028d20, \
0x019b, \
0x11d2, \
{0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
#endif // !NEW_PLUGIN_STREAM_API
////////////////////////////////////////////////////////////////////////////////
#endif /* nsISeekablePluginStreamPeer_h___ */

View File

@@ -0,0 +1,70 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this interface fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsIWindowlessPluginInstancePeer_h___
#define nsIWindowlessPluginInstancePeer_h___
#include "nsplugindefs.h"
#include "nsISupports.h"
////////////////////////////////////////////////////////////////////////////////
// Windowless Plugin Instance Peer Interface
class nsIWindowlessPluginInstancePeer : public nsISupports {
public:
// (Corresponds to NPN_InvalidateRect.)
NS_IMETHOD
InvalidateRect(nsPluginRect *invalidRect) = 0;
// (Corresponds to NPN_InvalidateRegion.)
NS_IMETHOD
InvalidateRegion(nsPluginRegion invalidRegion) = 0;
// (Corresponds to NPN_ForceRedraw.)
NS_IMETHOD
ForceRedraw(void) = 0;
};
#define NS_IWINDOWLESSPLUGININSTANCEPEER_IID \
{ /* 57b4e2f0-019b-11d2-815b-006008119d7a */ \
0x57b4e2f0, \
0x019b, \
0x11d2, \
{0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIWindowlessPluginInstancePeer_h___ */

View File

@@ -0,0 +1,264 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>This is the master header file that includes most of the other headers
* you'll need to write a plugin.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* The following diagram depicts the relationships between various objects
* implementing the new plugin interfaces. QueryInterface can be used to switch
* between interfaces in the same box:
*
*
* the plugin (only 1)
* +----------------------+
* | nsIPlugin or |<- - - - - -NSGetFactory()
* | nsILiveConnectPlugin |
* +----------------------+
* |
* |
* | instances (many) streams to receive URL data (many)
* | +-------------------+ +-----------------+
* | | nsIPluginInstance |+ | nsIPluginStream |+
* | | || | ||
* | +-------------------+| +-----------------+|
* | +------|-----------+ +------|---------+
* | | |
* | PLUGIN SIDE |peer |peer
*~~~~|~~~~~~~~~~~~~~~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|~~~~~~~~~~~~~~~~
* | BROWSER SIDE | |
* | v v
* | +---------------------------------+ +----------------------------+
* | | nsIPluginInstancePeer |+ | nsIPluginStreamPeer |+
* | | nsIWindowlessPluginInstancePeer || | nsISeekablePluginStreamPeer||
* | | nsILiveConnectPluginInstancePeer|| | nsIPluginstreamPeer2 ||
* | | nsIPluginTagInfo || +----------------------------+|
* | | nsIPluginTagInfo2 || +---------------------------+
* | +---------------------------------+|
* | +--------------------------------+
* |
* |
* v the browser (only 1)
* +---------------------+
* | nsIPluginManager |
* | nsIPluginManager2 |
* | nsIFileUtilities |
* | nsIPref |
* | nsICacheManager ... |
* +---------------------+
*
*/
#ifndef nsplugins_h___
#define nsplugins_h___
#include "nsRepository.h" // for NSGetFactory
////////////////////////////////////////////////////////////////////////////////
/**
* <B>Interfaces which must be implemented by a plugin</B>
* These interfaces have NPP equivalents in pre-5.0 browsers (see npapi.h).
*/
////////////////////////////////////////////////////////////////////////////////
/**
* NSGetFactory is the main entry point to the plugin's DLL. The plugin manager
* finds this symbol and calls it to create the plugin class. Once the plugin
* object is returned to the plugin manager, instances on the page are created
* by calling nsIPlugin::CreateInstance.
*/
// (Declared in nsRepository.h)
//extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aClass,
// nsIFactory **aFactory);
/**
* A plugin object is used to create new plugin instances. It manages the
* global state of all plugins with the same implementation.
*/
#include "nsIPlugin.h"
/**
* A plugin instance represents a particular activation of a plugin on a page.
*/
#include "nsIPluginInstance.h"
#ifdef NEW_PLUGIN_STREAM_API
/**
* A plugin stream listener ...
*/
#include "nsIPluginStreamListener.h"
#else // !NEW_PLUGIN_STREAM_API
/**
* A plugin stream gets instantiated when a plugin instance receives data from
* the browser.
*/
#include "nsIPluginStream.h"
#endif // !NEW_PLUGIN_STREAM_API
/**
* The nsILiveConnectPlugin interface provides additional operations that a
* plugin must implement if it is to be controlled by JavaScript through
* LiveConnect.
*
* Note that this interface is part of a new JNI-based LiveConnect
* implementation and superceeds that provided prior to Communicator 5.0.
*/
#include "nsILiveConnectPlugin.h"
////////////////////////////////////////////////////////////////////////////////
/**
* <B>Interfaces implemented by the browser:
* These interfaces have NPN equivalents in pre-5.0 browsers (see npapi.h).
*/
////////////////////////////////////////////////////////////////////////////////
/**
* The plugin manager which is the main point of interaction with the browser
* and provides general operations needed by a plugin.
*/
#include "nsIPluginManager.h"
/**
* A plugin instance peer gets created by the browser and associated with each
* plugin instance to represent tag information and other callbacks needed by
* the plugin instance.
*/
#include "nsIPluginInstancePeer.h"
/**
* The nsIPluginTagInfo interface provides information about the html tag
* that was used to instantiate the plugin instance.
*
* To obtain: QueryInterface on nsIPluginInstancePeer
*/
#include "nsIPluginTagInfo.h"
/**
* The nsIWindowlessPluginInstancePeer provides additional operations for
* windowless plugins.
*
* To obtain: QueryInterface on nsIPluginInstancePeer
*/
#include "nsIWindowlessPlugInstPeer.h"
#ifdef NEW_PLUGIN_STREAM_API
/**
*
*/
#include "nsIPluginInputStream.h"
#else // !NEW_PLUGIN_STREAM_API
/**
* A plugin stream peer gets create by the browser and associated with each
* plugin stream to represent stream and URL information, and provides
* other callbacks needed by the plugin stream.
*/
#include "nsIPluginStreamPeer.h"
/**
* The nsISeekablePluginStreamPeer provides additional operations for seekable
* plugin streams.
*
* To obtain: QueryInterface on nsIPluginStreamPeer
*/
#include "nsISeekablePluginStreamPeer.h"
#endif // !NEW_PLUGIN_STREAM_API
////////////////////////////////////////////////////////////////////////////////
/**
* <B>Interfaces implemented by the browser (new for 5.0):
*/
////////////////////////////////////////////////////////////////////////////////
/**
* The nsIPluginManager2 interface provides additional plugin manager features
* only available in Communicator 5.0.
*
* To obtain: QueryInterface on nsIPluginManager
*/
#include "nsIPluginManager2.h"
/**
* The nsIFileUtilities interface provides operations to manage temporary
* files and directories.
*
* To obtain: QueryInterface on nsIPluginManager
*/
#include "nsIFileUtilities.h"
/**
* The nsILiveConnectPluginInstancePeer allows plugins to be manipulated
* by JavaScript, providing basic scriptability.
*
* Note that this interface is part of a new JNI-based LiveConnect
* implementation and superceeds that provided prior to Communicator 5.0.
*
* To obtain: QueryInterface on nsIPluginInstancePeer
*/
#include "nsILiveConnectPlugInstPeer.h"
#ifdef NEW_PLUGIN_STREAM_API
/**
*
*/
#include "nsIPluginInputStream2.h"
#else // !NEW_PLUGIN_STREAM_API
/**
* The nsIPluginStreamPeer2 interface provides additional plugin stream
* peer features only available in Communicator 5.0.
*
* To obtain: QueryInterface on nsIPluginStreamPeer
*/
#include "nsIPluginStreamPeer2.h"
#endif // !NEW_PLUGIN_STREAM_API
/**
* The nsIPluginTagInfo2 interface provides additional html tag information
* only available in Communicator 5.0.
*
* To obtain: QueryInterface on nsIPluginTagInfo
*/
#include "nsIPluginTagInfo2.h"
#include "nsIOutputStream.h"
////////////////////////////////////////////////////////////////////////////////
#endif // nsplugins_h___

View File

@@ -0,0 +1,383 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
/**
* <B>INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API).</B>
*
* <P>This superscedes the old plugin API (npapi.h, npupp.h), and
* eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that
* get linked with the plugin. You will however need to link with the "backward
* adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0
* browsers.
*
* <P>See nsplugin.h for an overview of how this fits with the
* overall plugin architecture.
*/
////////////////////////////////////////////////////////////////////////////////
#ifndef nsplugindefs_h___
#define nsplugindefs_h___
#ifndef prtypes_h___
#include "prtypes.h"
#endif
#ifdef __OS2__
#pragma pack(1)
#endif
#ifdef XP_MAC
# include <Quickdraw.h>
# include <Events.h>
# include <MacWindows.h>
#endif
#if defined(XP_UNIX) && !defined(NO_X11)
# include <X11/Xlib.h>
# include <X11/Xutil.h>
#endif
#ifdef XP_PC
# include <windef.h>
#endif
////////////////////////////////////////////////////////////////////////////////
/* The OS/2 version of Netscape uses RC_DATA to define the
mime types, file extentions, etc that are required.
Use a vertical bar to seperate types, end types with \0.
FileVersion and ProductVersion are 32bit ints, all other
entries are strings the MUST be terminated wwith a \0.
AN EXAMPLE:
RCDATA NS_INFO_ProductVersion { 1,0,0,1,}
RCDATA NS_INFO_MIMEType { "video/x-video|",
"video/x-flick\0" }
RCDATA NS_INFO_FileExtents { "avi|",
"flc\0" }
RCDATA NS_INFO_FileOpenName{ "MMOS2 video player(*.avi)|",
"MMOS2 Flc/Fli player(*.flc)\0" }
RCDATA NS_INFO_FileVersion { 1,0,0,1 }
RCDATA NS_INFO_CompanyName { "Netscape Communications\0" }
RCDATA NS_INFO_FileDescription { "NPAVI32 Extension DLL\0"
RCDATA NS_INFO_InternalName { "NPAVI32\0" )
RCDATA NS_INFO_LegalCopyright { "Copyright Netscape Communications \251 1996\0"
RCDATA NS_INFO_OriginalFilename { "NVAPI32.DLL" }
RCDATA NS_INFO_ProductName { "NPAVI32 Dynamic Link Library\0" }
*/
/* RC_DATA types for version info - required */
#define NS_INFO_ProductVersion 1
#define NS_INFO_MIMEType 2
#define NS_INFO_FileOpenName 3
#define NS_INFO_FileExtents 4
/* RC_DATA types for version info - used if found */
#define NS_INFO_FileDescription 5
#define NS_INFO_ProductName 6
/* RC_DATA types for version info - optional */
#define NS_INFO_CompanyName 7
#define NS_INFO_FileVersion 8
#define NS_INFO_InternalName 9
#define NS_INFO_LegalCopyright 10
#define NS_INFO_OriginalFilename 11
#ifndef RC_INVOKED
////////////////////////////////////////////////////////////////////////////////
// Structures and definitions
#ifdef XP_MAC
#pragma options align=mac68k
#endif
typedef const char* nsMIMEType;
struct nsByteRange {
PRInt32 offset; /* negative offset means from the end */
PRUint32 length;
struct nsByteRange* next;
};
struct nsPluginRect {
PRUint16 top;
PRUint16 left;
PRUint16 bottom;
PRUint16 right;
};
////////////////////////////////////////////////////////////////////////////////
// Unix specific structures and definitions
#ifdef XP_UNIX
#include <stdio.h>
/*
* Callback Structures.
*
* These are used to pass additional platform specific information.
*/
enum nsPluginCallbackType {
nsPluginCallbackType_SetWindow = 1,
nsPluginCallbackType_Print
};
struct nsPluginAnyCallbackStruct {
PRInt32 type;
};
#ifndef NO_X11
struct nsPluginSetWindowCallbackStruct {
PRInt32 type;
Display* display;
Visual* visual;
Colormap colormap;
PRUint32 depth;
};
#else
struct nsPluginSetWindowCallbackStruct {
PRInt32 type;
};
#endif
struct nsPluginPrintCallbackStruct {
PRInt32 type;
FILE* fp;
};
#endif /* XP_UNIX */
////////////////////////////////////////////////////////////////////////////////
// List of variables which should be implmented by the plugin
enum nsPluginVariable {
nsPluginVariable_NameString = 1,
nsPluginVariable_DescriptionString = 2
};
enum nsPluginManagerVariable {
nsPluginManagerVariable_XDisplay = 1,
nsPluginManagerVariable_XtAppContext = 2
};
enum nsPluginInstancePeerVariable {
nsPluginInstancePeerVariable_NetscapeWindow = 3
// nsPluginInstancePeerVariable_JavaClass = 5,
// nsPluginInstancePeerVariable_TimerInterval = 7
};
enum nsPluginInstanceVariable {
nsPluginInstanceVariable_WindowlessBool = 3,
nsPluginInstanceVariable_TransparentBool = 4
};
////////////////////////////////////////////////////////////////////////////////
enum nsPluginMode {
nsPluginMode_Embedded = 1,
nsPluginMode_Full
};
// XXX this can go away now
enum nsPluginStreamType {
nsPluginStreamType_Normal = 1,
nsPluginStreamType_Seek,
nsPluginStreamType_AsFile,
nsPluginStreamType_AsFileOnly
};
/*
* The type of a nsPluginWindow - it specifies the type of the data structure
* returned in the window field.
*/
enum nsPluginWindowType {
nsPluginWindowType_Window = 1,
nsPluginWindowType_Drawable
};
#ifdef XP_MAC
struct nsPluginPort {
CGrafPtr port; /* Grafport */
PRInt32 portx; /* position inside the topmost window */
PRInt32 porty;
};
typedef RgnHandle nsPluginRegion;
typedef WindowRef nsPluginPlatformWindowRef;
#elif defined(XP_PC)
struct nsPluginPort;
typedef HRGN nsPluginRegion;
typedef HWND nsPluginPlatformWindowRef;
#elif defined(XP_UNIX) && !defined(NO_X11)
struct nsPluginPort;
typedef Region nsPluginRegion;
typedef Drawable nsPluginPlatformWindowRef;
#else
struct nsPluginPort;
typedef void* nsPluginRegion;
typedef void* nsPluginPlatformWindowRef;
#endif
struct nsPluginWindow {
nsPluginPort* window; /* Platform specific window handle */
/* OS/2: x - Position of bottom left corner */
/* OS/2: y - relative to visible netscape window */
PRUint32 x; /* Position of top left corner relative */
PRUint32 y; /* to a netscape page. */
PRUint32 width; /* Maximum window size */
PRUint32 height;
nsPluginRect clipRect; /* Clipping rectangle in port coordinates */
/* Used by MAC only. */
#ifdef XP_UNIX
void* ws_info; /* Platform-dependent additonal data */
#endif /* XP_UNIX */
nsPluginWindowType type; /* Is this a window or a drawable? */
};
struct nsPluginFullPrint {
PRBool pluginPrinted; /* Set TRUE if plugin handled fullscreen */
/* printing */
PRBool printOne; /* TRUE if plugin should print one copy */
/* to default printer */
void* platformPrint; /* Platform-specific printing info */
};
struct nsPluginEmbedPrint {
nsPluginWindow window;
void* platformPrint; /* Platform-specific printing info */
};
struct nsPluginPrint {
nsPluginMode mode; /* nsPluginMode_Full or nsPluginMode_Embedded */
union
{
nsPluginFullPrint fullPrint; /* if mode is nsPluginMode_Full */
nsPluginEmbedPrint embedPrint; /* if mode is nsPluginMode_Embedded */
} print;
};
struct nsPluginEvent {
#if defined(XP_MAC)
EventRecord* event;
nsPluginPlatformWindowRef window;
#elif defined(XP_PC)
uint16 event;
uint32 wParam;
uint32 lParam;
#elif defined(XP_OS2)
uint32 event;
uint32 wParam;
uint32 lParam;
#elif defined(XP_UNIX) && !defined(NO_X11)
XEvent event;
#else
void *event;
#endif
};
/*
* Non-standard event types that can be passed to HandleEvent
*/
enum nsPluginEventType {
#ifdef XP_MAC
nsPluginEventType_GetFocusEvent = (osEvt + 16),
nsPluginEventType_LoseFocusEvent = (osEvt + 17),
nsPluginEventType_AdjustCursorEvent = (osEvt + 18),
nsPluginEventType_MenuCommandEvent = (osEvt + 19),
#endif /* XP_MAC */
nsPluginEventType_Idle = 0
};
////////////////////////////////////////////////////////////////////////////////
enum nsPluginReason {
nsPluginReason_Base = 0,
nsPluginReason_Done = 0,
nsPluginReason_NetworkErr,
nsPluginReason_UserBreak,
nsPluginReason_NoReason
};
////////////////////////////////////////////////////////////////////////////////
// Version Numbers for Structs
// These version number are for structures whose fields may evolve over time.
// When fields are added to the end of the struct, the minor version will be
// incremented. When the struct changes in an incompatible way the major version
// will be incremented.
#define nsMajorVersion(v) (((PRInt32)(v) >> 16) & 0xffff)
#define nsMinorVersion(v) ((PRInt32)(v) & 0xffff)
#define nsVersionOK(suppliedV, requiredV) \
(nsMajorVersion(suppliedV) == nsMajorVersion(requiredV) \
&& nsMinorVersion(suppliedV) >= nsMinorVersion(requiredV))
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
// Classes that must be implemented by the plugin DLL:
struct nsIPlugin; // plugin class (MIME-type handler)
class nsILiveConnectPlugin; // subclass of nsIPlugin
class nsIEventHandler; // event handler interface
class nsIPluginInstance; // plugin instance
class nsIPluginStream; // stream to receive data from the browser
// Classes that are implemented by the browser:
class nsIPluginManager; // minimum browser requirements
class nsIFileUtilities; // file utilities (accessible from nsIPluginManager)
class nsIPluginInstancePeer; // parts of nsIPluginInstance implemented by the browser
class nsIWindowlessPluginInstancePeer; // subclass of nsIPluginInstancePeer for windowless plugins
class nsIPluginTagInfo; // describes html tag (accessible from nsIPluginInstancePeer)
class nsILiveConnectPluginInstancePeer; // subclass of nsIPluginInstancePeer
class nsIPluginStreamPeer; // parts of nsIPluginStream implemented by the browser
class nsISeekablePluginStreamPeer; // seekable subclass of nsIPluginStreamPeer
////////////////////////////////////////////////////////////////////////////////
#ifdef XP_MAC
#pragma options align=reset
#endif
#endif /* RC_INVOKED */
#ifdef __OS2__
#pragma pack()
#endif
#endif // nsplugindefs_h___

View File

@@ -0,0 +1,24 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
#
# This is a list of local files which get copied to the mozilla:dist directory
#
nsPluginsCID.h
nsIPluginHost.h
nsIPluginInstanceOwner.h

View File

@@ -0,0 +1,50 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=../../..
include $(DEPTH)/config/config.mk
MODULE=raptor
LIBRARY_NAME=raptorplugin
EXPORTS = \
nsPluginsCID.h \
nsIPluginHost.h \
nsIPluginInstanceOwner.h
CPPSRCS = \
nsPluginHostImpl.cpp \
nsPluginFactory.cpp \
ns4xPlugin.cpp \
ns4xPluginInstance.cpp \
ns4xPluginStream.cpp \
nsPluginInstancePeer.cpp \
nsPluginStreamPeer.cpp \
nsMalloc.cpp \
$(NULL)
REQUIRES = raptor plugin java xpcom netlib libplc21
LCFLAGS =-D_IMPL_NS_PLUGIN
TARGETS = $(LIBRARY)
INCLUDES += -I.
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,57 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
MODULE=raptor
LIBRARY_NAME=raptorplugin
EXPORTS = \
nsPluginsCID.h \
nsIPluginHost.h \
nsIPluginInstanceOwner.h
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
CPPSRCS = \
nsPluginHostImpl.cpp \
nsPluginFactory.cpp \
ns4xPlugin.cpp \
ns4xPluginInstance.cpp \
ns4xPluginStream.cpp \
nsPluginInstancePeer.cpp \
nsPluginStreamPeer.cpp \
nsMalloc.cpp \
$(NULL)
REQUIRES = raptor plugin java xpcom netlib libplc21
LCFLAGS =-D_IMPL_NS_PLUGIN
TARGETS = $(LIBRARY)
INCLUDES += -I$(srcdir)/
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,80 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..
IGNORE_MANIFEST=1
EXPORTS = \
nsPluginsCID.h \
nsIPluginHost.h \
nsIPluginInstanceOwner.h
MAKE_OBJ_TYPE = DLL
DLLNAME = raptorplugin
DLL=.\$(OBJDIR)\$(DLLNAME).dll
MISCDEP = $(OURLIBS)
MODULE=raptor
DEFINES =-D_IMPL_NS_PLUGIN -DWIN32_LEAN_AND_MEAN
OBJS = \
.\$(OBJDIR)\nsPluginHostImpl.obj \
.\$(OBJDIR)\nsPluginFactory.obj \
.\$(OBJDIR)\ns4xPlugin.obj \
.\$(OBJDIR)\ns4xPluginInstance.obj \
.\$(OBJDIR)\ns4xPluginStream.obj \
.\$(OBJDIR)\nsPluginInstancePeer.obj \
.\$(OBJDIR)\nsPluginStreamPeer.obj \
.\$(OBJDIR)\nsMalloc.obj \
$(NULL)
LINCS= \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\plugin \
-I$(PUBLIC)\java \
-I$(PUBLIC)\netlib \
$(NULL)
LCFLAGS = \
$(LCFLAGS) \
-D_IMPL_NS_PLUGIN \
$(NULL)
OURLIBS= \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\raptorbase.lib \
$(DIST)\lib\libplc21.lib \
$(DIST)\lib\netlib.lib \
$(LIBNSPR)
LLIBS= \
$(OURLIBS) \
version.lib
include <$(DEPTH)\config\rules.mak>
it:
echo $(LLIBS)
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin
clobber::
rm -f $(DIST)\bin\$(DLLNAME).dll

View File

@@ -0,0 +1,780 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
// TODO: Implement Java callbacks
#include "xp_core.h"
#include "nsplugin.h"
#include "ns4xPlugin.h"
#include "nsIPluginStream.h"
#include "ns4xPluginInstance.h"
////////////////////////////////////////////////////////////////////////
NPNetscapeFuncs ns4xPlugin::CALLBACKS;
nsIPluginManager * ns4xPlugin::mPluginManager;
nsIMalloc * ns4xPlugin::mMalloc;
void
ns4xPlugin::CheckClassInitialized(void)
{
static PRBool initialized = FALSE;
if (initialized)
return;
mPluginManager = nsnull;
mMalloc = nsnull;
// XXX It'd be nice to make this const and initialize it
// statically...
CALLBACKS.size = sizeof(CALLBACKS);
CALLBACKS.version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
CALLBACKS.geturl = NewNPN_GetURLProc(_geturl);
CALLBACKS.posturl = NewNPN_PostURLProc(_posturl);
CALLBACKS.requestread = NewNPN_RequestReadProc(_requestread);
CALLBACKS.newstream = NewNPN_NewStreamProc(_newstream);
CALLBACKS.write = NewNPN_WriteProc(_write);
CALLBACKS.destroystream = NewNPN_DestroyStreamProc(_destroystream);
CALLBACKS.status = NewNPN_StatusProc(_status);
CALLBACKS.uagent = NewNPN_UserAgentProc(_useragent);
CALLBACKS.memalloc = NewNPN_MemAllocProc(_memalloc);
CALLBACKS.memfree = NewNPN_MemFreeProc(_memfree);
CALLBACKS.memflush = NewNPN_MemFlushProc(_memflush);
CALLBACKS.reloadplugins = NewNPN_ReloadPluginsProc(_reloadplugins);
CALLBACKS.getJavaEnv = NewNPN_GetJavaEnvProc(_getJavaEnv);
// CALLBACKS.getJavaPeer = NewNPN_GetJavaPeerProc(_getJavaPeer);
CALLBACKS.geturlnotify = NewNPN_GetURLNotifyProc(_geturlnotify);
CALLBACKS.posturlnotify = NewNPN_PostURLNotifyProc(_posturlnotify);
CALLBACKS.getvalue = NewNPN_GetValueProc(_getvalue);
CALLBACKS.setvalue = NewNPN_SetValueProc(_setvalue);
CALLBACKS.invalidaterect = NewNPN_InvalidateRectProc(_invalidaterect);
CALLBACKS.invalidateregion = NewNPN_InvalidateRegionProc(_invalidateregion);
CALLBACKS.forceredraw = NewNPN_ForceRedrawProc(_forceredraw);
initialized = TRUE;
};
////////////////////////////////////////////////////////////////////////
ns4xPlugin::ns4xPlugin(NPPluginFuncs* callbacks, NP_PLUGINSHUTDOWN aShutdown)
{
NS_INIT_REFCNT();
memcpy((void*) &fCallbacks, (void*) callbacks, sizeof(fCallbacks));
fShutdownEntry = aShutdown;
}
ns4xPlugin::~ns4xPlugin(void)
{
}
////////////////////////////////////////////////////////////////////////
// nsISupports stuff
NS_IMPL_ADDREF(ns4xPlugin);
NS_IMPL_RELEASE(ns4xPlugin);
static NS_DEFINE_IID(kILiveConnectPluginIID, NS_ILIVECONNECTPLUGIN_IID);
static NS_DEFINE_IID(kIPluginIID, NS_IPLUGIN_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIWindowlessPluginInstancePeerIID, NS_IWINDOWLESSPLUGININSTANCEPEER_IID);
static NS_DEFINE_IID(kISeekablePluginStreamPeerIID, NS_ISEEKABLEPLUGINSTREAMPEER_IID);
nsresult
ns4xPlugin::QueryInterface(const nsIID& iid, void** instance)
{
if (instance == NULL)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIPluginIID))
{
*instance = (void *)(nsIPlugin *)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kILiveConnectPluginIID))
{
// Check the 4.x plugin callbacks to see if it supports
// LiveConnect...
if (fCallbacks.javaClass == NULL)
return NS_NOINTERFACE;
*instance = (void *)(nsILiveConnectPlugin *)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kISupportsIID))
{
*instance = (void *)(nsISupports *)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////
// Static factory method.
//
nsresult
ns4xPlugin::CreatePlugin(PRLibrary *library,
nsIPlugin **result)
{
CheckClassInitialized();
NP_GETENTRYPOINTS pfnGetEntryPoints =
(NP_GETENTRYPOINTS)PR_FindSymbol(library, "NP_GetEntryPoints");
if (pfnGetEntryPoints == NULL)
return NS_ERROR_FAILURE;
NPPluginFuncs callbacks;
memset((void*) &callbacks, 0, sizeof(callbacks));
callbacks.size = sizeof(callbacks);
if (pfnGetEntryPoints(&callbacks) != NS_OK)
return NS_ERROR_FAILURE; // XXX
#ifdef XP_WIN // XXX This is really XP, but we need to figure out how to do HIBYTE()
if (HIBYTE(callbacks.version) < NP_VERSION_MAJOR)
return NS_ERROR_FAILURE;
#endif
NP_PLUGINSHUTDOWN pfnShutdown =
(NP_PLUGINSHUTDOWN)PR_FindSymbol(library, "NP_Shutdown");
// the NP_Initialize entry point was misnamed as NP_PluginInit,
// early in plugin project development. Its correct name is
// documented now, and new developers expect it to work. However,
// I don't want to break the plugins already in the field, so
// we'll accept either name
NP_PLUGININIT pfnInitialize =
(NP_PLUGININIT)PR_FindSymbol(library, "NP_Initialize");
if (!pfnInitialize) {
pfnInitialize =
(NP_PLUGININIT)PR_FindSymbol(library, "NP_PluginInit");
}
if (pfnInitialize == NULL)
return NS_ERROR_UNEXPECTED; // XXX Right error?
if (pfnInitialize(&ns4xPlugin::CALLBACKS) != NS_OK)
return NS_ERROR_UNEXPECTED; // XXX shoudl convert the 4.x error...
*result = new ns4xPlugin(&callbacks, pfnShutdown);
NS_ADDREF(*result);
if (*result == NULL)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
nsresult ns4xPlugin :: CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
if (aResult == NULL) {
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
nsISupports *inst;
inst = nsnull;
inst = (nsISupports *)(nsIPluginInstance *)new ns4xPluginInstance(&fCallbacks);
if (inst == NULL) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult res = inst->QueryInterface(aIID, aResult);
if (res != NS_OK) {
// We didn't get the right interface, so clean up
delete inst;
}
return res;
}
nsresult ns4xPlugin :: LockFactory(PRBool aLock)
{
// Not implemented in simplest case.
return NS_OK;
}
static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID);
static NS_DEFINE_IID(kIMallocIID, NS_IMALLOC_IID);
nsresult
ns4xPlugin::Initialize(nsISupports* browserInterfaces)
{
nsresult rv = NS_OK;
if (nsnull == mPluginManager)
rv = browserInterfaces->QueryInterface(kIPluginManagerIID, (void **)&mPluginManager);
if (nsnull == mMalloc)
rv = browserInterfaces->QueryInterface(kIMallocIID, (void **)&mMalloc);
return rv;
}
nsresult
ns4xPlugin::Shutdown(void)
{
if (nsnull != fShutdownEntry)
{
#ifdef NS_DEBUG
printf("shutting down plugin %08x\n", this);
#endif
fShutdownEntry();
fShutdownEntry = nsnull;
}
NS_IF_RELEASE(mPluginManager);
NS_IF_RELEASE(mMalloc);
return NS_OK;
}
nsresult
ns4xPlugin::GetMIMEDescription(const char* *resultingDesc)
{
printf("plugin getmimedescription called\n");
*resultingDesc = "";
return NS_OK; // XXX make a callback, etc.
}
nsresult
ns4xPlugin::GetValue(nsPluginVariable variable, void *value)
{
printf("plugin getvalue %d called\n", variable);
return NS_OK;
}
nsresult
ns4xPlugin::GetJavaClass(jclass *resultingClass)
{
*resultingClass = (jclass)fCallbacks.javaClass;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
//
// Static callbacks that get routed back through the new C++ API
//
nsresult NP_EXPORT
ns4xPlugin::_geturl(NPP npp, const char* relativeURL, const char* target)
{
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
NS_ASSERTION(mPluginManager != NULL, "null manager");
if (inst == NULL)
return NS_ERROR_UNEXPECTED; // XXX
return mPluginManager->GetURL(inst, relativeURL, target);
}
nsresult NP_EXPORT
ns4xPlugin::_geturlnotify(NPP npp, const char* relativeURL, const char* target,
void* notifyData)
{
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
NS_ASSERTION(mPluginManager != NULL, "null manager");
if (inst == NULL)
return NS_ERROR_UNEXPECTED; // XXX
return mPluginManager->GetURL(inst, relativeURL, target,
notifyData);
}
nsresult NP_EXPORT
ns4xPlugin::_posturlnotify(NPP npp, const char* relativeURL, const char *target,
uint32 len, const char *buf, NPBool file,
void* notifyData)
{
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
NS_ASSERTION(mPluginManager != NULL, "null manager");
if (inst == NULL)
return NS_ERROR_UNEXPECTED; // XXX
return mPluginManager->PostURL(inst, relativeURL, target,
len, buf, file, notifyData);
}
nsresult NP_EXPORT
ns4xPlugin::_posturl(NPP npp, const char* relativeURL, const char *target, uint32 len,
const char *buf, NPBool file)
{
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
NS_ASSERTION(mPluginManager != NULL, "null manager");
if (inst == NULL)
return NS_ERROR_UNEXPECTED; // XXX
return mPluginManager->PostURL(inst, relativeURL, target,
len, buf, file);
}
////////////////////////////////////////////////////////////////////////
/**
* A little helper class used to wrap up plugin manager streams (that is,
* streams from the plugin to the browser).
*/
class ns4xStreamWrapper
{
protected:
nsIOutputStream *fStream;
NPStream fNPStream;
public:
ns4xStreamWrapper(nsIOutputStream* stream);
~ns4xStreamWrapper();
nsIOutputStream*
GetStream(void);
NPStream*
GetNPStream(void) {
return &fNPStream;
};
};
ns4xStreamWrapper::ns4xStreamWrapper(nsIOutputStream* stream)
: fStream(stream)
{
NS_ASSERTION(stream != NULL, "bad stream");
NS_ADDREF(fStream);
memset(&fNPStream, 0, sizeof(fNPStream));
fNPStream.ndata = (void*) this;
}
ns4xStreamWrapper::~ns4xStreamWrapper(void)
{
NS_IF_RELEASE(fStream);
}
nsIOutputStream*
ns4xStreamWrapper::GetStream(void)
{
NS_IF_ADDREF(fStream);
return fStream;
}
////////////////////////////////////////////////////////////////////////
nsresult NP_EXPORT
ns4xPlugin::_newstream(NPP npp, NPMIMEType type, const char* window, NPStream* *result)
{
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
if (inst == NULL)
return NS_ERROR_UNEXPECTED; // XXX
nsresult error;
nsIOutputStream* stream;
nsIPluginInstancePeer *peer;
if (NS_OK == inst->GetPeer(&peer))
{
if ((error = peer->NewStream((const char*) type, window, &stream)) != NS_OK)
{
NS_RELEASE(peer);
return error;
}
ns4xStreamWrapper* wrapper = new ns4xStreamWrapper(stream);
if (wrapper == NULL)
{
NS_RELEASE(peer);
NS_RELEASE(stream);
return NS_ERROR_OUT_OF_MEMORY;
}
(*result) = wrapper->GetNPStream();
NS_RELEASE(peer);
return error;
}
else
return NS_ERROR_UNEXPECTED;
}
int32 NP_EXPORT
ns4xPlugin::_write(NPP npp, NPStream *pstream, int32 len, void *buffer)
{
ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) npp->ndata;
NS_ASSERTION(wrapper != NULL, "null wrapper");
if (wrapper == NULL)
return 0;
nsIOutputStream* stream = wrapper->GetStream();
PRInt32 count = 0;
nsresult rv = stream->Write((char *)buffer, 0, len, &count);
NS_RELEASE(stream);
return count;
}
nsresult NP_EXPORT
ns4xPlugin::_destroystream(NPP npp, NPStream *pstream, NPError reason)
{
ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) npp->ndata;
NS_ASSERTION(wrapper != NULL, "null wrapper");
if (wrapper == NULL)
return 0;
// This will release the wrapped nsIOutputStream.
delete wrapper;
return NS_OK;
}
void NP_EXPORT
ns4xPlugin::_status(NPP npp, const char *message)
{
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
if (inst == NULL)
return;
nsIPluginInstancePeer *peer;
if (NS_OK == inst->GetPeer(&peer))
{
peer->ShowStatus(message);
NS_RELEASE(peer);
}
}
void NP_EXPORT
ns4xPlugin::_memfree (void *ptr)
{
mMalloc->Free(ptr);
}
uint32 NP_EXPORT
ns4xPlugin::_memflush(uint32 size)
{
mMalloc->HeapMinimize();
return 0;
}
void NP_EXPORT
ns4xPlugin::_reloadplugins(NPBool reloadPages)
{
mPluginManager->ReloadPlugins(reloadPages);
}
void NP_EXPORT
ns4xPlugin::_invalidaterect(NPP npp, NPRect *invalidRect)
{
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
if (inst == NULL)
return;
nsIPluginInstancePeer *peer;
nsIWindowlessPluginInstancePeer *wpeer;
if (NS_OK == inst->GetPeer(&peer))
{
if (NS_OK == peer->QueryInterface(kIWindowlessPluginInstancePeerIID, (void **)&wpeer))
{
// XXX nsRect & NPRect are structurally equivalent
wpeer->InvalidateRect((nsPluginRect *)invalidRect);
NS_RELEASE(wpeer);
}
NS_RELEASE(peer);
}
}
void NP_EXPORT
ns4xPlugin::_invalidateregion(NPP npp, NPRegion invalidRegion)
{
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
if (inst == NULL)
return;
nsIPluginInstancePeer *peer;
nsIWindowlessPluginInstancePeer *wpeer;
if (NS_OK == inst->GetPeer(&peer))
{
if (NS_OK == peer->QueryInterface(kIWindowlessPluginInstancePeerIID, (void **)&wpeer))
{
// XXX nsRegion & NPRegion are typedef'd to the same thing
wpeer->InvalidateRegion((nsPluginRegion)invalidRegion);
NS_RELEASE(wpeer);
}
NS_RELEASE(peer);
}
}
void NP_EXPORT
ns4xPlugin::_forceredraw(NPP npp)
{
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
if (inst == NULL)
return;
nsIPluginInstancePeer *peer;
nsIWindowlessPluginInstancePeer *wpeer;
if (NS_OK == inst->GetPeer(&peer))
{
if (NS_OK == peer->QueryInterface(kIWindowlessPluginInstancePeerIID, (void **)&wpeer))
{
wpeer->ForceRedraw();
NS_RELEASE(wpeer);
}
NS_RELEASE(peer);
}
}
nsresult NP_EXPORT
ns4xPlugin::_getvalue(NPP npp, NPNVariable variable, void *result)
{
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
if (inst == NULL)
return NS_ERROR_FAILURE; // XXX
nsIPluginInstancePeer *peer;
if (NS_OK == inst->GetPeer(&peer))
{
nsresult rv;
// XXX Note that for backwards compatibility, the old NPNVariables
// map correctly to NPPluginManagerVariables.
rv = peer->GetValue((nsPluginInstancePeerVariable)variable, result);
NS_RELEASE(peer);
return rv;
}
else
return NS_ERROR_UNEXPECTED;
}
nsresult NP_EXPORT
ns4xPlugin::_setvalue(NPP npp, NPPVariable variable, void *result)
{
ns4xPluginInstance *inst = (ns4xPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
if (inst == NULL)
return NS_ERROR_FAILURE; // XXX
switch (variable)
{
case NPPVpluginWindowBool:
return inst->SetWindowless(*((NPBool *)result));
case NPPVpluginTransparentBool:
return inst->SetTransparent(*((NPBool *)result));
default:
return NS_OK;
}
#if 0
nsIPluginInstancePeer *peer;
if (NS_OK == inst->GetPeer(&peer))
{
nsresult rv;
// XXX Note that for backwards compatibility, the old NPPVariables
// map correctly to NPPluginVariables.
rv = peer->SetValue((nsPluginInstancePeerVariable)variable, result);
NS_RELEASE(peer);
return rv;
}
else
return NS_ERROR_UNEXPECTED;
#endif
}
nsresult NP_EXPORT
ns4xPlugin::_requestread(NPStream *pstream, NPByteRange *rangeList)
{
nsIPluginStreamPeer* streamPeer = (nsIPluginStreamPeer*) pstream->ndata;
NS_ASSERTION(streamPeer != NULL, "null streampeer");
if (streamPeer == NULL)
return NS_ERROR_FAILURE; // XXX
nsISeekablePluginStreamPeer* seekablePeer = NULL;
if (streamPeer->QueryInterface(kISeekablePluginStreamPeerIID,
(void**)seekablePeer) == NS_OK)
{
nsresult error;
// XXX nsByteRange & NPByteRange are structurally equivalent.
error = seekablePeer->RequestRead((nsByteRange *)rangeList);
NS_RELEASE(seekablePeer);
return error;
}
return NS_ERROR_UNEXPECTED;
}
////////////////////////////////////////////////////////////////////////
//
// On 68K Mac (XXX still supported?), we need to make sure that the
// pointers are in D0 for the following functions that return pointers.
//
#if defined(XP_MAC) && !defined(powerc)
#pragma pointers_in_D0
#endif
JRIEnv* NP_EXPORT
ns4xPlugin::_getJavaEnv(void)
{
return NULL;
}
const char * NP_EXPORT
ns4xPlugin::_useragent(NPP npp)
{
NS_ASSERTION(mPluginManager != NULL, "null pluginmanager");
if (mPluginManager == NULL)
return NULL;
char *retstr;
mPluginManager->UserAgent((const char **)&retstr);
return retstr;
}
void * NP_EXPORT
ns4xPlugin::_memalloc (uint32 size)
{
return mMalloc->Alloc(size);
}
#if 0
#ifdef JAVA
java_lang_Class* NP_EXPORT
ns4xPlugin::_getJavaClass(void* handle)
{
// Is this just a generic call into the Java VM?
return NULL;
}
#endif
jref NP_EXPORT
ns4xPlugin::_getJavaPeer(NPP npp)
{
NPIPluginInstancePeer* peer = (NPIPluginInstancePeer*) npp->ndata;
PR_ASSERT(peer != NULL);
if (peer == NULL)
return NULL;
static NS_DEFINE_IID(kILiveConnectPluginInstancePeerIID,
NP_ILIVECONNECTPLUGININSTANCEPEER_IID);
NPILiveConnectPluginInstancePeer* lcPeer = NULL;
if (peer->QueryInterface(kILiveConnectPluginInstancePeerIID,
(void**) &lcPeer) == NS_OK) {
jobject result = lcPeer->GetJavaPeer();
lcPeer->Release();
return result;
}
return NULL;
}
#endif
#if defined(XP_MAC) && !defined(powerc)
#pragma pointers_in_A0
#endif
//
////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,233 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef ns4xPlugin_h__
#define ns4xPlugin_h__
#include "nsplugin.h"
#include "prlink.h" // for PRLibrary
#include "npupp.h"
#include "nsIMalloc.h"
////////////////////////////////////////////////////////////////////////
/*
* Use this macro before each exported function
* (between the return address and the function
* itself), to ensure that the function has the
* right calling conventions on Win16.
*/
#ifdef XP_WIN16
#define NP_EXPORT __export
#elif defined(XP_OS2)
#define NP_EXPORT _System
#else
#define NP_EXPORT
#endif
////////////////////////////////////////////////////////////////////////
// XXX These are defined in platform specific FE directories right now :-/
//BTW: this sucks rocks.
#ifdef XP_WIN
#define PLUGIN_ENTRYPOINT_CALL_TYPE __stdcall
#else
#define PLUGIN_ENTRYPOINT_CALL_TYPE
#endif
typedef NPError (PLUGIN_ENTRYPOINT_CALL_TYPE *NP_GETENTRYPOINTS)(NPPluginFuncs* pCallbacks);
typedef NPError (PLUGIN_ENTRYPOINT_CALL_TYPE *NP_PLUGININIT)(const NPNetscapeFuncs* pCallbacks);
typedef NPError (PLUGIN_ENTRYPOINT_CALL_TYPE *NP_PLUGINSHUTDOWN)();
////////////////////////////////////////////////////////////////////////
/**
* A 5.0 wrapper for a 4.x style plugin.
*/
class ns4xPlugin : public nsILiveConnectPlugin
{
public:
ns4xPlugin(NPPluginFuncs* callbacks, NP_PLUGINSHUTDOWN aShutdown);
~ns4xPlugin(void);
NS_DECL_ISUPPORTS
//nsIFactory interface
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
//nsIPlugin interface
NS_IMETHOD
Initialize(nsISupports* browserInterfaces);
NS_IMETHOD
Shutdown(void);
NS_IMETHOD
GetMIMEDescription(const char* *resultingDesc);
NS_IMETHOD
GetValue(nsPluginVariable variable, void *value);
//nsILiveConnectPlugin interface
NS_IMETHOD
GetJavaClass(jclass *resultingClass);
////////////////////////////////////////////////////////////////////
// ns4xPlugin-specific methods
/**
* A static factory method for constructing 4.x plugins. Constructs
* and initializes an ns4xPlugin object, and returns it in
* <b>result</b>.
*/
static nsresult
CreatePlugin(PRLibrary *library,
nsIPlugin **result);
protected:
/**
* Ensures that the static CALLBACKS is properly initialized
*/
static void CheckClassInitialized(void);
////////////////////////////////////////////////////////////////////////
// Static stub functions that are exported to the 4.x plugin as entry
// points via the CALLBACKS variable.
//
static nsresult NP_EXPORT
_requestread(NPStream *pstream, NPByteRange *rangeList);
static nsresult NP_EXPORT
_geturlnotify(NPP npp, const char* relativeURL, const char* target, void* notifyData);
static nsresult NP_EXPORT
_getvalue(NPP npp, NPNVariable variable, void *r_value);
static nsresult NP_EXPORT
_setvalue(NPP npp, NPPVariable variable, void *r_value);
static nsresult NP_EXPORT
_geturl(NPP npp, const char* relativeURL, const char* target);
static nsresult NP_EXPORT
_posturlnotify(NPP npp, const char* relativeURL, const char *target,
uint32 len, const char *buf, NPBool file, void* notifyData);
static nsresult NP_EXPORT
_posturl(NPP npp, const char* relativeURL, const char *target, uint32 len,
const char *buf, NPBool file);
static nsresult NP_EXPORT
_newstream(NPP npp, NPMIMEType type, const char* window, NPStream** pstream);
static int32 NP_EXPORT
_write(NPP npp, NPStream *pstream, int32 len, void *buffer);
static nsresult NP_EXPORT
_destroystream(NPP npp, NPStream *pstream, NPError reason);
static void NP_EXPORT
_status(NPP npp, const char *message);
#if 0
static void NP_EXPORT
_registerwindow(NPP npp, void* window);
static void NP_EXPORT
_unregisterwindow(NPP npp, void* window);
static int16 NP_EXPORT
_allocateMenuID(NPP npp, NPBool isSubmenu);
#endif
static void NP_EXPORT
_memfree (void *ptr);
static uint32 NP_EXPORT
_memflush(uint32 size);
static void NP_EXPORT
_reloadplugins(NPBool reloadPages);
static void NP_EXPORT
_invalidaterect(NPP npp, NPRect *invalidRect);
static void NP_EXPORT
_invalidateregion(NPP npp, NPRegion invalidRegion);
static void NP_EXPORT
_forceredraw(NPP npp);
////////////////////////////////////////////////////////////////////////
// Anything that returns a pointer needs to be _HERE_ for 68K Mac to
// work.
//
#if defined(XP_MAC) && !defined(powerc)
#pragma pointers_in_D0
#endif
static const char* NP_EXPORT
_useragent(NPP npp);
static void* NP_EXPORT
_memalloc (uint32 size);
static JRIEnv* NP_EXPORT
_getJavaEnv(void);
#if 0
static jref NP_EXPORT
_getJavaPeer(NPP npp);
#endif
#if defined(XP_MAC) && !defined(powerc)
#pragma pointers_in_A0
#endif
/**
* The plugin-side callbacks that the browser calls. One set of
* plugin callbacks for each plugin.
*/
NPPluginFuncs fCallbacks;
NP_PLUGINSHUTDOWN fShutdownEntry;
/**
* The browser-side callbacks that a 4.x-style plugin calls.
*/
static NPNetscapeFuncs CALLBACKS;
static nsIPluginManager *mPluginManager;
static nsIMalloc *mMalloc;
};
#endif // ns4xPlugin_h__

View File

@@ -0,0 +1,296 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "ns4xPluginInstance.h"
#include "ns4xPluginStream.h"
#include "prlog.h"
////////////////////////////////////////////////////////////////////////
ns4xPluginInstance :: ns4xPluginInstance(NPPluginFuncs* callbacks)
: fCallbacks(callbacks)
{
NS_INIT_REFCNT();
NS_ASSERTION(fCallbacks != NULL, "null callbacks");
// Initialize the NPP structure.
fNPP.pdata = NULL;
fNPP.ndata = this;
fPeer = nsnull;
mWindowless = PR_FALSE;
mTransparent = PR_FALSE;
}
ns4xPluginInstance :: ~ns4xPluginInstance(void)
{
NS_RELEASE(fPeer);
}
////////////////////////////////////////////////////////////////////////
NS_IMPL_ADDREF(ns4xPluginInstance);
NS_IMPL_RELEASE(ns4xPluginInstance);
static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID);
static NS_DEFINE_IID(kIEventHandlerIID, NS_IEVENTHANDLER_IID);
static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
NS_IMETHODIMP ns4xPluginInstance :: QueryInterface(const nsIID& iid, void** instance)
{
if (instance == NULL)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIPluginInstanceIID))
{
*instance = (void *)(nsIPluginInstance *)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kIEventHandlerIID))
{
*instance = (void *)(nsIEventHandler *)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kISupportsIID))
{
*instance = (void *)(nsISupports *)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP ns4xPluginInstance :: Initialize(nsIPluginInstancePeer* peer)
{
PRUint16 count;
const char* const* names;
const char* const* values;
NS_ASSERTION(peer != NULL, "null peer");
fPeer = peer;
NS_ADDREF(fPeer);
nsresult error;
nsIPluginTagInfo *taginfo;
error = fPeer->QueryInterface(kIPluginTagInfoIID, (void **)&taginfo);
if (NS_OK == error)
{
if ((error = taginfo->GetAttributes(count, names, values)) != NS_OK)
return error;
if (fCallbacks->newp == NULL)
return NS_ERROR_FAILURE; // XXX right error?
// XXX Note that the NPPluginType_* enums were crafted to be
// backward compatible...
nsPluginMode mode;
nsMIMEType mimetype;
fPeer->GetMode(&mode);
fPeer->GetMIMEType(&mimetype);
error = (nsresult)
CallNPP_NewProc(fCallbacks->newp,
(char *)mimetype,
&fNPP,
(PRUint16)mode,
count,
(char**)names,
(char**)values,
NULL); // saved data
NS_RELEASE(taginfo);
}
return error;
}
NS_IMETHODIMP ns4xPluginInstance :: GetPeer(nsIPluginInstancePeer* *resultingPeer)
{
NS_ADDREF(fPeer);
*resultingPeer = fPeer;
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::Start(void)
{
// XXX At some point, we maybe should implement start and stop to
// load/unload the 4.x plugin, just in case there are some plugins
// that rely on that behavior...
printf("instance start called\n");
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::Stop(void)
{
printf("instance stop called\n");
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::Destroy(void)
{
nsresult error;
printf("instance destroy called\n");
if (fCallbacks->destroy == NULL)
return NS_ERROR_FAILURE; // XXX right error?
NPSavedData *sdata;
error = (nsresult)CallNPP_DestroyProc(fCallbacks->destroy,
&fNPP, &sdata); // saved data
return error;
}
NS_IMETHODIMP ns4xPluginInstance::SetWindow(nsPluginWindow* window)
{
// XXX 4.x plugins don't want a SetWindow(NULL).
if (window == NULL)
return NS_OK;
nsresult error = NS_OK;
if (fCallbacks->setwindow)
{
// XXX Turns out that NPPluginWindow and NPWindow are structurally
// identical (on purpose!), so there's no need to make a copy.
error = (nsresult) CallNPP_SetWindowProc(fCallbacks->setwindow,
&fNPP,
(NPWindow*) window);
// XXX In the old code, we'd just ignore any errors coming
// back from the plugin's SetWindow(). Is this the correct
// behavior?!?
if (error != NS_OK)
printf("error in setwindow %d\n", error);
}
return error;
}
NS_IMETHODIMP ns4xPluginInstance::NewStream(nsIPluginStreamPeer* peer, nsIPluginStream* *result)
{
(*result) = NULL;
ns4xPluginStream* stream = new ns4xPluginStream();
if (stream == NULL)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(stream);
nsresult error;
// does it need the peer?
if ((error = stream->Initialize(this, peer)) != NS_OK)
{
NS_RELEASE(stream);
return error;
}
(*result) = stream;
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::Print(nsPluginPrint* platformPrint)
{
printf("instance print called\n");
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::HandleEvent(nsPluginEvent* event, PRBool* handled)
{
printf("instance handleevent called\n");
*handled = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::URLNotify(const char* url, const char* target,
nsPluginReason reason, void* notifyData)
{
if (fCallbacks->urlnotify != NULL)
{
CallNPP_URLNotifyProc(fCallbacks->urlnotify,
&fNPP,
url,
reason,
notifyData);
}
return NS_OK; //XXX this seems bad...
}
NS_IMETHODIMP ns4xPluginInstance :: GetValue(nsPluginInstanceVariable variable, void *value)
{
nsresult rv = NS_OK;
switch (variable)
{
case nsPluginInstanceVariable_WindowlessBool:
*(PRBool *)value = mWindowless;
break;
case nsPluginInstanceVariable_TransparentBool:
*(PRBool *)value = mTransparent;
break;
default:
rv = NS_ERROR_FAILURE; //XXX this is bad
}
return rv;
}
NS_IMETHODIMP ns4xPluginInstance :: SetWindowless(PRBool aWindowless)
{
mWindowless = aWindowless;
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance :: SetTransparent(PRBool aTransparent)
{
mTransparent = aTransparent;
return NS_OK;
}

View File

@@ -0,0 +1,145 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef ns4xPluginInstance_h__
#define ns4xPluginInstance_h__
#define _UINT32
#define _INT32
#include "nsplugin.h"
#include "npupp.h"
#include "jri.h"
////////////////////////////////////////////////////////////////////////
class ns4xPluginInstance : public nsIPluginInstance
{
public:
/**
* Construct a new 4.x plugin instance with the specified peer
* and callbacks.
*/
ns4xPluginInstance(NPPluginFuncs* callbacks);
// Use Release() to destroy this
~ns4xPluginInstance(void);
NS_DECL_ISUPPORTS
////////////////////////////////////////////////////////////////////////
// nsIPluginInstance methods
/**
* Actually initialize the plugin instance. This calls the 4.x <b>newp</b>
* callback, and may return an error (which is why it is distinct from the
* constructor.) If an error is returned, the caller should <i>not</i>
* continue to use the <b>ns4xPluginInstance</b> object.
*/
NS_METHOD
Initialize(nsIPluginInstancePeer* peer);
NS_IMETHOD
GetPeer(nsIPluginInstancePeer* *resultingPeer);
NS_IMETHOD
Start(void);
NS_IMETHOD
Stop(void);
NS_IMETHOD
Destroy(void);
NS_IMETHOD
SetWindow(nsPluginWindow* window);
NS_IMETHOD
NewStream(nsIPluginStreamPeer* peer, nsIPluginStream* *result);
NS_IMETHOD
Print(nsPluginPrint* platformPrint);
NS_IMETHOD
HandleEvent(nsPluginEvent* event, PRBool* handled);
NS_IMETHOD
URLNotify(const char* url, const char* target,
nsPluginReason reason, void* notifyData);
NS_IMETHOD
GetValue(nsPluginInstanceVariable variable, void *value);
////////////////////////////////////////////////////////////////////////
// ns4xPluginInstance-specific methods
/**
* Return the 4.x-style interface object.
*/
NS_IMETHOD
GetNPP(NPP * aNPP) {
*aNPP = &fNPP;
return NS_OK;
};
/**
* Return the callbacks for the plugin instance.
*/
NS_IMETHOD
GetCallbacks(const NPPluginFuncs ** aCallbacks) {
*aCallbacks = fCallbacks;
return NS_OK;
};
NS_IMETHOD
SetWindowless(PRBool aWindowless);
NS_IMETHOD
SetTransparent(PRBool aTransparent);
protected:
/**
* The plugin instance peer for this instance.
*/
nsIPluginInstancePeer* fPeer;
/**
* A pointer to the plugin's callback functions. This information
* is actually stored in the plugin class (<b>nsPluginClass</b>),
* and is common for all plugins of the class.
*/
NPPluginFuncs* fCallbacks;
/**
* The 4.x-style structure used to communicate between the plugin
* instance and the browser.
*/
NPP_t fNPP;
//these are used to store the windowless properties
//which the browser will later query
PRBool mWindowless;
PRBool mTransparent;
};
#endif // ns4xPluginInstance_h__

View File

@@ -0,0 +1,262 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "ns4xPluginStream.h"
#include "prlog.h" // for PR_ASSERT
////////////////////////////////////////////////////////////////////////
ns4xPluginStream::ns4xPluginStream(void)
: fStreamType(nsPluginStreamType_Normal), fSeekable(PR_FALSE), fPosition(0)
{
NS_INIT_REFCNT();
fPeer = nsnull;
fInstance = nsnull;
// Initialize the 4.x interface structure
memset(&fNPStream, 0, sizeof(fNPStream));
}
ns4xPluginStream::~ns4xPluginStream(void)
{
const NPPluginFuncs *callbacks;
NPP npp;
nsPluginReason reason;
fInstance->GetCallbacks(&callbacks);
fInstance->GetNPP(&npp);
fPeer->GetReason(&reason);
if (callbacks->destroystream != NULL)
{
CallNPP_DestroyStreamProc(callbacks->destroystream,
npp,
&fNPStream,
reason);
}
NS_IF_RELEASE(fPeer);
NS_IF_RELEASE(fInstance);
}
////////////////////////////////////////////////////////////////////////
NS_IMPL_ADDREF(ns4xPluginStream);
NS_IMPL_RELEASE(ns4xPluginStream);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIPluginStreamIID, NS_IPLUGINSTREAM_IID);
static NS_DEFINE_IID(kISeekablePluginStreamPeerIID, NS_ISEEKABLEPLUGINSTREAMPEER_IID);
NS_IMETHODIMP ns4xPluginStream::QueryInterface(const nsIID& iid, void** instance)
{
if (instance == NULL)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIPluginStreamIID))
{
*instance = (void *)(nsIPluginStream *)this;
AddRef();
return NS_OK;
}
else if (iid.Equals(kISupportsIID))
{
*instance = (void *)(nsISupports *)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP ns4xPluginStream::Initialize(ns4xPluginInstance* instance,
nsIPluginStreamPeer* peer)
{
fInstance = instance;
fPeer = peer;
NS_ASSERTION(fInstance != NULL, "null instance");
NS_ADDREF(fInstance);
NS_ASSERTION(fPeer != NULL, "null peer");
NS_ADDREF(fPeer);
const char *url;
PRUint32 length, modified;
fPeer->GetURL(&url);
fPeer->GetEnd(&length);
fPeer->GetLastModified(&modified);
fNPStream.ndata = (void*) fPeer;
fNPStream.url = url;
fNPStream.end = length;
fNPStream.lastmodified = modified;
// Are we seekable?
nsISupports* seekablePeer;
if (fPeer->QueryInterface(kISeekablePluginStreamPeerIID,
(void**) &seekablePeer) == NS_OK)
{
fSeekable = TRUE;
NS_RELEASE(seekablePeer);
}
const NPPluginFuncs *callbacks;
NPP npp;
nsMIMEType mimetype;
fInstance->GetCallbacks(&callbacks);
fInstance->GetNPP(&npp);
fPeer->GetMIMEType(&mimetype);
if (callbacks->newstream == NULL)
return NS_ERROR_FAILURE;
PRUint16 streamType = (PRUint16) fStreamType;
nsresult error
= (nsresult)CallNPP_NewStreamProc(callbacks->newstream,
npp,
(char *)mimetype,
&fNPStream,
fSeekable,
&streamType);
fStreamType = (nsPluginStreamType) streamType;
return error;
}
NS_IMETHODIMP ns4xPluginStream::Write(const char* buffer, PRInt32 offset, PRInt32 len, PRInt32 *aWriteCount)
{
const NPPluginFuncs *callbacks;
NPP npp;
PRInt32 remaining = len;
fInstance->GetCallbacks(&callbacks);
fInstance->GetNPP(&npp);
if (callbacks->write == NULL)
return NS_OK;
while (remaining > 0)
{
PRInt32 numtowrite;
if (callbacks->writeready != NULL)
{
numtowrite = CallNPP_WriteReadyProc(callbacks->writeready,
npp,
&fNPStream);
if (numtowrite > remaining)
numtowrite = remaining;
}
else
numtowrite = len;
*aWriteCount = CallNPP_WriteProc(callbacks->write,
npp,
&fNPStream,
fPosition,
numtowrite,
(void *)buffer);
remaining -= numtowrite;
}
fPosition += len;
return NS_OK; //XXX this seems bad...
}
NS_IMETHODIMP ns4xPluginStream::GetStreamType(nsPluginStreamType *result)
{
*result = fStreamType;
return NS_OK;
}
NS_IMETHODIMP ns4xPluginStream::AsFile(const char* filename)
{
const NPPluginFuncs *callbacks;
NPP npp;
fInstance->GetCallbacks(&callbacks);
fInstance->GetNPP(&npp);
if (callbacks->asfile == NULL)
return NS_OK;
CallNPP_StreamAsFileProc(callbacks->asfile,
npp,
&fNPStream,
filename);
return NS_OK;
}
NS_IMETHODIMP ns4xPluginStream :: Close(void)
{
const NPPluginFuncs *callbacks;
NPP npp;
void *notifydata;
fInstance->GetCallbacks(&callbacks);
fInstance->GetNPP(&npp);
fPeer->GetNotifyData(&notifydata);
nsPluginReason reason;
fPeer->GetReason(&reason);
if (nsnull != notifydata)
{
if (callbacks->urlnotify == NULL)
return NS_OK;
const char *url;
fPeer->GetURL(&url);
CallNPP_URLNotifyProc(callbacks->urlnotify,
npp,
url,
(NPReason)reason,
notifydata);
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////

Some files were not shown because too many files have changed in this diff Show More