Example #1
0
JSArrayBufferView::JSArrayBufferView(VM& vm, ConstructionContext& context)
    : Base(vm, context.structure(), context.butterfly())
    , m_vector(context.vector())
    , m_length(context.length())
    , m_mode(context.mode())
{
}
Example #2
0
JSArrayBufferView::JSArrayBufferView(VM& vm, ConstructionContext& context)
    : Base(vm, context.structure(), context.butterfly())
    , m_length(context.length())
    , m_mode(context.mode())
{
    m_vector.setWithoutBarrier(static_cast<char*>(context.vector()));
}
Example #3
0
void X86Generator::Build(ConstructionContext& Context,
	char *OutBinaryPath, size_t OutBinaryPathSize) const
{
	// some sanity checking
	if (!Context.SourceBaseFileName)
	{
		Context.Result = CR_InvalidFileName;
		Context.ResultArgument = 0;
		return;
	}

	Context.Stage = CS_Compiling;

	char CmdLine[256], SourcePath[256],  ListFile[256];

	// determine a path to the source file
	strncpy(SourcePath, Context.SourceBaseFileName, sizeof(SourcePath) - 5);
	SourcePath[sizeof(SourcePath) - 5] = 0;
	strcat(SourcePath, ".asm");

	// determine a path to the listing file
	strncpy(ListFile, Context.SourceBaseFileName, sizeof(ListFile) - 5);
	ListFile[sizeof(ListFile) - 5] = 0;
	strcat(ListFile, ".lst");

	// build the command line
	snprintf(CmdLine, sizeof(CmdLine) - 1, "nasm -f bin -l %s %s",
		ListFile, SourcePath);
	CmdLine[sizeof(CmdLine) - 1] = 0;

	// spawn the assembler
	if (!RunProcess(CmdLine, Context.ResultArgument,
		Context.StdoutBuffer, Context.StdoutBufferSize,
		Context.StderrBuffer, Context.StderrBufferSize))
	{
		Context.Result = CR_ToolchainSpawningFailure;
		Context.ResultArgument = 0;
		return;
	}

	if (Context.ResultArgument == 0)
	{
		FindCodeOffsets(Context, ListFile);
		if (Context.Result != CR_Success)
			return;

		strncpy(OutBinaryPath, Context.SourceBaseFileName,
			OutBinaryPathSize - 1);
		OutBinaryPath[OutBinaryPathSize] = 0;

		Context.Result = CR_Success;
		Context.Stage = CS_Finished;
	}
	else
		Context.Result = CR_ToolchainError;

	Context.DeleteIntermediateFile(ListFile);
}
Example #4
0
void X86Generator::FindCodeOffsets(ConstructionContext& Context,
	const char *ListFileName) const
{
	size_t FileSize;

	const char *Listing = (const char *)Context.OpenIntermediateFile(
		ListFileName, FAM_Read, &FileSize);

	if (!Listing)
	{
		Context.Result = CR_IntermediateFileAccessFailure;
		Context.ResultArgument = 0;
		return;
	}
	const char *End = Listing + FileSize;

	unsigned int Offset;
	char ProcName[32];
	bool FoundSpawn = false, FoundProcess = false;
	const char *LineEnd, *Line;
	for (Line = Listing;
		Line < End && (!FoundSpawn || !FoundProcess);
		Line = LineEnd + 1)
	{
		LineEnd = Line;
		while (LineEnd < End && *LineEnd != '\n')
			++LineEnd;
		const int Matches = sscanf(Line,
			"%*u %x %*x proc %32s",
			&Offset, ProcName);
		if (Matches != 2)
			continue;
		if (!strcmp(ProcName, "__Spawn"))
		{
			Context.SpawnCodeOffset = Offset;
			FoundSpawn = true;
		}
		else if (!strcmp(ProcName, "__Process"))
		{
			Context.ProcessCodeOffset = Offset;
			FoundProcess = true;
		}
	}
	// data is always at the start
	Context.DataOffset = 0;

	Context.CloseIntermediateFile(Listing);

	if (FoundSpawn && FoundProcess)
	{
		Context.Result = CR_Success;
		Context.ResultArgument = 0;
	}
	else
	{
		Context.Result = CR_CorruptIntermediateFile;
		// encode the cause in the lowest bits
		Context.ResultArgument = ((int)(!FoundSpawn)		* 1)
								| ((int)(!FoundProcess)		* 2)
								| ((int)(Line > End + 1)	* 4);
	}
}