repo_name
stringlengths 5
122
| path
stringlengths 3
232
| text
stringlengths 6
1.05M
|
---|---|---|
QuaternionMark/COMP371-FinalProject | Src/Primitives/Axis.h | #ifndef AXIS_H_INCLUDED
#define AXIS_H_INCLUDED
#include "../Graphics/Shader.h"
class Mesh;
class Axis {
private:
const float vertices[12] = {
// Position. // Normal.
0.f, 0.f, 0.f, 0.f, 1.f, 0.f,
0.f, 0.f, -1.f, 0.f, 1.f, 0.f
};
Mesh* mesh;
Shader::Uniform* worldMat;
Shader::Uniform* colorUniform;
public:
Vector3f rotation;
Vector4f color;
Axis(Shader* shd);
void render();
};
#endif // AXIS_H_INCLUDED
|
QuaternionMark/COMP371-FinalProject | Libraries/FreeImage-3170/Source/OpenEXR/Iex/IexNamespace.h | <gh_stars>1-10
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2012, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_IEXNAMESPACE_H
#define INCLUDED_IEXNAMESPACE_H
//
// The purpose of this file is to make it possible to specify an
// IEX_INTERNAL_NAMESPACE as a preprocessor definition and have all of the
// Iex symbols defined within that namespace rather than the standard
// Iex namespace. Those symbols are made available to client code through
// the IEX_NAMESPACE in addition to the IEX_INTERNAL_NAMESPACE.
//
// To ensure source code compatibility, the IEX_NAMESPACE defaults to Iex
// and then "using namespace IEX_INTERNAL_NAMESPACE;" brings all of the
// declarations from the IEX_INTERNAL_NAMESPACE into the IEX_NAMESPACE. This
// means that client code can continue to use syntax like Iex::BaseExc, but
// at link time it will resolve to a mangled symbol based on the
// IEX_INTERNAL_NAMESPACE.
//
// As an example, if one needed to build against a newer version of Iex and
// have it run alongside an older version in the same application, it is now
// possible to use an internal namespace to prevent collisions between the
// older versions of Iex symbols and the newer ones. To do this, the
// following could be defined at build time:
//
// IEX_INTERNAL_NAMESPACE = Iex_v2
//
// This means that declarations inside Iex headers look like this (after the
// preprocessor has done its work):
//
// namespace Iex_v2 {
// ...
// class declarations
// ...
// }
//
// namespace Iex {
// using namespace Iex_v2;
// }
//
//
// Open Source version of this file pulls in the IlmBaseConfig.h file
// for the configure time options.
//
#include "IlmBaseConfig.h"
#ifndef IEX_NAMESPACE
#define IEX_NAMESPACE Iex
#endif
#ifndef IEX_INTERNAL_NAMESPACE
#define IEX_INTERNAL_NAMESPACE IEX_NAMESPACE
#endif
//
// We need to be sure that we import the internal namespace into the public one.
// To do this, we use the small bit of code below which initially defines
// IEX_INTERNAL_NAMESPACE (so it can be referenced) and then defines
// IEX_NAMESPACE and pulls the internal symbols into the public namespace.
//
namespace IEX_INTERNAL_NAMESPACE {}
namespace IEX_NAMESPACE {
using namespace IEX_INTERNAL_NAMESPACE;
}
//
// There are identical pairs of HEADER/SOURCE ENTER/EXIT macros so that
// future extension to the namespace mechanism is possible without changing
// project source code.
//
#define IEX_INTERNAL_NAMESPACE_HEADER_ENTER namespace IEX_INTERNAL_NAMESPACE {
#define IEX_INTERNAL_NAMESPACE_HEADER_EXIT }
#define IEX_INTERNAL_NAMESPACE_SOURCE_ENTER namespace IEX_INTERNAL_NAMESPACE {
#define IEX_INTERNAL_NAMESPACE_SOURCE_EXIT }
#endif // INCLUDED_IEXNAMESPACE_H
|
QuaternionMark/COMP371-FinalProject | Src/Objects/Car.h | <gh_stars>1-10
#ifndef CAR_H_INCLUDED
#define CAR_H_INCLUDED
#include <vector>
#include <GL/glew.h>
#include "RectCollider.h"
#include "../Math/Vector.h"
#include "../Math/Matrix.h"
class Cube;
class Wheel;
class Shader;
class Texture;
class Smoke;
class Car {
public:
enum class WalkInput {
None = 0x0,
Forward = 0x1,
Backward = 0x2,
Left = 0x4,
Right = 0x8
};
private:
static std::vector<Car*> allCars;
const float INPUT_ACCELERATION = 1.f;
const float TURN_SPEED = 7.f;
const float TERMINAL_VELOCITY = 0.25f;
const float FRICTION = 1.f;
Vector3f position;
Vector2f deltaPositionXZ;
Vector2f velocity;
Vector2f acceleration;
Vector3f scale;
Vector3f rotation;
float deltaRotationY;
float tireRotation;
bool enableHeadlightsAndTailights;
Matrix4x4f rotationMatrix;
Texture* metalTexture;
Texture* tireTexture;
Shader* spriteShader;
std::vector<Smoke*> smokeParticles;
std::vector<Cube*> parts;
Wheel* wheels[4];
RectCollider* collider;
Vector2f getDirectionVector(RectCollider::CollisionDir dir);
void updateAcceleration(WalkInput input, float speed);
void updateVelocity(Car::WalkInput input, float timestep);
void updatePosition(WalkInput input);
void updateTireRotation(WalkInput input, float speed);
bool deltaPositionCausesCollision(int& collidedCar, RectCollider::CollisionDir& dir);
public:
Car(Shader* shd, Shader* colliderShd, Shader* spriteShd);
~Car();
void addPositionXZ(const Vector2f& vect);
Vector3f getPosition() const;
void addScale(float sca);
void addRotationX(float bruh);
void addRotationY(float bruh);
float getRotationY() const;
void addRotationZ(float bruh);
void toggleHeadlightsTaillights();
Matrix4x4f getRotationMatrix() const;
void setShader(Shader* shd);
void update(WalkInput input, float timestep);
void render();
};
const Car::WalkInput operator&(const Car::WalkInput& a, const Car::WalkInput& b);
const Car::WalkInput operator|(const Car::WalkInput& a, const Car::WalkInput& b);
#endif // CAR_H_INCLUDED
|
QuaternionMark/COMP371-FinalProject | Libraries/FreeImage-3170/Source/OpenEXR/IlmImf/ImfMultiPartInputFile.h | <reponame>QuaternionMark/COMP371-FinalProject<filename>Libraries/FreeImage-3170/Source/OpenEXR/IlmImf/ImfMultiPartInputFile.h
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2011, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
#ifndef IMFMULTIPARTINPUTFILE_H_
#define IMFMULTIPARTINPUTFILE_H_
#include "ImfGenericInputFile.h"
#include "ImfNamespace.h"
#include "ImfForward.h"
#include "ImfThreading.h"
#include "ImfExport.h"
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
class IMF_EXPORT MultiPartInputFile : public GenericInputFile
{
public:
MultiPartInputFile(const char fileName[],
int numThreads = globalThreadCount(),
bool reconstructChunkOffsetTable = true);
MultiPartInputFile(IStream& is,
int numThreads = globalThreadCount(),
bool reconstructChunkOffsetTable = true);
virtual ~MultiPartInputFile();
// ----------------------
// Count of number of parts in file
// ---------------------
int parts() const;
//----------------------
// Access to the headers
//----------------------
const Header & header(int n) const;
//----------------------------------
// Access to the file format version
//----------------------------------
int version () const;
// =----------------------------------------
// Check whether the entire chunk offset
// table for the part is written correctly
// -----------------------------------------
bool partComplete(int part) const;
struct Data;
private:
Data* _data;
MultiPartInputFile(const MultiPartInputFile &); // not implemented
//
// used internally by 'Part' types to access individual parts of the multipart file
//
template<class T> T* getInputPart(int partNumber);
InputPartData* getPart(int);
void initialize();
friend class InputPart;
friend class ScanLineInputPart;
friend class TiledInputPart;
friend class DeepScanLineInputPart;
friend class DeepTiledInputPart;
//
// For backward compatibility.
//
friend class InputFile;
friend class TiledInputFile;
friend class ScanLineInputFile;
friend class DeepScanLineInputFile;
friend class DeepTiledInputFile;
};
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
#endif /* IMFMULTIPARTINPUTFILE_H_ */
|
QuaternionMark/COMP371-FinalProject | Libraries/FreeImage-3170/Source/LibTIFF4/tif_jpeg.c | /* $Id: tif_jpeg.c,v 1.11 2015/02/19 22:39:58 drolon Exp $ */
/*
* Copyright (c) 1994-1997 <NAME>ler
* Copyright (c) 1994-1997 Silicon Graphics, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that (i) the above copyright notices and this permission notice appear in
* all copies of the software and related documentation, and (ii) the names of
* Sam Leffler and Silicon Graphics may not be used in any advertising or
* publicity relating to the software without the specific, prior written
* permission of Sam Leffler and Silicon Graphics.
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#define WIN32_LEAN_AND_MEAN
#define VC_EXTRALEAN
#include "tiffiop.h"
#ifdef JPEG_SUPPORT
/*
* TIFF Library
*
* JPEG Compression support per TIFF Technical Note #2
* (*not* per the original TIFF 6.0 spec).
*
* This file is simply an interface to the libjpeg library written by
* the Independent JPEG Group. You need release 5 or later of the IJG
* code, which you can find on the Internet at ftp.uu.net:/graphics/jpeg/.
*
* Contributed by <NAME> <<EMAIL>>.
*/
#include <setjmp.h>
int TIFFFillStrip(TIFF* tif, uint32 strip);
int TIFFFillTile(TIFF* tif, uint32 tile);
int TIFFReInitJPEG_12( TIFF *tif, int scheme, int is_encode );
/* We undefine FAR to avoid conflict with JPEG definition */
#ifdef FAR
#undef FAR
#endif
/*
Libjpeg's jmorecfg.h defines INT16 and INT32, but only if XMD_H is
not defined. Unfortunately, the MinGW and Borland compilers include
a typedef for INT32, which causes a conflict. MSVC does not include
a conficting typedef given the headers which are included.
*/
#if defined(__BORLANDC__) || defined(__MINGW32__)
# define XMD_H 1
#endif
/*
The windows RPCNDR.H file defines boolean, but defines it with the
unsigned char size. You should compile JPEG library using appropriate
definitions in jconfig.h header, but many users compile library in wrong
way. That causes errors of the following type:
"JPEGLib: JPEG parameter struct mismatch: library thinks size is 432,
caller expects 464"
For such users we wil fix the problem here. See install.doc file from
the JPEG library distribution for details.
*/
/* Define "boolean" as unsigned char, not int, per Windows custom. */
#if defined(__WIN32__) && !defined(__MINGW32__)
# ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
typedef unsigned char boolean;
# endif
# define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
#endif
#include "../LibJPEG/jpeglib.h"
#include "../LibJPEG/jerror.h"
/*
* Do we want to do special processing suitable for when JSAMPLE is a
* 16bit value?
*/
#if defined(JPEG_LIB_MK1)
# define JPEG_LIB_MK1_OR_12BIT 1
#elif BITS_IN_JSAMPLE == 12
# define JPEG_LIB_MK1_OR_12BIT 1
#endif
/*
* We are using width_in_blocks which is supposed to be private to
* libjpeg. Unfortunately, the libjpeg delivered with Cygwin has
* renamed this member to width_in_data_units. Since the header has
* also renamed a define, use that unique define name in order to
* detect the problem header and adjust to suit.
*/
#if defined(D_MAX_DATA_UNITS_IN_MCU)
#define width_in_blocks width_in_data_units
#endif
/*
* On some machines it may be worthwhile to use _setjmp or sigsetjmp
* in place of plain setjmp. These macros will make it easier.
*/
#define SETJMP(jbuf) setjmp(jbuf)
#define LONGJMP(jbuf,code) longjmp(jbuf,code)
#define JMP_BUF jmp_buf
typedef struct jpeg_destination_mgr jpeg_destination_mgr;
typedef struct jpeg_source_mgr jpeg_source_mgr;
typedef struct jpeg_error_mgr jpeg_error_mgr;
/*
* State block for each open TIFF file using
* libjpeg to do JPEG compression/decompression.
*
* libjpeg's visible state is either a jpeg_compress_struct
* or jpeg_decompress_struct depending on which way we
* are going. comm can be used to refer to the fields
* which are common to both.
*
* NB: cinfo is required to be the first member of JPEGState,
* so we can safely cast JPEGState* -> jpeg_xxx_struct*
* and vice versa!
*/
typedef struct {
union {
struct jpeg_compress_struct c;
struct jpeg_decompress_struct d;
struct jpeg_common_struct comm;
} cinfo; /* NB: must be first */
int cinfo_initialized;
jpeg_error_mgr err; /* libjpeg error manager */
JMP_BUF exit_jmpbuf; /* for catching libjpeg failures */
/*
* The following two members could be a union, but
* they're small enough that it's not worth the effort.
*/
jpeg_destination_mgr dest; /* data dest for compression */
jpeg_source_mgr src; /* data source for decompression */
/* private state */
TIFF* tif; /* back link needed by some code */
uint16 photometric; /* copy of PhotometricInterpretation */
uint16 h_sampling; /* luminance sampling factors */
uint16 v_sampling;
tmsize_t bytesperline; /* decompressed bytes per scanline */
/* pointers to intermediate buffers when processing downsampled data */
JSAMPARRAY ds_buffer[MAX_COMPONENTS];
int scancount; /* number of "scanlines" accumulated */
int samplesperclump;
TIFFVGetMethod vgetparent; /* super-class method */
TIFFVSetMethod vsetparent; /* super-class method */
TIFFPrintMethod printdir; /* super-class method */
TIFFStripMethod defsparent; /* super-class method */
TIFFTileMethod deftparent; /* super-class method */
/* pseudo-tag fields */
void* jpegtables; /* JPEGTables tag value, or NULL */
uint32 jpegtables_length; /* number of bytes in same */
int jpegquality; /* Compression quality level */
int jpegcolormode; /* Auto RGB<=>YCbCr convert? */
int jpegtablesmode; /* What to put in JPEGTables */
int ycbcrsampling_fetched;
} JPEGState;
#define JState(tif) ((JPEGState*)(tif)->tif_data)
static int JPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s);
static int JPEGDecodeRaw(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s);
static int JPEGEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s);
static int JPEGEncodeRaw(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s);
static int JPEGInitializeLibJPEG(TIFF * tif, int decode );
static int DecodeRowError(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s);
#define FIELD_JPEGTABLES (FIELD_CODEC+0)
static const TIFFField jpegFields[] = {
{ TIFFTAG_JPEGTABLES, -3, -3, TIFF_UNDEFINED, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_C32_UINT8, FIELD_JPEGTABLES, FALSE, TRUE, "JPEGTables", NULL },
{ TIFFTAG_JPEGQUALITY, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "", NULL },
{ TIFFTAG_JPEGCOLORMODE, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE, "", NULL },
{ TIFFTAG_JPEGTABLESMODE, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE, "", NULL }
};
/*
* libjpeg interface layer.
*
* We use setjmp/longjmp to return control to libtiff
* when a fatal error is encountered within the JPEG
* library. We also direct libjpeg error and warning
* messages through the appropriate libtiff handlers.
*/
/*
* Error handling routines (these replace corresponding
* IJG routines from jerror.c). These are used for both
* compression and decompression.
*/
static void
TIFFjpeg_error_exit(j_common_ptr cinfo)
{
JPEGState *sp = (JPEGState *) cinfo; /* NB: cinfo assumed first */
char buffer[JMSG_LENGTH_MAX];
(*cinfo->err->format_message) (cinfo, buffer);
TIFFErrorExt(sp->tif->tif_clientdata, "JPEGLib", "%s", buffer); /* display the error message */
jpeg_abort(cinfo); /* clean up libjpeg state */
LONGJMP(sp->exit_jmpbuf, 1); /* return to libtiff caller */
}
/*
* This routine is invoked only for warning messages,
* since error_exit does its own thing and trace_level
* is never set > 0.
*/
static void
TIFFjpeg_output_message(j_common_ptr cinfo)
{
char buffer[JMSG_LENGTH_MAX];
(*cinfo->err->format_message) (cinfo, buffer);
TIFFWarningExt(((JPEGState *) cinfo)->tif->tif_clientdata, "JPEGLib", "%s", buffer);
}
/*
* Interface routines. This layer of routines exists
* primarily to limit side-effects from using setjmp.
* Also, normal/error returns are converted into return
* values per libtiff practice.
*/
#define CALLJPEG(sp, fail, op) (SETJMP((sp)->exit_jmpbuf) ? (fail) : (op))
#define CALLVJPEG(sp, op) CALLJPEG(sp, 0, ((op),1))
static int
TIFFjpeg_create_compress(JPEGState* sp)
{
/* initialize JPEG error handling */
sp->cinfo.c.err = jpeg_std_error(&sp->err);
sp->err.error_exit = TIFFjpeg_error_exit;
sp->err.output_message = TIFFjpeg_output_message;
return CALLVJPEG(sp, jpeg_create_compress(&sp->cinfo.c));
}
static int
TIFFjpeg_create_decompress(JPEGState* sp)
{
/* initialize JPEG error handling */
sp->cinfo.d.err = jpeg_std_error(&sp->err);
sp->err.error_exit = TIFFjpeg_error_exit;
sp->err.output_message = TIFFjpeg_output_message;
return CALLVJPEG(sp, jpeg_create_decompress(&sp->cinfo.d));
}
static int
TIFFjpeg_set_defaults(JPEGState* sp)
{
return CALLVJPEG(sp, jpeg_set_defaults(&sp->cinfo.c));
}
static int
TIFFjpeg_set_colorspace(JPEGState* sp, J_COLOR_SPACE colorspace)
{
return CALLVJPEG(sp, jpeg_set_colorspace(&sp->cinfo.c, colorspace));
}
static int
TIFFjpeg_set_quality(JPEGState* sp, int quality, boolean force_baseline)
{
return CALLVJPEG(sp,
jpeg_set_quality(&sp->cinfo.c, quality, force_baseline));
}
static int
TIFFjpeg_suppress_tables(JPEGState* sp, boolean suppress)
{
return CALLVJPEG(sp, jpeg_suppress_tables(&sp->cinfo.c, suppress));
}
static int
TIFFjpeg_start_compress(JPEGState* sp, boolean write_all_tables)
{
return CALLVJPEG(sp,
jpeg_start_compress(&sp->cinfo.c, write_all_tables));
}
static int
TIFFjpeg_write_scanlines(JPEGState* sp, JSAMPARRAY scanlines, int num_lines)
{
return CALLJPEG(sp, -1, (int) jpeg_write_scanlines(&sp->cinfo.c,
scanlines, (JDIMENSION) num_lines));
}
static int
TIFFjpeg_write_raw_data(JPEGState* sp, JSAMPIMAGE data, int num_lines)
{
return CALLJPEG(sp, -1, (int) jpeg_write_raw_data(&sp->cinfo.c,
data, (JDIMENSION) num_lines));
}
static int
TIFFjpeg_finish_compress(JPEGState* sp)
{
return CALLVJPEG(sp, jpeg_finish_compress(&sp->cinfo.c));
}
static int
TIFFjpeg_write_tables(JPEGState* sp)
{
return CALLVJPEG(sp, jpeg_write_tables(&sp->cinfo.c));
}
static int
TIFFjpeg_read_header(JPEGState* sp, boolean require_image)
{
return CALLJPEG(sp, -1, jpeg_read_header(&sp->cinfo.d, require_image));
}
static int
TIFFjpeg_start_decompress(JPEGState* sp)
{
return CALLVJPEG(sp, jpeg_start_decompress(&sp->cinfo.d));
}
static int
TIFFjpeg_read_scanlines(JPEGState* sp, JSAMPARRAY scanlines, int max_lines)
{
return CALLJPEG(sp, -1, (int) jpeg_read_scanlines(&sp->cinfo.d,
scanlines, (JDIMENSION) max_lines));
}
static int
TIFFjpeg_read_raw_data(JPEGState* sp, JSAMPIMAGE data, int max_lines)
{
return CALLJPEG(sp, -1, (int) jpeg_read_raw_data(&sp->cinfo.d,
data, (JDIMENSION) max_lines));
}
static int
TIFFjpeg_finish_decompress(JPEGState* sp)
{
return CALLJPEG(sp, -1, (int) jpeg_finish_decompress(&sp->cinfo.d));
}
static int
TIFFjpeg_abort(JPEGState* sp)
{
return CALLVJPEG(sp, jpeg_abort(&sp->cinfo.comm));
}
static int
TIFFjpeg_destroy(JPEGState* sp)
{
return CALLVJPEG(sp, jpeg_destroy(&sp->cinfo.comm));
}
static JSAMPARRAY
TIFFjpeg_alloc_sarray(JPEGState* sp, int pool_id,
JDIMENSION samplesperrow, JDIMENSION numrows)
{
return CALLJPEG(sp, (JSAMPARRAY) NULL,
(*sp->cinfo.comm.mem->alloc_sarray)
(&sp->cinfo.comm, pool_id, samplesperrow, numrows));
}
/*
* JPEG library destination data manager.
* These routines direct compressed data from libjpeg into the
* libtiff output buffer.
*/
static void
std_init_destination(j_compress_ptr cinfo)
{
JPEGState* sp = (JPEGState*) cinfo;
TIFF* tif = sp->tif;
sp->dest.next_output_byte = (JOCTET*) tif->tif_rawdata;
sp->dest.free_in_buffer = (size_t) tif->tif_rawdatasize;
}
static boolean
std_empty_output_buffer(j_compress_ptr cinfo)
{
JPEGState* sp = (JPEGState*) cinfo;
TIFF* tif = sp->tif;
/* the entire buffer has been filled */
tif->tif_rawcc = tif->tif_rawdatasize;
#ifdef IPPJ_HUFF
/*
* The Intel IPP performance library does not necessarily fill up
* the whole output buffer on each pass, so only dump out the parts
* that have been filled.
* http://trac.osgeo.org/gdal/wiki/JpegIPP
*/
if ( sp->dest.free_in_buffer >= 0 ) {
tif->tif_rawcc = tif->tif_rawdatasize - sp->dest.free_in_buffer;
}
#endif
TIFFFlushData1(tif);
sp->dest.next_output_byte = (JOCTET*) tif->tif_rawdata;
sp->dest.free_in_buffer = (size_t) tif->tif_rawdatasize;
return (TRUE);
}
static void
std_term_destination(j_compress_ptr cinfo)
{
JPEGState* sp = (JPEGState*) cinfo;
TIFF* tif = sp->tif;
tif->tif_rawcp = (uint8*) sp->dest.next_output_byte;
tif->tif_rawcc =
tif->tif_rawdatasize - (tmsize_t) sp->dest.free_in_buffer;
/* NB: libtiff does the final buffer flush */
}
static void
TIFFjpeg_data_dest(JPEGState* sp, TIFF* tif)
{
(void) tif;
sp->cinfo.c.dest = &sp->dest;
sp->dest.init_destination = std_init_destination;
sp->dest.empty_output_buffer = std_empty_output_buffer;
sp->dest.term_destination = std_term_destination;
}
/*
* Alternate destination manager for outputting to JPEGTables field.
*/
static void
tables_init_destination(j_compress_ptr cinfo)
{
JPEGState* sp = (JPEGState*) cinfo;
/* while building, jpegtables_length is allocated buffer size */
sp->dest.next_output_byte = (JOCTET*) sp->jpegtables;
sp->dest.free_in_buffer = (size_t) sp->jpegtables_length;
}
static boolean
tables_empty_output_buffer(j_compress_ptr cinfo)
{
JPEGState* sp = (JPEGState*) cinfo;
void* newbuf;
/* the entire buffer has been filled; enlarge it by 1000 bytes */
newbuf = _TIFFrealloc((void*) sp->jpegtables,
(tmsize_t) (sp->jpegtables_length + 1000));
if (newbuf == NULL)
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 100);
sp->dest.next_output_byte = (JOCTET*) newbuf + sp->jpegtables_length;
sp->dest.free_in_buffer = (size_t) 1000;
sp->jpegtables = newbuf;
sp->jpegtables_length += 1000;
return (TRUE);
}
static void
tables_term_destination(j_compress_ptr cinfo)
{
JPEGState* sp = (JPEGState*) cinfo;
/* set tables length to number of bytes actually emitted */
sp->jpegtables_length -= (uint32) sp->dest.free_in_buffer;
}
static int
TIFFjpeg_tables_dest(JPEGState* sp, TIFF* tif)
{
(void) tif;
/*
* Allocate a working buffer for building tables.
* Initial size is 1000 bytes, which is usually adequate.
*/
if (sp->jpegtables)
_TIFFfree(sp->jpegtables);
sp->jpegtables_length = 1000;
sp->jpegtables = (void*) _TIFFmalloc((tmsize_t) sp->jpegtables_length);
if (sp->jpegtables == NULL) {
sp->jpegtables_length = 0;
TIFFErrorExt(sp->tif->tif_clientdata, "TIFFjpeg_tables_dest", "No space for JPEGTables");
return (0);
}
sp->cinfo.c.dest = &sp->dest;
sp->dest.init_destination = tables_init_destination;
sp->dest.empty_output_buffer = tables_empty_output_buffer;
sp->dest.term_destination = tables_term_destination;
return (1);
}
/*
* JPEG library source data manager.
* These routines supply compressed data to libjpeg.
*/
static void
std_init_source(j_decompress_ptr cinfo)
{
JPEGState* sp = (JPEGState*) cinfo;
TIFF* tif = sp->tif;
sp->src.next_input_byte = (const JOCTET*) tif->tif_rawdata;
sp->src.bytes_in_buffer = (size_t) tif->tif_rawcc;
}
static boolean
std_fill_input_buffer(j_decompress_ptr cinfo)
{
JPEGState* sp = (JPEGState* ) cinfo;
static const JOCTET dummy_EOI[2] = { 0xFF, JPEG_EOI };
#ifdef IPPJ_HUFF
/*
* The Intel IPP performance library does not necessarily read the whole
* input buffer in one pass, so it is possible to get here with data
* yet to read.
*
* We just return without doing anything, until the entire buffer has
* been read.
* http://trac.osgeo.org/gdal/wiki/JpegIPP
*/
if( sp->src.bytes_in_buffer > 0 ) {
return (TRUE);
}
#endif
/*
* Normally the whole strip/tile is read and so we don't need to do
* a fill. In the case of CHUNKY_STRIP_READ_SUPPORT we might not have
* all the data, but the rawdata is refreshed between scanlines and
* we push this into the io machinery in JPEGDecode().
* http://trac.osgeo.org/gdal/ticket/3894
*/
WARNMS(cinfo, JWRN_JPEG_EOF);
/* insert a fake EOI marker */
sp->src.next_input_byte = dummy_EOI;
sp->src.bytes_in_buffer = 2;
return (TRUE);
}
static void
std_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
{
JPEGState* sp = (JPEGState*) cinfo;
if (num_bytes > 0) {
if ((size_t)num_bytes > sp->src.bytes_in_buffer) {
/* oops, buffer overrun */
(void) std_fill_input_buffer(cinfo);
} else {
sp->src.next_input_byte += (size_t) num_bytes;
sp->src.bytes_in_buffer -= (size_t) num_bytes;
}
}
}
static void
std_term_source(j_decompress_ptr cinfo)
{
/* No work necessary here */
(void) cinfo;
}
static void
TIFFjpeg_data_src(JPEGState* sp, TIFF* tif)
{
(void) tif;
sp->cinfo.d.src = &sp->src;
sp->src.init_source = std_init_source;
sp->src.fill_input_buffer = std_fill_input_buffer;
sp->src.skip_input_data = std_skip_input_data;
sp->src.resync_to_restart = jpeg_resync_to_restart;
sp->src.term_source = std_term_source;
sp->src.bytes_in_buffer = 0; /* for safety */
sp->src.next_input_byte = NULL;
}
/*
* Alternate source manager for reading from JPEGTables.
* We can share all the code except for the init routine.
*/
static void
tables_init_source(j_decompress_ptr cinfo)
{
JPEGState* sp = (JPEGState*) cinfo;
sp->src.next_input_byte = (const JOCTET*) sp->jpegtables;
sp->src.bytes_in_buffer = (size_t) sp->jpegtables_length;
}
static void
TIFFjpeg_tables_src(JPEGState* sp, TIFF* tif)
{
TIFFjpeg_data_src(sp, tif);
sp->src.init_source = tables_init_source;
}
/*
* Allocate downsampled-data buffers needed for downsampled I/O.
* We use values computed in jpeg_start_compress or jpeg_start_decompress.
* We use libjpeg's allocator so that buffers will be released automatically
* when done with strip/tile.
* This is also a handy place to compute samplesperclump, bytesperline.
*/
static int
alloc_downsampled_buffers(TIFF* tif, jpeg_component_info* comp_info,
int num_components)
{
JPEGState* sp = JState(tif);
int ci;
jpeg_component_info* compptr;
JSAMPARRAY buf;
int samples_per_clump = 0;
for (ci = 0, compptr = comp_info; ci < num_components;
ci++, compptr++) {
samples_per_clump += compptr->h_samp_factor *
compptr->v_samp_factor;
buf = TIFFjpeg_alloc_sarray(sp, JPOOL_IMAGE,
compptr->width_in_blocks * DCTSIZE,
(JDIMENSION) (compptr->v_samp_factor*DCTSIZE));
if (buf == NULL)
return (0);
sp->ds_buffer[ci] = buf;
}
sp->samplesperclump = samples_per_clump;
return (1);
}
/*
* JPEG Decoding.
*/
#ifdef CHECK_JPEG_YCBCR_SUBSAMPLING
#define JPEG_MARKER_SOF0 0xC0
#define JPEG_MARKER_SOF1 0xC1
#define JPEG_MARKER_SOF2 0xC2
#define JPEG_MARKER_SOF9 0xC9
#define JPEG_MARKER_SOF10 0xCA
#define JPEG_MARKER_DHT 0xC4
#define JPEG_MARKER_SOI 0xD8
#define JPEG_MARKER_SOS 0xDA
#define JPEG_MARKER_DQT 0xDB
#define JPEG_MARKER_DRI 0xDD
#define JPEG_MARKER_APP0 0xE0
#define JPEG_MARKER_COM 0xFE
struct JPEGFixupTagsSubsamplingData
{
TIFF* tif;
void* buffer;
uint32 buffersize;
uint8* buffercurrentbyte;
uint32 bufferbytesleft;
uint64 fileoffset;
uint64 filebytesleft;
uint8 filepositioned;
};
static void JPEGFixupTagsSubsampling(TIFF* tif);
static int JPEGFixupTagsSubsamplingSec(struct JPEGFixupTagsSubsamplingData* data);
static int JPEGFixupTagsSubsamplingReadByte(struct JPEGFixupTagsSubsamplingData* data, uint8* result);
static int JPEGFixupTagsSubsamplingReadWord(struct JPEGFixupTagsSubsamplingData* data, uint16* result);
static void JPEGFixupTagsSubsamplingSkip(struct JPEGFixupTagsSubsamplingData* data, uint16 skiplength);
#endif
static int
JPEGFixupTags(TIFF* tif)
{
#ifdef CHECK_JPEG_YCBCR_SUBSAMPLING
if ((tif->tif_dir.td_photometric==PHOTOMETRIC_YCBCR)&&
(tif->tif_dir.td_planarconfig==PLANARCONFIG_CONTIG)&&
(tif->tif_dir.td_samplesperpixel==3))
JPEGFixupTagsSubsampling(tif);
#endif
return(1);
}
#ifdef CHECK_JPEG_YCBCR_SUBSAMPLING
static void
JPEGFixupTagsSubsampling(TIFF* tif)
{
/*
* Some JPEG-in-TIFF produces do not emit the YCBCRSUBSAMPLING values in
* the TIFF tags, but still use non-default (2,2) values within the jpeg
* data stream itself. In order for TIFF applications to work properly
* - for instance to get the strip buffer size right - it is imperative
* that the subsampling be available before we start reading the image
* data normally. This function will attempt to analyze the first strip in
* order to get the sampling values from the jpeg data stream.
*
* Note that JPEGPreDeocode() will produce a fairly loud warning when the
* discovered sampling does not match the default sampling (2,2) or whatever
* was actually in the tiff tags.
*
* See the bug in bugzilla for details:
*
* http://bugzilla.remotesensing.org/show_bug.cgi?id=168
*
* <NAME>, July 2002
* <NAME>, May 2007
*/
static const char module[] = "JPEGFixupTagsSubsampling";
struct JPEGFixupTagsSubsamplingData m;
_TIFFFillStriles( tif );
if( tif->tif_dir.td_stripbytecount == NULL
|| tif->tif_dir.td_stripoffset == NULL
|| tif->tif_dir.td_stripbytecount[0] == 0 )
{
/* Do not even try to check if the first strip/tile does not
yet exist, as occurs when GDAL has created a new NULL file
for instance. */
return;
}
m.tif=tif;
m.buffersize=2048;
m.buffer=_TIFFmalloc(m.buffersize);
if (m.buffer==NULL)
{
TIFFWarningExt(tif->tif_clientdata,module,
"Unable to allocate memory for auto-correcting of subsampling values; auto-correcting skipped");
return;
}
m.buffercurrentbyte=NULL;
m.bufferbytesleft=0;
m.fileoffset=tif->tif_dir.td_stripoffset[0];
m.filepositioned=0;
m.filebytesleft=tif->tif_dir.td_stripbytecount[0];
if (!JPEGFixupTagsSubsamplingSec(&m))
TIFFWarningExt(tif->tif_clientdata,module,
"Unable to auto-correct subsampling values, likely corrupt JPEG compressed data in first strip/tile; auto-correcting skipped");
_TIFFfree(m.buffer);
}
static int
JPEGFixupTagsSubsamplingSec(struct JPEGFixupTagsSubsamplingData* data)
{
static const char module[] = "JPEGFixupTagsSubsamplingSec";
uint8 m;
while (1)
{
while (1)
{
if (!JPEGFixupTagsSubsamplingReadByte(data,&m))
return(0);
if (m==255)
break;
}
while (1)
{
if (!JPEGFixupTagsSubsamplingReadByte(data,&m))
return(0);
if (m!=255)
break;
}
switch (m)
{
case JPEG_MARKER_SOI:
/* this type of marker has no data and should be skipped */
break;
case JPEG_MARKER_COM:
case JPEG_MARKER_APP0:
case JPEG_MARKER_APP0+1:
case JPEG_MARKER_APP0+2:
case JPEG_MARKER_APP0+3:
case JPEG_MARKER_APP0+4:
case JPEG_MARKER_APP0+5:
case JPEG_MARKER_APP0+6:
case JPEG_MARKER_APP0+7:
case JPEG_MARKER_APP0+8:
case JPEG_MARKER_APP0+9:
case JPEG_MARKER_APP0+10:
case JPEG_MARKER_APP0+11:
case JPEG_MARKER_APP0+12:
case JPEG_MARKER_APP0+13:
case JPEG_MARKER_APP0+14:
case JPEG_MARKER_APP0+15:
case JPEG_MARKER_DQT:
case JPEG_MARKER_SOS:
case JPEG_MARKER_DHT:
case JPEG_MARKER_DRI:
/* this type of marker has data, but it has no use to us and should be skipped */
{
uint16 n;
if (!JPEGFixupTagsSubsamplingReadWord(data,&n))
return(0);
if (n<2)
return(0);
n-=2;
if (n>0)
JPEGFixupTagsSubsamplingSkip(data,n);
}
break;
case JPEG_MARKER_SOF0: /* Baseline sequential Huffman */
case JPEG_MARKER_SOF1: /* Extended sequential Huffman */
case JPEG_MARKER_SOF2: /* Progressive Huffman: normally not allowed by TechNote, but that doesn't hurt supporting it */
case JPEG_MARKER_SOF9: /* Extended sequential arithmetic */
case JPEG_MARKER_SOF10: /* Progressive arithmetic: normally not allowed by TechNote, but that doesn't hurt supporting it */
/* this marker contains the subsampling factors we're scanning for */
{
uint16 n;
uint16 o;
uint8 p;
uint8 ph,pv;
if (!JPEGFixupTagsSubsamplingReadWord(data,&n))
return(0);
if (n!=8+data->tif->tif_dir.td_samplesperpixel*3)
return(0);
JPEGFixupTagsSubsamplingSkip(data,7);
if (!JPEGFixupTagsSubsamplingReadByte(data,&p))
return(0);
ph=(p>>4);
pv=(p&15);
JPEGFixupTagsSubsamplingSkip(data,1);
for (o=1; o<data->tif->tif_dir.td_samplesperpixel; o++)
{
JPEGFixupTagsSubsamplingSkip(data,1);
if (!JPEGFixupTagsSubsamplingReadByte(data,&p))
return(0);
if (p!=0x11)
{
TIFFWarningExt(data->tif->tif_clientdata,module,
"Subsampling values inside JPEG compressed data have no TIFF equivalent, auto-correction of TIFF subsampling values failed");
return(1);
}
JPEGFixupTagsSubsamplingSkip(data,1);
}
if (((ph!=1)&&(ph!=2)&&(ph!=4))||((pv!=1)&&(pv!=2)&&(pv!=4)))
{
TIFFWarningExt(data->tif->tif_clientdata,module,
"Subsampling values inside JPEG compressed data have no TIFF equivalent, auto-correction of TIFF subsampling values failed");
return(1);
}
if ((ph!=data->tif->tif_dir.td_ycbcrsubsampling[0])||(pv!=data->tif->tif_dir.td_ycbcrsubsampling[1]))
{
TIFFWarningExt(data->tif->tif_clientdata,module,
"Auto-corrected former TIFF subsampling values [%d,%d] to match subsampling values inside JPEG compressed data [%d,%d]",
(int)data->tif->tif_dir.td_ycbcrsubsampling[0],
(int)data->tif->tif_dir.td_ycbcrsubsampling[1],
(int)ph,(int)pv);
data->tif->tif_dir.td_ycbcrsubsampling[0]=ph;
data->tif->tif_dir.td_ycbcrsubsampling[1]=pv;
}
}
return(1);
default:
return(0);
}
}
}
static int
JPEGFixupTagsSubsamplingReadByte(struct JPEGFixupTagsSubsamplingData* data, uint8* result)
{
if (data->bufferbytesleft==0)
{
uint32 m;
if (data->filebytesleft==0)
return(0);
if (!data->filepositioned)
{
TIFFSeekFile(data->tif,data->fileoffset,SEEK_SET);
data->filepositioned=1;
}
m=data->buffersize;
if ((uint64)m>data->filebytesleft)
m=(uint32)data->filebytesleft;
assert(m<0x80000000UL);
if (TIFFReadFile(data->tif,data->buffer,(tmsize_t)m)!=(tmsize_t)m)
return(0);
data->buffercurrentbyte=data->buffer;
data->bufferbytesleft=m;
data->fileoffset+=m;
data->filebytesleft-=m;
}
*result=*data->buffercurrentbyte;
data->buffercurrentbyte++;
data->bufferbytesleft--;
return(1);
}
static int
JPEGFixupTagsSubsamplingReadWord(struct JPEGFixupTagsSubsamplingData* data, uint16* result)
{
uint8 ma;
uint8 mb;
if (!JPEGFixupTagsSubsamplingReadByte(data,&ma))
return(0);
if (!JPEGFixupTagsSubsamplingReadByte(data,&mb))
return(0);
*result=(ma<<8)|mb;
return(1);
}
static void
JPEGFixupTagsSubsamplingSkip(struct JPEGFixupTagsSubsamplingData* data, uint16 skiplength)
{
if ((uint32)skiplength<=data->bufferbytesleft)
{
data->buffercurrentbyte+=skiplength;
data->bufferbytesleft-=skiplength;
}
else
{
uint16 m;
m=skiplength-data->bufferbytesleft;
if (m<=data->filebytesleft)
{
data->bufferbytesleft=0;
data->fileoffset+=m;
data->filebytesleft-=m;
data->filepositioned=0;
}
else
{
data->bufferbytesleft=0;
data->filebytesleft=0;
}
}
}
#endif
static int
JPEGSetupDecode(TIFF* tif)
{
JPEGState* sp = JState(tif);
TIFFDirectory *td = &tif->tif_dir;
#if defined(JPEG_DUAL_MODE_8_12) && !defined(TIFFInitJPEG)
if( tif->tif_dir.td_bitspersample == 12 )
return TIFFReInitJPEG_12( tif, COMPRESSION_JPEG, 0 );
#endif
JPEGInitializeLibJPEG( tif, TRUE );
assert(sp != NULL);
assert(sp->cinfo.comm.is_decompressor);
/* Read JPEGTables if it is present */
if (TIFFFieldSet(tif,FIELD_JPEGTABLES)) {
TIFFjpeg_tables_src(sp, tif);
if(TIFFjpeg_read_header(sp,FALSE) != JPEG_HEADER_TABLES_ONLY) {
TIFFErrorExt(tif->tif_clientdata, "JPEGSetupDecode", "Bogus JPEGTables field");
return (0);
}
}
/* Grab parameters that are same for all strips/tiles */
sp->photometric = td->td_photometric;
switch (sp->photometric) {
case PHOTOMETRIC_YCBCR:
sp->h_sampling = td->td_ycbcrsubsampling[0];
sp->v_sampling = td->td_ycbcrsubsampling[1];
break;
default:
/* TIFF 6.0 forbids subsampling of all other color spaces */
sp->h_sampling = 1;
sp->v_sampling = 1;
break;
}
/* Set up for reading normal data */
TIFFjpeg_data_src(sp, tif);
tif->tif_postdecode = _TIFFNoPostDecode; /* override byte swapping */
return (1);
}
/*
* Set up for decoding a strip or tile.
*/
static int
JPEGPreDecode(TIFF* tif, uint16 s)
{
JPEGState *sp = JState(tif);
TIFFDirectory *td = &tif->tif_dir;
static const char module[] = "JPEGPreDecode";
uint32 segment_width, segment_height;
int downsampled_output;
int ci;
assert(sp != NULL);
if (sp->cinfo.comm.is_decompressor == 0)
{
tif->tif_setupdecode( tif );
}
assert(sp->cinfo.comm.is_decompressor);
/*
* Reset decoder state from any previous strip/tile,
* in case application didn't read the whole strip.
*/
if (!TIFFjpeg_abort(sp))
return (0);
/*
* Read the header for this strip/tile.
*/
if (TIFFjpeg_read_header(sp, TRUE) != JPEG_HEADER_OK)
return (0);
tif->tif_rawcp = (uint8*) sp->src.next_input_byte;
tif->tif_rawcc = sp->src.bytes_in_buffer;
/*
* Check image parameters and set decompression parameters.
*/
segment_width = td->td_imagewidth;
segment_height = td->td_imagelength - tif->tif_row;
if (isTiled(tif)) {
segment_width = td->td_tilewidth;
segment_height = td->td_tilelength;
sp->bytesperline = TIFFTileRowSize(tif);
} else {
if (segment_height > td->td_rowsperstrip)
segment_height = td->td_rowsperstrip;
sp->bytesperline = TIFFScanlineSize(tif);
}
if (td->td_planarconfig == PLANARCONFIG_SEPARATE && s > 0) {
/*
* For PC 2, scale down the expected strip/tile size
* to match a downsampled component
*/
segment_width = TIFFhowmany_32(segment_width, sp->h_sampling);
segment_height = TIFFhowmany_32(segment_height, sp->v_sampling);
}
if (sp->cinfo.d.image_width < segment_width ||
sp->cinfo.d.image_height < segment_height) {
TIFFWarningExt(tif->tif_clientdata, module,
"Improper JPEG strip/tile size, "
"expected %dx%d, got %dx%d",
segment_width, segment_height,
sp->cinfo.d.image_width,
sp->cinfo.d.image_height);
}
if (sp->cinfo.d.image_width > segment_width ||
sp->cinfo.d.image_height > segment_height) {
/*
* This case could be dangerous, if the strip or tile size has
* been reported as less than the amount of data jpeg will
* return, some potential security issues arise. Catch this
* case and error out.
*/
TIFFErrorExt(tif->tif_clientdata, module,
"JPEG strip/tile size exceeds expected dimensions,"
" expected %dx%d, got %dx%d",
segment_width, segment_height,
sp->cinfo.d.image_width, sp->cinfo.d.image_height);
return (0);
}
if (sp->cinfo.d.num_components !=
(td->td_planarconfig == PLANARCONFIG_CONTIG ?
td->td_samplesperpixel : 1)) {
TIFFErrorExt(tif->tif_clientdata, module, "Improper JPEG component count");
return (0);
}
#ifdef JPEG_LIB_MK1
if (12 != td->td_bitspersample && 8 != td->td_bitspersample) {
TIFFErrorExt(tif->tif_clientdata, module, "Improper JPEG data precision");
return (0);
}
sp->cinfo.d.data_precision = td->td_bitspersample;
sp->cinfo.d.bits_in_jsample = td->td_bitspersample;
#else
if (sp->cinfo.d.data_precision != td->td_bitspersample) {
TIFFErrorExt(tif->tif_clientdata, module, "Improper JPEG data precision");
return (0);
}
#endif
if (td->td_planarconfig == PLANARCONFIG_CONTIG) {
/* Component 0 should have expected sampling factors */
if (sp->cinfo.d.comp_info[0].h_samp_factor != sp->h_sampling ||
sp->cinfo.d.comp_info[0].v_samp_factor != sp->v_sampling) {
TIFFErrorExt(tif->tif_clientdata, module,
"Improper JPEG sampling factors %d,%d\n"
"Apparently should be %d,%d.",
sp->cinfo.d.comp_info[0].h_samp_factor,
sp->cinfo.d.comp_info[0].v_samp_factor,
sp->h_sampling, sp->v_sampling);
return (0);
}
/* Rest should have sampling factors 1,1 */
for (ci = 1; ci < sp->cinfo.d.num_components; ci++) {
if (sp->cinfo.d.comp_info[ci].h_samp_factor != 1 ||
sp->cinfo.d.comp_info[ci].v_samp_factor != 1) {
TIFFErrorExt(tif->tif_clientdata, module, "Improper JPEG sampling factors");
return (0);
}
}
} else {
/* PC 2's single component should have sampling factors 1,1 */
if (sp->cinfo.d.comp_info[0].h_samp_factor != 1 ||
sp->cinfo.d.comp_info[0].v_samp_factor != 1) {
TIFFErrorExt(tif->tif_clientdata, module, "Improper JPEG sampling factors");
return (0);
}
}
downsampled_output = FALSE;
if (td->td_planarconfig == PLANARCONFIG_CONTIG &&
sp->photometric == PHOTOMETRIC_YCBCR &&
sp->jpegcolormode == JPEGCOLORMODE_RGB) {
/* Convert YCbCr to RGB */
sp->cinfo.d.jpeg_color_space = JCS_YCbCr;
sp->cinfo.d.out_color_space = JCS_RGB;
} else {
/* Suppress colorspace handling */
sp->cinfo.d.jpeg_color_space = JCS_UNKNOWN;
sp->cinfo.d.out_color_space = JCS_UNKNOWN;
if (td->td_planarconfig == PLANARCONFIG_CONTIG &&
(sp->h_sampling != 1 || sp->v_sampling != 1))
downsampled_output = TRUE;
/* XXX what about up-sampling? */
}
if (downsampled_output) {
/* Need to use raw-data interface to libjpeg */
sp->cinfo.d.raw_data_out = TRUE;
#if JPEG_LIB_VERSION >= 70
sp->cinfo.d.do_fancy_upsampling = FALSE;
#endif /* JPEG_LIB_VERSION >= 70 */
tif->tif_decoderow = DecodeRowError;
tif->tif_decodestrip = JPEGDecodeRaw;
tif->tif_decodetile = JPEGDecodeRaw;
} else {
/* Use normal interface to libjpeg */
sp->cinfo.d.raw_data_out = FALSE;
tif->tif_decoderow = JPEGDecode;
tif->tif_decodestrip = JPEGDecode;
tif->tif_decodetile = JPEGDecode;
}
/* Start JPEG decompressor */
if (!TIFFjpeg_start_decompress(sp))
return (0);
/* Allocate downsampled-data buffers if needed */
if (downsampled_output) {
if (!alloc_downsampled_buffers(tif, sp->cinfo.d.comp_info,
sp->cinfo.d.num_components))
return (0);
sp->scancount = DCTSIZE; /* mark buffer empty */
}
return (1);
}
/*
* Decode a chunk of pixels.
* "Standard" case: returned data is not downsampled.
*/
/*ARGSUSED*/ static int
JPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
{
JPEGState *sp = JState(tif);
tmsize_t nrows;
(void) s;
/*
** Update available information, buffer may have been refilled
** between decode requests
*/
sp->src.next_input_byte = (const JOCTET*) tif->tif_rawcp;
sp->src.bytes_in_buffer = (size_t) tif->tif_rawcc;
if( sp->bytesperline == 0 )
return 0;
nrows = cc / sp->bytesperline;
if (cc % sp->bytesperline)
TIFFWarningExt(tif->tif_clientdata, tif->tif_name, "fractional scanline not read");
if( nrows > (tmsize_t) sp->cinfo.d.image_height )
nrows = sp->cinfo.d.image_height;
/* data is expected to be read in multiples of a scanline */
if (nrows)
{
JSAMPROW line_work_buf = NULL;
/*
* For 6B, only use temporary buffer for 12 bit imagery.
* For Mk1 always use it.
*/
#if !defined(JPEG_LIB_MK1)
if( sp->cinfo.d.data_precision == 12 )
#endif
{
line_work_buf = (JSAMPROW)
_TIFFmalloc(sizeof(short) * sp->cinfo.d.output_width
* sp->cinfo.d.num_components );
}
do {
if( line_work_buf != NULL )
{
/*
* In the MK1 case, we aways read into a 16bit buffer, and then
* pack down to 12bit or 8bit. In 6B case we only read into 16
* bit buffer for 12bit data, which we need to repack.
*/
if (TIFFjpeg_read_scanlines(sp, &line_work_buf, 1) != 1)
return (0);
if( sp->cinfo.d.data_precision == 12 )
{
int value_pairs = (sp->cinfo.d.output_width
* sp->cinfo.d.num_components) / 2;
int iPair;
for( iPair = 0; iPair < value_pairs; iPair++ )
{
unsigned char *out_ptr =
((unsigned char *) buf) + iPair * 3;
JSAMPLE *in_ptr = line_work_buf + iPair * 2;
out_ptr[0] = (in_ptr[0] & 0xff0) >> 4;
out_ptr[1] = ((in_ptr[0] & 0xf) << 4)
| ((in_ptr[1] & 0xf00) >> 8);
out_ptr[2] = ((in_ptr[1] & 0xff) >> 0);
}
}
else if( sp->cinfo.d.data_precision == 8 )
{
int value_count = (sp->cinfo.d.output_width
* sp->cinfo.d.num_components);
int iValue;
for( iValue = 0; iValue < value_count; iValue++ )
{
((unsigned char *) buf)[iValue] =
line_work_buf[iValue] & 0xff;
}
}
}
else
{
/*
* In the libjpeg6b 8bit case. We read directly into the
* TIFF buffer.
*/
JSAMPROW bufptr = (JSAMPROW)buf;
if (TIFFjpeg_read_scanlines(sp, &bufptr, 1) != 1)
return (0);
}
++tif->tif_row;
buf += sp->bytesperline;
cc -= sp->bytesperline;
} while (--nrows > 0);
if( line_work_buf != NULL )
_TIFFfree( line_work_buf );
}
/* Update information on consumed data */
tif->tif_rawcp = (uint8*) sp->src.next_input_byte;
tif->tif_rawcc = sp->src.bytes_in_buffer;
/* Close down the decompressor if we've finished the strip or tile. */
return sp->cinfo.d.output_scanline < sp->cinfo.d.output_height
|| TIFFjpeg_finish_decompress(sp);
}
/*ARGSUSED*/ static int
DecodeRowError(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
{
(void) buf;
(void) cc;
(void) s;
TIFFErrorExt(tif->tif_clientdata, "TIFFReadScanline",
"scanline oriented access is not supported for downsampled JPEG compressed images, consider enabling TIFF_JPEGCOLORMODE as JPEGCOLORMODE_RGB." );
return 0;
}
/*
* Decode a chunk of pixels.
* Returned data is downsampled per sampling factors.
*/
/*ARGSUSED*/ static int
JPEGDecodeRaw(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
{
JPEGState *sp = JState(tif);
tmsize_t nrows;
(void) s;
/* data is expected to be read in multiples of a scanline */
if ( (nrows = sp->cinfo.d.image_height) ) {
/* Cb,Cr both have sampling factors 1, so this is correct */
JDIMENSION clumps_per_line = sp->cinfo.d.comp_info[1].downsampled_width;
int samples_per_clump = sp->samplesperclump;
#if defined(JPEG_LIB_MK1_OR_12BIT)
unsigned short* tmpbuf = _TIFFmalloc(sizeof(unsigned short) *
sp->cinfo.d.output_width *
sp->cinfo.d.num_components);
if(tmpbuf==NULL) {
TIFFErrorExt(tif->tif_clientdata, "JPEGDecodeRaw",
"Out of memory");
return 0;
}
#endif
do {
jpeg_component_info *compptr;
int ci, clumpoffset;
if( cc < sp->bytesperline ) {
TIFFErrorExt(tif->tif_clientdata, "JPEGDecodeRaw",
"application buffer not large enough for all data.");
return 0;
}
/* Reload downsampled-data buffer if needed */
if (sp->scancount >= DCTSIZE) {
int n = sp->cinfo.d.max_v_samp_factor * DCTSIZE;
if (TIFFjpeg_read_raw_data(sp, sp->ds_buffer, n) != n)
return (0);
sp->scancount = 0;
}
/*
* Fastest way to unseparate data is to make one pass
* over the scanline for each row of each component.
*/
clumpoffset = 0; /* first sample in clump */
for (ci = 0, compptr = sp->cinfo.d.comp_info;
ci < sp->cinfo.d.num_components;
ci++, compptr++) {
int hsamp = compptr->h_samp_factor;
int vsamp = compptr->v_samp_factor;
int ypos;
for (ypos = 0; ypos < vsamp; ypos++) {
JSAMPLE *inptr = sp->ds_buffer[ci][sp->scancount*vsamp + ypos];
JDIMENSION nclump;
#if defined(JPEG_LIB_MK1_OR_12BIT)
JSAMPLE *outptr = (JSAMPLE*)tmpbuf + clumpoffset;
#else
JSAMPLE *outptr = (JSAMPLE*)buf + clumpoffset;
if (cc < (tmsize_t) (clumpoffset + samples_per_clump*(clumps_per_line-1) + hsamp)) {
TIFFErrorExt(tif->tif_clientdata, "JPEGDecodeRaw",
"application buffer not large enough for all data, possible subsampling issue");
return 0;
}
#endif
if (hsamp == 1) {
/* fast path for at least Cb and Cr */
for (nclump = clumps_per_line; nclump-- > 0; ) {
outptr[0] = *inptr++;
outptr += samples_per_clump;
}
} else {
int xpos;
/* general case */
for (nclump = clumps_per_line; nclump-- > 0; ) {
for (xpos = 0; xpos < hsamp; xpos++)
outptr[xpos] = *inptr++;
outptr += samples_per_clump;
}
}
clumpoffset += hsamp;
}
}
#if defined(JPEG_LIB_MK1_OR_12BIT)
{
if (sp->cinfo.d.data_precision == 8)
{
int i=0;
int len = sp->cinfo.d.output_width * sp->cinfo.d.num_components;
for (i=0; i<len; i++)
{
((unsigned char*)buf)[i] = tmpbuf[i] & 0xff;
}
}
else
{ /* 12-bit */
int value_pairs = (sp->cinfo.d.output_width
* sp->cinfo.d.num_components) / 2;
int iPair;
for( iPair = 0; iPair < value_pairs; iPair++ )
{
unsigned char *out_ptr = ((unsigned char *) buf) + iPair * 3;
JSAMPLE *in_ptr = (JSAMPLE *) (tmpbuf + iPair * 2);
out_ptr[0] = (in_ptr[0] & 0xff0) >> 4;
out_ptr[1] = ((in_ptr[0] & 0xf) << 4)
| ((in_ptr[1] & 0xf00) >> 8);
out_ptr[2] = ((in_ptr[1] & 0xff) >> 0);
}
}
}
#endif
sp->scancount ++;
tif->tif_row += sp->v_sampling;
buf += sp->bytesperline;
cc -= sp->bytesperline;
nrows -= sp->v_sampling;
} while (nrows > 0);
#if defined(JPEG_LIB_MK1_OR_12BIT)
_TIFFfree(tmpbuf);
#endif
}
/* Close down the decompressor if done. */
return sp->cinfo.d.output_scanline < sp->cinfo.d.output_height
|| TIFFjpeg_finish_decompress(sp);
}
/*
* JPEG Encoding.
*/
static void
unsuppress_quant_table (JPEGState* sp, int tblno)
{
JQUANT_TBL* qtbl;
if ((qtbl = sp->cinfo.c.quant_tbl_ptrs[tblno]) != NULL)
qtbl->sent_table = FALSE;
}
static void
suppress_quant_table (JPEGState* sp, int tblno)
{
JQUANT_TBL* qtbl;
if ((qtbl = sp->cinfo.c.quant_tbl_ptrs[tblno]) != NULL)
qtbl->sent_table = TRUE;
}
static void
unsuppress_huff_table (JPEGState* sp, int tblno)
{
JHUFF_TBL* htbl;
if ((htbl = sp->cinfo.c.dc_huff_tbl_ptrs[tblno]) != NULL)
htbl->sent_table = FALSE;
if ((htbl = sp->cinfo.c.ac_huff_tbl_ptrs[tblno]) != NULL)
htbl->sent_table = FALSE;
}
static void
suppress_huff_table (JPEGState* sp, int tblno)
{
JHUFF_TBL* htbl;
if ((htbl = sp->cinfo.c.dc_huff_tbl_ptrs[tblno]) != NULL)
htbl->sent_table = TRUE;
if ((htbl = sp->cinfo.c.ac_huff_tbl_ptrs[tblno]) != NULL)
htbl->sent_table = TRUE;
}
static int
prepare_JPEGTables(TIFF* tif)
{
JPEGState* sp = JState(tif);
/* Initialize quant tables for current quality setting */
if (!TIFFjpeg_set_quality(sp, sp->jpegquality, FALSE))
return (0);
/* Mark only the tables we want for output */
/* NB: chrominance tables are currently used only with YCbCr */
if (!TIFFjpeg_suppress_tables(sp, TRUE))
return (0);
if (sp->jpegtablesmode & JPEGTABLESMODE_QUANT) {
unsuppress_quant_table(sp, 0);
if (sp->photometric == PHOTOMETRIC_YCBCR)
unsuppress_quant_table(sp, 1);
}
if (sp->jpegtablesmode & JPEGTABLESMODE_HUFF) {
unsuppress_huff_table(sp, 0);
if (sp->photometric == PHOTOMETRIC_YCBCR)
unsuppress_huff_table(sp, 1);
}
/* Direct libjpeg output into jpegtables */
if (!TIFFjpeg_tables_dest(sp, tif))
return (0);
/* Emit tables-only datastream */
if (!TIFFjpeg_write_tables(sp))
return (0);
return (1);
}
static int
JPEGSetupEncode(TIFF* tif)
{
JPEGState* sp = JState(tif);
TIFFDirectory *td = &tif->tif_dir;
static const char module[] = "JPEGSetupEncode";
#if defined(JPEG_DUAL_MODE_8_12) && !defined(TIFFInitJPEG)
if( tif->tif_dir.td_bitspersample == 12 )
return TIFFReInitJPEG_12( tif, COMPRESSION_JPEG, 1 );
#endif
JPEGInitializeLibJPEG( tif, FALSE );
assert(sp != NULL);
assert(!sp->cinfo.comm.is_decompressor);
sp->photometric = td->td_photometric;
/*
* Initialize all JPEG parameters to default values.
* Note that jpeg_set_defaults needs legal values for
* in_color_space and input_components.
*/
if (td->td_planarconfig == PLANARCONFIG_CONTIG) {
sp->cinfo.c.input_components = td->td_samplesperpixel;
if (sp->photometric == PHOTOMETRIC_YCBCR) {
if (sp->jpegcolormode == JPEGCOLORMODE_RGB) {
sp->cinfo.c.in_color_space = JCS_RGB;
} else {
sp->cinfo.c.in_color_space = JCS_YCbCr;
}
} else {
if ((td->td_photometric == PHOTOMETRIC_MINISWHITE || td->td_photometric == PHOTOMETRIC_MINISBLACK) && td->td_samplesperpixel == 1)
sp->cinfo.c.in_color_space = JCS_GRAYSCALE;
else if (td->td_photometric == PHOTOMETRIC_RGB && td->td_samplesperpixel == 3)
sp->cinfo.c.in_color_space = JCS_RGB;
else if (td->td_photometric == PHOTOMETRIC_SEPARATED && td->td_samplesperpixel == 4)
sp->cinfo.c.in_color_space = JCS_CMYK;
else
sp->cinfo.c.in_color_space = JCS_UNKNOWN;
}
} else {
sp->cinfo.c.input_components = 1;
sp->cinfo.c.in_color_space = JCS_UNKNOWN;
}
if (!TIFFjpeg_set_defaults(sp))
return (0);
/* Set per-file parameters */
switch (sp->photometric) {
case PHOTOMETRIC_YCBCR:
sp->h_sampling = td->td_ycbcrsubsampling[0];
sp->v_sampling = td->td_ycbcrsubsampling[1];
/*
* A ReferenceBlackWhite field *must* be present since the
* default value is inappropriate for YCbCr. Fill in the
* proper value if application didn't set it.
*/
{
float *ref;
if (!TIFFGetField(tif, TIFFTAG_REFERENCEBLACKWHITE,
&ref)) {
float refbw[6];
long top = 1L << td->td_bitspersample;
refbw[0] = 0;
refbw[1] = (float)(top-1L);
refbw[2] = (float)(top>>1);
refbw[3] = refbw[1];
refbw[4] = refbw[2];
refbw[5] = refbw[1];
TIFFSetField(tif, TIFFTAG_REFERENCEBLACKWHITE,
refbw);
}
}
break;
case PHOTOMETRIC_PALETTE: /* disallowed by Tech Note */
case PHOTOMETRIC_MASK:
TIFFErrorExt(tif->tif_clientdata, module,
"PhotometricInterpretation %d not allowed for JPEG",
(int) sp->photometric);
return (0);
default:
/* TIFF 6.0 forbids subsampling of all other color spaces */
sp->h_sampling = 1;
sp->v_sampling = 1;
break;
}
/* Verify miscellaneous parameters */
/*
* This would need work if libtiff ever supports different
* depths for different components, or if libjpeg ever supports
* run-time selection of depth. Neither is imminent.
*/
#ifdef JPEG_LIB_MK1
/* BITS_IN_JSAMPLE now permits 8 and 12 --- dgilbert */
if (td->td_bitspersample != 8 && td->td_bitspersample != 12)
#else
if (td->td_bitspersample != BITS_IN_JSAMPLE )
#endif
{
TIFFErrorExt(tif->tif_clientdata, module, "BitsPerSample %d not allowed for JPEG",
(int) td->td_bitspersample);
return (0);
}
sp->cinfo.c.data_precision = td->td_bitspersample;
#ifdef JPEG_LIB_MK1
sp->cinfo.c.bits_in_jsample = td->td_bitspersample;
#endif
if (isTiled(tif)) {
if ((td->td_tilelength % (sp->v_sampling * DCTSIZE)) != 0) {
TIFFErrorExt(tif->tif_clientdata, module,
"JPEG tile height must be multiple of %d",
sp->v_sampling * DCTSIZE);
return (0);
}
if ((td->td_tilewidth % (sp->h_sampling * DCTSIZE)) != 0) {
TIFFErrorExt(tif->tif_clientdata, module,
"JPEG tile width must be multiple of %d",
sp->h_sampling * DCTSIZE);
return (0);
}
} else {
if (td->td_rowsperstrip < td->td_imagelength &&
(td->td_rowsperstrip % (sp->v_sampling * DCTSIZE)) != 0) {
TIFFErrorExt(tif->tif_clientdata, module,
"RowsPerStrip must be multiple of %d for JPEG",
sp->v_sampling * DCTSIZE);
return (0);
}
}
/* Create a JPEGTables field if appropriate */
if (sp->jpegtablesmode & (JPEGTABLESMODE_QUANT|JPEGTABLESMODE_HUFF)) {
if( sp->jpegtables == NULL
|| memcmp(sp->jpegtables,"\0\0\0\0\0\0\0\0\0",8) == 0 )
{
if (!prepare_JPEGTables(tif))
return (0);
/* Mark the field present */
/* Can't use TIFFSetField since BEENWRITING is already set! */
tif->tif_flags |= TIFF_DIRTYDIRECT;
TIFFSetFieldBit(tif, FIELD_JPEGTABLES);
}
} else {
/* We do not support application-supplied JPEGTables, */
/* so mark the field not present */
TIFFClrFieldBit(tif, FIELD_JPEGTABLES);
}
/* Direct libjpeg output to libtiff's output buffer */
TIFFjpeg_data_dest(sp, tif);
return (1);
}
/*
* Set encoding state at the start of a strip or tile.
*/
static int
JPEGPreEncode(TIFF* tif, uint16 s)
{
JPEGState *sp = JState(tif);
TIFFDirectory *td = &tif->tif_dir;
static const char module[] = "JPEGPreEncode";
uint32 segment_width, segment_height;
int downsampled_input;
assert(sp != NULL);
if (sp->cinfo.comm.is_decompressor == 1)
{
tif->tif_setupencode( tif );
}
assert(!sp->cinfo.comm.is_decompressor);
/*
* Set encoding parameters for this strip/tile.
*/
if (isTiled(tif)) {
segment_width = td->td_tilewidth;
segment_height = td->td_tilelength;
sp->bytesperline = TIFFTileRowSize(tif);
} else {
segment_width = td->td_imagewidth;
segment_height = td->td_imagelength - tif->tif_row;
if (segment_height > td->td_rowsperstrip)
segment_height = td->td_rowsperstrip;
sp->bytesperline = TIFFScanlineSize(tif);
}
if (td->td_planarconfig == PLANARCONFIG_SEPARATE && s > 0) {
/* for PC 2, scale down the strip/tile size
* to match a downsampled component
*/
segment_width = TIFFhowmany_32(segment_width, sp->h_sampling);
segment_height = TIFFhowmany_32(segment_height, sp->v_sampling);
}
if (segment_width > 65535 || segment_height > 65535) {
TIFFErrorExt(tif->tif_clientdata, module, "Strip/tile too large for JPEG");
return (0);
}
sp->cinfo.c.image_width = segment_width;
sp->cinfo.c.image_height = segment_height;
downsampled_input = FALSE;
if (td->td_planarconfig == PLANARCONFIG_CONTIG) {
sp->cinfo.c.input_components = td->td_samplesperpixel;
if (sp->photometric == PHOTOMETRIC_YCBCR) {
if (sp->jpegcolormode != JPEGCOLORMODE_RGB) {
if (sp->h_sampling != 1 || sp->v_sampling != 1)
downsampled_input = TRUE;
}
if (!TIFFjpeg_set_colorspace(sp, JCS_YCbCr))
return (0);
/*
* Set Y sampling factors;
* we assume jpeg_set_colorspace() set the rest to 1
*/
sp->cinfo.c.comp_info[0].h_samp_factor = sp->h_sampling;
sp->cinfo.c.comp_info[0].v_samp_factor = sp->v_sampling;
} else {
if (!TIFFjpeg_set_colorspace(sp, sp->cinfo.c.in_color_space))
return (0);
/* jpeg_set_colorspace set all sampling factors to 1 */
}
} else {
if (!TIFFjpeg_set_colorspace(sp, JCS_UNKNOWN))
return (0);
sp->cinfo.c.comp_info[0].component_id = s;
/* jpeg_set_colorspace() set sampling factors to 1 */
if (sp->photometric == PHOTOMETRIC_YCBCR && s > 0) {
sp->cinfo.c.comp_info[0].quant_tbl_no = 1;
sp->cinfo.c.comp_info[0].dc_tbl_no = 1;
sp->cinfo.c.comp_info[0].ac_tbl_no = 1;
}
}
/* ensure libjpeg won't write any extraneous markers */
sp->cinfo.c.write_JFIF_header = FALSE;
sp->cinfo.c.write_Adobe_marker = FALSE;
/* set up table handling correctly */
/* calling TIFFjpeg_set_quality() causes quantization tables to be flagged */
/* as being to be emitted, which we don't want in the JPEGTABLESMODE_QUANT */
/* mode, so we must manually suppress them. However TIFFjpeg_set_quality() */
/* should really be called when dealing with files with directories with */
/* mixed qualities. see http://trac.osgeo.org/gdal/ticket/3539 */
if (!TIFFjpeg_set_quality(sp, sp->jpegquality, FALSE))
return (0);
if (sp->jpegtablesmode & JPEGTABLESMODE_QUANT) {
suppress_quant_table(sp, 0);
suppress_quant_table(sp, 1);
}
else {
unsuppress_quant_table(sp, 0);
unsuppress_quant_table(sp, 1);
}
if (sp->jpegtablesmode & JPEGTABLESMODE_HUFF)
{
/* Explicit suppression is only needed if we did not go through the */
/* prepare_JPEGTables() code path, which may be the case if updating */
/* an existing file */
suppress_huff_table(sp, 0);
suppress_huff_table(sp, 1);
sp->cinfo.c.optimize_coding = FALSE;
}
else
sp->cinfo.c.optimize_coding = TRUE;
if (downsampled_input) {
/* Need to use raw-data interface to libjpeg */
sp->cinfo.c.raw_data_in = TRUE;
tif->tif_encoderow = JPEGEncodeRaw;
tif->tif_encodestrip = JPEGEncodeRaw;
tif->tif_encodetile = JPEGEncodeRaw;
} else {
/* Use normal interface to libjpeg */
sp->cinfo.c.raw_data_in = FALSE;
tif->tif_encoderow = JPEGEncode;
tif->tif_encodestrip = JPEGEncode;
tif->tif_encodetile = JPEGEncode;
}
/* Start JPEG compressor */
if (!TIFFjpeg_start_compress(sp, FALSE))
return (0);
/* Allocate downsampled-data buffers if needed */
if (downsampled_input) {
if (!alloc_downsampled_buffers(tif, sp->cinfo.c.comp_info,
sp->cinfo.c.num_components))
return (0);
}
sp->scancount = 0;
return (1);
}
/*
* Encode a chunk of pixels.
* "Standard" case: incoming data is not downsampled.
*/
static int
JPEGEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
{
JPEGState *sp = JState(tif);
tmsize_t nrows;
JSAMPROW bufptr[1];
short *line16 = NULL;
int line16_count = 0;
(void) s;
assert(sp != NULL);
/* data is expected to be supplied in multiples of a scanline */
nrows = cc / sp->bytesperline;
if (cc % sp->bytesperline)
TIFFWarningExt(tif->tif_clientdata, tif->tif_name,
"fractional scanline discarded");
/* The last strip will be limited to image size */
if( !isTiled(tif) && tif->tif_row+nrows > tif->tif_dir.td_imagelength )
nrows = tif->tif_dir.td_imagelength - tif->tif_row;
if( sp->cinfo.c.data_precision == 12 )
{
line16_count = (sp->bytesperline * 2) / 3;
line16 = (short *) _TIFFmalloc(sizeof(short) * line16_count);
// FIXME: undiagnosed malloc failure
}
while (nrows-- > 0) {
if( sp->cinfo.c.data_precision == 12 )
{
int value_pairs = line16_count / 2;
int iPair;
bufptr[0] = (JSAMPROW) line16;
for( iPair = 0; iPair < value_pairs; iPair++ )
{
unsigned char *in_ptr =
((unsigned char *) buf) + iPair * 3;
JSAMPLE *out_ptr = (JSAMPLE *) (line16 + iPair * 2);
out_ptr[0] = (in_ptr[0] << 4) | ((in_ptr[1] & 0xf0) >> 4);
out_ptr[1] = ((in_ptr[1] & 0x0f) << 8) | in_ptr[2];
}
}
else
{
bufptr[0] = (JSAMPROW) buf;
}
if (TIFFjpeg_write_scanlines(sp, bufptr, 1) != 1)
return (0);
if (nrows > 0)
tif->tif_row++;
buf += sp->bytesperline;
}
if( sp->cinfo.c.data_precision == 12 )
{
_TIFFfree( line16 );
}
return (1);
}
/*
* Encode a chunk of pixels.
* Incoming data is expected to be downsampled per sampling factors.
*/
static int
JPEGEncodeRaw(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
{
JPEGState *sp = JState(tif);
JSAMPLE* inptr;
JSAMPLE* outptr;
tmsize_t nrows;
JDIMENSION clumps_per_line, nclump;
int clumpoffset, ci, xpos, ypos;
jpeg_component_info* compptr;
int samples_per_clump = sp->samplesperclump;
tmsize_t bytesperclumpline;
(void) s;
assert(sp != NULL);
/* data is expected to be supplied in multiples of a clumpline */
/* a clumpline is equivalent to v_sampling desubsampled scanlines */
/* TODO: the following calculation of bytesperclumpline, should substitute calculation of sp->bytesperline, except that it is per v_sampling lines */
bytesperclumpline = (((sp->cinfo.c.image_width+sp->h_sampling-1)/sp->h_sampling)
*(sp->h_sampling*sp->v_sampling+2)*sp->cinfo.c.data_precision+7)
/8;
nrows = ( cc / bytesperclumpline ) * sp->v_sampling;
if (cc % bytesperclumpline)
TIFFWarningExt(tif->tif_clientdata, tif->tif_name, "fractional scanline discarded");
/* Cb,Cr both have sampling factors 1, so this is correct */
clumps_per_line = sp->cinfo.c.comp_info[1].downsampled_width;
while (nrows > 0) {
/*
* Fastest way to separate the data is to make one pass
* over the scanline for each row of each component.
*/
clumpoffset = 0; /* first sample in clump */
for (ci = 0, compptr = sp->cinfo.c.comp_info;
ci < sp->cinfo.c.num_components;
ci++, compptr++) {
int hsamp = compptr->h_samp_factor;
int vsamp = compptr->v_samp_factor;
int padding = (int) (compptr->width_in_blocks * DCTSIZE -
clumps_per_line * hsamp);
for (ypos = 0; ypos < vsamp; ypos++) {
inptr = ((JSAMPLE*) buf) + clumpoffset;
outptr = sp->ds_buffer[ci][sp->scancount*vsamp + ypos];
if (hsamp == 1) {
/* fast path for at least Cb and Cr */
for (nclump = clumps_per_line; nclump-- > 0; ) {
*outptr++ = inptr[0];
inptr += samples_per_clump;
}
} else {
/* general case */
for (nclump = clumps_per_line; nclump-- > 0; ) {
for (xpos = 0; xpos < hsamp; xpos++)
*outptr++ = inptr[xpos];
inptr += samples_per_clump;
}
}
/* pad each scanline as needed */
for (xpos = 0; xpos < padding; xpos++) {
*outptr = outptr[-1];
outptr++;
}
clumpoffset += hsamp;
}
}
sp->scancount++;
if (sp->scancount >= DCTSIZE) {
int n = sp->cinfo.c.max_v_samp_factor * DCTSIZE;
if (TIFFjpeg_write_raw_data(sp, sp->ds_buffer, n) != n)
return (0);
sp->scancount = 0;
}
tif->tif_row += sp->v_sampling;
buf += bytesperclumpline;
nrows -= sp->v_sampling;
}
return (1);
}
/*
* Finish up at the end of a strip or tile.
*/
static int
JPEGPostEncode(TIFF* tif)
{
JPEGState *sp = JState(tif);
if (sp->scancount > 0) {
/*
* Need to emit a partial bufferload of downsampled data.
* Pad the data vertically.
*/
int ci, ypos, n;
jpeg_component_info* compptr;
for (ci = 0, compptr = sp->cinfo.c.comp_info;
ci < sp->cinfo.c.num_components;
ci++, compptr++) {
int vsamp = compptr->v_samp_factor;
tmsize_t row_width = compptr->width_in_blocks * DCTSIZE
* sizeof(JSAMPLE);
for (ypos = sp->scancount * vsamp;
ypos < DCTSIZE * vsamp; ypos++) {
_TIFFmemcpy((void*)sp->ds_buffer[ci][ypos],
(void*)sp->ds_buffer[ci][ypos-1],
row_width);
}
}
n = sp->cinfo.c.max_v_samp_factor * DCTSIZE;
if (TIFFjpeg_write_raw_data(sp, sp->ds_buffer, n) != n)
return (0);
}
return (TIFFjpeg_finish_compress(JState(tif)));
}
static void
JPEGCleanup(TIFF* tif)
{
JPEGState *sp = JState(tif);
assert(sp != 0);
tif->tif_tagmethods.vgetfield = sp->vgetparent;
tif->tif_tagmethods.vsetfield = sp->vsetparent;
tif->tif_tagmethods.printdir = sp->printdir;
if( sp != NULL ) {
if( sp->cinfo_initialized )
TIFFjpeg_destroy(sp); /* release libjpeg resources */
if (sp->jpegtables) /* tag value */
_TIFFfree(sp->jpegtables);
}
_TIFFfree(tif->tif_data); /* release local state */
tif->tif_data = NULL;
_TIFFSetDefaultCompressionState(tif);
}
static void
JPEGResetUpsampled( TIFF* tif )
{
JPEGState* sp = JState(tif);
TIFFDirectory* td = &tif->tif_dir;
/*
* Mark whether returned data is up-sampled or not so TIFFStripSize
* and TIFFTileSize return values that reflect the true amount of
* data.
*/
tif->tif_flags &= ~TIFF_UPSAMPLED;
if (td->td_planarconfig == PLANARCONFIG_CONTIG) {
if (td->td_photometric == PHOTOMETRIC_YCBCR &&
sp->jpegcolormode == JPEGCOLORMODE_RGB) {
tif->tif_flags |= TIFF_UPSAMPLED;
} else {
#ifdef notdef
if (td->td_ycbcrsubsampling[0] != 1 ||
td->td_ycbcrsubsampling[1] != 1)
; /* XXX what about up-sampling? */
#endif
}
}
/*
* Must recalculate cached tile size in case sampling state changed.
* Should we really be doing this now if image size isn't set?
*/
if( tif->tif_tilesize > 0 )
tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tmsize_t)(-1);
if( tif->tif_scanlinesize > 0 )
tif->tif_scanlinesize = TIFFScanlineSize(tif);
}
static int
JPEGVSetField(TIFF* tif, uint32 tag, va_list ap)
{
JPEGState* sp = JState(tif);
const TIFFField* fip;
uint32 v32;
assert(sp != NULL);
switch (tag) {
case TIFFTAG_JPEGTABLES:
v32 = (uint32) va_arg(ap, uint32);
if (v32 == 0) {
/* XXX */
return (0);
}
_TIFFsetByteArray(&sp->jpegtables, va_arg(ap, void*),
(long) v32);
sp->jpegtables_length = v32;
TIFFSetFieldBit(tif, FIELD_JPEGTABLES);
break;
case TIFFTAG_JPEGQUALITY:
sp->jpegquality = (int) va_arg(ap, int);
return (1); /* pseudo tag */
case TIFFTAG_JPEGCOLORMODE:
sp->jpegcolormode = (int) va_arg(ap, int);
JPEGResetUpsampled( tif );
return (1); /* pseudo tag */
case TIFFTAG_PHOTOMETRIC:
{
int ret_value = (*sp->vsetparent)(tif, tag, ap);
JPEGResetUpsampled( tif );
return ret_value;
}
case TIFFTAG_JPEGTABLESMODE:
sp->jpegtablesmode = (int) va_arg(ap, int);
return (1); /* pseudo tag */
case TIFFTAG_YCBCRSUBSAMPLING:
/* mark the fact that we have a real ycbcrsubsampling! */
sp->ycbcrsampling_fetched = 1;
/* should we be recomputing upsampling info here? */
return (*sp->vsetparent)(tif, tag, ap);
default:
return (*sp->vsetparent)(tif, tag, ap);
}
if ((fip = TIFFFieldWithTag(tif, tag))) {
TIFFSetFieldBit(tif, fip->field_bit);
} else {
return (0);
}
tif->tif_flags |= TIFF_DIRTYDIRECT;
return (1);
}
static int
JPEGVGetField(TIFF* tif, uint32 tag, va_list ap)
{
JPEGState* sp = JState(tif);
assert(sp != NULL);
switch (tag) {
case TIFFTAG_JPEGTABLES:
*va_arg(ap, uint32*) = sp->jpegtables_length;
*va_arg(ap, void**) = sp->jpegtables;
break;
case TIFFTAG_JPEGQUALITY:
*va_arg(ap, int*) = sp->jpegquality;
break;
case TIFFTAG_JPEGCOLORMODE:
*va_arg(ap, int*) = sp->jpegcolormode;
break;
case TIFFTAG_JPEGTABLESMODE:
*va_arg(ap, int*) = sp->jpegtablesmode;
break;
default:
return (*sp->vgetparent)(tif, tag, ap);
}
return (1);
}
static void
JPEGPrintDir(TIFF* tif, FILE* fd, long flags)
{
JPEGState* sp = JState(tif);
assert(sp != NULL);
(void) flags;
if( sp != NULL ) {
if (TIFFFieldSet(tif,FIELD_JPEGTABLES))
fprintf(fd, " JPEG Tables: (%lu bytes)\n",
(unsigned long) sp->jpegtables_length);
if (sp->printdir)
(*sp->printdir)(tif, fd, flags);
}
}
static uint32
JPEGDefaultStripSize(TIFF* tif, uint32 s)
{
JPEGState* sp = JState(tif);
TIFFDirectory *td = &tif->tif_dir;
s = (*sp->defsparent)(tif, s);
if (s < td->td_imagelength)
s = TIFFroundup_32(s, td->td_ycbcrsubsampling[1] * DCTSIZE);
return (s);
}
static void
JPEGDefaultTileSize(TIFF* tif, uint32* tw, uint32* th)
{
JPEGState* sp = JState(tif);
TIFFDirectory *td = &tif->tif_dir;
(*sp->deftparent)(tif, tw, th);
*tw = TIFFroundup_32(*tw, td->td_ycbcrsubsampling[0] * DCTSIZE);
*th = TIFFroundup_32(*th, td->td_ycbcrsubsampling[1] * DCTSIZE);
}
/*
* The JPEG library initialized used to be done in TIFFInitJPEG(), but
* now that we allow a TIFF file to be opened in update mode it is necessary
* to have some way of deciding whether compression or decompression is
* desired other than looking at tif->tif_mode. We accomplish this by
* examining {TILE/STRIP}BYTECOUNTS to see if there is a non-zero entry.
* If so, we assume decompression is desired.
*
* This is tricky, because TIFFInitJPEG() is called while the directory is
* being read, and generally speaking the BYTECOUNTS tag won't have been read
* at that point. So we try to defer jpeg library initialization till we
* do have that tag ... basically any access that might require the compressor
* or decompressor that occurs after the reading of the directory.
*
* In an ideal world compressors or decompressors would be setup
* at the point where a single tile or strip was accessed (for read or write)
* so that stuff like update of missing tiles, or replacement of tiles could
* be done. However, we aren't trying to crack that nut just yet ...
*
* NFW, Feb 3rd, 2003.
*/
static int JPEGInitializeLibJPEG( TIFF * tif, int decompress )
{
JPEGState* sp = JState(tif);
if(sp->cinfo_initialized)
{
if( !decompress && sp->cinfo.comm.is_decompressor )
TIFFjpeg_destroy( sp );
else if( decompress && !sp->cinfo.comm.is_decompressor )
TIFFjpeg_destroy( sp );
else
return 1;
sp->cinfo_initialized = 0;
}
/*
* Initialize libjpeg.
*/
if ( decompress ) {
if (!TIFFjpeg_create_decompress(sp))
return (0);
} else {
if (!TIFFjpeg_create_compress(sp))
return (0);
}
sp->cinfo_initialized = TRUE;
return 1;
}
int
TIFFInitJPEG(TIFF* tif, int scheme)
{
JPEGState* sp;
assert(scheme == COMPRESSION_JPEG);
/*
* Merge codec-specific tag information.
*/
if (!_TIFFMergeFields(tif, jpegFields, TIFFArrayCount(jpegFields))) {
TIFFErrorExt(tif->tif_clientdata,
"TIFFInitJPEG",
"Merging JPEG codec-specific tags failed");
return 0;
}
/*
* Allocate state block so tag methods have storage to record values.
*/
tif->tif_data = (uint8*) _TIFFmalloc(sizeof (JPEGState));
if (tif->tif_data == NULL) {
TIFFErrorExt(tif->tif_clientdata,
"TIFFInitJPEG", "No space for JPEG state block");
return 0;
}
_TIFFmemset(tif->tif_data, 0, sizeof(JPEGState));
sp = JState(tif);
sp->tif = tif; /* back link */
/*
* Override parent get/set field methods.
*/
sp->vgetparent = tif->tif_tagmethods.vgetfield;
tif->tif_tagmethods.vgetfield = JPEGVGetField; /* hook for codec tags */
sp->vsetparent = tif->tif_tagmethods.vsetfield;
tif->tif_tagmethods.vsetfield = JPEGVSetField; /* hook for codec tags */
sp->printdir = tif->tif_tagmethods.printdir;
tif->tif_tagmethods.printdir = JPEGPrintDir; /* hook for codec tags */
/* Default values for codec-specific fields */
sp->jpegtables = NULL;
sp->jpegtables_length = 0;
sp->jpegquality = 75; /* Default IJG quality */
sp->jpegcolormode = JPEGCOLORMODE_RAW;
sp->jpegtablesmode = JPEGTABLESMODE_QUANT | JPEGTABLESMODE_HUFF;
sp->ycbcrsampling_fetched = 0;
/*
* Install codec methods.
*/
tif->tif_fixuptags = JPEGFixupTags;
tif->tif_setupdecode = JPEGSetupDecode;
tif->tif_predecode = JPEGPreDecode;
tif->tif_decoderow = JPEGDecode;
tif->tif_decodestrip = JPEGDecode;
tif->tif_decodetile = JPEGDecode;
tif->tif_setupencode = JPEGSetupEncode;
tif->tif_preencode = JPEGPreEncode;
tif->tif_postencode = JPEGPostEncode;
tif->tif_encoderow = JPEGEncode;
tif->tif_encodestrip = JPEGEncode;
tif->tif_encodetile = JPEGEncode;
tif->tif_cleanup = JPEGCleanup;
sp->defsparent = tif->tif_defstripsize;
tif->tif_defstripsize = JPEGDefaultStripSize;
sp->deftparent = tif->tif_deftilesize;
tif->tif_deftilesize = JPEGDefaultTileSize;
tif->tif_flags |= TIFF_NOBITREV; /* no bit reversal, please */
sp->cinfo_initialized = FALSE;
/*
** Create a JPEGTables field if no directory has yet been created.
** We do this just to ensure that sufficient space is reserved for
** the JPEGTables field. It will be properly created the right
** size later.
*/
if( tif->tif_diroff == 0 )
{
#define SIZE_OF_JPEGTABLES 2000
/*
The following line assumes incorrectly that all JPEG-in-TIFF files will have
a JPEGTABLES tag generated and causes null-filled JPEGTABLES tags to be written
when the JPEG data is placed with TIFFWriteRawStrip. The field bit should be
set, anyway, later when actual JPEGTABLES header is generated, so removing it
here hopefully is harmless.
TIFFSetFieldBit(tif, FIELD_JPEGTABLES);
*/
sp->jpegtables_length = SIZE_OF_JPEGTABLES;
sp->jpegtables = (void *) _TIFFmalloc(sp->jpegtables_length);
// FIXME: NULL-deref after malloc failure
_TIFFmemset(sp->jpegtables, 0, SIZE_OF_JPEGTABLES);
#undef SIZE_OF_JPEGTABLES
}
return 1;
}
#endif /* JPEG_SUPPORT */
/* vim: set ts=8 sts=8 sw=8 noet: */
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
|
QuaternionMark/COMP371-FinalProject | Src/Primitives/Quad.h | #ifndef QUAD_H_INCLUDED
#define QUAD_H_INCLUDED
class Shader;
class Mesh;
class Quad {
private:
float quadVertices[16] = {
// positions // texture Coords
-1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, -1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, -1.0f, 1.0f, 0.0f,
};
Mesh* mesh;
public:
Quad(Shader* shd);
void render();
};
#endif // QUAD_H_INCLUDED
|
QuaternionMark/COMP371-FinalProject | Src/Utils/InputUtil.h | #ifndef INPUTUTIL_H_INCLUDED
#define INPUTUTIL_H_INCLUDED
struct GLFWwindow;
class InputUtil {
public:
static bool keyHit(GLFWwindow* window, int key, int& lastKeyState);
};
#endif // INPUTUTIL_H_INCLUDED
|
QuaternionMark/COMP371-FinalProject | Src/Primitives/Grid.h | <reponame>QuaternionMark/COMP371-FinalProject
#ifndef GRID_H_INCLUDED
#define GRID_H_INCLUDED
#include <vector>
#include "../Graphics/Shader.h"
class Mesh;
class Grid {
private:
const float vertices[32] = {
// Positions // Normals // UV Coords
-1.f, 0.f, -1.f, 0.f, 1.f, 0.f, 0.f, 0.f,
-1.f, 0.f, 1.f, 0.f, 1.f, 0.f, 0.f, 1.f,
1.f, 0.f, -1.f, 0.f, 1.f, 0.f, 1.f, 0.f,
1.f, 0.f, 1.f, 0.f, 1.f, 0.f, 1.f, 1.f
};
Mesh* mesh;
Shader::Uniform* worldMat;
Shader::Uniform* colorUniform;
public:
Vector4f color;
Vector3f scale;
Grid(Shader* shd);
void setShader(Shader* shd);
void render();
};
#endif // GRID_H_INCLUDED
|
QuaternionMark/COMP371-FinalProject | Src/Utils/Timing.h | <filename>Src/Utils/Timing.h
#ifndef TIMING_H_INCLUDED
#define TIMING_H_INCLUDED
#include <chrono>
class Timing {
private:
// The maximum amount of time the accumulator can store.
const double MAX_ACCUMULATED_SECONDS = 1.0;
double timeStep;
double accumulatedSeconds;
// Total time since the object's initialization.
std::chrono::high_resolution_clock::time_point initialTime;
// Previous time when the last call to getElapsedSeconds() was made.
std::chrono::high_resolution_clock::time_point prevTime;
public:
Timing(int tickrate);
~Timing()=default;
double getTimeStep() const;
void addSecondsToAccumulator(double seconds);
// Returns whether enough time is left on the accumulator for another tick.
bool tickReady();
// Subtracts one tick from the accumlator.
void subtractTick();
// Returns the elapsed seconds since the last call to this function.
double getElapsedSeconds();
// Returns the total elapsed time since the object's creation.
double getTotalElapsedTime();
};
#endif // TIMING_H_INCLUDED
|
QuaternionMark/COMP371-FinalProject | Libraries/FreeImage-3170/Examples/Generic/FIIO_Mem.h | /*--------------------------------------------------------------------------*\
|| fiio_mem.h by <NAME> <<EMAIL>> ||
|| ||
|| (v1.02) 4-28-2004 ||
|| FreeImageIO to memory ||
|| ||
\*--------------------------------------------------------------------------*/
#ifndef _FIIO_MEM_H_
#define _FIIO_MEM_H_
#include "freeimage.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct fiio_mem_handle_s {
long filelen,datalen,curpos;
void *data;
} fiio_mem_handle;
/* it is up to the user to create a fiio_mem_handle and init datalen and data
* filelen will be pre-set to 0 by SaveToMem
* curpos will be pre-set to 0 by SaveToMem and LoadFromMem
* IMPORTANT: data should be set to NULL and datalen to 0,
* unless the user wants to manually malloc a larger buffer
*/
FIBITMAP *FreeImage_LoadFromMem(FREE_IMAGE_FORMAT fif, fiio_mem_handle *handle, int flags);
BOOL FreeImage_SaveToMem(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, fiio_mem_handle *handle, int flags);
void SetMemIO(FreeImageIO *io);
unsigned fiio_mem_ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle);
unsigned fiio_mem_WriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle);
int fiio_mem_SeekProc(fi_handle handle, long offset, int origin);
long fiio_mem_TellProc(fi_handle handle);
/*** Example Usage ***
//variables
FIBITMAP *bitmap, *bitmap2;
fiio_mem_handle fmh;
//important initialization
fmh.data = NULL;
fmh.datalen = 0;
//load a regular file
bitmap = FreeImage_Load(FIF_PNG, "sample.png");
//save the file to memory
FreeImage_SaveToMem(FIF_PNG, bitmap, &fmh, 0);
//at this point, fmh.data contains the entire PNG data in memory
//fmh.datalen is the amount of space malloc'd for the image in memory,
//but only fmh.filelen amount of that space is actually used.
//its easy load an image from memory as well
bitmap2 = FreeImage_LoadFromMem(FIF_PNG, &fmh, 0);
//you could also have image data in memory via some other method, and just set
//fmh.data to point to it, and set both fmh.datalen and fmh.filelen to the
//size of that data, then FreeImage_LoadFromMem could load the image from that
//memory
//make sure to free the data since SaveToMem will cause it to be malloc'd
free(fmh.data);
*/
#ifdef __cplusplus
}
#endif
#endif
|
QuaternionMark/COMP371-FinalProject | Libraries/FreeImage-3170/Source/OpenEXR/IlmImf/ImfArray.h | <filename>Libraries/FreeImage-3170/Source/OpenEXR/IlmImf/ImfArray.h
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_IMF_ARRAY_H
#define INCLUDED_IMF_ARRAY_H
#include "ImfForward.h"
//-------------------------------------------------------------------------
//
// class Array
// class Array2D
//
// "Arrays of T" whose sizes are not known at compile time.
// When an array goes out of scope, its elements are automatically
// deleted.
//
// Usage example:
//
// struct C
// {
// C () {std::cout << "C::C (" << this << ")\n";};
// virtual ~C () {std::cout << "C::~C (" << this << ")\n";};
// };
//
// int
// main ()
// {
// Array <C> a(3);
//
// C &b = a[1];
// const C &c = a[1];
// C *d = a + 2;
// const C *e = a;
//
// return 0;
// }
//
//-------------------------------------------------------------------------
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
template <class T>
class Array
{
public:
//-----------------------------
// Constructors and destructors
//-----------------------------
Array () {_data = 0; _size = 0;}
Array (long size) {_data = new T[size]; _size = size;}
~Array () {delete [] _data;}
//-----------------------------
// Access to the array elements
//-----------------------------
operator T * () {return _data;}
operator const T * () const {return _data;}
//------------------------------------------------------
// Resize and clear the array (the contents of the array
// are not preserved across the resize operation).
//
// resizeEraseUnsafe() is more memory efficient than
// resizeErase() because it deletes the old memory block
// before allocating a new one, but if allocating the
// new block throws an exception, resizeEraseUnsafe()
// leaves the array in an unusable state.
//
//------------------------------------------------------
void resizeErase (long size);
void resizeEraseUnsafe (long size);
//-------------------------------
// Return the size of this array.
//-------------------------------
long size() const {return _size;}
private:
Array (const Array &); // Copying and assignment
Array & operator = (const Array &); // are not implemented
long _size;
T * _data;
};
template <class T>
class Array2D
{
public:
//-----------------------------
// Constructors and destructors
//-----------------------------
Array2D (); // empty array, 0 by 0 elements
Array2D (long sizeX, long sizeY); // sizeX by sizeY elements
~Array2D ();
//-----------------------------
// Access to the array elements
//-----------------------------
T * operator [] (long x);
const T * operator [] (long x) const;
//------------------------------------------------------
// Resize and clear the array (the contents of the array
// are not preserved across the resize operation).
//
// resizeEraseUnsafe() is more memory efficient than
// resizeErase() because it deletes the old memory block
// before allocating a new one, but if allocating the
// new block throws an exception, resizeEraseUnsafe()
// leaves the array in an unusable state.
//
//------------------------------------------------------
void resizeErase (long sizeX, long sizeY);
void resizeEraseUnsafe (long sizeX, long sizeY);
//-------------------------------
// Return the size of this array.
//-------------------------------
long height() const {return _sizeX;}
long width() const {return _sizeY;}
private:
Array2D (const Array2D &); // Copying and assignment
Array2D & operator = (const Array2D &); // are not implemented
long _sizeX;
long _sizeY;
T * _data;
};
//---------------
// Implementation
//---------------
template <class T>
inline void
Array<T>::resizeErase (long size)
{
T *tmp = new T[size];
delete [] _data;
_size = size;
_data = tmp;
}
template <class T>
inline void
Array<T>::resizeEraseUnsafe (long size)
{
delete [] _data;
_data = 0;
_size = 0;
_data = new T[size];
_size = size;
}
template <class T>
inline
Array2D<T>::Array2D ():
_sizeX(0), _sizeY (0), _data (0)
{
// emtpy
}
template <class T>
inline
Array2D<T>::Array2D (long sizeX, long sizeY):
_sizeX (sizeX), _sizeY (sizeY), _data (new T[sizeX * sizeY])
{
// emtpy
}
template <class T>
inline
Array2D<T>::~Array2D ()
{
delete [] _data;
}
template <class T>
inline T *
Array2D<T>::operator [] (long x)
{
return _data + x * _sizeY;
}
template <class T>
inline const T *
Array2D<T>::operator [] (long x) const
{
return _data + x * _sizeY;
}
template <class T>
inline void
Array2D<T>::resizeErase (long sizeX, long sizeY)
{
T *tmp = new T[sizeX * sizeY];
delete [] _data;
_sizeX = sizeX;
_sizeY = sizeY;
_data = tmp;
}
template <class T>
inline void
Array2D<T>::resizeEraseUnsafe (long sizeX, long sizeY)
{
delete [] _data;
_data = 0;
_sizeX = 0;
_sizeY = 0;
_data = new T[sizeX * sizeY];
_sizeX = sizeX;
_sizeY = sizeY;
}
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
#endif
|
QuaternionMark/COMP371-FinalProject | Src/Graphics/Texture.h | #ifndef TEXTURE_H_INCLUDED
#define TEXTURE_H_INCLUDED
#include <GL/glew.h>
#include "../Utils/String.h"
class Shader;
class Texture {
private:
String filePath;
GLuint textureID;
public:
Texture(const String& path);
~Texture();
void activate(int index) const;
};
#endif // TEXTURE_H_INCLUDED
|
QuaternionMark/COMP371-FinalProject | Src/Graphics/Mesh.h | #ifndef MESH_H_INCLUDED
#define MESH_H_INCLUDED
#include <GL/glew.h>
#include <vector>
class Shader;
class Mesh {
private:
GLuint vertexArrayObject = 0;
GLuint vertexBufferObject = 0;
GLuint primitiveBuffer = 0;
std::vector<float> vertexData;
std::vector<int> primData;
Shader* shader;
GLenum mode;
bool needsUpload;
void uploadData();
public:
Mesh(Shader* shd);
~Mesh();
void setGeometry(std::vector<float>& vertices, std::vector<int>& primitives, GLenum mod = GL_TRIANGLES);
void setShader(Shader* shd);
void render();
};
#endif // MESH_H_INCLUDED
|
QuaternionMark/COMP371-FinalProject | Libraries/FreeImage-3170/Source/OpenEXR/IlmImf/ImfMisc.h | ///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_IMF_MISC_H
#define INCLUDED_IMF_MISC_H
//-----------------------------------------------------------------------------
//
// Miscellaneous helper functions for OpenEXR image file I/O
//
//-----------------------------------------------------------------------------
#include "ImfPixelType.h"
#include "ImfCompressor.h"
#include "ImfArray.h"
#include "ImfNamespace.h"
#include "ImfExport.h"
#include "ImfForward.h"
#include <cstddef>
#include <vector>
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
//
// Return the size of a single value of the indicated type,
// in the machine's native format.
//
IMF_EXPORT
int pixelTypeSize (PixelType type);
//
// Return the number of samples a channel with subsampling rate
// s has in the interval [a, b]. For example, a channel with
// subsampling rate 2 (and samples at 0, 2, 4, 6, 8, etc.) has
// 2 samples in the interval [1, 5] and three samples in the
// interval [2, 6].
//
IMF_EXPORT
int numSamples (int s, int a, int b);
//
// Build a table that lists, for each scanline in a file's
// data window, how many bytes are required to store all
// pixels in all channels in that scanline (assuming that
// the pixel data are tightly packed).
//
IMF_EXPORT
size_t bytesPerLineTable (const Header &header,
std::vector<size_t> &bytesPerLine);
//
// Get the sample count for pixel (x, y) using the array base
// pointer, xStride and yStride.
//
IMF_EXPORT
int&
sampleCount(char* base, int xStride, int yStride, int x, int y);
IMF_EXPORT
const int&
sampleCount(const char* base, int xStride, int yStride, int x, int y);
//
// Build a table that lists, for each scanline in a DEEP file's
// data window, how many bytes are required to store all
// pixels in all channels in scanlines ranged in [minY, maxY]
// (assuming that the pixel data are tightly packed).
//
IMF_EXPORT
size_t bytesPerDeepLineTable (const Header &header,
int minY, int maxY,
const char* base,
int xStride,
int yStride,
std::vector<size_t> &bytesPerLine);
//
// Build a table that lists, for each scanline in a DEEP file's
// data window, how many bytes are required to store all
// pixels in all channels in every scanline (assuming that
// the pixel data are tightly packed).
//
IMF_EXPORT
size_t bytesPerDeepLineTable (const Header &header,
char* base,
int xStride,
int yStride,
std::vector<size_t> &bytesPerLine);
//
// For scanline-based files, pixels are read or written in
// in multi-scanline blocks. Internally, class OutputFile
// and class ScanLineInputFile store a block of scan lines
// in a "line buffer". Function offsetInLineBufferTable()
// builds a table that lists, scanlines within range
// [scanline1, scanline2], the location of the pixel data
// for the scanline relative to the beginning of the line buffer,
// where scanline1 = 0 represents the first line in the DATA WINDOW.
// The one without specifying the range will make scanline1 = 0
// and scanline2 = bytesPerLine.size().
//
IMF_EXPORT
void offsetInLineBufferTable (const std::vector<size_t> &bytesPerLine,
int scanline1, int scanline2,
int linesInLineBuffer,
std::vector<size_t> &offsetInLineBuffer);
IMF_EXPORT
void offsetInLineBufferTable (const std::vector<size_t> &bytesPerLine,
int linesInLineBuffer,
std::vector<size_t> &offsetInLineBuffer);
//
// For a scanline-based file, compute the range of scanlines
// that occupy the same line buffer as a given scanline, y.
// (minY is the minimum y coordinate of the file's data window.)
//
IMF_EXPORT int lineBufferMinY (int y, int minY, int linesInLineBuffer);
IMF_EXPORT int lineBufferMaxY (int y, int minY, int linesInLineBuffer);
//
// Return a compressor's data format (Compressor::NATIVE or Compressor::XDR).
// If compressor is 0, return Compressor::XDR.
//
IMF_EXPORT
Compressor::Format defaultFormat (Compressor *compressor);
//
// Return the number of scan lines a compressor wants to compress
// or uncompress at once. If compressor is 0, return 1.
//
IMF_EXPORT
int numLinesInBuffer (Compressor *compressor);
//
// Copy a single channel of a horizontal row of pixels from an
// input file's internal line buffer or tile buffer into a
// frame buffer slice. If necessary, perform on-the-fly data
// type conversion.
//
// readPtr initially points to the beginning of the
// data in the line or tile buffer. readPtr
// is advanced as the pixel data are copied;
// when copyIntoFrameBuffer() returns,
// readPtr points just past the end of the
// copied data.
//
// writePtr, endPtr point to the lefmost and rightmost pixels
// in the frame buffer slice
//
// xStride the xStride for the frame buffer slice
//
// format indicates if the line or tile buffer is
// in NATIVE or XDR format.
//
// typeInFrameBuffer the pixel data type of the frame buffer slice
//
// typeInFile the pixel data type in the input file's channel
//
IMF_EXPORT
void copyIntoFrameBuffer (const char *&readPtr,
char *writePtr,
char *endPtr,
size_t xStride,
bool fill,
double fillValue,
Compressor::Format format,
PixelType typeInFrameBuffer,
PixelType typeInFile);
//
// Copy a single channel of a horizontal row of pixels from an
// input file's internal line buffer or tile buffer into a
// frame buffer slice. If necessary, perform on-the-fly data
// type conversion.
//
// readPtr initially points to the beginning of the
// data in the line or tile buffer. readPtr
// is advanced as the pixel data are copied;
// when copyIntoFrameBuffer() returns,
// readPtr points just past the end of the
// copied data.
//
// base point to each pixel in the framebuffer
//
// sampleCountBase, provide the number of samples in each pixel
// sampleCountXStride,
// sampleCountYStride
//
// y the scanline to copy. The coordinate is
// relative to the datawindow.min.y.
//
// minX, maxX used to indicate which pixels in the scanline
// will be copied.
//
// xOffsetForSampleCount, used to offset the sample count array
// yOffsetForSampleCount, and the base array.
// xOffsetForData,
// yOffsetForData
//
// xStride the xStride for the frame buffer slice
//
// format indicates if the line or tile buffer is
// in NATIVE or XDR format.
//
// typeInFrameBuffer the pixel data type of the frame buffer slice
//
// typeInFile the pixel data type in the input file's channel
//
IMF_EXPORT
void copyIntoDeepFrameBuffer (const char *& readPtr,
char * base,
const char* sampleCountBase,
ptrdiff_t sampleCountXStride,
ptrdiff_t sampleCountYStride,
int y, int minX, int maxX,
int xOffsetForSampleCount,
int yOffsetForSampleCount,
int xOffsetForData,
int yOffsetForData,
ptrdiff_t xStride,
ptrdiff_t xPointerStride,
ptrdiff_t yPointerStride,
bool fill,
double fillValue,
Compressor::Format format,
PixelType typeInFrameBuffer,
PixelType typeInFile);
//
// Given a pointer into a an input file's line buffer or tile buffer,
// skip over the data for xSize pixels of type typeInFile.
// readPtr initially points to the beginning of the data to be skipped;
// when skipChannel() returns, readPtr points just past the end of the
// skipped data.
//
IMF_EXPORT
void skipChannel (const char *&readPtr,
PixelType typeInFile,
size_t xSize);
//
// Convert an array of pixel data from the machine's native
// representation to XDR format.
//
// toPtr, fromPtr initially point to the beginning of the input
// and output pixel data arrays; when convertInPlace()
// returns, toPtr and fromPtr point just past the
// end of the input and output arrays.
// If the native representation of the data has the
// same size as the XDR data, then the conversion
// can take in place, without an intermediate
// temporary buffer (toPtr and fromPtr can point
// to the same location).
//
// type the pixel data type
//
// numPixels number of pixels in the input and output arrays
//
IMF_EXPORT
void convertInPlace (char *&toPtr,
const char *&fromPtr,
PixelType type,
size_t numPixels);
//
// Copy a single channel of a horizontal row of pixels from a
// a frame buffer into an output file's internal line buffer or
// tile buffer.
//
// writePtr initially points to the beginning of the
// data in the line or tile buffer. writePtr
// is advanced as the pixel data are copied;
// when copyFromFrameBuffer() returns,
// writePtr points just past the end of the
// copied data.
//
// readPtr, endPtr point to the lefmost and rightmost pixels
// in the frame buffer slice
//
// xStride the xStride for the frame buffer slice
//
// format indicates if the line or tile buffer is
// in NATIVE or XDR format.
//
// type the pixel data type in the frame buffer
// and in the output file's channel (function
// copyFromFrameBuffer() doesn't do on-the-fly
// data type conversion)
//
IMF_EXPORT
void copyFromFrameBuffer (char *&writePtr,
const char *&readPtr,
const char *endPtr,
size_t xStride,
Compressor::Format format,
PixelType type);
//
// Copy a single channel of a horizontal row of pixels from a
// a frame buffer in a deep data file into an output file's
// internal line buffer or tile buffer.
//
// writePtr initially points to the beginning of the
// data in the line or tile buffer. writePtr
// is advanced as the pixel data are copied;
// when copyFromDeepFrameBuffer() returns,
// writePtr points just past the end of the
// copied data.
//
// base the start pointer of each pixel in this channel.
// It points to the real data in FrameBuffer.
// It is different for different channels.
// dataWindowMinX and dataWindowMinY are involved in
// locating for base.
//
// sampleCountBase, used to locate the position to get
// sampleCountXStride, the number of samples for each pixel.
// sampleCountYStride Used to determine how far we should
// read based on the pointer provided by base.
//
// y the scanline to copy. If we are dealing
// with a tiled deep file, then probably a portion
// of the scanline is copied.
//
// xMin, xMax used to indicate which pixels in the scanline
// will be copied.
//
// xOffsetForSampleCount, used to offset the sample count array
// yOffsetForSampleCount, and the base array.
// xOffsetForData,
// yOffsetForData
//
// xStride the xStride for the frame buffer slice
//
// format indicates if the line or tile buffer is
// in NATIVE or XDR format.
//
// type the pixel data type in the frame buffer
// and in the output file's channel (function
// copyFromFrameBuffer() doesn't do on-the-fly
// data type conversion)
//
IMF_EXPORT
void copyFromDeepFrameBuffer (char *& writePtr,
const char * base,
char* sampleCountBase,
ptrdiff_t sampleCountXStride,
ptrdiff_t sampleCountYStride,
int y, int xMin, int xMax,
int xOffsetForSampleCount,
int yOffsetForSampleCount,
int xOffsetForData,
int yOffsetForData,
ptrdiff_t sampleStride,
ptrdiff_t xStrideForData,
ptrdiff_t yStrideForData,
Compressor::Format format,
PixelType type);
//
// Fill part of an output file's line buffer or tile buffer with
// zeroes. This routine is called when an output file contains
// a channel for which the frame buffer contains no corresponding
// slice.
//
// writePtr initially points to the beginning of the
// data in the line or tile buffer. When
// fillChannelWithZeroes() returns, writePtr
// points just past the end of the zeroed
// data.
//
// format indicates if the line or tile buffer is
// in NATIVE or XDR format.
//
// type the pixel data type in the line or frame buffer.
//
// xSize number of pixels to be filled with zeroes.
//
IMF_EXPORT
void fillChannelWithZeroes (char *&writePtr,
Compressor::Format format,
PixelType type,
size_t xSize);
IMF_EXPORT
bool usesLongNames (const Header &header);
//
// compute size of chunk offset table - if ignore_attribute set to true
// will compute from the image size and layout, rather than the attribute
// The default behaviour is to read the attribute
//
IMF_EXPORT
int getChunkOffsetTableSize(const Header& header,bool ignore_attribute=false);
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
#endif
|
QuaternionMark/COMP371-FinalProject | Src/Objects/RectCollider.h | <filename>Src/Objects/RectCollider.h
#ifndef RECTCOLLIDER_H_INCLUDED
#define RECTCOLLIDER_H_INCLUDED
#include "../Math/Vector.h"
#include "../Math/Matrix.h"
#include "../Math/Line.h"
#include "../Graphics/Shader.h"
class Mesh;
class RectCollider {
public:
enum class CollisionDir {
None = -1,
Top = 0,
Right = 1,
Bottom = 2,
Left = 3
};
private:
Vector2f topLeft;
Vector2f topRight;
Vector2f bottomLeft;
Vector2f bottomRight;
Line2f top;
Line2f right;
Line2f bottom;
Line2f left;
Mesh* mesh;
Matrix4x4f worldMatrix;
Shader::Uniform* worldMatrixUniform;
Shader::Uniform* colorUniform;
static Vector2f transformXZCoordinates(const Vector2f& xzCoordinates, const Matrix4x4f& worldMatrix);
static bool lineSegmentIntersectsCollider(const Line2f& line, const RectCollider* other, CollisionDir& collisionSide);
public:
RectCollider()=default;
RectCollider(const Vector2f& tl, const Vector2f& tr, const Vector2f& bl, const Vector2f& br, Shader* shd);
~RectCollider();
bool collides(const RectCollider* other, CollisionDir& collisionSide) const;
void update(const Matrix4x4f& worldMatrix);
void render() const;
};
const RectCollider::CollisionDir operator&(const RectCollider::CollisionDir& a, const RectCollider::CollisionDir& b);
const RectCollider::CollisionDir operator|(const RectCollider::CollisionDir& a, const RectCollider::CollisionDir& b);
#endif // RECTCOLLIDER_H_INCLUDED
|
QuaternionMark/COMP371-FinalProject | Src/Math/Matrix.h | /**
Modified from https://github.com/juanjp600/pge.
Copyright (c) 2019 <NAME>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
**/
#ifndef MATRIX_H_INCLUDED
#define MATRIX_H_INCLUDED
#include "Vector.h"
class Matrix4x4f {
public:
float elements[4][4];
Matrix4x4f();
Matrix4x4f(float aa,float ab,float ac,float ad,
float ba,float bb,float bc,float bd,
float ca,float cb,float cc,float cd,
float da,float db,float dc,float dd);
Matrix4x4f transpose() const;
Matrix4x4f product(const Matrix4x4f& other) const;
Vector4f transform(const Vector4f& other) const;
Vector3f transform(const Vector3f& other) const;
static Matrix4x4f translate(const Vector3f& position);
static Matrix4x4f scale(const Vector3f& scale);
static Matrix4x4f scale(const Vector3f& scale, const Vector3f& origin);
static Matrix4x4f rotate(const Vector3f& rotation);
static Matrix4x4f rotate(const Vector3f& rotation, const Vector3f& origin);
static Matrix4x4f constructWorldMat(const Vector3f& position,const Vector3f& scale,const Vector3f& rotation);
static Matrix4x4f constructViewMat(const Vector3f& position,const Vector3f& target,const Vector3f& upVector);
static Matrix4x4f constructPerspectiveMat(float horizontalfov, float aspectRatio, float nearZ, float farZ);
static Matrix4x4f constructOrthographicMat(float width, float height, float nearZ, float farZ);
static const Matrix4x4f identity;
};
#endif // MATRIX_H_INCLUDED
|
QuaternionMark/COMP371-FinalProject | Libraries/FreeImage-3170/Source/OpenEXR/IlmImf/ImfMultiView.h | ///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007, Weta Digital Ltd
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Weta Digital nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_IMF_MULTIVIEW_H
#define INCLUDED_IMF_MULTIVIEW_H
#include "ImfChannelList.h"
#include "ImfStringVectorAttribute.h"
#include "ImfExport.h"
#include "ImfNamespace.h"
//-----------------------------------------------------------------------------
//
// Functions related to accessing channels and views in multi-view
// OpenEXR files.
//
// A multi-view image file contains two or more views of the same
// scene, as seen from different viewpoints, for example, a left-eye
// and a right-eye view for stereo displays. Each view has its own
// set of image channels. A naming convention identifies the channels
// that belong to a given view.
//
// A "multiView" attribute in the file header lists the names of the
// views in an image (see ImfStandardAttributes.h), and channel names
// of the form
//
// layer.view.channel
//
// allow channels to be matched with views.
//
// For compatibility with singe-view images, the first view listed in
// the multiView attribute is the "default view", and channels that
// have no periods in their names are considered part of the default
// view.
//
// For example, if a file's multiView attribute lists the views
// "left" and "right", in that order, then "left" is the default
// view. Channels
//
// "R", "left.Z", "diffuse.left.R"
//
// are part of the "left" view; channels
//
// "right.R", "right.Z", "diffuse.right.R"
//
// are part of the "right" view; and channels
//
// "tmp.R", "right.diffuse.R", "diffuse.tmp.R"
//
// belong to no view at all.
//
//-----------------------------------------------------------------------------
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
//
// Return the name of the default view given a multi-view string vector,
// that is, return the first element of the string vector. If the string
// vector is empty, return "".
//
IMF_EXPORT
std::string defaultViewName (const StringVector &multiView);
//
// Given the name of a channel, return the name of the view to
// which it belongs. Returns the empty string ("") if the channel
// is not a member of any named view.
//
IMF_EXPORT
std::string viewFromChannelName (const std::string &channel,
const StringVector &multiView);
//
// Return whether channel1 and channel2 are the same channel but
// viewed in different views. (Return false if either channel
// belongs to no view or if both channels belong to the same view.)
//
IMF_EXPORT
bool areCounterparts (const std::string &channel1,
const std::string &channel2,
const StringVector &multiView);
//
// Return a list of all channels belonging to view viewName.
//
IMF_EXPORT
ChannelList channelsInView (const std::string &viewName,
const ChannelList &channelList,
const StringVector &multiView);
//
// Return a list of channels not associated with any view.
//
IMF_EXPORT
ChannelList channelsInNoView (const ChannelList &channelList,
const StringVector &multiView);
//
// Given the name of a channel, return a list of the same channel
// in all views (for example, given X.left.Y return X.left.Y,
// X.right.Y, X.centre.Y, etc.).
//
IMF_EXPORT
ChannelList channelInAllViews (const std::string &channame,
const ChannelList &channelList,
const StringVector &multiView);
//
// Given the name of a channel in one view, return the corresponding
// channel name for view otherViewName. Return "" if no corresponding
// channel exists in view otherViewName, or if view otherViewName doesn't
// exist.
//
IMF_EXPORT
std::string channelInOtherView (const std::string &channel,
const ChannelList &channelList,
const StringVector &multiView,
const std::string &otherViewName);
//
// Given a channel name that does not include a view name, insert
// multiView[i] into the channel name at the appropriate location.
// If i is zero and the channel name contains no periods, then do
// not insert the view name.
//
IMF_EXPORT
std::string insertViewName (const std::string &channel,
const StringVector &multiView,
int i);
//
// Given a channel name that does may include a view name, return
// string without the view name. If the string does not contain
// the view name, return the string unaltered.
// (Will only remove the viewname if it is in the correct position
// in the string)
//
IMF_EXPORT
std::string removeViewName (const std::string &channel,
const std::string &view);
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
#endif
|
QuaternionMark/COMP371-FinalProject | Src/Graphics/Camera.h | <gh_stars>1-10
#ifndef CAMERA_H_INCLUDED
#define CAMERA_H_INCLUDED
#include "../Math/Matrix.h"
#include "Shader.h"
class Camera {
private:
float xAngle;
float yAngle;
// The range of the yAngle field before it is clamped.
float yAngleLimit;
float tilt;
float nearPlaneZ;
float farPlaneZ;
int width;
int height;
float fov;
// Perspective or Orthographic matrix.
bool orthographicProj;
bool thirdPerson;
float thirdPersonRadius;
bool needsViewUpdate;
bool needsProjUpdate;
Vector3f position;
Vector3f lookAt;
Vector3f upDir;
Matrix4x4f viewMatrix;
Matrix4x4f projectionMatrix;
Matrix4x4f rotation;
std::vector<Shader*> shaders;
public:
Camera(int w, int h, float fov, float nearZ = 0.01f, float farZ = 30.f, bool orthographic = false);
Camera(int w, int h);
void addShader(Shader* shd);
Matrix4x4f getViewMatrix() const;
Matrix4x4f getProjectionMatrix() const;
void update();
Vector3f getPosition() const;
void setPosition(const Vector3f& pos);
void setTilt(float rad);
void addAngle(float xAngle, float yAngle);
void resetAngle();
void setThirdPersonPerspective(bool bruh);
bool isThirdPerson() const;
void addFov(float deg);
void setXYClippings(int w, int h);
void setZClippings(float nearZ, float farZ);
float getAspectRatio() const;
void setOrthographicProj(bool bruh);
};
#endif // CAMERA_H_INCLUDED
|
QuaternionMark/COMP371-FinalProject | Libraries/FreeImage-3170/Source/LibOpenJPEG/opj_config.h | #ifndef OPJ_CONFIG_H
#define OPJ_CONFIG_H
#ifndef _MSC_VER
#define OPJ_HAVE_STDINT_H
#define OPJ_HAVE_INTTYPES_H
#endif
#endif /* OPJ_CONFIG_H */
|
QuaternionMark/COMP371-FinalProject | Libraries/FreeImage-3170/Source/OpenEXR/IlmThread/IlmThreadNamespace.h | ///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2012, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_ILMTHREADNAMESPACE_H
#define INCLUDED_ILMTHREADNAMESPACE_H
//
// The purpose of this file is to make it possible to specify an
// ILMTHREAD_INTERNAL_NAMESPACE as a preprocessor definition and have all of
// the IlmThread symbols defined within that namespace rather than the
// standard IlmThread namespace. Those symbols are made available to client
// code through the ILMTHREAD_NAMESPACE in addition to the
// ILMTHREAD_INTERNAL_NAMESPACE.
//
// To ensure source code compatibility, the ILMTHREAD_NAMESPACE defaults to
// IlmThread and then "using namespace ILMTHREAD_INTERNAL_NAMESPACE;" brings
// all of the declarations from the ILMTHREAD_INTERNAL_NAMESPACE into the
// ILMTHREAD_NAMESPACE. This means that client code can continue to use
// syntax like IlmThread::Thread, but at link time it will resolve to a
// mangled symbol based on the ILMTHREAD_INTERNAL_NAMESPACE.
//
// As an example, if one needed to build against a newer version of IlmThread
// and have it run alongside an older version in the same application, it is
// now possible to use an internal namespace to prevent collisions between
// the older versions of IlmThread symbols and the newer ones. To do this,
// the following could be defined at build time:
//
// ILMTHREAD_INTERNAL_NAMESPACE = IlmThread_v2
//
// This means that declarations inside IlmThread headers look like this
// (after the preprocessor has done its work):
//
// namespace IlmThread_v2 {
// ...
// class declarations
// ...
// }
//
// namespace IlmThread {
// using namespace IlmThread_v2;
// }
//
//
// Open Source version of this file pulls in the IlmBaseConfig.h file
// for the configure time options.
//
#include "IlmBaseConfig.h"
#ifndef ILMTHREAD_NAMESPACE
#define ILMTHREAD_NAMESPACE IlmThread
#endif
#ifndef ILMTHREAD_INTERNAL_NAMESPACE
#define ILMTHREAD_INTERNAL_NAMESPACE ILMTHREAD_NAMESPACE
#endif
//
// We need to be sure that we import the internal namespace into the public one.
// To do this, we use the small bit of code below which initially defines
// ILMTHREAD_INTERNAL_NAMESPACE (so it can be referenced) and then defines
// ILMTHREAD_NAMESPACE and pulls the internal symbols into the public
// namespace.
//
namespace ILMTHREAD_INTERNAL_NAMESPACE {}
namespace ILMTHREAD_NAMESPACE {
using namespace ILMTHREAD_INTERNAL_NAMESPACE;
}
//
// There are identical pairs of HEADER/SOURCE ENTER/EXIT macros so that
// future extension to the namespace mechanism is possible without changing
// project source code.
//
#define ILMTHREAD_INTERNAL_NAMESPACE_HEADER_ENTER namespace ILMTHREAD_INTERNAL_NAMESPACE {
#define ILMTHREAD_INTERNAL_NAMESPACE_HEADER_EXIT }
#define ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_ENTER namespace ILMTHREAD_INTERNAL_NAMESPACE {
#define ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT }
#endif // INCLUDED_ILMTHREADNAMESPACE_H
|
QuaternionMark/COMP371-FinalProject | Src/Utils/String.h | #ifndef STRING_H_INCLUDED
#define STRING_H_INCLUDED
#include <vector>
#include <string>
class String {
public:
~String();
String();
String(const String& a);
String(const char* cstr);
String(const std::string& cppstr);
String(const String& a,const String& b);
String(char c);
String(int i,bool hex=false);
String(float f);
const char* cstr() const;
int toInt() const;
float toFloat() const;
int size() const;
int findFirst(const String& fnd,int from=-1) const;
int findLast(const String& fnd,int from=-1) const;
String substr(int start,int cnt=-1) const;
char charAt(int pos) const;
String replace(const String& fnd,const String& rplace) const;
String toUpper() const;
String toLower() const;
String trim() const;
std::vector<String> split(const String& needle, bool removeEmptyEntries) const;
static String join(const std::vector<String>& vect, const String& separator);
String unHex() const;
String resourcePath() const;
String& operator=(const String& other);
long long getHashCode() const;
bool equals(const String& other) const;
bool isEmpty() const;
protected:
char* cbuffer = nullptr;
long long hashCode;
int capacity = 16;
int strSize = 0;
void genHashCode();
};
const String operator+(const String& a, const String& b);
const String operator+(const char* a, const String& b);
bool operator<(const String& a, const String& b);
bool operator>(const String& a, const String& b);
std::ostream& operator<<(std::ostream& os, const String& s);
#endif
|
QuaternionMark/COMP371-FinalProject | Libraries/FreeImage-3170/Source/OpenEXR/Imath/ImathBox.h | <filename>Libraries/FreeImage-3170/Source/OpenEXR/Imath/ImathBox.h
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2004-2012, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_IMATHBOX_H
#define INCLUDED_IMATHBOX_H
//-------------------------------------------------------------------
//
// class Imath::Box<class T>
// --------------------------------
//
// This class imposes the following requirements on its
// parameter class:
//
// 1) The class T must implement these operators:
// + - < > <= >= =
// with the signature (T,T) and the expected
// return values for a numeric type.
//
// 2) The class T must implement operator=
// with the signature (T,float and/or double)
//
// 3) The class T must have a constructor which takes
// a float (and/or double) for use in initializing the box.
//
// 4) The class T must have a function T::dimensions()
// which returns the number of dimensions in the class
// (since its assumed its a vector) -- preferably, this
// returns a constant expression.
//
//-------------------------------------------------------------------
#include "ImathVec.h"
#include "ImathNamespace.h"
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
template <class T>
class Box
{
public:
//-------------------------
// Data Members are public
//-------------------------
T min;
T max;
//-----------------------------------------------------
// Constructors - an "empty" box is created by default
//-----------------------------------------------------
Box ();
Box (const T &point);
Box (const T &minT, const T &maxT);
//--------------------
// Operators: ==, !=
//--------------------
bool operator == (const Box<T> &src) const;
bool operator != (const Box<T> &src) const;
//------------------
// Box manipulation
//------------------
void makeEmpty ();
void extendBy (const T &point);
void extendBy (const Box<T> &box);
void makeInfinite ();
//---------------------------------------------------
// Query functions - these compute results each time
//---------------------------------------------------
T size () const;
T center () const;
bool intersects (const T &point) const;
bool intersects (const Box<T> &box) const;
unsigned int majorAxis () const;
//----------------
// Classification
//----------------
bool isEmpty () const;
bool hasVolume () const;
bool isInfinite () const;
};
//--------------------
// Convenient typedefs
//--------------------
typedef Box <V2s> Box2s;
typedef Box <V2i> Box2i;
typedef Box <V2f> Box2f;
typedef Box <V2d> Box2d;
typedef Box <V3s> Box3s;
typedef Box <V3i> Box3i;
typedef Box <V3f> Box3f;
typedef Box <V3d> Box3d;
//----------------
// Implementation
template <class T>
inline Box<T>::Box()
{
makeEmpty();
}
template <class T>
inline Box<T>::Box (const T &point)
{
min = point;
max = point;
}
template <class T>
inline Box<T>::Box (const T &minT, const T &maxT)
{
min = minT;
max = maxT;
}
template <class T>
inline bool
Box<T>::operator == (const Box<T> &src) const
{
return (min == src.min && max == src.max);
}
template <class T>
inline bool
Box<T>::operator != (const Box<T> &src) const
{
return (min != src.min || max != src.max);
}
template <class T>
inline void Box<T>::makeEmpty()
{
min = T(T::baseTypeMax());
max = T(T::baseTypeMin());
}
template <class T>
inline void Box<T>::makeInfinite()
{
min = T(T::baseTypeMin());
max = T(T::baseTypeMax());
}
template <class T>
inline void
Box<T>::extendBy(const T &point)
{
for (unsigned int i = 0; i < min.dimensions(); i++)
{
if (point[i] < min[i])
min[i] = point[i];
if (point[i] > max[i])
max[i] = point[i];
}
}
template <class T>
inline void
Box<T>::extendBy(const Box<T> &box)
{
for (unsigned int i = 0; i < min.dimensions(); i++)
{
if (box.min[i] < min[i])
min[i] = box.min[i];
if (box.max[i] > max[i])
max[i] = box.max[i];
}
}
template <class T>
inline bool
Box<T>::intersects(const T &point) const
{
for (unsigned int i = 0; i < min.dimensions(); i++)
{
if (point[i] < min[i] || point[i] > max[i])
return false;
}
return true;
}
template <class T>
inline bool
Box<T>::intersects(const Box<T> &box) const
{
for (unsigned int i = 0; i < min.dimensions(); i++)
{
if (box.max[i] < min[i] || box.min[i] > max[i])
return false;
}
return true;
}
template <class T>
inline T
Box<T>::size() const
{
if (isEmpty())
return T (0);
return max - min;
}
template <class T>
inline T
Box<T>::center() const
{
return (max + min) / 2;
}
template <class T>
inline bool
Box<T>::isEmpty() const
{
for (unsigned int i = 0; i < min.dimensions(); i++)
{
if (max[i] < min[i])
return true;
}
return false;
}
template <class T>
inline bool
Box<T>::isInfinite() const
{
for (unsigned int i = 0; i < min.dimensions(); i++)
{
if (min[i] != T::baseTypeMin() || max[i] != T::baseTypeMax())
return false;
}
return true;
}
template <class T>
inline bool
Box<T>::hasVolume() const
{
for (unsigned int i = 0; i < min.dimensions(); i++)
{
if (max[i] <= min[i])
return false;
}
return true;
}
template<class T>
inline unsigned int
Box<T>::majorAxis() const
{
unsigned int major = 0;
T s = size();
for (unsigned int i = 1; i < min.dimensions(); i++)
{
if (s[i] > s[major])
major = i;
}
return major;
}
//-------------------------------------------------------------------
//
// Partial class specializations for Imath::Vec2<T> and Imath::Vec3<T>
//
//-------------------------------------------------------------------
template <typename T> class Box;
template <class T>
class Box<Vec2<T> >
{
public:
//-------------------------
// Data Members are public
//-------------------------
Vec2<T> min;
Vec2<T> max;
//-----------------------------------------------------
// Constructors - an "empty" box is created by default
//-----------------------------------------------------
Box();
Box (const Vec2<T> &point);
Box (const Vec2<T> &minT, const Vec2<T> &maxT);
//--------------------
// Operators: ==, !=
//--------------------
bool operator == (const Box<Vec2<T> > &src) const;
bool operator != (const Box<Vec2<T> > &src) const;
//------------------
// Box manipulation
//------------------
void makeEmpty();
void extendBy (const Vec2<T> &point);
void extendBy (const Box<Vec2<T> > &box);
void makeInfinite();
//---------------------------------------------------
// Query functions - these compute results each time
//---------------------------------------------------
Vec2<T> size() const;
Vec2<T> center() const;
bool intersects (const Vec2<T> &point) const;
bool intersects (const Box<Vec2<T> > &box) const;
unsigned int majorAxis() const;
//----------------
// Classification
//----------------
bool isEmpty() const;
bool hasVolume() const;
bool isInfinite() const;
};
//----------------
// Implementation
template <class T>
inline Box<Vec2<T> >::Box()
{
makeEmpty();
}
template <class T>
inline Box<Vec2<T> >::Box (const Vec2<T> &point)
{
min = point;
max = point;
}
template <class T>
inline Box<Vec2<T> >::Box (const Vec2<T> &minT, const Vec2<T> &maxT)
{
min = minT;
max = maxT;
}
template <class T>
inline bool
Box<Vec2<T> >::operator == (const Box<Vec2<T> > &src) const
{
return (min == src.min && max == src.max);
}
template <class T>
inline bool
Box<Vec2<T> >::operator != (const Box<Vec2<T> > &src) const
{
return (min != src.min || max != src.max);
}
template <class T>
inline void Box<Vec2<T> >::makeEmpty()
{
min = Vec2<T>(Vec2<T>::baseTypeMax());
max = Vec2<T>(Vec2<T>::baseTypeMin());
}
template <class T>
inline void Box<Vec2<T> >::makeInfinite()
{
min = Vec2<T>(Vec2<T>::baseTypeMin());
max = Vec2<T>(Vec2<T>::baseTypeMax());
}
template <class T>
inline void
Box<Vec2<T> >::extendBy (const Vec2<T> &point)
{
if (point[0] < min[0])
min[0] = point[0];
if (point[0] > max[0])
max[0] = point[0];
if (point[1] < min[1])
min[1] = point[1];
if (point[1] > max[1])
max[1] = point[1];
}
template <class T>
inline void
Box<Vec2<T> >::extendBy (const Box<Vec2<T> > &box)
{
if (box.min[0] < min[0])
min[0] = box.min[0];
if (box.max[0] > max[0])
max[0] = box.max[0];
if (box.min[1] < min[1])
min[1] = box.min[1];
if (box.max[1] > max[1])
max[1] = box.max[1];
}
template <class T>
inline bool
Box<Vec2<T> >::intersects (const Vec2<T> &point) const
{
if (point[0] < min[0] || point[0] > max[0] ||
point[1] < min[1] || point[1] > max[1])
return false;
return true;
}
template <class T>
inline bool
Box<Vec2<T> >::intersects (const Box<Vec2<T> > &box) const
{
if (box.max[0] < min[0] || box.min[0] > max[0] ||
box.max[1] < min[1] || box.min[1] > max[1])
return false;
return true;
}
template <class T>
inline Vec2<T>
Box<Vec2<T> >::size() const
{
if (isEmpty())
return Vec2<T> (0);
return max - min;
}
template <class T>
inline Vec2<T>
Box<Vec2<T> >::center() const
{
return (max + min) / 2;
}
template <class T>
inline bool
Box<Vec2<T> >::isEmpty() const
{
if (max[0] < min[0] ||
max[1] < min[1])
return true;
return false;
}
template <class T>
inline bool
Box<Vec2<T> > ::isInfinite() const
{
if (min[0] != limits<T>::min() || max[0] != limits<T>::max() ||
min[1] != limits<T>::min() || max[1] != limits<T>::max())
return false;
return true;
}
template <class T>
inline bool
Box<Vec2<T> >::hasVolume() const
{
if (max[0] <= min[0] ||
max[1] <= min[1])
return false;
return true;
}
template <class T>
inline unsigned int
Box<Vec2<T> >::majorAxis() const
{
unsigned int major = 0;
Vec2<T> s = size();
if (s[1] > s[major])
major = 1;
return major;
}
template <class T>
class Box<Vec3<T> >
{
public:
//-------------------------
// Data Members are public
//-------------------------
Vec3<T> min;
Vec3<T> max;
//-----------------------------------------------------
// Constructors - an "empty" box is created by default
//-----------------------------------------------------
Box();
Box (const Vec3<T> &point);
Box (const Vec3<T> &minT, const Vec3<T> &maxT);
//--------------------
// Operators: ==, !=
//--------------------
bool operator == (const Box<Vec3<T> > &src) const;
bool operator != (const Box<Vec3<T> > &src) const;
//------------------
// Box manipulation
//------------------
void makeEmpty();
void extendBy (const Vec3<T> &point);
void extendBy (const Box<Vec3<T> > &box);
void makeInfinite ();
//---------------------------------------------------
// Query functions - these compute results each time
//---------------------------------------------------
Vec3<T> size() const;
Vec3<T> center() const;
bool intersects (const Vec3<T> &point) const;
bool intersects (const Box<Vec3<T> > &box) const;
unsigned int majorAxis() const;
//----------------
// Classification
//----------------
bool isEmpty() const;
bool hasVolume() const;
bool isInfinite() const;
};
//----------------
// Implementation
template <class T>
inline Box<Vec3<T> >::Box()
{
makeEmpty();
}
template <class T>
inline Box<Vec3<T> >::Box (const Vec3<T> &point)
{
min = point;
max = point;
}
template <class T>
inline Box<Vec3<T> >::Box (const Vec3<T> &minT, const Vec3<T> &maxT)
{
min = minT;
max = maxT;
}
template <class T>
inline bool
Box<Vec3<T> >::operator == (const Box<Vec3<T> > &src) const
{
return (min == src.min && max == src.max);
}
template <class T>
inline bool
Box<Vec3<T> >::operator != (const Box<Vec3<T> > &src) const
{
return (min != src.min || max != src.max);
}
template <class T>
inline void Box<Vec3<T> >::makeEmpty()
{
min = Vec3<T>(Vec3<T>::baseTypeMax());
max = Vec3<T>(Vec3<T>::baseTypeMin());
}
template <class T>
inline void Box<Vec3<T> >::makeInfinite()
{
min = Vec3<T>(Vec3<T>::baseTypeMin());
max = Vec3<T>(Vec3<T>::baseTypeMax());
}
template <class T>
inline void
Box<Vec3<T> >::extendBy (const Vec3<T> &point)
{
if (point[0] < min[0])
min[0] = point[0];
if (point[0] > max[0])
max[0] = point[0];
if (point[1] < min[1])
min[1] = point[1];
if (point[1] > max[1])
max[1] = point[1];
if (point[2] < min[2])
min[2] = point[2];
if (point[2] > max[2])
max[2] = point[2];
}
template <class T>
inline void
Box<Vec3<T> >::extendBy (const Box<Vec3<T> > &box)
{
if (box.min[0] < min[0])
min[0] = box.min[0];
if (box.max[0] > max[0])
max[0] = box.max[0];
if (box.min[1] < min[1])
min[1] = box.min[1];
if (box.max[1] > max[1])
max[1] = box.max[1];
if (box.min[2] < min[2])
min[2] = box.min[2];
if (box.max[2] > max[2])
max[2] = box.max[2];
}
template <class T>
inline bool
Box<Vec3<T> >::intersects (const Vec3<T> &point) const
{
if (point[0] < min[0] || point[0] > max[0] ||
point[1] < min[1] || point[1] > max[1] ||
point[2] < min[2] || point[2] > max[2])
return false;
return true;
}
template <class T>
inline bool
Box<Vec3<T> >::intersects (const Box<Vec3<T> > &box) const
{
if (box.max[0] < min[0] || box.min[0] > max[0] ||
box.max[1] < min[1] || box.min[1] > max[1] ||
box.max[2] < min[2] || box.min[2] > max[2])
return false;
return true;
}
template <class T>
inline Vec3<T>
Box<Vec3<T> >::size() const
{
if (isEmpty())
return Vec3<T> (0);
return max - min;
}
template <class T>
inline Vec3<T>
Box<Vec3<T> >::center() const
{
return (max + min) / 2;
}
template <class T>
inline bool
Box<Vec3<T> >::isEmpty() const
{
if (max[0] < min[0] ||
max[1] < min[1] ||
max[2] < min[2])
return true;
return false;
}
template <class T>
inline bool
Box<Vec3<T> >::isInfinite() const
{
if (min[0] != limits<T>::min() || max[0] != limits<T>::max() ||
min[1] != limits<T>::min() || max[1] != limits<T>::max() ||
min[2] != limits<T>::min() || max[2] != limits<T>::max())
return false;
return true;
}
template <class T>
inline bool
Box<Vec3<T> >::hasVolume() const
{
if (max[0] <= min[0] ||
max[1] <= min[1] ||
max[2] <= min[2])
return false;
return true;
}
template <class T>
inline unsigned int
Box<Vec3<T> >::majorAxis() const
{
unsigned int major = 0;
Vec3<T> s = size();
if (s[1] > s[major])
major = 1;
if (s[2] > s[major])
major = 2;
return major;
}
IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
#endif // INCLUDED_IMATHBOX_H
|
QuaternionMark/COMP371-FinalProject | Src/Primitives/Triangle.h | <reponame>QuaternionMark/COMP371-FinalProject
#ifndef TRIANGLE_H_INCLUDED
#define TRIANGLE_H_INCLUDED
#include <vector>
#include "../Graphics/Shader.h"
class Mesh;
class Triangle {
private:
const float vertices[9] = {
0.f, 0.5f, 0.f, // Top.
-0.5f, -0.5f, 0.f, // Left.
0.5f, -0.5f, 0.f // Right.
};
Mesh* mesh;
Shader::Uniform* worldMat;
Shader::Uniform* colorUniform;
public:
Triangle(Shader* shd);
void render();
};
#endif // TRIANGLE_H_INCLUDED
|
QuaternionMark/COMP371-FinalProject | Libraries/FreeImage-3170/Source/LibOpenJPEG/opj_config_private.h | <reponame>QuaternionMark/COMP371-FinalProject
#ifndef OPJ_CONFIG_PRIVATE_H
#define OPJ_CONFIG_PRIVATE_H
#define OPJ_PACKAGE_VERSION "2.0.0"
/**
Some versions of gcc may have BYTE_ORDER or __BYTE_ORDER defined
If your big endian system isn't being detected, add an OS specific check
*/
#if (defined(BYTE_ORDER) && BYTE_ORDER==BIG_ENDIAN) || \
(defined(__BYTE_ORDER) && __BYTE_ORDER==__BIG_ENDIAN) || \
defined(__BIG_ENDIAN__)
#define OPJ_BIG_ENDIAN
#endif /* BYTE_ORDER */
#endif /* OPJ_CONFIG_PRIVATE_H */
|
QuaternionMark/COMP371-FinalProject | Src/Math/Vector.h | /**
Modified from https://github.com/juanjp600/pge.
Copyright (c) 2019 <NAME>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
**/
#ifndef VECTOR_H_INCLUDED
#define VECTOR_H_INCLUDED
#include "MathUtil.h"
class Vector2f; class Vector3f;
class Vector2f {
public:
float x; float y;
Vector2f();
Vector2f(float s);
Vector2f(float ix,float iy);
float lengthSquared() const;
float length() const;
float distanceSquared(const Vector2f& b) const;
float distance(const Vector2f& b) const;
bool equals(const Vector2f& b,float epsilon=MathUtil::MARGIN_ERROR) const;
Vector2f add(const Vector2f& b) const;
Vector2f subtract(const Vector2f& b) const;
Vector2f multiply(float s) const;
Vector2f normalize() const;
Vector2f negate() const;
Vector2f reflect(const Vector2f& n) const;
float dotProduct(const Vector2f& b) const;
float crossProduct(const Vector2f& b) const;
static const Vector2f zero;
static const Vector2f one;
};
class Vector3f {
public:
float x; float y; float z;
Vector3f();
Vector3f(float s);
Vector3f(float ix,float iy,float iz);
float lengthSquared() const;
float length() const;
float distanceSquared(const Vector3f& b) const;
float distance(const Vector3f& b) const;
Vector3f add(const Vector3f& b) const;
Vector3f subtract(const Vector3f& b) const;
Vector3f multiply(float s) const;
Vector3f normalize() const;
Vector3f negate() const;
Vector3f reflect(const Vector3f& n) const;
float dotProduct(const Vector3f& b) const;
Vector3f crossProduct(const Vector3f& b) const;
static const Vector3f zero;
static const Vector3f one;
};
class Vector4f {
public:
float x; float y; float z; float w;
Vector4f();
Vector4f(float s);
Vector4f(float ix,float iy,float iz,float iw);
static const Vector4f zero;
static const Vector4f one;
};
#endif // VECTOR_H_INCLUDED
|
QuaternionMark/COMP371-FinalProject | Src/Math/MathUtil.h | #ifndef MATH_H_INCLUDED
#define MATH_H_INCLUDED
class MathUtil {
public:
constexpr static float MARGIN_ERROR = 0.001f;
constexpr static float PI = 3.1415926535897932f;
static float degToRad(float degrees);
static bool eqFloats(float p1, float p2);
// Clamps an integer between a min and max inclusively.
static int clamp(int val, int min, int max);
static float clampFloat(float val, float min, float max);
static float minFloat(float val1, float val2);
static float maxFloat(float val1, float val2);
static float absFloat(float val);
};
#endif // MATH_H_INCLUDED
|
QuaternionMark/COMP371-FinalProject | Src/Primitives/Wheel.h | #ifndef WHEEL_H_INCLUDED
#define WHEEL_H_INCLUDED
#include "../Graphics/Shader.h"
class Mesh;
class Wheel {
private:
Vector3f position;
Vector3f scale;
Vector3f rotation;
// Lateral rotation of wheels.
float tireRotation;
Mesh* mesh;
Matrix4x4f worldMatrix;
Shader::Uniform* worldMatrixUniform;
Shader::Uniform* colorUniform;
public:
Vector4f color;
Wheel(Shader* shd);
void setPosition(float x, float y, float z);
void addPositionXZ(const Vector2f& vect);
void addRotationX(float bruh);
void addRotationZ(float bruh);
void setTireRotation(float bruh);
void setShader(Shader* shd);
void update(const Matrix4x4f& originWorldMatrix);
void render();
};
#endif // WHEEL_H_INCLUDED
|
QuaternionMark/COMP371-FinalProject | Libraries/FreeImage-3170/Source/OpenEXR/IlmImf/ImfDeepScanLineInputFile.h | <filename>Libraries/FreeImage-3170/Source/OpenEXR/IlmImf/ImfDeepScanLineInputFile.h
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2011, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_IMF_DEEP_SCAN_LINE_INPUT_FILE_H
#define INCLUDED_IMF_DEEP_SCAN_LINE_INPUT_FILE_H
//-----------------------------------------------------------------------------
//
// class DeepScanLineInputFile
//
//-----------------------------------------------------------------------------
#include "ImfThreading.h"
#include "ImfGenericInputFile.h"
#include "ImfNamespace.h"
#include "ImfForward.h"
#include "ImfExport.h"
#include "ImfDeepScanLineOutputFile.h"
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
class IMF_EXPORT DeepScanLineInputFile : public GenericInputFile
{
public:
//------------
// Constructor
//------------
DeepScanLineInputFile (const char fileName[],
int numThreads = globalThreadCount());
DeepScanLineInputFile (const Header &header, OPENEXR_IMF_INTERNAL_NAMESPACE::IStream *is,
int version, /*version field from file*/
int numThreads = globalThreadCount());
//-----------------------------------------
// Destructor -- deallocates internal data
// structures, but does not close the file.
//-----------------------------------------
virtual ~DeepScanLineInputFile ();
//------------------------
// Access to the file name
//------------------------
const char * fileName () const;
//--------------------------
// Access to the file header
//--------------------------
const Header & header () const;
//----------------------------------
// Access to the file format version
//----------------------------------
int version () const;
//-----------------------------------------------------------
// Set the current frame buffer -- copies the FrameBuffer
// object into the InputFile object.
//
// The current frame buffer is the destination for the pixel
// data read from the file. The current frame buffer must be
// set at least once before readPixels() is called.
// The current frame buffer can be changed after each call
// to readPixels().
//-----------------------------------------------------------
void setFrameBuffer (const DeepFrameBuffer &frameBuffer);
//-----------------------------------
// Access to the current frame buffer
//-----------------------------------
const DeepFrameBuffer & frameBuffer () const;
//---------------------------------------------------------------
// Check if the file is complete:
//
// isComplete() returns true if all pixels in the data window are
// present in the input file, or false if any pixels are missing.
// (Another program may still be busy writing the file, or file
// writing may have been aborted prematurely.)
//---------------------------------------------------------------
bool isComplete () const;
//---------------------------------------------------------------
// Read pixel data:
//
// readPixels(s1,s2) reads all scan lines with y coordinates
// in the interval [min (s1, s2), max (s1, s2)] from the file,
// and stores them in the current frame buffer.
//
// Both s1 and s2 must be within the interval
// [header().dataWindow().min.y, header.dataWindow().max.y]
//
// The scan lines can be read from the file in random order, and
// individual scan lines may be skipped or read multiple times.
// For maximum efficiency, the scan lines should be read in the
// order in which they were written to the file.
//
// readPixels(s) calls readPixels(s,s).
//
// If threading is enabled, readPixels (s1, s2) tries to perform
// decopmression of multiple scanlines in parallel.
//
//---------------------------------------------------------------
void readPixels (int scanLine1, int scanLine2);
void readPixels (int scanLine);
//---------------------------------------------------------------
// Extract pixel data from pre-read block
//
// readPixels(rawPixelData,frameBuffer,s1,s2) reads all scan lines with y coordinates
// in the interval [min (s1, s2), max (s1, s2)] from the data provided and
// stores them in the provided frameBuffer.
// the data can be obtained from a call to rawPixelData()
//
//
// Both s1 and s2 must be within the data specified
//
// you must provide a frameBuffer with a samplecountslice, which must have been read
// and the data valid - readPixels uses your sample count buffer to compute
// offsets to the data it needs
//
// This call does not block, and is thread safe for clients with an existing
// threading model. The InputFile's frameBuffer is not used in this call.
//
// This call is only provided for clients which have an existing threading model in place
// and unpredictable access patterns to the data.
// The fastest way to read an entire image is to enable threading,use setFrameBuffer then
// readPixels(header().dataWindow().min.y, header.dataWindow().max.y)
//
//---------------------------------------------------------------
void readPixels (const char * rawPixelData,
const DeepFrameBuffer & frameBuffer,
int scanLine1,
int scanLine2) const;
//----------------------------------------------
// Read a block of raw pixel data from the file,
// without uncompressing it (this function is
// used to implement OutputFile::copyPixels()).
// note: returns the entire payload of the relevant chunk of data, not including part number
// including compressed and uncompressed sizes
// on entry, if pixelDataSize is insufficiently large, no bytes are read (pixelData can safely be NULL)
// on exit, pixelDataSize is the number of bytes required to read the chunk
//
//----------------------------------------------
void rawPixelData (int firstScanLine,
char * pixelData,
Int64 &pixelDataSize);
//-------------------------------------------------
// firstScanLineInChunk() returns the row number of the first row that's stored in the
// same chunk as scanline y. Depending on the compression mode, this may not be the same as y
//
// lastScanLineInChunk() returns the row number of the last row that's stored in the same
// chunk as scanline y. Depending on the compression mode, this may not be the same as y.
// The last chunk in the file may be smaller than all the others
//
//------------------------------------------------
int firstScanLineInChunk(int y) const;
int lastScanLineInChunk (int y) const;
//-----------------------------------------------------------
// Read pixel sample counts into a slice in the frame buffer.
//
// readPixelSampleCounts(s1, s2) reads all the counts of
// pixel samples with y coordinates in the interval
// [min (s1, s2), max (s1, s2)] from the file, and stores
// them in the slice naming "sample count".
//
// Both s1 and s2 must be within the interval
// [header().dataWindow().min.y, header.dataWindow().max.y]
//
// readPixelSampleCounts(s) calls readPixelSampleCounts(s,s).
//
//-----------------------------------------------------------
void readPixelSampleCounts (int scanline1,
int scanline2);
void readPixelSampleCounts (int scanline);
//----------------------------------------------------------
// Read pixel sample counts into the provided frameBuffer
// using a block read of data read by rawPixelData
// for multi-scanline compression schemes, you must decode the entire block
// so scanline1=firstScanLineInChunk(y) and scanline2=lastScanLineInChunk(y)
//
// This call does not block, and is thread safe for clients with an existing
// threading model. The InputFile's frameBuffer is not used in this call.
//
// The fastest way to read an entire image is to enable threading in OpenEXR, use setFrameBuffer then
// readPixelSampleCounts(header().dataWindow().min.y, header.dataWindow().max.y)
//
//----------------------------------------------------------
void readPixelSampleCounts (const char * rawdata ,
const DeepFrameBuffer & frameBuffer,
int scanLine1 ,
int scanLine2) const;
struct Data;
private:
Data * _data;
DeepScanLineInputFile (InputPartData* part);
void initialize(const Header& header);
void compatibilityInitialize(OPENEXR_IMF_INTERNAL_NAMESPACE::IStream & is);
void multiPartInitialize(InputPartData* part);
friend class InputFile;
friend class MultiPartInputFile;
friend void DeepScanLineOutputFile::copyPixels(DeepScanLineInputFile &);
};
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
#endif
|
QuaternionMark/COMP371-FinalProject | Libraries/FreeImage-3170/Source/OpenEXR/IlmImf/ImfFastHuf.h | ///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2009-2014 DreamWorks Animation LLC.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of DreamWorks Animation nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_IMF_FAST_HUF_H
#define INCLUDED_IMF_FAST_HUF_H
#include "ImfInt64.h"
#include "ImfNamespace.h"
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
//
// Alternative Canonical Huffman decoder:
//
// Canonical Huffman decoder based on 'On the Implementation of Minimum
// Redundancy Prefix Codes' by Moffat and Turpin - highly recommended
// reading as a good description of the problem space, as well as
// a fast decoding algorithm.
//
// The premise is that instead of working directly with the coded
// symbols, we create a new ordering based on the frequency of symbols.
// Less frequent symbols (and thus longer codes) are ordered earler.
// We're calling the values in this ordering 'Ids', as oppsed to
// 'Symbols' - which are the short values we eventually want decoded.
//
// With this new ordering, a few small tables can be derived ('base'
// and 'offset') which drive the decoding. To cut down on the
// linear scanning of these tables, you can add a small table
// to directly look up short codes (as you might in a traditional
// lookup-table driven decoder).
//
// The decoder is meant to be compatible with the encoder (and decoder)
// in ImfHuf.cpp, just faster. For ease of implementation, this decoder
// should only be used on compressed bitstreams >= 128 bits long.
//
class FastHufDecoder
{
public:
//
// Longest compressed code length that ImfHuf supports (58 bits)
//
static const int MAX_CODE_LEN = 58;
//
// Number of bits in our acceleration table. Should match all
// codes up to TABLE_LOOKUP_BITS in length.
//
static const int TABLE_LOOKUP_BITS = 12;
FastHufDecoder (const char*& table,
int numBytes,
int minSymbol,
int maxSymbol,
int rleSymbol);
~FastHufDecoder ();
static bool enabled ();
void decode (const unsigned char *src,
int numSrcBits,
unsigned short *dst,
int numDstElems);
private:
void buildTables (Int64*, Int64*);
void refill (Int64&, int, Int64&, int&, const unsigned char *&, int&);
Int64 readBits (int, Int64&, int&, const char *&);
int _rleSymbol; // RLE symbol written by the encoder.
// This could be 65536, so beware
// when you use shorts to hold things.
int _numSymbols; // Number of symbols in the codebook.
unsigned char _minCodeLength; // Minimum code length, in bits.
unsigned char _maxCodeLength; // Maximum code length, in bits.
int *_idToSymbol; // Maps Ids to symbols. Ids are a symbol
// ordering sorted first in terms of
// code length, and by code within
// the same length. Ids run from 0
// to mNumSymbols-1.
Int64 _ljBase[MAX_CODE_LEN + 1]; // the 'left justified base' table.
// Takes base[i] (i = code length)
// and 'left justifies' it into an Int64
Int64 _ljOffset[MAX_CODE_LEN +1 ]; // There are some other terms that can
// be folded into constants when taking
// the 'left justified' decode path. This
// holds those constants, indexed by
// code length
//
// We can accelerate the 'left justified' processing by running the
// top TABLE_LOOKUP_BITS through a LUT, to find the symbol and code
// length. These are those acceleration tables.
//
// Even though our evental 'symbols' are ushort's, the encoder adds
// a symbol to indicate RLE. So with a dense code book, we could
// have 2^16+1 codes, so both mIdToSymbol and mTableSymbol need
// to be bigger than 16 bits.
//
int _tableSymbol[1 << TABLE_LOOKUP_BITS];
unsigned char _tableCodeLen[1 << TABLE_LOOKUP_BITS];
Int64 _tableMin;
};
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
#endif
|
QuaternionMark/COMP371-FinalProject | Libraries/FreeImage-3170/Source/OpenEXR/IlmImf/ImfDwaCompressor.h | <reponame>QuaternionMark/COMP371-FinalProject
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2009-2014 DreamWorks Animation LLC.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of DreamWorks Animation nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_IMF_DWA_COMRESSOR_H
#define INCLUDED_IMF_DWA_COMRESSOR_H
//------------------------------------------------------------------------------
//
// class DwaCompressor -- Store lossy RGB data by quantizing DCT components.
//
//------------------------------------------------------------------------------
#include <vector>
#include <half.h>
#include "ImfInt64.h"
#include "ImfZip.h"
#include "ImfChannelList.h"
#include "ImfCompressor.h"
#include "ImfNamespace.h"
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
class DwaCompressor: public Compressor
{
public:
enum AcCompression
{
STATIC_HUFFMAN,
DEFLATE,
};
DwaCompressor (const Header &hdr,
int maxScanLineSize,
int numScanLines, // ideally is a multiple of 8
AcCompression acCompression);
virtual ~DwaCompressor ();
virtual int numScanLines () const;
virtual Imf::Compressor::Format format () const;
virtual int compress (const char *inPtr,
int inSize,
int minY,
const char *&outPtr);
virtual int compressTile (const char *inPtr,
int inSize,
Imath::Box2i range,
const char *&outPtr);
virtual int uncompress (const char *inPtr,
int inSize,
int minY,
const char *&outPtr);
virtual int uncompressTile (const char *inPtr,
int inSize,
Imath::Box2i range,
const char *&outPtr);
static void initializeFuncs ();
private:
struct ChannelData;
struct CscChannelSet;
struct Classifier;
class LossyDctDecoderBase;
class LossyDctDecoder;
class LossyDctDecoderCsc;
class LossyDctEncoderBase;
class LossyDctEncoder;
class LossyDctEncoderCsc;
enum CompressorScheme
{
UNKNOWN = 0,
LOSSY_DCT,
RLE,
NUM_COMPRESSOR_SCHEMES
};
//
// Per-chunk compressed data sizes, one value per chunk
//
enum DataSizesSingle
{
VERSION = 0, // Version number:
// 0: classic
// 1: adds "end of block" to the AC RLE
UNKNOWN_UNCOMPRESSED_SIZE, // Size of leftover data, uncompressed.
UNKNOWN_COMPRESSED_SIZE, // Size of leftover data, zlib compressed.
AC_COMPRESSED_SIZE, // AC RLE + Huffman size
DC_COMPRESSED_SIZE, // DC + Deflate size
RLE_COMPRESSED_SIZE, // RLE + Deflate data size
RLE_UNCOMPRESSED_SIZE, // RLE'd data size
RLE_RAW_SIZE, // Un-RLE'd data size
AC_UNCOMPRESSED_COUNT, // AC RLE number of elements
DC_UNCOMPRESSED_COUNT, // DC number of elements
AC_COMPRESSION, // AC compression strategy
NUM_SIZES_SINGLE
};
AcCompression _acCompression;
int _maxScanLineSize;
int _numScanLines;
int _min[2], _max[2];
ChannelList _channels;
std::vector<ChannelData> _channelData;
std::vector<CscChannelSet> _cscSets;
std::vector<Classifier> _channelRules;
char *_packedAcBuffer;
size_t _packedAcBufferSize;
char *_packedDcBuffer;
size_t _packedDcBufferSize;
char *_rleBuffer;
size_t _rleBufferSize;
char *_outBuffer;
size_t _outBufferSize;
char *_planarUncBuffer[NUM_COMPRESSOR_SCHEMES];
size_t _planarUncBufferSize[NUM_COMPRESSOR_SCHEMES];
Zip *_zip;
float _dwaCompressionLevel;
int compress (const char *inPtr,
int inSize,
Imath::Box2i range,
const char *&outPtr);
int uncompress (const char *inPtr,
int inSize,
Imath::Box2i range,
const char *&outPtr);
void initializeBuffers (size_t&);
void initializeDefaultChannelRules ();
void initializeLegacyChannelRules ();
void relevantChannelRules( std::vector<Classifier> &) const;
//
// Populate our cached version of the channel data with
// data from the real channel list. We want to
// copy over attributes, determine compression schemes
// releveant for the channel type, and find sets of
// channels to be compressed from Y'CbCr data instead
// of R'G'B'.
//
void classifyChannels (ChannelList channels,
std::vector<ChannelData> &chanData,
std::vector<CscChannelSet> &cscData);
//
// Compute various buffer pointers for each channel
//
void setupChannelData (int minX, int minY, int maxX, int maxY);
};
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
#endif
|
QuaternionMark/COMP371-FinalProject | Src/Graphics/Sprite.h | <gh_stars>1-10
#ifndef SPRITE_H_INCLUDED
#define SPRITE_H_INCLUDED
#include "Shader.h"
class Mesh;
class Sprite {
private:
Shader::Uniform* modelMatrixUniform;
Shader::Uniform* scaleUniform;
Shader::Uniform* rotationMatrixUniform;
Shader::Uniform* colorUniform;
Mesh* mesh;
Vector3f position;
Vector2f scale;
float rotation;
Matrix4x4f modelMatrix;
// Stores the roll rotations of the sprite.
Matrix4x4f rotationMatrix;
Vector4f color;
public:
Sprite(Shader* shd);
~Sprite();
void setScale(float scale);
void setPosition(const Vector3f& pos);
void addRotation(float rad);
void setOpacity(float value);
void update();
void render() const;
};
#endif // SPRITE_H_INCLUDED
|
QuaternionMark/COMP371-FinalProject | Src/Primitives/Cube.h | #ifndef CUBE_H_INCLUDED
#define CUBE_H_INCLUDED
#include "../Graphics/Shader.h"
class Mesh;
class Cube {
private:
const float vertices[288] = {
// Positions // Normals // UV Coords
// back face
-0.5f, 0.0f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, // bottom-left
0.5f, 1.0f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f, // top-right
0.5f, 0.0f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f, // bottom-right
0.5f, 1.0f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f, // top-right
-0.5f, 0.0f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, // bottom-left
-0.5f, 1.0f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, // top-left
// front face
-0.5f, 0.0f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom-left
0.5f, 0.0f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, // bottom-right
0.5f, 1.0f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, // top-right
0.5f, 1.0f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, // top-right
-0.5f, 1.0f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, // top-left
-0.5f, 0.0f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom-left
// left face
-0.5f, 1.0f, 0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, // top-right
-0.5f, 1.0f, -0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, // top-left
-0.5f, 0.0f, -0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, // bottom-left
-0.5f, 0.0f, -0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, // bottom-left
-0.5f, 0.0f, 0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, // bottom-right
-0.5f, 1.0f, 0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, // top-right
// right face
0.5f, 1.0f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, // top-left
0.5f, 0.0f, -0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, // bottom-right
0.5f, 1.0f, -0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, // top-right
0.5f, 0.0f, -0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, // bottom-right
0.5f, 1.0f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, // top-left
0.5f, 0.0f, 0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, // bottom-left
// bottom face
-0.5f, 0.0f, -0.5f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, // top-right
0.5f, 0.0f, -0.5f, 0.0f, -1.0f, 0.0f, 1.0f, 1.0f, // top-left
0.5f, 0.0f, 0.5f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, // bottom-left
0.5f, 0.0f, 0.5f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, // bottom-left
-0.5f, 0.0f, 0.5f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, // bottom-right
-0.5f, 0.0f, -0.5f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, // top-right
// top face
-0.5f, 1.0f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, // top-left
0.5f, 1.0f , 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // bottom-right
0.5f, 1.0f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, // top-right
0.5f, 1.0f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // bottom-right
-0.5f, 1.0f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, // top-left
-0.5f, 1.0f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f // bottom-left
};
Vector3f position;
Vector3f scale;
Vector3f rotation;
Mesh* mesh;
Matrix4x4f worldMatrix;
Shader::Uniform* worldMatUniform;
Shader::Uniform* colorUniform;
public:
Vector4f color;
Cube(Shader* shd);
void setPosition(const Vector3f& vect);
void setPosition(float x, float y, float z);
void addPositionXZ(const Vector2f& vect);
void setScale(const Vector3f& vect);
void setScale(float x, float y, float z);
void addRotationX(float bruh);
void addRotationY(float bruh);
void addRotationZ(float bruh);
void setShader(Shader* shd);
void constructWorldMat();
void constructWorldMat( const Matrix4x4f& originWorldMatrix);
Matrix4x4f getWorldMatrix() const;
void update(const Matrix4x4f& originWorldMatrix);
void render() const;
};
#endif // CUBE_H_INCLUDED
|
QuaternionMark/COMP371-FinalProject | Src/Graphics/Shader.h | <reponame>QuaternionMark/COMP371-FinalProject<gh_stars>1-10
#ifndef SHADER_H_INCLUDED
#define SHADER_H_INCLUDED
#include <GL/glew.h>
#include <vector>
#include "../Utils/String.h"
#include "../Math/Matrix.h"
class Shader {
public:
class Uniform {
public:
union Values {
Values();
Matrix4x4f matrixVal;
Vector4f vec4Val;
Vector3f vec3Val;
Vector2f vec2Val;
int intVal;
bool boolVal;
};
Values value;
enum class Kind {
Matrix,
Vector4f,
Vector3f,
Vector2f,
Integer,
Boolean
};
String name;
Kind type;
GLuint location;
Uniform(Kind kind, GLuint location);
void setValue(Matrix4x4f value);
void setValue(Vector4f value);
void setValue(Vector3f value);
void setValue(Vector2f value);
void setValue(int value);
void setValue(bool value);
};
private:
GLuint shaderProgramID;
GLuint vertexShaderID;
GLuint fragmentShaderID;
GLuint stride;
class VertexInput {
public:
GLuint location;
GLuint size;
GLenum type;
};
std::vector<VertexInput> inputVars;
std::vector<Uniform*> uniformVars;
public:
Shader(const String& shaderFolder);
~Shader();
void addVec2VertexInput(const String& name);
void addVec3VertexInput(const String& name);
void addVec4VertexInput(const String& name);
Uniform* getMat4Uniform(const String& name);
Uniform* getVec4fUniform(const String& name);
Uniform* getVec3fUniform(const String& name);
Uniform* getVec2fUniform(const String& name);
Uniform* getIntUniform(const String& name);
Uniform* getBoolUniform(const String& name);
void use() const;
void unbindVertexInputs();
};
#endif // SHADER_H_INCLUDED
|
QuaternionMark/COMP371-FinalProject | Libraries/FreeImage-3170/Source/OpenEXR/IlmBaseConfig.h | <reponame>QuaternionMark/COMP371-FinalProject
/**
Define and set to 1 if the target system has POSIX thread support
and you want IlmBase to use it for multithreaded file I/O.
*/
#if defined(_MSC_VER) || defined(__MINGW32__)
#undef HAVE_PTHREAD
#else
#undef HAVE_PTHREAD
#endif
/**
Define and set to 1 if the target system supports POSIX semaphores
and you want OpenEXR to use them; otherwise, OpenEXR will use its
own semaphore implementation.
*/
#if defined(_MSC_VER) || defined(__MINGW32__)
#undef HAVE_POSIX_SEMAPHORES
#else
#undef HAVE_POSIX_SEMAPHORES
#endif
/**
Define and set to 1 if the target system has support for large stack sizes.
*/
#undef ILMBASE_HAVE_LARGE_STACK
/**
Current (internal) library namepace name and corresponding public client namespaces.
*/
#define ILMBASE_INTERNAL_NAMESPACE_CUSTOM 1
#define IMATH_INTERNAL_NAMESPACE Imath_2_2
#define IEX_INTERNAL_NAMESPACE Iex_2_2
#define ILMTHREAD_INTERNAL_NAMESPACE IlmThread_2_2
#define IMATH_NAMESPACE Imath
#define IEX_NAMESPACE Iex
#define ILMTHREAD_NAMESPACE IlmThread
/**
Required for system-specific debug trap code in IexBaseExc.cpp
*/
#ifdef _WIN32
#define PLATFORM_WINDOWS 1
#endif
//
// Version information
//
#define ILMBASE_VERSION_STRING "2.2.0"
#define ILMBASE_PACKAGE_STRING "IlmBase 2.2.0"
#define ILMBASE_VERSION_MAJOR 2
#define ILMBASE_VERSION_MINOR 2
#define ILMBASE_VERSION_PATCH 0
// Version as a single hex number, e.g. 0x01000300 == 1.0.3
#define ILMBASE_VERSION_HEX ((ILMBASE_VERSION_MAJOR << 24) | \
(ILMBASE_VERSION_MINOR << 16) | \
(ILMBASE_VERSION_PATCH << 8))
|
QuaternionMark/COMP371-FinalProject | Src/Controllers/AI.h | #ifndef AI_H_INCLUDED
#define AI_H_INCLUDED
#include "../Objects/Car.h"
class Shader;
class AI {
private:
Car* car;
Car::WalkInput currTaskDirection;
int stepsUntilNewTask;
bool brainFreeze;
public:
AI(Shader* shd, Shader* colliderShd, Shader* spriteShd);
~AI();
void setCarShader(Shader* shd);
Car* getCar() const;
Car::WalkInput getCurrentTaskDirection();
void updateCurrentTaskDirection();
void toggleBrainFreeze();
void updateFarInput(Car::WalkInput& input);
void updateNearInput(Car::WalkInput& input);
void update(float timestep);
void render() const;
};
#endif // AI_H_INCLUDED
|
QuaternionMark/COMP371-FinalProject | Libraries/FreeImage-3170/Source/OpenEXR/Imath/ImathRoots.h | <gh_stars>1-10
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2002-2012, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_IMATHROOTS_H
#define INCLUDED_IMATHROOTS_H
//---------------------------------------------------------------------
//
// Functions to solve linear, quadratic or cubic equations
//
//---------------------------------------------------------------------
#include "ImathMath.h"
#include "ImathNamespace.h"
#include <complex>
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
//--------------------------------------------------------------------------
// Find the real solutions of a linear, quadratic or cubic equation:
//
// function equation solved
//
// solveLinear (a, b, x) a * x + b == 0
// solveQuadratic (a, b, c, x) a * x*x + b * x + c == 0
// solveNormalizedCubic (r, s, t, x) x*x*x + r * x*x + s * x + t == 0
// solveCubic (a, b, c, d, x) a * x*x*x + b * x*x + c * x + d == 0
//
// Return value:
//
// 3 three real solutions, stored in x[0], x[1] and x[2]
// 2 two real solutions, stored in x[0] and x[1]
// 1 one real solution, stored in x[1]
// 0 no real solutions
// -1 all real numbers are solutions
//
// Notes:
//
// * It is possible that an equation has real solutions, but that the
// solutions (or some intermediate result) are not representable.
// In this case, either some of the solutions returned are invalid
// (nan or infinity), or, if floating-point exceptions have been
// enabled with Iex::mathExcOn(), an Iex::MathExc exception is
// thrown.
//
// * Cubic equations are solved using Cardano's Formula; even though
// only real solutions are produced, some intermediate results are
// complex (std::complex<T>).
//
//--------------------------------------------------------------------------
template <class T> int solveLinear (T a, T b, T &x);
template <class T> int solveQuadratic (T a, T b, T c, T x[2]);
template <class T> int solveNormalizedCubic (T r, T s, T t, T x[3]);
template <class T> int solveCubic (T a, T b, T c, T d, T x[3]);
//---------------
// Implementation
//---------------
template <class T>
int
solveLinear (T a, T b, T &x)
{
if (a != 0)
{
x = -b / a;
return 1;
}
else if (b != 0)
{
return 0;
}
else
{
return -1;
}
}
template <class T>
int
solveQuadratic (T a, T b, T c, T x[2])
{
if (a == 0)
{
return solveLinear (b, c, x[0]);
}
else
{
T D = b * b - 4 * a * c;
if (D > 0)
{
T s = Math<T>::sqrt (D);
T q = -(b + (b > 0 ? 1 : -1) * s) / T(2);
x[0] = q / a;
x[1] = c / q;
return 2;
}
if (D == 0)
{
x[0] = -b / (2 * a);
return 1;
}
else
{
return 0;
}
}
}
template <class T>
int
solveNormalizedCubic (T r, T s, T t, T x[3])
{
T p = (3 * s - r * r) / 3;
T q = 2 * r * r * r / 27 - r * s / 3 + t;
T p3 = p / 3;
T q2 = q / 2;
T D = p3 * p3 * p3 + q2 * q2;
if (D == 0 && p3 == 0)
{
x[0] = -r / 3;
x[1] = -r / 3;
x[2] = -r / 3;
return 1;
}
std::complex<T> u = std::pow (-q / 2 + std::sqrt (std::complex<T> (D)),
T (1) / T (3));
std::complex<T> v = -p / (T (3) * u);
const T sqrt3 = T (1.73205080756887729352744634150587); // enough digits
// for long double
std::complex<T> y0 (u + v);
std::complex<T> y1 (-(u + v) / T (2) +
(u - v) / T (2) * std::complex<T> (0, sqrt3));
std::complex<T> y2 (-(u + v) / T (2) -
(u - v) / T (2) * std::complex<T> (0, sqrt3));
if (D > 0)
{
x[0] = y0.real() - r / 3;
return 1;
}
else if (D == 0)
{
x[0] = y0.real() - r / 3;
x[1] = y1.real() - r / 3;
return 2;
}
else
{
x[0] = y0.real() - r / 3;
x[1] = y1.real() - r / 3;
x[2] = y2.real() - r / 3;
return 3;
}
}
template <class T>
int
solveCubic (T a, T b, T c, T d, T x[3])
{
if (a == 0)
{
return solveQuadratic (b, c, d, x);
}
else
{
return solveNormalizedCubic (b / a, c / a, d / a, x);
}
}
IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
#endif // INCLUDED_IMATHROOTS_H
|
QuaternionMark/COMP371-FinalProject | Libraries/FreeImage-3170/Source/OpenEXR/IlmImf/ImfForward.h |
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2011, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// Portions (c) 2012 Weta Digital Ltd
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_IMF_FORWARD_H
#define INCLUDED_IMF_FORWARD_H
////////////////////////////////////////////////////////////////////
//
// Forward declarations for OpenEXR - correctly declares namespace
//
////////////////////////////////////////////////////////////////////
#include "ImfNamespace.h"
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
// classes for basic types;
template<class T> class Array;
template<class T> class Array2D;
struct Channel;
class ChannelList;
struct Chromaticities;
// attributes used in headers are TypedAttributes
class Attribute;
class Header;
// file handling classes
class OutputFile;
class TiledInputFile;
class ScanLineInputFile;
class InputFile;
class TiledOutputFile;
class DeepScanLineInputFile;
class DeepScanLineOutputFile;
class DeepTiledInputFile;
class DeepTiledOutputFile;
class AcesInputFile;
class AcesOutputFile;
class TiledInputPart;
class TiledInputFile;
class TileOffsets;
// multipart file handling
class GenericInputFile;
class GenericOutputFile;
class MultiPartInputFile;
class MultiPartOutputFile;
class InputPart;
class TiledInputPart;
class DeepScanLineInputPart;
class DeepTiledInputPart;
class OutputPart;
class ScanLineOutputPart;
class TiledOutputPart;
class DeepScanLineOutputPart;
class DeepTiledOutputPart;
// internal use only
struct InputPartData;
struct OutputStreamMutex;
struct OutputPartData;
struct InputStreamMutex;
// frame buffers
class FrameBuffer;
class DeepFrameBuffer;
struct DeepSlice;
// compositing
class DeepCompositing;
class CompositeDeepScanLine;
// preview image
class PreviewImage;
struct PreviewRgba;
// streams
class OStream;
class IStream;
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
#endif // include guard
|
QuaternionMark/COMP371-FinalProject | Src/Objects/Smoke.h | <reponame>QuaternionMark/COMP371-FinalProject
#ifndef SMOKE_H_INCLUDED
#define SMOKE_H_INCLUDED
#include "../Math/Vector.h"
class Shader;
class Sprite;
class Smoke {
private:
const float MIN_SCALE = 0.2f;
const float RANGE = 4.f - MIN_SCALE;
Sprite* sprite;
const float LIFESPAN = 1.f;
float age;
bool markedForRemoval;
public:
Smoke(Shader* shd, const Vector3f& position);
~Smoke();
bool isMarkedForRemoval() const;
void update(float timestep);
void render() const;
};
#endif // SMOKE_H_INCLUDED
|
QuaternionMark/COMP371-FinalProject | Libraries/FreeImage-3170/Source/OpenEXR/Iex/IexForward.h | ///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2012, Industrial Light & Magic, a division of Lucas
// Digital Ltd. LLC
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_IEXFORWARD_H
#define INCLUDED_IEXFORWARD_H
#include "IexNamespace.h"
IEX_INTERNAL_NAMESPACE_HEADER_ENTER
//
// Base exceptions.
//
class BaseExc;
class ArgExc;
class LogicExc;
class InputExc;
class IoExc;
class MathExc;
class ErrnoExc;
class NoImplExc;
class NullExc;
class TypeExc;
//
// Math exceptions.
//
class OverflowExc;
class UnderflowExc;
class DivzeroExc;
class InexactExc;
class InvalidFpOpExc;
//
// Errno exceptions.
//
class EpermExc;
class EnoentExc;
class EsrchExc;
class EintrExc;
class EioExc;
class EnxioExc;
class E2bigExc;
class EnoexecExc;
class EbadfExc;
class EchildExc;
class EagainExc;
class EnomemExc;
class EaccesExc;
class EfaultExc;
class EnotblkExc;
class EbusyExc;
class EexistExc;
class ExdevExc;
class EnodevExc;
class EnotdirExc;
class EisdirExc;
class EinvalExc;
class EnfileExc;
class EmfileExc;
class EnottyExc;
class EtxtbsyExc;
class EfbigExc;
class EnospcExc;
class EspipeExc;
class ErofsExc;
class EmlinkExc;
class EpipeExc;
class EdomExc;
class ErangeExc;
class EnomsgExc;
class EidrmExc;
class EchrngExc;
class El2nsyncExc;
class El3hltExc;
class El3rstExc;
class ElnrngExc;
class EunatchExc;
class EnocsiExc;
class El2hltExc;
class EdeadlkExc;
class EnolckExc;
class EbadeExc;
class EbadrExc;
class ExfullExc;
class EnoanoExc;
class EbadrqcExc;
class EbadsltExc;
class EdeadlockExc;
class EbfontExc;
class EnostrExc;
class EnodataExc;
class EtimeExc;
class EnosrExc;
class EnonetExc;
class EnopkgExc;
class EremoteExc;
class EnolinkExc;
class EadvExc;
class EsrmntExc;
class EcommExc;
class EprotoExc;
class EmultihopExc;
class EbadmsgExc;
class EnametoolongExc;
class EoverflowExc;
class EnotuniqExc;
class EbadfdExc;
class EremchgExc;
class ElibaccExc;
class ElibbadExc;
class ElibscnExc;
class ElibmaxExc;
class ElibexecExc;
class EilseqExc;
class EnosysExc;
class EloopExc;
class ErestartExc;
class EstrpipeExc;
class EnotemptyExc;
class EusersExc;
class EnotsockExc;
class EdestaddrreqExc;
class EmsgsizeExc;
class EprototypeExc;
class EnoprotooptExc;
class EprotonosupportExc;
class EsocktnosupportExc;
class EopnotsuppExc;
class EpfnosupportExc;
class EafnosupportExc;
class EaddrinuseExc;
class EaddrnotavailExc;
class EnetdownExc;
class EnetunreachExc;
class EnetresetExc;
class EconnabortedExc;
class EconnresetExc;
class EnobufsExc;
class EisconnExc;
class EnotconnExc;
class EshutdownExc;
class EtoomanyrefsExc;
class EtimedoutExc;
class EconnrefusedExc;
class EhostdownExc;
class EhostunreachExc;
class EalreadyExc;
class EinprogressExc;
class EstaleExc;
class EioresidExc;
class EucleanExc;
class EnotnamExc;
class EnavailExc;
class EisnamExc;
class EremoteioExc;
class EinitExc;
class EremdevExc;
class EcanceledExc;
class EnolimfileExc;
class EproclimExc;
class EdisjointExc;
class EnologinExc;
class EloginlimExc;
class EgrouploopExc;
class EnoattachExc;
class EnotsupExc;
class EnoattrExc;
class EdircorruptedExc;
class EdquotExc;
class EnfsremoteExc;
class EcontrollerExc;
class EnotcontrollerExc;
class EenqueuedExc;
class EnotenqueuedExc;
class EjoinedExc;
class EnotjoinedExc;
class EnoprocExc;
class EmustrunExc;
class EnotstoppedExc;
class EclockcpuExc;
class EinvalstateExc;
class EnoexistExc;
class EendofminorExc;
class EbufsizeExc;
class EemptyExc;
class EnointrgroupExc;
class EinvalmodeExc;
class EcantextentExc;
class EinvaltimeExc;
class EdestroyedExc;
IEX_INTERNAL_NAMESPACE_HEADER_EXIT
#endif // INCLUDED_IEXFORWARD_H
|
QuaternionMark/COMP371-FinalProject | Src/Controllers/Player.h | #ifndef PLAYER_H_INCLUDED
#define PLAYER_H_INCLUDED
#include "../Math/Vector.h"
class Camera;
class Car;
struct GLFWwindow;
class Shader;
class Player {
private:
Camera* camera;
Car* car;
bool cameraFollowingCar;
public:
Player(Shader* shd, Shader* colliderShd, Shader* spriteShd, int camWidth, int camHeight);
~Player();
Camera* getCamera() const;
void setCarShader(Shader* shd);
Vector3f getCarPosition() const;
void toggleCarHeadlightsTaillight();
void update(float timestep, GLFWwindow* window);
void render() const;
};
#endif // PLAYER_H_INCLUDED
|
DenisBabarykin/DynamicMatrixWorkExample | matrix.c | <reponame>DenisBabarykin/DynamicMatrixWorkExample
#define _CRT_NONSTDC_NO_DEPRECATE // Отключение сообщений об устаревших функциях, не входящих в стандарт
#define _CRT_SECURE_NO_WARNINGS // Отключение сообщений о небезопасных функциях
#define _CRT_SECURE_NO_DEPRECATE // Отключение сообщений об устаревших небезопасных функциях
#include <stdio.h> // Для функций printf() и scanf()
#include <conio.h> // Для функции getch()
#include <stdlib.h> // Для функций malloc() и free()
int *alloc_linear_memory_matrix_c(int row_count, int col_count);
void free_linear_memory_matrix_c(int *matrix);
int *alloc_linear_memory_matrix_cpp(int row_count, int col_count);
void free_linear_memory_matrix_cpp(int *matrix);
int **alloc_sparse_rows_memory_matrix_c(int row_count, int col_count);
void free_sparse_rows_memory_matrix_c(int **matrix, int row_count);
int **alloc_sparse_rows_memory_matrix_cpp(int row_count, int col_count);
void free_sparse_rows_memory_matrix_cpp(int **matrix, int row_count);
int **alloc_dense_rows_memory_matrix_c(int row_count, int col_count);
void free_dense_rows_memory_matrix_c(int **matrix);
int **alloc_dense_rows_memory_matrix_cpp(int row_count, int col_count);
void free_dense_rows_memory_matrix_cpp(int **matrix);
void input_linear_matrix(int *matrix, int row_count, int col_count);
void output_linear_matrix(int *matrix, int row_count, int col_count);
void input_matrix(int **matrix, int row_count, int col_count);
void output_matrix(int **matrix, int row_count, int col_count);
void main()
{
int row_count, col_count;
int *linear_matrix;
int **matrix;
printf("Input number of rows and columns:\n");
scanf("%d%d", &row_count, &col_count);
printf("\nAllocation memory for linear matrix in c-style...\n");
linear_matrix = alloc_linear_memory_matrix_c(row_count, col_count);
printf("Input matrix:\n");
input_linear_matrix(linear_matrix, row_count, col_count);
printf("Inputed matrix:\n");
output_linear_matrix(linear_matrix, row_count, col_count);
printf("Freeing memory from matrix...\n");
free_linear_memory_matrix_c(linear_matrix);
printf("\nAllocation memory for linear matrix in cpp-style...\n");
linear_matrix = alloc_linear_memory_matrix_cpp(row_count, col_count);
printf("Input matrix:\n");
input_linear_matrix(linear_matrix, row_count, col_count);
printf("Inputed matrix:\n");
output_linear_matrix(linear_matrix, row_count, col_count);
printf("Freeing memory from matrix...\n");
free_linear_memory_matrix_cpp(linear_matrix);
printf("\nAllocation memory for sparse-row matrix in c-style...\n");
matrix = alloc_sparse_rows_memory_matrix_c(row_count, col_count);
printf("Input matrix:\n");
input_matrix(matrix, row_count, col_count);
printf("Inputed matrix:\n");
output_matrix(matrix, row_count, col_count);
printf("Freeing memory from matrix...\n");
free_sparse_rows_memory_matrix_c(matrix, row_count);
printf("\nAllocation memory for sparse-row matrix in cpp-style...\n");
matrix = alloc_sparse_rows_memory_matrix_cpp(row_count, col_count);
printf("Input matrix:\n");
input_matrix(matrix, row_count, col_count);
printf("Inputed matrix:\n");
output_matrix(matrix, row_count, col_count);
printf("Freeing memory from matrix...\n");
free_sparse_rows_memory_matrix_cpp(matrix, row_count);
printf("\nAllocation memory for dense-row matrix in c-style...\n");
matrix = alloc_dense_rows_memory_matrix_c(row_count, col_count);
printf("Input matrix:\n");
input_matrix(matrix, row_count, col_count);
printf("Inputed matrix:\n");
output_matrix(matrix, row_count, col_count);
printf("Freeing memory from matrix...\n");
free_dense_rows_memory_matrix_c(matrix);
printf("\nAllocation memory for dense-row matrix in cpp-style...\n");
matrix = alloc_dense_rows_memory_matrix_cpp(row_count, col_count);
printf("Input matrix:\n");
input_matrix(matrix, row_count, col_count);
printf("Inputed matrix:\n");
output_matrix(matrix, row_count, col_count);
printf("Freeing memory from matrix...\n");
free_dense_rows_memory_matrix_cpp(matrix);
getch();
}
int *alloc_linear_memory_matrix_c(int row_count, int col_count)
{
return (int *) malloc(row_count * col_count * sizeof(int));
}
void free_linear_memory_matrix_c(int *matrix)
{
free(matrix);
}
int *alloc_linear_memory_matrix_cpp(int row_count, int col_count)
{
return new int[row_count * col_count];
}
void free_linear_memory_matrix_cpp(int *matrix)
{
delete [] matrix;
}
int **alloc_sparse_rows_memory_matrix_c(int row_count, int col_count)
{
int **matrix = (int **) malloc(row_count * sizeof(int *));
for (int i = 0; i < row_count; i++)
{
matrix[i] = (int *) malloc(col_count * sizeof(int));
}
return matrix;
}
void free_sparse_rows_memory_matrix_c(int **matrix, int row_count)
{
for (int i = 0; i < row_count; i++)
{
free(matrix[i]);
}
free(matrix);
}
int **alloc_sparse_rows_memory_matrix_cpp(int row_count, int col_count)
{
int **matrix = new int*[row_count];
for (int i = 0; i < row_count; i++)
{
matrix[i] = new int[col_count];
}
return matrix;
}
void free_sparse_rows_memory_matrix_cpp(int **matrix, int row_count)
{
for (int i = 0; i < row_count; i++)
{
delete [] matrix[i];
}
delete [] matrix;
}
int **alloc_dense_rows_memory_matrix_c(int row_count, int col_count)
{
int **matrix = (int **) malloc(row_count * sizeof(int *) + row_count * col_count * sizeof(int));
int *matrix_body = (int *) (matrix + row_count);
for (int i = 0; i < row_count; i++)
{
matrix[i] = matrix_body + i * col_count;
}
return matrix;
}
void free_dense_rows_memory_matrix_c(int **matrix)
{
free(matrix);
}
int **alloc_dense_rows_memory_matrix_cpp(int row_count, int col_count)
{
int **matrix = (int **) new char[row_count * sizeof(int *) + row_count * col_count * sizeof(int)];
int *matrix_body = (int *)(matrix + row_count);
for (int i = 0; i < row_count; i++)
{
matrix[i] = matrix_body + i * col_count;
}
return matrix;
}
void free_dense_rows_memory_matrix_cpp(int **matrix)
{
delete [] matrix;
}
void input_linear_matrix(int *matrix, int row_count, int col_count)
{
for (int i = 0; i < row_count; i++)
for (int j = 0; j < col_count; j++)
scanf("%d", matrix + i * col_count + j);
}
void output_linear_matrix(int *matrix, int row_count, int col_count)
{
for (int i = 0; i < row_count; i++)
{
for (int j = 0; j < col_count; j++)
printf("%d ", matrix[i * col_count + j]);
printf("\n");
}
}
void input_matrix(int **matrix, int row_count, int col_count)
{
for (int i = 0; i < row_count; i++)
for (int j = 0; j < col_count; j++)
scanf("%d", &matrix[i][j]);
}
void output_matrix(int **matrix, int row_count, int col_count)
{
for (int i = 0; i < row_count; i++)
{
for (int j = 0; j < col_count; j++)
printf("%d ", matrix[i][j]);
printf("\n");
}
}
|
meesokim/z80asm | zmac.c | /* A Bison parser, made by GNU Bison 3.0.2. */
/* Bison implementation for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* C LALR(1) parser skeleton written by <NAME>, by
simplifying the original so-called "semantic" parser. */
/* All symbols defined below should begin with yy or YY, to avoid
infringing on user name space. This should be done even for local
variables, as they might otherwise be expanded by user macros.
There are some unavoidable exceptions within include files to
define necessary library symbols; they are noted "INFRINGES ON
USER NAME SPACE" below. */
/* Identify Bison output. */
#define YYBISON 1
/* Bison version. */
#define YYBISON_VERSION "3.0.2"
/* Skeleton name. */
#define YYSKELETON_NAME "yacc.c"
/* Pure parsers. */
#define YYPURE 0
/* Push parsers. */
#define YYPUSH 0
/* Pull parsers. */
#define YYPULL 1
#define stderr stdout
/* Copy the first part of user declarations. */
////#line 1 "zmac.y" /* yacc.c:339 */
// GWP - keep track of version via hand-maintained date stamp.
#define VERSION "3dec2014"
/*
* zmac -- macro cross-assembler for the Zilog Z80 microprocessor
*
* <NAME> 4/78
*
* Last modification 1-18-87 by cdk
* This assembler is modeled after the Intel 8080 macro cross-assembler
* for the Intel 8080 by <NAME>. The major features are:
* 1. Full macro capabilities
* 2. Conditional assembly
* 3. A very flexible set of listing options and pseudo-ops
* 4. Symbol table output
* 5. Error report
* 6. Elimination of sequential searching
* 7. Commenting of source
* 8. Facilities for system definiton files
*
* Revision History:
*
* jrp 3-8-82 Converted to run on Vax, updated syntax to conform better
* to the Zilog standard.
*
* jrp 3-15-82 Added underscore as a character type in the lex table
* 'numpart' (0x5F).
*
* Changed maximum number of characters in a label to 15
* from 7. Note that 'putsymtab' uses this value inside
* of a quoted string, so we use 15.
*
* jrp 2-15-83 Fixed 'getlocal' to return better local labels. It used
* to crash after 6 invocations.
*
* jrp 6-7-83 Fixed bug in the ADD IX,... instruction.
*
* jrp 5-11-84 Added code to print unused labels out with the symbol table
* Also sped up the macro processor by using stdio.
*
* jrp 5-22-84 Added include files ala ormac
*
* jrp 8-27-84 Added PHASE/DEPHASE commands
*
* cdk 9-20-86 Converted to run on a Pyramid. This meant changing yylval
* to be a %union, and then putting in the appropriate
* typecasts where ints are pointers are used interchangeably.
* The current version still probably won't run on machines where
* sizeof(int) != sizeof(char *).
* Also changed emit() to use varargs, and got rid of the
* old style = in front of yacc action code.
* -<NAME> vu-vlsi!colin
*
* cdk 10-2-86 Added some more typecasts to keep lint a little happier.
* Removed several unused variables. Changed most vars
* declared as char to int, since many of them were being
* compared with -1! I still don't know what's going on with
* est[][] being malloc'd and free'd everywhere...it looks pretty
* fishy...
*
* cdk 1-18-87 Added MIO code to emulate 'mfile' using malloc()'d memory.
* This was needed to get the code to work when compiled under
* MSC 4.0 on a PC, and it's probably faster anyway.
*
* cdk 2-5-87 Added 'cmp' as a synonym for 'cp', 'jmp' as a synonym for
* 'jp', and added tolerance of accumulator specification for arithmetic
* and logical instructions. (For example, 'or a,12' is now accepted,
* same as 'or 12'.)
*
* gwp 12-29-08 Changes to allow compilation with modern C compiler and using bison
* as the .y to .c converter. assert, tstate pseudo-ops.
* t(), tilo(), tihi() functions. ==, <=, >=, !=, !, <, > operators.
* -c to turn cycle counts off in listing. Usage, -h and version.
*
* gwp 9-26-10 Add ocf() and setocf to track and set op code fetch counts.
* Add sett as an alias for tstate
*
* gwp 12-30-11 Add undocumented instructions sl1, pfix, pfiy, in (c), out (c),0
* bit/set/res (ixy+d),reg and ld/inc/dec ixylh.
*
* gwp 2-8-12 Increase MAXIFS massively due to massive lowt macro
*
* gwp 2-11-12 Support 32 bit constants. '%' alias for MOD. Add defd, dword.
* lo(x) and hi(x) for easy low and high byte extraction. Allow
* filenames longer than 15 characters. All output to "zout" subdirectory
* of source file.
*
* gwp 2-15-12 Perform multiple passes while equates are changing. Support
* .label for temporary label definitions and _label for file
* scoped labels. Allow '.' within labels. Assert listing bugfix.
*
* gwp 4-27-12 Implement $ prefixed hex constants and double-quoted strings.
*
* gwp 6-30-12 Minor changes to allow compilation with gcc.
*
* gwp 9-05-12 incbin added.
*
* gwp 11-24-12 Fix macro expansion bug when symbol larger than MAXSYMBOLSIZE
* due to file name prepending when symbol starts with '_'.
*
* gwp 12-04-12 Optional JR promotion and JP demotion errors. Output a warning
* if no execute address given. Output ".bds" file to enable easy
* simple source level debugging.
*
* gwp 4-14-13 Parens in expressions, else, .pseudo, full set of C operators
* with conventional precedence and various aliases and code
* changes to make source similar to zmac 1.3 on internet.
*
* gwp 5-5-13 .cmd,.cas,.lcas,.bin output. dc (both MACRO-80 and EDAS types).
* lo, hi renamed to low, high and make unary operators. Allow
* label::, placeholder public, extern declarations. Bug fixes
* in defs, t, ocf, tihi, tilo in phase mode. Initial support
* for -I include directories. 0x hex constants. --mras flag for
* limited MRAS compatibility (allows $ in labels, $? to start
* labels).
*
* gwp 4-6-13 --rel for .rel (Microsoft linker) output and extern, public,
* aseg, cseg, dseg in support (big emit + expression revamp).
* -I follows C preprocessor convention, output relative to
* current directory. 8080 mnemonics, .z80, .8080, -z, -8.
* Change .bin to .cim. Warn on labels not in first column.
*
* gwp 8-11-13 Allow $ to start identifiers and do '$' dropping when macro
* parsed so we no longer need to drop '$' in identifiers.
* Even $FCB allowed, with warning. Add --zmac for backwards
* compatibility with zmac. ` now used for joining in macros.
* Most reserved words can be used as labels or variables.
* Free-form title, name, comment, subttl parsing. Allow #arg
* for macro arguments (in --mras mode). Support <CR> delimited
* files. Add .ams output. Integrate documentation (--doc).
*
* gwp 3-12-14 Emit jr even if out of range. z80.lib support.
* Warning and bug fixes from <NAME>.
* Macros can override built-ins and are no longer listed
* in symbol table. A, B, C, D, E, H, L, M, PSW, SP are
* pre-defined values which can be used in data statements
* (db, dw, dd). Reserved words can be equated but are only
* accessbile in data. SET can be used in place of DEFL
* (MAC and MACRO-80 agree on this). '=' can be used in place
* of EQU. 'maclib file' includes 'file.lib'. Bug fix in "dw 0,$".
* Removed error flagging in expressions which could cause parse
* to fail from that point onwards.
* expression(ix) equivalent to (ix + expression).
* Macro expanded lines didn't go through the line analyzer.
* Empty macro arguments (e.g., mac 1,,2)
* Implemented rept, irp, irpc, exitm. Add more detail on phase
* errors. '' is an empty string in db/ascii/etc, 0 otherwise.
* Almost any name can be used as a macro parameter name.
* Allow 'if' in first column.
* Fix .rel mode bug in dc, incbin.
* Emit .bds output for dc, incbin.
* Allow assembly to wrap past end of memory.
* "pragma bds" for raw output to .bds file. Also output equates
* to .bds file.
* Macro bug fix from <NAME>.
*/
#define MIO /* use emulation routines from mio.c */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <time.h>
#include <sys/stat.h>
#ifdef WIN32
#include <windows.h> // just for colouring the output
#include <tchar.h>
#endif
#include "zi80dis.h"
#ifdef vax11c
#define unlink(filename) delete(filename)
#endif
#ifdef MIO
#include "mio.h"
FILE *mfopen();
#else
#define mfopen(filename,mode) fopen(filename,mode)
#define mfclose(filename,mode) fclose(filename,mode)
#define mfputc(c,f) putc(c,f)
#define mfgetc(f) getc(f)
#define mfseek(f,loc,origin) fseek(f,loc,origin)
#define mfread(ptr,size,nitems,f) fread(ptr,size,nitems,f)
#define mfwrite(ptr,size,nitems,f) fread(ptr,size,nitems,f)
#endif /* MIO */
/*
* DEBUG turns on pass reporting.
* DBUG enables -d to allow yacc/bison yydebug increment (but must be passed
* on the command line)
* Macro debug and Token debug enables.
#define DEBUG
#define M_DEBUG
#define T_DEBUG
*/
#ifdef DBUG
#define YYDEBUG 1
#endif
#define ITEMTABLESIZE 100000
#define TEMPBUFSIZE (1000+MAXSYMBOLSIZE)
#define LINEBUFFERSIZE 1000
#define EMITBUFFERSIZE 200
#define MAXSYMBOLSIZE 40
#define IFSTACKSIZE 20
// GWP - I use lots of if's with my lowt macro
#define MAXIFS 65536
#define TITLELEN 50
#define BINPERLINE 16
#define PARMMAX 25
#define MAXEXP 25
#define SYMMAJIC 07203
#define NEST_IN 32
#define MAXPASS 32
#define MAXINCPATH 32
int iflist();
int yylex();
int phaseaddr(int addr);
int nextchar();
int getcol();
int skipline(int ac);
int tokenofitem(int deftoken, int keyexclude, int keyinclude);
int getm();
int counterr();
int countwarn();
void yyerror(char *err)
{} /* we will do our own error printing */
struct argparse {
char *arg; // output buffer for argument
int argsize; // size of output buffer
int (*getch)(struct argparse *); // get next character
int *peek; // pointer single item pushback buffer
int macarg; // working on macro arguments
char *user_ptr; // state for getch
int user_int; // state for getch
int user_peek; // state for getch
int didarg; // internal parsing state
int numarg; // internal parsing state
};
int getarg(struct argparse *ap);
struct item {
char *i_string;
int i_value;
int i_token;
int i_uses;
int i_scope;
int i_chain;
};
void itemcpy(struct item *dst, struct item *src);
struct item *keyword(char *name);
#define SCOPE_NONE (0)
#define SCOPE_PROGRAM (1)
#define SCOPE_DATA (2)
#define SCOPE_PUBLIC (4)
#define SCOPE_EXTERNAL (8)
#define SCOPE_NORELOC (16)
#define SCOPE_BUILTIN (32) /* abuse */
#define SCOPE_SEGMASK (3)
#define SCOPE_SEG(s) ((s) & SCOPE_SEGMASK)
struct expr {
int e_value;
int e_scope;
int e_token;
struct item *e_item;
struct expr *e_left;
struct expr *e_right;
};
#define EXPR_SEG(e) SCOPE_SEG(e->e_scope)
FILE *fout,
*fbuf,
*fbds,
*fcmd,
*fcas,
*flcas,
*fcim,
*fams,
*frel,
*fin[NEST_IN],
*now_file ;
int pass2; /*set when pass one completed*/
int outpass; // set when we decide to stop doing passes */
int passfail; // set when an error means passes should not continue
int passretry; // set when an inconsistency will require another pass
int dollarsign ; /* location counter */
int olddollar ; /* kept to put out binary */
int oldothdollar; // output address of next .cmd/.cas/.lcas block
int emit_addr; // were code and data are being placed in memory
int tstates; // cumulative T-states
int ocf; // cumulative op code fetches
int llseq; // local label sequence number
int mras; // MRAS semi-compatibility mode
int zcompat; // Original zmac compatibility mode
char modstr[8]; // Replacement string for '?' in labels when MRAS compatible
int relopt; // Only output .rel files.
char progname[8]; // Program name for .rel output
int note_depend; // Print names of files included
int firstcol;
int logcol;
int coloncnt;
int full_exprs; // expression parsing mode allowing almost any identifier
struct item *label, pristine_label; //
int list_dollarsign;// flag used to change list output for some operations
int list_addr; // address to display for operation if !list_dollarsign
// Include file search path
char *incpath[MAXINCPATH];
int incpath_cnt;
/* program counter save for PHASE/DEPHASE */
int phdollar, phbegin, phaseflag ;
char *src_name[NEST_IN] ;
int linein[NEST_IN] ;
int now_in ;
// These first 5 errors are singled out in lsterr1() for reasons I don't
// quite understand.
#define bflag 0 /* balance error */
#define eflag 1 /* expression error */
#define fflag 2 /* syntax error */
#define iflag 3 /* bad digits */
#define mflag 4 /* multiply defined */
#define pflag 5 /* phase error */
#define uflag 6 /* undeclared used */
#define vflag 7 /* value out of range */
#define oflag 8 /* phase/dephase error */
#define aflag 9 /* assert failed */
#define jflag 10 /* JP could be JR */
#define rflag 11 /* expression not relocatable */
#define gflag 12 /* incorrect register */
#define zflag 13 /* Z-80 instruction */
#define FIRSTWARN warn_hex
#define warn_hex 14
#define warn_notimpl 15
#define warn_general 16
#define FLAGS 17 /* number of errors and warnings */
char err[FLAGS];
int keeperr[FLAGS];
char errlet[FLAGS]="BEFIMPUVOAJRGZHNW";
char *errname[FLAGS]={
"Balance",
"Expression",
"Syntax",
"Digit",
"Mult. def.",
"Phase",
"Undeclared",
"Value",
"Phase/Dephase",
"Assertion failure",
"Use JR",
"Not relocatable",
"Register usage",
"Z-80 instruction in 8080 mode",
"$hex constant interpreted as symbol",
"Not implemented",
"General"
};
char errdetail[FLAGS][1024];
char detail[1024];
unsigned char inpbuf[LINEBUFFERSIZE];
unsigned char *inpptr;
char linebuf[LINEBUFFERSIZE];
char *lineptr;
char *linemax = linebuf+LINEBUFFERSIZE;
char outbin[BINPERLINE];
char *outbinp = outbin;
char *outbinm = outbin+BINPERLINE;
char outoth[256];
int outoth_cnt = 0;
unsigned char emitbuf[EMITBUFFERSIZE];
unsigned char *emitptr;
char ifstack[IFSTACKSIZE];
char *ifptr;
char *ifstmax = ifstack+IFSTACKSIZE-1;
char hexadec[] = "0123456789ABCDEF" ;
int nitems;
int linecnt;
int nbytes;
int invented;
int npass;
int njrpromo;
char tempbuf[TEMPBUFSIZE];
char *tempmax = tempbuf+TEMPBUFSIZE-1;
char arg_flag;
struct argparse arg_state;
void arg_start();
void arg_reset();
int str_getch(struct argparse *ap);
char inmlex;
char mlex_list_on;
int parm_number;
int exp_number;
char symlong[] = "Symbol/number too long";
int raw;
int disp;
int param_parse;
#define PARAMTABSIZE (PARMMAX * 2)
struct item paramtab[PARAMTABSIZE];
#define FLOC PARMMAX
#define TEMPNUM PARMMAX+1
#define REPNUM PARMMAX+2
#define MSTART PARMMAX+3
#define MSTR PARMMAX+4
#define MARGP PARMMAX+5
#define MIF PARMMAX+6
#define PAREXT 7
union exprec {
char *param;
int value;
struct argparse *ap;
};
union exprec *est;
union exprec *est2;
union exprec *expstack[MAXEXP];
int expptr;
int floc;
int mfptr;
FILE *mfile;
char *writesyms;
char *title;
char titlespace[TITLELEN];
char *timp;
char *sourcef;
/* changed to cope with filenames longer than 14 chars -rjm 1998-12-15 */
char src[1024];
char bin[1024];
char mtmp[1024];
char listf[1024];
char bds[1024];
char oth[1024];
char bopt = 1,
copt = 1, /* cycle counts in listings by default */
edef = 1,
eopt = 1,
fdef = 0,
fopt = 0,
gdef = 1,
gopt = 1,
iopt = 0 , /* list include files */
jopt = 0,
JPopt = 0,
lstoff = 0,
lston = 0, /* flag to force listing on */
lopt = 0,
mdef = 0,
mopt = 0,
nopt = 1 , /* line numbers on as default */
oopt = 0,
popt = 1, /* form feed as default page eject */
sopt = 0, /* turn on symbol table listing */
topt = 1, /* terse, only error count to terminal */
printer_output = 0, // GWP - printer style output
z80,
saveopt;
char default_jopt, default_JPopt, default_z80 = 1;
char xeq_flag = 1;
int xeq;
time_t now;
int line;
int page = 1;
struct stab {
char t_name[MAXSYMBOLSIZE+1];
int t_value;
int t_token;
};
// GWP - support for cycle count tracking (and opens door for efficient .cmd, etc. output)
unsigned char memory[1 << 16];
char memflag[1 << 16];
enum {
MEM_DATA = 1,
MEM_INST = 2,
MEM_T_SET = 4
};
int tstatesum[1 << 16];
int ocfsum[1 << 16];
// GWP - expression handling extensions for .rel output.
void advance_segment(int step);
void expr_reloc_check(struct expr *ex);
void expr_number_check(struct expr *ex);
void expr_scope_same(struct expr *ex1, struct expr *ex2);
void expr_word_check(struct expr *ex);
int is_number(struct expr *ex);
int is_external(struct expr *ex);
struct expr *expr_num(int value);
struct expr *expr_alloc(void);
struct expr *expr_op(struct expr *left, int token, struct expr *right, int value);
struct expr *expr_op_sc(struct expr *left, int token, struct expr *right, int value);
void expr_free(struct expr *ex);
int can_extend_link(struct expr *ex);
void extend_link(struct expr *ex);
void putrelop(int op);
#define RELOP_BYTE (1)
#define RELOP_WORD (2)
#define RELOP_HIGH (3)
#define RELOP_LOW (4)
#define RELOP_NOT (5)
#define RELOP_NEG (6)
#define RELOP_SUB (7)
#define RELOP_ADD (8)
#define RELOP_MUL (9)
#define RELOP_DIV (10)
#define RELOP_MOD (11)
struct item *item_lookup(char *name, struct item *table, int table_size);
struct item *locate(char *name);
// Data descriptions for emit()
#define E_CODE (0)
#define E_DATA (1)
#define E_CODE8 (2)
#define E_CODE16 (3)
int segment;
#define SEGCHAR(s) " '\"!"[s]
#define SEG_ABS (0)
#define SEG_CODE (1)
#define SEG_DATA (2)
int seg_pos[4]; // may eventually support SEG_COMMON
int seg_size[4];
int rel_main;
int segchange;
void putout(int value);
int outrec;
int outlen;
unsigned char outbuf[1024 * 1024];
/*
* push back character
*/
int peekc;
int nextline_peek;
/* function prototypes */
void error(char *as);
void usage(char *msg, char *param);
void help();
void erreport();
void errorprt(int errnum);
void errwarn(int errnum, char *message);
void mlex(char *look);
void popsi();
void suffix(char *str, char *suff);
char *basename(char *filename);
char *getsuffix(char *str);
void outpath(char *out, char *src, char *suff);
void casname(char *out, char *src);
void putm(int c);
void insymtab(char *name);
void outsymtab(char *name);
void compactsymtab();
void putsymtab();
void clear();
void setmem(int addr, int value, int type);
void setvars();
void flushbin();
void flushoth();
void lineout();
void puthex(int byte, FILE *buf);
void putcas(int byte);
void putrelbits(int count, int bits);
void putrel(int byte);
void putrelname(char *str);
void putrelextaddr(int extaddr);
void putrelcmd(int cmd);
void putrelsegref(int scope, int addr);
void flushrel(void);
void lsterr1();
void lsterr2(int lst);
void copyname(char *st1, char *st2);
void next_source(char *sp);
void incbin(char *filename);
void dc(int count, int value);
char *getmraslocal();
#define RELCMD_PUBLIC (0)
#define RELCMD_COMMON (1)
#define RELCMD_PROGNAME (2)
#define RELCMD_LIBLOOK (3)
#define RELCMD_EXTLINK (4)
#define RELCMD_COMSIZE (5)
#define RELCMD_EXTCHAIN (6)
#define RELCMD_PUBVALUE (7)
#define RELCMD_EXTMINUS (8)
#define RELCMD_EXTPLUS (9)
#define RELCMD_DATASIZE (10)
#define RELCMD_SETLOC (11)
#define RELCMD_CODESIZE (13)
#define RELCMD_ENDMOD (14)
#define RELCMD_ENDPROG (15)
/*
* add a character to the output line buffer
*/
void addtoline(int ac)
{
/* check for EOF from stdio */
if (ac == -1)
ac = 0 ;
if (lineptr >= linemax)
error("line buffer overflow");
*lineptr++ = ac;
}
/*
* put values in buffer for outputing
*/
void emit(int bytes, int desc, struct expr *data, ...)
{
int type, i, args, dsize;
va_list ap;
if (relopt && segchange) {
segchange = 0;
putrelcmd(RELCMD_SETLOC);
putrelsegref(segment, seg_pos[segment]);
}
// External references only supported in .rel output.
if (!relopt && data && (data->e_scope & SCOPE_EXTERNAL)) {
sprintf(detail, "External references only allowed in .rel output\n");
errwarn(uflag, detail);
}
va_start(ap, data);
type = desc == E_DATA ? MEM_DATA : MEM_INST;
// Check emit is not adding instructions to the buffer.
if (desc != E_DATA && emitptr != emitbuf)
fprintf(stderr, "internal inconsistency in t-state counting\n");
dsize = 0;
args = bytes;
if (desc == E_DATA) {
args = 0;
dsize = bytes;
}
else if (desc == E_CODE16)
dsize = 2;
else if (desc == E_CODE8)
dsize = 1;
for (i = 0; i < args; i++)
{
if (emitptr >= &emitbuf[EMITBUFFERSIZE])
error("emit buffer overflow");
else {
int addr = (emit_addr + (emitptr - emitbuf)) & 0xffff;
*emitptr = va_arg(ap, int);
if (segment == SEG_CODE)
setmem(addr, *emitptr, type);
putrel(*emitptr);
putout(*emitptr);
emitptr++;
}
}
va_end(ap);
for (i = 0; i < dsize; i++) {
int addr = (emit_addr + (emitptr - emitbuf)) & 0xffff;
*emitptr = data->e_value >> (i * 8);
if (segment == SEG_CODE)
setmem(addr, *emitptr, type);
putout(*emitptr);
emitptr++;
}
if (desc != E_DATA)
{
int eaddr = emit_addr, low, fetch, low8080, addr_after;
// emitbuf is OK since this only happens with single emits
if (!z80) {
// Check for invalid 8080 instructions.
int op = emitbuf[0] & 0xff;
if (op == 0x08 || op == 0x10 || op == 0x18 ||
op == 0x20 || op == 0x28 || op == 0x30 ||
op == 0x38 || op == 0xCB || op == 0xD9 ||
op == 0xDD || op == 0xED || op == 0xFD)
{
err[zflag]++;
}
}
zi_tstates(emitbuf, &low, 0, &fetch, &low8080, 0);
if (!z80)
low = low8080;
// Sanity check
if (low <= 0)
{
fprintf(stderr, "undefined instruction on %02x %02x (assembler or diassembler broken)\n",
emitbuf[0], emitbuf[1]);
}
// Special case to catch promotion of djnz to DEC B JP NZ
// Even update the tstatesum[] counter though that seems to
// me to be above and beyond.
if (emitbuf[0] == 5 && args == 2) {
tstatesum[eaddr] = tstates;
ocfsum[eaddr] = ocf;
memflag[eaddr] |= MEM_T_SET;
eaddr++;
tstates += low;
ocf += fetch;
low = 10;
// still 1 fetch
}
// Double setting of both sides of tstatesum[] seems like too
// much, but must be done in the isolated instruction case:
// org x ; inc a ; org y
tstatesum[eaddr] = tstates;
ocfsum[eaddr] = ocf;
memflag[eaddr] |= MEM_T_SET;
// Well, OK, should we default to high or low???
// Guess it should be whatever makes sense for you
// to get here which, generally, is the low.
// low it is.
tstates += low;
ocf += fetch;
addr_after = (emit_addr + (emitptr - emitbuf)) & 0xffff;
tstatesum[addr_after] = tstates;
ocfsum[addr_after] = ocf;
memflag[addr_after] |= MEM_T_SET;
}
if (relopt && outpass && dsize > 0) {
if (dsize == 1) {
if (is_number(data))
putrel(data->e_value);
else if (can_extend_link(data)) {
extend_link(data);
putrelop(RELOP_BYTE);
putrel(0);
}
else {
err[rflag]++;
putrel(0);
}
}
else if (dsize == 2) {
int handled = 0;
if (data->e_scope & SCOPE_EXTERNAL) {
struct item *var = 0;
int offset = 0;
// Simple external reference.
if (is_external(data))
var = data->e_item;
else if (is_external(data->e_left) &&
data->e_token == '+' &&
is_number(data->e_right))
{
var = data->e_left->e_item;
offset = data->e_right->e_value;
}
else if (is_number(data->e_left) &&
data->e_token == '+' &&
is_external(data->e_right))
{
offset = data->e_left->e_value;
var = data->e_right->e_item;
}
else if (is_external(data->e_left) &&
data->e_token == '-' &&
is_number(data->e_right))
{
var = data->e_left->e_item;
offset = data->e_right->e_value;
}
if (var && offset) {
putrelcmd(data->e_token == '-' ?
RELCMD_EXTMINUS : RELCMD_EXTPLUS);
// Theoretically we could put a
// program or data relative value here...
putrelsegref(SEG_ABS, offset);
}
if (var) {
if (var->i_chain == 0) {
putrel(0);
putrel(0);
}
else {
putrelbits(1, 1);
putrelextaddr(var->i_chain);
}
var->i_chain = (segment << 16) |
((dollarsign + args) & 0xffff);
handled = 1;
}
}
else if ((data->e_scope & ~SCOPE_PUBLIC) == 0) {
// nice constant value
putrel(data->e_value);
putrel(data->e_value >> 8);
handled = 1;
}
else if (!(data->e_scope & SCOPE_NORELOC)) {
// relocatable value
putrelbits(1, 1);
putrelbits(2, data->e_scope);
putrelbits(8, data->e_value);
putrelbits(8, data->e_value >> 8);
handled = 1;
}
if (!handled) {
if (can_extend_link(data)) {
extend_link(data);
putrelop(RELOP_WORD);
putrel(0);
putrel(0);
}
else {
err[rflag]++;
putrel(data->e_value);
putrel(data->e_value >> 8);
}
}
}
else if (dsize == 4) {
// Only numbers are allowed.
if (data->e_scope != 0) {
err[vflag]++;
if (data->e_scope & SCOPE_NORELOC)
err[rflag]++;
}
for (i = 0; i < dsize; i++)
putrel(data->e_value >> (i * 8));
}
else
error("internal dsize error");
}
}
#define ET_NOARG_DISP (0)
#define ET_NOARG (1)
#define ET_BYTE (2)
#define ET_WORD (5)
void emit1(int opcode, int regvalh, struct expr *data, int type)
{
if (type == ET_BYTE && (data->e_value < -128 || data->e_value > 255))
err[vflag]++;
if (regvalh & 0x10000) {
switch (type) {
case ET_NOARG_DISP:
emit(2, E_CODE, 0, regvalh >> 8, opcode);
break;
case ET_BYTE:
emit(2, E_CODE8, data, regvalh >> 8, opcode);
break;
}
}
else if (regvalh & 0x8000) {
switch (type) {
case ET_NOARG_DISP:
if (opcode & 0x8000)
emit(4, E_CODE, 0, regvalh >> 8, opcode >> 8, disp, opcode);
else
emit(3, E_CODE, 0, regvalh >> 8, opcode, disp);
break;
case ET_NOARG:
emit(2, E_CODE, 0, regvalh >> 8, opcode);
break;
case ET_BYTE:
emit(3, E_CODE8, data, regvalh >> 8, opcode, disp);
break;
case ET_WORD:
emit(2, E_CODE16, data, regvalh >> 8, opcode);
}
} else
switch(type) {
case ET_NOARG_DISP:
case ET_NOARG:
if (opcode & 0100000)
emit(2, E_CODE, 0, opcode >> 8, opcode);
else
emit(1, E_CODE, 0, opcode);
break;
case ET_BYTE:
emit(1, E_CODE8, data, opcode);
break;
case ET_WORD:
if (opcode & 0100000)
emit(2, E_CODE16, data, opcode >> 8, opcode);
else
emit(1, E_CODE16, data, opcode);
}
}
void emitdad(int rp1,int rp2)
{
if (rp1 & 0x8000)
emit(2, E_CODE, 0, rp1 >> 8, rp2 + 9);
else
emit(1, E_CODE, 0, rp2 + 9);
}
void emitjr(int opcode, struct expr *dest)
{
int disp = dest->e_value - dollarsign - 2;
if (dest->e_scope & SCOPE_NORELOC)
err[rflag]++;
// Can't relative jump to other segments or an external
// However, without .rel output we default to the code segment
// for various reasons thus we let "jr 0" (and such) be acceptable
// in those cases.
if (((relopt && (dest->e_scope & SCOPE_SEGMASK) != segment) ||
(dest->e_scope & SCOPE_EXTERNAL) ||
disp > 127 || disp < -128) && z80)
{
if (jopt) {
njrpromo++;
switch (opcode) {
case 0x10: // DJNZ
emit(2, E_CODE16, dest, 0x05, 0xC2); // DEC B, JP NZ
break;
case 0x18: // JR
emit(1, E_CODE16, dest, 0xC3); // JP
break;
case 0x20: // JR NZ
emit(1, E_CODE16, dest, 0xC2); // JP NZ
break;
case 0x28: // JR Z
emit(1, E_CODE16, dest, 0xCA); // JP Z
break;
case 0x30: // JR NC
emit(1, E_CODE16, dest, 0xD2); // JP NC
break;
case 0x38: // JR C
emit(1, E_CODE16, dest, 0xDA); // JP C
break;
default:
err[vflag]++; // shouldn't happen!
expr_free(dest);
break;
}
}
else {
emit(2, E_CODE, 0, opcode, -2); // branch to itself
err[vflag]++;
expr_free(dest);
}
}
else {
emit(2, E_CODE, 0, opcode, disp);
expr_free(dest);
}
}
void checkjp(int op, struct expr *dest)
{
op &= 0x030;
// Only applies to Z-80 output and if JP optimization checking is on.
// JR only has z, nz, nc, c
// A jump to the current segment might have been optimizable
if (z80 && JPopt && (op == 0 || op == 010 || op == 020 || op == 030) &&
(dest->e_scope & (SCOPE_SEGMASK | SCOPE_EXTERNAL)) == segment)
{
int disp = dest->e_value - dollarsign - 2;
if (disp >= -128 && disp <= 127)
err[jflag]++;
}
}
/*
* put out a byte of binary
*/
void putbin(int v)
{
if(!outpass || !bopt) return;
*outbinp++ = v;
if (outbinp >= outbinm) flushbin();
outoth[outoth_cnt++] = v;
if (outoth_cnt == 256) flushoth();
}
/*
* output one line of binary in INTEL standard form
*/
void flushbin()
{
char *p;
int check=outbinp-outbin;
if (!outpass || !bopt)
return;
nbytes += check;
if (check) {
putc(':', fbuf);
puthex(check, fbuf);
puthex(olddollar>>8, fbuf);
puthex(olddollar, fbuf);
puthex(0, fbuf);
check += (olddollar >> 8) + olddollar;
olddollar += (outbinp-outbin);
for (p=outbin; p<outbinp; p++) {
puthex(*p, fbuf);
check += *p;
}
puthex(256-check, fbuf);
putc('\n', fbuf);
outbinp = outbin;
}
}
/*
* put out one byte of hex
*/
void puthex(int byte, FILE *buf)
{
putc(hexadec[(byte >> 4) & 017], buf);
putc(hexadec[byte & 017], buf);
}
// Case-independent strcmp()
int ci_strcmp(char *s1, char *s2)
{
int c1, c2;
do {
c1 = *s1++;
if (c1 >= 'A' && c1 <= 'Z') c1 += 'a' - 'A';
c2 = *s2++;
if (c2 >= 'A' && c2 <= 'Z') c2 += 'a' - 'A';
if (c1 != c2)
return c1 - c2;
} while (c1 && c2);
return 0;
}
void flushoth()
{
int i, checksum;
if (!outpass || !bopt || outoth_cnt == 0)
return;
fprintf(fcmd, "%c%c%c%c", 1, outoth_cnt + 2, oldothdollar, oldothdollar >> 8);
fwrite(outoth, outoth_cnt, 1, fcmd);
putcas(0x3c);
putcas(outoth_cnt);
putcas(oldothdollar);
putcas(oldothdollar >> 8);
checksum = oldothdollar + (oldothdollar >> 8);
for (i = 0; i < outoth_cnt; i++) {
putcas(outoth[i]);
checksum += outoth[i];
}
putcas(checksum);
oldothdollar += outoth_cnt;
outoth_cnt = 0;
}
int casbit, casbitcnt = 0;
void putcas(int byte)
{
fputc(byte, flcas);
// Buffer 0 stop bit and the 8 data bits.
casbit = (casbit << 9) | (byte & 0xff);
casbitcnt += 9;
while (casbitcnt >= 8) {
casbitcnt -= 8;
fputc(casbit >> casbitcnt, fcas);
}
}
void casname(char *out, char *src)
{
char *base = basename(src);
int i;
out[0] = 'N';
for (i = 1; i < 6; i++)
out[i] = ' ';
for (i = 0; *base && i < 6; base++) {
if (ci_strcmp(base, ".z") == 0)
break;
if (*base >= 'a' && *base <= 'z') {
*out++ = *base - ('a' - 'A');
i++;
}
else if (*base >= 'A' && *base <= 'Z') {
*out++ = *base;
i++;
}
}
}
int relbit, relbitcnt = 0;
void putrelbits(int count, int bits)
{
if (!outpass || !relopt)
return;
relbit <<= count;
relbit |= bits & ((1 << count) - 1);
relbitcnt += count;
while (relbitcnt >= 8) {
relbitcnt -= 8;
fputc(relbit >> relbitcnt, frel);
}
}
void putrel(int byte)
{
// Add 0 bit indicating byte to load at next counter
putrelbits(1, 0);
// Add byte to load
putrelbits(8, byte);
}
void putrelname(char *str)
{
int len = strlen(str);
// .rel file format can do strings 7 long but for compatibility
// we restrict them to 6. I believe this is important because
// extended link functions require a character when they wish to
// operate on an external symbol.
if (len > 6)
len = 6;
putrelbits(3, len);
while (len-- > 0) {
int ch = *str++;
if (ch >= 'a' && ch <= 'z')
ch -= 'a' - 'A';
putrelbits(8, ch);
}
}
void putrelsegref(int scope, int addr)
{
putrelbits(2, scope);
putrelbits(8, addr);
putrelbits(8, addr >> 8);
}
void putrelextaddr(int extaddr)
{
putrelsegref(extaddr >> 16, extaddr);
}
void putrelcmd(int relcmd)
{
putrelbits(1, 1);
putrelbits(2, 0);
putrelbits(4, relcmd);
}
void flushrel(void)
{
if (relbitcnt > 0)
putrelbits(8 - relbitcnt, 0);
if (relopt)
fflush(frel);
}
/*
* put out a line of output -- also put out binary
*/
void list(int optarg)
{
unsigned char * p;
int i;
int lst;
char seg = ' ';
if (!expptr)
linecnt++;
addtoline('\0');
if (outpass) {
lst = iflist();
if (lst) {
lineout();
if (nopt)
fprintf(fout, "%4d:", linein[now_in]);
if (copt)
{
if (emitptr > emitbuf && (memflag[emit_addr] & MEM_INST))
{
int low, high, fetch, low8080, high8080;
zi_tstates(memory + emit_addr, &low, &high, &fetch, &low8080, &high8080);
if (!z80) {
low = low8080;
high = high8080;
}
// Special case to catch promotion of djnz to DEC B JP NZ
if (memory[emit_addr] == 5 && emitptr - emitbuf == 4) {
low += 10;
high += 10;
}
fprintf(fout, nopt ? "%5d" : "%4d", tstatesum[emit_addr]);
fprintf(fout, "+%d", low);
if (low != high)
fprintf(fout, "+%d", high - low);
}
else
{
fprintf(fout, nopt ? "%5s-" : "%4s-", "");
}
}
if (nopt || copt)
fprintf(fout, "\t");
puthex(optarg >> 8, fout);
puthex(optarg, fout);
if (relopt)
seg = SEGCHAR(segment);
fputc(seg, fout);
fputc(' ', fout);
for (p = emitbuf; (p < emitptr) && (p - emitbuf < 4); p++) {
puthex(*p, fout);
}
for (i = 4 - (p-emitbuf); i > 0; i--)
fputs(" ", fout);
putc('\t', fout);
fputs(linebuf, fout);
}
if (bopt) {
if (emitptr > emitbuf) {
fprintf(fbds, "%04x %04x d ", dollarsign, emit_addr);
for (p = emitbuf; p < emitptr; p++)
fprintf(fbds, "%02x", *p & 0xff);
fprintf(fbds, "\n");
}
fprintf(fbds, "%04x %04x s %s", dollarsign, emit_addr, linebuf);
for (p = emitbuf; p < emitptr; p++)
putbin(*p);
}
p = emitbuf+4;
while (lst && gopt && p < emitptr) {
lineout();
if (nopt) putc('\t', fout);
fputs(" ", fout);
for (i = 0; (i < 4) && (p < emitptr);i++) {
puthex(*p, fout);
p++;
}
putc('\n', fout);
}
lsterr2(lst);
} else
lsterr1();
dollarsign += emitptr - emitbuf;
emit_addr += emitptr - emitbuf;
dollarsign &= 0xffff;
emit_addr &= 0xffff;
emitptr = emitbuf;
lineptr = linebuf;
}
/*
* keep track of line numbers and put out headers as necessary
*/
void lineout()
{
if (!printer_output)
return;
if (line == 60) {
if (popt)
putc('\014', fout); /* send the form feed */
else
fputs("\n\n\n\n\n", fout);
line = 0;
}
if (line == 0) {
fprintf(fout, "\n\n%s %s\t%s\t Page %d\n\n\n",
&timp[4], &timp[20], title, page++);
line = 4;
}
line++;
}
/*
* cause a page eject
*/
void eject()
{
if (printer_output)
return;
if (outpass && iflist()) {
if (popt) {
putc('\014', fout); /* send the form feed */
} else {
while (line < 65) {
line++;
putc('\n', fout);
}
}
}
line = 0;
}
/*
* space n lines on the list file
*/
void space(int n)
{
int i ;
if (outpass && iflist())
for (i = 0; i<n; i++) {
lineout();
putc('\n', fout);
}
}
/*
* Error handling - pass 1
*/
void lsterr1()
{
int i;
for (i = 0; i <= mflag; i++)
if (err[i]) {
if (topt)
errorprt(i);
passfail = 1;
err[i] = 0;
}
}
/*
* Error handling - pass 2.
*/
void lsterr2(int lst)
{
int i;
for (i=0; i<FLAGS; i++)
if (err[i]) {
if (i < FIRSTWARN)
passfail = 1;
if (lst) {
char *desc = errname[i];
char *type = i < FIRSTWARN ? " error" : " warning";
if (errdetail[i][0]) {
desc = errdetail[i];
type = "";
}
lineout();
fprintf(fout, "%c %s%s\n",
errlet[i], desc, type);
}
err[i] = 0;
keeperr[i]++;
if (i > mflag && topt)
errorprt(i);
}
fflush(fout); /*to avoid putc(har) mix bug*/
}
/*
* print diagnostic to error terminal
*/
void errorprt(int errnum)
{
char *desc = errname[errnum];
char *type = errnum < FIRSTWARN ? " error" : " warning";
if (errdetail[errnum][0]) {
desc = errdetail[errnum];
type = "";
}
fprintf(stderr, "%s(%d) : %s%s",
src_name[now_in], linein[now_in], desc, type);
errdetail[errnum][0] = '\0';
fprintf(stderr, "\n");
fprintf(stderr, "%s\n", linebuf);
fflush(stderr) ;
}
void errwarn(int errnum, char *message)
{
err[errnum]++;
strcpy(errdetail[errnum], message);
}
/*
* list without address -- for comments and if skipped lines
*/
void list1()
{
int lst;
addtoline('\0');
lineptr = linebuf;
if (!expptr) linecnt++;
if (outpass) {
if ((lst = iflist())) {
lineout();
if (nopt)
fprintf(fout, "%4d:\t", linein[now_in]);
if (copt)
fprintf(fout, "\t");
fprintf(fout, "\t\t%s", linebuf);
lsterr2(lst);
}
if (bopt)
fprintf(fbds, "%04x %04x s %s", dollarsign, emit_addr, linebuf);
}
else
lsterr1();
}
/*
* see if listing is desired
*/
int iflist()
{
int i, j;
if (inmlex)
return mlex_list_on;
if (lston)
return(1) ;
if (lopt)
return(0);
if (*ifptr && !fopt)
return(0);
if (!lstoff && !expptr)
return(1);
j = 0;
for (i=0; i<FLAGS; i++)
if (err[i])
j++;
if (expptr)
return(mopt || j);
if (eopt && j)
return(1);
return(0);
}
void do_equ(struct item *sym, struct expr *val, int call_list);
void do_defl(struct item *sym, struct expr *val, int call_list);
// GWP - This avoids an apparent bug in bison as it tries to start out the
// Not needed under gcc which defines __STDC__ so I guard it to prevent
// warnings.
// yyparse() function with yyparse() ; { }.
#ifndef __STDC__
#define __STDC__
#endif
#define PSTITL (0) /* title */
#define PSRSYM (1) /* rsym */
#define PSWSYM (2) /* wsym */
#define PSINC (3) /* include file */
#define PSMACLIB (4) /* maclib (similar to include) */
#define SPTITL (0) /* title */
#define SPSBTL (1) /* sub title */
#define SPNAME (2) /* name */
#define SPCOM (3) /* comment */
#define SPPRAGMA (4) /* pragma */
////#line 1639 "zmac.c" /* yacc.c:339 */
# ifndef YY_NULLPTR
# if defined __cplusplus && 201103L <= __cplusplus
# define YY_NULLPTR nullptr
# else
# define YY_NULLPTR 0
# endif
# endif
/* Enabling verbose error messages. */
#ifdef YYERROR_VERBOSE
# undef YYERROR_VERBOSE
# define YYERROR_VERBOSE 1
#else
# define YYERROR_VERBOSE 0
#endif
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
extern int yydebug;
#endif
/* Token type. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
typedef enum _yytokentype
{
STRING = 258,
NOOPERAND = 259,
ARITHC = 260,
ADD = 261,
LOGICAL = 262,
AND = 263,
OR = 264,
XOR = 265,
ANDAND = 266,
OROR = 267,
BIT = 268,
CALL = 269,
INCDEC = 270,
DJNZ = 271,
EX = 272,
IM = 273,
PHASE = 274,
DEPHASE = 275,
TK_IN = 276,
JR = 277,
LD = 278,
TK_OUT = 279,
PUSHPOP = 280,
RET = 281,
SHIFT = 282,
RST = 283,
REGNAME = 284,
IXYLH = 285,
ACC = 286,
C = 287,
RP = 288,
HL = 289,
INDEX = 290,
AF = 291,
AFp = 292,
SP = 293,
MISCREG = 294,
COND = 295,
SPCOND = 296,
NUMBER = 297,
UNDECLARED = 298,
END = 299,
ORG = 300,
ASSERT = 301,
TSTATE = 302,
T = 303,
TILO = 304,
TIHI = 305,
SETOCF = 306,
OCF = 307,
LOW = 308,
HIGH = 309,
DC = 310,
DEFB = 311,
DEFD = 312,
DEFS = 313,
DEFW = 314,
EQU = 315,
DEFL = 316,
LABEL = 317,
EQUATED = 318,
WASEQUATED = 319,
DEFLED = 320,
MULTDEF = 321,
MOD = 322,
SHL = 323,
SHR = 324,
NOT = 325,
LT = 326,
GT = 327,
LE = 328,
GE = 329,
NE = 330,
IF_TK = 331,
ELSE_TK = 332,
ENDIF_TK = 333,
ARGPSEUDO = 334,
INCBIN = 335,
LIST = 336,
MINMAX = 337,
MACRO = 338,
MNAME = 339,
ARG = 340,
ENDM = 341,
ONECHAR = 342,
TWOCHAR = 343,
JRPROMOTE = 344,
JPERROR = 345,
PUBLIC = 346,
EXTRN = 347,
MRAS_MOD = 348,
SETSEG = 349,
INSTSET = 350,
LXI = 351,
DAD = 352,
STAX = 353,
STA = 354,
SHLD = 355,
LDAX = 356,
LHLD = 357,
LDA = 358,
MVI = 359,
MOV = 360,
INXDCX = 361,
INRDCR = 362,
PSW = 363,
JUMP8 = 364,
JP = 365,
CALL8 = 366,
ALUI8 = 367,
SPECIAL = 368,
RAWTOKEN = 369,
LOCAL = 370,
LD_XY = 371,
ST_XY = 372,
MV_XY = 373,
ALU_XY = 374,
BIT_XY = 375,
SHIFT_XY = 376,
INP = 377,
OUTP = 378,
JR_COND = 379,
LDST16 = 380,
ARITH16 = 381,
REPT = 382,
IRPC = 383,
IRP = 384,
EXITM = 385,
NUL = 386,
MPARM = 387,
UNARY = 388
} yytokentype;
#endif
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE YYSTYPE;
union YYSTYPE
{
////#line 1574 "zmac.y" /* yacc.c:355 */
struct expr *exprptr;
struct item *itemptr;
int ival;
char *cval;
////#line 1818 "zmac.c" /* yacc.c:355 */
};
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE yylval;
int yyparse (void);
/* Copy the second part of user declarations. */
////#line 1707 "zmac.y" /* yacc.c:358 */
char *cp;
int i;
void do_equ(struct item *sym, struct expr *val, int call_list)
{
expr_reloc_check(val);
switch(sym->i_token) {
case UNDECLARED: case WASEQUATED:
if (sym->i_token == WASEQUATED &&
(sym->i_value != val->e_value ||
((sym->i_scope ^ val->e_scope) & SCOPE_SEGMASK)))
{
if (outpass) {
if (sym->i_value != val->e_value)
sprintf(detail, "%s error - %s went from $%04x to $%04x",
errname[pflag], sym->i_string, sym->i_value, val->e_value);
else
sprintf(detail, "%s error - %s changed scope",
errname[pflag], sym->i_string);
errwarn(pflag, detail);
}
else
passretry = 1;
}
sym->i_token = EQUATED;
sym->i_value = val->e_value;
sym->i_scope |= val->e_scope;
break;
default:
// m80 allows multiple equates as long as the value
// does not change. So does newer zmac.
if (sym->i_value != val->e_value ||
((sym->i_scope ^ val->e_scope) & SCOPE_SEGMASK))
{
err[mflag]++;
sym->i_token = MULTDEF;
}
}
sym->i_scope &= ~SCOPE_BUILTIN;
if (call_list)
list(val->e_value);
expr_free(val);
}
void do_defl(struct item *sym, struct expr *val, int call_list)
{
expr_reloc_check(val);
switch(sym->i_token) {
case UNDECLARED: case DEFLED:
sym->i_token = DEFLED;
sym->i_value = val->e_value;
sym->i_scope = (sym->i_scope & SCOPE_SEGMASK) | val->e_scope;
break;
default:
err[mflag]++;
sym->i_token = MULTDEF;
}
if (call_list)
list(val->e_value);
expr_free(val);
}
////#line 1898 "zmac.c" /* yacc.c:358 */
#ifdef short
# undef short
#endif
#ifdef YYTYPE_UINT8
typedef YYTYPE_UINT8 yytype_uint8;
#else
typedef unsigned char yytype_uint8;
#endif
#ifdef YYTYPE_INT8
typedef YYTYPE_INT8 yytype_int8;
#else
typedef signed char yytype_int8;
#endif
#ifdef YYTYPE_UINT16
typedef YYTYPE_UINT16 yytype_uint16;
#else
typedef unsigned short int yytype_uint16;
#endif
#ifdef YYTYPE_INT16
typedef YYTYPE_INT16 yytype_int16;
#else
typedef short int yytype_int16;
#endif
#ifndef YYSIZE_T
# ifdef __SIZE_TYPE__
# define YYSIZE_T __SIZE_TYPE__
# elif defined size_t
# define YYSIZE_T size_t
# elif ! defined YYSIZE_T
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
# define YYSIZE_T size_t
# else
# define YYSIZE_T unsigned int
# endif
#endif
#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
#ifndef YY_
# if defined YYENABLE_NLS && YYENABLE_NLS
# if ENABLE_NLS
# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
# endif
# endif
# ifndef YY_
# define YY_(Msgid) Msgid
# endif
#endif
#ifndef YY_ATTRIBUTE
# if (defined __GNUC__ \
&& (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
|| defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
# define YY_ATTRIBUTE(Spec) __attribute__(Spec)
# else
# define YY_ATTRIBUTE(Spec) /* empty */
# endif
#endif
#ifndef YY_ATTRIBUTE_PURE
# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
#endif
#ifndef YY_ATTRIBUTE_UNUSED
# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
#endif
#if !defined _Noreturn \
&& (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
# if defined _MSC_VER && 1200 <= _MSC_VER
# define _Noreturn __declspec (noreturn)
# else
# define _Noreturn YY_ATTRIBUTE ((__noreturn__))
# endif
#endif
/* Suppress unused-variable warnings by "using" E. */
#if ! defined lint || defined __GNUC__
# define YYUSE(E) ((void) (E))
#else
# define YYUSE(E) /* empty */
#endif
#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
/* Suppress an incorrect diagnostic about yylval being uninitialized. */
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
_Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
_Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
_Pragma ("GCC diagnostic pop")
#else
# define YY_INITIAL_VALUE(Value) Value
#endif
#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
# define YY_IGNORE_MAYBE_UNINITIALIZED_END
#endif
#ifndef YY_INITIAL_VALUE
# define YY_INITIAL_VALUE(Value) /* Nothing. */
#endif
#if ! defined yyoverflow || YYERROR_VERBOSE
/* The parser invokes alloca or malloc; define the necessary symbols. */
# ifdef YYSTACK_USE_ALLOCA
# if YYSTACK_USE_ALLOCA
# ifdef __GNUC__
# define YYSTACK_ALLOC __builtin_alloca
# elif defined __BUILTIN_VA_ARG_INCR
# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
# elif defined _AIX
# define YYSTACK_ALLOC __alloca
# elif defined _MSC_VER
# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
# define alloca _alloca
# else
# define YYSTACK_ALLOC alloca
# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
/* Use EXIT_SUCCESS as a witness for stdlib.h. */
# ifndef EXIT_SUCCESS
# define EXIT_SUCCESS 0
# endif
# endif
# endif
# endif
# endif
# ifdef YYSTACK_ALLOC
/* Pacify GCC's 'empty if-body' warning. */
# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
# ifndef YYSTACK_ALLOC_MAXIMUM
/* The OS might guarantee only one guard page at the bottom of the stack,
and a page size can be as small as 4096 bytes. So we cannot safely
invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
to allow for a few compiler-allocated temporary stack slots. */
# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
# endif
# else
# define YYSTACK_ALLOC YYMALLOC
# define YYSTACK_FREE YYFREE
# ifndef YYSTACK_ALLOC_MAXIMUM
# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
# endif
# if (defined __cplusplus && ! defined EXIT_SUCCESS \
&& ! ((defined YYMALLOC || defined malloc) \
&& (defined YYFREE || defined free)))
# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
# ifndef EXIT_SUCCESS
# define EXIT_SUCCESS 0
# endif
# endif
# ifndef YYMALLOC
# define YYMALLOC malloc
# if ! defined malloc && ! defined EXIT_SUCCESS
void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
# endif
# endif
# ifndef YYFREE
# define YYFREE free
# if ! defined free && ! defined EXIT_SUCCESS
void free (void *); /* INFRINGES ON USER NAME SPACE */
# endif
# endif
# endif
#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
#if (! defined yyoverflow \
&& (! defined __cplusplus \
|| (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
/* A type that is properly aligned for any stack member. */
union yyalloc
{
yytype_int16 yyss_alloc;
YYSTYPE yyvs_alloc;
};
/* The size of the maximum gap between one aligned stack and the next. */
# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
/* The size of an array large to enough to hold all stacks, each with
N elements. */
# define YYSTACK_BYTES(N) \
((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
+ YYSTACK_GAP_MAXIMUM)
# define YYCOPY_NEEDED 1
/* Relocate STACK from its old location to the new one. The
local variables YYSIZE and YYSTACKSIZE give the old and new number of
elements in the stack, and YYPTR gives the new location of the
stack. Advance YYPTR to a properly aligned location for the next
stack. */
# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
do \
{ \
YYSIZE_T yynewbytes; \
YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
Stack = &yyptr->Stack_alloc; \
yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
yyptr += yynewbytes / sizeof (*yyptr); \
} \
while (0)
#endif
#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
/* Copy COUNT objects from SRC to DST. The source and destination do
not overlap. */
# ifndef YYCOPY
# if defined __GNUC__ && 1 < __GNUC__
# define YYCOPY(Dst, Src, Count) \
__builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
# else
# define YYCOPY(Dst, Src, Count) \
do \
{ \
YYSIZE_T yyi; \
for (yyi = 0; yyi < (Count); yyi++) \
(Dst)[yyi] = (Src)[yyi]; \
} \
while (0)
# endif
# endif
#endif /* !YYCOPY_NEEDED */
/* YYFINAL -- State number of the termination state. */
#define YYFINAL 2
/* YYLAST -- Last index in YYTABLE. */
#define YYLAST 3838
/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS 158
/* YYNNTS -- Number of nonterminals. */
#define YYNNTS 69
/* YYNRULES -- Number of rules. */
#define YYNRULES 310
/* YYNSTATES -- Number of states. */
#define YYNSTATES 577
/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
by yylex, with out-of-bounds checking. */
#define YYUNDEFTOK 2
#define YYMAXUTOK 388
#define YYTRANSLATE(YYX) \
((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
as returned by yylex, without out-of-bounds checking. */
static const yytype_uint8 yytranslate[] =
{
0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
149, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 146, 2, 154, 155, 145, 137, 2,
151, 152, 143, 141, 150, 142, 2, 144, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 134, 2,
139, 138, 140, 133, 2, 2, 2, 2, 2, 2,
153, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 156, 2, 157, 136, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 135, 2, 147, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
125, 126, 127, 128, 129, 130, 131, 132, 148
};
#if YYDEBUG
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] =
{
0, 1775, 1775, 1778, 1783, 1800, 1800, 1804, 1808, 1812,
1816, 1839, 1853, 1862, 1868, 1873, 1883, 1908, 1923, 1925,
1927, 1938, 1947, 1979, 1985, 1989, 1989, 2044, 2047, 2099,
2106, 2113, 2117, 2121, 2132, 2141, 2146, 2146, 2146, 2169,
2169, 2190, 2190, 2218, 2219, 2218, 2248, 2249, 2248, 2292,
2300, 2328, 2330, 2332, 2337, 2339, 2389, 2391, 2395, 2407,
2409, 2413, 2429, 2432, 2441, 2449, 2460, 2463, 2475, 2478,
2483, 2486, 2489, 2492, 2495, 2503, 2506, 2509, 2512, 2515,
2518, 2521, 2524, 2527, 2530, 2533, 2536, 2539, 2542, 2545,
2548, 2551, 2554, 2557, 2560, 2563, 2566, 2569, 2572, 2577,
2580, 2583, 2586, 2593, 2596, 2605, 2607, 2612, 2630, 2633,
2636, 2639, 2642, 2657, 2667, 2678, 2688, 2694, 2700, 2703,
2706, 2709, 2712, 2715, 2718, 2721, 2724, 2727, 2758, 2763,
2768, 2774, 2777, 2782, 2785, 2793, 2799, 2811, 2817, 2820,
2826, 2832, 2838, 2847, 2850, 2856, 2862, 2871, 2877, 2886,
2892, 2902, 2908, 2918, 2921, 2924, 2937, 2944, 2947, 2950,
2953, 2956, 2963, 2970, 2973, 2976, 2988, 2999, 3013, 3023,
3051, 3063, 3073, 3083, 3083, 3085, 3085, 3087, 3087, 3089,
3092, 3094, 3096, 3099, 3099, 3101, 3101, 3104, 3114, 3128,
3130, 3130, 3133, 3135, 3137, 3141, 3151, 3154, 3156, 3161,
3171, 3171, 3182, 3184, 3187, 3189, 3192, 3198, 3200, 3203,
3206, 3211, 3216, 3222, 3227, 3230, 3235, 3241, 3246, 3256,
3258, 3261, 3263, 3266, 3271, 3276, 3279, 3281, 3284, 3289,
3295, 3297, 3303, 3308, 3314, 3316, 3322, 3327, 3331, 3333,
3336, 3342, 3349, 3359, 3361, 3366, 3376, 3378, 3383, 3393,
3395, 3402, 3404, 3408, 3425, 3435, 3440, 3445, 3454, 3463,
3472, 3478, 3493, 3505, 3505, 3510, 3525, 3538, 3549, 3552,
3565, 3568, 3571, 3574, 3577, 3580, 3583, 3586, 3589, 3595,
3598, 3601, 3604, 3607, 3610, 3613, 3616, 3619, 3622, 3625,
3639, 3642, 3645, 3648, 3651, 3654, 3657, 3664, 3673, 3682,
3689, 3694, 3701, 3703, 3705, 3707, 3709, 3711, 3716, 3729,
3733
};
#endif
#if YYDEBUG || YYERROR_VERBOSE || 0
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
{
"$end", "error", "$undefined", "STRING", "NOOPERAND", "ARITHC", "ADD",
"LOGICAL", "AND", "OR", "XOR", "ANDAND", "OROR", "BIT", "CALL", "INCDEC",
"DJNZ", "EX", "IM", "PHASE", "DEPHASE", "TK_IN", "JR", "LD", "TK_OUT",
"PUSHPOP", "RET", "SHIFT", "RST", "REGNAME", "IXYLH", "ACC", "C", "RP",
"HL", "INDEX", "AF", "AFp", "SP", "MISCREG", "COND", "SPCOND", "NUMBER",
"UNDECLARED", "END", "ORG", "ASSERT", "TSTATE", "T", "TILO", "TIHI",
"SETOCF", "OCF", "LOW", "HIGH", "DC", "DEFB", "DEFD", "DEFS", "DEFW",
"EQU", "DEFL", "LABEL", "EQUATED", "WASEQUATED", "DEFLED", "MULTDEF",
"MOD", "SHL", "SHR", "NOT", "LT", "GT", "LE", "GE", "NE", "IF_TK",
"ELSE_TK", "ENDIF_TK", "ARGPSEUDO", "INCBIN", "LIST", "MINMAX", "MACRO",
"MNAME", "ARG", "ENDM", "ONECHAR", "TWOCHAR", "JRPROMOTE", "JPERROR",
"PUBLIC", "EXTRN", "MRAS_MOD", "SETSEG", "INSTSET", "LXI", "DAD", "STAX",
"STA", "SHLD", "LDAX", "LHLD", "LDA", "MVI", "MOV", "INXDCX", "INRDCR",
"PSW", "JUMP8", "JP", "CALL8", "ALUI8", "SPECIAL", "RAWTOKEN", "LOCAL",
"LD_XY", "ST_XY", "MV_XY", "ALU_XY", "BIT_XY", "SHIFT_XY", "INP", "OUTP",
"JR_COND", "LDST16", "ARITH16", "REPT", "IRPC", "IRP", "EXITM", "NUL",
"MPARM", "'?'", "':'", "'|'", "'^'", "'&'", "'='", "'<'", "'>'", "'+'",
"'-'", "'*'", "'/'", "'%'", "'!'", "'~'", "UNARY", "'\\n'", "','", "'('",
"')'", "'F'", "'#'", "'$'", "'['", "']'", "$accept", "statements",
"statement", "$@1", "$@2", "$@3", "$@4", "$@5", "$@6", "$@7", "$@8",
"$@9", "$@10", "maybecolon", "label.part", "public.list", "public.part",
"extrn.list", "extrn.part", "operation", "$@11", "$@12", "$@13",
"parm.list", "parm.single", "$@14", "maybeocto", "parm.element",
"locals", "local_decls", "$@15", "local.list", "local.element",
"arg.list", "arg.element", "$@16", "allreg", "reg", "ixylhreg", "reg8",
"m", "realreg", "mem", "memxy", "dxy", "evenreg", "evenreg8", "pushable",
"pushable8", "bcdesp", "bcdehlsp", "mar", "condition", "spcondition",
"db.list", "db.list.element", "dw.list", "dw.list.element", "dd.list",
"dd.list.element", "lxexpression", "expression", "parenexpr",
"noparenexpr", "$@17", "symbol", "al", "arg_on", "arg_off", YY_NULLPTR
};
#endif
# ifdef YYPRINT
/* YYTOKNUM[NUM] -- (External) token number corresponding to the
(internal) symbol number NUM (which must be that of a token). */
static const yytype_uint16 yytoknum[] =
{
0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
315, 316, 317, 318, 319, 320, 321, 322, 323, 324,
325, 326, 327, 328, 329, 330, 331, 332, 333, 334,
335, 336, 337, 338, 339, 340, 341, 342, 343, 344,
345, 346, 347, 348, 349, 350, 351, 352, 353, 354,
355, 356, 357, 358, 359, 360, 361, 362, 363, 364,
365, 366, 367, 368, 369, 370, 371, 372, 373, 374,
375, 376, 377, 378, 379, 380, 381, 382, 383, 384,
385, 386, 387, 63, 58, 124, 94, 38, 61, 60,
62, 43, 45, 42, 47, 37, 33, 126, 388, 10,
44, 40, 41, 70, 35, 36, 91, 93
};
# endif
#define YYPACT_NINF -453
#define yypact_value_is_default(Yystate) \
(!!((Yystate) == (-453)))
#define YYTABLE_NINF -250
#define yytable_value_is_error(Yytable_value) \
0
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */
static const yytype_int16 yypact[] =
{
-453, 568, -453, -453, -42, -453, -453, -453, -453, -453,
3609, -105, -90, -453, 3379, 3609, 3609, 21, 21, -61,
-20, 3, -453, -453, 170, -3, -453, -453, -453, 3609,
3609, 3609, 3609, 3609, 3609, -453, -453, -453, -453, -453,
3609, -453, -453, 3609, 3609, 3609, 3609, 3609, -453, 3609,
1132, -453, -453, -453, -453, 57, -453, 1156, 1171, 1250,
-453, -81, -453, -453, 24, -453, -453, -453, -453, -453,
48, 3494, 305, 3609, -453, -453, 3609, -453, -453, 15,
-453, 3213, 3609, 3609, 3609, 42, 3609, -453, -77, -453,
-453, -453, -453, -453, -453, -453, 68, -453, -453, -453,
-453, 714, 691, 3609, 3609, 3609, 3609, 3609, 3609, 3609,
3609, 3609, 3609, 3609, 3609, 3609, 3609, 3609, 3609, 3609,
3609, 3609, 3609, 3609, 3609, 3609, 3609, 3609, -453, -453,
36, -453, -453, -453, -453, 21, -453, 21, -453, -453,
1274, 44, 59, 64, 852, 829, 136, -453, 1629, 83,
72, 88, -453, 3609, 2037, 1995, 2165, 2322, 2348, 2374,
3609, 2704, 1867, 3609, 9, 3609, 3609, -453, 2495, 2847,
1825, 3682, 18, 50, 2547, 3609, 3609, 3609, 3609, 3609,
-453, -453, -453, -453, 101, 101, 96, 3609, 3609, 96,
3609, 3609, 49, 49, 101, 49, 3609, 2821, 3609, 3609,
96, 96, 3609, 3609, 3609, 3609, 96, 96, 3609, 3609,
137, 93, 1353, 1368, 870, -453, 1392, -453, 41, 111,
-453, -453, -453, -453, 959, 1708, 747, 1668, 462, -453,
-21, -21, 168, 168, 168, 168, 569, 1589, 1708, 747,
959, 569, 168, 168, -7, -7, -453, -453, -453, 95,
-453, -453, -453, -453, -453, -453, -453, 3609, -453, 3609,
-453, -53, 97, -453, -453, -453, 1629, -453, -453, 98,
-453, 102, -453, 3347, -453, -453, -453, -453, -453, -453,
-453, 94, 732, 103, -453, -453, -453, -453, 107, 732,
108, -453, -453, 732, 109, -453, 732, 110, -453, 732,
114, -453, 732, 972, -453, -453, -453, 119, -453, 1629,
-453, -453, -453, -453, -453, -453, -453, 1629, 1629, 121,
126, 213, 1629, 1629, 2873, 127, 128, 1629, 135, 1629,
140, 3057, 141, 142, 143, 2984, 1629, 144, -453, -453,
-453, -453, -453, -453, -453, -453, -453, 145, 1629, 1629,
1629, 1629, 1629, 415, 3609, 3609, -453, -453, 151, -453,
-453, 1629, 1629, -453, 1629, 1629, 152, -453, -453, 153,
-453, -453, 1629, 3421, 154, 1629, 1629, 1629, 155, 156,
1013, -453, 1052, -453, -453, -453, 1629, 1629, -453, -453,
-453, -453, -453, 3609, -453, -453, 72, -453, 3609, -453,
1471, 1510, 158, -453, -453, 52, -453, -453, -453, -453,
2521, 37, 134, 3536, 280, 2521, 137, 2521, 2521, 2521,
2521, 2547, 3609, 282, 281, 165, 171, 169, 173, 3609,
291, 174, 2194, 3306, 189, 175, 297, 96, -453, -453,
179, -453, 1629, 180, -453, 1629, 182, -453, 1629, 3567,
3609, 49, 183, 3609, 3609, 3609, 3609, 3609, 1550, -453,
-453, 1629, -453, -453, -453, 3609, -453, -53, -453, -53,
-53, -453, 732, -453, -453, -453, -453, -453, 184, 185,
-453, 732, -453, -453, -453, 732, -453, 732, -453, 732,
-453, 732, -453, 188, 1629, -453, -453, 190, -453, 299,
3010, -453, 1629, -453, 191, -453, 3120, -453, 193, 197,
-453, -453, -453, 1629, 200, 201, -453, -453, 202, -453,
-453, 415, 3609, 3609, -453, 1629, -453, -453, 1629, -453,
-453, -453, -453, -453, -453, 218, 1629, -453, -453, -453,
-453, -453, -453, 96, 181, 187, 199, 303, 204, 2668,
-453, -453, -453, -453, 211, 212, -453, -453, -453, -453,
-453, -453, -453, 1629, 230, -453, -453, -453, 91, -453,
-453, -453, -453, 230, -453, -453, -453
};
/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
Performed when YYTABLE does not specify something else to do. Zero
means the default is an error. */
static const yytype_uint16 yydefact[] =
{
2, 0, 1, 50, 302, 303, 305, 306, 307, 304,
0, 0, 0, 309, 0, 0, 0, 0, 0, 0,
0, 0, 25, 3, 5, 51, 36, 255, 261, 0,
0, 0, 0, 0, 0, 254, 257, 258, 259, 262,
0, 256, 263, 0, 0, 0, 0, 0, 260, 0,
0, 251, 252, 12, 13, 310, 27, 0, 0, 0,
302, 0, 56, 58, 0, 59, 61, 33, 34, 35,
0, 0, 0, 0, 309, 308, 0, 183, 183, 0,
4, 0, 0, 0, 0, 52, 0, 55, 180, 296,
297, 298, 299, 300, 301, 291, 0, 294, 295, 293,
292, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 11, 310,
0, 28, 29, 30, 31, 0, 32, 0, 26, 14,
0, 0, 256, 0, 0, 0, 0, 39, 308, 0,
185, 0, 49, 62, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 168, 0, 0,
0, 0, 0, 125, 64, 0, 0, 0, 0, 0,
173, 177, 175, 179, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 53, 0, 186, 0, 0,
181, 264, 253, 290, 272, 274, 276, 287, 288, 270,
277, 278, 282, 283, 284, 285, 286, 0, 273, 275,
271, 280, 279, 281, 265, 266, 268, 267, 269, 0,
23, 57, 60, 15, 20, 18, 19, 0, 16, 0,
310, 196, 0, 43, 184, 46, 63, 210, 206, 211,
212, 0, 209, 0, 85, 202, 203, 87, 204, 205,
214, 0, 72, 211, 232, 233, 82, 84, 0, 70,
211, 88, 89, 74, 211, 90, 75, 211, 91, 76,
211, 92, 77, 112, 237, 235, 236, 0, 234, 66,
211, 228, 229, 100, 108, 219, 220, 218, 124, 0,
0, 0, 166, 167, 0, 0, 0, 156, 0, 121,
0, 0, 0, 0, 251, 0, 162, 251, 223, 224,
227, 226, 110, 111, 225, 126, 97, 214, 67, 169,
170, 171, 172, 0, 0, 0, 222, 221, 0, 105,
139, 141, 149, 135, 147, 137, 0, 208, 207, 0,
109, 101, 117, 0, 0, 65, 120, 68, 0, 0,
0, 69, 0, 98, 158, 164, 123, 151, 106, 107,
6, 7, 9, 0, 8, 37, 185, 187, 0, 22,
0, 0, 0, 199, 200, 0, 197, 41, 308, 308,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 241, 240,
174, 238, 242, 178, 246, 248, 176, 243, 245, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 189,
182, 289, 21, 17, 24, 0, 40, 0, 189, 0,
0, 86, 73, 231, 230, 102, 213, 216, 0, 0,
83, 71, 103, 104, 93, 78, 94, 79, 95, 80,
96, 81, 113, 214, 119, 152, 153, 0, 160, 0,
0, 155, 122, 143, 0, 142, 0, 127, 251, 252,
250, 150, 144, 0, 251, 252, 140, 148, 0, 161,
99, 0, 0, 0, 145, 133, 130, 118, 116, 128,
129, 132, 114, 10, 38, 188, 201, 198, 42, 310,
310, 215, 217, 0, 0, 0, 0, 0, 0, 0,
239, 247, 244, 190, 0, 0, 115, 154, 159, 157,
138, 134, 163, 165, 192, 44, 47, 195, 0, 193,
189, 189, 191, 0, 45, 48, 194
};
/* YYPGOTO[NTERM-NUM]. */
static const yytype_int16 yypgoto[] =
{
-453, -453, -453, -453, -453, -453, -453, -453, -453, -453,
-453, -453, -453, -453, -453, -453, 229, -453, 228, -453,
-453, -453, -453, -453, 288, -453, -453, -135, -452, -453,
-453, -453, -201, -453, -260, -453, -145, -166, -453, -155,
76, 11, -453, -165, -174, -168, -31, -453, -453, -182,
-453, -154, -130, 205, -453, -148, -453, -147, -453, -143,
-72, -10, -144, -292, -453, 47, -141, 304, -126
};
/* YYDEFGOTO[NTERM-NUM]. */
static const yytype_int16 yydefgoto[] =
{
-1, 1, 23, 81, 70, 88, 459, 261, 468, 408,
570, 409, 571, 87, 24, 61, 62, 64, 65, 211,
353, 355, 354, 218, 149, 150, 219, 220, 534, 535,
564, 568, 569, 405, 406, 465, 274, 275, 276, 366,
367, 278, 279, 280, 281, 314, 358, 342, 343, 315,
475, 316, 307, 308, 440, 441, 446, 447, 443, 444,
512, 317, 51, 52, 96, 63, 147, 55, 130
};
/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
positive, shift that token. If negative, reduce the rule whose
number is the opposite. If YYTABLE_NINF, syntax error. */
static const yytype_int16 yytable[] =
{
50, 288, 333, 249, 57, 58, 59, 262, 346, 347,
286, 291, 295, 298, 301, 264, 538, 313, 344, 89,
90, 91, 92, 93, 94, 332, 334, 337, 388, 381,
95, 383, 403, 97, 98, 99, 100, 101, 369, 102,
371, 26, 319, 345, 53, 320, 108, 267, 25, 310,
270, 338, 284, 285, 339, -185, 389, 82, 83, 54,
108, 140, 144, 145, 60, 66, 148, 374, 134, 135,
311, 473, 212, 213, 214, 312, 216, 217, 267, 84,
310, 270, 304, 5, 6, 7, 8, 9, 67, 272,
305, 306, 404, 224, 225, 226, 227, 228, 229, 230,
231, 232, 233, 234, 235, 236, 237, 238, 239, 240,
241, 242, 243, 244, 245, 246, 247, 248, 574, 575,
123, 124, 125, 126, 127, 267, 340, 310, 270, 68,
267, 85, 310, 270, 402, 86, 125, 126, 127, 356,
509, 515, 129, 266, 282, 289, 293, 296, 299, 302,
303, 309, 69, 318, 359, 322, 323, 515, 327, 329,
321, 336, 138, 370, 152, 348, 349, 350, 351, 352,
311, 284, 285, 136, 137, 312, 215, 361, 362, 326,
364, 365, 221, 341, 66, 250, 372, 375, 376, 377,
395, 396, 380, 254, 382, 357, 357, 360, 386, 387,
363, 466, 467, 368, 368, 357, 368, 537, 255, 539,
540, 378, 379, 256, 71, 284, 285, 384, 385, 452,
516, 260, 311, 284, 285, 72, 217, 312, 73, 474,
277, 287, 292, 263, 482, 108, 109, 110, 265, 478,
572, 573, 390, 397, 399, 414, 407, 400, 410, 401,
74, 425, 411, 415, 75, 492, 493, 416, 417, 418,
419, 460, 483, 101, 420, 471, 517, 469, 470, 422,
480, 423, 484, 486, 488, 490, 424, 427, 428, 511,
529, 530, 531, 532, 501, 429, 476, 507, 508, 514,
430, 432, 433, 434, 436, 437, 526, 76, 77, 78,
79, 449, 450, 451, 453, 454, 455, 464, 141, 123,
124, 125, 126, 127, 101, 479, 495, 497, 496, 80,
499, 101, 503, 498, 500, 101, 504, 518, 519, 521,
522, 545, 523, 553, 560, 527, 541, 542, 543, 558,
544, 547, -136, 442, 445, 448, -131, 27, 28, -146,
-249, 559, 549, 29, 30, 31, 561, 32, 33, 34,
565, 566, 567, 101, 251, 252, 151, 35, 36, 37,
38, 39, 576, 550, 328, 40, 552, 524, 146, 551,
0, 0, 0, 458, 0, 0, 0, 0, 461, 0,
557, 0, 142, 143, 0, 0, 0, 0, 0, 0,
472, 0, 0, 0, 0, 481, 0, 485, 487, 489,
491, 0, 494, 554, 555, 0, 0, 0, 438, 502,
0, 0, 0, 513, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 42, 0, 0, 513,
525, 0, 0, 528, 0, 0, 43, 44, 520, 0,
0, 45, 46, 0, 0, 536, 47, 27, 28, 0,
48, 49, 368, 29, 30, 31, 0, 32, 33, 34,
103, 104, 105, 106, 0, 0, 0, 35, 36, 37,
38, 39, 0, 0, 0, 40, 0, 0, 0, 0,
101, 0, 0, 0, 0, 0, 101, 0, 0, 0,
0, 0, 41, 439, 0, 0, 0, 0, 0, 0,
0, 442, 445, 448, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 108,
109, 110, 0, 111, 112, 113, 114, 115, 0, 563,
0, 0, 0, 0, 0, 0, 42, 0, 0, 0,
0, 0, 0, 0, 556, 0, 43, 44, 0, 0,
562, 45, 46, 0, 0, 0, 47, 0, 2, 3,
48, 49, -54, -54, -54, -54, -54, -54, -54, 0,
0, -54, -54, -54, -54, -54, -54, -54, -54, -54,
-54, -54, -54, -54, -54, -54, -54, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 0, 0,
0, 4, -54, -54, -54, -54, 0, 0, 0, -54,
0, 0, 0, -54, -54, -54, -54, -54, 0, 0,
5, 6, 7, 8, 9, 0, 108, 109, 110, 0,
111, 112, 113, 114, 10, 11, 12, 13, -54, 14,
0, 0, -54, 0, -54, 0, 0, 15, 16, 17,
18, 19, 20, 21, -54, -54, -54, -54, -54, -54,
-54, -54, -54, -54, -54, -54, 0, -54, -54, -54,
-54, 22, 0, 0, -54, -54, -54, -54, -54, -54,
-54, -54, -54, -54, -54, -54, -54, -54, -54, 103,
104, 105, 106, 107, 0, 0, 0, 0, 121, 122,
123, 124, 125, 126, 127, 0, 0, -54, 0, 0,
0, 0, 103, 104, 105, 106, 107, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103, 104, 105, 106, 107, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 103, 0, 0, 108, 109,
110, 0, 111, 112, 113, 114, 115, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 108, 109, 110, 0, 111, 112, 113, 114, 115,
0, 0, 0, 0, 0, 0, 0, 0, 0, 108,
109, 110, 0, 111, 112, 113, 114, 115, 0, 0,
0, 0, 0, 0, 108, 109, 110, 0, 111, 112,
113, 114, 115, 0, 116, 0, 117, 118, 119, 120,
121, 122, 123, 124, 125, 126, 127, 103, 104, 105,
106, 107, 0, 0, 0, 0, 0, 116, 223, 117,
118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
103, 104, 105, 106, 107, 116, 222, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 103, 104,
105, 106, 107, -218, 119, 120, 121, 122, 123, 124,
125, 126, 127, 0, 0, 0, 108, 109, 110, 0,
111, 112, 113, 114, 115, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 108,
109, 110, 0, 111, 112, 113, 114, 115, 0, 0,
0, 0, 0, 0, 0, 0, 0, 108, 109, 110,
0, 111, 112, 113, 114, 115, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 116, 0, 117, 118, 119, 120, 121, 122,
123, 124, 125, 126, 127, 0, 0, 0, 258, 259,
103, 104, 105, 106, 107, 116, 0, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 0, 0,
0, 0, 257, 116, 0, 117, 118, 119, 120, 121,
122, 123, 124, 125, 126, 127, 0, 0, 0, 0,
393, 103, 104, 105, 106, 107, 108, 109, 110, 0,
111, 112, 113, 114, 115, 0, 0, 0, 0, 108,
109, 110, 0, 111, 112, 113, 114, 115, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103, 104, 105, 106, 107, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
108, 109, 110, 0, 111, 112, 113, 114, 115, 0,
0, 0, 0, 0, 0, 0, 0, 120, 121, 122,
123, 124, 125, 126, 127, 116, 0, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 0, 108,
109, 110, 421, 111, 112, 113, 114, 115, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103, 104, 105, 106, 107, 0, 116, 0, 117, 118,
119, 120, 121, 122, 123, 124, 125, 126, 127, 0,
0, 0, 0, 456, 103, 104, 105, 106, 107, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 103,
104, 105, 106, 107, 0, 116, 0, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 0, 108,
109, 110, 457, 111, 112, 113, 114, 115, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 108, 109, 110, 0, 111, 112, 113,
114, 115, 0, 0, 0, 0, 0, 0, 108, 109,
110, 0, 111, 112, 113, 114, 115, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 103, 104,
105, 106, 107, 0, 0, 116, 0, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 0, 0,
0, 128, 103, 104, 105, 106, 107, 0, 0, 116,
0, 117, 118, 119, 120, 121, 122, 123, 124, 125,
126, 127, 0, 0, 116, 131, 117, 118, 119, 120,
121, 122, 123, 124, 125, 126, 127, 108, 109, 110,
132, 111, 112, 113, 114, 115, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 108, 109, 110, 0, 111, 112, 113, 114, 115,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 103, 104, 105, 106, 107, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 103, 104, 105, 106,
107, 0, 0, 116, 0, 117, 118, 119, 120, 121,
122, 123, 124, 125, 126, 127, 0, 0, 0, 133,
103, 104, 105, 106, 107, 0, 0, 116, 0, 117,
118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
108, 109, 110, 253, 111, 112, 113, 114, 115, 0,
0, 0, 0, 0, 0, 108, 109, 110, 0, 111,
112, 113, 114, 115, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 108,
109, 110, 0, 111, 112, 113, 114, 115, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 103,
104, 105, 106, 107, 0, 0, 116, 0, 117, 118,
119, 120, 121, 122, 123, 124, 125, 126, 127, 0,
0, 116, 391, 117, 118, 119, 120, 121, 122, 123,
124, 125, 126, 127, 0, 0, 0, 392, 103, 104,
105, 106, 107, 0, 0, 116, 0, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 108, 109,
110, 394, 111, 112, 113, 114, 115, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 103, 104,
105, 106, 107, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 108, 109, 110,
0, 111, 112, 113, 114, 115, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 103, 104, 105,
106, 107, 0, 0, 116, 0, 117, 118, 119, 120,
121, 122, 123, 124, 125, 126, 127, 108, 109, 110,
462, 111, 112, 113, 114, 115, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 103, 104, 105,
106, 107, 0, 116, 0, 117, 118, 119, 120, 121,
122, 123, 124, 125, 126, 127, 108, 109, 110, 463,
111, 112, 113, 114, 115, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 103, 104, 105, 0,
0, 0, 0, 116, 0, 117, 118, 119, 120, 121,
122, 123, 124, 125, 126, 127, 108, 109, 110, 533,
111, 112, 113, 114, 115, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 103, 0, 105, 0,
0, 0, 116, 398, 117, 118, 119, 120, 121, 122,
123, 124, 125, 126, 127, 108, 109, 110, 0, 111,
112, 113, 114, 115, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 116, 0, 117, 118, 119, 120, 121, 122,
123, 124, 125, 126, 127, 108, 109, 110, 0, 111,
112, 113, 114, 115, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 117, 118, 119, 120, 121, 122, 123,
124, 125, 126, 127, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 118, 119, 120, 121, 122, 123,
124, 125, 126, 127, 267, 268, 310, 270, 311, 284,
285, 0, 0, 312, 330, 0, 0, 27, 28, 0,
0, 0, 0, 29, 30, 31, 0, 32, 33, 34,
0, 0, 0, 0, 0, 0, 0, 35, 36, 37,
38, 39, 0, 0, 0, 40, 267, 268, 310, 270,
311, 284, 285, 0, 0, 312, 0, 0, 0, 27,
28, 0, 41, 0, 0, 29, 30, 31, 0, 32,
33, 34, 0, 0, 0, 0, 0, 0, 0, 35,
36, 37, 38, 39, 0, 0, 0, 40, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 41, 0, 42, 0, 0, 0,
0, 0, 0, 0, 0, 0, 43, 44, 0, 0,
0, 45, 46, 0, 0, 0, 331, 0, 0, 0,
48, 49, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 42, 0,
0, 0, 0, 0, 0, 0, 0, 0, 43, 44,
0, 0, 0, 45, 46, 0, 0, 0, 273, 0,
0, 0, 48, 49, 267, 268, 283, 270, 0, 284,
285, 0, 0, 0, 0, 272, 0, 27, 28, 0,
0, 0, 0, 29, 30, 31, 0, 32, 33, 34,
0, 0, 0, 0, 0, 0, 0, 35, 36, 37,
38, 39, 0, 0, 0, 40, 267, 268, 269, 270,
0, 271, 0, 0, 0, 0, 0, 272, 0, 27,
28, 0, 41, 0, 0, 29, 30, 31, 0, 32,
33, 34, 0, 0, 0, 0, 0, 0, 0, 35,
36, 37, 38, 39, 0, 0, 0, 40, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 41, 0, 42, 0, 0, 0,
0, 0, 0, 0, 0, 0, 43, 44, 0, 0,
0, 45, 46, 0, 0, 0, 273, 0, 0, 0,
48, 49, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 42, 0,
0, 0, 0, 0, 0, 0, 0, 0, 43, 44,
0, 0, 0, 45, 46, 0, 0, 0, 273, 0,
0, 0, 48, 49, 267, 268, 290, 270, 0, 0,
0, 0, 0, 0, 0, 272, 0, 27, 28, 0,
0, 0, 0, 29, 30, 31, 0, 32, 33, 34,
0, 0, 0, 267, 268, 310, 270, 35, 36, 37,
38, 39, 0, 505, 0, 40, 27, 28, 0, 0,
0, 0, 29, 30, 31, 0, 32, 33, 34, 0,
0, 0, 41, 0, 0, 0, 35, 36, 37, 38,
39, 0, 0, 0, 40, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 41, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 42, 0, 0, 0,
0, 0, 0, 0, 0, 0, 43, 44, 0, 0,
0, 45, 46, 0, 0, 0, 273, 0, 0, 0,
48, 49, 0, 0, 0, 42, 0, 0, 0, 0,
0, 0, 0, 0, 0, 43, 44, 0, 0, 0,
45, 46, 0, 0, 0, 506, 0, 0, 0, 48,
49, 267, 268, 294, 270, 0, 0, 0, 0, 0,
0, 0, 0, 0, 27, 28, 0, 0, 0, 0,
29, 30, 31, 0, 32, 33, 34, 267, 268, 297,
270, 0, 0, 0, 35, 36, 37, 38, 39, 0,
27, 28, 40, 0, 0, 0, 29, 30, 31, 0,
32, 33, 34, 267, 268, 300, 270, 0, 0, 41,
35, 36, 37, 38, 39, 0, 27, 28, 40, 0,
0, 0, 29, 30, 31, 0, 32, 33, 34, 0,
0, 0, 0, 0, 0, 41, 35, 36, 37, 38,
39, 0, 0, 0, 40, 0, 0, 0, 0, 0,
0, 0, 0, 42, 0, 0, 0, 0, 0, 0,
0, 41, 0, 43, 44, 0, 0, 0, 45, 46,
0, 0, 0, 273, 0, 0, 0, 48, 49, 42,
0, 0, 0, 0, 0, 0, 0, 0, 0, 43,
44, 0, 0, 0, 45, 46, 0, 0, 0, 273,
0, 0, 0, 48, 49, 42, 0, 0, 0, 0,
0, 0, 0, 0, 0, 43, 44, 0, 0, 0,
45, 46, 0, 0, 267, 273, 310, 270, 0, 48,
49, 0, 0, 0, 0, 0, 0, 27, 28, 0,
0, 0, 0, 29, 30, 31, 0, 32, 33, 34,
267, 268, 310, 270, 0, 0, 0, 35, 36, 37,
38, 39, 0, 27, 28, 40, 0, 0, 0, 29,
30, 31, 0, 32, 33, 34, 267, 0, 310, 270,
0, 0, 41, 35, 36, 37, 38, 39, 0, 27,
28, 40, 0, 0, 0, 29, 30, 31, 0, 32,
33, 34, 0, 0, 0, 0, 0, 0, 41, 35,
36, 37, 38, 39, 0, 0, 0, 40, 0, 0,
0, 0, 0, 0, 0, 0, 42, 0, 0, 0,
0, 0, 0, 0, 41, 0, 43, 44, 0, 0,
0, 45, 46, 0, 0, 0, 324, 0, 325, 0,
48, 49, 42, 0, 0, 0, 0, 0, 0, 0,
0, 0, 43, 44, 0, 0, 0, 45, 46, 0,
0, 0, 273, 0, 0, 0, 48, 49, 42, 0,
0, 0, 0, 0, 0, 0, 0, 0, 43, 44,
0, 0, 0, 45, 46, 0, 0, 267, 273, 310,
270, 0, 48, 49, 0, 0, 0, 0, 0, 0,
27, 28, 0, 0, 0, 0, 29, 30, 31, 0,
32, 33, 34, 0, 0, 0, 0, 0, 0, 0,
35, 36, 37, 38, 39, 0, 304, 0, 40, 0,
0, 0, 0, 0, 305, 306, 27, 28, 0, 0,
0, 0, 29, 30, 31, 41, 32, 33, 34, 0,
0, 0, 0, 0, 0, 0, 35, 36, 37, 38,
39, 0, 0, 0, 40, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 41, 0, 0, 0, 0, 0, 0, 0, 42,
0, 0, 0, 0, 0, 0, 0, 0, 0, 43,
44, 0, 0, 0, 45, 46, 0, 0, 0, 47,
0, 0, 0, 48, 49, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 42, 0, 0, 0, 0,
0, 0, 0, 0, 0, 43, 44, 0, 0, 0,
45, 46, 0, 304, 0, 47, 0, 0, 0, 48,
49, 305, 306, 27, 28, 0, 0, 0, 0, 29,
30, 31, 0, 32, 33, 34, 0, 0, 0, 304,
0, 0, 0, 35, 36, 37, 38, 39, 306, 27,
28, 40, 0, 0, 0, 29, 30, 31, 0, 32,
33, 34, 0, 0, 0, 426, 0, 0, 41, 35,
36, 37, 38, 39, 0, 27, 28, 40, 0, 0,
0, 29, 30, 31, 0, 32, 33, 34, 0, 0,
0, 0, 0, 0, 41, 35, 36, 37, 38, 39,
0, 0, 0, 40, 0, 0, 0, 0, 0, 0,
0, 0, 42, 0, 0, 0, 0, 0, 0, 0,
41, 0, 43, 44, 0, 0, 0, 45, 46, 0,
0, 0, 373, 0, 0, 0, 48, 49, 42, 0,
0, 0, 0, 0, 0, 0, 0, 0, 43, 44,
0, 0, 0, 45, 46, 0, 0, 0, 47, 0,
0, 0, 48, 49, 42, 0, 0, 0, 0, 0,
0, 0, 0, 0, 43, 44, 435, 0, 0, 45,
46, 0, 0, 0, 47, 0, 27, 28, 48, 49,
0, 0, 29, 30, 31, 0, 32, 33, 34, 0,
0, 0, 546, 0, 0, 0, 35, 36, 37, 38,
39, 0, 27, 28, 40, 0, 0, 0, 29, 30,
31, 0, 32, 33, 34, 0, 0, 0, 0, 0,
0, 41, 35, 36, 37, 38, 39, 0, 0, 0,
40, 0, 0, 0, 0, 0, 0, 0, 0, 0,
431, 412, 413, 0, 0, 0, 0, 41, 0, 27,
28, 0, 0, 0, 0, 29, 30, 31, 0, 32,
33, 34, 0, 0, 0, 42, 0, 0, 0, 35,
36, 37, 38, 39, 0, 43, 44, 40, 0, 0,
45, 46, 0, 0, 0, 47, 0, 0, 0, 48,
49, 42, 0, 0, 41, 0, 0, 0, 0, 0,
0, 43, 44, 548, 412, 413, 45, 46, 0, 0,
0, 47, 27, 28, 0, 48, 49, 0, 29, 30,
31, 0, 32, 33, 34, 0, 0, 0, 0, 0,
0, 0, 35, 36, 37, 38, 39, 0, 42, 0,
40, 0, 0, 0, 0, 0, 0, 0, 43, 44,
0, 0, 0, 45, 46, 0, 0, 41, 47, 0,
0, 0, 48, 49, 0, 0, 0, 153, 154, 155,
156, 157, 158, 159, 0, 0, 160, 161, 162, 163,
164, 165, 166, 167, 168, 169, 170, 171, 172, 173,
174, 175, 0, 0, 0, 0, 0, 0, 0, 0,
0, 42, 0, 0, 0, 0, 0, 0, 176, 177,
178, 43, 44, 0, 179, 0, 45, 46, 0, 180,
181, 47, 182, 0, 0, 48, 49, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 183,
0, 0, 0, 0, 0, 0, 0, 0, 0, 184,
185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
195, 0, 196, 197, 198, 199, 0, 0, 0, 200,
201, 202, 203, 204, 205, 206, 207, 208, 209, 210,
284, 285, 0, 0, 0, 0, 0, 0, 27, 28,
0, 0, 0, 0, 29, 30, 31, 0, 32, 33,
34, 0, 0, 0, 0, 0, 0, 0, 35, 36,
37, 38, 39, 0, 0, 0, 40, 0, 0, 0,
0, 412, 413, 0, 0, 0, 0, 0, 0, 27,
28, 0, 0, 41, 510, 29, 30, 31, 0, 32,
33, 34, 0, 0, 0, 0, 0, 0, 0, 35,
36, 37, 38, 39, 0, 0, 0, 40, 0, 0,
0, 27, 28, 0, 0, 0, 0, 29, 30, 31,
0, 32, 33, 34, 41, 0, 0, 42, 0, 0,
0, 35, 36, 37, 38, 39, 0, 43, 44, 40,
0, 0, 45, 46, 0, 284, 285, 47, 0, 0,
0, 48, 49, 27, 28, 0, 41, 0, 0, 29,
30, 31, 0, 32, 33, 34, 0, 0, 42, 0,
0, 0, 0, 35, 36, 37, 38, 39, 43, 44,
0, 40, 0, 45, 46, 0, 0, 0, 47, 0,
0, 0, 48, 49, 0, 0, 0, 0, 41, 0,
42, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43, 44, 0, 0, 0, 45, 46, 0, 56, 0,
47, 0, 0, 0, 48, 49, 27, 28, 0, 0,
0, 0, 29, 30, 31, 0, 32, 33, 34, 0,
0, 0, 42, 0, 0, 0, 35, 36, 37, 38,
39, 0, 43, 44, 40, 0, 0, 45, 46, 0,
0, 0, 47, 0, 0, 0, 48, 49, 27, 28,
0, 41, 0, 0, 29, 30, 31, 0, 32, 33,
34, 0, 0, 0, 0, 0, 0, 0, 35, 36,
37, 38, 39, 0, 0, 0, 40, 0, 0, 27,
28, 0, 0, 0, 0, 29, 30, 31, 0, 32,
33, 34, 0, 41, 0, 42, 0, 0, 0, 35,
36, 37, 38, 39, 0, 43, 44, 40, 0, 0,
45, 46, 0, 139, 0, 47, 0, 0, 0, 48,
49, 27, 28, 0, 41, 510, 0, 29, 30, 31,
0, 32, 33, 34, 0, 0, 0, 42, 0, 0,
0, 35, 36, 37, 38, 39, 0, 43, 44, 40,
0, 0, 45, 46, 0, 0, 0, 47, 477, 0,
0, 48, 49, 0, 0, 0, 41, 0, 42, 0,
0, 0, 0, 0, 0, 0, 0, 0, 43, 44,
0, 0, 0, 45, 46, 0, 0, 0, 47, 0,
0, 0, 48, 49, 27, 28, 0, 0, 0, 0,
29, 30, 31, 0, 32, 33, 34, 0, 0, 0,
42, 0, 0, 0, 35, 36, 37, 38, 39, 0,
43, 44, 40, 0, 0, 45, 46, 0, 0, 0,
47, 0, 0, 0, 48, 49, 0, 0, 0, 41,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 42, 0, 0, 0, 0, 0, 0,
0, 0, 0, 43, 44, 0, 0, 0, 45, 46,
0, 0, 0, 335, 0, 0, 0, 48, 49
};
static const yytype_int16 yycheck[] =
{
10, 155, 170, 129, 14, 15, 16, 148, 174, 174,
155, 156, 157, 158, 159, 150, 468, 162, 172, 29,
30, 31, 32, 33, 34, 170, 170, 171, 210, 203,
40, 205, 85, 43, 44, 45, 46, 47, 193, 49,
195, 83, 33, 173, 149, 36, 67, 29, 1, 31,
32, 33, 34, 35, 36, 132, 210, 60, 61, 149,
67, 71, 72, 73, 43, 18, 76, 197, 149, 150,
33, 34, 82, 83, 84, 38, 86, 154, 29, 82,
31, 32, 32, 62, 63, 64, 65, 66, 149, 40,
40, 41, 145, 103, 104, 105, 106, 107, 108, 109,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 570, 571,
141, 142, 143, 144, 145, 29, 108, 31, 32, 149,
29, 134, 31, 32, 260, 138, 143, 144, 145, 38,
432, 433, 85, 153, 154, 155, 156, 157, 158, 159,
160, 161, 149, 163, 185, 165, 166, 449, 168, 169,
151, 171, 114, 194, 149, 175, 176, 177, 178, 179,
33, 34, 35, 149, 150, 38, 134, 187, 188, 168,
190, 191, 114, 172, 137, 149, 196, 197, 198, 199,
149, 150, 202, 149, 204, 184, 185, 186, 208, 209,
189, 149, 150, 192, 193, 194, 195, 467, 149, 469,
470, 200, 201, 149, 44, 34, 35, 206, 207, 373,
31, 85, 33, 34, 35, 55, 154, 38, 58, 411,
154, 155, 156, 150, 416, 67, 68, 69, 150, 413,
149, 150, 149, 132, 149, 151, 149, 257, 150, 259,
80, 38, 150, 150, 84, 421, 421, 150, 150, 150,
150, 396, 416, 273, 150, 410, 434, 408, 409, 150,
415, 150, 417, 418, 419, 420, 150, 150, 150, 433,
454, 455, 456, 457, 428, 150, 152, 432, 432, 433,
150, 150, 150, 150, 150, 150, 451, 127, 128, 129,
130, 150, 150, 150, 150, 150, 150, 149, 3, 141,
142, 143, 144, 145, 324, 35, 34, 152, 37, 149,
151, 331, 31, 152, 151, 335, 152, 152, 31, 150,
150, 32, 150, 115, 31, 152, 152, 152, 150, 152,
150, 150, 149, 353, 354, 355, 149, 42, 43, 149,
149, 152, 150, 48, 49, 50, 152, 52, 53, 54,
149, 149, 132, 373, 135, 137, 78, 62, 63, 64,
65, 66, 573, 521, 169, 70, 523, 449, 74, 522,
-1, -1, -1, 393, -1, -1, -1, -1, 398, -1,
544, -1, 87, 88, -1, -1, -1, -1, -1, -1,
410, -1, -1, -1, -1, 415, -1, 417, 418, 419,
420, -1, 422, 539, 540, -1, -1, -1, 3, 429,
-1, -1, -1, 433, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 131, -1, -1, 449,
450, -1, -1, 453, -1, -1, 141, 142, 437, -1,
-1, 146, 147, -1, -1, 465, 151, 42, 43, -1,
155, 156, 451, 48, 49, 50, -1, 52, 53, 54,
8, 9, 10, 11, -1, -1, -1, 62, 63, 64,
65, 66, -1, -1, -1, 70, -1, -1, -1, -1,
500, -1, -1, -1, -1, -1, 506, -1, -1, -1,
-1, -1, 87, 88, -1, -1, -1, -1, -1, -1,
-1, 521, 522, 523, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, 67,
68, 69, -1, 71, 72, 73, 74, 75, -1, 549,
-1, -1, -1, -1, -1, -1, 131, -1, -1, -1,
-1, -1, -1, -1, 543, -1, 141, 142, -1, -1,
549, 146, 147, -1, -1, -1, 151, -1, 0, 1,
155, 156, 4, 5, 6, 7, 8, 9, 10, -1,
-1, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 135, 136, 137,
138, 139, 140, 141, 142, 143, 144, 145, -1, -1,
-1, 43, 44, 45, 46, 47, -1, -1, -1, 51,
-1, -1, -1, 55, 56, 57, 58, 59, -1, -1,
62, 63, 64, 65, 66, -1, 67, 68, 69, -1,
71, 72, 73, 74, 76, 77, 78, 79, 80, 81,
-1, -1, 84, -1, 86, -1, -1, 89, 90, 91,
92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
102, 103, 104, 105, 106, 107, -1, 109, 110, 111,
112, 113, -1, -1, 116, 117, 118, 119, 120, 121,
122, 123, 124, 125, 126, 127, 128, 129, 130, 8,
9, 10, 11, 12, -1, -1, -1, -1, 139, 140,
141, 142, 143, 144, 145, -1, -1, 149, -1, -1,
-1, -1, 8, 9, 10, 11, 12, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
8, 9, 10, 11, 12, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 8, -1, -1, 67, 68,
69, -1, 71, 72, 73, 74, 75, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 67, 68, 69, -1, 71, 72, 73, 74, 75,
-1, -1, -1, -1, -1, -1, -1, -1, -1, 67,
68, 69, -1, 71, 72, 73, 74, 75, -1, -1,
-1, -1, -1, -1, 67, 68, 69, -1, 71, 72,
73, 74, 75, -1, 133, -1, 135, 136, 137, 138,
139, 140, 141, 142, 143, 144, 145, 8, 9, 10,
11, 12, -1, -1, -1, -1, -1, 133, 157, 135,
136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
8, 9, 10, 11, 12, 133, 152, 135, 136, 137,
138, 139, 140, 141, 142, 143, 144, 145, 8, 9,
10, 11, 12, 151, 137, 138, 139, 140, 141, 142,
143, 144, 145, -1, -1, -1, 67, 68, 69, -1,
71, 72, 73, 74, 75, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, 67,
68, 69, -1, 71, 72, 73, 74, 75, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 67, 68, 69,
-1, 71, 72, 73, 74, 75, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, 133, -1, 135, 136, 137, 138, 139, 140,
141, 142, 143, 144, 145, -1, -1, -1, 149, 150,
8, 9, 10, 11, 12, 133, -1, 135, 136, 137,
138, 139, 140, 141, 142, 143, 144, 145, -1, -1,
-1, -1, 150, 133, -1, 135, 136, 137, 138, 139,
140, 141, 142, 143, 144, 145, -1, -1, -1, -1,
150, 8, 9, 10, 11, 12, 67, 68, 69, -1,
71, 72, 73, 74, 75, -1, -1, -1, -1, 67,
68, 69, -1, 71, 72, 73, 74, 75, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
8, 9, 10, 11, 12, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
67, 68, 69, -1, 71, 72, 73, 74, 75, -1,
-1, -1, -1, -1, -1, -1, -1, 138, 139, 140,
141, 142, 143, 144, 145, 133, -1, 135, 136, 137,
138, 139, 140, 141, 142, 143, 144, 145, -1, 67,
68, 69, 150, 71, 72, 73, 74, 75, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
8, 9, 10, 11, 12, -1, 133, -1, 135, 136,
137, 138, 139, 140, 141, 142, 143, 144, 145, -1,
-1, -1, -1, 150, 8, 9, 10, 11, 12, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, 8,
9, 10, 11, 12, -1, 133, -1, 135, 136, 137,
138, 139, 140, 141, 142, 143, 144, 145, -1, 67,
68, 69, 150, 71, 72, 73, 74, 75, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 67, 68, 69, -1, 71, 72, 73,
74, 75, -1, -1, -1, -1, -1, -1, 67, 68,
69, -1, 71, 72, 73, 74, 75, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 8, 9,
10, 11, 12, -1, -1, 133, -1, 135, 136, 137,
138, 139, 140, 141, 142, 143, 144, 145, -1, -1,
-1, 149, 8, 9, 10, 11, 12, -1, -1, 133,
-1, 135, 136, 137, 138, 139, 140, 141, 142, 143,
144, 145, -1, -1, 133, 149, 135, 136, 137, 138,
139, 140, 141, 142, 143, 144, 145, 67, 68, 69,
149, 71, 72, 73, 74, 75, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 67, 68, 69, -1, 71, 72, 73, 74, 75,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 8, 9, 10, 11, 12, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 8, 9, 10, 11,
12, -1, -1, 133, -1, 135, 136, 137, 138, 139,
140, 141, 142, 143, 144, 145, -1, -1, -1, 149,
8, 9, 10, 11, 12, -1, -1, 133, -1, 135,
136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
67, 68, 69, 149, 71, 72, 73, 74, 75, -1,
-1, -1, -1, -1, -1, 67, 68, 69, -1, 71,
72, 73, 74, 75, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, 67,
68, 69, -1, 71, 72, 73, 74, 75, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, 8,
9, 10, 11, 12, -1, -1, 133, -1, 135, 136,
137, 138, 139, 140, 141, 142, 143, 144, 145, -1,
-1, 133, 149, 135, 136, 137, 138, 139, 140, 141,
142, 143, 144, 145, -1, -1, -1, 149, 8, 9,
10, 11, 12, -1, -1, 133, -1, 135, 136, 137,
138, 139, 140, 141, 142, 143, 144, 145, 67, 68,
69, 149, 71, 72, 73, 74, 75, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 8, 9,
10, 11, 12, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 67, 68, 69,
-1, 71, 72, 73, 74, 75, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 8, 9, 10,
11, 12, -1, -1, 133, -1, 135, 136, 137, 138,
139, 140, 141, 142, 143, 144, 145, 67, 68, 69,
149, 71, 72, 73, 74, 75, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 8, 9, 10,
11, 12, -1, 133, -1, 135, 136, 137, 138, 139,
140, 141, 142, 143, 144, 145, 67, 68, 69, 149,
71, 72, 73, 74, 75, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 8, 9, 10, -1,
-1, -1, -1, 133, -1, 135, 136, 137, 138, 139,
140, 141, 142, 143, 144, 145, 67, 68, 69, 149,
71, 72, 73, 74, 75, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 8, -1, 10, -1,
-1, -1, 133, 134, 135, 136, 137, 138, 139, 140,
141, 142, 143, 144, 145, 67, 68, 69, -1, 71,
72, 73, 74, 75, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, 133, -1, 135, 136, 137, 138, 139, 140,
141, 142, 143, 144, 145, 67, 68, 69, -1, 71,
72, 73, 74, 75, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 135, 136, 137, 138, 139, 140, 141,
142, 143, 144, 145, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, 136, 137, 138, 139, 140, 141,
142, 143, 144, 145, 29, 30, 31, 32, 33, 34,
35, -1, -1, 38, 39, -1, -1, 42, 43, -1,
-1, -1, -1, 48, 49, 50, -1, 52, 53, 54,
-1, -1, -1, -1, -1, -1, -1, 62, 63, 64,
65, 66, -1, -1, -1, 70, 29, 30, 31, 32,
33, 34, 35, -1, -1, 38, -1, -1, -1, 42,
43, -1, 87, -1, -1, 48, 49, 50, -1, 52,
53, 54, -1, -1, -1, -1, -1, -1, -1, 62,
63, 64, 65, 66, -1, -1, -1, 70, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, 87, -1, 131, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 141, 142, -1, -1,
-1, 146, 147, -1, -1, -1, 151, -1, -1, -1,
155, 156, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 131, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 141, 142,
-1, -1, -1, 146, 147, -1, -1, -1, 151, -1,
-1, -1, 155, 156, 29, 30, 31, 32, -1, 34,
35, -1, -1, -1, -1, 40, -1, 42, 43, -1,
-1, -1, -1, 48, 49, 50, -1, 52, 53, 54,
-1, -1, -1, -1, -1, -1, -1, 62, 63, 64,
65, 66, -1, -1, -1, 70, 29, 30, 31, 32,
-1, 34, -1, -1, -1, -1, -1, 40, -1, 42,
43, -1, 87, -1, -1, 48, 49, 50, -1, 52,
53, 54, -1, -1, -1, -1, -1, -1, -1, 62,
63, 64, 65, 66, -1, -1, -1, 70, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, 87, -1, 131, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 141, 142, -1, -1,
-1, 146, 147, -1, -1, -1, 151, -1, -1, -1,
155, 156, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 131, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 141, 142,
-1, -1, -1, 146, 147, -1, -1, -1, 151, -1,
-1, -1, 155, 156, 29, 30, 31, 32, -1, -1,
-1, -1, -1, -1, -1, 40, -1, 42, 43, -1,
-1, -1, -1, 48, 49, 50, -1, 52, 53, 54,
-1, -1, -1, 29, 30, 31, 32, 62, 63, 64,
65, 66, -1, 39, -1, 70, 42, 43, -1, -1,
-1, -1, 48, 49, 50, -1, 52, 53, 54, -1,
-1, -1, 87, -1, -1, -1, 62, 63, 64, 65,
66, -1, -1, -1, 70, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 87, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 131, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 141, 142, -1, -1,
-1, 146, 147, -1, -1, -1, 151, -1, -1, -1,
155, 156, -1, -1, -1, 131, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 141, 142, -1, -1, -1,
146, 147, -1, -1, -1, 151, -1, -1, -1, 155,
156, 29, 30, 31, 32, -1, -1, -1, -1, -1,
-1, -1, -1, -1, 42, 43, -1, -1, -1, -1,
48, 49, 50, -1, 52, 53, 54, 29, 30, 31,
32, -1, -1, -1, 62, 63, 64, 65, 66, -1,
42, 43, 70, -1, -1, -1, 48, 49, 50, -1,
52, 53, 54, 29, 30, 31, 32, -1, -1, 87,
62, 63, 64, 65, 66, -1, 42, 43, 70, -1,
-1, -1, 48, 49, 50, -1, 52, 53, 54, -1,
-1, -1, -1, -1, -1, 87, 62, 63, 64, 65,
66, -1, -1, -1, 70, -1, -1, -1, -1, -1,
-1, -1, -1, 131, -1, -1, -1, -1, -1, -1,
-1, 87, -1, 141, 142, -1, -1, -1, 146, 147,
-1, -1, -1, 151, -1, -1, -1, 155, 156, 131,
-1, -1, -1, -1, -1, -1, -1, -1, -1, 141,
142, -1, -1, -1, 146, 147, -1, -1, -1, 151,
-1, -1, -1, 155, 156, 131, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 141, 142, -1, -1, -1,
146, 147, -1, -1, 29, 151, 31, 32, -1, 155,
156, -1, -1, -1, -1, -1, -1, 42, 43, -1,
-1, -1, -1, 48, 49, 50, -1, 52, 53, 54,
29, 30, 31, 32, -1, -1, -1, 62, 63, 64,
65, 66, -1, 42, 43, 70, -1, -1, -1, 48,
49, 50, -1, 52, 53, 54, 29, -1, 31, 32,
-1, -1, 87, 62, 63, 64, 65, 66, -1, 42,
43, 70, -1, -1, -1, 48, 49, 50, -1, 52,
53, 54, -1, -1, -1, -1, -1, -1, 87, 62,
63, 64, 65, 66, -1, -1, -1, 70, -1, -1,
-1, -1, -1, -1, -1, -1, 131, -1, -1, -1,
-1, -1, -1, -1, 87, -1, 141, 142, -1, -1,
-1, 146, 147, -1, -1, -1, 151, -1, 153, -1,
155, 156, 131, -1, -1, -1, -1, -1, -1, -1,
-1, -1, 141, 142, -1, -1, -1, 146, 147, -1,
-1, -1, 151, -1, -1, -1, 155, 156, 131, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 141, 142,
-1, -1, -1, 146, 147, -1, -1, 29, 151, 31,
32, -1, 155, 156, -1, -1, -1, -1, -1, -1,
42, 43, -1, -1, -1, -1, 48, 49, 50, -1,
52, 53, 54, -1, -1, -1, -1, -1, -1, -1,
62, 63, 64, 65, 66, -1, 32, -1, 70, -1,
-1, -1, -1, -1, 40, 41, 42, 43, -1, -1,
-1, -1, 48, 49, 50, 87, 52, 53, 54, -1,
-1, -1, -1, -1, -1, -1, 62, 63, 64, 65,
66, -1, -1, -1, 70, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 87, -1, -1, -1, -1, -1, -1, -1, 131,
-1, -1, -1, -1, -1, -1, -1, -1, -1, 141,
142, -1, -1, -1, 146, 147, -1, -1, -1, 151,
-1, -1, -1, 155, 156, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 131, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 141, 142, -1, -1, -1,
146, 147, -1, 32, -1, 151, -1, -1, -1, 155,
156, 40, 41, 42, 43, -1, -1, -1, -1, 48,
49, 50, -1, 52, 53, 54, -1, -1, -1, 32,
-1, -1, -1, 62, 63, 64, 65, 66, 41, 42,
43, 70, -1, -1, -1, 48, 49, 50, -1, 52,
53, 54, -1, -1, -1, 32, -1, -1, 87, 62,
63, 64, 65, 66, -1, 42, 43, 70, -1, -1,
-1, 48, 49, 50, -1, 52, 53, 54, -1, -1,
-1, -1, -1, -1, 87, 62, 63, 64, 65, 66,
-1, -1, -1, 70, -1, -1, -1, -1, -1, -1,
-1, -1, 131, -1, -1, -1, -1, -1, -1, -1,
87, -1, 141, 142, -1, -1, -1, 146, 147, -1,
-1, -1, 151, -1, -1, -1, 155, 156, 131, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 141, 142,
-1, -1, -1, 146, 147, -1, -1, -1, 151, -1,
-1, -1, 155, 156, 131, -1, -1, -1, -1, -1,
-1, -1, -1, -1, 141, 142, 32, -1, -1, 146,
147, -1, -1, -1, 151, -1, 42, 43, 155, 156,
-1, -1, 48, 49, 50, -1, 52, 53, 54, -1,
-1, -1, 32, -1, -1, -1, 62, 63, 64, 65,
66, -1, 42, 43, 70, -1, -1, -1, 48, 49,
50, -1, 52, 53, 54, -1, -1, -1, -1, -1,
-1, 87, 62, 63, 64, 65, 66, -1, -1, -1,
70, -1, -1, -1, -1, -1, -1, -1, -1, -1,
33, 34, 35, -1, -1, -1, -1, 87, -1, 42,
43, -1, -1, -1, -1, 48, 49, 50, -1, 52,
53, 54, -1, -1, -1, 131, -1, -1, -1, 62,
63, 64, 65, 66, -1, 141, 142, 70, -1, -1,
146, 147, -1, -1, -1, 151, -1, -1, -1, 155,
156, 131, -1, -1, 87, -1, -1, -1, -1, -1,
-1, 141, 142, 33, 34, 35, 146, 147, -1, -1,
-1, 151, 42, 43, -1, 155, 156, -1, 48, 49,
50, -1, 52, 53, 54, -1, -1, -1, -1, -1,
-1, -1, 62, 63, 64, 65, 66, -1, 131, -1,
70, -1, -1, -1, -1, -1, -1, -1, 141, 142,
-1, -1, -1, 146, 147, -1, -1, 87, 151, -1,
-1, -1, 155, 156, -1, -1, -1, 4, 5, 6,
7, 8, 9, 10, -1, -1, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 131, -1, -1, -1, -1, -1, -1, 45, 46,
47, 141, 142, -1, 51, -1, 146, 147, -1, 56,
57, 151, 59, -1, -1, 155, 156, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, 86,
-1, -1, -1, -1, -1, -1, -1, -1, -1, 96,
97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
107, -1, 109, 110, 111, 112, -1, -1, -1, 116,
117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
34, 35, -1, -1, -1, -1, -1, -1, 42, 43,
-1, -1, -1, -1, 48, 49, 50, -1, 52, 53,
54, -1, -1, -1, -1, -1, -1, -1, 62, 63,
64, 65, 66, -1, -1, -1, 70, -1, -1, -1,
-1, 34, 35, -1, -1, -1, -1, -1, -1, 42,
43, -1, -1, 87, 88, 48, 49, 50, -1, 52,
53, 54, -1, -1, -1, -1, -1, -1, -1, 62,
63, 64, 65, 66, -1, -1, -1, 70, -1, -1,
-1, 42, 43, -1, -1, -1, -1, 48, 49, 50,
-1, 52, 53, 54, 87, -1, -1, 131, -1, -1,
-1, 62, 63, 64, 65, 66, -1, 141, 142, 70,
-1, -1, 146, 147, -1, 34, 35, 151, -1, -1,
-1, 155, 156, 42, 43, -1, 87, -1, -1, 48,
49, 50, -1, 52, 53, 54, -1, -1, 131, -1,
-1, -1, -1, 62, 63, 64, 65, 66, 141, 142,
-1, 70, -1, 146, 147, -1, -1, -1, 151, -1,
-1, -1, 155, 156, -1, -1, -1, -1, 87, -1,
131, -1, -1, -1, -1, -1, -1, -1, -1, -1,
141, 142, -1, -1, -1, 146, 147, -1, 149, -1,
151, -1, -1, -1, 155, 156, 42, 43, -1, -1,
-1, -1, 48, 49, 50, -1, 52, 53, 54, -1,
-1, -1, 131, -1, -1, -1, 62, 63, 64, 65,
66, -1, 141, 142, 70, -1, -1, 146, 147, -1,
-1, -1, 151, -1, -1, -1, 155, 156, 42, 43,
-1, 87, -1, -1, 48, 49, 50, -1, 52, 53,
54, -1, -1, -1, -1, -1, -1, -1, 62, 63,
64, 65, 66, -1, -1, -1, 70, -1, -1, 42,
43, -1, -1, -1, -1, 48, 49, 50, -1, 52,
53, 54, -1, 87, -1, 131, -1, -1, -1, 62,
63, 64, 65, 66, -1, 141, 142, 70, -1, -1,
146, 147, -1, 149, -1, 151, -1, -1, -1, 155,
156, 42, 43, -1, 87, 88, -1, 48, 49, 50,
-1, 52, 53, 54, -1, -1, -1, 131, -1, -1,
-1, 62, 63, 64, 65, 66, -1, 141, 142, 70,
-1, -1, 146, 147, -1, -1, -1, 151, 152, -1,
-1, 155, 156, -1, -1, -1, 87, -1, 131, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 141, 142,
-1, -1, -1, 146, 147, -1, -1, -1, 151, -1,
-1, -1, 155, 156, 42, 43, -1, -1, -1, -1,
48, 49, 50, -1, 52, 53, 54, -1, -1, -1,
131, -1, -1, -1, 62, 63, 64, 65, 66, -1,
141, 142, 70, -1, -1, 146, 147, -1, -1, -1,
151, -1, -1, -1, 155, 156, -1, -1, -1, 87,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 131, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 141, 142, -1, -1, -1, 146, 147,
-1, -1, -1, 151, -1, -1, -1, 155, 156
};
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
symbol of state STATE-NUM. */
static const yytype_uint8 yystos[] =
{
0, 159, 0, 1, 43, 62, 63, 64, 65, 66,
76, 77, 78, 79, 81, 89, 90, 91, 92, 93,
94, 95, 113, 160, 172, 223, 83, 42, 43, 48,
49, 50, 52, 53, 54, 62, 63, 64, 65, 66,
70, 87, 131, 141, 142, 146, 147, 151, 155, 156,
219, 220, 221, 149, 149, 225, 149, 219, 219, 219,
43, 173, 174, 223, 175, 176, 223, 149, 149, 149,
162, 44, 55, 58, 80, 84, 127, 128, 129, 130,
149, 161, 60, 61, 82, 134, 138, 171, 163, 219,
219, 219, 219, 219, 219, 219, 222, 219, 219, 219,
219, 219, 219, 8, 9, 10, 11, 12, 67, 68,
69, 71, 72, 73, 74, 75, 133, 135, 136, 137,
138, 139, 140, 141, 142, 143, 144, 145, 149, 85,
226, 149, 149, 149, 149, 150, 149, 150, 114, 149,
219, 3, 87, 88, 219, 219, 225, 224, 219, 182,
183, 182, 149, 4, 5, 6, 7, 8, 9, 10,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 45, 46, 47, 51,
56, 57, 59, 86, 96, 97, 98, 99, 100, 101,
102, 103, 104, 105, 106, 107, 109, 110, 111, 112,
116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
126, 177, 219, 219, 219, 134, 219, 154, 181, 184,
185, 114, 152, 157, 219, 219, 219, 219, 219, 219,
219, 219, 219, 219, 219, 219, 219, 219, 219, 219,
219, 219, 219, 219, 219, 219, 219, 219, 219, 226,
149, 174, 176, 149, 149, 149, 149, 150, 149, 150,
85, 165, 224, 150, 185, 150, 219, 29, 30, 31,
32, 34, 40, 151, 194, 195, 196, 198, 199, 200,
201, 202, 219, 31, 34, 35, 194, 198, 209, 219,
31, 194, 198, 219, 31, 194, 219, 31, 194, 219,
31, 194, 219, 219, 32, 40, 41, 210, 211, 219,
31, 33, 38, 194, 203, 207, 209, 219, 219, 33,
36, 151, 219, 219, 151, 153, 199, 219, 211, 219,
39, 151, 194, 203, 220, 151, 219, 220, 33, 36,
108, 199, 205, 206, 209, 210, 195, 201, 219, 219,
219, 219, 219, 178, 180, 179, 38, 199, 204, 204,
199, 219, 219, 199, 219, 219, 197, 198, 199, 197,
204, 197, 219, 151, 210, 219, 219, 219, 199, 199,
219, 202, 219, 202, 199, 199, 219, 219, 207, 209,
149, 149, 149, 150, 149, 149, 150, 132, 134, 149,
219, 219, 226, 85, 145, 191, 192, 149, 167, 169,
150, 150, 34, 35, 151, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 38, 32, 150, 150, 150,
150, 33, 150, 150, 150, 32, 150, 150, 3, 88,
212, 213, 219, 216, 217, 219, 214, 215, 219, 150,
150, 150, 209, 150, 150, 150, 150, 150, 219, 164,
185, 219, 149, 149, 149, 193, 149, 150, 166, 224,
224, 194, 219, 34, 207, 208, 152, 152, 202, 35,
194, 219, 207, 209, 194, 219, 194, 219, 194, 219,
194, 219, 195, 201, 219, 34, 37, 152, 152, 151,
151, 220, 219, 31, 152, 39, 151, 194, 220, 221,
88, 209, 218, 219, 220, 221, 31, 203, 152, 31,
199, 150, 150, 150, 218, 219, 197, 152, 219, 202,
202, 202, 202, 149, 186, 187, 219, 192, 186, 192,
192, 152, 152, 150, 150, 32, 32, 150, 33, 150,
213, 217, 215, 115, 226, 226, 199, 209, 152, 152,
31, 152, 199, 219, 188, 149, 149, 132, 189, 190,
168, 170, 149, 150, 186, 186, 190
};
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
static const yytype_uint8 yyr1[] =
{
0, 158, 159, 159, 160, 161, 160, 160, 160, 160,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 160, 160, 162, 160, 160, 160, 160,
160, 160, 160, 160, 160, 160, 163, 164, 160, 165,
160, 166, 160, 167, 168, 160, 169, 170, 160, 160,
160, 171, 171, 171, 172, 172, 173, 173, 174, 175,
175, 176, 177, 177, 177, 177, 177, 177, 177, 177,
177, 177, 177, 177, 177, 177, 177, 177, 177, 177,
177, 177, 177, 177, 177, 177, 177, 177, 177, 177,
177, 177, 177, 177, 177, 177, 177, 177, 177, 177,
177, 177, 177, 177, 177, 177, 177, 177, 177, 177,
177, 177, 177, 177, 177, 177, 177, 177, 177, 177,
177, 177, 177, 177, 177, 177, 177, 177, 177, 177,
177, 177, 177, 177, 177, 177, 177, 177, 177, 177,
177, 177, 177, 177, 177, 177, 177, 177, 177, 177,
177, 177, 177, 177, 177, 177, 177, 177, 177, 177,
177, 177, 177, 177, 177, 177, 177, 177, 177, 177,
177, 177, 177, 178, 177, 179, 177, 180, 177, 177,
181, 181, 181, 183, 182, 184, 184, 185, 186, 187,
188, 187, 189, 189, 189, 190, 191, 191, 191, 192,
193, 192, 194, 194, 195, 195, 196, 197, 197, 198,
199, 199, 199, 200, 200, 201, 201, 201, 202, 203,
203, 204, 204, 205, 205, 205, 206, 206, 207, 207,
208, 208, 209, 209, 210, 210, 211, 211, 212, 212,
213, 213, 213, 214, 214, 215, 216, 216, 217, 218,
218, 219, 219, 220, 221, 221, 221, 221, 221, 221,
221, 221, 221, 222, 221, 221, 221, 221, 221, 221,
221, 221, 221, 221, 221, 221, 221, 221, 221, 221,
221, 221, 221, 221, 221, 221, 221, 221, 221, 221,
221, 221, 221, 221, 221, 221, 221, 221, 221, 221,
221, 221, 223, 223, 223, 223, 223, 223, 224, 225,
226
};
/* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
static const yytype_uint8 yyr2[] =
{
0, 2, 0, 2, 2, 0, 4, 4, 4, 4,
6, 3, 2, 2, 3, 4, 4, 6, 4, 4,
4, 6, 5, 4, 6, 0, 3, 2, 3, 3,
3, 3, 3, 2, 2, 2, 0, 0, 7, 0,
6, 0, 7, 0, 0, 11, 0, 0, 11, 3,
1, 0, 1, 2, 0, 2, 1, 3, 1, 1,
3, 1, 1, 2, 1, 2, 2, 2, 2, 2,
2, 4, 2, 4, 2, 2, 2, 2, 4, 4,
4, 4, 2, 4, 2, 2, 4, 2, 2, 2,
2, 2, 2, 4, 4, 4, 4, 2, 2, 4,
2, 2, 4, 4, 4, 2, 2, 2, 2, 2,
2, 2, 2, 4, 4, 6, 4, 2, 4, 4,
2, 2, 4, 2, 2, 1, 2, 4, 4, 4,
4, 4, 4, 4, 6, 2, 4, 2, 6, 2,
4, 2, 4, 4, 4, 4, 4, 2, 4, 2,
4, 2, 4, 4, 6, 4, 2, 6, 2, 6,
4, 4, 2, 6, 2, 6, 2, 2, 1, 2,
2, 2, 2, 0, 3, 0, 3, 0, 3, 1,
0, 1, 3, 0, 2, 0, 1, 2, 1, 0,
0, 5, 0, 1, 3, 1, 0, 1, 3, 1,
0, 3, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 3, 1, 4, 3, 4, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 3,
1, 1, 1, 1, 3, 1, 1, 3, 1, 1,
1, 1, 1, 3, 1, 1, 1, 1, 1, 1,
1, 1, 1, 0, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 5,
3, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 1, 1, 1, 1, 1, 1, 0, 0,
0
};
#define yyerrok (yyerrstatus = 0)
#define yyclearin (yychar = YYEMPTY)
#define YYEMPTY (-2)
#define YYEOF 0
#define YYACCEPT goto yyacceptlab
#define YYABORT goto yyabortlab
#define YYERROR goto yyerrorlab
#define YYRECOVERING() (!!yyerrstatus)
#define YYBACKUP(Token, Value) \
do \
if (yychar == YYEMPTY) \
{ \
yychar = (Token); \
yylval = (Value); \
YYPOPSTACK (yylen); \
yystate = *yyssp; \
goto yybackup; \
} \
else \
{ \
yyerror (YY_("syntax error: cannot back up")); \
YYERROR; \
} \
while (0)
/* Error token number */
#define YYTERROR 1
#define YYERRCODE 256
/* Enable debugging if requested. */
#if YYDEBUG
# ifndef YYFPRINTF
# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
# define YYFPRINTF fprintf
////# define YYFPRINTF printf
# endif
# define YYDPRINTF(Args) \
do { \
if (yydebug) \
YYFPRINTF Args; \
} while (0)
/* This macro is provided for backward compatibility. */
#ifndef YY_LOCATION_PRINT
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
#endif
# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
do { \
if (yydebug) \
{ \
YYFPRINTF (stderr, "%s ", Title); \
yy_symbol_print (stderr, \
Type, Value); \
YYFPRINTF (stderr, "\n"); \
} \
} while (0)
/*----------------------------------------.
| Print this symbol's value on YYOUTPUT. |
`----------------------------------------*/
static void
yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
{
FILE *yyo = yyoutput;
YYUSE (yyo);
if (!yyvaluep)
return;
# ifdef YYPRINT
if (yytype < YYNTOKENS)
YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
# endif
YYUSE (yytype);
}
/*--------------------------------.
| Print this symbol on YYOUTPUT. |
`--------------------------------*/
static void
yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
{
YYFPRINTF (yyoutput, "%s %s (",
yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
yy_symbol_value_print (yyoutput, yytype, yyvaluep);
YYFPRINTF (yyoutput, ")");
}
/*------------------------------------------------------------------.
| yy_stack_print -- Print the state stack from its BOTTOM up to its |
| TOP (included). |
`------------------------------------------------------------------*/
static void
yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
{
YYFPRINTF (stderr, "Stack now");
for (; yybottom <= yytop; yybottom++)
{
int yybot = *yybottom;
YYFPRINTF (stderr, " %d", yybot);
}
YYFPRINTF (stderr, "\n");
}
# define YY_STACK_PRINT(Bottom, Top) \
do { \
if (yydebug) \
yy_stack_print ((Bottom), (Top)); \
} while (0)
/*------------------------------------------------.
| Report that the YYRULE is going to be reduced. |
`------------------------------------------------*/
static void
yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
{
unsigned long int yylno = yyrline[yyrule];
int yynrhs = yyr2[yyrule];
int yyi;
YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
yyrule - 1, yylno);
/* The symbols being reduced. */
for (yyi = 0; yyi < yynrhs; yyi++)
{
YYFPRINTF (stderr, " $%d = ", yyi + 1);
yy_symbol_print (stderr,
yystos[yyssp[yyi + 1 - yynrhs]],
&(yyvsp[(yyi + 1) - (yynrhs)])
);
YYFPRINTF (stderr, "\n");
}
}
# define YY_REDUCE_PRINT(Rule) \
do { \
if (yydebug) \
yy_reduce_print (yyssp, yyvsp, Rule); \
} while (0)
/* Nonzero means print parse trace. It is left uninitialized so that
multiple parsers can coexist. */
int yydebug = 1;
#else /* !YYDEBUG */
# define YYDPRINTF(Args)
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
# define YY_STACK_PRINT(Bottom, Top)
# define YY_REDUCE_PRINT(Rule)
#endif /* !YYDEBUG */
/* YYINITDEPTH -- initial size of the parser's stacks. */
#ifndef YYINITDEPTH
# define YYINITDEPTH 200
#endif
/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
if the built-in stack extension method is used).
Do not make this value too large; the results are undefined if
YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
evaluated with infinite-precision integer arithmetic. */
#ifndef YYMAXDEPTH
# define YYMAXDEPTH 10000
#endif
#if YYERROR_VERBOSE
# ifndef yystrlen
# if defined __GLIBC__ && defined _STRING_H
# define yystrlen strlen
# else
/* Return the length of YYSTR. */
static YYSIZE_T
yystrlen (const char *yystr)
{
YYSIZE_T yylen;
for (yylen = 0; yystr[yylen]; yylen++)
continue;
return yylen;
}
# endif
# endif
# ifndef yystpcpy
# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
# define yystpcpy stpcpy
# else
/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
YYDEST. */
static char *
yystpcpy (char *yydest, const char *yysrc)
{
char *yyd = yydest;
const char *yys = yysrc;
while ((*yyd++ = *yys++) != '\0')
continue;
return yyd - 1;
}
# endif
# endif
# ifndef yytnamerr
/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
quotes and backslashes, so that it's suitable for yyerror. The
heuristic is that double-quoting is unnecessary unless the string
contains an apostrophe, a comma, or backslash (other than
backslash-backslash). YYSTR is taken from yytname. If YYRES is
null, do not copy; instead, return the length of what the result
would have been. */
static YYSIZE_T
yytnamerr (char *yyres, const char *yystr)
{
if (*yystr == '"')
{
YYSIZE_T yyn = 0;
char const *yyp = yystr;
for (;;)
switch (*++yyp)
{
case '\'':
case ',':
goto do_not_strip_quotes;
case '\\':
if (*++yyp != '\\')
goto do_not_strip_quotes;
/* Fall through. */
default:
if (yyres)
yyres[yyn] = *yyp;
yyn++;
break;
case '"':
if (yyres)
yyres[yyn] = '\0';
return yyn;
}
do_not_strip_quotes: ;
}
if (! yyres)
return yystrlen (yystr);
return yystpcpy (yyres, yystr) - yyres;
}
# endif
/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
about the unexpected token YYTOKEN for the state stack whose top is
YYSSP.
Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
not large enough to hold the message. In that case, also set
*YYMSG_ALLOC to the required number of bytes. Return 2 if the
required number of bytes is too large to store. */
static int
yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
yytype_int16 *yyssp, int yytoken)
{
YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
YYSIZE_T yysize = yysize0;
enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
/* Internationalized format string. */
const char *yyformat = YY_NULLPTR;
/* Arguments of yyformat. */
char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
/* Number of reported tokens (one for the "unexpected", one per
"expected"). */
int yycount = 0;
/* There are many possibilities here to consider:
- If this state is a consistent state with a default action, then
the only way this function was invoked is if the default action
is an error action. In that case, don't check for expected
tokens because there are none.
- The only way there can be no lookahead present (in yychar) is if
this state is a consistent state with a default action. Thus,
detecting the absence of a lookahead is sufficient to determine
that there is no unexpected or expected token to report. In that
case, just report a simple "syntax error".
- Don't assume there isn't a lookahead just because this state is a
consistent state with a default action. There might have been a
previous inconsistent state, consistent state with a non-default
action, or user semantic action that manipulated yychar.
- Of course, the expected token list depends on states to have
correct lookahead information, and it depends on the parser not
to perform extra reductions after fetching a lookahead from the
scanner and before detecting a syntax error. Thus, state merging
(from LALR or IELR) and default reductions corrupt the expected
token list. However, the list is correct for canonical LR with
one exception: it will still contain any token that will not be
accepted due to an error action in a later state.
*/
if (yytoken != YYEMPTY)
{
int yyn = yypact[*yyssp];
yyarg[yycount++] = yytname[yytoken];
if (!yypact_value_is_default (yyn))
{
/* Start YYX at -YYN if negative to avoid negative indexes in
YYCHECK. In other words, skip the first -YYN actions for
this state because they are default actions. */
int yyxbegin = yyn < 0 ? -yyn : 0;
/* Stay within bounds of both yycheck and yytname. */
int yychecklim = YYLAST - yyn + 1;
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
int yyx;
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
&& !yytable_value_is_error (yytable[yyx + yyn]))
{
if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
{
yycount = 1;
yysize = yysize0;
break;
}
yyarg[yycount++] = yytname[yyx];
{
YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
if (! (yysize <= yysize1
&& yysize1 <= YYSTACK_ALLOC_MAXIMUM))
return 2;
yysize = yysize1;
}
}
}
}
switch (yycount)
{
# define YYCASE_(N, S) \
case N: \
yyformat = S; \
break
YYCASE_(0, YY_("syntax error"));
YYCASE_(1, YY_("syntax error, unexpected %s"));
YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
# undef YYCASE_
}
{
YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
return 2;
yysize = yysize1;
}
if (*yymsg_alloc < yysize)
{
*yymsg_alloc = 2 * yysize;
if (! (yysize <= *yymsg_alloc
&& *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
*yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
return 1;
}
/* Avoid sprintf, as that infringes on the user's name space.
Don't have undefined behavior even if the translation
produced a string with the wrong number of "%s"s. */
{
char *yyp = *yymsg;
int yyi = 0;
while ((*yyp = *yyformat) != '\0')
if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
{
yyp += yytnamerr (yyp, yyarg[yyi++]);
yyformat += 2;
}
else
{
yyp++;
yyformat++;
}
}
return 0;
}
#endif /* YYERROR_VERBOSE */
/*-----------------------------------------------.
| Release the memory associated to this symbol. |
`-----------------------------------------------*/
static void
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
{
YYUSE (yyvaluep);
if (!yymsg)
yymsg = "Deleting";
YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
YYUSE (yytype);
YY_IGNORE_MAYBE_UNINITIALIZED_END
}
/* The lookahead symbol. */
int yychar;
/* The semantic value of the lookahead symbol. */
YYSTYPE yylval;
/* Number of syntax errors so far. */
int yynerrs;
/*----------.
| yyparse. |
`----------*/
int
yyparse (void)
{
int yystate;
/* Number of tokens to shift before error messages enabled. */
int yyerrstatus;
/* The stacks and their tools:
'yyss': related to states.
'yyvs': related to semantic values.
Refer to the stacks through separate pointers, to allow yyoverflow
to reallocate them elsewhere. */
/* The state stack. */
yytype_int16 yyssa[YYINITDEPTH];
yytype_int16 *yyss;
yytype_int16 *yyssp;
/* The semantic value stack. */
YYSTYPE yyvsa[YYINITDEPTH];
YYSTYPE *yyvs;
YYSTYPE *yyvsp;
YYSIZE_T yystacksize;
int yyn;
int yyresult;
/* Lookahead token as an internal (translated) token number. */
int yytoken = 0;
/* The variables used to return semantic value and location from the
action routines. */
YYSTYPE yyval;
#if YYERROR_VERBOSE
/* Buffer for error messages, and its allocated size. */
char yymsgbuf[128];
char *yymsg = yymsgbuf;
YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
#endif
#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
/* The number of symbols on the RHS of the reduced rule.
Keep to zero when no symbol should be popped. */
int yylen = 0;
yyssp = yyss = yyssa;
yyvsp = yyvs = yyvsa;
yystacksize = YYINITDEPTH;
YYDPRINTF ((stderr, "Starting parse\n"));
yystate = 0;
yyerrstatus = 0;
yynerrs = 0;
yychar = YYEMPTY; /* Cause a token to be read. */
goto yysetstate;
/*------------------------------------------------------------.
| yynewstate -- Push a new state, which is found in yystate. |
`------------------------------------------------------------*/
yynewstate:
/* In all cases, when you get here, the value and location stacks
have just been pushed. So pushing a state here evens the stacks. */
yyssp++;
yysetstate:
*yyssp = yystate;
if (yyss + yystacksize - 1 <= yyssp)
{
/* Get the current used size of the three stacks, in elements. */
YYSIZE_T yysize = yyssp - yyss + 1;
#ifdef yyoverflow
{
/* Give user a chance to reallocate the stack. Use copies of
these so that the &'s don't force the real ones into
memory. */
YYSTYPE *yyvs1 = yyvs;
yytype_int16 *yyss1 = yyss;
/* Each stack pointer address is followed by the size of the
data in use in that stack, in bytes. This used to be a
conditional around just the two extra args, but that might
be undefined if yyoverflow is a macro. */
yyoverflow (YY_("memory exhausted"),
&yyss1, yysize * sizeof (*yyssp),
&yyvs1, yysize * sizeof (*yyvsp),
&yystacksize);
yyss = yyss1;
yyvs = yyvs1;
}
#else /* no yyoverflow */
# ifndef YYSTACK_RELOCATE
goto yyexhaustedlab;
# else
/* Extend the stack our own way. */
if (YYMAXDEPTH <= yystacksize)
goto yyexhaustedlab;
yystacksize *= 2;
if (YYMAXDEPTH < yystacksize)
yystacksize = YYMAXDEPTH;
{
yytype_int16 *yyss1 = yyss;
union yyalloc *yyptr =
(union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
if (! yyptr)
goto yyexhaustedlab;
YYSTACK_RELOCATE (yyss_alloc, yyss);
YYSTACK_RELOCATE (yyvs_alloc, yyvs);
# undef YYSTACK_RELOCATE
if (yyss1 != yyssa)
YYSTACK_FREE (yyss1);
}
# endif
#endif /* no yyoverflow */
yyssp = yyss + yysize - 1;
yyvsp = yyvs + yysize - 1;
YYDPRINTF ((stderr, "Stack size increased to %lu\n",
(unsigned long int) yystacksize));
if (yyss + yystacksize - 1 <= yyssp)
YYABORT;
}
YYDPRINTF ((stderr, "Entering state %d\n", yystate));
if (yystate == YYFINAL)
YYACCEPT;
goto yybackup;
/*-----------.
| yybackup. |
`-----------*/
yybackup:
/* Do appropriate processing given the current state. Read a
lookahead token if we need one and don't already have one. */
/* First try to decide what to do without reference to lookahead token. */
yyn = yypact[yystate];
if (yypact_value_is_default (yyn))
goto yydefault;
/* Not known => get a lookahead token if don't already have one. */
/* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
if (yychar == YYEMPTY)
{
YYDPRINTF ((stderr, "Reading a token: "));
yychar = yylex ();
if (yychar == 386) {
yychar = yychar;
}
}
if (yychar <= YYEOF)
{
yychar = yytoken = YYEOF;
YYDPRINTF ((stderr, "Now at end of input.\n"));
}
else
{
yytokentype ytyp = yychar;
yytoken = YYTRANSLATE (yychar);
YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
}
/* If the proper action on seeing token YYTOKEN is to reduce or to
detect an error, take that action. */
yyn += yytoken;
if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
goto yydefault;
yyn = yytable[yyn];
if (yyn <= 0)
{
if (yytable_value_is_error (yyn))
goto yyerrlab;
yyn = -yyn;
goto yyreduce;
}
/* Count tokens shifted since error; after three, turn off error
status. */
if (yyerrstatus)
yyerrstatus--;
/* Shift the lookahead token. */
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
/* Discard the shifted token. */
yychar = YYEMPTY;
yystate = yyn;
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
*++yyvsp = yylval;
YY_IGNORE_MAYBE_UNINITIALIZED_END
goto yynewstate;
/*-----------------------------------------------------------.
| yydefault -- do the default action for the current state. |
`-----------------------------------------------------------*/
yydefault:
yyn = yydefact[yystate];
if (yyn == 0)
goto yyerrlab;
goto yyreduce;
/*-----------------------------.
| yyreduce -- Do a reduction. |
`-----------------------------*/
yyreduce:
/* yyn is the number of a rule to reduce with. */
yylen = yyr2[yyn];
/* If YYLEN is nonzero, implement the default value of the action:
'$$ = $1'.
Otherwise, the following line sets YYVAL to garbage.
This behavior is undocumented and Bison
users should not rely upon it. Assigning to YYVAL
unconditionally makes the parser a bit smaller, and it avoids a
GCC warning that YYVAL may be used uninitialized. */
yyval = yyvsp[1-yylen];
YY_REDUCE_PRINT (yyn);
switch (yyn)
{
case 4:
////#line 1783 "zmac.y" /* yacc.c:1646 */
{
// An identfier without a colon all by itself on a line
// will be interpreted as a label. But there's a very
// good chance it is a misspelling of an instruction or
// pseudo-op name creating silent errors. Since the condition
// is unusual we print a warning. Unless it is followed by
// a colon in which case there's no ambiguity.
if ((yyvsp[-1].itemptr) && !firstcol && coloncnt == 0 && outpass) {
fprintf(stderr, "%s(%d): warning: '%s' treated as label (instruction typo?)\n",
src_name[now_in], linein[now_in], (yyvsp[-1].itemptr)->i_string);
fprintf(stderr, "\tAdd a colon or move to first column to stop this warning.\n");
}
if ((yyvsp[-1].itemptr)) list(dollarsign);
else list1();
}
////#line 4076 "zmac.c" /* yacc.c:1646 */
break;
case 5:
////#line 1800 "zmac.y" /* yacc.c:1646 */
{ list_dollarsign = 1; }
////#line 4082 "zmac.c" /* yacc.c:1646 */
break;
case 6:
////#line 1800 "zmac.y" /* yacc.c:1646 */
{
list(list_dollarsign ? dollarsign : list_addr);
}
////#line 4090 "zmac.c" /* yacc.c:1646 */
break;
case 7:
////#line 1804 "zmac.y" /* yacc.c:1646 */
{
do_equ((yyvsp[-3].itemptr), (yyvsp[-1].exprptr), 1);
}
////#line 4098 "zmac.c" /* yacc.c:1646 */
break;
case 8:
////#line 1808 "zmac.y" /* yacc.c:1646 */
{
do_equ((yyvsp[-3].itemptr), (yyvsp[-1].exprptr), 1); // TODO: is '=' equate or defl?
}
////#line 4106 "zmac.c" /* yacc.c:1646 */
break;
case 9:
////#line 1812 "zmac.y" /* yacc.c:1646 */
{
do_defl((yyvsp[-3].itemptr), (yyvsp[-1].exprptr), 1);
}
////#line 4114 "zmac.c" /* yacc.c:1646 */
break;
case 10:
////#line 1816 "zmac.y" /* yacc.c:1646 */
{
int val3 = (yyvsp[-3].exprptr)->e_value;
int val5 = (yyvsp[-1].exprptr)->e_value;
expr_reloc_check((yyvsp[-3].exprptr));
expr_reloc_check((yyvsp[-1].exprptr));
expr_scope_same((yyvsp[-3].exprptr), (yyvsp[-1].exprptr));
switch ((yyvsp[-5].itemptr)->i_token) {
case UNDECLARED: case DEFLED:
(yyvsp[-5].itemptr)->i_token = DEFLED;
(yyvsp[-5].itemptr)->i_scope |= (yyvsp[-3].exprptr)->e_scope;
if ((yyvsp[-4].itemptr)->i_value) /* max */
list((yyvsp[-5].itemptr)->i_value = (val3 > val5? val3:val5));
else list((yyvsp[-5].itemptr)->i_value = (val3 < val5? val3:val5));
break;
default:
err[mflag]++;
(yyvsp[-5].itemptr)->i_token = MULTDEF;
list((yyvsp[-5].itemptr)->i_value);
}
expr_free((yyvsp[-3].exprptr));
expr_free((yyvsp[-1].exprptr));
}
////#line 4141 "zmac.c" /* yacc.c:1646 */
break;
case 11:
////#line 1839 "zmac.y" /* yacc.c:1646 */
{
expr_number_check((yyvsp[-1].exprptr));
if (ifptr >= ifstmax)
error("Too many ifs");
else
*++ifptr = !((yyvsp[-1].exprptr)->e_value);
saveopt = fopt;
fopt = 1;
list((yyvsp[-1].exprptr)->e_value);
fopt = saveopt;
expr_free((yyvsp[-1].exprptr));
}
////#line 4159 "zmac.c" /* yacc.c:1646 */
break;
case 12:
////#line 1853 "zmac.y" /* yacc.c:1646 */
{
/* FIXME: it would be nice to spot repeated ELSEs, but how? */
*ifptr = !*ifptr;
saveopt = fopt;
fopt = 1;
list1();
fopt = saveopt;
}
////#line 4172 "zmac.c" /* yacc.c:1646 */
break;
case 13:
////#line 1862 "zmac.y" /* yacc.c:1646 */
{
if (ifptr == ifstack) err[bflag]++;
else --ifptr;
list1();
}
////#line 4182 "zmac.c" /* yacc.c:1646 */
break;
case 14:
////#line 1868 "zmac.y" /* yacc.c:1646 */
{
list(dollarsign);
peekc = 0;
}
////#line 4191 "zmac.c" /* yacc.c:1646 */
break;
case 15:
////#line 1873 "zmac.y" /* yacc.c:1646 */
{
expr_reloc_check((yyvsp[-1].exprptr));
xeq_flag++;
xeq = (yyvsp[-1].exprptr)->e_value & 0xffff;
list((yyvsp[-1].exprptr)->e_value);
peekc = 0;
rel_main = (((yyvsp[-1].exprptr)->e_scope & SCOPE_SEGMASK) << 16) | xeq;
expr_free((yyvsp[-1].exprptr));
}
////#line 4205 "zmac.c" /* yacc.c:1646 */
break;
case 16:
////#line 1883 "zmac.y" /* yacc.c:1646 */
{
expr_number_check((yyvsp[-1].exprptr));
if ((yyvsp[-1].exprptr)->e_value < 0) err[vflag]++;
if ((yyvsp[-1].exprptr)->e_value > 0) {
if (!phaseflag) {
list(dollarsign);
flushbin();
flushoth();
dollarsign += (yyvsp[-1].exprptr)->e_value;
olddollar += (yyvsp[-1].exprptr)->e_value;
oldothdollar += (yyvsp[-1].exprptr)->e_value;
emit_addr += (yyvsp[-1].exprptr)->e_value;
advance_segment((yyvsp[-1].exprptr)->e_value);
putrelcmd(RELCMD_SETLOC);
putrelsegref(segment, seg_pos[segment]);
}
else
dc((yyvsp[-1].exprptr)->e_value, 0);
}
else
list1();
expr_free((yyvsp[-1].exprptr));
}
////#line 4234 "zmac.c" /* yacc.c:1646 */
break;
case 17:
////#line 1908 "zmac.y" /* yacc.c:1646 */
{
expr_number_check((yyvsp[-3].exprptr));
expr_number_check((yyvsp[-1].exprptr));
if ((yyvsp[-3].exprptr)->e_value < 0) err[vflag]++;
if ((yyvsp[-1].exprptr)->e_value < -128 || (yyvsp[-1].exprptr)->e_value > 127) err[vflag]++;
if ((yyvsp[-3].exprptr)->e_value > 0) {
dc((yyvsp[-3].exprptr)->e_value, (yyvsp[-1].exprptr)->e_value);
}
else
list1();
expr_free((yyvsp[-3].exprptr));
expr_free((yyvsp[-1].exprptr));
}
////#line 4253 "zmac.c" /* yacc.c:1646 */
break;
case 18:
////#line 1923 "zmac.y" /* yacc.c:1646 */
{ emit(1, E_DATA, expr_num((yyvsp[-1].ival) | 0x80)); list(dollarsign); }
////#line 4259 "zmac.c" /* yacc.c:1646 */
break;
case 19:
////#line 1925 "zmac.y" /* yacc.c:1646 */
{ emit(1, E_DATA, expr_num((yyvsp[-1].ival))); emit(1, E_DATA, expr_num(((yyvsp[-1].ival) >> 8) | 0x80)); list(dollarsign); }
////#line 4265 "zmac.c" /* yacc.c:1646 */
break;
case 20:
////#line 1928 "zmac.y" /* yacc.c:1646 */
{
for (cp = (yyvsp[-1].cval); *cp != '\0'; cp++)
if (!cp[1])
emit(1, E_DATA, expr_num(*cp | 0x80));
else
emit(1, E_DATA, expr_num(*cp));
list(dollarsign);
}
////#line 4279 "zmac.c" /* yacc.c:1646 */
break;
case 21:
////#line 1939 "zmac.y" /* yacc.c:1646 */
{
expr_number_check((yyvsp[-3].exprptr));
expr_number_check((yyvsp[-1].exprptr));
dc((yyvsp[-3].exprptr)->e_value, (yyvsp[-1].exprptr)->e_value);
expr_free((yyvsp[-3].exprptr));
expr_free((yyvsp[-1].exprptr));
}
////#line 4291 "zmac.c" /* yacc.c:1646 */
break;
case 22:
////#line 1947 "zmac.y" /* yacc.c:1646 */
{
list1();
switch ((yyvsp[-4].itemptr)->i_value) {
case PSTITL: /* title */
lineptr = linebuf;
cp = tempbuf;
title = titlespace;
while ((*title++ = *cp++) && (title < &titlespace[TITLELEN]));
*title = 0;
title = titlespace;
break;
case PSRSYM: /* rsym */
if (pass2) break;
insymtab(tempbuf);
break;
case PSWSYM: /* wsym */
writesyms = malloc(strlen(tempbuf)+1);
strcpy(writesyms, tempbuf);
break;
case PSINC: /* include file */
next_source(tempbuf) ;
break ;
case PSMACLIB:
strcat(tempbuf, ".lib");
next_source(tempbuf);
break;
}
}
////#line 4327 "zmac.c" /* yacc.c:1646 */
break;
case 23:
////#line 1979 "zmac.y" /* yacc.c:1646 */
{
fprintf(stderr, "Missing argument of '%s'\n", (yyvsp[-3].itemptr)->i_string);
err[fflag]++;
list(dollarsign);
}
////#line 4337 "zmac.c" /* yacc.c:1646 */
break;
case 24:
////#line 1985 "zmac.y" /* yacc.c:1646 */
{
incbin(tempbuf);
}
////#line 4345 "zmac.c" /* yacc.c:1646 */
break;
case 25:
////#line 1989 "zmac.y" /* yacc.c:1646 */
{ raw = 1; }
////#line 4351 "zmac.c" /* yacc.c:1646 */
break;
case 26:
////#line 1989 "zmac.y" /* yacc.c:1646 */
{
int quote = 0;
char *p, *q;
switch ((yyvsp[-2].itemptr)->i_value) {
case SPTITL:
cp = tempbuf;
title = titlespace;
if (*cp == '\'' || *cp == '"')
quote = *cp++;
while ((*title++ = *cp++) && (title < &titlespace[TITLELEN]));
if (quote && title > titlespace + 1 && title[-2] == quote)
title[-2] = '\0';
title = titlespace;
list1();
break;
case SPSBTL:
err[warn_notimpl]++;
list1();
break;
case SPNAME:
// Drop surrounding ('') if present
p = tempbuf;
q = strchr(tempbuf, '\0') - 1;
if (*p == '(' && *q == ')' && q > p) p++, q--;
if (*p == '\'' && *q == '\'' && q > p) p++, q--;
q[1] = '\0';
strncpy(progname, p, sizeof progname);
progname[sizeof progname - 1] = '\0';
list1();
break;
case SPCOM:
quote = *tempbuf;
list1();
for (;;) {
raw = 1;
yychar = yylex();
list1();
if (yychar == 0)
break;
if (*tempbuf == quote) {
yychar = yylex();
break;
}
}
break;
case SPPRAGMA:
if (strncmp(tempbuf, "bds", 3) == 0 && bopt && outpass) {
fprintf(fbds, "%s\n", tempbuf + 4);
}
list1();
break;
}
}
////#line 4410 "zmac.c" /* yacc.c:1646 */
break;
case 27:
////#line 2044 "zmac.y" /* yacc.c:1646 */
{
goto dolopt; }
////#line 4417 "zmac.c" /* yacc.c:1646 */
break;
case 28:
////#line 2047 "zmac.y" /* yacc.c:1646 */
{
int enable = (yyvsp[-1].exprptr)->e_value;
expr_number_check((yyvsp[-1].exprptr));
expr_free((yyvsp[-1].exprptr));
goto doloptA;
dolopt:
enable = 1;
doloptA:
linecnt++;
if (outpass) {
lineptr = linebuf;
switch ((yyvsp[-2].itemptr)->i_value) {
case 0: /* list */
if (enable < 0) lstoff = 1;
if (enable > 0) lstoff = 0;
break;
case 1: /* eject */
if (enable) eject();
break;
case 2: /* space */
if ((line + enable) > 60) eject();
else space(enable);
break;
case 3: /* elist */
eopt = edef;
if (enable < 0) eopt = 0;
if (enable > 0) eopt = 1;
break;
case 4: /* fopt */
fopt = fdef;
if (enable < 0) fopt = 0;
if (enable > 0) fopt = 1;
break;
case 5: /* gopt */
gopt = gdef;
if (enable < 0) gopt = 1;
if (enable > 0) gopt = 0;
break;
case 6: /* mopt */
mopt = mdef;
if (enable < 0) mopt = 0;
if (enable > 0) mopt = 1;
}
}
}
////#line 4473 "zmac.c" /* yacc.c:1646 */
break;
case 29:
////#line 2099 "zmac.y" /* yacc.c:1646 */
{
expr_number_check((yyvsp[-1].exprptr));
jopt = !!(yyvsp[-1].exprptr)->e_value;
list1();
expr_free((yyvsp[-1].exprptr));
}
////#line 4484 "zmac.c" /* yacc.c:1646 */
break;
case 30:
////#line 2106 "zmac.y" /* yacc.c:1646 */
{
expr_number_check((yyvsp[-1].exprptr));
JPopt = !!(yyvsp[-1].exprptr)->e_value;
list1();
expr_free((yyvsp[-1].exprptr));
}
////#line 4495 "zmac.c" /* yacc.c:1646 */
break;
case 31:
////#line 2113 "zmac.y" /* yacc.c:1646 */
{
list1();
}
////#line 4503 "zmac.c" /* yacc.c:1646 */
break;
case 32:
////#line 2117 "zmac.y" /* yacc.c:1646 */
{
list1();
}
////#line 4511 "zmac.c" /* yacc.c:1646 */
break;
case 33:
////#line 2121 "zmac.y" /* yacc.c:1646 */
{
char *p = strchr(modstr, '\0') - 1;
for (; p >= modstr; p--) {
(*p)++;
if (*p < 'Z')
break;
*p = 'A';
}
list1();
}
////#line 4526 "zmac.c" /* yacc.c:1646 */
break;
case 34:
////#line 2132 "zmac.y" /* yacc.c:1646 */
{
if (relopt && segment != (yyvsp[-1].itemptr)->i_value) {
segment = (yyvsp[-1].itemptr)->i_value;
segchange = 1;
dollarsign = seg_pos[(yyvsp[-1].itemptr)->i_value];
}
list1();
}
////#line 4539 "zmac.c" /* yacc.c:1646 */
break;
case 35:
////#line 2141 "zmac.y" /* yacc.c:1646 */
{
z80 = (yyvsp[-1].itemptr)->i_value;
list1();
}
////#line 4548 "zmac.c" /* yacc.c:1646 */
break;
case 36:
////#line 2146 "zmac.y" /* yacc.c:1646 */
{ param_parse = 1; }
////#line 4554 "zmac.c" /* yacc.c:1646 */
break;
case 37:
////#line 2146 "zmac.y" /* yacc.c:1646 */
{
param_parse = 0;
(yyvsp[-4].itemptr)->i_token = MNAME;
(yyvsp[-4].itemptr)->i_value = mfptr;
if (keyword((yyvsp[-4].itemptr)->i_string)) {
sprintf(detail, "Macro '%s' will override the built-in '%s'",
(yyvsp[-4].itemptr)->i_string, (yyvsp[-4].itemptr)->i_string);
errwarn(warn_general, detail);
}
#ifdef M_DEBUG
fprintf (stderr, "%s(%d) [UNDECLARED MACRO %s]\n",
src_name[now_in], linein[now_in], (yyvsp[-4].itemptr)->i_string);
#endif
list1();
}
////#line 4574 "zmac.c" /* yacc.c:1646 */
break;
case 38:
////#line 2161 "zmac.y" /* yacc.c:1646 */
{
mlex_list_on++;
mfseek(mfile, (long)mfptr, 0);
mlex((yyvsp[0].cval));
mlex_list_on--;
parm_number = 0;
}
////#line 4586 "zmac.c" /* yacc.c:1646 */
break;
case 39:
////#line 2169 "zmac.y" /* yacc.c:1646 */
{ arg_state.macarg = 1; }
////#line 4592 "zmac.c" /* yacc.c:1646 */
break;
case 40:
////#line 2169 "zmac.y" /* yacc.c:1646 */
{
#ifdef M_DEBUG
fprintf (stderr, "%s(%d) [MNAME %s]\n",
src_name[now_in], linein[now_in], (yyvsp[-4].itemptr)->i_string);
#endif
(yyvsp[-4].itemptr)->i_uses++ ;
arg_reset();
parm_number = 0;
list(dollarsign);
expptr++;
est = est2;
est2 = NULL; // GWP - this may leak, but it avoids double-free crashes
est[FLOC].value = floc;
est[TEMPNUM].value = exp_number++;
est[MIF].param = ifptr;
est[REPNUM].value = 0;
est[MSTR].param = NULL;
floc = (yyvsp[-4].itemptr)->i_value;
mfseek(mfile, (long)floc, 0);
}
////#line 4617 "zmac.c" /* yacc.c:1646 */
break;
case 41:
////#line 2190 "zmac.y" /* yacc.c:1646 */
{
expr_reloc_check((yyvsp[-2].exprptr));
list1();
arg_reset();
}
////#line 4627 "zmac.c" /* yacc.c:1646 */
break;
case 42:
////#line 2195 "zmac.y" /* yacc.c:1646 */
{
int pos = mfptr;
mfseek(mfile, (long)mfptr, 0);
mlex((yyvsp[0].cval));
parm_number = 0;
// MRAS compat would require treating the repeat count
// as a byte value with 0 == 256.
if ((yyvsp[-4].exprptr)->e_value > 0) {
expptr++;
est = est2;
est2 = NULL;
est[FLOC].value = floc;
est[TEMPNUM].value = exp_number++;
est[MIF].param = ifptr;
est[REPNUM].value = (yyvsp[-4].exprptr)->e_value - 1;
est[MSTART].value = pos;
est[MSTR].param = NULL;
floc = pos;
mfseek(mfile, (long)floc, 0);
}
}
////#line 4654 "zmac.c" /* yacc.c:1646 */
break;
case 43:
////#line 2218 "zmac.y" /* yacc.c:1646 */
{ parm_number = 0; }
////#line 4660 "zmac.c" /* yacc.c:1646 */
break;
case 44:
////#line 2219 "zmac.y" /* yacc.c:1646 */
{
list1();
}
////#line 4668 "zmac.c" /* yacc.c:1646 */
break;
case 45:
////#line 2222 "zmac.y" /* yacc.c:1646 */
{
int pos = mfptr;
mfseek(mfile, (long)mfptr, 0);
mlex((yyvsp[0].cval));
parm_number = 0;
if (est2[0].param[0]) {
expptr++;
est = est2;
est2 = NULL;
est[FLOC].value = floc;
est[TEMPNUM].value = exp_number++;
est[MIF].param = ifptr;
est[REPNUM].value = 0;
est[MSTART].value = pos;
est[MSTR].param = est[0].param;
est[0].param = malloc(2);
est[0].param[0] = est[MSTR].param[0];
est[0].param[1] = '\0';
floc = pos;
mfseek(mfile, (long)floc, 0);
}
}
////#line 4698 "zmac.c" /* yacc.c:1646 */
break;
case 46:
////#line 2248 "zmac.y" /* yacc.c:1646 */
{ parm_number = 0; }
////#line 4704 "zmac.c" /* yacc.c:1646 */
break;
case 47:
////#line 2249 "zmac.y" /* yacc.c:1646 */
{
list1();
}
////#line 4712 "zmac.c" /* yacc.c:1646 */
break;
case 48:
////#line 2252 "zmac.y" /* yacc.c:1646 */
{
int pos = mfptr;
mfseek(mfile, (long)mfptr, 0);
mlex((yyvsp[0].cval));
parm_number = 0;
// if the sub list is not empty
if (est2[0].param[0] && est2[0].param[0] != ';'
&& est2[0].param[0] != '\n')
{
expptr++;
est = est2;
est2 = NULL;
est[FLOC].value = floc;
est[TEMPNUM].value = exp_number++;
est[MIF].param = ifptr;
est[REPNUM].value = -1;
est[MSTART].value = pos;
est[MSTR].param = NULL;
est[MARGP].ap = malloc(sizeof *est[MARGP].ap);
est[MARGP].ap->arg = malloc(TEMPBUFSIZE);
est[MARGP].ap->argsize = TEMPBUFSIZE;
est[MARGP].ap->getch = str_getch;
est[MARGP].ap->user_ptr = est[0].param;
est[MARGP].ap->user_int = 0;
est[MARGP].ap->user_peek = -1;
est[MARGP].ap->peek = &est[MARGP].ap->user_peek;
est[MARGP].ap->macarg = 0;
est[MARGP].ap->didarg = 0;
est[MARGP].ap->numarg = 0;
est[0].param = est[MARGP].ap->arg;
getarg(est[MARGP].ap);
floc = pos;
mfseek(mfile, (long)floc, 0);
}
}
////#line 4756 "zmac.c" /* yacc.c:1646 */
break;
case 49:
////#line 2292 "zmac.y" /* yacc.c:1646 */
{
// XXX - popsi() is not safe, There is type-specific cleanup.
// But for now...
// popsi() must be made safe as others use it.
list1();
popsi();
}
////#line 4768 "zmac.c" /* yacc.c:1646 */
break;
case 50:
////#line 2300 "zmac.y" /* yacc.c:1646 */
{
err[fflag]++;
arg_reset();
parm_number = 0;
param_parse = 0;
if (est2)
{
int i;
for (i=0; i<PARMMAX; i++) {
if (est2[i].param) {
#ifdef M_DEBUG
fprintf (stderr, "[Freeing2 arg%u(%p)]\n", i, est2[i].param),
#endif
free(est2[i].param);
}
}
free(est2);
est2 = NULL;
}
while(yychar != '\n' && yychar != '\0') yychar = yylex();
list(dollarsign);
yyclearin;yyerrok;
}
////#line 4798 "zmac.c" /* yacc.c:1646 */
break;
case 51:
////#line 2328 "zmac.y" /* yacc.c:1646 */
{ (yyval.ival) = 0; }
////#line 4804 "zmac.c" /* yacc.c:1646 */
break;
case 52:
////#line 2330 "zmac.y" /* yacc.c:1646 */
{ (yyval.ival) = 1; }
////#line 4810 "zmac.c" /* yacc.c:1646 */
break;
case 53:
////#line 2332 "zmac.y" /* yacc.c:1646 */
{ (yyval.ival) = 2; }
////#line 4816 "zmac.c" /* yacc.c:1646 */
break;
case 54:
////#line 2337 "zmac.y" /* yacc.c:1646 */
{ label = (yyval.itemptr) = NULL; }
////#line 4822 "zmac.c" /* yacc.c:1646 */
break;
case 55:
////#line 2339 "zmac.y" /* yacc.c:1646 */
{
coloncnt = (yyvsp[0].ival);
itemcpy(&pristine_label, (yyvsp[-1].itemptr));
label = coloncnt == 0 ? (yyvsp[-1].itemptr) : NULL;
(yyvsp[-1].itemptr)->i_scope |= segment;
if ((yyvsp[0].ival) == 2)
(yyvsp[-1].itemptr)->i_scope |= SCOPE_PUBLIC;
if ((yyvsp[-1].itemptr)->i_string[0] != '.')
llseq++;
switch((yyvsp[-1].itemptr)->i_token) {
case UNDECLARED:
if (pass2) {
sprintf(detail, "%s error - label '%s' not declared",
errname[pflag], (yyvsp[-1].itemptr)->i_string);
errwarn(pflag, detail);
}
else {
(yyvsp[-1].itemptr)->i_token = LABEL;
(yyvsp[-1].itemptr)->i_value = dollarsign;
}
break;
case LABEL:
if (!pass2) {
(yyvsp[-1].itemptr)->i_token = MULTDEF;
err[mflag]++;
} else if ((yyvsp[-1].itemptr)->i_value != dollarsign) {
// XXX - perhaps only allow retrys if JR promotions are in play?
if (outpass) {
if (!passfail) {
sprintf(detail, "%s error - label '%s' changed from $%04x to $%04x",
errname[pflag], (yyvsp[-1].itemptr)->i_string, (yyvsp[-1].itemptr)->i_value, dollarsign);
errwarn(pflag, detail);
}
}
else {
(yyvsp[-1].itemptr)->i_value = dollarsign;
passretry = 1;
}
}
break;
default:
err[mflag]++;
(yyvsp[-1].itemptr)->i_token = MULTDEF;
}
}
////#line 4874 "zmac.c" /* yacc.c:1646 */
break;
case 58:
////#line 2395 "zmac.y" /* yacc.c:1646 */
{
(yyvsp[0].itemptr)->i_scope |= SCOPE_PUBLIC;
if (pass2) {
if ((yyvsp[0].itemptr)->i_token == UNDECLARED) {
sprintf(detail, "'%s' %s", (yyvsp[0].itemptr)->i_string, errname[uflag]);
errwarn(uflag, detail);
}
}
}
////#line 4888 "zmac.c" /* yacc.c:1646 */
break;
case 61:
////#line 2413 "zmac.y" /* yacc.c:1646 */
{
if (pass2 && (yyvsp[0].itemptr)->i_scope != SCOPE_NONE && !((yyvsp[0].itemptr)->i_scope & SCOPE_EXTERNAL)) {
fprintf(stderr, "Label scope change\n");
err[fflag]++;
}
(yyvsp[0].itemptr)->i_scope |= SCOPE_EXTERNAL;
if (pass2) {
if ((yyvsp[0].itemptr)->i_token != UNDECLARED) {
fprintf(stderr, "External label defined locally.\n");
err[fflag]++;
}
}
}
////#line 4906 "zmac.c" /* yacc.c:1646 */
break;
case 62:
////#line 2430 "zmac.y" /* yacc.c:1646 */
{ emit1((yyvsp[0].itemptr)->i_value, 0, 0, ET_NOARG); }
////#line 4912 "zmac.c" /* yacc.c:1646 */
break;
case 63:
////#line 2433 "zmac.y" /* yacc.c:1646 */
{
// XXX - maybe splitting out CPI is better?
if (!z80 && (yyvsp[-1].itemptr)->i_value == 0166641)
emit1(0376, 0, (yyvsp[0].exprptr), ET_BYTE);
else
err[fflag]++;
}
////#line 4924 "zmac.c" /* yacc.c:1646 */
break;
case 64:
////#line 2442 "zmac.y" /* yacc.c:1646 */
{
if (!z80 && (yyvsp[0].itemptr)->i_value < 2)
emit(1, E_CODE, 0, 007 | ((yyvsp[0].itemptr)->i_value << 3));
else
err[fflag]++;
}
////#line 4935 "zmac.c" /* yacc.c:1646 */
break;
case 65:
////#line 2450 "zmac.y" /* yacc.c:1646 */
{
if (z80 || (yyvsp[-1].itemptr)->i_value == 0303) {
checkjp(0, (yyvsp[0].exprptr));
emit(1, E_CODE16, (yyvsp[0].exprptr), 0303);
}
else
// can't optimize jump on plus
emit(1, E_CODE16, (yyvsp[0].exprptr), 0362);
}
////#line 4949 "zmac.c" /* yacc.c:1646 */
break;
case 66:
////#line 2461 "zmac.y" /* yacc.c:1646 */
{ emit(1, E_CODE16, (yyvsp[0].exprptr), 0315); }
////#line 4955 "zmac.c" /* yacc.c:1646 */
break;
case 67:
////#line 2464 "zmac.y" /* yacc.c:1646 */
{
// accepts rst 0-7 or rst 0,8,16,...,56
int vec = (yyvsp[0].exprptr)->e_value;
expr_number_check((yyvsp[0].exprptr));
if ((vec > 7 || vec < 0) && (vec & ~(7 << 3)))
err[vflag]++;
if (vec > 7) vec >>= 3;
emit(1, E_CODE, 0, (yyvsp[-1].itemptr)->i_value + ((vec & 7) << 3));
expr_free((yyvsp[0].exprptr));
}
////#line 4970 "zmac.c" /* yacc.c:1646 */
break;
case 68:
////#line 2476 "zmac.y" /* yacc.c:1646 */
{ emit1((yyvsp[-1].itemptr)->i_value, 0, (yyvsp[0].exprptr), ET_BYTE); }
////#line 4976 "zmac.c" /* yacc.c:1646 */
break;
case 69:
////#line 2479 "zmac.y" /* yacc.c:1646 */
{
emit(3, E_CODE, 0, (yyvsp[-1].itemptr)->i_value >> 8, (yyvsp[-1].itemptr)->i_value, disp);
}
////#line 4984 "zmac.c" /* yacc.c:1646 */
break;
case 70:
////#line 2484 "zmac.y" /* yacc.c:1646 */
{ emit1(0306, 0, (yyvsp[0].exprptr), ET_BYTE); }
////#line 4990 "zmac.c" /* yacc.c:1646 */
break;
case 71:
////#line 2487 "zmac.y" /* yacc.c:1646 */
{ emit1(0306, 0, (yyvsp[0].exprptr), ET_BYTE); }
////#line 4996 "zmac.c" /* yacc.c:1646 */
break;
case 72:
////#line 2490 "zmac.y" /* yacc.c:1646 */
{ emit1(0306 + ((yyvsp[-1].itemptr)->i_value << 3), 0, (yyvsp[0].exprptr), ET_BYTE); }
////#line 5002 "zmac.c" /* yacc.c:1646 */
break;
case 73:
////#line 2493 "zmac.y" /* yacc.c:1646 */
{ emit1(0306 + ((yyvsp[-3].itemptr)->i_value << 3), 0, (yyvsp[0].exprptr), ET_BYTE); }
////#line 5008 "zmac.c" /* yacc.c:1646 */
break;
case 74:
////#line 2496 "zmac.y" /* yacc.c:1646 */
{
if (!z80 && (yyvsp[-1].itemptr)->i_value == 7)
emit(1, E_CODE16, (yyvsp[0].exprptr), 0364);
else
emit1(0306 | ((yyvsp[-1].itemptr)->i_value << 3), 0, (yyvsp[0].exprptr), ET_BYTE);
}
////#line 5019 "zmac.c" /* yacc.c:1646 */
break;
case 75:
////#line 2504 "zmac.y" /* yacc.c:1646 */
{ emit1(0306 | ((yyvsp[-1].itemptr)->i_value << 3), 0, (yyvsp[0].exprptr), ET_BYTE); }
////#line 5025 "zmac.c" /* yacc.c:1646 */
break;
case 76:
////#line 2507 "zmac.y" /* yacc.c:1646 */
{ emit1(0306 | ((yyvsp[-1].itemptr)->i_value << 3), 0, (yyvsp[0].exprptr), ET_BYTE); }
////#line 5031 "zmac.c" /* yacc.c:1646 */
break;
case 77:
////#line 2510 "zmac.y" /* yacc.c:1646 */
{ emit1(0306 | ((yyvsp[-1].itemptr)->i_value << 3), 0, (yyvsp[0].exprptr), ET_BYTE); }
////#line 5037 "zmac.c" /* yacc.c:1646 */
break;
case 78:
////#line 2513 "zmac.y" /* yacc.c:1646 */
{ emit1(0306 | ((yyvsp[-3].itemptr)->i_value << 3), 0, (yyvsp[0].exprptr), ET_BYTE); }
////#line 5043 "zmac.c" /* yacc.c:1646 */
break;
case 79:
////#line 2516 "zmac.y" /* yacc.c:1646 */
{ emit1(0306 | ((yyvsp[-3].itemptr)->i_value << 3), 0, (yyvsp[0].exprptr), ET_BYTE); }
////#line 5049 "zmac.c" /* yacc.c:1646 */
break;
case 80:
////#line 2519 "zmac.y" /* yacc.c:1646 */
{ emit1(0306 | ((yyvsp[-3].itemptr)->i_value << 3), 0, (yyvsp[0].exprptr), ET_BYTE); }
////#line 5055 "zmac.c" /* yacc.c:1646 */
break;
case 81:
////#line 2522 "zmac.y" /* yacc.c:1646 */
{ emit1(0306 | ((yyvsp[-3].itemptr)->i_value << 3), 0, (yyvsp[0].exprptr), ET_BYTE); }
////#line 5061 "zmac.c" /* yacc.c:1646 */
break;
case 82:
////#line 2525 "zmac.y" /* yacc.c:1646 */
{ emit1(0200 + ((yyvsp[0].ival) & 0377), (yyvsp[0].ival), 0, ET_NOARG_DISP); }
////#line 5067 "zmac.c" /* yacc.c:1646 */
break;
case 83:
////#line 2528 "zmac.y" /* yacc.c:1646 */
{ emit1(0200 + ((yyvsp[0].ival) & 0377), (yyvsp[0].ival), 0, ET_NOARG_DISP); }
////#line 5073 "zmac.c" /* yacc.c:1646 */
break;
case 84:
////#line 2531 "zmac.y" /* yacc.c:1646 */
{ emit(1, E_CODE, 0, 0206); }
////#line 5079 "zmac.c" /* yacc.c:1646 */
break;
case 85:
////#line 2534 "zmac.y" /* yacc.c:1646 */
{ emit1(0200 + ((yyvsp[-1].itemptr)->i_value << 3) + ((yyvsp[0].ival) & 0377), (yyvsp[0].ival), 0, ET_NOARG_DISP); }
////#line 5085 "zmac.c" /* yacc.c:1646 */
break;
case 86:
////#line 2537 "zmac.y" /* yacc.c:1646 */
{ emit1(0200 + ((yyvsp[-3].itemptr)->i_value << 3) + ((yyvsp[0].ival) & 0377), (yyvsp[0].ival), 0, ET_NOARG_DISP); }
////#line 5091 "zmac.c" /* yacc.c:1646 */
break;
case 87:
////#line 2540 "zmac.y" /* yacc.c:1646 */
{ emit1(0200 + ((yyvsp[-1].itemptr)->i_value << 3) + ((yyvsp[0].ival) & 0377), (yyvsp[0].ival), 0, ET_NOARG_DISP); }
////#line 5097 "zmac.c" /* yacc.c:1646 */
break;
case 88:
////#line 2543 "zmac.y" /* yacc.c:1646 */
{ emit1(0200 + ((yyvsp[-1].itemptr)->i_value << 3) + ((yyvsp[0].ival) & 0377), (yyvsp[0].ival), 0, ET_NOARG_DISP); }
////#line 5103 "zmac.c" /* yacc.c:1646 */
break;
case 89:
////#line 2546 "zmac.y" /* yacc.c:1646 */
{ emit1(0200 + ((yyvsp[-1].itemptr)->i_value << 3) + ((yyvsp[0].ival) & 0377), (yyvsp[0].ival), 0, ET_NOARG_DISP); }
////#line 5109 "zmac.c" /* yacc.c:1646 */
break;
case 90:
////#line 2549 "zmac.y" /* yacc.c:1646 */
{ emit1(0200 + ((yyvsp[-1].itemptr)->i_value << 3) + ((yyvsp[0].ival) & 0377), (yyvsp[0].ival), 0, ET_NOARG_DISP); }
////#line 5115 "zmac.c" /* yacc.c:1646 */
break;
case 91:
////#line 2552 "zmac.y" /* yacc.c:1646 */
{ emit1(0200 + ((yyvsp[-1].itemptr)->i_value << 3) + ((yyvsp[0].ival) & 0377), (yyvsp[0].ival), 0, ET_NOARG_DISP); }
////#line 5121 "zmac.c" /* yacc.c:1646 */
break;
case 92:
////#line 2555 "zmac.y" /* yacc.c:1646 */
{ emit1(0200 + ((yyvsp[-1].itemptr)->i_value << 3) + ((yyvsp[0].ival) & 0377), (yyvsp[0].ival), 0, ET_NOARG_DISP); }
////#line 5127 "zmac.c" /* yacc.c:1646 */
break;
case 93:
////#line 2558 "zmac.y" /* yacc.c:1646 */
{ emit1(0200 + ((yyvsp[-3].itemptr)->i_value << 3) + ((yyvsp[0].ival) & 0377), (yyvsp[0].ival), 0, ET_NOARG_DISP); }
////#line 5133 "zmac.c" /* yacc.c:1646 */
break;
case 94:
////#line 2561 "zmac.y" /* yacc.c:1646 */
{ emit1(0200 + ((yyvsp[-3].itemptr)->i_value << 3) + ((yyvsp[0].ival) & 0377), (yyvsp[0].ival), 0, ET_NOARG_DISP); }
////#line 5139 "zmac.c" /* yacc.c:1646 */
break;
case 95:
////#line 2564 "zmac.y" /* yacc.c:1646 */
{ emit1(0200 + ((yyvsp[-3].itemptr)->i_value << 3) + ((yyvsp[0].ival) & 0377), (yyvsp[0].ival), 0, ET_NOARG_DISP); }
////#line 5145 "zmac.c" /* yacc.c:1646 */
break;
case 96:
////#line 2567 "zmac.y" /* yacc.c:1646 */
{ emit1(0200 + ((yyvsp[-3].itemptr)->i_value << 3) + ((yyvsp[0].ival) & 0377), (yyvsp[0].ival), 0, ET_NOARG_DISP); }
////#line 5151 "zmac.c" /* yacc.c:1646 */
break;
case 97:
////#line 2570 "zmac.y" /* yacc.c:1646 */
{ emit1(0145400 + ((yyvsp[-1].itemptr)->i_value << 3) + ((yyvsp[0].ival) & 0377), (yyvsp[0].ival), 0, ET_NOARG_DISP); }
////#line 5157 "zmac.c" /* yacc.c:1646 */
break;
case 98:
////#line 2573 "zmac.y" /* yacc.c:1646 */
{
emit(4, E_CODE, 0, (yyvsp[-1].itemptr)->i_value >> 8, 0xcb, disp, (yyvsp[-1].itemptr)->i_value);
}
////#line 5165 "zmac.c" /* yacc.c:1646 */
break;
case 99:
////#line 2578 "zmac.y" /* yacc.c:1646 */
{ emit1(0xCB00 + ((yyvsp[-3].itemptr)->i_value << 3) + ((yyvsp[0].ival) & 0377), (yyvsp[-2].ival), 0, ET_NOARG_DISP); }
////#line 5171 "zmac.c" /* yacc.c:1646 */
break;
case 100:
////#line 2581 "zmac.y" /* yacc.c:1646 */
{ emit1((yyvsp[-1].itemptr)->i_value + (((yyvsp[0].ival) & 0377) << 3) + 4, (yyvsp[0].ival), 0, ET_NOARG_DISP); }
////#line 5177 "zmac.c" /* yacc.c:1646 */
break;
case 101:
////#line 2584 "zmac.y" /* yacc.c:1646 */
{ emit1((yyvsp[-1].itemptr)->i_value + (((yyvsp[0].ival) & 0377) << 3) + 4, (yyvsp[0].ival), 0, ET_NOARG_DISP); }
////#line 5183 "zmac.c" /* yacc.c:1646 */
break;
case 102:
////#line 2587 "zmac.y" /* yacc.c:1646 */
{ if ((yyvsp[-3].itemptr)->i_value == 1)
emit(2,E_CODE,0,0355,0112+(yyvsp[0].ival));
else
emit(2,E_CODE,0,0355,0102+(yyvsp[0].ival));
}
////#line 5193 "zmac.c" /* yacc.c:1646 */
break;
case 103:
////#line 2594 "zmac.y" /* yacc.c:1646 */
{ emitdad((yyvsp[-2].ival),(yyvsp[0].ival)); }
////#line 5199 "zmac.c" /* yacc.c:1646 */
break;
case 104:
////#line 2597 "zmac.y" /* yacc.c:1646 */
{
if ((yyvsp[-2].ival) != (yyvsp[0].ival)) {
fprintf(stderr,"ADD mar, mar error\n");
err[gflag]++;
}
emitdad((yyvsp[-2].ival),(yyvsp[0].ival));
}
////#line 5211 "zmac.c" /* yacc.c:1646 */
break;
case 105:
////#line 2605 "zmac.y" /* yacc.c:1646 */
{ emitdad(040, (yyvsp[0].ival)); }
////#line 5217 "zmac.c" /* yacc.c:1646 */
break;
case 106:
////#line 2608 "zmac.y" /* yacc.c:1646 */
{
emit(2, E_CODE, 0, (yyvsp[-1].itemptr)->i_value >> 8, (yyvsp[-1].itemptr)->i_value | (yyvsp[0].ival));
}
////#line 5225 "zmac.c" /* yacc.c:1646 */
break;
case 107:
////#line 2613 "zmac.y" /* yacc.c:1646 */
{
int dst = (yyvsp[-1].itemptr)->i_value >> 8;
int reg = (yyvsp[0].ival) >> 8;
if (!reg) reg = 0xed;
if (dst != reg) {
if (dst == 0xed)
fprintf(stderr, "dadc/dsbc cannot take ix or iy\n");
else if (dst == 0xdd)
fprintf(stderr, "dadx cannot take hl or iy\n");
else
fprintf(stderr, "dady cannot take hl or ix\n");
err[gflag]++;
}
emit(2, E_CODE, 0, (yyvsp[-1].itemptr)->i_value >> 8, (yyvsp[-1].itemptr)->i_value | (yyvsp[0].ival));
}
////#line 5246 "zmac.c" /* yacc.c:1646 */
break;
case 108:
////#line 2631 "zmac.y" /* yacc.c:1646 */
{ emit1(((yyvsp[-1].itemptr)->i_value << 3) + ((yyvsp[0].ival) & 0377) + 3, (yyvsp[0].ival), 0, ET_NOARG); }
////#line 5252 "zmac.c" /* yacc.c:1646 */
break;
case 109:
////#line 2634 "zmac.y" /* yacc.c:1646 */
{ emit1(((yyvsp[-1].itemptr)->i_value << 3) + ((yyvsp[0].ival) & 0377) + 3, (yyvsp[0].ival), 0, ET_NOARG); }
////#line 5258 "zmac.c" /* yacc.c:1646 */
break;
case 110:
////#line 2637 "zmac.y" /* yacc.c:1646 */
{ emit1((yyvsp[-1].itemptr)->i_value + ((yyvsp[0].ival) & 0377), (yyvsp[0].ival), 0, ET_NOARG); }
////#line 5264 "zmac.c" /* yacc.c:1646 */
break;
case 111:
////#line 2640 "zmac.y" /* yacc.c:1646 */
{ emit1((yyvsp[-1].itemptr)->i_value + ((yyvsp[0].ival) & 0377), (yyvsp[0].ival), 0, ET_NOARG); }
////#line 5270 "zmac.c" /* yacc.c:1646 */
break;
case 112:
////#line 2643 "zmac.y" /* yacc.c:1646 */
{
if (strcmp((yyvsp[-1].itemptr)->i_string, "set") == 0 && label) {
// Clear error that label definition will have been set
err[mflag] = 0;
itemcpy(label, &pristine_label);
do_defl(label, (yyvsp[0].exprptr), 0);
list_dollarsign = 0;
list_addr = label->i_value;
}
else {
err[fflag]++;
}
}
////#line 5288 "zmac.c" /* yacc.c:1646 */
break;
case 113:
////#line 2658 "zmac.y" /* yacc.c:1646 */
{
int bit = (yyvsp[-2].exprptr)->e_value;
expr_number_check((yyvsp[-2].exprptr));
expr_free((yyvsp[-2].exprptr));
if (bit < 0 || bit > 7)
err[vflag]++;
emit1((yyvsp[-3].itemptr)->i_value + ((bit & 7) << 3) + ((yyvsp[0].ival) & 0377), (yyvsp[0].ival), 0, ET_NOARG_DISP);
}
////#line 5301 "zmac.c" /* yacc.c:1646 */
break;
case 114:
////#line 2668 "zmac.y" /* yacc.c:1646 */
{
int bit = (yyvsp[-2].exprptr)->e_value;
expr_number_check((yyvsp[-2].exprptr));
expr_free((yyvsp[-2].exprptr));
if (bit < 0 || bit > 7)
err[vflag]++;
emit(4, E_CODE, 0, (yyvsp[-3].itemptr)->i_value >> 8, 0xcb, disp,
(yyvsp[-3].itemptr)->i_value | (bit << 3));
}
////#line 5315 "zmac.c" /* yacc.c:1646 */
break;
case 115:
////#line 2679 "zmac.y" /* yacc.c:1646 */
{
int bit = (yyvsp[-4].exprptr)->e_value;
expr_number_check((yyvsp[-4].exprptr));
expr_free((yyvsp[-4].exprptr));
if (bit < 0 || bit > 7)
err[vflag]++;
emit1((yyvsp[-5].itemptr)->i_value + ((bit & 7) << 3) + ((yyvsp[0].ival) & 0377), (yyvsp[-2].ival), 0, ET_NOARG_DISP);
}
////#line 5328 "zmac.c" /* yacc.c:1646 */
break;
case 116:
////#line 2689 "zmac.y" /* yacc.c:1646 */
{
checkjp((yyvsp[-2].ival), (yyvsp[0].exprptr));
emit(1, E_CODE16, (yyvsp[0].exprptr), 0302 + (yyvsp[-2].ival));
}
////#line 5337 "zmac.c" /* yacc.c:1646 */
break;
case 117:
////#line 2695 "zmac.y" /* yacc.c:1646 */
{
checkjp((yyvsp[-1].itemptr)->i_value, (yyvsp[0].exprptr));
emit(1, E_CODE16, (yyvsp[0].exprptr), (yyvsp[-1].itemptr)->i_value);
}
////#line 5346 "zmac.c" /* yacc.c:1646 */
break;
case 118:
////#line 2701 "zmac.y" /* yacc.c:1646 */
{ emit1(0351, (yyvsp[-1].ival), 0, ET_NOARG); }
////#line 5352 "zmac.c" /* yacc.c:1646 */
break;
case 119:
////#line 2704 "zmac.y" /* yacc.c:1646 */
{ emit(1, E_CODE16, (yyvsp[0].exprptr), 0304 + (yyvsp[-2].ival)); }
////#line 5358 "zmac.c" /* yacc.c:1646 */
break;
case 120:
////#line 2707 "zmac.y" /* yacc.c:1646 */
{ emit(1, E_CODE16, (yyvsp[0].exprptr), (yyvsp[-1].itemptr)->i_value); }
////#line 5364 "zmac.c" /* yacc.c:1646 */
break;
case 121:
////#line 2710 "zmac.y" /* yacc.c:1646 */
{ emitjr(030,(yyvsp[0].exprptr)); }
////#line 5370 "zmac.c" /* yacc.c:1646 */
break;
case 122:
////#line 2713 "zmac.y" /* yacc.c:1646 */
{ emitjr((yyvsp[-3].itemptr)->i_value + (yyvsp[-2].ival), (yyvsp[0].exprptr)); }
////#line 5376 "zmac.c" /* yacc.c:1646 */
break;
case 123:
////#line 2716 "zmac.y" /* yacc.c:1646 */
{ emitjr((yyvsp[-1].itemptr)->i_value, (yyvsp[0].exprptr)); }
////#line 5382 "zmac.c" /* yacc.c:1646 */
break;
case 124:
////#line 2719 "zmac.y" /* yacc.c:1646 */
{ emitjr((yyvsp[-1].itemptr)->i_value, (yyvsp[0].exprptr)); }
////#line 5388 "zmac.c" /* yacc.c:1646 */
break;
case 125:
////#line 2722 "zmac.y" /* yacc.c:1646 */
{ emit(1, E_CODE, 0, (yyvsp[0].itemptr)->i_value); }
////#line 5394 "zmac.c" /* yacc.c:1646 */
break;
case 126:
////#line 2725 "zmac.y" /* yacc.c:1646 */
{ emit(1, E_CODE, 0, 0300 + (yyvsp[0].ival)); }
////#line 5400 "zmac.c" /* yacc.c:1646 */
break;
case 127:
////#line 2728 "zmac.y" /* yacc.c:1646 */
{
// Many constraints on byte access to IX/IY registers.
if (((yyvsp[-2].ival) | (yyvsp[0].ival)) >> 16) {
int a = (yyvsp[-2].ival);
int b = (yyvsp[0].ival);
// Only ixh,ixh; ixh,ixl; ixl,ixh; ixl,ixl allowed.
if (a >> 16 && b >> 16) {
if (a >> 8 != b >> 8) {
fprintf(stderr, "LD cannot move between ix and iy\n");
err[gflag]++;
}
}
else {
int c = b >> 16 ? a : b;
// No access to h, l, (hl), (ix), (iy)
if (c == 4 || c == 5 || (c & 0xff) == 6) {
fprintf(stderr, "LD cannot combine i/xy/lh and h,l,(hl),(ix) or (iy).\n");
err[gflag]++;
}
}
}
if (((yyvsp[-2].ival) & 0377) == 6 && ((yyvsp[0].ival) & 0377) == 6) {
fprintf(stderr,"LD reg, reg error: can't do memory to memory\n");
err[gflag]++;
}
emit1(0100 + (((yyvsp[-2].ival) & 7) << 3) + ((yyvsp[0].ival) & 7),(yyvsp[-2].ival) | (yyvsp[0].ival), 0, ET_NOARG_DISP);
}
////#line 5434 "zmac.c" /* yacc.c:1646 */
break;
case 128:
////#line 2759 "zmac.y" /* yacc.c:1646 */
{
emit(3, E_CODE, 0, (yyvsp[-3].itemptr)->i_value >> 8, (yyvsp[-3].itemptr)->i_value | ((yyvsp[-2].ival) << 3), disp);
}
////#line 5442 "zmac.c" /* yacc.c:1646 */
break;
case 129:
////#line 2764 "zmac.y" /* yacc.c:1646 */
{
emit(3, E_CODE, 0, (yyvsp[-3].itemptr)->i_value >> 8, (yyvsp[-3].itemptr)->i_value | (yyvsp[-2].ival), disp);
}
////#line 5450 "zmac.c" /* yacc.c:1646 */
break;
case 130:
////#line 2769 "zmac.y" /* yacc.c:1646 */
{
if ((yyvsp[-2].ival) == 6 && (yyvsp[0].ival) == 6) err[gflag]++;
emit1(0100 + (((yyvsp[-2].ival) & 7) << 3) + ((yyvsp[0].ival) & 7),(yyvsp[-2].ival) | (yyvsp[0].ival), 0, ET_NOARG_DISP);
}
////#line 5459 "zmac.c" /* yacc.c:1646 */
break;
case 131:
////#line 2775 "zmac.y" /* yacc.c:1646 */
{ emit1(6 + (((yyvsp[-2].ival) & 0377) << 3), (yyvsp[-2].ival), (yyvsp[0].exprptr), ET_BYTE); }
////#line 5465 "zmac.c" /* yacc.c:1646 */
break;
case 132:
////#line 2778 "zmac.y" /* yacc.c:1646 */
{
emit(3, E_CODE8, (yyvsp[-2].exprptr), (yyvsp[-3].itemptr)->i_value >> 8, (yyvsp[-3].itemptr)->i_value, disp);
}
////#line 5473 "zmac.c" /* yacc.c:1646 */
break;
case 133:
////#line 2783 "zmac.y" /* yacc.c:1646 */
{ emit1(6 + (((yyvsp[-2].ival) & 0377) << 3), (yyvsp[-2].ival), (yyvsp[0].exprptr), ET_BYTE); }
////#line 5479 "zmac.c" /* yacc.c:1646 */
break;
case 134:
////#line 2786 "zmac.y" /* yacc.c:1646 */
{ if ((yyvsp[-4].ival) != 7) {
fprintf(stderr,"LD reg, (RP) error\n");
err[gflag]++;
}
else emit(1, E_CODE, 0, 012 + (yyvsp[-1].itemptr)->i_value);
}
////#line 5490 "zmac.c" /* yacc.c:1646 */
break;
case 135:
////#line 2794 "zmac.y" /* yacc.c:1646 */
{
if ((yyvsp[0].ival) != 0 && (yyvsp[0].ival) != 2) err[gflag]++;
emit(1, E_CODE, 0, 012 + ((yyvsp[0].ival) << 3));
}
////#line 5499 "zmac.c" /* yacc.c:1646 */
break;
case 136:
////#line 2800 "zmac.y" /* yacc.c:1646 */
{
if ((yyvsp[-2].ival) != 7) {
fprintf(stderr,"LD reg, (expr) error: A only valid destination\n");
err[gflag]++;
}
else {
expr_word_check((yyvsp[0].exprptr));
emit(1, E_CODE16, (yyvsp[0].exprptr), 072);
}
}
////#line 5514 "zmac.c" /* yacc.c:1646 */
break;
case 137:
////#line 2812 "zmac.y" /* yacc.c:1646 */
{
expr_word_check((yyvsp[0].exprptr));
emit(1, E_CODE16, (yyvsp[0].exprptr), 072);
}
////#line 5523 "zmac.c" /* yacc.c:1646 */
break;
case 138:
////#line 2818 "zmac.y" /* yacc.c:1646 */
{ emit(1, E_CODE, 0, 2 + (yyvsp[-3].itemptr)->i_value); }
////#line 5529 "zmac.c" /* yacc.c:1646 */
break;
case 139:
////#line 2821 "zmac.y" /* yacc.c:1646 */
{
if ((yyvsp[0].ival) != 0 && (yyvsp[0].ival) != 2) err[gflag]++;
emit(1, E_CODE, 0, 2 + ((yyvsp[0].ival) << 3));
}
////#line 5538 "zmac.c" /* yacc.c:1646 */
break;
case 140:
////#line 2827 "zmac.y" /* yacc.c:1646 */
{
expr_word_check((yyvsp[-2].exprptr));
emit(1, E_CODE16, (yyvsp[-2].exprptr), 062);
}
////#line 5547 "zmac.c" /* yacc.c:1646 */
break;
case 141:
////#line 2833 "zmac.y" /* yacc.c:1646 */
{
expr_word_check((yyvsp[0].exprptr));
emit(1, E_CODE16, (yyvsp[0].exprptr), 062);
}
////#line 5556 "zmac.c" /* yacc.c:1646 */
break;
case 142:
////#line 2839 "zmac.y" /* yacc.c:1646 */
{
if ((yyvsp[-2].ival) != 7) {
fprintf(stderr,"LD reg, MISCREG error: A only valid destination\n");
err[gflag]++;
}
else emit(2, E_CODE, 0, 0355, 0127 + (yyvsp[0].itemptr)->i_value);
}
////#line 5568 "zmac.c" /* yacc.c:1646 */
break;
case 143:
////#line 2848 "zmac.y" /* yacc.c:1646 */
{ emit(2, E_CODE, 0, 0355, 0107 + (yyvsp[-2].itemptr)->i_value); }
////#line 5574 "zmac.c" /* yacc.c:1646 */
break;
case 144:
////#line 2851 "zmac.y" /* yacc.c:1646 */
{
expr_word_check((yyvsp[0].exprptr));
emit1(1 + ((yyvsp[-2].ival) & 060), (yyvsp[-2].ival), (yyvsp[0].exprptr), ET_WORD);
}
////#line 5583 "zmac.c" /* yacc.c:1646 */
break;
case 145:
////#line 2857 "zmac.y" /* yacc.c:1646 */
{
expr_word_check((yyvsp[0].exprptr));
emit1(1 + ((yyvsp[-2].ival) & 060), (yyvsp[-2].ival), (yyvsp[0].exprptr), ET_WORD);
}
////#line 5592 "zmac.c" /* yacc.c:1646 */
break;
case 146:
////#line 2863 "zmac.y" /* yacc.c:1646 */
{
expr_word_check((yyvsp[0].exprptr));
if (((yyvsp[-2].ival) & 060) == 040)
emit1(052, (yyvsp[-2].ival), (yyvsp[0].exprptr), ET_WORD);
else
emit(2, E_CODE16, (yyvsp[0].exprptr), 0355, 0113 + (yyvsp[-2].ival));
}
////#line 5604 "zmac.c" /* yacc.c:1646 */
break;
case 147:
////#line 2872 "zmac.y" /* yacc.c:1646 */
{
expr_word_check((yyvsp[0].exprptr));
emit1(052, 040, (yyvsp[0].exprptr), ET_WORD);
}
////#line 5613 "zmac.c" /* yacc.c:1646 */
break;
case 148:
////#line 2878 "zmac.y" /* yacc.c:1646 */
{
expr_word_check((yyvsp[-2].exprptr));
if (((yyvsp[0].ival) & 060) == 040)
emit1(042, (yyvsp[0].ival), (yyvsp[-2].exprptr), ET_WORD);
else
emit(2, E_CODE16, (yyvsp[-2].exprptr), 0355, 0103 + (yyvsp[0].ival));
}
////#line 5625 "zmac.c" /* yacc.c:1646 */
break;
case 149:
////#line 2887 "zmac.y" /* yacc.c:1646 */
{
expr_word_check((yyvsp[0].exprptr));
emit1(042, 040, (yyvsp[0].exprptr), ET_WORD);
}
////#line 5634 "zmac.c" /* yacc.c:1646 */
break;
case 150:
////#line 2893 "zmac.y" /* yacc.c:1646 */
{
if ((yyvsp[-2].ival) != 060) {
fprintf(stderr,"LD evenreg error\n");
err[gflag]++;
}
else
emit1(0371, (yyvsp[0].ival), 0, ET_NOARG);
}
////#line 5647 "zmac.c" /* yacc.c:1646 */
break;
case 151:
////#line 2903 "zmac.y" /* yacc.c:1646 */
{
expr_word_check((yyvsp[0].exprptr));
emit(2, E_CODE16, (yyvsp[0].exprptr), (yyvsp[-1].itemptr)->i_value >> 8, (yyvsp[-1].itemptr)->i_value);
}
////#line 5656 "zmac.c" /* yacc.c:1646 */
break;
case 152:
////#line 2909 "zmac.y" /* yacc.c:1646 */
{
if ((yyvsp[-2].itemptr)->i_value != 020) {
fprintf(stderr,"EX RP, HL error\n");
err[gflag]++;
}
else
emit(1, E_CODE, 0, 0353);
}
////#line 5669 "zmac.c" /* yacc.c:1646 */
break;
case 153:
////#line 2919 "zmac.y" /* yacc.c:1646 */
{ emit(1, E_CODE, 0, 010); }
////#line 5675 "zmac.c" /* yacc.c:1646 */
break;
case 154:
////#line 2922 "zmac.y" /* yacc.c:1646 */
{ emit1(0343, (yyvsp[0].ival), 0, ET_NOARG); }
////#line 5681 "zmac.c" /* yacc.c:1646 */
break;
case 155:
////#line 2925 "zmac.y" /* yacc.c:1646 */
{
if ((yyvsp[-2].ival) != 7) {
fprintf(stderr,"IN reg, (expr) error\n");
err[gflag]++;
}
else {
if ((yyvsp[0].exprptr)->e_value < 0 || (yyvsp[0].exprptr)->e_value > 255)
err[vflag]++;
emit(1, E_CODE8, (yyvsp[0].exprptr), (yyvsp[-3].itemptr)->i_value);
}
}
////#line 5697 "zmac.c" /* yacc.c:1646 */
break;
case 156:
////#line 2938 "zmac.y" /* yacc.c:1646 */
{
if ((yyvsp[0].exprptr)->e_value < 0 || (yyvsp[0].exprptr)->e_value > 255)
err[vflag]++;
emit(1, E_CODE8, (yyvsp[0].exprptr), (yyvsp[-1].itemptr)->i_value);
}
////#line 5707 "zmac.c" /* yacc.c:1646 */
break;
case 157:
////#line 2945 "zmac.y" /* yacc.c:1646 */
{ emit(2, E_CODE, 0, 0355, 0100 + ((yyvsp[-4].ival) << 3)); }
////#line 5713 "zmac.c" /* yacc.c:1646 */
break;
case 158:
////#line 2948 "zmac.y" /* yacc.c:1646 */
{ emit(2, E_CODE, 0, 0355, 0101 + ((yyvsp[0].ival) << 3)); }
////#line 5719 "zmac.c" /* yacc.c:1646 */
break;
case 159:
////#line 2951 "zmac.y" /* yacc.c:1646 */
{ emit(2, E_CODE, 0, 0355, 0160); }
////#line 5725 "zmac.c" /* yacc.c:1646 */
break;
case 160:
////#line 2954 "zmac.y" /* yacc.c:1646 */
{ emit(2, E_CODE, 0, 0355, 0160); }
////#line 5731 "zmac.c" /* yacc.c:1646 */
break;
case 161:
////#line 2957 "zmac.y" /* yacc.c:1646 */
{
if ((yyvsp[-2].exprptr)->e_value < 0 || (yyvsp[-2].exprptr)->e_value > 255)
err[vflag]++;
emit(1, E_CODE8, (yyvsp[-2].exprptr), (yyvsp[-3].itemptr)->i_value);
}
////#line 5741 "zmac.c" /* yacc.c:1646 */
break;
case 162:
////#line 2964 "zmac.y" /* yacc.c:1646 */
{
if ((yyvsp[0].exprptr)->e_value < 0 || (yyvsp[0].exprptr)->e_value > 255)
err[vflag]++;
emit(1, E_CODE8, (yyvsp[0].exprptr), (yyvsp[-1].itemptr)->i_value);
}
////#line 5751 "zmac.c" /* yacc.c:1646 */
break;
case 163:
////#line 2971 "zmac.y" /* yacc.c:1646 */
{ emit(2, E_CODE, 0, 0355, 0101 + ((yyvsp[0].ival) << 3)); }
////#line 5757 "zmac.c" /* yacc.c:1646 */
break;
case 164:
////#line 2974 "zmac.y" /* yacc.c:1646 */
{ emit(2, E_CODE, 0, 0355, 0101 + ((yyvsp[0].ival) << 3)); }
////#line 5763 "zmac.c" /* yacc.c:1646 */
break;
case 165:
////#line 2977 "zmac.y" /* yacc.c:1646 */
{
expr_number_check((yyvsp[0].exprptr));
if ((yyvsp[0].exprptr)->e_value != 0) {
fprintf(stderr, "Can only output 0 to port C with OUT\n");
err[vflag]++;
}
expr_free((yyvsp[0].exprptr));
emit(2, E_CODE8, 0, 0355, 0101 + (6 << 3));
}
////#line 5778 "zmac.c" /* yacc.c:1646 */
break;
case 166:
////#line 2989 "zmac.y" /* yacc.c:1646 */
{
int im = (yyvsp[0].exprptr)->e_value;
expr_number_check((yyvsp[0].exprptr));
expr_free((yyvsp[0].exprptr));
if (im > 2 || im < 0)
err[vflag]++;
else
emit(2, E_CODE, 0, (yyvsp[-1].itemptr)->i_value >> 8, (yyvsp[-1].itemptr)->i_value + ((im + (im > 0)) << 3));
}
////#line 5792 "zmac.c" /* yacc.c:1646 */
break;
case 167:
////#line 3000 "zmac.y" /* yacc.c:1646 */
{
expr_number_check((yyvsp[0].exprptr));
if (phaseflag) {
err[oflag]++;
} else {
phaseflag = 1;
phdollar = dollarsign;
dollarsign = (yyvsp[0].exprptr)->e_value;
phbegin = dollarsign;
}
expr_free((yyvsp[0].exprptr));
}
////#line 5809 "zmac.c" /* yacc.c:1646 */
break;
case 168:
////#line 3014 "zmac.y" /* yacc.c:1646 */
{
if (!phaseflag) {
err[oflag]++;
} else {
phaseflag = 0;
dollarsign = phdollar + dollarsign - phbegin;
}
}
////#line 5822 "zmac.c" /* yacc.c:1646 */
break;
case 169:
////#line 3024 "zmac.y" /* yacc.c:1646 */
{
expr_reloc_check((yyvsp[0].exprptr));
// Cannot org to the other segment (but absolute values are OK)
if (relopt && segment && ((yyvsp[0].exprptr)->e_scope & SCOPE_SEGMASK) != segment)
err[rflag]++;
if (phaseflag) {
err[oflag]++;
dollarsign = phdollar + dollarsign - phbegin;
phaseflag = 0;
}
if ((yyvsp[0].exprptr)->e_value-dollarsign) {
flushbin();
flushoth();
olddollar = (yyvsp[0].exprptr)->e_value;
oldothdollar = (yyvsp[0].exprptr)->e_value;
dollarsign = (yyvsp[0].exprptr)->e_value;
emit_addr = (yyvsp[0].exprptr)->e_value;
seg_pos[segment] = dollarsign;
if (seg_pos[segment] > seg_size[segment])
seg_size[segment] = seg_pos[segment];
putrelcmd(RELCMD_SETLOC);
putrelsegref(segment, seg_pos[segment]);
segchange = 0;
}
expr_free((yyvsp[0].exprptr));
}
////#line 5853 "zmac.c" /* yacc.c:1646 */
break;
case 170:
////#line 3052 "zmac.y" /* yacc.c:1646 */
{
list_dollarsign = 0;
list_addr = (yyvsp[0].exprptr)->e_value;
expr_number_check((yyvsp[0].exprptr));
if (outpass && !(yyvsp[0].exprptr)->e_value)
{
err[aflag]++;
}
expr_free((yyvsp[0].exprptr));
}
////#line 5868 "zmac.c" /* yacc.c:1646 */
break;
case 171:
////#line 3064 "zmac.y" /* yacc.c:1646 */
{
list_dollarsign = 0;
list_addr = (yyvsp[0].exprptr)->e_value;
expr_number_check((yyvsp[0].exprptr));
tstates = (yyvsp[0].exprptr)->e_value;
tstatesum[emit_addr] = tstates;
expr_free((yyvsp[0].exprptr));
}
////#line 5881 "zmac.c" /* yacc.c:1646 */
break;
case 172:
////#line 3074 "zmac.y" /* yacc.c:1646 */
{
list_dollarsign = 0;
list_addr = (yyvsp[0].exprptr)->e_value;
expr_number_check((yyvsp[0].exprptr));
ocf = (yyvsp[0].exprptr)->e_value;
ocfsum[emit_addr] = ocf;
expr_free((yyvsp[0].exprptr));
}
////#line 5894 "zmac.c" /* yacc.c:1646 */
break;
case 173:
////#line 3083 "zmac.y" /* yacc.c:1646 */
{ full_exprs = 1; }
////#line 5900 "zmac.c" /* yacc.c:1646 */
break;
case 174:
////#line 3083 "zmac.y" /* yacc.c:1646 */
{ full_exprs = 0; }
////#line 5906 "zmac.c" /* yacc.c:1646 */
break;
case 175:
////#line 3085 "zmac.y" /* yacc.c:1646 */
{ full_exprs = 1; }
////#line 5912 "zmac.c" /* yacc.c:1646 */
break;
case 176:
////#line 3085 "zmac.y" /* yacc.c:1646 */
{ full_exprs = 0; }
////#line 5918 "zmac.c" /* yacc.c:1646 */
break;
case 177:
////#line 3087 "zmac.y" /* yacc.c:1646 */
{ full_exprs = 1; }
////#line 5924 "zmac.c" /* yacc.c:1646 */
break;
case 178:
////#line 3087 "zmac.y" /* yacc.c:1646 */
{ full_exprs = 0; }
////#line 5930 "zmac.c" /* yacc.c:1646 */
break;
case 183:
////#line 3099 "zmac.y" /* yacc.c:1646 */
{ param_parse = 1; }
////#line 5936 "zmac.c" /* yacc.c:1646 */
break;
case 184:
////#line 3099 "zmac.y" /* yacc.c:1646 */
{ param_parse = 0; }
////#line 5942 "zmac.c" /* yacc.c:1646 */
break;
case 185:
////#line 3101 "zmac.y" /* yacc.c:1646 */
{ (yyval.ival) = 0; }
////#line 5948 "zmac.c" /* yacc.c:1646 */
break;
case 186:
////#line 3101 "zmac.y" /* yacc.c:1646 */
{ (yyval.ival) = 1; }
////#line 5954 "zmac.c" /* yacc.c:1646 */
break;
case 187:
////#line 3105 "zmac.y" /* yacc.c:1646 */
{
if (parm_number >= PARMMAX)
error("Too many parameters");
(yyvsp[0].itemptr)->i_value = parm_number++;
(yyvsp[0].itemptr)->i_scope = (yyvsp[-1].ival);
(yyvsp[0].itemptr)->i_chain = 0;
}
////#line 5966 "zmac.c" /* yacc.c:1646 */
break;
case 188:
////#line 3114 "zmac.y" /* yacc.c:1646 */
{
static char macpush[LINEBUFFERSIZE];
// Because of locals the parser has to look ahead.
// We'll have buffered that as we usually do so just a
// matter of picking that up and cancelling any look-ahead.
*lineptr = '\0';
strcpy(macpush, linebuf);
lineptr = linebuf;
peekc = -1;
yychar = YYEMPTY;
(yyval.cval) = macpush;
}
////#line 5983 "zmac.c" /* yacc.c:1646 */
break;
case 190:
////#line 3130 "zmac.y" /* yacc.c:1646 */
{ param_parse = 1; }
////#line 5989 "zmac.c" /* yacc.c:1646 */
break;
case 191:
////#line 3130 "zmac.y" /* yacc.c:1646 */
{ param_parse = 0; list1(); }
////#line 5995 "zmac.c" /* yacc.c:1646 */
break;
case 195:
////#line 3142 "zmac.y" /* yacc.c:1646 */
{
if (parm_number >= PARMMAX)
error("Too many parameters");
(yyvsp[0].itemptr)->i_value = parm_number++;
(yyvsp[0].itemptr)->i_scope = 0;
(yyvsp[0].itemptr)->i_chain = 1;
}
////#line 6007 "zmac.c" /* yacc.c:1646 */
break;
case 199:
////#line 3162 "zmac.y" /* yacc.c:1646 */
{
cp = malloc(strlen(tempbuf)+1);
#ifdef M_DEBUG
fprintf (stderr, "[Arg%u(%p): %s]\n", parm_number, cp, tempbuf);
#endif
est2[parm_number++].param = cp;
strcpy(cp, tempbuf);
}
////#line 6020 "zmac.c" /* yacc.c:1646 */
break;
case 200:
////#line 3171 "zmac.y" /* yacc.c:1646 */
{ arg_flag = 0; }
////#line 6026 "zmac.c" /* yacc.c:1646 */
break;
case 201:
////#line 3172 "zmac.y" /* yacc.c:1646 */
{
arg_flag = 1;
expr_reloc_check((yyvsp[0].exprptr));
sprintf(tempbuf, "%d", (yyvsp[0].exprptr)->e_value);
est2[parm_number++].param = _strdup(tempbuf);
expr_free((yyvsp[0].exprptr));
}
////#line 6038 "zmac.c" /* yacc.c:1646 */
break;
case 206:
////#line 3193 "zmac.y" /* yacc.c:1646 */
{
(yyval.ival) = (yyvsp[0].itemptr)->i_value;
}
////#line 6046 "zmac.c" /* yacc.c:1646 */
break;
case 209:
////#line 3203 "zmac.y" /* yacc.c:1646 */
{ if ((yyvsp[0].itemptr)->i_value != 070) err[gflag]++; (yyval.ival) = 6; }
////#line 6052 "zmac.c" /* yacc.c:1646 */
break;
case 210:
////#line 3207 "zmac.y" /* yacc.c:1646 */
{
(yyval.ival) = (yyvsp[0].itemptr)->i_value;
}
////#line 6060 "zmac.c" /* yacc.c:1646 */
break;
case 211:
////#line 3212 "zmac.y" /* yacc.c:1646 */
{
(yyval.ival) = (yyvsp[0].itemptr)->i_value;
}
////#line 6068 "zmac.c" /* yacc.c:1646 */
break;
case 212:
////#line 3217 "zmac.y" /* yacc.c:1646 */
{
(yyval.ival) = (yyvsp[0].itemptr)->i_value;
}
////#line 6076 "zmac.c" /* yacc.c:1646 */
break;
case 213:
////#line 3223 "zmac.y" /* yacc.c:1646 */
{
(yyval.ival) = 6;
}
////#line 6084 "zmac.c" /* yacc.c:1646 */
break;
case 215:
////#line 3231 "zmac.y" /* yacc.c:1646 */
{
(yyval.ival) = ((yyvsp[-2].itemptr)->i_value & 0177400) | 6;
}
////#line 6092 "zmac.c" /* yacc.c:1646 */
break;
case 216:
////#line 3236 "zmac.y" /* yacc.c:1646 */
{
disp = 0;
(yyval.ival) = ((yyvsp[-1].itemptr)->i_value & 0177400) | 6;
}
////#line 6101 "zmac.c" /* yacc.c:1646 */
break;
case 217:
////#line 3242 "zmac.y" /* yacc.c:1646 */
{
(yyval.ival) = ((yyvsp[-1].itemptr)->i_value & 0177400) | 6;
}
////#line 6109 "zmac.c" /* yacc.c:1646 */
break;
case 218:
////#line 3247 "zmac.y" /* yacc.c:1646 */
{
expr_number_check((yyvsp[0].exprptr));
disp = (yyvsp[0].exprptr)->e_value;
expr_free((yyvsp[0].exprptr));
if (disp > 127 || disp < -128)
err[vflag]++;
}
////#line 6121 "zmac.c" /* yacc.c:1646 */
break;
case 221:
////#line 3261 "zmac.y" /* yacc.c:1646 */
{ if ((yyvsp[0].ival) & 1) err[gflag]++; (yyval.ival) = (yyvsp[0].ival) << 3; }
////#line 6127 "zmac.c" /* yacc.c:1646 */
break;
case 222:
////#line 3263 "zmac.y" /* yacc.c:1646 */
{ (yyval.ival) = (yyvsp[0].itemptr)->i_value; }
////#line 6133 "zmac.c" /* yacc.c:1646 */
break;
case 223:
////#line 3267 "zmac.y" /* yacc.c:1646 */
{
(yyval.ival) = (yyvsp[0].itemptr)->i_value;
}
////#line 6141 "zmac.c" /* yacc.c:1646 */
break;
case 224:
////#line 3272 "zmac.y" /* yacc.c:1646 */
{
(yyval.ival) = (yyvsp[0].itemptr)->i_value;
}
////#line 6149 "zmac.c" /* yacc.c:1646 */
break;
case 226:
////#line 3279 "zmac.y" /* yacc.c:1646 */
{ if ((yyvsp[0].ival) & 1) err[gflag]++; (yyval.ival) = (yyvsp[0].ival) << 3; }
////#line 6155 "zmac.c" /* yacc.c:1646 */
break;
case 227:
////#line 3281 "zmac.y" /* yacc.c:1646 */
{ (yyval.ival) = (yyvsp[0].itemptr)->i_value; }
////#line 6161 "zmac.c" /* yacc.c:1646 */
break;
case 228:
////#line 3285 "zmac.y" /* yacc.c:1646 */
{
(yyval.ival) = (yyvsp[0].itemptr)->i_value;
}
////#line 6169 "zmac.c" /* yacc.c:1646 */
break;
case 229:
////#line 3290 "zmac.y" /* yacc.c:1646 */
{
(yyval.ival) = (yyvsp[0].itemptr)->i_value;
}
////#line 6177 "zmac.c" /* yacc.c:1646 */
break;
case 231:
////#line 3298 "zmac.y" /* yacc.c:1646 */
{
(yyval.ival) = (yyvsp[0].itemptr)->i_value;
}
////#line 6185 "zmac.c" /* yacc.c:1646 */
break;
case 232:
////#line 3304 "zmac.y" /* yacc.c:1646 */
{
(yyval.ival) = (yyvsp[0].itemptr)->i_value;
}
////#line 6193 "zmac.c" /* yacc.c:1646 */
break;
case 233:
////#line 3309 "zmac.y" /* yacc.c:1646 */
{
(yyval.ival) = (yyvsp[0].itemptr)->i_value;
}
////#line 6201 "zmac.c" /* yacc.c:1646 */
break;
case 235:
////#line 3317 "zmac.y" /* yacc.c:1646 */
{
(yyval.ival) = (yyvsp[0].itemptr)->i_value;
}
////#line 6209 "zmac.c" /* yacc.c:1646 */
break;
case 236:
////#line 3323 "zmac.y" /* yacc.c:1646 */
{
(yyval.ival) = (yyvsp[0].itemptr)->i_value;
}
////#line 6217 "zmac.c" /* yacc.c:1646 */
break;
case 237:
////#line 3328 "zmac.y" /* yacc.c:1646 */
{ (yyval.ival) = 030; }
////#line 6223 "zmac.c" /* yacc.c:1646 */
break;
case 240:
////#line 3337 "zmac.y" /* yacc.c:1646 */
{
emit(1, E_DATA, expr_num((yyvsp[0].ival)));
emit(1, E_DATA, expr_num((yyvsp[0].ival)>>8));
}
////#line 6232 "zmac.c" /* yacc.c:1646 */
break;
case 241:
////#line 3343 "zmac.y" /* yacc.c:1646 */
{
cp = (yyvsp[0].cval);
while (*cp != '\0')
emit(1,E_DATA,expr_num(*cp++));
}
////#line 6242 "zmac.c" /* yacc.c:1646 */
break;
case 242:
////#line 3350 "zmac.y" /* yacc.c:1646 */
{
if (is_number((yyvsp[0].exprptr)) && ((yyvsp[0].exprptr)->e_value < -128 || (yyvsp[0].exprptr)->e_value > 255))
err[vflag]++;
emit(1, E_DATA, (yyvsp[0].exprptr));
}
////#line 6252 "zmac.c" /* yacc.c:1646 */
break;
case 245:
////#line 3367 "zmac.y" /* yacc.c:1646 */
{
if ((yyvsp[0].exprptr)->e_value < -32768 || (yyvsp[0].exprptr)->e_value > 65535) {
err[vflag]++;
}
emit(2, E_DATA, (yyvsp[0].exprptr));
}
////#line 6263 "zmac.c" /* yacc.c:1646 */
break;
case 248:
////#line 3384 "zmac.y" /* yacc.c:1646 */
{
// Can't check overflow as I only have 32 bit ints.
emit(4, E_DATA, (yyvsp[0].exprptr));
}
////#line 6272 "zmac.c" /* yacc.c:1646 */
break;
case 250:
////#line 3396 "zmac.y" /* yacc.c:1646 */
{
(yyval.exprptr) = expr_num((yyvsp[0].ival));
}
////#line 6280 "zmac.c" /* yacc.c:1646 */
break;
case 253:
////#line 3409 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = (yyvsp[-1].exprptr); }
////#line 6286 "zmac.c" /* yacc.c:1646 */
break;
case 254:
////#line 3426 "zmac.y" /* yacc.c:1646 */
{
(yyval.exprptr) = expr_alloc();
(yyval.exprptr)->e_token = 'v';
(yyval.exprptr)->e_item = (yyvsp[0].itemptr);
(yyval.exprptr)->e_scope = (yyvsp[0].itemptr)->i_scope;
(yyval.exprptr)->e_value = (yyvsp[0].itemptr)->i_value;
(yyvsp[0].itemptr)->i_uses++;
}
////#line 6299 "zmac.c" /* yacc.c:1646 */
break;
case 255:
////#line 3436 "zmac.y" /* yacc.c:1646 */
{
(yyval.exprptr) = expr_num((yyvsp[0].ival));
}
////#line 6307 "zmac.c" /* yacc.c:1646 */
break;
case 256:
////#line 3441 "zmac.y" /* yacc.c:1646 */
{
(yyval.exprptr) = expr_num((yyvsp[0].ival));
}
////#line 6315 "zmac.c" /* yacc.c:1646 */
break;
case 257:
////#line 3446 "zmac.y" /* yacc.c:1646 */
{
(yyval.exprptr) = expr_alloc();
(yyval.exprptr)->e_token = 'v';
(yyval.exprptr)->e_item = (yyvsp[0].itemptr); // not necessary
(yyval.exprptr)->e_scope = (yyvsp[0].itemptr)->i_scope;
(yyval.exprptr)->e_value = (yyvsp[0].itemptr)->i_value;
}
////#line 6327 "zmac.c" /* yacc.c:1646 */
break;
case 258:
////#line 3455 "zmac.y" /* yacc.c:1646 */
{
(yyval.exprptr) = expr_alloc();
(yyval.exprptr)->e_token = 'v';
(yyval.exprptr)->e_item = (yyvsp[0].itemptr); // not necessary
(yyval.exprptr)->e_scope = (yyvsp[0].itemptr)->i_scope;
(yyval.exprptr)->e_value = (yyvsp[0].itemptr)->i_value;
}
////#line 6339 "zmac.c" /* yacc.c:1646 */
break;
case 259:
////#line 3464 "zmac.y" /* yacc.c:1646 */
{
(yyval.exprptr) = expr_alloc();
(yyval.exprptr)->e_token = 'v';
(yyval.exprptr)->e_item = (yyvsp[0].itemptr); // not necessary
(yyval.exprptr)->e_scope = (yyvsp[0].itemptr)->i_scope;
(yyval.exprptr)->e_value = (yyvsp[0].itemptr)->i_value;
}
////#line 6351 "zmac.c" /* yacc.c:1646 */
break;
case 260:
////#line 3473 "zmac.y" /* yacc.c:1646 */
{
(yyval.exprptr) = expr_num(dollarsign + emitptr - emitbuf);
(yyval.exprptr)->e_scope = segment;
}
////#line 6360 "zmac.c" /* yacc.c:1646 */
break;
case 261:
////#line 3479 "zmac.y" /* yacc.c:1646 */
{
(yyval.exprptr) = expr_alloc();
(yyval.exprptr)->e_token = 'u';
(yyval.exprptr)->e_item = (yyvsp[0].itemptr);
(yyval.exprptr)->e_scope = (yyvsp[0].itemptr)->i_scope;
(yyval.exprptr)->e_value = 0;
if (!((yyvsp[0].itemptr)->i_scope & SCOPE_EXTERNAL)) {
sprintf(detail, "'%s' %s", (yyvsp[0].itemptr)->i_string, errname[uflag]);
// Would be nice to add to list of undeclared errors
errwarn(uflag, detail);
}
}
////#line 6378 "zmac.c" /* yacc.c:1646 */
break;
case 262:
////#line 3494 "zmac.y" /* yacc.c:1646 */
{
(yyval.exprptr) = expr_alloc();
(yyval.exprptr)->e_token = 'm';
(yyval.exprptr)->e_item = (yyvsp[0].itemptr);
(yyval.exprptr)->e_scope = (yyvsp[0].itemptr)->i_scope;
// Use the current value. Harmless enough as this
// will normally error out yet vital to allow
// "var set var+1" to function.
(yyval.exprptr)->e_value = (yyvsp[0].itemptr)->i_value;
}
////#line 6393 "zmac.c" /* yacc.c:1646 */
break;
case 263:
////#line 3505 "zmac.y" /* yacc.c:1646 */
{ raw = 2; }
////#line 6399 "zmac.c" /* yacc.c:1646 */
break;
case 264:
////#line 3506 "zmac.y" /* yacc.c:1646 */
{
(yyval.exprptr) = expr_num(tempbuf[0] ? -1 : 0);
}
////#line 6407 "zmac.c" /* yacc.c:1646 */
break;
case 265:
////#line 3511 "zmac.y" /* yacc.c:1646 */
{
(yyval.exprptr) = expr_op((yyvsp[-2].exprptr), '+', (yyvsp[0].exprptr), (yyvsp[-2].exprptr)->e_value + (yyvsp[0].exprptr)->e_value);
// Can't operate on external labels.
// But we can add constants to any scope.
if (!(((yyvsp[-2].exprptr)->e_scope | (yyvsp[0].exprptr)->e_scope) & SCOPE_EXTERNAL) &&
(((yyvsp[-2].exprptr)->e_scope & SCOPE_SEGMASK) == 0 ||
((yyvsp[0].exprptr)->e_scope & SCOPE_SEGMASK) == 0))
{
(yyval.exprptr)->e_scope &= ~(SCOPE_NORELOC | SCOPE_SEGMASK);
(yyval.exprptr)->e_scope |= ((yyvsp[-2].exprptr)->e_scope | (yyvsp[0].exprptr)->e_scope) & SCOPE_SEGMASK;
}
}
////#line 6425 "zmac.c" /* yacc.c:1646 */
break;
case 266:
////#line 3526 "zmac.y" /* yacc.c:1646 */
{
(yyval.exprptr) = expr_op_sc((yyvsp[-2].exprptr), '-', (yyvsp[0].exprptr), (yyvsp[-2].exprptr)->e_value - (yyvsp[0].exprptr)->e_value);
// But we can subtract a constant.
if (!(((yyvsp[-2].exprptr)->e_scope | (yyvsp[0].exprptr)->e_scope) & SCOPE_EXTERNAL) &&
(((yyvsp[0].exprptr)->e_scope & SCOPE_SEGMASK) == 0))
{
(yyval.exprptr)->e_scope &= ~(SCOPE_NORELOC | SCOPE_SEGMASK);
(yyval.exprptr)->e_scope |= ((yyvsp[-2].exprptr)->e_scope & SCOPE_SEGMASK);
}
}
////#line 6441 "zmac.c" /* yacc.c:1646 */
break;
case 267:
////#line 3539 "zmac.y" /* yacc.c:1646 */
{
int val = 0;
if ((yyvsp[0].exprptr)->e_value == 0)
err[eflag]++;
else
val = (yyvsp[-2].exprptr)->e_value / (yyvsp[0].exprptr)->e_value;
(yyval.exprptr) = expr_op((yyvsp[-2].exprptr), '/', (yyvsp[0].exprptr), val);
}
////#line 6455 "zmac.c" /* yacc.c:1646 */
break;
case 268:
////#line 3550 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op((yyvsp[-2].exprptr), '*', (yyvsp[0].exprptr), (yyvsp[-2].exprptr)->e_value * (yyvsp[0].exprptr)->e_value); }
////#line 6461 "zmac.c" /* yacc.c:1646 */
break;
case 269:
////#line 3553 "zmac.y" /* yacc.c:1646 */
{
int val;
domod:
val = 0;
if ((yyvsp[0].exprptr)->e_value == 0)
err[eflag]++;
else
val = (yyvsp[-2].exprptr)->e_value % (yyvsp[0].exprptr)->e_value;
(yyval.exprptr) = expr_op((yyvsp[-2].exprptr), '%', (yyvsp[0].exprptr), val);
}
////#line 6477 "zmac.c" /* yacc.c:1646 */
break;
case 270:
////#line 3566 "zmac.y" /* yacc.c:1646 */
{ goto domod; }
////#line 6483 "zmac.c" /* yacc.c:1646 */
break;
case 271:
////#line 3569 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op((yyvsp[-2].exprptr), '&', (yyvsp[0].exprptr), (yyvsp[-2].exprptr)->e_value & (yyvsp[0].exprptr)->e_value); }
////#line 6489 "zmac.c" /* yacc.c:1646 */
break;
case 272:
////#line 3572 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op((yyvsp[-2].exprptr), '&', (yyvsp[0].exprptr), (yyvsp[-2].exprptr)->e_value & (yyvsp[0].exprptr)->e_value); }
////#line 6495 "zmac.c" /* yacc.c:1646 */
break;
case 273:
////#line 3575 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op((yyvsp[-2].exprptr), '|', (yyvsp[0].exprptr), (yyvsp[-2].exprptr)->e_value | (yyvsp[0].exprptr)->e_value); }
////#line 6501 "zmac.c" /* yacc.c:1646 */
break;
case 274:
////#line 3578 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op((yyvsp[-2].exprptr), '|', (yyvsp[0].exprptr), (yyvsp[-2].exprptr)->e_value | (yyvsp[0].exprptr)->e_value); }
////#line 6507 "zmac.c" /* yacc.c:1646 */
break;
case 275:
////#line 3581 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op((yyvsp[-2].exprptr), '^', (yyvsp[0].exprptr), (yyvsp[-2].exprptr)->e_value ^ (yyvsp[0].exprptr)->e_value); }
////#line 6513 "zmac.c" /* yacc.c:1646 */
break;
case 276:
////#line 3584 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op((yyvsp[-2].exprptr), '^', (yyvsp[0].exprptr), (yyvsp[-2].exprptr)->e_value ^ (yyvsp[0].exprptr)->e_value); }
////#line 6519 "zmac.c" /* yacc.c:1646 */
break;
case 277:
////#line 3587 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op((yyvsp[-2].exprptr), (yyvsp[-1].ival), (yyvsp[0].exprptr), (yyvsp[-2].exprptr)->e_value << (yyvsp[0].exprptr)->e_value); }
////#line 6525 "zmac.c" /* yacc.c:1646 */
break;
case 278:
////#line 3590 "zmac.y" /* yacc.c:1646 */
{
int val = (yyvsp[0].exprptr)->e_value == 0 ? (yyvsp[-2].exprptr)->e_value : (((yyvsp[-2].exprptr)->e_value >> 1) & ((0x7fff << 16) | 0xffff)) >> ((yyvsp[0].exprptr)->e_value - 1);
(yyval.exprptr) = expr_op((yyvsp[-2].exprptr), (yyvsp[-1].ival), (yyvsp[0].exprptr), val);
}
////#line 6534 "zmac.c" /* yacc.c:1646 */
break;
case 279:
////#line 3596 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op_sc((yyvsp[-2].exprptr), '<', (yyvsp[0].exprptr), (yyvsp[-2].exprptr)->e_value < (yyvsp[0].exprptr)->e_value); }
////#line 6540 "zmac.c" /* yacc.c:1646 */
break;
case 280:
////#line 3599 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op_sc((yyvsp[-2].exprptr), '=', (yyvsp[0].exprptr), (yyvsp[-2].exprptr)->e_value == (yyvsp[0].exprptr)->e_value); }
////#line 6546 "zmac.c" /* yacc.c:1646 */
break;
case 281:
////#line 3602 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op_sc((yyvsp[-2].exprptr), '>', (yyvsp[0].exprptr), (yyvsp[-2].exprptr)->e_value > (yyvsp[0].exprptr)->e_value); }
////#line 6552 "zmac.c" /* yacc.c:1646 */
break;
case 282:
////#line 3605 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op_sc((yyvsp[-2].exprptr), (yyvsp[-1].ival), (yyvsp[0].exprptr), (yyvsp[-2].exprptr)->e_value < (yyvsp[0].exprptr)->e_value); }
////#line 6558 "zmac.c" /* yacc.c:1646 */
break;
case 283:
////#line 3608 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op_sc((yyvsp[-2].exprptr), (yyvsp[-1].ival), (yyvsp[0].exprptr), (yyvsp[-2].exprptr)->e_value > (yyvsp[0].exprptr)->e_value); }
////#line 6564 "zmac.c" /* yacc.c:1646 */
break;
case 284:
////#line 3611 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op_sc((yyvsp[-2].exprptr), (yyvsp[-1].ival), (yyvsp[0].exprptr), (yyvsp[-2].exprptr)->e_value <= (yyvsp[0].exprptr)->e_value); }
////#line 6570 "zmac.c" /* yacc.c:1646 */
break;
case 285:
////#line 3614 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op_sc((yyvsp[-2].exprptr), (yyvsp[-1].ival), (yyvsp[0].exprptr), (yyvsp[-2].exprptr)->e_value >= (yyvsp[0].exprptr)->e_value); }
////#line 6576 "zmac.c" /* yacc.c:1646 */
break;
case 286:
////#line 3617 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op_sc((yyvsp[-2].exprptr), (yyvsp[-1].ival), (yyvsp[0].exprptr), (yyvsp[-2].exprptr)->e_value != (yyvsp[0].exprptr)->e_value); }
////#line 6582 "zmac.c" /* yacc.c:1646 */
break;
case 287:
////#line 3620 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op((yyvsp[-2].exprptr), (yyvsp[-1].ival), (yyvsp[0].exprptr), (yyvsp[-2].exprptr)->e_value && (yyvsp[0].exprptr)->e_value); }
////#line 6588 "zmac.c" /* yacc.c:1646 */
break;
case 288:
////#line 3623 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op((yyvsp[-2].exprptr), (yyvsp[-1].ival), (yyvsp[0].exprptr), (yyvsp[-2].exprptr)->e_value || (yyvsp[0].exprptr)->e_value); }
////#line 6594 "zmac.c" /* yacc.c:1646 */
break;
case 289:
////#line 3626 "zmac.y" /* yacc.c:1646 */
{
expr_number_check((yyvsp[-4].exprptr));
if ((yyvsp[-4].exprptr)->e_value) {
(yyval.exprptr) = (yyvsp[-2].exprptr);
expr_free((yyvsp[0].exprptr));
}
else {
(yyval.exprptr) = (yyvsp[0].exprptr);
expr_free((yyvsp[-2].exprptr));
}
expr_free((yyvsp[-4].exprptr));
}
////#line 6611 "zmac.c" /* yacc.c:1646 */
break;
case 290:
////#line 3640 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = (yyvsp[-1].exprptr); }
////#line 6617 "zmac.c" /* yacc.c:1646 */
break;
case 291:
////#line 3643 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op((yyvsp[0].exprptr), '~', 0, ~(yyvsp[0].exprptr)->e_value); }
////#line 6623 "zmac.c" /* yacc.c:1646 */
break;
case 292:
////#line 3646 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op((yyvsp[0].exprptr), '~', 0, ~(yyvsp[0].exprptr)->e_value); }
////#line 6629 "zmac.c" /* yacc.c:1646 */
break;
case 293:
////#line 3649 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op((yyvsp[0].exprptr), '!', 0, !(yyvsp[0].exprptr)->e_value); }
////#line 6635 "zmac.c" /* yacc.c:1646 */
break;
case 294:
////#line 3652 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = (yyvsp[0].exprptr); /* no effect */ }
////#line 6641 "zmac.c" /* yacc.c:1646 */
break;
case 295:
////#line 3655 "zmac.y" /* yacc.c:1646 */
{ (yyval.exprptr) = expr_op((yyvsp[0].exprptr), '-', 0, -(yyvsp[0].exprptr)->e_value); }
////#line 6647 "zmac.c" /* yacc.c:1646 */
break;
case 296:
////#line 3658 "zmac.y" /* yacc.c:1646 */
{
expr_reloc_check((yyvsp[0].exprptr));
(yyval.exprptr) = expr_num(tstatesum[phaseaddr((yyvsp[0].exprptr)->e_value)]);
expr_free((yyvsp[0].exprptr));
}
////#line 6657 "zmac.c" /* yacc.c:1646 */
break;
case 297:
////#line 3665 "zmac.y" /* yacc.c:1646 */
{
int low, low8080, fetch;
expr_reloc_check((yyvsp[0].exprptr));
zi_tstates(memory + phaseaddr((yyvsp[0].exprptr)->e_value), &low, 0, &fetch, &low8080, 0);
(yyval.exprptr) = expr_num(z80 ? low : low8080);
expr_free((yyvsp[0].exprptr));
}
////#line 6669 "zmac.c" /* yacc.c:1646 */
break;
case 298:
////#line 3674 "zmac.y" /* yacc.c:1646 */
{
int high, high8080, fetch;
expr_reloc_check((yyvsp[0].exprptr));
zi_tstates(memory + phaseaddr((yyvsp[0].exprptr)->e_value), 0, &high, &fetch, 0, &high8080);
(yyval.exprptr) = expr_num(z80 ? high : high8080);
expr_free((yyvsp[0].exprptr));
}
////#line 6681 "zmac.c" /* yacc.c:1646 */
break;
case 299:
////#line 3683 "zmac.y" /* yacc.c:1646 */
{
expr_reloc_check((yyvsp[0].exprptr));
(yyval.exprptr) = expr_num(ocfsum[phaseaddr((yyvsp[0].exprptr)->e_value)]);
expr_free((yyvsp[0].exprptr));
}
////#line 6691 "zmac.c" /* yacc.c:1646 */
break;
case 300:
////#line 3690 "zmac.y" /* yacc.c:1646 */
{
(yyval.exprptr) = expr_op((yyvsp[0].exprptr), (yyvsp[-1].ival), 0, (yyvsp[0].exprptr)->e_value & 0xff);
}
////#line 6699 "zmac.c" /* yacc.c:1646 */
break;
case 301:
////#line 3695 "zmac.y" /* yacc.c:1646 */
{
(yyval.exprptr) = expr_op((yyvsp[0].exprptr), (yyvsp[-1].ival), 0, ((yyvsp[0].exprptr)->e_value >> 8) & 0xff);
}
////#line 6707 "zmac.c" /* yacc.c:1646 */
break;
case 308:
////#line 3716 "zmac.y" /* yacc.c:1646 */
{ int i;
if (expptr >= MAXEXP)
error("Macro expansion level too deep");
est2 = (union exprec *) malloc((PARMMAX + PAREXT) * sizeof *est2);
expstack[expptr] = est2;
for (i=0; i<PARMMAX; i++)
est2[i].param = 0;
arg_start();
}
////#line 6721 "zmac.c" /* yacc.c:1646 */
break;
case 309:
////#line 3729 "zmac.y" /* yacc.c:1646 */
{ arg_start(); }
////#line 6727 "zmac.c" /* yacc.c:1646 */
break;
case 310:
////#line 3733 "zmac.y" /* yacc.c:1646 */
{ arg_reset(); }
////#line 6733 "zmac.c" /* yacc.c:1646 */
break;
////#line 6737 "zmac.c" /* yacc.c:1646 */
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
that yytoken be updated with the new translation. We take the
approach of translating immediately before every use of yytoken.
One alternative is translating here after every semantic action,
but that translation would be missed if the semantic action invokes
YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
incorrect destructor might then be invoked immediately. In the
case of YYERROR or YYBACKUP, subsequent parser actions might lead
to an incorrect destructor call or verbose syntax error message
before the lookahead is translated. */
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
YYPOPSTACK (yylen);
yylen = 0;
YY_STACK_PRINT (yyss, yyssp);
*++yyvsp = yyval;
/* Now 'shift' the result of the reduction. Determine what state
that goes to, based on the state we popped back to and the rule
number reduced by. */
yyn = yyr1[yyn];
yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
yystate = yytable[yystate];
else
yystate = yydefgoto[yyn - YYNTOKENS];
goto yynewstate;
/*--------------------------------------.
| yyerrlab -- here on detecting error. |
`--------------------------------------*/
yyerrlab:
/* Make sure we have latest lookahead translation. See comments at
user semantic actions for why this is necessary. */
yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
/* If not already recovering from an error, report this error. */
if (!yyerrstatus)
{
++yynerrs;
#if ! YYERROR_VERBOSE
yyerror (YY_("syntax error"));
#else
# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
yyssp, yytoken)
{
char const *yymsgp = YY_("syntax error");
int yysyntax_error_status;
yysyntax_error_status = YYSYNTAX_ERROR;
if (yysyntax_error_status == 0)
yymsgp = yymsg;
else if (yysyntax_error_status == 1)
{
if (yymsg != yymsgbuf)
YYSTACK_FREE (yymsg);
yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
if (!yymsg)
{
yymsg = yymsgbuf;
yymsg_alloc = sizeof yymsgbuf;
yysyntax_error_status = 2;
}
else
{
yysyntax_error_status = YYSYNTAX_ERROR;
yymsgp = yymsg;
}
}
yyerror (yymsgp);
if (yysyntax_error_status == 2)
goto yyexhaustedlab;
}
# undef YYSYNTAX_ERROR
#endif
}
if (yyerrstatus == 3)
{
/* If just tried and failed to reuse lookahead token after an
error, discard it. */
if (yychar <= YYEOF)
{
/* Return failure if at end of input. */
if (yychar == YYEOF)
YYABORT;
}
else
{
yydestruct ("Error: discarding",
yytoken, &yylval);
yychar = YYEMPTY;
}
}
/* Else will try to reuse lookahead token after shifting the error
token. */
goto yyerrlab1;
/*---------------------------------------------------.
| yyerrorlab -- error raised explicitly by YYERROR. |
`---------------------------------------------------*/
yyerrorlab:
/* Pacify compilers like GCC when the user code never invokes
YYERROR and the label yyerrorlab therefore never appears in user
code. */
if (/*CONSTCOND*/ 0)
goto yyerrorlab;
/* Do not reclaim the symbols of the rule whose action triggered
this YYERROR. */
YYPOPSTACK (yylen);
yylen = 0;
YY_STACK_PRINT (yyss, yyssp);
yystate = *yyssp;
goto yyerrlab1;
/*-------------------------------------------------------------.
| yyerrlab1 -- common code for both syntax error and YYERROR. |
`-------------------------------------------------------------*/
yyerrlab1:
yyerrstatus = 3; /* Each real token shifted decrements this. */
for (;;)
{
yyn = yypact[yystate];
if (!yypact_value_is_default (yyn))
{
yyn += YYTERROR;
if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
{
yyn = yytable[yyn];
if (0 < yyn)
break;
}
}
/* Pop the current state because it cannot handle the error token. */
if (yyssp == yyss)
YYABORT;
yydestruct ("Error: popping",
yystos[yystate], yyvsp);
YYPOPSTACK (1);
yystate = *yyssp;
YY_STACK_PRINT (yyss, yyssp);
}
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
*++yyvsp = yylval;
YY_IGNORE_MAYBE_UNINITIALIZED_END
/* Shift the error token. */
YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
yystate = yyn;
goto yynewstate;
/*-------------------------------------.
| yyacceptlab -- YYACCEPT comes here. |
`-------------------------------------*/
yyacceptlab:
yyresult = 0;
goto yyreturn;
/*-----------------------------------.
| yyabortlab -- YYABORT comes here. |
`-----------------------------------*/
yyabortlab:
yyresult = 1;
goto yyreturn;
#if !defined yyoverflow || YYERROR_VERBOSE
/*-------------------------------------------------.
| yyexhaustedlab -- memory exhaustion comes here. |
`-------------------------------------------------*/
yyexhaustedlab:
yyerror (YY_("memory exhausted"));
yyresult = 2;
/* Fall through. */
#endif
yyreturn:
if (yychar != YYEMPTY)
{
/* Make sure we have latest lookahead translation. See comments at
user semantic actions for why this is necessary. */
yytoken = YYTRANSLATE (yychar);
yydestruct ("Cleanup: discarding lookahead",
yytoken, &yylval);
}
/* Do not reclaim the symbols of the rule whose action triggered
this YYABORT or YYACCEPT. */
YYPOPSTACK (yylen);
YY_STACK_PRINT (yyss, yyssp);
while (yyssp != yyss)
{
yydestruct ("Cleanup: popping",
yystos[*yyssp], yyvsp);
YYPOPSTACK (1);
}
#ifndef yyoverflow
if (yyss != yyssa)
YYSTACK_FREE (yyss);
#endif
#if YYERROR_VERBOSE
if (yymsg != yymsgbuf)
YYSTACK_FREE (yymsg);
#endif
return yyresult;
}
////#line 3736 "zmac.y" /* yacc.c:1906 */
/*extern int yylval;*/
#define F_END 0
#define OTHER 1
#define SPACE 2
#define DIGIT 3
#define LETTER 4
#define STARTER 5
#define DOLLAR 6
/*
* This is the table of character classes. It is used by the lexical
* analyser. (yylex())
*/
char charclass[] = {
F_END, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
OTHER, SPACE, OTHER, OTHER, OTHER, SPACE, OTHER, OTHER,
OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
SPACE, OTHER, OTHER, OTHER, DOLLAR, OTHER, OTHER, OTHER, // !"#$%&'
OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, STARTER,OTHER, // ()*+,-./
DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, // 01234567
DIGIT, DIGIT, OTHER, OTHER, OTHER, OTHER, OTHER, STARTER,// 89:;<=>?
STARTER,LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, // @ABCDEFG
LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, // HIJKLMNO
LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, // PQRSTUVW
LETTER, LETTER, LETTER, OTHER, OTHER, OTHER, OTHER, LETTER, // XYZ[\]^_
OTHER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, // `abcdefg
LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, // hijklmno
LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, // pqrstuvw
LETTER, LETTER, LETTER, OTHER, OTHER, OTHER, OTHER, OTHER, // xyz{|}~
};
/*
* the following table tells which characters are parts of numbers.
* The entry is non-zero for characters which can be parts of numbers.
*/
char numpart[] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 0, 0, 0, 0, 0, 0,
0, 'A', 'B', 'C', 'D', 'E', 'F', 0,
'H', 0, 0, 0, 0, 0, 0, 'O',
0, 'Q', 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 'a', 'b', 'c', 'd', 'e', 'f', 0,
'h', 0, 0, 0, 0, 0, 0, 'o',
0, 'q', 0, 0, 0, 0, 0, 0,
'x', 0, 0, 0, 0, 0, 0, 0,
0};
/*
* the following table is a list of assembler mnemonics;
* for each mnemonic the associated machine-code bit pattern
* and symbol type are given.
*
* The i_uses field is overloaded to indicate the possible uses for
* a token.
*/
#define VERB (1) /* opcode or psuedo-op */
#define I8080 (2) /* used in 8080 instructions */
#define Z80 (4) /* used in Z80 instructions */
#define UNDOC (8) /* used only in undocumented instructions */
#define TERM (16) /* can appear in expressions (not all marked) */
#define ZNONSTD (32) /* non-standard Z-80 mnemonic (probably TDL or DRI) */
#define COL0 (64) /* will always be recognized in logical column 0 */
struct item keytab[] = {
{"*mod", 0, MRAS_MOD, VERB },
{".8080", 0, INSTSET, VERB },
{"a", 7, ACC, I8080 | Z80 },
{"aci", 0316, ALUI8, VERB | I8080 },
{"adc", 1, ARITHC, VERB | I8080 | Z80 },
{"adcx", 0xdd8e, ALU_XY, VERB | Z80 | ZNONSTD },
{"adcy", 0xfd8e, ALU_XY, VERB | Z80 | ZNONSTD },
{"add", 0, ADD, VERB | I8080 | Z80 },
{"addx", 0xdd86, ALU_XY, VERB | Z80 | ZNONSTD },
{"addy", 0xfd86, ALU_XY, VERB | Z80 | ZNONSTD },
{"adi", 0306, ALUI8, VERB | I8080 },
{"af", 060, AF, Z80 },
{"ana", 4, ARITHC, VERB | I8080},
{"and", 4, AND, VERB | Z80 | TERM },
{"andx", 0xdda6, ALU_XY, VERB | Z80 | ZNONSTD },
{"andy", 0xfda6, ALU_XY, VERB | Z80 | ZNONSTD },
{"ani", 0346, ALUI8, VERB | I8080 },
{".ascii", 0, DEFB, VERB },
{".aseg", SEG_ABS,SETSEG, VERB },
{".aset", 0, DEFL, VERB },
{".assert", 0, ASSERT, VERB },
{"b", 0, REGNAME, I8080 | Z80 },
{"bc", 0, RP, Z80 },
{"bit", 0145500,BIT, VERB | Z80 },
{"bitx", 0xdd46, BIT_XY, VERB | Z80 | ZNONSTD },
{"bity", 0xfd46, BIT_XY, VERB | Z80 | ZNONSTD },
{".block", 0, DEFS, VERB },
{".byte", 0, DEFB, VERB },
{"c", 1, C, I8080 | Z80 },
{"call", 0315, CALL, VERB | I8080 | Z80 },
{"cc", 0334, CALL8, VERB | I8080 },
{"ccd", 0xeda9, NOOPERAND, VERB | Z80 | ZNONSTD },
{"ccdr", 0xedb9, NOOPERAND, VERB | Z80 | ZNONSTD },
{"ccf", 077, NOOPERAND, VERB | Z80 },
{"cci", 0xeda1, NOOPERAND, VERB | Z80 | ZNONSTD },
{"ccir", 0xedb1, NOOPERAND, VERB | Z80 | ZNONSTD },
{"cm", 0374, CALL8, VERB | I8080 },
{"cma", 057, NOOPERAND, VERB | I8080 },
{"cmc", 077, NOOPERAND, VERB | I8080 },
{"cmp", 7, LOGICAL, VERB | I8080 },
{"cmpx", 0xddbe, ALU_XY, VERB | Z80 | ZNONSTD },
{"cmpy", 0xfdbe, ALU_XY, VERB | Z80 | ZNONSTD },
{"cnc", 0324, CALL8, VERB | I8080 },
{"cnz", 0304, CALL8, VERB | I8080 },
{".comment", SPCOM, SPECIAL, VERB },
{".cond", 0, IF_TK, VERB },
{"cp", 7, LOGICAL, VERB | I8080 | Z80 },
{"cpd", 0166651,NOOPERAND, VERB | Z80 },
{"cpdr", 0166671,NOOPERAND, VERB | Z80 },
{"cpe", 0354, CALL8, VERB | I8080 },
{"cpi", 0166641,NOOPERAND, VERB | I8080 | Z80 },
{"cpir", 0166661,NOOPERAND, VERB | Z80 },
{"cpl", 057, NOOPERAND, VERB | Z80 },
{"cpo", 0344, CALL8, VERB | I8080 },
{".cseg", SEG_CODE,SETSEG, VERB },
{"cz", 0314, CALL8, VERB | I8080 },
{"d", 2, REGNAME, I8080 | Z80 },
{"daa", 0047, NOOPERAND, VERB | I8080 | Z80 },
{"dad", 0, DAD, VERB | I8080 },
{"dadc", 0xed4a, ARITH16, VERB | Z80 | ZNONSTD },
{"dadx", 0xdd09, ARITH16, VERB | Z80 | ZNONSTD },
{"dady", 0xfd09, ARITH16, VERB | Z80 | ZNONSTD },
{".db", 0, DEFB, VERB },
{".dc", 0, DC, VERB },
{"dcr", 1, INRDCR, VERB | I8080 },
{"dcrx", 0xdd35, ALU_XY, VERB | Z80 | ZNONSTD },
{"dcry", 0xfd35, ALU_XY, VERB | Z80 | ZNONSTD },
{"dcx", 1, INXDCX, VERB | I8080 },
{"dcxix", 0xdd2b, NOOPERAND, VERB | Z80 | ZNONSTD },
{"dcxiy", 0xfd2b, NOOPERAND, VERB | Z80 | ZNONSTD },
{"de", 020, RP, Z80 },
{"dec", 1, INCDEC, VERB | I8080 | Z80 },
{".defb", 0, DEFB, VERB },
{".defd", 0, DEFD, VERB },
{".defl", 0, DEFL, VERB },
{".defm", 0, DEFB, VERB },
{".defs", 0, DEFS, VERB },
{".defw", 0, DEFW, VERB },
{".dephase", 0, DEPHASE, VERB },
{"di", 0363, NOOPERAND, VERB | I8080 | Z80 },
{"djnz", 020, DJNZ, VERB | Z80 },
{".ds", 0, DEFS, VERB },
{"dsbc", 0xed42, ARITH16, VERB | Z80 | ZNONSTD },
{".dseg", SEG_DATA,SETSEG, VERB },
{".dw", 0, DEFW, VERB },
{".dword", 0, DEFD, VERB },
{"e", 3, REGNAME, I8080 | Z80 },
{"ei", 0373, NOOPERAND, VERB | I8080 | Z80 },
{".eject", 1, LIST, VERB },
{".elist", 3, LIST, VERB },
{".else", 0, ELSE_TK, VERB },
{".end", 0, END, VERB },
{".endc", 0, ENDIF_TK, VERB },
{".endif", 0, ENDIF_TK, VERB },
{".endm", 0, ENDM, VERB },
{ ".endr", 0, ENDM, VERB },
{".entry", 0, PUBLIC, VERB },
{"eq", 0, '=', 0 },
{".equ", 0, EQU, VERB },
{"ex", 0, EX, VERB | Z80 },
{"exaf", 0x08, NOOPERAND, VERB | Z80 | ZNONSTD },
{".exitm", 0, EXITM, VERB },
{".ext", 0, EXTRN, VERB },
{".extern", 0, EXTRN, VERB },
{".extrn", 0, EXTRN, VERB },
{"exx", 0331, NOOPERAND, VERB | Z80 },
{".flist", 4, LIST, VERB },
{"ge", 0, GE, 0 },
{".glist", 5, LIST, VERB },
{".global", 0, PUBLIC, VERB },
{"gt", 0, GT, 0 },
{"h", 4, REGNAME, I8080 | Z80 },
{"halt", 0166, NOOPERAND, VERB | Z80 },
{"high", 0, HIGH, 0 },
{"hl", 040, HL, Z80 },
{"hlt", 0166, NOOPERAND, VERB | I8080 },
{"i", 0, MISCREG, Z80 },
{".if", 0, IF_TK, VERB | COL0 },
{"im", 0166506,IM, VERB | Z80 },
{"im0", 0xed46, NOOPERAND, VERB | Z80 | ZNONSTD },
{"im1", 0xed56, NOOPERAND, VERB | Z80 | ZNONSTD },
{"im2", 0xed5e, NOOPERAND, VERB | Z80 | ZNONSTD },
{"in", 0333, TK_IN, VERB | I8080 | Z80 },
{"inc", 0, INCDEC, VERB | Z80 },
{".incbin", 0, INCBIN, VERB },
{".include", PSINC, ARGPSEUDO, VERB },
{"ind", 0166652,NOOPERAND, VERB | Z80 },
{"indr", 0166672,NOOPERAND, VERB | Z80 },
{"ini", 0166642,NOOPERAND, VERB | Z80 },
{"inir", 0166662,NOOPERAND, VERB | Z80 },
{"inp", 0, INP, VERB | Z80 | ZNONSTD },
{"inr", 0, INRDCR, VERB | I8080 },
{"inrx", 0xdd34, ALU_XY, VERB | Z80 | ZNONSTD },
{"inry", 0xfd34, ALU_XY, VERB | Z80 | ZNONSTD },
{"inx", 0, INXDCX, VERB | I8080 },
{"inxix", 0xdd23, NOOPERAND, VERB | Z80 | ZNONSTD },
{"inxiy", 0xfd23, NOOPERAND, VERB | Z80 | ZNONSTD },
{"irp", 0, IRP, VERB },
{"irpc", 0, IRPC, VERB },
{"ix", 0156440,INDEX, Z80 },
{"ixh", 0x1DD04,IXYLH, Z80 | UNDOC },
{"ixl", 0x1DD05,IXYLH, Z80 | UNDOC },
{"iy", 0176440,INDEX, Z80 },
{"iyh", 0x1FD04,IXYLH, Z80 | UNDOC },
{"iyl", 0x1FD05,IXYLH, Z80 | UNDOC },
{"jc", 0332, JUMP8, VERB | I8080 },
{"jm", 0372, JUMP8, VERB | I8080 },
{"jmp", 0303, JP, VERB | I8080 },
{"jnc", 0322, JUMP8, VERB | I8080 },
{"jnz", 0302, JUMP8, VERB | I8080 },
{"jp", 0, JP, VERB | I8080 | Z80 },
{"jpe", 0352, JUMP8, VERB | I8080 },
{".jperror", 0, JPERROR, VERB },
{"jpo", 0342, JUMP8, VERB | I8080 },
{"jr", 040, JR, VERB | Z80 },
{"jrc", 0x38, JR_COND, VERB | Z80 | ZNONSTD },
{"jrnc", 0x30, JR_COND, VERB | Z80 | ZNONSTD },
{"jrnz", 0x20, JR_COND, VERB | Z80 | ZNONSTD },
{".jrpromote", 0, JRPROMOTE, VERB },
{"jrz", 0x28, JR_COND, VERB | Z80 | ZNONSTD },
{"jz", 0312, JUMP8, VERB | I8080 },
{"l", 5, REGNAME, I8080 | Z80 },
{"lbcd", 0xed4b, LDST16, VERB | Z80 | ZNONSTD },
{"ld", 0, LD, VERB | Z80 },
{"lda", 0, LDA, VERB | I8080 },
{"ldai", 0xed57, NOOPERAND, VERB | Z80 | ZNONSTD },
{"ldar", 0xed5f, NOOPERAND, VERB | Z80 | ZNONSTD },
{"ldax", 0, LDAX, VERB | I8080 },
{"ldd", 0166650,NOOPERAND, VERB | Z80 },
{"lddr", 0166670,NOOPERAND, VERB | Z80 },
{"lded", 0xed5b, LDST16, VERB | Z80 | ZNONSTD },
{"ldi", 0166640,NOOPERAND, VERB | Z80 },
{"ldir", 0166660,NOOPERAND, VERB | Z80 },
{"ldx", 0xdd46, LD_XY, VERB | Z80 | ZNONSTD},
{"ldy", 0xfd46, LD_XY, VERB | Z80 | ZNONSTD},
{"le", 0, LE, 0 },
{"lhld", 0, LHLD, VERB | I8080 },
{".list", 0, LIST, VERB },
{"lixd", 0xdd2a, LDST16, VERB | Z80 | ZNONSTD },
{"liyd", 0xfd2a, LDST16, VERB | Z80 | ZNONSTD },
{".local", 0, LOCAL, VERB },
{"low", 0, LOW, 0 },
{"lspd", 0xed7b, LDST16, VERB | Z80 | ZNONSTD },
{"lt", 0, LT, 0 },
{"lxi", 0, LXI, VERB | I8080 },
{"lxix", 0xdd21, LDST16, VERB | Z80 | ZNONSTD },
{"lxiy", 0xfd21, LDST16, VERB | Z80 | ZNONSTD },
{"m", 070, COND, I8080 | Z80 },
{".maclib", PSMACLIB,ARGPSEUDO, VERB },
{".macro", 0, MACRO, VERB },
{".max", 1, MINMAX, VERB },
{".min", 0, MINMAX, VERB },
{".mlist", 6, LIST, VERB },
{"mod", 0, MOD, 0 },
{"mov", 0, MOV, VERB | I8080 },
{"mvi", 0, MVI, VERB | I8080 },
{"mvix", 0xdd36, MV_XY, VERB | Z80 | ZNONSTD },
{"mviy", 0xfd36, MV_XY, VERB | Z80 | ZNONSTD },
{".name", SPNAME, SPECIAL, VERB },
{"nc", 020, SPCOND, 0 },
{"ne", 0, NE, 0 },
{"neg", 0166504,NOOPERAND, VERB | Z80 },
{".nolist", -1, LIST, VERB },
{"nop", 0, NOOPERAND, VERB | I8080 | Z80 },
{"not", 0, NOT, 0 },
{"nul", 0, NUL, 0 },
{"nv", 040, COND, Z80 },
{"nz", 0, SPCOND, Z80 },
{"ocf", 0, OCF, 0 },
{"or", 6, OR, VERB | Z80 | TERM },
{"ora", 6, LOGICAL, VERB | I8080 },
{".org", 0, ORG, VERB },
{"ori", 0366, ALUI8, VERB | I8080 },
{"orx", 0xddb6, ALU_XY, VERB | Z80 | ZNONSTD },
{"ory", 0xfdb6, ALU_XY, VERB | Z80 | ZNONSTD },
{"otdr", 0166673,NOOPERAND, VERB | Z80 },
{"otir", 0166663,NOOPERAND, VERB | Z80 },
{"out", 0323, TK_OUT, VERB | I8080 | Z80 },
{"outd", 0166653,NOOPERAND, VERB | Z80 },
{"outdr", 0166673,NOOPERAND, VERB | Z80 | ZNONSTD },
{"outi", 0166643,NOOPERAND, VERB | Z80 },
{"outir", 0166663,NOOPERAND, VERB | Z80 | ZNONSTD },
{"outp", 0, OUTP, VERB | Z80 | ZNONSTD },
{"p", 060, COND, Z80 },
{".page", 1, LIST, VERB },
{"pchl", 0351, NOOPERAND, VERB | I8080 },
{"pcix", 0xdde9, NOOPERAND, VERB | Z80 | ZNONSTD },
{"pciy", 0xfde9, NOOPERAND, VERB | Z80 | ZNONSTD },
{"pe", 050, COND, Z80 },
{"pfix", 0xdd, NOOPERAND, VERB | Z80 | UNDOC },
{"pfiy", 0xfd, NOOPERAND, VERB | Z80 | UNDOC },
{".phase", 0, PHASE, VERB },
{"po", 040, COND, Z80 },
{"pop", 0301, PUSHPOP, VERB | I8080 | Z80 },
{"popix", 0xdde1, NOOPERAND, VERB | Z80 | ZNONSTD },
{"popiy", 0xfde1, NOOPERAND, VERB | Z80 | ZNONSTD },
{"pragma", SPPRAGMA,SPECIAL, VERB },
{"psw", 060, PSW, I8080 },
{".public", 0, PUBLIC, VERB },
{"push", 0305, PUSHPOP, VERB | I8080 | Z80 },
{"pushix", 0xdde5, NOOPERAND, VERB | Z80 | ZNONSTD },
{"pushiy", 0xfde5, NOOPERAND, VERB | Z80 | ZNONSTD },
{"r", 010, MISCREG, Z80 },
{"ral", 027, NOOPERAND, VERB | I8080 },
{"ralr", 2, SHIFT, VERB | Z80 | ZNONSTD },
{"ralx", 0xdd16, SHIFT_XY, VERB | Z80 | ZNONSTD },
{"raly", 0xfd16, SHIFT_XY, VERB | Z80 | ZNONSTD },
{"rar", 037, NOOPERAND, VERB | I8080 },
{"rarr", 3, SHIFT, VERB | Z80 | ZNONSTD },
{"rarx", 0xdd1e, SHIFT_XY, VERB | Z80 | ZNONSTD },
{"rary", 0xfd1e, SHIFT_XY, VERB | Z80 | ZNONSTD },
{"rc", 0330, NOOPERAND, VERB | I8080 },
{".read", PSINC, ARGPSEUDO, VERB },
{"rept", 0, REPT, VERB },
{"res", 0145600,BIT, VERB | Z80 },
{"resx", 0xdd86, BIT_XY, VERB | Z80 | ZNONSTD },
{"resy", 0xfd86, BIT_XY, VERB | Z80 | ZNONSTD },
{"ret", 0311, RET, VERB | I8080 | Z80 },
{"reti", 0166515,NOOPERAND, VERB | Z80 },
{"retn", 0166505,NOOPERAND, VERB | Z80 },
{"rl", 2, SHIFT, VERB | Z80 },
{"rla", 027, NOOPERAND, VERB | Z80 },
{"rlc", 0, SHIFT, VERB | I8080 | Z80 },
{"rlca", 07, NOOPERAND, VERB | Z80 },
{"rlcr", 0, SHIFT, VERB | I8080 | Z80 | ZNONSTD },
{"rlcx", 0xdd06, SHIFT_XY, VERB | Z80 | ZNONSTD },
{"rlcy", 0xfd06, SHIFT_XY, VERB | Z80 | ZNONSTD },
{"rld", 0166557,NOOPERAND, VERB | Z80 },
{"rm", 0370, NOOPERAND, VERB | I8080 },
{".rmem", 0, DEFS, VERB },
{"rnc", 0320, NOOPERAND, VERB | I8080 },
{"rnz", 0300, NOOPERAND, VERB | I8080 },
{"rp", 0360, NOOPERAND, VERB | I8080 },
{"rpe", 0350, NOOPERAND, VERB | I8080 },
{"rpo", 0340, NOOPERAND, VERB | I8080 },
{"rr", 3, SHIFT, VERB | Z80 },
{"rra", 037, NOOPERAND, VERB | Z80 },
{"rrc", 1, SHIFT, VERB | I8080 | Z80 },
{"rrca", 017, NOOPERAND, VERB | Z80 },
{"rrcr", 1, SHIFT, VERB | Z80 | ZNONSTD },
{"rrcx", 0xdd0e, SHIFT_XY, VERB | Z80 | ZNONSTD },
{"rrcy", 0xfd0e, SHIFT_XY, VERB | Z80 | ZNONSTD },
{"rrd", 0166547,NOOPERAND, VERB | Z80 },
{"rst", 0307, RST, VERB | I8080 | Z80 },
{".rsym", PSRSYM, ARGPSEUDO, VERB },
{"rz", 0310, NOOPERAND, VERB | I8080 },
{"sbb", 3, ARITHC, VERB | I8080 },
{"sbc", 3, ARITHC, VERB | Z80 },
{"sbcd", 0xed43, LDST16, VERB | Z80 | ZNONSTD },
{"sbcx", 0xdd9e, ALU_XY, VERB | Z80 | ZNONSTD },
{"sbcy", 0xfd9e, ALU_XY, VERB | Z80 | ZNONSTD },
{"sbi", 0336, ALUI8, VERB | I8080 },
{"scf", 067, NOOPERAND, VERB | Z80 },
{"sded", 0xed53, LDST16, VERB | Z80 | ZNONSTD },
{"set", 0145700,BIT, VERB | Z80 },
{"setb", 0145700,BIT, VERB | Z80 | ZNONSTD },
{".setocf", 0, SETOCF, VERB },
{".sett", 0, TSTATE, VERB },
{"setx", 0xddc6, BIT_XY, VERB | Z80 | ZNONSTD },
{"sety", 0xfdc6, BIT_XY, VERB | Z80 | ZNONSTD },
{"shl", 0, SHL, TERM },
{"shld", 0, SHLD, VERB | I8080 },
{"shr", 0, SHR, TERM },
{"sixd", 0xdd22, LDST16, VERB | Z80 | ZNONSTD },
{"siyd", 0xfd22, LDST16, VERB | Z80 | ZNONSTD },
{"sl1", 6, SHIFT, VERB | Z80 | UNDOC },
{"sla", 4, SHIFT, VERB | Z80 },
{"slar", 4, SHIFT, VERB | Z80 | ZNONSTD },
{"slax", 0xdd26, SHIFT_XY, VERB | Z80 | ZNONSTD },
{"slay", 0xfd26, SHIFT_XY, VERB | Z80 | ZNONSTD },
{"sll", 6, SHIFT, VERB | Z80 },
{"sp", 060, SP, I8080 | Z80 },
{".space", 2, LIST, VERB },
{"sphl", 0371, NOOPERAND, VERB | I8080 },
{"spix", 0xddf9, NOOPERAND, VERB | Z80 | ZNONSTD },
{"spiy", 0xfdf9, NOOPERAND, VERB | Z80 | ZNONSTD },
{"sra", 5, SHIFT, VERB | Z80 },
{"srar", 5, SHIFT, VERB | Z80 | ZNONSTD },
{"srax", 0xdd2e, SHIFT_XY, VERB | Z80 | ZNONSTD },
{"sray", 0xfd2e, SHIFT_XY, VERB | Z80 | ZNONSTD },
{"srl", 7, SHIFT, VERB | Z80 },
{"srlr", 7, SHIFT, VERB | Z80 | ZNONSTD },
{"srlx", 0xdd3e, SHIFT_XY, VERB | Z80 | ZNONSTD },
{"srly", 0xfd3e, SHIFT_XY, VERB | Z80 | ZNONSTD },
{"sspd", 0xed73, LDST16, VERB | Z80 | ZNONSTD },
{"sta", 0, STA, VERB | I8080 },
{"stai", 0xed47, NOOPERAND, VERB | Z80 | ZNONSTD },
{"star", 0xed4f, NOOPERAND, VERB | Z80 | ZNONSTD },
{"stax", 0, STAX, VERB | I8080 },
{"stc", 067, NOOPERAND, VERB | I8080 },
{"stx", 0xdd70, ST_XY, VERB | Z80 | ZNONSTD},
{"sty", 0xfd70, ST_XY, VERB | Z80 | ZNONSTD},
{"sub", 2, LOGICAL, VERB | I8080 | Z80 },
{".subttl", SPSBTL, SPECIAL, VERB },
{"subx", 0xdd96, ALU_XY, VERB | Z80 | ZNONSTD },
{"suby", 0xfd96, ALU_XY, VERB | Z80 | ZNONSTD },
{"sui", 0326, ALUI8, VERB | I8080 },
{"t", 0, T, 0 },
{".text", 0, DEFB, VERB },
{"tihi", 0, TIHI, 0 },
{"tilo", 0, TILO, 0 },
{".title", SPTITL, SPECIAL, VERB },
{".tstate", 0, TSTATE, VERB },
{"v", 050, COND, Z80 },
{".word", 0, DEFW, VERB },
{".wsym", PSWSYM, ARGPSEUDO, VERB },
{"xchg", 0353, NOOPERAND, VERB | I8080 },
{ ".xlist", -1, LIST, VERB },
{"xor", 5, XOR, VERB | Z80 | TERM },
{"xorx", 0xddae, ALU_XY, VERB | Z80 | ZNONSTD },
{"xory", 0xfdae, ALU_XY, VERB | Z80 | ZNONSTD },
{"xra", 5, LOGICAL, VERB | I8080 },
{"xri", 0356, ALUI8, VERB | I8080 },
{"xthl", 0343, NOOPERAND, VERB | I8080 },
{"xtix", 0xdde3, NOOPERAND, VERB | Z80 | ZNONSTD },
{"xtiy", 0xfde3, NOOPERAND, VERB | Z80 | ZNONSTD },
{"z", 010, SPCOND, Z80 },
{".z80", 1, INSTSET, VERB },
};
/*
* user-defined items are tabulated in the following table.
*/
struct item itemtab[ITEMTABLESIZE];
struct item *itemmax = itemtab+ITEMTABLESIZE;
/*
* lexical analyser, called by yyparse.
*/
int yylex()
{
int c;
char *p;
int radix;
int sep;
char *d0=0, *dn=0;
int exclude, include, overflow;
if (arg_flag) {
yylval.cval = arg_state.arg;
c = getarg(&arg_state);
if (c == '\0' || c == '\n' || c == ';')
c = skipline(c);
return c;
}
if (raw == 2) {
while (charclass[c = nextchar()] == SPACE)
;
*tempbuf = c == '\n' || c == '\0';
peekc = skipline(c);
raw = 0;
return RAWTOKEN;
}
else if (raw) {
int skip = 1;
p = tempbuf;
while ((c = nextchar()) != '\n' && c) {
if (p >= tempmax) {
*p = '\0';
printf("was parsing '%s'\n", tempbuf);
error(symlong);
}
if (!skip || charclass[c] != SPACE) {
*p++ = c;
skip = 0;
}
}
if (c == 0)
peekc = c;
*p-- = '\0';
while (p >= tempbuf && charclass[*p] == SPACE)
*p-- = '\0';
raw = 0;
return RAWTOKEN;
}
for (;;) {
c = nextchar();
switch (charclass[c]) {
case F_END:
if (!expptr)
return 0;
if (est[MSTR].param) {
int ch;
est[REPNUM].value++;
ch = est[MSTR].param[est[REPNUM].value];
if (ch) {
est[0].param[0] = ch;
floc = est[MSTART].value;
mfseek(mfile, (long)floc, 0);
est[TEMPNUM].value = exp_number++;
}
else {
free(est[MSTR].param);
est[MSTR].param = 0;
popsi();
}
}
else if (est[REPNUM].value < 0) {
int arg;
do {
switch (getarg(est[MARGP].ap)) {
case ARG:
arg = 1;
break;
case ',':
arg = 0;
break;
default:
arg = 2;
break;
}
} while (!arg);
if (arg == 1) {
floc = est[MSTART].value;
mfseek(mfile, (long)floc, 0);
est[TEMPNUM].value = exp_number++;
}
else {
// XXX - memory leak
est[0].param = NULL;
free(est[MARGP].ap);
popsi();
}
}
else if (est[REPNUM].value-- > 0) {
floc = est[MSTART].value;
mfseek(mfile, (long)floc, 0);
est[TEMPNUM].value = exp_number++;
}
else
popsi();
continue;
case SPACE:
while (charclass[c = nextchar()] == SPACE)
;
peekc = c;
logcol++;
break;
case LETTER:
case STARTER:
case DIGIT:
case DOLLAR:
spectok :
firstcol = getcol() == 1;
radix = -1; // might be a number
p = tempbuf;
do {
if (p >= tempmax) {
*tempmax = '\0';
printf("was parsing '%s'\n", tempbuf);
error(symlong);
}
*p = (c >= 'A' && c <= 'Z') ? c + 'a' - 'A' : c;
if (mras && *p == '?') {
char *q;
radix = 0; // can't be a number even if it looks like it
if (expptr)
q = getmraslocal();
else
for (q = modstr; *q == '@'; q++)
;
if (*q) {
strcpy(p, q);
p = strchr(p, '\0') - 1;
}
else
*p = '?';
}
p++;
c = nextchar();
} while (charclass[c] == LETTER || charclass[c] == DIGIT ||
charclass[c] == STARTER || charclass[c] == DOLLAR);
*p = '\0';
// When parsing macro parameters we use a custom symbol table.
// And, heck, almost anything goes.
if (param_parse) {
struct item *param = item_lookup(tempbuf, paramtab, PARAMTABSIZE);
peekc = c;
if (param->i_token) {
sprintf(detail, "%s error. Macro parameter '%s' repeated",
errname[fflag], tempbuf);
errwarn(fflag, detail);
}
param->i_token = MPARM;
param->i_string = malloc(strlen(tempbuf) + 1);
strcpy(param->i_string, tempbuf);
yylval.itemptr = param;
return param->i_token;
}
// Special case for AF'
if (c == '\'' && strcmp(tempbuf, "af") == 0)
return AFp;
peekc = c;
// Pass off '?' (XXX but, technically, should only be done in expression context)
if (strcmp(tempbuf, "?") == 0)
return '?';
// Pass off '$'
if (strcmp(tempbuf, "$") == 0)
return '$';
// Look ahead at what we have.
while (charclass[c] == SPACE)
c = nextchar();
peekc = c;
//printf("%d %s\n", logcol, tempbuf);
// If logcol == 0 then if c == ':' we're a label for sure.
// If logcol == 1 if c == ':' we're a label, change logcol
// otherwise we're op or pseudo
// If logcol == 0 and c == '\n' or ';' then we're alone so
// we give tokenization a chance otherwise label
// If logcol >= 2 we're in the arguments
//
// There is quite a lot of unrealized scope for error
// detection and helpful warnings.
// Default to any tokenization.
exclude = 0;
include = 0;
if (logcol >= 2) {
// Arguments allow mnemonics and psuedo-ops
exclude = VERB;
include = TERM;
}
else if (logcol == 0 && c != ';' && c != '\n') {
exclude = ~TERM;
include = COL0;
}
else if (logcol == 1 && c == ':') {
exclude = ~TERM;
logcol = 0;
}
logcol++;
// Look for possible numbers.
// 0x<hex> $<hex> <hex>h <octal>o <octal>q <binary>b
// <decimal> <decimal>d
// Suffix formats must start with 0-9.
if (radix) {
if (tempbuf[0] == '0' && tempbuf[1] == 'x' && tempbuf[2]) {
radix = 16;
d0 = tempbuf + 2;
dn = p;
}
else if (tempbuf[0] == '$') {
radix = 16;
d0 = tempbuf + 1;
dn = p;
}
else if (tempbuf[0] >= '0' && tempbuf[0] <= '9') {
d0 = tempbuf;
dn = p - 1;
switch (*dn) {
case 'o':
case 'q':
radix = 8;
break;
case 'd':
radix = 10;
break;
case 'h':
radix = 16;
break;
case 'b':
radix = 2;
break;
default:
radix = 10;
dn++;
}
}
}
// We may have a number on our hands.
if (radix > 0) {
overflow = 0;
yylval.ival = 0;
for (; d0 < dn; d0++) {
unsigned int ovchk = (unsigned int)yylval.ival;
c = *d0 - (*d0 > '9' ? ('a' - 10) : '0');
if (c < 0 || c >= radix) {
radix = 0;
break;
}
if (ovchk * radix / radix != ovchk)
overflow = 1;
yylval.ival *= radix;
yylval.ival += c;
}
}
// If we're in the first logical column and the token starts with
// '$' then we'll force it to be a label even though it could be
// a $hex constant. This will allow $FCB as a label.
// Thus we must also allow symbol lookup a chance to override number
// parsing if we start with a '$'.
if (tempbuf[0] == '$') {
if (logcol == 1 || locate(tempbuf)->i_token) {
if (radix > 0) {
sprintf(detail, "warning: $hex constant '%s' interpreted as symbol", tempbuf);
errwarn(warn_hex, detail);
}
radix = 0;
}
}
if (radix > 0) {
// Might be line skipping time, though.
if (*ifptr)
return skipline(c);
if (overflow) {
err[iflag]++;
yylval.ival = 0;
}
return NUMBER;
}
// Too late to do '$' concatenation of numbers. But zmac
// didn't allow for that previously at any rate.
if (zcompat) {
char *q = tempbuf;
// Normal zmac operation requires we ignore $ in identifiers
for (p = q; *p; p++)
if (*p != '$')
*q++ = *p;
*q = '\0';
p = q;
}
// GWP - boy, this should be a warning or error
if (p - tempbuf > MAXSYMBOLSIZE) {
p = tempbuf + MAXSYMBOLSIZE;
*p = '\0';
}
return tokenofitem(UNDECLARED, exclude, include);
default:
if (*ifptr)
return(skipline(c));
if (mras && getcol() == 1 && c == '*')
goto spectok;
switch (c) {
int corig;
case ':':
if (logcol == 1) {
// Make sure "label:ret", "label: ret",
// "label: :ret", "label: : ret" work out OK.
// But stop fooling around once we've done the VERB
peekc = nextchar();
if (charclass[peekc] == SPACE)
logcol--;
}
return c;
case ';':
return(skipline(c));
case '\'':
case '"':
sep = c;
p = tempbuf;
p[1] = 0;
do switch (c = nextchar()) {
case '\0':
case '\n':
err[bflag]++;
goto retstring;
default:
if (c == sep && (c = nextchar()) != sep) {
retstring:
peekc = c;
*p = '\0';
switch (p - tempbuf) {
case 2:
p = tempbuf;
yylval.ival = *p++ & 255;
yylval.ival |= (*p & 255) << 8;
return TWOCHAR;
case 1:
p = tempbuf;
yylval.ival = *p++;
return ONECHAR;
case 0:
if (!full_exprs) {
yylval.ival = 0;
return NUMBER;
}
// fall through
default:
yylval.cval = tempbuf;
return STRING;
}
}
*p++ = c;
} while (p < tempmax);
/*
* if we break out here, our string is longer than
* our input line
*/
error("string buffer overflow");
case '<':
corig = c;
switch (c = nextchar()) {
case '=':
return LE;
case '<':
return SHL;
case '>':
return NE;
default:
peekc = c;
return corig;
}
/* break; suppress "unreachable" warning for tcc */
case '>':
corig = c;
switch (c = nextchar()) {
case '=':
return GE;
case '>':
return SHR;
default:
peekc = c;
return corig;
}
/* break; suppress "unreachable" warning for tcc */
case '!':
corig = c;
switch (c = nextchar()) {
case '=':
return NE;
default:
peekc = c;
return corig;
}
/* break; suppress "unreachable" warning for tcc */
case '=':
corig = c;
switch (c = nextchar()) {
case '=':
return '=';
default:
peekc = c;
return corig;
}
/* break; suppress "unreachable" warning for tcc */
case '&':
corig = c;
if ((c = nextchar()) == '&')
return ANDAND;
else {
peekc = c;
return corig;
}
/* break; suppress "unreachable" warning for tcc */
case '|':
corig = c;
if ((c = nextchar()) == '|')
return OROR;
else {
peekc = c;
return corig;
}
/* break; suppress "unreachable" warning for tcc */
default:
return(c);
}
}
}
}
// Verify keytab is in alphabetical order.
int check_keytab()
{
int i;
char *prev=keytab[0].i_string;
for (i = 0; i < sizeof(keytab) / sizeof(keytab[0]); i++) {
char *next = keytab[i].i_string;
next += *next == '.';
if (i != 0) {
if (strcmp(prev, next) >= 0) {
printf("keytab error: %s >= %s\n", prev, next);
return 0;
}
}
prev = next;
}
printf("keytab OK\n");
return 1;
}
struct item *keyword(char *name)
{
int r, l, u;
struct item *ip;
/*
* binary search
*/
l = 0;
u = (sizeof keytab/sizeof keytab[0])-1;
while (l <= u) {
char *key;
i = (l+u)/2;
ip = &keytab[i];
key = ip->i_string;
r = strcmp(name + (name[0] == '.'), key + (key[0] == '.'));
if (r == 0) {
// Do not allow ".foo" to match "foo"
if (name[0] == '.' && key[0] != '.')
break;
return ip;
}
if (r < 0)
u = i-1;
else
l = i+1;
}
return 0;
}
// Find 'name' in an item table. Returns an empty slot if not found.
// Uses case-independent comparisions which are largely wasted as
// there is only 1 case where 'name' has not already been lowercased.
struct item *item_lookup(char *name, struct item *table, int table_size)
{
struct item *ip;
/*
* hash into item table
*/
int hash = 0;
char *p = name;
while (*p) {
char ch = *p++;
if (ch >= 'A' && ch <= 'Z') ch += 'a' - 'A';
hash += ch;
}
hash %= table_size;
ip = &table[hash];
for (;;) {
if (ip->i_token == 0)
break;
if (ci_strcmp(name, ip->i_string) == 0)
break;
if (++ip >= table + table_size)
ip = table;
}
return ip;
}
struct item *locate(char *name)
{
return item_lookup(name, itemtab, ITEMTABLESIZE);
}
/*
* return the token associated with the string pointed to by
* tempbuf. if no token is associated with the string, associate
* deftoken with the string and return deftoken.
* in either case, cause yylval to point to the relevant
* symbol table entry.
*
* Only keys not matching the keyexclude will be returned allowing
* context-dependent tokenization. Unless they match keyinclude.
*/
int tokenofitem(int deftoken, int keyexclude, int keyinclude)
{
struct item *ip;
int i;
#ifdef T_DEBUG
fputs("'tokenofitem entry' ", stderr) ;
fputs(tempbuf, stderr) ;
#endif
// Allow macros to override built-ins
// Maybe shouldn't be done for identifiers that will undergo
// '.' and '_' expansion.
ip = locate(tempbuf);
if (ip->i_token == MNAME)
goto found;
if (full_exprs)
keyexclude = ~TERM;
ip = keyword(tempbuf);
if (ip) {
if (ip->i_uses & keyinclude)
goto found;
if (!(ip->i_uses & keyexclude))
goto found;
}
// This is really my own thing rather than old zmac, but zmac
// didn't support it and it does depend on '$' crushing a bit.
if (zcompat) {
// '_' prefixed labels are local to the file
if (tempbuf[0] == '_') {
strcat(tempbuf, "$");
strcat(tempbuf, basename(src_name[now_in]));
}
// '.' prefixed labels are local between labels
if (tempbuf[0] == '.') {
char *p = tempbuf;
while (*p) p++;
sprintf(p, "$%d", llseq);
}
}
ip = locate(tempbuf);
if (ip->i_token)
goto found;
if (!deftoken) {
i = 0 ;
goto token_done ;
}
if (++nitems > ITEMTABLESIZE-20)
error("item table overflow");
ip->i_string = malloc(strlen(tempbuf)+1);
ip->i_token = deftoken;
ip->i_uses = 0;
strcpy(ip->i_string, tempbuf);
found:
if (*ifptr) {
if (ip->i_token == ENDIF_TK) {
i = ENDIF_TK;
goto token_done ;
}
if (ip->i_token == ELSE_TK) {
/* We must only honour the ELSE if it is not
in a nested failed IF/ELSE */
char forbid = 0;
char *ifstackptr;
for (ifstackptr = ifstack; ifstackptr != ifptr; ++ifstackptr) {
if (*ifstackptr) {
forbid = 1;
break;
}
}
if (!forbid) {
i = ELSE_TK;
goto token_done;
}
}
if (ip->i_token == IF_TK) {
if (ifptr >= ifstmax)
error("Too many ifs");
else *++ifptr = 1;
}
i = skipline(' ');
goto token_done ;
}
yylval.itemptr = ip;
i = ip->i_token;
token_done:
#ifdef T_DEBUG
fputs("\t'tokenofitem exit'\n", stderr) ;
#endif
return(i) ;
}
void itemcpy(struct item *dst, struct item *src)
{
if (dst && src) {
dst->i_string = src->i_string;
dst->i_value = src->i_value;
dst->i_token = src->i_token;
dst->i_uses = src->i_uses;
dst->i_scope = src->i_scope;
dst->i_chain = src->i_chain;
}
}
/*
* interchange two entries in the item table -- used by custom_qsort
*/
void interchange(int i, int j)
{
struct item temp;
itemcpy(&temp, itemtab + i);
itemcpy(itemtab + i, itemtab + j);
itemcpy(itemtab + j, &temp);
}
/*
* quick sort -- used by compactsymtab to sort the symbol table
*/
void custom_qsort(int m, int n)
{
int i, j;
if (m < n) {
i = m;
j = n+1;
for (;;) {
do i++; while(strcmp(itemtab[i].i_string,
itemtab[m].i_string) < 0);
do j--; while(strcmp(itemtab[j].i_string,
itemtab[m].i_string) > 0);
if (i < j) interchange(i, j); else break;
}
interchange(m, j);
custom_qsort(m, j-1);
custom_qsort(j+1, n);
}
}
int getcol()
{
return inpptr - inpbuf;
}
/*
* get the next character
*/
int nextchar()
{
int c, ch;
unsigned char *p;
char *getlocal();
if (peekc != -1) {
c = peekc;
peekc = -1;
return c;
}
if (inpptr) {
// Double nul indicates EOF for macros
if (expptr && inpptr[0] == '\0' && inpptr[1] == '\0') {
inpptr = 0;
return 0;
}
if (getcol() == 0) {
void analyze_inpbuf(void);
if (!expptr)
linein[now_in]++;
analyze_inpbuf();
}
c = *inpptr++;
addtoline(c);
if (*inpptr == '\0')
inpptr = 0;
return c;
}
inpptr = inpbuf;
logcol = 0;
p = inpbuf;
// XXX - should check for input line overflow!
// If invoking a macro then pull the next line from it.
if (expptr) {
for (;;) {
ch = getm();
if (ch == '\1') { /* expand argument */
ch = getm() - 'A';
if (ch >= 0 && ch < PARMMAX && est[ch].param) {
strcpy((char *)p, est[ch].param);
p = (unsigned char *)strchr((char *)p, '\0');
}
}
else if (ch == '\2') { /* local symbol */
ch = getm() - 'A';
if (ch >= 0 && ch < PARMMAX && est[ch].param)
strcpy((char *)p, est[ch].param);
else
strcpy((char *)p, getlocal(ch, est[TEMPNUM].value));
p = (unsigned char *)strchr((char *)p, '\0');
}
else {
if (ch == 0)
break;
*p++ = ch;
if (ch == '\n')
break;
}
}
*p = '\0';
p[1] = ch;
}
else {
if (nextline_peek != -1) {
*p++ = nextline_peek;
nextline_peek = -1;
}
for (;;) {
ch = getc(now_file);
if (ch == '\r') {
nextline_peek = getc(now_file);
if (nextline_peek == '\n')
nextline_peek = -1;
else if (nextline_peek == EOF) {
*p++ = '\n';
nextline_peek = -1;
ch = EOF;
break;
}
ch = '\n';
}
if (ch == EOF)
break;
*p++ = ch;
if (ch == '\n')
break;
}
*p = '\0';
/* if EOF, check for include file */
if (ch == EOF) {
if (now_in) {
fclose(fin[now_in]) ;
free(src_name[now_in]);
now_file = fin[--now_in];
}
else if (p == inpbuf)
return 0;
if (linein[now_in] < 0) {
lstoff = 1;
linein[now_in] = -linein[now_in];
} else {
lstoff = 0 ;
}
if (outpass) {
if (iflist()) {
lineout();
fprintf(fout, "**** %s ****\n", src_name[now_in]) ;
}
if (bopt)
fprintf(fbds, "%04x %04x f %s\n", dollarsign, emit_addr, src_name[now_in]);
}
if (p != inpbuf) {
*p++='\n';
*p = '\0';
}
else
inpptr = 0;
}
}
return nextchar();
}
char *skipspace(char *p)
{
while (charclass[*p] == SPACE)
p++;
return p;
}
// Look at inpbuf and try to determine what logical column we are starting
// at. We could put all of the work in here and keep yylex simple but for
// now we share the load.
void analyze_inpbuf(void)
{
int cc;
char *p, *q, save;
char *word1, *word2;
struct item *ip, *word1item;
int triplecase = 1;
// No need to do this when pulling in data for a macro. In fact,
// in can be harmful to undef a macro.
if (inmlex)
return;
// Default if we find nothing to override
logcol = 0;
// One case to check is when you start with whitespace yet there are
// 3 columns. If so then we change logcol to -1 to compensate.
// If the 2nd column is a VERB.
// If we start with whitespace then we can give up on triple word case.
p = (char *)inpbuf;
if (charclass[*p] != SPACE)
triplecase = 0;
p = skipspace(p);
word1 = p;
// Now skip over a token or abort if we don't find one
cc = charclass[*p];
if (cc != LETTER && cc != STARTER && cc != DIGIT && cc != DOLLAR)
return;
for (;;) {
cc = charclass[*p];
if (cc == LETTER || cc == STARTER || cc == DIGIT || cc == DOLLAR)
p++;
else
break;
}
// We could skip space-separated colons now, but if we see a colon
// both issues have been decided to do that because it is easier.
if (*p == ':')
return;
save = *p;
*p = '\0';
word1item = locate(word1);
*p = save;
p = skipspace(p);
// Another token to skip past.
// But we need to examine it to see if it is a verb.
cc = charclass[*p];
if (cc != LETTER && cc != STARTER && cc != DIGIT && cc != DOLLAR)
return;
q = p;
word2 = p;
for (;;) {
cc = charclass[*p];
if (cc == LETTER || cc == STARTER || cc == DIGIT || cc == DOLLAR)
p++;
else
break;
}
// Now we have a second word we can check for the "name macro" case.
// Unless we're skipping.
save = *p;
*p = '\0';
if (ci_strcmp(word2, "macro") == 0 && word1item->i_token && !*ifptr)
word1item->i_token = UNDECLARED;
*p = save;
if (!triplecase)
return;
// Must have space to skip over
if (charclass[*p] != SPACE)
return;
// This 2nd token must be a verb.
cc = *p;
*p = '\0';
ip = keyword(q);
*p = cc;
if (!ip || !(ip->i_uses & VERB))
return;
// Now skip over space. If there's anything but a comment or end
// of the line then we've may have 3 logical columns.
// "ld a, 5" can throw that off, but we've done the verb check.
p = skipspace(p);
if (*p != ';' && *p != '\n' && *p != '\0')
logcol--;
}
/*
* skip to rest of the line -- comments and if skipped lines
*/
int skipline(int ac)
{
int c;
c = ac;
while (c != '\n' && c != '\0')
c = nextchar();
return('\n');
}
void add_incpath(char *dir)
{
char *p;
if (incpath_cnt >= MAXINCPATH) {
fprintf(stderr, "Sorry, can only handle %d include paths\n", MAXINCPATH);
exit(1);
}
p = malloc(strlen(dir) + 1);
strcpy(p, dir);
incpath[incpath_cnt++] = dir;
}
FILE *open_incpath(char *filename, char *mode)
{
char quote;
int i;
char path[1024];
FILE *fp;
// Due to the way parsing works the string can be specified
// without quotes or will allow quotes but include them. Instead
// of fooling with the parsing I just strip the quotes. I think
// you can still include a file that starts with a single or double
// quote by quoting it, but that's an awful thing to do to yourself.
quote = *filename;
if (quote == '"' || quote == '\'') {
strcpy(filename, filename + 1);
if (strrchr(filename, quote))
*strrchr(filename, quote) = '\0';
}
// First look for included file in same directory as source file.
strcpy(path, src_name[now_in]);
*basename(path) = '\0';
strcat(path, filename);
fp = fopen(path, mode);
if (fp) {
if (note_depend && outpass)
printf("%s\n", path);
return fp;
}
for (i = 0; i < incpath_cnt; i++) {
sprintf(path, "%s/%s", incpath[i], filename);
fp = fopen(path, mode);
if (fp) {
if (note_depend && outpass)
printf("%s\n", path);
return fp;
}
}
if (note_depend && outpass)
printf("%s\n", filename);
return fopen(filename, mode);
}
void version()
{
fprintf(stderr, "zmac version " VERSION "\n");
}
//
// Print out a usage message and exit.
//
void usage(char *msg, char *param)
{
fprintf(stderr, msg, param);
fprintf(stderr, "\n");
version();
fprintf(stderr, "usage: zmac [-8bcefghijJlLmnopstz] [-I dir] file[.z]\n");
fprintf(stderr, "other opts: --rel --mras --zmac --dep --help --doc --version\n");
fprintf(stderr, " zmac -h for more detail about options.\n");
exit(1);
}
void help()
{
version();
fprintf(stderr, "\t--version show version number\n");
fprintf(stderr, "\t--help\tshow this help message\n");
fprintf(stderr, "\t-8\tuse 8080 interpretation of mnemonics\n");
fprintf(stderr, "\t-b\tno binary (.hex,.cmd,.cas, etc.) output\n");
fprintf(stderr, "\t-c\tno cycle counts in listing\n");
fprintf(stderr, "\t-e\terror list only\n");
fprintf(stderr, "\t-f\tprint if skipped lines\n");
fprintf(stderr, "\t-g\tdo not list extra code\n");
fprintf(stderr, "\t-h\tshow this information about options and quit\n");
fprintf(stderr, "\t-i\tdo not list include files\n");
fprintf(stderr, "\t-I dir\tadd 'dir' to include file search path\n");
fprintf(stderr, "\t-j\tpromote relative jumps to absolute as needed\n");
fprintf(stderr, "\t-J\twarn when a jump could be relative\n");
fprintf(stderr, "\t-l\tno list\n");
fprintf(stderr, "\t-L\tforce listing of everything\n");
fprintf(stderr, "\t-m\tprint macro expansions\n");
fprintf(stderr, "\t-n\tput line numbers off\n");
fprintf(stderr, "\t-o\tlist to standard output\n");
fprintf(stderr, "\t-p\tput out four \\n's for eject\n");
fprintf(stderr, "\t-s\tdon't produce a symbol list\n");
fprintf(stderr, "\t-t\toutput error count instead of list of errors\n");
fprintf(stderr, "\t-z\tuse Z-80 interpretation of mnemonics\n");
fprintf(stderr, "\t--dep\tlist files included\n");
fprintf(stderr, "\t--mras\tlimited MRAS/EDAS compatibility\n");
fprintf(stderr, "\t--rel\toutput .rel file only\n");
fprintf(stderr, "\t--zmac\tcompatibility with original zmac\n");
fprintf(stderr, "\t--doc\toutput documentation as HTML file\n");
exit(0);
}
int mainy(int argc, char *argv[])
//int _tmain(int argc, _TCHAR* argv[])
{
//#define MYAPP_DEBUG_TRACE
#ifdef MYAPP_DEBUG_TRACE
FreeConsole();
if (AllocConsole())
{
freopen("CONOUT$", "wt", stderr);
SetConsoleTitle(L"MyApp : stderr Console");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);
printf("\n");
printf(" MyApp Debug Console\n");
printf("\n");
}
#endif
/*
FILE*fp = stdout;
stdout = stderr;
stderr = fp;
*/
/*
freopen("dev\null", "w", stdout);
freopen("dev\null", "w", stderr);
*/
struct item *ip;
int i;
int files;
#ifdef DBUG
extern yydebug;
#endif
fout = stdout ;
fin[0] = stdin ;
now_file = stdin ;
files = 0;
// Special flag for unit testing.
if (argc > 1 && strcmp(argv[1], "--test") == 0)
exit(!check_keytab());
for (i=1; i<argc; i++) {
int skip = 0;
if (strcmp(argv[i], "--mras") == 0) {
mras = 1;
continue;
}
if (strcmp(argv[i], "--rel") == 0) {
relopt = 1;
bopt = 0;
continue;
}
if (strcmp(argv[i], "--zmac") == 0) {
zcompat = 1;
continue;
}
if (strcmp(argv[i], "--dep") == 0) {
note_depend = 1;
continue;
}
if (strcmp(argv[i], "--help") == 0) {
help();
continue;
}
if (strcmp(argv[i], "--doc") == 0) {
extern void doc(void);
doc();
exit(0);
continue; // not reached
}
if (strcmp(argv[i], "--version") == 0) {
version();
exit(0);
continue; // not reached
}
if (*argv[i] == '-') while (*++argv[i]) {
switch(*argv[i]) {
case '8': /* Equivalent to .8080 */
default_z80 = 0;
continue;
case 'b': /* no binary */
bopt = 0;
continue;
case 'c': /* no cycle counts in listing */
copt-- ;
continue;
#ifdef DBUG
case 'd': /* debug */
yydebug++;
continue;
#endif
case 'e': /* error list only */
eopt = 0;
edef = 0;
continue;
case 'f': /* print if skipped lines */
fopt++;
fdef++;
continue;
case 'g': /* do not list extra code */
gopt = 0;
gdef = 0;
continue;
case 'h':
help();
continue;
case 'i': /* do not list include files */
iopt = 1 ;
continue ;
case 'I':
if (argv[i][1])
add_incpath(argv[i] + 1);
else {
i++;
if (i < argc)
add_incpath(argv[i]);
else
usage("missing argument to -I option", 0);
}
skip = 1;
break;
case 'l': /* no list */
lopt++;
continue;
case 'L': /* force listing of everything */
lston++;
continue;
case 'j': // promote relative jumps to absolute as needed
default_jopt = 1;
continue;
case 'J': // error when JR instructions could replace JP
default_JPopt = 1;
continue;
case 'm': /* print macro expansions */
mdef++;
mopt++;
continue;
case 'n': /* put line numbers off */
nopt-- ;
continue;
case 'o': /* list to standard output */
oopt++;
continue;
case 'p': /* put out four \n's for eject */
popt-- ;
continue;
case 'P': // GWP - printer style output (headers, page separation, etc.)
printer_output = 1;
continue;
case 's': /* don't produce a symbol list */
sopt++;
continue;
case 't': /* output only number of errors */
topt = 0;
continue;
case 'z': /* Equivalent to .z80 */
default_z80 = 1;
continue;
default: /* error */
usage("Unknown option", 0);
}
if (skip)
break;
}
else if (files++ == 0) {
sourcef = argv[i];
strcpy(src, sourcef);
if ((now_file = fopen(src, "r")) == NULL) {
if (!*getsuffix(src))
suffix(src, ".z");
if ((now_file = fopen(src, "r")) == NULL)
usage("Cannot open source file '%s'", src);
}
now_in = 0;
fin[now_in] = now_file ;
src_name[now_in] = src ;
} else if (files)
usage("Too many arguments", 0);
}
if (files == 0)
usage("No source file", 0);
{
char outdir[1025];
outpath(outdir, sourcef, 0);
#ifdef WIN32
_mkdir(outdir);
#else
mkdir(outdir, 0777);
#endif
}
if (bopt) {
outpath(bds, sourcef, ".bds");
fbds = fopen(bds, "w");
if (fbds == NULL)
error("Cannot create .bds file");
fprintf(fbds, "binary-debuggable-source\n");
fprintf(fbds, "%04x %04x f %s\n", dollarsign, emit_addr, src_name[now_in]);
outpath(oth, sourcef, ".cmd");
fcmd = fopen(oth, "wb");
if (fcmd == NULL)
error("Cannot create .cmd file");
outpath(oth, sourcef, ".cas");
fcas = fopen(oth, "wb");
if (fcas == NULL)
error("Cannot create .cas file");
outpath(oth, sourcef, ".lcas");
flcas = fopen(oth, "wb");
if (flcas == NULL)
error("Cannot create .lcas file");
// Tape header
for (i = 0; i < 255; i++) {
fputc(0, flcas);
fputc(0x55, fcas);
}
fputc(0xA5, flcas);
fputc(0x7F, fcas);
casname(oth, sourcef);
putcas(0x55);
for (i = 0; i < 6; i++)
putcas(oth[i]);
outpath(oth, sourcef, ".cim");
fcim = fopen(oth, "wb");
if (fcim == NULL)
error("Cannot create .cim file");
outpath(oth, sourcef, ".ams");
fams = fopen(oth, "wb");
if (fams == NULL)
error("Cannot create .ams file");
outpath(bin, sourcef, ".hex");
#ifdef MSDOS
if (( fbuf = fopen(bin, "wb")) == NULL)
#else
if (( fbuf = fopen(bin, "w")) == NULL)
#endif
error("Cannot create .hex file");
}
else if (relopt) {
outpath(oth, sourcef, ".rel");
frel = fopen(oth, "wb");
if (frel == NULL)
error("Cannot create .rel file");
strncpy(progname, basename(sourcef), sizeof progname);
progname[sizeof progname - 1] = '\0';
}
if (!lopt && !oopt) {
outpath(listf, sourcef, ".lst");
if ((fout = fopen(listf, "w")) == NULL)
error("Cannot create list file");
} else
fout = stdout ;
outpath(mtmp, sourcef, ".tmp");
#ifdef MSDOS
mfile = mfopen(mtmp,"w+b") ;
#else
mfile = mfopen(mtmp,"w+") ;
#endif
if (mfile == NULL) {
error("Cannot create temp file");
}
/*unlink(mtmp);*/
/*
* get the time
*/
time(&now);
timp = ctime(&now);
timp[16] = 0;
timp[24] = 0;
title = sourcef;
/*
* pass 1
*/
#ifdef DEBUG
fputs("DEBUG-pass 1\n", stderr) ;
#endif
clear();
setvars();
outpass = 0;
yyparse();
// GWP - errors should stop us, but the listing is very useful.
pass2++;
for (npass = 2; npass < MAXPASS; npass++) {
if (passfail || npass == MAXPASS - 1)
outpass = 1;
if (outpass) {
putrelcmd(RELCMD_PROGNAME);
putrelname(progname);
}
ip = itemtab;
ip--;
while (++ip < itemmax) {
// Output list of public labels. m80 will let
// equates and aseg values be public so we do, too.
if (outpass && ip->i_token && (ip->i_scope & SCOPE_PUBLIC)) {
putrelcmd(RELCMD_PUBLIC);
putrelname(ip->i_string);
}
/* reset use count */
ip->i_uses = 0 ;
/* set macro names, equated and defined names */
switch (ip->i_token) {
case MNAME:
ip->i_token = UNDECLARED;
break;
case EQUATED:
ip->i_token = W<PASSWORD>;
break;
case DEFLED:
if (zcompat)
ip->i_token = UNDECLARED;
break;
}
}
if (outpass) {
// m80 outputs data size as an absolute value, but
// code size as code segment relative. Odd, but
// I'll follow suit.
putrelcmd(RELCMD_DATASIZE);
putrelsegref(SEG_ABS, seg_size[SEG_DATA]);
putrelcmd(RELCMD_CODESIZE);
putrelsegref(SEG_CODE, seg_size[SEG_CODE]);
}
// In case we hit 'end' inside an included file
while (now_in > 0) {
fclose(fin[now_in]);
free(src_name[now_in]);
now_file = fin[--now_in];
}
setvars();
fseek(now_file, (long)0, 0);
#ifdef DEBUG
fprintf(stderr, "DEBUG- pass %d\n", npass) ;
#endif
yyparse();
if (outpass || passfail)
break;
if (!passretry)
outpass = 1;
}
if (bopt) {
flushbin();
flushoth();
putc(':', fbuf);
if (xeq_flag) {
puthex(0, fbuf);
puthex(xeq >> 8, fbuf);
puthex(xeq, fbuf);
puthex(1, fbuf);
puthex(255-(xeq >> 8)-xeq, fbuf);
fprintf(fcmd, "%c%c%c%c", 2, 2, xeq, xeq >> 8);
fflush(fcmd);
putcas(0x78);
putcas(xeq);
putcas(xeq >> 8);
} else
for (i = 0; i < 10; i++)
putc('0', fbuf);
putc('\n', fbuf);
fflush(fbuf);
// "Play Cas" seems to require trailing zeros to work
// properly. And we need to output at least one zero byte
// to flush out the final high speed bits.
for (i = 0; i < 6; i++)
putcas(0);
}
if (relopt) {
struct item *ip;
// Output external symbols and value of public symbols
for (ip = itemtab; ip < itemmax; ip++) {
if (ip->i_token == <PASSWORD> && (ip->i_scope & SCOPE_EXTERNAL)) {
putrelcmd(RELCMD_EXTCHAIN);
// Chain value will have top two bits set appropriately
putrelextaddr(ip->i_chain);
putrelname(ip->i_string);
}
if (ip->i_scope & SCOPE_PUBLIC)
{
putrelcmd(RELCMD_PUBVALUE);
putrelsegref(ip->i_scope, ip->i_value);
putrelname(ip->i_string);
}
}
// End module, entry address if any
putrelcmd(RELCMD_ENDMOD);
putrelextaddr(rel_main);
flushrel(); // byte alignment expected after end module
// End .rel file
putrelcmd(RELCMD_ENDPROG);
flushrel();
}
if (xeq_flag == 0) {
#if WIN32
CONSOLE_SCREEN_BUFFER_INFO inf;
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hOut, &inf);
SetConsoleTextAttribute(hOut, FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
#endif
fprintf(stderr, "Warning: no entry address (forgot \"end label\")\n");
fflush(stderr);
#if WIN32
SetConsoleTextAttribute(hOut, inf.wAttributes);
#endif
}
else if (bopt) {
fprintf(fbds, "%04x e\n", xeq);
}
if (bopt) {
int low = 0;
int high = sizeof(memory) - 1;
int chk;
int filelen;
char leafname[] = "FILENAMEBIN";
while (low < sizeof(memory) && (memflag[low] & (MEM_INST | MEM_DATA)) == 0)
low++;
while (high >= 0 && (memflag[high] & (MEM_INST | MEM_DATA)) == 0)
high--;
if (high >= low)
fwrite(memory + low, high + 1 - low, 1, fcim);
// AMSDOS binary file output (A for Amstrad, code from zmac 1.3)
filelen = (high + 1) - low;
chk = 0;
putc(0, fams);
for (i = 0; i < 11; i++) {
putc(leafname[i], fams);
chk += leafname[i];
}
for (i = 0; i < 6; i++)
putc(0, fams);
putc(2, fams); // Unprotected binary
chk += 2;
putc(0, fams);
putc(0, fams);
putc(low & 0xff, fams);
chk += low & 0xff;
putc(low >> 8, fams);
chk += low >> 8;
putc(0, fams);
putc(filelen & 0xff, fams);
chk += filelen & 0xff;
putc(filelen >> 8, fams);
chk += filelen >> 8;
putc(xeq & 0xff, fams);
chk += xeq & 0xff;
putc(xeq >> 8, fams);
chk += xeq >> 8;
for (i = 28; i < 64; i++)
putc(0, fams);
putc(filelen & 0xff, fams);
chk += filelen & 0xff;
putc(filelen >> 8, fams);
chk += filelen >> 8;
putc(0, fams); // this would be used if filelen > 64K
putc(chk & 0xff, fams);
putc(chk >> 8, fams);
for (i = 69; i < 128; i++)
putc(0, fams);
if (filelen > 0)
fwrite(memory + low, filelen, 1, fams);
if (filelen & 0x7f)
putc(0x1a, fams); // CP/M EOF character
}
if (bopt) {
struct item *tp;
for (tp = itemtab; tp < itemmax; tp++) {
if (tp->i_token == LABEL)
fprintf(fbds, "%04x a %s\n", tp->i_value, tp->i_string);
else if (tp->i_token == EQUATED)
fprintf(fbds, "%04x v %s\n", tp->i_value, tp->i_string);
}
}
if (!lopt)
fflush(fout);
if (writesyms)
outsymtab(writesyms);
compactsymtab();
if (eopt)
erreport();
if (!lopt && !sopt)
putsymtab();
if (!lopt) {
eject();
fflush(fout);
}
// GWP - some things (like balance errors in macro definitions) do
// not show up until you use them. So just in case we print an error
// count here as not to confuse the programmer who is unlikely to check
// the listing for errors if none are shown in the command window.
if (counterr() > 0)
fprintf(stderr, "%d errors (see listing if no diagnostics appeared here)\n", counterr());
if (countwarn() > 0)
fprintf(stderr, "%d warnings (see listing if no diagnostics appeared here)\n", countwarn());
exit(counterr() > 0);
}
void equate(char *id, int value)
{
struct item *it;
it = locate(id);
if (!it->i_token) {
nitems++;
it->i_value = value;
it->i_token = EQUATED;
it->i_scope = SCOPE_BUILTIN;
it->i_uses = 0;
it->i_string = malloc(strlen(id)+1);
strcpy(it->i_string, id);
}
}
/*
* set some data values before each pass
*/
void setvars()
{
int i;
peekc = -1;
inpptr = 0;
nextline_peek = -1;
raw = 0;
linein[now_in] = linecnt = 0;
exp_number = 0;
emitptr = emitbuf;
lineptr = linebuf;
ifptr = ifstack;
*ifptr = 0;
dollarsign = 0;
emit_addr = 0;
olddollar = 0;
oldothdollar = 0;
phaseflag = 0;
for (i=0; i<FLAGS; i++) err[i] = 0;
tstates = 0;
ocf = 0;
llseq = 0;
passfail = 0;
passretry = 0;
njrpromo = 0;
jopt = default_jopt;
JPopt = default_JPopt;
strcpy(modstr, "@@@@");
segment = SEG_CODE;
memset(seg_pos, 0, sizeof(seg_pos));
memset(seg_size, 0, sizeof(seg_size));
segchange = 0;
z80 = default_z80;
outrec = 0;
param_parse = 0;
arg_reset();
mfptr = 0;
mfseek(mfile, mfptr, 0);
// These are slighly harmful, but not too bad. Only
// absolutely necessary for MAC compatibility. But there's
// some use in having them available always.
equate("b", 0);
equate("c", 1);
equate("d", 2);
equate("e", 3);
equate("h", 4);
equate("l", 5);
equate("m", 6);
equate("a", 7);
equate("sp", 6);
equate("psw", 6);
// There are a large number of symbols to add to support
// "LXI H,MOV" and the like.
}
//
// Clear out cycle counts and memory.
//
void clear()
{
int i;
for (i = 0; i < sizeof(memory) / sizeof(memory[0]); i++)
{
memory[i] = 0;
memflag[i] = 0;
tstatesum[i] = 0;
}
}
void setmem(int addr, int value, int type)
{
value &= 0xff;
memory[addr] = value;
memflag[addr] |= type;
}
/*
* print out an error message and die
*/
void error(char *as)
{
*linemax = 0;
fprintf(fout, "%s\n", linebuf);
fflush(fout);
fprintf(stderr, "%s\n", as) ;
exit(1);
}
/*
* Compact the symbol table, removing unused, UNDECLARED entries,
* macros and built-in identifiers.
*/
void compactsymtab()
{
struct item *tp, *fp;
if (!nitems)
return;
tp = itemtab;
tp--;
for (fp = itemtab; fp<itemmax; fp++) {
if (fp->i_token == UNDECLARED && !(fp->i_scope & SCOPE_EXTERNAL)) {
nitems--;
continue;
}
if (fp->i_token == 0)
continue;
// Don't list macros or internally defined symbols
if (fp->i_token == MNAME || (fp->i_scope & SCOPE_BUILTIN)) {
nitems--;
continue;
}
tp++;
if (tp != fp) {
tp->i_string = fp->i_string;
tp->i_value = fp->i_value;
tp->i_token = fp->i_token;
tp->i_uses = fp->i_uses;
tp->i_scope = fp->i_scope;
tp->i_chain = fp->i_chain;
}
}
tp++;
tp->i_string = "{"; /* } */
/* sort the table */
custom_qsort(0, nitems-1);
}
/*
* output the symbol table
*/
void putsymtab()
{
int i, j, k, t, rows;
char c, c1, seg = ' ';
int numcol = printer_output ? 4 : 1;
struct item *tp;
if (!nitems)
return;
title = "** Symbol Table **";
rows = (nitems+numcol-1) / numcol;
if (rows+5+line > 60)
eject();
lineout();
fprintf(fout,"\n\n\nSymbol Table:\n\n") ;
line += 4;
for (i=0; i<rows; i++) {
for(j=0; j<numcol; j++) {
k = rows*j+i;
if (k < nitems) {
tp = &itemtab[k];
t = tp->i_token;
c = ' ' ;
if (t == EQUATED || t == DEFLED)
c = '=' ;
if (tp->i_uses == 0)
c1 = '+' ;
else
c1 = ' ' ;
// GWP - decided I don't care about uses
// even if it were accurate.
// TODO: Should use maxsymbol size in there,
// but makes output harder to read.
fprintf(fout, "%-15s%c", tp->i_string, c);
if (relopt)
seg = SEGCHAR(tp->i_scope & SCOPE_SEGMASK);
if (tp->i_value >> 16)
fprintf(fout, "%8x%c", tp->i_value, seg);
else
fprintf(fout, "%4x%c ", tp->i_value & 0xffff, seg);
if (tp->i_scope & SCOPE_EXTERNAL)
fprintf(fout, " (extern)");
if (tp->i_scope & SCOPE_PUBLIC)
fprintf(fout, " (public)");
}
}
lineout();
putc('\n', fout);
}
}
/*
* put out error report
*/
void erreport()
{
int i, numerr, numwarn;
if (line > 49) eject();
lineout();
numerr = 0;
for (i=0; i<FIRSTWARN; i++) numerr += keeperr[i];
numwarn = 0;
for (i = FIRSTWARN; i < FLAGS; i++) numwarn += keeperr[i];
if (numerr || numwarn) {
fputs("\n\n\nError + Warning report:\n\n", fout);
fprintf(fout, "%6d errors\n", numerr);
fprintf(fout, "%6d warnings\n", numwarn);
line += 6;
} else {
fputs("\n\n\nStatistics:\n", fout);
line += 3;
}
for (i=0; i<FLAGS; i++)
if (keeperr[i]) {
lineout();
fprintf(fout, "%6d %c -- %s %s\n",
keeperr[i], errlet[i], errname[i],
i < FIRSTWARN ? "error" : "warnings");
}
if (line > 52) eject();
lineout();
fprintf(fout, "\n%6d\tpasses\n", npass);
fprintf(fout, "%6d\tjr promotions\n", njrpromo);
fprintf(fout, "%6d\tsymbols\n", nitems);
fprintf(fout, "%6d\tbytes\n", nbytes);
line += 4;
if (mfptr) {
if (line > 53) eject();
lineout();
fprintf(fout, "\n%6d\tmacro calls\n", exp_number);
fprintf(fout, "%6d\tmacro bytes\n", mfptr);
fprintf(fout, "%6d\tinvented symbols\n", invented/2);
line += 3;
}
}
/*
* count errors (GWP - added to set exit code)
*/
int counterr()
{
int i, numerr = 0;
for (i=0; i<FIRSTWARN; i++) numerr += keeperr[i];
return numerr;
}
// Count warnings
int countwarn()
{
int i, numwarn = 0;
for (i = FIRSTWARN; i < FLAGS; i++)
numwarn += keeperr[i];
return numwarn;
}
char *mlook;
int nextmac()
{
int ch;
if (mlook) {
if (*mlook) {
ch = *mlook++;
addtoline(ch);
}
else
mlook = 0;
}
if (!mlook)
ch = nextchar();
return ch;
}
/*
* lexical analyser for macro definition
*/
void mlex(char *look)
{
char *p;
int c;
int t;
int quote = 0, ampdrop = 0;
struct item *param, *key;
char symbuf[TEMPBUFSIZE];
char *symbufmax = symbuf+TEMPBUFSIZE-1;
/*
* move text onto macro file, changing formal parameters
*/
#ifdef M_DEBUG
fprintf(stderr,"enter 'mlex' at %d\n", mfptr) ;
#endif
inmlex++;
mlook = look;
c = nextmac();
for (;;) {
int octo = 0, amp = 0, caret = 0;
if (c == '#' || c == '&' || c == '^') {
int esc = c;
c = nextmac();
if (charclass[c] != STARTER && charclass[c] != LETTER) {
if (esc != '&' || !ampdrop)
putm(esc);
ampdrop = 0;
continue;
}
if (esc == '#')
octo = 1;
else if (esc == '&')
amp = 1;
else
caret = 1;
}
switch(charclass[c]) {
case DIGIT:
while (numpart[c]) {
putm(c);
c = nextmac();
}
continue;
case STARTER:
case LETTER:
t = 0;
p = symbuf;
do {
if (p >= symbufmax) {
*symbufmax = '\0';
printf("was parsing '%s' in macro definition\n", tempbuf);
error(symlong);
}
*p++ = c;
if (t < MAXSYMBOLSIZE)
tempbuf[t++] = (c >= 'A' && c <= 'Z') ?
c+'a'-'A' : c;
c = nextmac();
} while (charclass[c]==LETTER || charclass[c]==DIGIT || charclass[c]==STARTER);
tempbuf[t] = 0;
*p++ = '\0';
p = symbuf;
key = keyword(tempbuf);
t = key ? key->i_token : 0;
param = item_lookup(tempbuf, paramtab, PARAMTABSIZE);
// Accept almost anything as a parameter. But a few
// keywords will just screw things up royally.
if (t != ENDM && t != REPT && t != IRPC && t != IRP && t != MACRO)
t = param->i_token;
// Caret escaping kills all expansion
// And interpretation of ENDM, etc. For better or worse.
if (caret)
t = 0;
if (t == MPARM) {
int pfx = octo || amp || c == '&';
// # prefix only allowed if declared that way
if (octo != param->i_scope)
t = 0;
else
octo = 0;
// Expansion in quoted strings only with prefix character.
if (quote && !pfx && !zcompat)
t = 0;
amp = 0; // parameter substitution, eat '&'
}
else if (t && quote)
t = 0;
if (ampdrop)
amp = 0;
ampdrop = c == '&' && t == MPARM;
if (octo) putm('#');
if (amp) putm('&');
if (t != MPARM) {
for (p = symbuf; *p; p++)
putm(*p);
}
else {
if (*(param->i_string) == '?' || param->i_chain)
putm('\2');
else
putm('\1');
putm(param->i_value + 'A');
}
if (t == ENDM) {
if (--inmlex == 0)
goto done;
}
else if (t == REPT || t == IRPC || t == IRP || t == MACRO) {
inmlex++;
}
continue;
case F_END:
errwarn(warn_general, "macro definition went until end of file");
if (expptr) {
popsi();
c = nextmac();
continue;
}
goto done;
default:
switch (c) {
case '\n':
quote = 0;
list1();
break;
case ';':
if (!quote) {
while (c != '\n' && c != 0) {
putm(c);
c = nextmac();
}
continue;
}
break;
case '\'':
case '"':
if (c == quote)
quote = 0;
else
quote = c;
break;
default:
break;
}
if (c != '\1' && c != '`') putm(c);
c = nextmac();
}
}
/*
* finish off the file entry
*/
done:
while(c != EOF && c != '\n' && c != '\0') c = nextmac();
inmlex++;
list1();
inmlex--;
// WHY two newlines??
// putm('\n');
putm('\n');
putm(0);
// TODO - here's where we could save parameter names for MRAS
for (c = 0; c < PARAMTABSIZE; c++) {
if (paramtab[c].i_token == MPARM) {
free(paramtab[c].i_string);
paramtab[c].i_string = NULL;
paramtab[c].i_token = 0;
}
}
inmlex = 0;
#ifdef M_DEBUG
fprintf(stderr,"exit 'mlex' at %d\n", mfptr) ;
#endif
}
int str_getch(struct argparse *ap)
{
int ch = ap->user_peek;
if (ch >= 0) {
ap->user_peek = -1;
return ch;
}
if (!ap->user_ptr || ap->user_ptr[ap->user_int] == '\0')
return '\0';
return ap->user_ptr[ap->user_int++];
}
int arg_getch(struct argparse *ap)
{
(void)ap; // suppress warning
return nextchar();
}
void arg_start()
{
arg_reset();
arg_flag = 1;
}
void arg_reset()
{
arg_flag = 0;
arg_state.arg = tempbuf;
arg_state.argsize = sizeof tempbuf;
arg_state.peek = &peekc;
arg_state.getch = arg_getch;
arg_state.macarg = 0;
arg_state.user_ptr = 0;
arg_state.user_int = 0;
arg_state.didarg = 0;
arg_state.numarg = 0;
}
/*
* lexical analyser for the arguments of a macro call
*/
int getarg(struct argparse *ap)
{
int c;
char *p;
int quote;
int depth;
*ap->arg = 0;
while (charclass[c = ap->getch(ap)] == SPACE);
switch(c) {
case '\0':
if (!ap->user_ptr)
popsi(); // a seemingly unlikely case?
case '\n':
case ';':
if (!ap->didarg && ap->numarg) {
*ap->peek = c;
ap->didarg = 1;
ap->numarg++;
return ARG;
}
ap->didarg = 0;
ap->numarg = 0;
return c;
case ',':
if (!ap->didarg) {
ap->didarg = 1;
*ap->peek = c;
ap->numarg++;
return ARG;
}
ap->didarg = 0;
return c;
case '\'':
case '\"':
quote = c;
p = ap->arg;
if (!zcompat)
*p++ = c;
do {
c = ap->getch(ap);
if (c == '\0' || c == '\n') {
*ap->peek = c;
*p = 0;
err[bflag]++;
ap->didarg = 1;
ap->numarg++;
return ARG;
}
else if (c == quote) {
if ((c = ap->getch(ap)) != quote) {
if (!zcompat)
*p++ = quote;
*ap->peek = c;
*p = '\0';
ap->didarg = 1;
ap->numarg++;
return ARG;
}
}
else
*p++ = c;
} while (p < ap->arg + ap->argsize - 1);
ap->arg[ap->argsize - 1] = '\0';
printf("was parsing macro argument '%s'\n", ap->arg);
error(symlong);
return 0; // not reached
case '<':
depth = 1;
p = ap->arg;
do {
c = ap->getch(ap);
if (c == '\0' || c == '\n') {
*ap->peek = c;
*p = 0;
err[bflag]++;
ap->didarg = 1;
ap->numarg++;
return ARG;
}
if (c == '>') {
depth--;
if (depth == 0) {
*p = '\0';
ap->didarg = 1;
ap->numarg++;
return ARG;
}
}
else if (c == '<')
depth++;
*p++ = c;
} while (p < ap->arg + ap->argsize - 1);
ap->arg[ap->argsize - 1] = '\0';
printf("was parsing macro argument '%s'\n", ap->arg);
error(symlong);
return 0; // not reached
default: /* unquoted string */
if (c == '%' && ap->macarg) {
ap->didarg = 1;
ap->numarg++;
return c;
}
p = ap->arg;
*ap->peek = c;
do {
c = ap->getch(ap);
switch(c) {
case '\0':
case '\n':
case '\t':
case ' ':
case ',':
*ap->peek = c;
*p = '\0';
ap->didarg = 1;
ap->numarg++;
return ARG;
case '^':
c = ap->getch(ap);
switch (c) {
case ',':
case '^':
case ' ':
case '\t':
*p++ = c;
break;
default:
*p++ = '^';
*ap->peek = c;
break;
}
break;
default:
*p++ = c;
}
} while (p < ap->arg + ap->argsize - 1);
ap->arg[ap->argsize - 1] = '\0';
printf("was parsing macro argument '%s'\n", ap->arg);
error("macro argument too long");
return 0; // not reached
}
}
/*
* add a suffix to a string
*/
void suffix(char *str, char *suff)
{
strcpy(getsuffix(str), suff);
}
char *basename(char *filename)
{
char *base, *p;
base = filename;
for (p = filename; *p; p++) {
if (*p == '/' || *p == '\\') {
base = p + 1;
}
}
return base;
}
char *getsuffix(char *str)
{
char *suffix = 0;
str = basename(str);
for (; *str; str++) {
if (*str == '.')
suffix = str;
}
return suffix ? suffix : str;
}
// Construct output file given input path.
// Essentially files for "file.z" are sent to "zout/file.suffix".
// And for "dir/file.z" they are "zout/file.suffix"
void outpath(char *out, char *src, char *suff)
{
strcpy(out, "zout");
if (!suff)
return;
strcat(out, "/");
strcat(out, basename(src));
suffix(out, suff);
}
/*
* put out a byte to the macro file, keeping the offset
*/
void putm(int c)
{
mfseek(mfile, mfptr, 0);
mfptr++;
mfputc(c, mfile);
}
/*
* get a byte from the macro file
*/
int getm()
{
int ch;
mfseek(mfile, floc, 0);
floc++;
ch = mfgetc(mfile);
if (ch == EOF) {
ch = 0;
fprintf(stderr, "bad macro read\n");
}
return ch;
}
/*
* pop standard input
*/
void popsi()
{
int i;
for (i=0; i<PARMMAX; i++) {
if (est[i].param) free(est[i].param);
}
floc = est[FLOC].value;
ifptr = est[MIF].param;
free(est);
expptr--;
est = expptr ? expstack[expptr-1] : 0;
mfseek(mfile, (long)floc, 0);
if (lineptr > linebuf) lineptr--;
}
/*
* return a unique name for a local symbol
* c is the parameter number, n is the macro number.
*/
char *getlocal(int c, int n)
{
static char local_label[10];
invented++;
if (c >= 26)
c += 'a' - '0';
sprintf(local_label, "?%c%04d", c+'a', n) ;
return(local_label);
}
char *getmraslocal()
{
static char mras_local[32];
char *p = mras_local + sizeof mras_local - 1;
int n = est[TEMPNUM].value;
*p = '\0';
for (; n > 0; n /= 26)
*--p = 'A' + n % 26;
return p;
}
/*
* read in a symbol table
*/
void insymtab(char *name)
{
struct stab *t;
int s, i;
FILE *sfile;
t = (struct stab *) tempbuf;
if (!(sfile = fopen(name, "rb")))
return;
fread((char *)t, 1, sizeof *t, sfile);
if (t->t_value != SYMMAJIC)
return;
s = t->t_token;
for (i=0; i<s; i++) {
fread((char *)t, 1, sizeof *t, sfile);
if (tokenofitem(UNDECLARED, 0, 0) != UNDECLARED)
continue;
yylval.itemptr->i_token = t->t_token;
yylval.itemptr->i_value = t->t_value;
if (t->t_token == MACRO)
yylval.itemptr->i_value += mfptr;
}
while ((s = fread(tempbuf, 1, TEMPBUFSIZE, sfile)) > 0) {
mfptr += s;
mfwrite(tempbuf, 1, s, mfile) ;
}
fclose(sfile);
}
/*
* write out symbol table
*/
void outsymtab(char *name)
{
struct stab *t;
struct item *ip;
int i;
FILE *sfile;
t = (struct stab *) tempbuf;
if (!(sfile = fopen(name, "wb")))
return;
for (ip=itemtab; ip<itemmax; ip++) {
if (ip->i_token == UNDECLARED) {
ip->i_token = 0;
nitems--;
}
}
copyname(title, (char *)t);
t->t_value = SYMMAJIC;
t->t_token = nitems;
fwrite((char *)t, 1, sizeof *t, sfile);
for (ip=itemtab; ip<itemmax; ip++) {
if (ip->i_token != 0) {
t->t_token = ip->i_token;
t->t_value = ip->i_value;
copyname(ip->i_string, (char *)t);
fwrite((char *)t, 1, sizeof *t, sfile);
}
}
mfseek(mfile, (long)0, 0);
while((i = mfread(tempbuf, 1, TEMPBUFSIZE, mfile) ) > 0)
fwrite(tempbuf, 1, i, sfile);
fclose(sfile);
}
/*
* copy a name into the symbol file
*/
void copyname(char *st1, char *st2)
{
char *s1, *s2;
int i;
i = (MAXSYMBOLSIZE+2) & ~01;
s1 = st1;
s2 = st2;
while((*s2++ = *s1++)) i--; /* -Wall-ishness :-) -RJM */
while(--i > 0) *s2++ = '\0';
}
/* get the next source file */
void next_source(char *sp)
{
if(now_in == NEST_IN -1)
error("Too many nested includes") ;
if ((now_file = open_incpath(sp, "r")) == NULL) {
char ebuf[1024] ;
sprintf(ebuf,"Can't open include file: %s", sp) ;
error(ebuf) ;
}
if (outpass && iflist()) {
lineout() ;
fprintf(fout, "**** %s ****\n",sp) ;
}
if (outpass && bopt)
fprintf(fbds, "%04x %04x f %s\n", dollarsign, emit_addr, sp);
/* save the list control flag with the current line number */
if (lstoff)
linein[now_in] = - linein[now_in] ;
/* no list if include files are turned off */
lstoff |= iopt ;
/* save the new file descriptor. */
fin[++now_in] = now_file ;
/* start with line 0 */
linein[now_in] = 0 ;
/* save away the file name */
src_name[now_in] = malloc(strlen(sp)+1) ;
strcpy(src_name[now_in],sp) ;
}
int phaseaddr(int addr)
{
if (!phaseflag)
return addr;
if (addr < phbegin || addr > dollarsign) {
err[vflag]++;
if (pass2)
fprintf(stderr, "$%04x outside current phase area\n", addr);
return 0;
}
return phdollar + (addr - phbegin);
}
// Include contents of named file as binary data.
void incbin(char *filename)
{
FILE *fp = open_incpath(filename, "rb");
int ch;
int start = dollarsign;
int last = start;
int bds_count;
if (!fp) {
char ebuf[1024];
sprintf(ebuf, "Can't binary include file: %s", filename);
error(ebuf);
return;
}
addtoline('\0');
if (outpass && bopt)
fprintf(fbds, "%04x %04x s %s", dollarsign, emit_addr, linebuf);
// Avoid emit() because it has a small buffer and it'll spam the listing.
bds_count = 0;
while ((ch = fgetc(fp)) != EOF) {
if (outpass && bopt) {
if (bds_count == 0)
fprintf(fbds, "%04x %04x d ", dollarsign, emit_addr);
fprintf(fbds, "%02x", ch);
bds_count++;
if (bds_count == 16) {
fprintf(fbds, "\n");
bds_count = 0;
}
}
if (segment == SEG_CODE)
setmem(emit_addr, ch, MEM_DATA);
emit_addr++;
emit_addr &= 0xffff;
last = dollarsign;
dollarsign++;
dollarsign &= 0xffff;
putbin(ch);
putrel(ch);
putout(ch);
}
if (outpass && bopt && bds_count)
fprintf(fbds, "\n");
fclose(fp);
// Do our own list() work as we emit bytes manually.
if (outpass && iflist()) {
lineout();
if (nopt)
fprintf(fout, "%4d:", linein[now_in]);
if (copt)
fprintf(fout, nopt ? "%5s-" : "%4s-", "");
if (nopt || copt)
fprintf(fout, "\t");
puthex(start >> 8, fout);
puthex(start, fout);
if (relopt)
fputc(SEGCHAR(segment), fout);
fprintf(fout, " .. ");
puthex(last >> 8, fout);
puthex(last, fout);
if (relopt)
fputc(SEGCHAR(segment), fout);
putc('\t', fout);
fputs(linebuf, fout);
lineptr = linebuf;
}
}
void dc(int count, int value)
{
int start = dollarsign;
int bds_count;
addtoline('\0');
if (outpass && bopt)
fprintf(fbds, "%04x %04x s %s", dollarsign, emit_addr, linebuf);
// Avoid emit() because it has a small buffer and it'll spam the listing.
bds_count = 0;
while (count-- > 0) {
if (outpass && bopt) {
if (bds_count == 0)
fprintf(fbds, "%04x %04x d ", dollarsign, emit_addr);
fprintf(fbds, "%02x", value);
bds_count++;
if (bds_count == 16) {
fprintf(fbds, "\n");
bds_count = 0;
}
}
if (segment == SEG_CODE)
setmem(emit_addr, value, MEM_DATA);
emit_addr++;
emit_addr &= 0xffff;
dollarsign++;
dollarsign &= 0xffff;
putbin(value);
putrel(value);
putout(value);
}
if (outpass && bopt && bds_count)
fprintf(fbds, "\n");
// Do our own list() work as we emit bytes manually.
if (outpass && iflist()) {
lineout();
if (nopt)
fprintf(fout, "%4d:", linein[now_in]);
if (copt)
fprintf(fout, nopt ? "%5s-" : "%4s-", "");
if (nopt || copt)
fprintf(fout, "\t");
puthex(start >> 8, fout);
puthex(start, fout);
if (relopt) {
fputc(SEGCHAR(segment), fout);
fprintf(fout, "..");
}
else
fprintf(fout, " .. ");
puthex((dollarsign - 1) >> 8, fout);
puthex((dollarsign - 1), fout);
if (relopt)
fputc(SEGCHAR(segment), fout);
putc(' ', fout);
puthex(value, fout);
putc('\t', fout);
fputs(linebuf, fout);
lsterr2(1);
lineptr = linebuf;
}
else
lsterr1();
}
#define OUTREC_SEG outbuf[outrec]
#define OUTREC_ADDR ((outbuf[outrec + 1] << 8) | outbuf[outrec + 2])
#define OUTREC_LEN outbuf[outrec + 3]
#define OUTREC_DATA outbuf[outrec + 4 + outlen]
#define OUTREC_SIZEOF 5
void new_outrec(void)
{
OUTREC_LEN = outlen;
outrec += OUTREC_SIZEOF + outlen;
outlen = 0;
OUTREC_SEG = segment;
outbuf[outrec + 1] = seg_pos[segment] >> 8;
outbuf[outrec + 2] = seg_pos[segment];
}
void putout(int value)
{
int addr = (OUTREC_ADDR + outlen) & 0xffff;
if (OUTREC_SEG != segment || addr != seg_pos[segment])
new_outrec();
if (pass2 && OUTREC_DATA != value && !passfail) {
char segname[2];
if (relopt)
sprintf(segname, "%c", SEGCHAR(segment));
else
segname[0] = '\0';
sprintf(detail, "%s error - $%04x%s changed from $%02x to $%02x",
errname[pflag], addr, segname, OUTREC_DATA, value);
errwarn(pflag, detail);
if (!outpass)
passretry = 1;
}
OUTREC_DATA = value;
outlen++;
if (outlen >= 256)
new_outrec();
advance_segment(1);
}
void advance_segment(int step)
{
int top = seg_pos[segment] += step;
seg_pos[segment] &= 0xffff;
if (top >= 0x10000)
top = 0xffff;
if (top > seg_size[segment])
seg_size[segment] = top;
}
void expr_reloc_check(struct expr *ex)
{
if (!relopt) return;
if (ex->e_scope & (SCOPE_EXTERNAL | SCOPE_NORELOC))
err[rflag]++;
}
void expr_number_check(struct expr *ex)
{
if (!relopt) return;
expr_reloc_check(ex);
if (ex->e_scope & SCOPE_SEGMASK)
err[rflag]++;
}
void expr_scope_same(struct expr *ex1, struct expr *ex2)
{
if (!relopt) return;
if ((ex1->e_scope & SCOPE_SEGMASK) != (ex2->e_scope & SCOPE_SEGMASK))
err[rflag]++;
}
void expr_word_check(struct expr *ex)
{
if (ex->e_value < -32768 || ex->e_value > 65535) {
err[vflag]++;
}
}
int is_number(struct expr *ex)
{
return ex && (ex->e_scope & ~SCOPE_PUBLIC) == 0;
}
int is_external(struct expr *ex)
{
return ex && (ex->e_scope & SCOPE_EXTERNAL) && !ex->e_left && !ex->e_right &&
ex->e_item;
}
struct expr *expr_alloc(void)
{
struct expr *ex = malloc(sizeof *ex);
ex->e_value = 0;
ex->e_scope = 0;
ex->e_token = 0;
ex->e_item = 0;
ex->e_left = 0;
ex->e_right = 0;
return ex;
}
struct expr *expr_num(int value)
{
struct expr *ex = expr_alloc();
ex->e_value = value;
ex->e_token = '0';
return ex;
}
// Expression consruction for operators that subtract/compare.
// They produce a valid result if operating on numbers in the same segment.
struct expr *expr_op_sc(struct expr *left, int token, struct expr *right, int value)
{
struct expr *ex = expr_op(left, token, right, value);
if (!(ex->e_scope & SCOPE_EXTERNAL) &&
((left->e_scope ^ right->e_scope) & SCOPE_SEGMASK) == 0)
{
// Result relocatable and a simple number
ex->e_scope &= ~(SCOPE_NORELOC | SCOPE_SEGMASK);
}
return ex;
}
struct expr *expr_op(struct expr *left, int token, struct expr *right, int value)
{
struct expr *ex = expr_alloc();
ex->e_value = value;
ex->e_token = token;
ex->e_left = left;
ex->e_right = right;
// Combining two numbers will be fine as long as they're not
// flagged as external or already not relocatable. In which case
// it is up to the particular operator to allow the value
// to become valid.
ex->e_scope = left->e_scope;
if (left->e_scope & SCOPE_SEGMASK)
ex->e_scope |= SCOPE_NORELOC;
if (right) {
ex->e_scope |= right->e_scope;
if (right->e_scope & SCOPE_SEGMASK)
ex->e_scope |= SCOPE_NORELOC;
}
return ex;
}
void expr_free(struct expr *ex)
{
if (!ex)
return;
expr_free(ex->e_left);
expr_free(ex->e_right);
free(ex);
}
int synth_op(struct expr *ex, int gen)
{
if (ex->e_token == '&' && is_number(ex->e_right) &&
ex->e_right->e_value == 255)
{
if (gen) {
extend_link(ex->e_left);
putrelop(RELOP_LOW);
return 1;
}
return can_extend_link(ex->e_left);
}
return 0;
}
int link_op(struct expr *ex)
{
if (!ex)
return 0;
switch (ex->e_token) {
case HIGH: return RELOP_HIGH;
case LOW: return RELOP_LOW;
case '~': return RELOP_NOT;
case '-': return !ex->e_right ? RELOP_NEG : RELOP_SUB;
case '+': return RELOP_ADD;
case '*': return RELOP_MUL;
case '/': return RELOP_DIV;
case '%': return RELOP_MOD;
default: return 0;
}
}
int can_extend_link(struct expr *ex)
{
if (!ex)
return 1;
// If we have a value available then we're good.
if (!(ex->e_scope & SCOPE_NORELOC))
return 1;
// Might be able to synthesize the operation.
if (synth_op(ex, 0))
return 1;
// Otherwise, the operator must be supported and the children
// must be linkable.
return link_op(ex) && can_extend_link(ex->e_left) && can_extend_link(ex->e_right);
}
void extend_link(struct expr *ex)
{
int op;
if (!ex)
return;
if (synth_op(ex, 1))
return;
extend_link(ex->e_left);
extend_link(ex->e_right);
op = link_op(ex);
if (op) {
putrelop(op);
return;
}
putrelcmd(RELCMD_EXTLINK);
if (is_external(ex)) {
char *str = ex->e_item->i_string;
int len = strlen(str);
if (len > 6)
len = 6;
putrelbits(3, 1 + len);
putrelbits(8, 'B');
while (len-- > 0) {
int ch = *str++;
if (ch >= 'a' && ch <= 'z')
ch -= 'a' - 'A';
putrelbits(8, ch);
}
}
else {
putrelbits(3, 4);
putrelbits(8, 'C');
putrelbits(8, ex->e_scope & SCOPE_SEGMASK);
putrelbits(8, ex->e_value);
putrelbits(8, ex->e_value >> 8);
}
}
void putrelop(int op)
{
putrelcmd(RELCMD_EXTLINK);
putrelbits(3, 2);
putrelbits(8, 'A');
putrelbits(8, op);
}
|
chris781245/ZYCycleView | ZYCycleCell.h | <reponame>chris781245/ZYCycleView
//
// ZYCycleCell.h
// Investank
//
// Created by 史泽东 on 2019/1/14.
// Copyright © 2019 史泽东. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface ZYCycleCell : UICollectionViewCell
@property (nonatomic, strong) NSURL *imageURL;
@end
NS_ASSUME_NONNULL_END
|
chris781245/ZYCycleView | ZYCycleFlowLayout.h | //
// ZYCycleFlowLayout.h
// Investank
//
// Created by 史泽东 on 2019/1/14.
// Copyright © 2019 史泽东. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface ZYCycleFlowLayout : UICollectionViewFlowLayout
@end
NS_ASSUME_NONNULL_END
|
chris781245/ZYCycleView | ZYCycleView.h | <reponame>chris781245/ZYCycleView
//
// ZYCycleView.h
// Investank
//
// Created by 史泽东 on 2019/1/14.
// Copyright © 2019 史泽东. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface ZYCycleView : UIView
@property (nonatomic, strong) NSArray *imageURLs;
@end
NS_ASSUME_NONNULL_END
|
menshikh-iv/hw | intel-opt/3_vector/2.c | #include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#define N 100000
#define MAX_ITER 100
struct s_of_arrs{
double a[N];
double b[N];
};
struct el_of_arrs{
double a;
double b;
};
int main(){
srand(time(0));
struct el_of_arrs fst[N];
struct s_of_arrs snd;
double full_time_el_of_arrs = 0.;
double full_time_s_of_arrs = 0.;
double r_a, r_b;
double result_1 = 0.;
double result_2 = 0.;
struct timeval start_s, end_s;
for (int iter = 0; iter < MAX_ITER; iter++){
for (int i = 0; i < N; i++){
r_a = (double)rand()/(double)RAND_MAX;
r_b = (double)rand()/(double)RAND_MAX;
fst[i].a = r_a;
fst[i].b = r_b;
snd.a[i] = r_a;
snd.b[i] = r_b;
}
gettimeofday(&start_s, NULL);
for (int i = 0; i < N; i++){
result_1 += fst[i].a * fst[i].b;
}
gettimeofday(&end_s, NULL);
full_time_el_of_arrs += ((end_s.tv_sec - start_s.tv_sec) * 1000000u +
end_s.tv_usec - start_s.tv_usec) / 1.e6;
gettimeofday(&start_s, NULL);
for (int i = 0; i < N; i++){
result_2 += snd.a[i] * snd.b[i];
}
gettimeofday(&end_s, NULL);
full_time_s_of_arrs += ((end_s.tv_sec - start_s.tv_sec) * 1000000u +
end_s.tv_usec - start_s.tv_usec) / 1.e6;
}
printf("time [array of structs]: %f sec (%f)\n", full_time_el_of_arrs / MAX_ITER, result_1);
printf("time [struct of arrays]: %f sec (%f)\n", full_time_s_of_arrs / MAX_ITER, result_2);
}
|
menshikh-iv/hw | intel-opt/123_int/2/2_1.c | <filename>intel-opt/123_int/2/2_1.c<gh_stars>0
#include <stdio.h>
#include <stdlib.h>
#define N 10000
extern float calculate(float *a, float *b);
int main()
{
float *a,*b,res;
int i;
a = (float*)malloc(N*sizeof(float));
b = (float*)malloc(N*sizeof(float));
for(i=0;i<N;i++)
{
a[i] = i;
b[i] = 1 - i;
}
res = calculate(a,b);
printf("res = %f", res);
}
|
menshikh-iv/hw | intel-opt/5_openmp/8.c | <reponame>menshikh-iv/hw
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
#include <time.h>
#define N 500000
#define MAX_ITER 100
/*
Элементы массива a инициализируются 0, массива b[0]...b[n-1] – случайными числами от 0 до n-1.
Распараллелить цикл for (i=0; i<n; i++) a[b[i]]++;
*/
int main() {
srand(0);
int a[N], b[N], prior[N];
float full_time = 0.;
struct timeval start_s, end_s;
for (int iter = 0; iter < MAX_ITER; iter++){
for (int i = 0; i < N; i++){
a[i] = prior[i] = 0;
b[i] = (int)((rand() >> 15) % N);
}
gettimeofday(&start_s, NULL);
#pragma omp parallel for
for (int i = 0; i < N; i++){
#pragma omp atomic
a[b[i]]++;
}
gettimeofday(&end_s, NULL);
for (int i = 0; i < N; i++){
prior[b[i]]++;
}
for (int i = 0; i < N; i++){
if (a[b[i]] != prior[b[i]]){
printf("Raise condition detected, index #%d (%d, %d)\n", i, a[b[i]], prior[b[i]]);
return 1;
}
}
full_time += ((end_s.tv_sec - start_s.tv_sec) * 1000000u +
end_s.tv_usec - start_s.tv_usec) / 1.e6;
}
printf("time: %f sec\n", full_time / MAX_ITER);
}
|
menshikh-iv/hw | intel-opt/5_openmp/9.c | #include <stdio.h>
#include <stdlib.h>
#include <omp.h>
#include <time.h>
#define N 1000000
#define MAX_ITER 50
/*
Распараллелить цикл вычисления суммы
for (i=0; i<n; i++) sum+=F(i);
*/
double func(double element){
return element * element * element - element * 0.15;
}
int main() {
srand(0);
double a[N];
double full_time = 0.;
double sum_res = 0.;
struct timeval start_s, end_s;
for (int iter = 0; iter < MAX_ITER; iter++){
sum_res = 0.;
for (int i = 0; i < N; i++){
a[i] = (double)rand()/(double)RAND_MAX;
}
gettimeofday(&start_s, NULL);
#pragma omp parallel for reduction(+:sum_res)
for (int i = 0; i < N; i++){
sum_res += func(a[i]);
}
gettimeofday(&end_s, NULL);
if (iter == 0){
printf("Sum: %f\n", sum_res);
}
full_time += ((end_s.tv_sec - start_s.tv_sec) * 1000000u +
end_s.tv_usec - start_s.tv_usec) / 1.e6;
}
printf("time: %f sec\n", full_time / MAX_ITER);
}
|
menshikh-iv/hw | intel-opt/3_vector/1.c | <filename>intel-opt/3_vector/1.c<gh_stars>0
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#define N 100000
#define MAX_ITER 100
int main(){
srand(time(0));
float a_fl[N], b_fl[N];
double a_dl[N], b_dl[N];
float full_time_fl = 0.;
float full_time_dl = 0.;
float result_1 = 0.;
double result_2 = 0.;
struct timeval start_s, end_s;
for (int iter = 0; iter < MAX_ITER; iter++){
for (int i = 0; i < N; i++){
a_fl[i] = (float)rand()/(float)RAND_MAX;
b_fl[i] = (float)rand()/(float)RAND_MAX;
}
gettimeofday(&start_s, NULL);
for (int i = 0; i < N; i++){
result_1 += a_fl[i] * b_fl[i];
}
gettimeofday(&end_s, NULL);
full_time_fl += ((end_s.tv_sec - start_s.tv_sec) * 1000000u +
end_s.tv_usec - start_s.tv_usec) / 1.e6;
for (int i = 0; i < N; i++){
a_dl[i] = (double)rand()/(double)RAND_MAX;
b_dl[i] = (double)rand()/(double)RAND_MAX;
}
gettimeofday(&start_s, NULL);
for (int i = 0; i < N; i++){
result_2 += a_dl[i] * b_dl[i];
}
gettimeofday(&end_s, NULL);
full_time_dl += ((end_s.tv_sec - start_s.tv_sec) * 1000000u +
end_s.tv_usec - start_s.tv_usec) / 1.e6;
}
printf("time [float]: %f sec (%f)\n", full_time_fl / MAX_ITER, result_1);
printf("time [double]: %f sec (%f)\n", full_time_dl / MAX_ITER, result_2);
}
|
menshikh-iv/hw | intel-opt/123_int/1/1_2.c | <gh_stars>0
void unknown(int *a)
{
int x = 0;
x++;
} |
menshikh-iv/hw | intel-opt/5_openmp/7.c | <reponame>menshikh-iv/hw
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
#include <time.h>
#define N 1000000
#define MAX_ITER 25
/*
Ускорить выполнение цикла for в программе, вычисляющей
покоординатную функцию от элементов массива a: a[i]=F(a[i]);
*/
float func(float element){
return element * element * element - element * 0.15;
}
int main() {
srand(time(0));
float a[N];
float full_time = 0.;
struct timeval start_s, end_s;
for (int iter = 0; iter < MAX_ITER; iter++){
for (int i = 0; i < N; i++){
a[i] = (float)rand()/(float)RAND_MAX;
}
gettimeofday(&start_s, NULL);
#pragma omp parallel for
for (int i = 0; i < N; i++){
a[i] = func(a[i]);
}
gettimeofday(&end_s, NULL);
full_time += ((end_s.tv_sec - start_s.tv_sec) * 1000000u +
end_s.tv_usec - start_s.tv_usec) / 1.e6;
}
printf("time: %f sec\n", full_time / MAX_ITER);
}
|
menshikh-iv/hw | intel-opt/123_int/1/1_1.c | <reponame>menshikh-iv/hw
#include <stdio.h>
extern void unknown(int *a);
int main()
{
int a,b,c;
a=5;
c=a;
unknown(&a);
if(a==5)
printf("a==5\n");
b=a;
printf("%d %d %d\n",a,b,c);
return(1);
}
|
menshikh-iv/hw | intel-opt/4_parallel/5.c | <gh_stars>0
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <sys/time.h>
#define M 300
#define N 400
#define K 200
#define MAX_ITER 5
/*
Написать программу по перемножению матриц. Запустить программу с автоматическим распараллеливанием и без него, оценить разницу
*/
int main(){
srand(0);
float m1[M][N], m2[N][K], result[M][K];
float full_time = 0.;
struct timeval start_s, end_s;
for (int iter = 0; iter < MAX_ITER; iter++){
for (int i = 0; i < M; i++){
for (int j = 0; j < N; j++){
m1[i][j] = rand();
}
}
for (int i = 0; i < N; i++){
for (int j = 0; j < K; j++){
m2[i][j] = rand();
}
}
gettimeofday(&start_s, NULL);
float sum = 0.;
#pragma parallel
for (int i = 0; i < M; i++){
for(int j = 0; j < K; j++){
sum = 0.;
for(int k = 0; k < N; k++){
sum += m1[i][k] * m2[k][j];
}
result[i][j] = sum;
}
}
gettimeofday(&end_s, NULL);
printf("%f\n", result[0][0]);
full_time += ((end_s.tv_sec - start_s.tv_sec) * 1000000u +
end_s.tv_usec - start_s.tv_usec) / 1.e6;
}
printf("time: %f sec\n", full_time / MAX_ITER);
}
|
menshikh-iv/hw | intel-opt/4_parallel/6.c | #include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <sys/time.h>
#define N 500000
#define MAX_ITER 20
/*
Написать программу, определяющую количество всех простых числе в диапазоне от 0 до N
Запустить программу с автоматическим распараллеливанием и без него, оценить разницу и объяснить результат
*/
main(){
bool prime_cand[N];
float full_time = 0.;
int prime_count = 0;
struct timeval start_s, end_s;
for (int iter = 0; iter < MAX_ITER; iter++){
prime_count = 0;
for(int i = 0;i < N; i++){
prime_cand[i] = true;
}
prime_cand[0] = prime_cand[1] = false;
gettimeofday(&start_s, NULL);
for(int i = 2; i * i < N; i++){
for(int j = i * i;j < N;j = j + i){
prime_cand[j] = false;
}
}
for (int i = 0; i < N; i++){
prime_count += prime_cand[i];
}
gettimeofday(&end_s, NULL);
full_time += ((end_s.tv_sec - start_s.tv_sec) * 1000000u +
end_s.tv_usec - start_s.tv_usec) / 1.e6;
}
printf("time: %f sec (%d)\n", full_time / MAX_ITER, prime_count);
}
|
menshikh-iv/hw | intel-opt/123_int/2/2_2.c | #include <stdio.h>
#define N 10000
extern float calc(float a, float b);
float calculate(float * restrict a, float * restrict b)
{
int i;
float res;
for(i=0;i<N;i++)
{
res = calc(a[i],b[i]);
}
return res;
}
|
hareat/trials | c/bypass_fflush.c | <filename>c/bypass_fflush.c<gh_stars>0
// bypass_fflush.c Are file buffers flushed in case of forgotten fclose,
// a terminating signal or an exit call?
// Answer: no in case of an abnormal program end by a terminating signal
// or an _exit call.
// yes in case of a normal program end by reaching end of life
// or an exit call.
//
// build: cc bypass_fflush.cpp -o bypass_fflush
// use: ./bypass_fflush ; cat tmp/f?
// unbuffered file content
// buffered file content
// ./bypass_fflush term ; cat tmp/f?
// raise SIGTERM
// Terminated
// unbuffered file content
// ./bypass_fflush exit ; cat tmp/f?
// call stdlib exit
// unbuffered file content
// buffered file content
// ./bypass_fflush _exit ; cat tmp/f?
// call unistd _exit
// unbuffered file content
/////////////////////////////////////////////////////////////////////
#include <fcntl.h> // open
#include <signal.h> // raise SIG*
#include <stdio.h> // fputs perror
#include <stdlib.h> // exit EXIT*
#include <string.h> // strcmp strlen
#include <unistd.h> // _exit unlink write
int main(const int argc, const char* argv[])
{
// open the FILE pointer
const char *filename = "tmp/fp";
unlink(filename);
FILE *fp = fopen(filename, "w");
if (!fp) {
perror(filename);
return EXIT_FAILURE;
}
// open the file handle
filename = "tmp/fh";
unlink(filename);
int fh = open(filename, O_WRONLY | O_CREAT, 0644);
if (fh == -1) {
perror(filename);
return EXIT_FAILURE;
}
// fill the files
fputs("buffered file content\n", fp);
const char * const content = "unbuffered file content\n";
write(fh, content, strlen(content));
// decide which kind of process end you want
if (argc == 2) {
if (strcmp(argv[1], "term") == 0) {
puts("raise SIGTERM");
raise(SIGTERM);
} else if (strcmp(argv[1], "exit") == 0) {
puts("call stdlib exit");
exit(EXIT_FAILURE);
} else if (strcmp(argv[1], "_exit") == 0) {
puts("call unistd _exit");
_exit(EXIT_FAILURE);
}
}
// in this trial do not fclose(fp) and close(fh)
return EXIT_SUCCESS;
}
|
hareat/trials | c/forkExecChild.c | // forkExecChild.c sleeps for a while to show the use of fork+exec*
// to start several child programs.
//
// build: cc forkExecChild.c -o forkExecChild
// use: ./forkExecChild
// ./forkExecChild 3
/////////////////////////////////////////////////////////////////////
#include <stdio.h> // printf
#include <stdlib.h> // atoi
#include <unistd.h> // getpid sleep
// EXIT_SUCCESS or EXIT_FAILURE or an error number would be recommended.
// But in this trial I use the input value to show the relation
// between child and parent by the use of the exit status.
int main(const int argc, const char *argv[])
{
int seconds = 1;
if (argc > 1)
seconds = atoi(argv[1]);
printf("Child pid %d sleeps for %d seconds.\n", getpid(), seconds);
sleep(seconds);
printf("Child pid %d exits with %d.\n", getpid(), seconds);
return seconds;
}
|
hareat/trials | c/fork.c | <filename>c/fork.c
// fork.c shows the use of fork to create several child processes.
//
// build: cc fork.c -o fork
// use: ./fork 5
// ./fork 100000
// meanwhile try ps u to show the current processes
/////////////////////////////////////////////////////////////////////
#include <errno.h>
#include <stdio.h> // printf
#include <stdlib.h> // atoi exit EXIT_*
#include <string.h> // strerror
#include <unistd.h> // fork getpid sleep
#include <sys/wait.h>
// EXIT_SUCCESS or EXIT_FAILURE or an error number would be recommended.
// But in this trial I use the input value to show the relation
// between child and parent by the use of the exit status.
int child_process_function(const int seconds)
{
printf("Child pid %d sleeps for %d seconds.\n", getpid(), seconds);
sleep(seconds);
printf("Child pid %d exits with %d.\n", getpid(), seconds);
return seconds;
}
int main(const int argc, const char *argv[])
{
int childs = 1;
if (argc > 1)
childs = atoi(argv[1]);
// start the child processes
for (int seconds = 1; seconds <= childs; ++seconds)
{
pid_t pid = fork();
if (pid == 0)
{
// child
const int status = child_process_function(seconds);
return status;
// anywhere else than main use exit(status);
// to terminate the child process.
// I prefer calling exit() close to fork() to be have the
// obvious relation and not hidden in the called function.
}
// parent
if (pid == -1)
printf("Parent pid %d failed to create %d. child process."
" Reason: %s\n", getpid(), seconds, strerror(errno));
else
printf("Parent pid %d created child %d.\n", getpid(), pid);
}
// parent waits for its child processes
printf("Parent pid %d waits for its childs.\n", getpid());
pid_t pid = 0;
do
{
int status = 0;
pid = wait(&status);
// in the trial do not care about errno could be modified by printf
printf("Parent pid %d wait pid %d status %d", getpid(), pid, status);
if (pid != -1 && WIFEXITED(status))
printf(" WEXITSTATUS %d", WEXITSTATUS(status));
else if (pid == -1)
printf(" errno %d (%s)", errno, strerror(errno));
printf(".\n");
} while (pid != -1 && errno != ECHILD);
printf("Parent pid %d exits.\n", getpid());
return EXIT_SUCCESS;
}
|
hareat/trials | c/shm_posix.c | // shm_posix.c shows the use of POSIX shared memory.
// In POSIX a pathname relative to /dev/shm is the shared information
// all processes or binaries need. The necessary size is often calculated.
// Uses fork() to create multiple processes - see fork.c.
// In the trial do not care about closing ressources in the case of an error.
//
// build: cc shm_posix.c -o shm_posix
// use: ./shm_posix
/////////////////////////////////////////////////////////////////////
#include <errno.h>
#include <fcntl.h> // O_*
#include <stdio.h>
#include <stdlib.h> // EXIT_*
#include <string.h> // strerror
#include <unistd.h> // fork sleep
#include <sys/mman.h>
#include <sys/wait.h>
int child_process_shm_read(const char *name, const size_t size)
{
const int mode = 0444; // octal is common; read only
const int shm_fd = shm_open(name, O_RDONLY, mode);
if (shm_fd == -1)
{
fprintf(stderr, "shm_open(%s, O_RDONLY, 0%03o)"
" failed with %d = %s\n", name, mode, errno, strerror(errno));
return EXIT_FAILURE;
}
printf("shm_open(%s, O_RDONLY, 0%03o) succeeded"
" with shm_fd = %d\n", name, mode, shm_fd);
char *addr = mmap(NULL, size, PROT_READ, MAP_SHARED, shm_fd, 0);
if (addr == MAP_FAILED)
{
fprintf(stderr, "%s: %s failed with %d = %s\n",
__func__, "mmap", errno, strerror(errno));
return EXIT_FAILURE;
}
for (int i = 1; i <= 5; ++i)
{
printf("child read: %s\n", addr);
sleep(1);
}
if (close(shm_fd) == -1)
{
fprintf(stderr, "%s: %s(%d) failed with %d = %s\n",
__func__, "shmdt", shm_fd, errno, strerror(errno));
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int child_process_shm_write(const char *name, const size_t size)
{
const int mode = 0644; // octal is common
const int shm_fd = shm_open(name, O_RDWR, mode);
if (shm_fd == -1)
{
fprintf(stderr, "shm_open(%s, O_RDWR, 0%03o)"
" failed with %d = %s\n", name, mode, errno, strerror(errno));
return EXIT_FAILURE;
}
printf("shm_open(%s, O_RDRW, 0%03o) succeeded"
" with shm_fd = %d\n", name, mode, shm_fd);
char *addr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
if (addr == MAP_FAILED)
{
fprintf(stderr, "%s: %s failed with %d = %s\n",
__func__, "mmap", errno, strerror(errno));
return EXIT_FAILURE;
}
for (int i = 1; i <= 5; ++i)
{
// in the trial do not care about using a semaphore or a lock
sprintf(addr, "child write %d\n", i);
sleep(1);
}
if (close(shm_fd) == -1)
{
fprintf(stderr, "%s: %s(%d) failed with %d = %s\n",
__func__, "shmdt", shm_fd, errno, strerror(errno));
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int main(int argc, char *argv[])
{
const char *name = "/shm_posix";
const size_t size = 1234;
const int mode = 0644; // octal is common
// IPC_EXCL | IPC_CREAT should ensure shm is created by this process.
const int shm_fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL, mode);
if (shm_fd == -1)
{
fprintf(stderr, "shm_open(%s, O_RDWR | O_CREAT | O_EXCL, 0%03o)"
" failed with %d = %s\n", name, mode, errno, strerror(errno));
return EXIT_FAILURE;
}
printf("shm_open(%s, O_RDWR | O_CREAT | O_EXCL, 0%03o) succeeded"
" with shm_fd = %d\n", name, mode, shm_fd);
printf("You can delete the shared memory with: rm /dev/shm%s\n", name);
// without fallocate you will get a "bus error"
if (posix_fallocate(shm_fd, 0, size) == -1)
{
fprintf(stderr, "%s failed with %d = %s\n",
"fallocate", errno, strerror(errno));
return EXIT_FAILURE;
}
char *addr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
if (addr == MAP_FAILED)
{
fprintf(stderr, "%s failed with %d = %s\n",
"mmap", errno, strerror(errno));
return EXIT_FAILURE;
}
strcpy(addr, "filled by parent");
pid_t pid = fork();
if (pid == -1)
{
printf("Parent failed to create %s. Reason: %s\n",
"child_process_shm_read", strerror(errno));
return EXIT_FAILURE;
}
if (pid == 0) // child
return child_process_shm_read(name, size);
// parent
pid = fork();
if (pid == -1)
{
printf("Parent failed to create %s. Reason: %s\n",
"child_process_shm_write", strerror(errno));
return EXIT_FAILURE;
}
if (pid == 0) // child
return child_process_shm_write(name, size);
// parent
// wait for all child processes to terminate
do {
int status = 0;
pid = wait(&status);
} while (pid != -1 && errno != ECHILD);
printf("parent read: %s\n", addr);
if (munmap(addr, size) == -1)
{
fprintf(stderr, "munmap(%p) failed with %d = %s\n",
addr, errno, strerror(errno));
return EXIT_FAILURE;
}
if (close(shm_fd) == -1)
{
fprintf(stderr, "%s: %s(%d) failed with %d = %s\n",
__func__, "shmdt", shm_fd, errno, strerror(errno));
return EXIT_FAILURE;
}
// remove the shared memory
if (shm_unlink(name) == -1)
{
fprintf(stderr, "shm_unlink(%s) failed with %d = %s\n",
name, errno, strerror(errno));
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
|
hareat/trials | c/shm_sysv.c | <gh_stars>0
// shm_sysv.c shows the use of System V shared memory.
// In System V a numeric key is the shared information all processes
// or binaries need. The necessary size is often calculated.
// Uses fork() to create multiple processes - see fork.c.
// In the trial do not care about closing ressources in the case of an error.
//
// build: cc shm_sysv.c -o shm_sysv
// use: ./shm_sysv
/////////////////////////////////////////////////////////////////////
#include <errno.h>
#include <stdio.h>
#include <stdlib.h> // EXIT_*
#include <string.h> // strerror
#include <unistd.h> // fork sleep
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/wait.h>
int child_process_shm_read(const key_t key, const size_t size)
{
const int mode = 0444; // octal is common; read only
const int shm_id = shmget(key, 0, mode);
if (shm_id == -1)
{
fprintf(stderr, "%s: shmget(0x%x, %zu, 0%03o) failed with %d = %s\n",
__func__, key, size, mode, errno, strerror(errno));
return EXIT_FAILURE;
}
printf("%s: shmget(0x%x, %zu, 0%03o) succeeded with shm_id = %d\n",
__func__, key, size, mode, shm_id);
char *addr = shmat(shm_id, NULL, SHM_RDONLY);
if (addr == ((void*)-1))
{
fprintf(stderr, "shmat(%d, NULL, SHM_RDONLY) failed with %d = %s\n",
shm_id, errno, strerror(errno));
return EXIT_FAILURE;
}
for (int i = 1; i <= 5; ++i)
{
printf("%s: %s\n", __func__, addr);
sleep(1);
}
if (shmdt(addr) == -1)
{
fprintf(stderr, "%s: shmdt(%d) failed with %d = %s\n",
__func__, shm_id, errno, strerror(errno));
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int child_process_shm_write(const key_t key, const size_t size)
{
const int mode = 0644; // octal is common
const int shm_id = shmget(key, 0, mode);
if (shm_id == -1)
{
fprintf(stderr, "%s: shmget(0x%x, %zu, 0%03o) failed with %d = %s\n",
__func__, key, size, mode, errno, strerror(errno));
return EXIT_FAILURE;
}
printf("%s: shmget(0x%x, %zu, 0%03o) succeeded with shm_id = %d\n",
__func__, key, size, mode, shm_id);
char *addr = shmat(shm_id, NULL, 0);
if (addr == ((void*)-1))
{
fprintf(stderr, "shmat(%d, NULL, 0) failed with %d = %s\n",
shm_id, errno, strerror(errno));
return EXIT_FAILURE;
}
for (int i = 1; i <= 5; ++i)
{
// in the trial do not care about using a semaphore or a lock
sprintf(addr, "child write %d", i);
sleep(1);
}
if (shmdt(addr) == -1)
{
fprintf(stderr, "%s: shmdt(%d) failed with %d = %s\n",
__func__, shm_id, errno, strerror(errno));
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int main(int argc, char *argv[])
{
const key_t key = 0x1234; // hex is common
const size_t size = 1234;
const int mode = 0644; // octal is common
// IPC_EXCL | IPC_CREAT should ensure shm is created by this process.
const int shm_id = shmget(key, size, mode | IPC_EXCL | IPC_CREAT);
if (shm_id == -1)
{
fprintf(stderr, "shmget(0x%x, %zu, 0%03o | IPC_EXCL | IPC_CREAT)"
" failed with %d = %s\n", key, size, mode, errno, strerror(errno));
return EXIT_FAILURE;
}
printf("%s; shmget(0x%x, %zu, 0%03o | IPC_EXCL | IPC_CREAT) succeeded"
" with shm_id = %d\n", __func__, key, size, mode, shm_id);
printf("You can delete the shared memory with: ipcrm -m %d\n", shm_id);
char *addr = shmat(shm_id, NULL, 0);
if (addr == ((void*)-1))
{
fprintf(stderr, "shmat(%d, NULL, 0) failed with %d = %s\n",
shm_id, errno, strerror(errno));
return EXIT_FAILURE;
}
strcpy(addr, "filled by parent");
pid_t pid = fork();
if (pid == -1)
{
printf("Parent failed to create %s. Reason: %s\n",
"child_process_shm_read", strerror(errno));
return EXIT_FAILURE;
}
if (pid == 0) // child
return child_process_shm_read(key, size);
// parent
pid = fork();
if (pid == -1)
{
printf("Parent failed to create %s. Reason: %s\n",
"child_process_shm_write", strerror(errno));
return EXIT_FAILURE;
}
if (pid == 0) // child
return child_process_shm_write(key, size);
// parent
// wait for all child processes to terminate
do {
int status = 0;
pid = wait(&status);
} while (pid != -1 && errno != ECHILD);
printf("%s: %s\n", __func__, addr);
if (shmdt(addr) == -1)
{
fprintf(stderr, "shmdt(%p) failed with %d = %s\n",
addr, errno, strerror(errno));
return EXIT_FAILURE;
}
// remove the shared memory
if (shmctl(shm_id, IPC_RMID, NULL) == -1)
{
fprintf(stderr, "shmctl(%d, IPC_RMID, NULL) failed with %d = %s\n",
shm_id, errno, strerror(errno));
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
|
hareat/trials | c/signal.c | <gh_stars>0
// signal.c shows the use of signal to handle signals.
// use kill -l for a list of signal numbers
//
// build: cc signal.c -o signal
// use: ./signal
// you have to kill with killall -9 signal
// because CTRL+C is handled by the signal handler, try it
// ./signal 10 12
// killall -s SIGUSR1 signal
// killall -s SIGUSR2 signal
// CTRL+C
// ./signal 10
// killall -s SIGUSR1 signal
// killall -s SIGUSR2 signal
/////////////////////////////////////////////////////////////////////
#include <signal.h>
#include <stdio.h> // perror
#include <stdlib.h> // atoi EXIT*
#include <string.h> // strlen
#include <unistd.h> // sleep write
const char* signum_to_sz(const int signum)
{
switch (signum)
{
case SIGHUP:
return "SIGHUP\n";
case SIGINT:
return "SIGINT\n";
case SIGQUIT:
return "SIGQUIT\n";
case SIGILL:
return "SIGILL\n";
case SIGTRAP:
return "SIGTRAP\n";
case SIGABRT:
return "SIGABRT\n";
case SIGBUS:
return "SIGBUS\n";
case SIGFPE:
return "SIGFPE\n";
case SIGKILL:
return "SIGKILL\n";
case SIGUSR1:
return "SIGUSR1\n";
case SIGSEGV:
return "SIGSEGV\n";
case SIGUSR2:
return "SIGUSR2\n";
case SIGPIPE:
return "SIGPIPE\n";
case SIGALRM:
return "SIGALRM\n";
case SIGTERM:
return "SIGTERM\n";
case SIGCHLD:
return "SIGCHLD\n";
case SIGCONT:
return "SIGCONT\n";
case SIGSTOP:
return "SIGSTOP\n";
case SIGTSTP:
return "SIGTSTP\n";
case SIGVTALRM:
return "SIGVTALRM\n";
default:
return "unknown\n";
}
}
void signal_handler(int signum)
{
const char *signame = signum_to_sz(signum);
// use write because it is signal safe. see man signal-safety
write(STDOUT_FILENO, signame, strlen(signame));
}
int main(const int argc, const char* argv[])
{
if (argc > 1) {
for (int i = 1; i < argc; ++i)
if (signal(atoi(argv[i]), signal_handler) == SIG_ERR) {
perror(argv[i]);
return EXIT_FAILURE;
}
} else { // no args
if (signal(SIGINT, signal_handler) == SIG_ERR
|| signal(SIGQUIT, signal_handler) == SIG_ERR
|| signal(SIGABRT, signal_handler) == SIG_ERR
|| signal(SIGKILL, signal_handler) == SIG_ERR
|| signal(SIGUSR1, signal_handler) == SIG_ERR
|| signal(SIGUSR2, signal_handler) == SIG_ERR
|| signal(SIGALRM, signal_handler) == SIG_ERR
|| signal(SIGTERM, signal_handler) == SIG_ERR
|| signal(SIGCHLD, signal_handler) == SIG_ERR
|| signal(SIGCONT, signal_handler) == SIG_ERR
|| signal(SIGSTOP, signal_handler) == SIG_ERR
|| signal(SIGTSTP, signal_handler) == SIG_ERR) {
perror("");
return EXIT_FAILURE;
}
}
for (int seconds = 1;; ++seconds) {
const char *output = "sleeping\n";
write(STDOUT_FILENO, output, strlen(output));
sleep(seconds);
}
return EXIT_SUCCESS;
}
|
hareat/trials | c/forkExec.c | // forkExec.c shows the use of fork+exec* to start several child programs.
//
// build: cc forkExec.c -o forkExec
// use: ./forkExec 3
// ./forkExec 5 /bin/sleep
// meanwhile try ps u to show the current processes
/////////////////////////////////////////////////////////////////////
#include <errno.h>
#include <stdio.h> // printf
#include <stdlib.h> // atoi exit EXIT_*
#include <string.h> // strerror
#include <unistd.h> // fork getpid sleep
#include <sys/wait.h>
int main(const int argc, const char *argv[])
{
int childs = 1;
if (argc > 1)
childs = atoi(argv[1]);
char *childbin = NULL;
if (argc > 2)
childbin = strdup(argv[2]);
else
childbin = strdup("bin/forkExecChild");
// in the trial do not care about childbin == NULL
// start the child processes
char buffer[22] = "";
for (int seconds = 1; seconds <= childs; ++seconds)
{
pid_t pid = fork();
if (pid == 0)
{
// child
snprintf(buffer, 22, "%d", seconds);
char* argvChild[3] = {childbin, buffer};
execv(childbin, argvChild);
// exec only return in case of an error
printf("Parent pid %d failed to replace %d. process image."
" Reason: %s\n", getpid(), seconds, strerror(errno));
return EXIT_FAILURE;
// anywhere else than main use exit(EXIT_FAILURE);
// to terminate the child process.
}
// parent
if (pid == -1)
printf("Parent pid %d failed to create %d. child process."
" Reason: %s\n", getpid(), seconds, strerror(errno));
else
printf("Parent pid %d created child %d.\n", getpid(), pid);
}
// parent waits for its child processes
printf("Parent pid %d waits for its childs.\n", getpid());
pid_t pid = 0;
do
{
int status = 0;
pid = wait(&status);
// in the trial do not care about errno could be modified by printf
printf("Parent pid %d wait pid %d status %d", getpid(), pid, status);
if (pid != -1 && WIFEXITED(status))
printf(" WEXITSTATUS %d", WEXITSTATUS(status));
else if (pid == -1)
printf(" errno %d (%s)", errno, strerror(errno));
printf(".\n");
} while (pid != -1 && errno != ECHILD);
free(childbin);
printf("Parent pid %d exits.\n", getpid());
return EXIT_SUCCESS;
}
|
tbartelmess/sqlite-trace | sqlite-trace/Public Headers/sqlite-trace.h | //
// sqlite-trace.h
// sqlite-trace
//
// Created by <NAME> on 2020-12-24.
//
#ifndef sqlite_trace_h
#define sqlite_trace_h
#include <stdio.h>
#include "sqlite3.h"
void sqlite_trace_configure(sqlite3* db, const char* name);
#endif
|
tbartelmess/sqlite-trace | sqlite-trace/main.c | //
// main.c
// sqlite-trace
//
// Created by <NAME> on 2020-12-21.
//
#include <stdio.h>
#include "sqlite3.h"
#include <os/log.h>
#include <os/signpost.h>
#include "Cleanup.h"
os_log_t logger;
os_signpost_id_t sqlite_signpost;
void setup_logger() {
logger = os_log_create("sqlite", "tracing");
sqlite_signpost = os_signpost_enabled(logger);
os_log_info(logger, "Hello Logger");
}
int sqlite_trace_profile(sqlite3_stmt* stmt, uint64_t* nanoseconds) {
os_log_debug(logger, "Statement %{public}s took %llu nanoseconds", sqlite3_expanded_sql(stmt), *nanoseconds);
return 0;
}
int sqlite_trace_callback(unsigned int type, void* context, void* p, void* x) {
switch (type) {
case SQLITE_TRACE_STMT:
os_signpost_event_emit(logger, sqlite_signpost, "STMT", "Statement: %{public}p SQL: %{public}s",
p, sqlite3_sql(p));
os_log_debug(logger, "Trace: STMT");
break;
case SQLITE_TRACE_PROFILE:
{
int32_t fullscan = sqlite3_stmt_status(p, SQLITE_STMTSTATUS_FULLSCAN_STEP, false);
int32_t sort = sqlite3_stmt_status(p, SQLITE_STMTSTATUS_SORT, false);
int32_t autoindex = sqlite3_stmt_status(p, SQLITE_STMTSTATUS_AUTOINDEX, false);
int32_t vm_step = sqlite3_stmt_status(p, SQLITE_STMTSTATUS_VM_STEP, false);
int32_t run_count = sqlite3_stmt_status(p, SQLITE_STMTSTATUS_RUN, false);
uint64_t* duration = x;
os_signpost_event_emit(logger,
sqlite_signpost,
"PROFILE",
"SQL: %{public}s duration: %llu "
"fullscan: %{public}d "
"sort: %{public}d "
"autoindex: %{public}d "
"vm_step: %{public}d "
"run: %{public}d",
sqlite3_expanded_sql(p),
*duration,
fullscan,
sort,
autoindex,
vm_step,
run_count);
}
break;
case SQLITE_TRACE_ROW:
os_log_debug(logger, "Trace: ROW");
break;
case SQLITE_TRACE_CLOSE:
os_log_debug(logger, "Trace: CLOSE");
break;
default:
os_log_error(logger, "Unknown trace type: %d", type);
}
return SQLITE_OK;
}
int configure_tracer(sqlite3* db) {
os_log_info(logger, "Configuring SQLite tracer for %p", db);
sqlite3_trace_v2(db, SQLITE_TRACE_STMT|SQLITE_TRACE_PROFILE|SQLITE_TRACE_ROW|SQLITE_TRACE_CLOSE, sqlite_trace_callback, NULL);
return SQLITE_OK;
}
int main(int argc, const char * argv[]) {
cleanup();
setup_logger();
os_log_info(logger, "Creating in-memory sqlite database");
sqlite3* database;
int result = sqlite3_open_v2("/tmp/testdb.sqlite", &database, SQLITE_OPEN_SHAREDCACHE | SQLITE_OPEN_CREATE| SQLITE_OPEN_READWRITE, NULL);
if (result != SQLITE_OK) {
os_log_error(logger, "Failed to open SQLite database");
}
os_log_info(logger, "Opened SQLite database");
configure_tracer(database);
sqlite3_stmt* create_table_statement;
result = sqlite3_prepare_v2(database, "CREATE TABLE foo (pk INTEGER PRIMARY KEY);", -1, &create_table_statement, NULL);
if (result != SQLITE_OK) {
os_log_error(logger, "Failed to prepare statement %{public}s", sqlite3_errmsg(database));
}
os_log_debug(logger, "Created Statement %{public}s", sqlite3_sql(create_table_statement));
result = sqlite3_step(create_table_statement);
if (result != SQLITE_DONE) {
os_log_error(logger, "Failed to stp statement %{public}s", sqlite3_errmsg(database));
}
return 0;
}
|
tbartelmess/sqlite-trace | sqlite-trace/sqlite-trace.c | //
// sqlite-trace.c
// sqlite-trace
//
// Created by <NAME> on 2020-12-24.
//
#include "sqlite-trace.h"
#include "sqlite3.h"
#include <os/log.h>
#include <os/signpost.h>
static os_log_t logger;
typedef struct {
os_signpost_id_t signpost_id;
char* name;
} sqlite_trace_context_t;
static void configure_logger() {
static dispatch_once_t token;
dispatch_once(&token, ^{
logger = os_log_create("io.bartelmess.sqlite-trace", "SQLite Trace");
});
}
static int sqlite_trace_callback(unsigned int type, void* ctx, void* p, void* x) {
sqlite_trace_context_t* context = ctx;
context->signpost_id = os_signpost_id_generate(logger);
switch (type) {
case SQLITE_TRACE_STMT:
os_signpost_event_emit(logger, context->signpost_id,
"STMT",
"statement %{public}p "
"SQL %{public}s",
p, sqlite3_normalized_sql(p));
os_log_debug(logger, "Trace: STMT");
break;
case SQLITE_TRACE_PROFILE:
{
int32_t fullscan = sqlite3_stmt_status(p, SQLITE_STMTSTATUS_FULLSCAN_STEP, false);
int32_t sort = sqlite3_stmt_status(p, SQLITE_STMTSTATUS_SORT, false);
int32_t autoindex = sqlite3_stmt_status(p, SQLITE_STMTSTATUS_AUTOINDEX, false);
int32_t vm_step = sqlite3_stmt_status(p, SQLITE_STMTSTATUS_VM_STEP, false);
int32_t run_count = sqlite3_stmt_status(p, SQLITE_STMTSTATUS_RUN, false);
uint64_t* duration = x;
os_signpost_event_emit(logger,
context->signpost_id,
"PROFILE",
"SQL: %{public}s duration: %llu "
"fullscan: %{public}d "
"sort: %{public}d "
"autoindex: %{public}d "
"vm_step: %{public}d "
"run: %{public}d",
sqlite3_normalized_sql(p),
*duration,
fullscan,
sort,
autoindex,
vm_step,
run_count);
}
break;
case SQLITE_TRACE_ROW:
os_log_debug(logger, "Trace: ROW");
break;
case SQLITE_TRACE_CLOSE:
os_log_debug(logger, "Trace: CLOSE");
break;
default:
os_log_error(logger, "Unknown trace type: %d", type);
}
return SQLITE_OK;
}
void sqlite_trace_configure(sqlite3* db, const char* name) {
configure_logger();
if (os_signpost_enabled(logger)) {
sqlite_trace_context_t* context = malloc(sizeof(sqlite_trace_context_t));
sqlite3_trace_v2(db, (SQLITE_TRACE_STMT| SQLITE_TRACE_PROFILE|SQLITE_TRACE_CLOSE), sqlite_trace_callback, context);
} else {
}
}
|
yingyulou/PDBToolsCpp | src/Residue.h | /*
Residue.h
=========
Class Residue header.
*/
#pragma once
#include <string>
#include <vector>
#include <unordered_map>
#include <utility>
#include <iostream>
#include <Eigen/Dense>
#include "NotAtom.h"
#include "NotProtein.h"
#include "Chain.h"
#include "Atom.h"
#include "Constants.hpp"
namespace PDBTools
{
////////////////////////////////////////////////////////////////////////////////
// Using
////////////////////////////////////////////////////////////////////////////////
using std::string;
using std::vector;
using std::unordered_map;
using std::pair;
using std::ostream;
using Eigen::RowVector3d;
using Eigen::Matrix3d;
////////////////////////////////////////////////////////////////////////////////
// Class Residue
////////////////////////////////////////////////////////////////////////////////
class Residue: public __NotAtom<Residue, Atom>,
public __NotProtein<Residue, Chain>
{
// Friend
friend ostream &operator<<(ostream &os, const Residue &resObj);
public:
// Constructor
explicit Residue(const string &name = "", int num = 0,
const string &ins = "", Chain *owner = nullptr);
// Getter: __name
string &name();
// Getter: __num
int num();
// Getter: __ins
string &ins();
// Getter: __owner
Chain *owner();
// Getter: __sub
vector<Atom *> &sub();
// Setter: __name
Residue *name(const string &val);
// Setter: __num
Residue *num(int val);
// Setter: __ins
Residue *ins(const string &val);
// Setter: __owner
Residue *owner(Chain *val);
// Setter: __sub
Residue *sub(const vector<Atom *> &val);
// Getter: compNum
string compNum();
// Setter: compNum
Residue *compNum(int num, const string &ins = "");
// Setter: compNum (by compNumPair)
Residue *compNum(const pair<int, string> &compNumPair);
// Copy
Residue *copy();
// GetResidues
vector<Residue *> getResidues();
// GetAtoms
vector<Atom *> getAtoms();
// subMap
unordered_map<string, Atom *> subMap();
// coordMap
unordered_map<string, RowVector3d> coordMap();
// Calc Backbone Dihedral Angle
double calcBBDihedralAngle(DIH dihedralEnum);
// Calc Backbone Rotation Matrix By Delta Angle
pair<RowVector3d, Matrix3d> calcBBRotationMatrixByDeltaAngle(
DIH dihedralEnum, SIDE sideEnum, double deltaAngle);
// Calc Backbone Rotation Matrix By Target Angle
pair<RowVector3d, Matrix3d> calcBBRotationMatrixByTargetAngle(
DIH dihedralEnum, SIDE sideEnum, double targetAngle);
// Get Backbone Rotation Atom Pointer
vector<Atom *> getBBRotationAtomPtr(DIH dihedralEnum, SIDE sideEnum);
// Rotate Backbone Dihedral Angle By Delta Angle
Residue *rotateBBDihedralAngleByDeltaAngle(DIH dihedralEnum,
SIDE sideEnum, double deltaAngle);
// Rotate Backbone Dihedral Angle By Target Angle
Residue *rotateBBDihedralAngleByTargetAngle(DIH dihedralEnum,
SIDE sideEnum, double targetAngle);
// Calc Side Chain Dihedral Angle
double calcSCDihedralAngle(int dihedralIdx);
// Calc Side Chain Rotation Matrix By Delta Angle
pair<RowVector3d, Matrix3d> calcSCRotationMatrixByDeltaAngle(
int dihedralIdx, double deltaAngle);
// Calc Side Chain Rotation Matrix By Target Angle
pair<RowVector3d, Matrix3d> calcSCRotationMatrixByTargetAngle(
int dihedralIdx, double targetAngle);
// Get Side Chain Rotation Atom Pointer
vector<Atom *> getSCRotationAtomPtr(int dihedralIdx);
// Rotate Side Chain Dihedral Angle By Delta Angle
Residue *rotateSCDihedralAngleByDeltaAngle(int dihedralIdx, double deltaAngle);
// Rotate Side Chain Dihedral Angle By Target Angle
Residue *rotateSCDihedralAngleByTargetAngle(int dihedralIdx, double targetAngle);
// Dump
Residue *dump(const string &dumpFilePath, const string &fileMode = "w");
// Destructor
~Residue();
private:
// Attribute
string __name;
int __num;
string __ins;
Chain *__owner;
vector<Atom *> __sub;
// str
string __str() const;
};
} // End namespace PDBTools
|
yingyulou/PDBToolsCpp | src/Protein.h | <reponame>yingyulou/PDBToolsCpp<filename>src/Protein.h
/*
Protein.h
=========
Class Protein header.
*/
#pragma once
#include <string>
#include <vector>
#include <unordered_map>
#include <iostream>
#include "NotAtom.h"
#include "Chain.h"
#include "Residue.h"
#include "Atom.h"
namespace PDBTools
{
////////////////////////////////////////////////////////////////////////////////
// Using
////////////////////////////////////////////////////////////////////////////////
using std::string;
using std::vector;
using std::unordered_map;
using std::ostream;
////////////////////////////////////////////////////////////////////////////////
// Class Protein
////////////////////////////////////////////////////////////////////////////////
class Protein: public __NotAtom<Protein, Chain>
{
// Friend
friend ostream &operator<<(ostream &os, const Protein &proObj);
public:
// Constructor
explicit Protein(const string &name = "", int model = 0);
// Getter: __name
string &name();
// Getter: __model
int model();
// Getter: __sub
vector<Chain *> &sub();
// Setter: __name
Protein *name(const string &val);
// Setter: __model
Protein *model(int val);
// Setter: __sub
Protein *sub(const vector<Chain *> &val);
// Copy
Protein *copy();
// Get Residues
vector<Residue *> getResidues();
// Get Atoms
vector<Atom *> getAtoms();
// subMap
unordered_map<string, Chain *> subMap();
// Dump
Protein *dump(const string &dumpFilePath, const string &fileMode = "w");
// Destructor
~Protein();
private:
// Attribute
string __name;
int __model;
vector<Chain *> __sub;
// str
string __str() const;
};
} // End namespace PDBTools
|
yingyulou/PDBToolsCpp | src/NotAtom.h | /*
NotAtom.h
=========
Class __NotAtom header.
*/
#pragma once
#include <string>
#include <vector>
#include <unordered_set>
#include <initializer_list>
#include <Eigen/Dense>
#include "Predecl.h"
namespace PDBTools
{
////////////////////////////////////////////////////////////////////////////////
// Using
////////////////////////////////////////////////////////////////////////////////
using std::string;
using std::vector;
using std::unordered_set;
using std::initializer_list;
using Eigen::RowVector3d;
using Eigen::Matrix;
using Eigen::Dynamic;
////////////////////////////////////////////////////////////////////////////////
// Class __NotAtom
////////////////////////////////////////////////////////////////////////////////
template <typename SelfType, typename SubType>
class __NotAtom
{
public:
// Begin
typename vector<SubType *>::iterator begin();
// End
typename vector<SubType *>::iterator end();
// Filter Atoms
vector<Atom *> filterAtoms(
const unordered_set<string> &atomNameSet = {"CA"});
// Get Atoms Coord
Matrix<double, Dynamic, 3> getAtomsCoord();
// Filter Atoms Coord
Matrix<double, Dynamic, 3> filterAtomsCoord(
const unordered_set<string> &atomNameSet = {"CA"});
// Center
RowVector3d center();
// Move Center
SelfType *moveCenter();
// Seq
string seq();
// Fasta Str
string fastaStr(const string &titleStr = "");
// Dump Fasta
SelfType *dumpFasta(const string &dumpFilePath,
const string &fileMode = "w", const string &titleStr = "");
// Renum Residues
SelfType *renumResidues(int startNum = 1);
// Renum Atoms
SelfType *renumAtoms(int startNum = 1);
// Append
SelfType *append(SubType *subPtr, bool copyBool = true);
// Insert
SelfType *insert(typename vector<SubType *>::iterator insertIter,
SubType *subPtr, bool copyBool = true);
// Remove Alt
SelfType *removeAlt();
// Dump Str
string dumpStr();
};
} // End namespace PDBTools
|
yingyulou/PDBToolsCpp | src/NotProtein.h | /*
NotProtein.h
============
Class __NotProtein header.
*/
#pragma once
#include <vector>
namespace PDBTools
{
////////////////////////////////////////////////////////////////////////////////
// Using
////////////////////////////////////////////////////////////////////////////////
using std::vector;
////////////////////////////////////////////////////////////////////////////////
// Class __NotProtein
////////////////////////////////////////////////////////////////////////////////
template <typename SelfType, typename OwnerType>
class __NotProtein
{
public:
// Iter
typename vector<SelfType *>::iterator iter();
// Prev
SelfType *prev(int shiftLen = 1);
// Next
SelfType *next(int shiftLen = 1);
// Remove
typename vector<SelfType *>::iterator remove(bool deteleBool = true);
};
} // End namespace PDBTools
|
yingyulou/PDBToolsCpp | src/Predecl.h | <filename>src/Predecl.h
/*
Predecl.h
=========
Struct class predeclaration.
*/
#pragma once
namespace PDBTools
{
////////////////////////////////////////////////////////////////////////////////
// Class Predeclaration
////////////////////////////////////////////////////////////////////////////////
class Protein;
class Chain;
class Residue;
class Atom;
} // End namespace PDBTools
|
yingyulou/PDBToolsCpp | src/Chain.h | /*
Chain.h
=======
Class Chain header.
*/
#pragma once
#include <string>
#include <vector>
#include <unordered_map>
#include <iostream>
#include "NotAtom.h"
#include "NotProtein.h"
#include "Protein.h"
#include "Residue.h"
#include "Atom.h"
namespace PDBTools
{
////////////////////////////////////////////////////////////////////////////////
// Using
////////////////////////////////////////////////////////////////////////////////
using std::string;
using std::vector;
using std::unordered_map;
using std::ostream;
////////////////////////////////////////////////////////////////////////////////
// Class Chain
////////////////////////////////////////////////////////////////////////////////
class Chain: public __NotAtom<Chain, Residue>,
public __NotProtein<Chain, Protein>
{
// Friend
friend ostream &operator<<(ostream &os, const Chain &chainObj);
public:
// Constructor
explicit Chain(const string &name = "", Protein *owner = nullptr);
// Getter: __name
string &name();
// Getter: __owner
Protein *owner();
// Getter: __sub
vector<Residue *> &sub();
// Setter: __name
Chain *name(const string &val);
// Setter: __owner
Chain *owner(Protein *val);
// Setter: __sub
Chain *sub(const vector<Residue *> &val);
// Copy
Chain *copy();
// GetResidues
vector<Residue *> getResidues();
// GetAtoms
vector<Atom *> getAtoms();
// subMap
unordered_map<string, Residue *> subMap();
// Dump
Chain *dump(const string &dumpFilePath, const string &fileMode = "w");
// Destructor
~Chain();
private:
// Attribute
string __name;
Protein *__owner;
vector<Residue *> __sub;
// str
string __str() const;
};
} // End namespace PDBTools
|
yingyulou/PDBToolsCpp | src/Atom.h | <filename>src/Atom.h
/*
Atom.h
======
Class Atom header.
*/
#pragma once
#include <string>
#include <iostream>
#include <Eigen/Dense>
#include "NotProtein.h"
#include "Residue.h"
namespace PDBTools
{
////////////////////////////////////////////////////////////////////////////////
// Using
////////////////////////////////////////////////////////////////////////////////
using std::string;
using std::ostream;
using Eigen::RowVector3d;
////////////////////////////////////////////////////////////////////////////////
// Class Atom
////////////////////////////////////////////////////////////////////////////////
class Atom: public __NotProtein<Atom, Residue>
{
// Friend
friend ostream &operator<<(ostream &os, const Atom &atomObj);
public:
// Constructor
explicit Atom(const string &name = "", int num = 0,
const RowVector3d &coord = RowVector3d::Zero(),
const string &alt = "", const string &occ = "",
const string &tempF = "", const string &ele = "",
const string &chg = "", Residue *owner = nullptr);
// Getter: __name
string &name();
// Getter: __num
int num();
// Getter: __coord
RowVector3d &coord();
// Getter: __alt
string &alt();
// Getter: __occ
string &occ();
// Getter: __tempF
string &tempF();
// Getter: __ele
string &ele();
// Getter: __chg
string &chg();
// Getter: __owner
Residue *owner();
// Setter: __name
Atom *name(const string &val);
// Setter: __num
Atom *num(int val);
// Setter: __coord
Atom *coord(const RowVector3d &val);
// Setter: __alt
Atom *alt(const string &val);
// Setter: __occ
Atom *occ(const string &val);
// Setter: __tempF
Atom *tempF(const string &val);
// Setter: __ele
Atom *ele(const string &val);
// Setter: __chg
Atom *chg(const string &val);
// Setter: __owner
Atom *owner(Residue *val);
// Copy
Atom *copy();
// operator-
double operator-(const Atom &rhs) const;
// Dump
Atom *dump(const string &dumpFilePath, const string &fileMode = "w");
// Dump Str
string dumpStr();
private:
// Attribute
string __name;
int __num;
RowVector3d __coord;
string __alt;
string __occ;
string __tempF;
string __ele;
string __chg;
Residue *__owner;
// str
string __str() const;
};
} // End namespace PDBTools
|
nikolausmayer/cpp-queueprocessor | QueueProcessor.h | <gh_stars>0
/**
* <NAME>, 2018 (<EMAIL>)
*/
#ifndef QUEUEPROCESSOR_H__
#define QUEUEPROCESSOR_H__
/// System/STL
#include <chrono>
#include <functional>
#include <memory>
#include <mutex>
#include <queue>
#include <thread>
namespace QueueProcessor
{
template <class T>
class QueueProcessor
{
typedef std::shared_ptr<T> item_t;
public:
QueueProcessor(
std::function<int(item_t&)> func,
unsigned int number_of_threads,
bool start_immediately);
~QueueProcessor();
void Start();
void Stop();
void BlockUntilDone() const;
bool IsDone() const;
void Give(
item_t item_ptr);
void Give(
T raw_item);
private:
void _WatchQueue();
int _ProcessItem(
item_t item_ptr);
void _PushItem(
item_t item_ptr);
bool m_running;
unsigned int m_threads;
bool m_print_information;
std::function<int(item_t&)> m_item_processor_handle;
std::queue<item_t> m_queue;
std::vector<std::thread*> m_worker_threads;
std::mutex m_queue_lock;
};
/**
* Implementation
*/
/// Not pretty but readable
#define QPT QueueProcessor<T>
template <class T>
QPT::QueueProcessor(std::function<int(item_t&)> func,
unsigned int number_of_threads,
bool start_immediately)
: m_running(start_immediately),
m_threads(number_of_threads),
m_item_processor_handle(func)
{
if (start_immediately) {
m_worker_threads.resize(m_threads);
for (size_t i = 0; i < m_worker_threads.size(); ++i) {
m_worker_threads[i] = new std::thread(&QPT::_WatchQueue, this);
}
}
}
template <class T>
QPT::~QueueProcessor()
{
m_running = false;
/// Stop and delete worker threads
for (size_t i = 0; i < m_worker_threads.size(); ++i) {
if (m_worker_threads[i]) {
if (m_worker_threads[i]->joinable()) {
m_worker_threads[i]->join();
}
delete m_worker_threads[i];
}
}
m_worker_threads.clear();
}
template <class T>
void QPT::Start()
{
if (m_running)
return;
m_running = true;
m_worker_threads.resize(m_threads);
for (size_t i = 0; i < m_worker_threads.size(); ++i) {
m_worker_threads[i] = new std::thread(&QPT::_WatchQueue, this);
}
}
template <class T>
void QPT::Stop()
{
if (not m_running)
return;
m_running = false;
/// Deplete queue (will NOT wait until items are processed)
m_queue_lock.lock();
while (m_queue.size() > 0) {
m_queue.pop();
}
m_queue_lock.unlock();
/// Stop and delete worker threads
for (size_t i = 0; i < m_worker_threads.size(); ++i) {
if (m_worker_threads[i]) {
if (m_worker_threads[i]->joinable()) {
m_worker_threads[i]->join();
}
delete m_worker_threads[i];
}
}
m_worker_threads.clear();
}
template <class T>
void QPT::BlockUntilDone() const
{
while (not IsDone()) {
std::this_thread::sleep_for(std::chrono::milliseconds{1});
}
}
template <class T>
bool QPT::IsDone() const
{
return (m_queue.size() == 0);
}
template <class T>
void QPT::Give(item_t item_ptr)
{
std::lock_guard<std::mutex> lock(m_queue_lock);
m_queue.push(item_ptr);
}
template <class T>
void QPT::Give(T raw_item)
{
std::lock_guard<std::mutex> lock(m_queue_lock);
m_queue.push(std::make_shared<T>(raw_item));
}
template <class T>
void QPT::_WatchQueue()
{
while (m_running or m_queue.size() > 0) {
if (m_queue.size() > 0) {
/// Read queue
item_t item;
m_queue_lock.lock();
try {
item = m_queue.front();
} catch(...) {
m_queue_lock.unlock();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
continue;
}
/// Pop from queue
try {
m_queue.pop();
} catch(...) {
m_queue_lock.unlock();
continue;
}
m_queue_lock.unlock();
/// Process item
_ProcessItem(item);
} else {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}
}
template <class T>
int QPT::_ProcessItem(item_t item)
{
return m_item_processor_handle(item);
}
#undef QPT
} // namespace QueueProcessor
#endif // QUEUEPROCESSOR_H__
|
sympt0m/fourth | fourth.c | #include "stdafx.h"
static volatile char *HELP = "Windows XP sucks and so does Visual C++ 2010, but I'm not about to shell out $200 for Windows 10 Pro for this keygenme stuff. I hate licensing costs.";
struct RSAKey {
uint32_t d;
uint32_t n;
uint32_t e;
};
static void
randombytes(void *buf, size_t len)
{
HCRYPTPROV p;
if (!CryptAcquireContext(&p, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
abort();
if (!CryptGenRandom(p, (DWORD)len, buf))
abort();
CryptReleaseContext(p, 0);
}
static uint32_t
modexp(uint32_t b, uint32_t e, uint32_t m)
{
uint32_t ret;
uint64_t i;
for (ret = 1; e != 0; e >>= 1) {
if ((e & 1) == 1) {
i = ret;
i *= b;
i %= m;
ret = (uint32_t)i;
}
i = b;
i *= b;
i %= m;
b = (uint32_t)i;
}
return ret;
}
#if GENERATING
/* lol RSA-32 */
static uint32_t
sign(const struct RSAKey *key, uint32_t seed)
{
return modexp(seed, key->d, key->n);
}
static void
generateSerial(const struct RSAKey *key, uint32_t serial[])
{
randombytes(&serial[0], sizeof(serial[0]));
serial[1] = sign(key, serial[0]);
}
static void
encodeKey(char *key, const uint32_t serial[])
{
static const char *alphabet = "ABCDEFGHIJKLMNOP";
const uint8_t *serialb = (const uint8_t *)serial;
size_t i;
for (i = 0; i < 2 * sizeof(*serial); ++i) {
*key++ = alphabet[serialb[i] >> 4];
*key++ = alphabet[serialb[i] & 0xF];
if (i != 0 && i != 2 * sizeof(*serial) - 1 && i % 2 == 1)
*key++ = '-';
}
key[19] = '\0';
}
#else
static bool
verify(const struct RSAKey *key, uint32_t seed, uint32_t sig)
{
/* Note: Normally verification functions operate over more than just one value.
*
* The correct way to verify is always timing-safe. In this case, we only
* compare one value, so the timing-safety is a given.
*/
return modexp(sig, key->e, key->n) == seed;
}
static int
decodeKey(uint32_t serial[], char *key)
{
uint8_t *serialb = (uint8_t *)serial;
serial[0] = 0;
serial[1] = 0;
while (*key != '\0') {
if (*key == '-') {
++key;
continue;
}
if (*key < 'A' || *key > 'P')
return -1;
*serialb++ = ((key[0] - 'A') << 4) | (key[1] - 'A');
key += 2;
}
return 0;
}
bool
isValidKey(const struct RSAKey *rsa, char *key)
{
uint32_t serial[2];
uint32_t *seed = serial, *sig = serial + 1;
if (strlen(key) != 19 || key[4] != '-' || key[9] != '-' || key[14] != '-')
return false;
if (decodeKey(serial, key) != 0)
return false;
return verify(rsa, *seed, *sig);
}
#endif
int
main(int argc, char *argv[])
{
const struct RSAKey rsa = {
#if GENERATING
0x77e18239,
#else
0,
#endif
0xc0c9eb8d, 0x10001
};
#if !(GENERATING)
if (argc < 2) {
fprintf(stderr, "Usage: %s key\n"
"This program will print \"PASS\" if the key is valid.\n", argv[0]);
return EXIT_FAILURE;
}
if (isValidKey(&rsa, argv[1])) {
puts("PASS");
return EXIT_SUCCESS;
} else {
return EXIT_FAILURE;
}
#else
uint32_t serial[2];
uint32_t *seed = serial, *checksum = serial + 1;
/* LDJL-JDGP-BMBC-OODL */
char key[20];
generateSerial(&rsa, serial);
encodeKey(key, serial);
printf("%s (== 0x%08x / 0x%08x)\n", key, serial[0], serial[1]);
return EXIT_SUCCESS;
#endif
}
|
sympt0m/fourth | stdafx.h | // stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
#include <Windows.h>
#include <WinCrypt.h>
#if defined(__STDC__) && __STDC_VERSION__ >= 199901L
#include <stdbool.h>
#else
typedef unsigned char bool;
#define true 1
#define false 0
#define __bool_true_false_are_defined 1
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <time.h>
#define GENERATING 0
|
egorzainullin/Skillbox-part-2 | Task8_3/Task8_3/TwoViewController.h | //
// TwoViewController.h
// Task8_3
//
// Created by <NAME> on 04.06.2022.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TwoViewController : UIViewController
@end
NS_ASSUME_NONNULL_END
|
egorzainullin/Skillbox-part-2 | Task8_3/Task8_3/ViewController.h | <gh_stars>0
//
// ViewController.h
// Task8_3
//
// Created by <NAME> on 04.06.2022.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
|
MasterofGalaxies/smg2-powerstarcolors | getstarcolorandstarselecthandler.c | #include <stddef.h>
#include <string.h>
extern char *getCurrentStageName__2MRFv(void);
extern void *makeGalaxyStatusAccessor__2MRFPCc(const char *galaxyname);
// Reads a galaxy's ScenarioData.bcsv
extern void FUN_804CBB60(void *galaxystatusaccessor, const char *column,
int starnumber, char **valueptr);
/*
* Checks if the Cosmic Guide was used to get a Star.
* Of the multiple functions that are used for this purpose,
* this is the one originally used by the Star Select code.
*/
extern int FUN_80024AE0(int starnumber);
/*
* Kamek seems to have a bug where it throws an error about a
* string's name being undefined when it is referenced in the
* same translation unit where it is defined, so we have to
* define these in another file (for which I used strings.s).
*/
extern const char powerstartype[];
extern const char gold[];
extern const char bronze[];
extern const char green[];
extern const char red[];
extern const char blue[];
int getstarcolor(char *galaxyname, int starnumber);
int starselect(int starnumber) {
/*
* Set the color of the Stars that appear on the Star
* Select screen. This function gets run for every
* Star on the Star Select screen that isn't clear.
*/
if (FUN_80024AE0(starnumber))
return 1;
int starcolor = getstarcolor(getCurrentStageName__2MRFv(), starnumber);
return starcolor == -1 ? 0 : starcolor;
}
int getstarcolor(char *galaxyname, int starnumber) {
char *powerstartypevalue = NULL;
FUN_804CBB60(makeGalaxyStatusAccessor__2MRFPCc(galaxyname),
powerstartype, starnumber, &powerstartypevalue);
if (powerstartypevalue == NULL)
return -1;
if (strcmp(powerstartypevalue, gold) == 0)
return 0;
if (strcmp(powerstartypevalue, bronze) == 0)
return 1;
if (strcmp(powerstartypevalue, green) == 0)
return 2;
if (strcmp(powerstartypevalue, red) == 0)
return 3;
if (strcmp(powerstartypevalue, blue) == 0)
return 4;
return -1;
}
|
CobaltXV/REP-001 | csrc/net/transmit.c | #include "transmit.h"
EXTERN_C_BEGIN
EXTERN_C_END |
CobaltXV/REP-001 | include/socket.h | #ifndef SOCKET_H
#define _SOCKET_H
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include "common.h"
#ifdef __cplusplus
# ifndef EXTERN_C
# define EXTERN_C extern "C"
# endif
# ifndef EXTERN_C_BEGIN
# define EXTERN_C_BEGIN extern "C" {
# endif
# ifndef EXTERN_C_END
# define EXTERN_C_END }
# endif
#else
# ifndef EXTERN_C
# define EXTERN_C
# endif
# ifndef EXTERN_C_BEGIN
# define EXTERN_C_BEGIN
# endif
# ifndef EXTERN_C_END
# define EXTERN_C_END
# endif
#endif
EXTERN_C typedef int32_t socket_t;
EXTERN_C typedef uint16_t port_t;
EXTERN_C typedef struct sockaddr_in sockaddr_in_t;
EXTERN_C typedef struct sockaddr sockaddr_t;
EXTERN_C_BEGIN
#define PORT_MAX 0xFFFF
#define DFL_PORT 0x49
socket_t CreateSecSocket(int domain, int type, int proto);
void CloseSocket(socket_t socket);
sockaddr_in_t CreateSockAddrInput(const char * restrict ip, int ip_define, int domain, port_t port);
int BindSockWithAddr(socket_t socket, sockaddr_in_t *addr);
port_t GetRandomPort(int seedterm);
port_t GetRandomRangePort(port_t *exclude, port_t begin, port_t end, int seedterm);
EXTERN_C_END
#endif |
CobaltXV/REP-001 | include/common.h | #ifndef _COMMON_H
#define _COMMON_H
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
# ifndef EXTERN_C
# define EXTERN_C extern "C"
# endif
# ifndef EXTERN_C_BEGIN
# define EXTERN_C_BEGIN extern "C" {
# endif
# ifndef EXTERN_C_END
# define EXTERN_C_END }
# endif
#else
# ifndef EXTERN_C
# define EXTERN_C
# endif
# ifndef EXTERN_C_BEGIN
# define EXTERN_C_BEGIN
# endif
# ifndef EXTERN_C_END
# define EXTERN_C_END
# endif
#endif
EXTERN_C_BEGIN
#define LIST_MAX 0xFF
bool SubValueList16(uint16_t *list, uint16_t item, int32_t size);
bool SubValueList32(uint32_t *list, uint32_t item, int32_t size);
bool SubValueList64(uint64_t *list, uint64_t item, int32_t size);
int16_t GetListSize16(uint16_t *list, uint16_t delim);
int32_t GetListSize32(uint32_t *list, uint32_t delim);
int64_t GetListSize64(uint64_t *list, uint64_t delim);
// TODO: GENERIC FUNCTIONS
EXTERN_C_END
#endif |
CobaltXV/REP-001 | csrc/net/socket.c | #include "socket.h"
EXTERN_C_BEGIN
socket_t CreateSecSocket(int domain, int type, int proto) {
socket_t sock;
sock = socket(domain, type, proto);
if (sock < 0) {
// TODO: ERROR
return (sock);
}
int returnValue;
returnValue = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &(int) {1}, sizeof(int));
if (returnValue < 0) {
// TODO: ERROR
return (returnValue);
}
return (sock);
}
port_t GetRandomPort(int seedterm) {
srand(time(NULL) + seedterm);
return ((port_t) (rand() % PORT_MAX) + 1);
}
port_t GetRandomRangePort(port_t *exclude, port_t begin, port_t end, int seedterm) {
port_t returnPort = 0;
int32_t size = GetListSize16(exclude, 0);
do {
srand(time(NULL) + seedterm);
returnPort = (port_t) ((rand() % (end - begin)) + begin + 1);
} while(!(SubValueList16(exclude, returnPort, size)));
return (returnPort);
}
void CloseSocket(socket_t socket) {
close(socket);
// TODO: ERROR
}
sockaddr_in_t CreateSockAddrInput(const char * restrict ip, int ip_define, int domain, port_t port) {
if ((ip_define == 0 && ip == NULL) || port == 0) {
// TODO: ERROR
}
sockaddr_in_t sockaddr;
memset(&sockaddr, '\0', sizeof(sockaddr_in_t));
sockaddr.sin_port = htons(port);
sockaddr.sin_family = domain;
if (ip == NULL && ip_define != 0) {
sockaddr.sin_addr.s_addr = ip_define;
return (sockaddr);
}
else if (inet_pton(domain, ip, &sockaddr.sin_addr) <= 0) {
// TODO: ERROR
}
return (sockaddr);
}
int BindSockWithAddr(socket_t socket, sockaddr_in_t *addr) {
if (socket <= 0 || addr == NULL) {
// TODO: ERROR
}
else {
if (bind(socket, (sockaddr_t *) addr, sizeof(addr)) < 0) {
// TODO: ERROR
}
}
return (1);
}
EXTERN_C_END |
CobaltXV/REP-001 | csrc/error.c | <filename>csrc/error.c
#include "error.h"
EXTERN_C_BEGIN
EXTERN_C_END |
CobaltXV/REP-001 | include/error.h | <gh_stars>0
#ifndef _ERROR_H
#define _ERROR_H
#ifdef __cplusplus
# ifndef EXTERN_C
# define EXTERN_C extern "C"
# endif
# ifndef EXTERN_C_BEGIN
# define EXTERN_C_BEGIN extern "C" {
# endif
# ifndef EXTERN_C_END
# define EXTERN_C_END }
# endif
#else
# ifndef EXTERN_C
# define EXTERN_C
# endif
# ifndef EXTERN_C_BEGIN
# define EXTERN_C_BEGIN
# endif
# ifndef EXTERN_C_END
# define EXTERN_C_END
# endif
#endif
EXTERN_C_BEGIN
EXTERN_C_END
#endif |
CobaltXV/REP-001 | csrc/enc/encrypt.c | <gh_stars>0
#include "encrypt.h"
EXTERN_C_BEGIN
EXTERN_C_END |
CobaltXV/REP-001 | csrc/common.c | #include "common.h"
EXTERN_C_BEGIN
bool SubValueList16(uint16_t *list, uint16_t item, int32_t size) {
if (list == NULL) {
// TODO: ERROR
return (false);
}
for (int32_t i = 0; i < size; i++) {
if (list[i] == item) return (true);
}
return (false);
}
bool SubValueList32(uint32_t *list, uint32_t item, int32_t size) {
if (list == NULL) {
// TODO: ERROR
return (false);
}
for (int32_t i = 0; i < size; i++) {
if (list[i] == item) return (true);
}
return (false);
}
bool SubValueList64(uint64_t *list, uint64_t item, int32_t size) {
if (list == NULL) {
// TODO: ERROR
return (false);
}
for (int32_t i = 0; i < size; i++) {
if (list[i] == item) return (true);
}
return (false);
}
int16_t GetListSize16(uint16_t *list, uint16_t delim) {
if (list == NULL) {
// TODO: ERROR
return (0);
}
int16_t count = 0;
for (int i = 0; i < LIST_MAX; i++) {
if (list[i] == delim) {
return (++count);
}
count++;
}
return (count);
}
int32_t GetListSize32(uint32_t *list, uint32_t delim) {
if (list == NULL) {
// TODO: ERROR
return (0);
}
int32_t count = 0;
for (int i = 0; i < LIST_MAX; i++) {
if (list[i] == delim) {
return (++count);
}
count++;
}
return (count);
}
int64_t GetListSize64(uint64_t *list, uint64_t delim) {
if (list == NULL) {
// TODO: ERROR
return (0);
}
int64_t count = 0;
for (int i = 0; i < LIST_MAX; i++) {
if (list[i] == delim) {
return (++count);
}
count++;
}
return (count);
}
EXTERN_C_END |
CobaltXV/REP-001 | csrc/main.c | <reponame>CobaltXV/REP-001<gh_stars>0
#include <stdio.h>
#include <stdlib.h>
#include "socket.h"
#include "transmit.h"
#include "encrypt.h"
#include "error.h"
#ifdef __cplusplus
# ifndef EXTERN_C
# define EXTERN_C extern "C"
# endif
# ifndef EXTERN_C_BEGIN
# define EXTERN_C_BEGIN extern "C" {
# endif
# ifndef EXTERN_C_END
# define EXTERN_C_END }
# endif
#endif
#ifndef STD_PORT
# define STD_PORT 502
#endif
// #define DEBUG
#ifdef DEBUG
# ifndef DEBUG_LOG
# define DEBUG_LOG(...) printf("\033[1;36mDebug \033[0m[\033[1;34m%d\033[0m]: ", __COUNTER__); printf(__VA_ARGS__)
# endif
#else
# ifndef DEBUG_LOG
# define DEBUG_LOG(...)
# endif
#endif
EXTERN_C_BEGIN
extern int main(int argc, char **argv) {
(void) argc;
(void) argv;
DEBUG_LOG("Starting Networking Processes..\n");
// TODO: AF_INET6 SUPPORT
socket_t socket = CreateSecSocket(AF_INET, SOCK_STREAM, 0);
if (socket < 0) { return (1); }
sockaddr_in_t servSocket = CreateSockAddrInput(NULL, INADDR_ANY, AF_INET, STD_PORT);
if (BindSockWithAddr(socket, &servSocket) == 1) {
DEBUG_LOG("Cleaning up..\n");
CloseSocket(socket);
return (1);
}
if (listen(socket, 5) < 0) {
// TODO: ERROR
}
DEBUG_LOG("Cleaning Up..\n");
CloseSocket(socket);
DEBUG_LOG("Finished Succesfully\n");
return (0);
}
EXTERN_C_END |
irustm/nodegui | src/cpp/include/nodegui/QtCore/QSize/qsize_wrap.h | <gh_stars>1-10
#pragma once
#include <napi.h>
#include <stdlib.h>
#include <QSize>
#include "core/Component/component_macro.h"
class QSizeWrap : public Napi::ObjectWrap<QSizeWrap> {
private:
std::unique_ptr<QSize> instance;
public:
static Napi::FunctionReference constructor;
static Napi::Object init(Napi::Env env, Napi::Object exports);
QSizeWrap(const Napi::CallbackInfo& info);
~QSizeWrap();
QSize* getInternalInstance();
// Wrapped methods
Napi::Value setHeight(const Napi::CallbackInfo& info);
Napi::Value setWidth(const Napi::CallbackInfo& info);
Napi::Value height(const Napi::CallbackInfo& info);
Napi::Value width(const Napi::CallbackInfo& info);
COMPONENT_WRAPPED_METHODS_DECLARATION
};
namespace StaticQSizeWrapMethods {
Napi::Value fromQVariant(const Napi::CallbackInfo& info);
} // namespace StaticQSizeWrapMethods |
irustm/nodegui | src/cpp/include/nodegui/QtWidgets/QAbstractButton/qabstractbutton_macro.h | <reponame>irustm/nodegui<gh_stars>1-10
#pragma once
#include "QtGui/QIcon/qicon_wrap.h"
#include "QtWidgets/QWidget/qwidget_macro.h"
#include "QtWidgets/QWidget/qwidget_wrap.h"
/*
This macro adds common QAbstractScrollArea exported methods
The exported methods are taken into this macro to avoid writing them in each
and every widget we export.
*/
#ifndef QABSTRACTBUTTON_WRAPPED_METHODS_DECLARATION
#define QABSTRACTBUTTON_WRAPPED_METHODS_DECLARATION \
QWIDGET_WRAPPED_METHODS_DECLARATION \
Napi::Value setText(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
\
Napi::String napiText = info[0].As<Napi::String>(); \
std::string text = napiText.Utf8Value(); \
this->instance->setText(QString::fromUtf8(text.c_str())); \
return env.Null(); \
} \
\
Napi::Value setIcon(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
\
Napi::Object iconObject = info[0].As<Napi::Object>(); \
QIconWrap* iconWrap = Napi::ObjectWrap<QIconWrap>::Unwrap(iconObject); \
this->instance->setIcon(*iconWrap->getInternalInstance()); \
return env.Null(); \
}
#endif // QABSTRACTBUTTON_WRAPPED_METHODS_DECLARATION
#ifndef QABSTRACTBUTTON_WRAPPED_METHODS_EXPORT_DEFINE
#define QABSTRACTBUTTON_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
InstanceMethod("setText", &WidgetWrapName::setText), \
InstanceMethod("setIcon", &WidgetWrapName::setIcon),
#endif // QABSTRACTBUTTON_WRAPPED_METHODS_EXPORT_DEFINE
|
irustm/nodegui | src/cpp/include/nodegui/QtWidgets/QSystemTrayIcon/qsystemtrayicon_wrap.h | #pragma once
#include <napi.h>
#include <QPointer>
#include "QtWidgets/QWidget/qwidget_macro.h"
#include "nsystemtrayicon.hpp"
class QSystemTrayIconWrap : public Napi::ObjectWrap<QSystemTrayIconWrap> {
private:
QPointer<NSystemTrayIcon> instance;
public:
static Napi::Object init(Napi::Env env, Napi::Object exports);
QSystemTrayIconWrap(const Napi::CallbackInfo& info);
~QSystemTrayIconWrap();
NSystemTrayIcon* getInternalInstance();
// class constructor
static Napi::FunctionReference constructor;
// wrapped methods
Napi::Value show(const Napi::CallbackInfo& info);
Napi::Value hide(const Napi::CallbackInfo& info);
Napi::Value setIcon(const Napi::CallbackInfo& info);
Napi::Value isVisible(const Napi::CallbackInfo& info);
Napi::Value setToolTip(const Napi::CallbackInfo& info);
Napi::Value setContextMenu(const Napi::CallbackInfo& info);
EVENTWIDGET_WRAPPED_METHODS_DECLARATION
};
|
irustm/nodegui | src/cpp/include/nodegui/QtWidgets/QBoxLayout/qboxlayout_wrap.h | <filename>src/cpp/include/nodegui/QtWidgets/QBoxLayout/qboxlayout_wrap.h
#pragma once
#include <napi.h>
#include <stdlib.h>
#include <QBoxLayout>
#include <QPointer>
#include "QtWidgets/QBoxLayout/nboxlayout.hpp"
#include "QtWidgets/QLayout/qlayout_macro.h"
class QBoxLayoutWrap : public Napi::ObjectWrap<QBoxLayoutWrap> {
private:
QPointer<NBoxLayout> instance;
public:
static Napi::Object init(Napi::Env env, Napi::Object exports);
QBoxLayoutWrap(const Napi::CallbackInfo& info);
~QBoxLayoutWrap();
NBoxLayout* getInternalInstance();
// class constructor
static Napi::FunctionReference constructor;
// wrapped methods
Napi::Value addLayout(const Napi::CallbackInfo& info);
Napi::Value addSpacing(const Napi::CallbackInfo& info);
Napi::Value addStretch(const Napi::CallbackInfo& info);
Napi::Value addStrut(const Napi::CallbackInfo& info);
Napi::Value addWidget(const Napi::CallbackInfo& info);
Napi::Value direction(const Napi::CallbackInfo& info);
Napi::Value insertLayout(const Napi::CallbackInfo& info);
Napi::Value removeWidget(const Napi::CallbackInfo& info);
Napi::Value setDirection(const Napi::CallbackInfo& info);
QLAYOUT_WRAPPED_METHODS_DECLARATION
};
|
irustm/nodegui | src/cpp/include/nodegui/QtGui/QKeySequence/qkeysequence_wrap.h | <gh_stars>1-10
#pragma once
#include <napi.h>
#include <stdlib.h>
#include <QKeySequence>
#include "core/Component/component_macro.h"
class QKeySequenceWrap : public Napi::ObjectWrap<QKeySequenceWrap> {
private:
std::unique_ptr<QKeySequence> instance;
public:
static Napi::FunctionReference constructor;
static Napi::Object init(Napi::Env env, Napi::Object exports);
QKeySequenceWrap(const Napi::CallbackInfo &info);
~QKeySequenceWrap();
QKeySequence *getInternalInstance();
// Wrapped methods
Napi::Value count(const Napi::CallbackInfo &info);
COMPONENT_WRAPPED_METHODS_DECLARATION
};
|
irustm/nodegui | src/cpp/include/nodegui/QtGui/QApplication/qapplication_wrap.h | <filename>src/cpp/include/nodegui/QtGui/QApplication/qapplication_wrap.h
#pragma once
#include <napi.h>
#include <QApplication>
#include <QPointer>
#include "core/Component/component_macro.h"
class QApplicationWrap : public Napi::ObjectWrap<QApplicationWrap> {
private:
QPointer<QApplication> instance;
static int argc;
static char** argv;
bool _wasManuallyCreated = false;
public:
static Napi::FunctionReference constructor;
static Napi::Object init(Napi::Env env, Napi::Object exports);
QApplicationWrap(const Napi::CallbackInfo& info);
~QApplicationWrap();
QApplication* getInternalInstance();
// Wrapped methods
Napi::Value processEvents(const Napi::CallbackInfo& info);
Napi::Value exec(const Napi::CallbackInfo& info);
Napi::Value quit(const Napi::CallbackInfo& info);
Napi::Value exit(const Napi::CallbackInfo& info);
Napi::Value setQuitOnLastWindowClosed(const Napi::CallbackInfo& info);
Napi::Value quitOnLastWindowClosed(const Napi::CallbackInfo& info);
COMPONENT_WRAPPED_METHODS_DECLARATION
};
namespace StaticQApplicationWrapMethods {
Napi::Value instance(const Napi::CallbackInfo& info);
Napi::Value clipboard(const Napi::CallbackInfo& info);
Napi::Value style(const Napi::CallbackInfo& info);
} // namespace StaticQApplicationWrapMethods
|
irustm/nodegui | src/cpp/include/nodegui/QtGui/QStyle/qstyle_wrap.h | #pragma once
#include <napi.h>
#include <QStyle>
#include "core/Component/component_macro.h"
class QStyleWrap : public Napi::ObjectWrap<QStyleWrap> {
private:
QStyle* instance;
public:
static Napi::FunctionReference constructor;
static Napi::Object init(Napi::Env env, Napi::Object exports);
QStyleWrap(const Napi::CallbackInfo& info);
QStyle* getInternalInstance();
// Wrapped methods
Napi::Value pixelMetric(const Napi::CallbackInfo& info);
COMPONENT_WRAPPED_METHODS_DECLARATION
};
|
stardot/ncc | mip/mipvsn.h | #define MIP_VERSION "500"
|
stardot/ncc | mip/aetree.h | <gh_stars>0
/*
* aetree.h - AE Tree constructor and print functions.
* Copyright (C) Acorn Computers Ltd., 1988-1990.
* Copyright (C) Codemist Ltd., 1987-1992.
* Copyright (C) Advanced RISC Machines Limited, 1991-1992.
* SPDX-Licence-Identifier: Apache-2.0
*/
/*
* RCS $Revision$ Codemist 15
* Checkin $Date$
* Revising $Author$
*/
#ifndef _aetree_h
#define _aetree_h
#ifndef _defs_LOADED
# include "defs.h"
#endif
/* NB: it is unclear that the TypeExpr creation fns should be in this */
/* mip file -- TypeExpr's are moving to being a cfe local (opaque) */
/* whose interface to mip is via mcrepoftype. */
#define mk_typevar() ((TypeExpr *)global_cons2(SU_Type, t_unknown, 0))
extern AEop tagbindsort(TagBinder *b);
extern Expr *mk_expr1(AEop op, TypeExpr *t, Expr *a1);
extern Expr *mk_expr2(AEop op, TypeExpr *t, Expr *a1, Expr *a2);
extern Expr *mk_exprlet(AEop op, TypeExpr *t, SynBindList *a1, Expr *a2);
extern Expr *mk_expr3(AEop op, TypeExpr *t, Expr *a1, Expr *a2, Expr *a3);
#ifdef EXTENSION_VALOF
extern Expr *mk_expr_valof(AEop op, TypeExpr *t, Cmd *c);
#endif
#ifdef TARGET_HAS_INLINE_ASSEMBLER
extern AsmInstr *mk_asminstr(void);
#endif
extern Expr *mk_exprwdot(AEop op, TypeExpr *t, Expr *a1, IPtr a2);
extern Expr *mk_exprbdot(AEop op, TypeExpr *t, Expr *a1, int32 a2, int32 a3,
int32 a4);
/* mkDeclRhsList is slowly dying in C++ (syntax aid only). */
extern DeclRhsList *mkDeclRhsList(Symstr *sv, TypeExpr *t, SET_BITMAP s);
extern TopDecl *mkTopDeclFnDef(AEop a, Binder *b, SynBindList *c,
Cmd *d, bool e);
extern TypeExpr *mk_typeexpr1(AEop op, TypeExpr *t, Expr *a1);
extern TypeExpr *mkTypeExprfn(AEop a, TypeExpr *b, SET_BITMAP s,
FormTypeList *c, const TypeExprFnAux *d);
extern TypeExpr *g_mkTypeExprfn(AEop a, TypeExpr *b, SET_BITMAP s,
FormTypeList *c, const TypeExprFnAux *d);
extern FormTypeList *mkFormTypeList(FormTypeList *ftcdr, Symstr *ftname,
TypeExpr *fttype, Expr *ftdefault);
extern FormTypeList *g_mkFormTypeList(FormTypeList *ftcdr, Symstr *ftname,
TypeExpr *fttype, Expr *ftdefault);
/* temporary home, pending demise... */
extern int32 evaluate(Expr *a);
extern Expr *globalize_int(int32 n);
extern FormTypeList *globalize_formals(FormTypeList *d);
/* globalize_typeexpr caches only basic types (including structs/typedefs) */
/* and pointers to things which are already cached. Tough ched arrays/fns */
extern TypeExpr *globalize_typeexpr(TypeExpr *t);
/* and this omits default argument values to avoid a redeclaration by a */
/* postponed class function definition */
extern TypeExpr *globalize_typeexpr_no_default_arg_vals(TypeExpr *t);
extern StringSegList *globalize_strseg(StringSegList *s);
extern Expr *globalize_expr(Expr *e);
extern ScopeSaver globalize_env(ScopeSaver env);
extern TypeExpr *clone_typeexpr(TypeExpr *t);
extern void aetree_init(void);
extern Cmd *mk_cmd_0(AEop op, FileLine x);
/* op = s_break,s_endcase,s_continue */
extern Cmd *mk_cmd_e(AEop op, FileLine x, Expr *e);
/* op = s_return,s_semicolon */
extern Cmd *mk_cmd_default(FileLine x, Cmd *c);
extern Cmd *mk_cmd_lab(AEop op, FileLine x, LabBind *b, Cmd *c);
extern Cmd *mk_cmd_block(FileLine x, SynBindList *bl, CmdList *cl);
extern Cmd *mk_cmd_do(FileLine x, Cmd *c, Expr *e);
extern Cmd *mk_cmd_if(FileLine x, Expr *e, Cmd *c1, Cmd *c2);
extern Cmd *mk_cmd_switch(FileLine x, Expr *e, Cmd *c1, Cmd *c2, Cmd *c3);
extern Cmd *mk_cmd_for(FileLine x, Expr *e1, Expr *e2, Expr *e3, Cmd *c);
extern Cmd *mk_cmd_case(FileLine x, Expr *e, Cmd *c1, Cmd *c2);
extern Cmd *mk_cmd_try(FileLine x, Cmd *body, Handler *handler_list, Cmd *exit);
extern bool is_fpzero(Expr const *e);
extern bool is_fpone(Expr const *e);
extern bool is_fpminusone(Expr const *e);
extern int32 result2;
extern bool integer_constant(Expr const *e);
extern bool is_intzero(Expr const *e);
extern bool is_intone(Expr const *e);
extern bool is_intminusone(Expr const *e);
extern bool resultinflags_fn(Expr *e);
extern void eprintf(char const *s, ...);
extern void pr_typeexpr(TypeExpr *x, Symstr *s);
extern void pr_stringsegs(StringSegList *z);
void pr_int64(int64 const *x);
extern void pr_expr(Expr *x);
extern void pr_exproftype(char const *s, Expr *x);
extern void pr_cmd(Cmd *c);
extern void pr_topdecl(TopDecl *x);
extern void pr_typeexpr_nl(TypeExpr *x, Symstr *s);
extern void pr_expr_nl(Expr *x);
#endif
/* end of aetree.h */
|
stardot/ncc | tests/2368.c | /*
* ARM C compiler regression test $RCSfile$
* Copyright (C) 1997 Advanced Risc Machines Ltd. All rights reserved.
* SPDX-Licence-Identifier: Apache-2.0
*/
/*
* RCS $Revision$
* Checkin $Date$
* Revising $Author$
*/
#include "testutil.h"
/********************* 2368 ***********************/
/* no executable test needed */
#include <math.h>
double t1_2368(double a)
{
return a;
}
void t_2368(void)
{
double a, b, c;
a = t1_2368(1.1);
b = t1_2368(1.2);
c = t1_2368(a / b);
}
/********************* ***********************/
int main(void)
{
BeginTest();
EndTest();
return 0;
}
|
stardot/ncc | arm/asm.c | <filename>arm/asm.c
/*
* arm/asm.c: ARM assembly language output, Codemist version 21
* Copyright (C) Codemist Ltd., 1987-1993
* Copyright (C) Advanced RISC Machines Limited., 1990-1993
* SPDX-Licence-Identifier: Apache-2.0
*/
/*
* RCS $Revision$
* Checkin $Date$
* Revising $Author$
*/
/* Assembler output is routed to asmstream, annotated if FEATURE_ANNOTATE. */
/* See c.armobj for more details on datastructures. */
/* exports: asmstream, display_assembly_code, asm_header, asm_trailer. */
#ifdef __STDC__
# include <string.h>
#else
# include <strings.h>
#endif
#include <ctype.h>
#include "globals.h"
#include "mcdep.h"
#include "mcdpriv.h"
#include "xrefs.h"
#include "store.h"
#include "codebuf.h"
#include "armops.h"
#include "version.h"
#include "builtin.h" /* for codesegment, code_area_idx... */
#include "errors.h"
#include "disass.h"
#include "bind.h"
#ifdef CPLUSPLUS
#include "unmangle.h"
#endif
#define lx_arg(x) ((unsigned long)((x) & 0xfffffffful))
FILE *asmstream;
#ifndef NO_ASSEMBLER_OUTPUT
#define annotations (feature & FEATURE_ANNOTATE)
static char const spaces_18[20] = " \0"; /* 18 blanks and 2 NULs */
static char const *regnames[16] = {"a1","a2","a3","a4","v1","v2","v3","v4",
"v5","v6","fp","sl","ip","sp","lr","pc"};
/* fp and sl may change when pcs is set */
static char const *fregnames[8] = {"f0","f1","f2","f3","f4","f5","f6","f7"};
static Symstr *out_codeseg;
static bool first_area;
static bool new_area;
static void newline(void)
{
fputc('\n', asmstream);
}
static void indent_18_if_annotating(void)
{
if (annotations) fputs(spaces_18, asmstream);
}
static void padtocol8(unsigned32 n)
{
if (n > 8) n = 8;
fputs(spaces_18 + 18 - 8 + n, asmstream);
}
static void indent8(void)
{
padtocol8(0);
}
static void pr_chars(int32 w)
/* Works on both sexes of host machine. */
/* Assumes ASCII target machine. */
{ unsigned i, c;
FILE *as = asmstream;
fputc('\'', as);
for (i=0; i<sizeof(int32); i++)
{ c = ((uint8 *)&w)[i];
if (c < ' ' || c >= 127)
{ if (c >= 7 && c <= 13)
{ c = "abtnvfr"[c-7];
goto escape;
}
else
{ fprintf(as, "\\%o", c);
continue;
}
}
else if (c == '\\' || c == '\'' || c == '\"')
escape: fputc('\\', as);
fputc(c, as);
}
fputc('\'', as);
}
static void spr_asmname(char *buf, char const *s)
{ const char *s1 = s;
char c;
bool oddchars = NO;
if (!isalpha(*s) && *s != '_')
oddchars = YES;
else
while ((c = *s1++) != 0)
if (!isalnum(c) && c != '_')
{ oddchars=YES;
break;
}
if (oddchars)
sprintf(buf, "|%s|", s);
else
strcpy(buf, s);
}
static void spr_asmsym(char *buf, Symstr const *sym) {
spr_asmname(buf, symname_(sym));
}
static void pr_asmname(char const *s) {
char buf[256];
spr_asmname(buf, s);
fputs(buf, asmstream);
}
static void pr_asmsym(Symstr const *sym) {
char buf[256];
spr_asmsym(buf, sym);
fputs(buf, asmstream);
}
#ifdef CPLUSPLUS
static void pr_unmangled_name(const Symstr *sym) {
char buf[256];
if (LanguageIsCPlusPlus && annotations) {
char const *name = unmangle2(symname_(sym), buf, sizeof buf);
if (name != symname_(sym))
fprintf(asmstream, " ; %s", buf);
}
}
#else
#define pr_unmangled_name(sym) ((void)0)
#endif
static Symstr *find_extsym(int32 p)
{ CodeXref *x;
for (x = codexrefs; x != NULL; x = x->codexrcdr) {
if (p == (x->codexroff & 0x00ffffffL)) return(x->codexrsym);
}
syserr(syserr_find_extsym);
return(NULL);
}
static void printlabelname(char *buf, const char *before, const char *after, int32 offset, const Symstr *sym)
{
/* For data references, ignore the function name: it will be wrong for backward
* references to the literal pool of another function. (Labels which are the
* subject of data references have already been removed from asm_lablist).
* For code refs, generate a label of the form L<address>.J<label>.<proc>.
*/
LabList *p;
/*
* in various places showcode(NULL) gets called - the following lines arrange
* that the stuff printed here is nevertheless at least textual.
*/
if (sym != NULL)
{ for ( p = asm_lablist ; p != NULL ; p = p->labcdr) {
LabelNumber *lab = p->labcar;
if ((lab->u.defn & 0x00ffffff) == offset)
{ sprintf(buf, "%s|L%.6lx.J%ld.%s|%s",
before, offset+codebase, lab_name_(lab) & 0x7fffffff,
symname_(sym), after);
return;
}
}
}
sprintf(buf, "%sL%lx%.5lx%s", before,
code_area_idx == 1 ? 0L : code_area_idx, offset+codebase, after);
}
static Symstr const *procname;
typedef struct RelAddrRec {
Symstr *sym;
int32 count;
int32 offset;
char *buf;
} RelAddrRec;
static char *disass_adrl(RelAddrRec *r, char *buf, int32 offset) {
int pos = (r->buf[3] == 'S' || r->buf[3] == ' ') ? 3 : 5;
int c = r->buf[pos];
do buf--; while (buf[-1] != ',');
memcpy(r->buf, "ADR", 3);
while (--r->count >= 0) r->buf[pos++] = 'L';
r->buf[pos] = c;
if (offset != 0) {
sprintf(buf, "%ld+", offset);
buf += strlen(buf);
}
spr_asmsym(buf, r->sym);
return buf;
}
static List *litlabels;
static int32 LiteralBefore(int32 target) {
List *p;
for (p = litlabels; p != NULL; p = cdr_(p))
if (car_(p) <= target) return car_(p);
return 0;
}
static char *disass_cb(dis_cb_type type, int32 offset, unsigned32 address, int w, void *cb_arg, char *buf) {
RelAddrRec *r = (RelAddrRec *)cb_arg;
IGNORE(w);
*buf = 0;
if (type == D_BORBL) {
if (cb_arg == NULL)
printlabelname(buf, "", "", address, procname);
else
spr_asmsym(buf, r->sym);
} else if (type == D_ADDPCREL) {
if (r != NULL)
buf = disass_adrl(r, buf, address + offset + r->offset);
else
printlabelname(buf, "#", "-.-8", address+offset, procname);
} else if (type == D_SUBPCREL) {
if (r != NULL)
buf = disass_adrl(r, buf, address - offset - r->offset);
else {
/* Backward reference to a string may be to an address part way through
a literal in a different function, for which therefore no label was
generated. (Hence the list litlabels).
*/
int32 target = address - offset + codebase;
int32 litaddr = LiteralBefore(target);
if (litaddr == target)
printlabelname(buf, "#.+8-", "", address - offset, procname);
else {
char b[8];
sprintf(b, "+%ld)", target - litaddr);
printlabelname(buf, "#.+8-(", b, litaddr - codebase, procname);
}
}
} else if (type == D_LOADPCREL || type == D_STOREPCREL) {
/* Backward references here can't currently be to an address for which
no label was generated (loading as an integer the second word of a
double constant or some non-initial word of a string are the
possibilities, which literal pool management currently precludes).
Still, we allow the possibility for safety.
*/
int32 target = address + codebase;
int32 litaddr = offset >= 0 ? target : LiteralBefore(target);
if (litaddr == target)
printlabelname(buf, "[pc, #", "-.-8]", address, procname);
else {
char b[8];
sprintf(b, "+%ld)-.-8", target - litaddr);
printlabelname(buf, "[pc, #(", b, litaddr - codebase, procname);
}
} else if (type == D_LOAD || type == D_STORE) {
if (r != NULL) {
sprintf(buf, "%ld+", offset);
buf += strlen(buf);
spr_asmsym(buf, r->sym);
}
}
return buf+strlen(buf);
}
typedef struct Import {
struct Import *next;
Symstr *sym;
int32 patch;
} Import;
static char *asm_needslabel; /* a bitmap, 1 bit per code word */
#define needslabel(widx) (((widx) & 0x80000000) ? 0 : (asm_needslabel[(widx) >> 3] & (1 << ((widx)&7))))
#define setlabbit(widx) (((widx) & 0x80000000) ? 0 : (asm_needslabel[(widx) >> 3] |= (1 << ((widx)&7))))
static void NoteLiteralLabel(int32 q) {
if (needslabel(q / 4))
litlabels = (List *)global_cons2(SU_Other, litlabels, q+codebase);
}
static void killasmlabel(int32 wordoffset)
{
/* Ensure that jopcode labels are present only for instructions, not data items */
LabList *p, *prev = NULL;
int32 offset = wordoffset * 4L;
for ( p = asm_lablist ; p != NULL ; prev = p, p = p->labcdr)
if ((p->labcar->u.defn & 0x00ffffff) == offset) {
p = (LabList *) discard2((VoidStar) p);
if (prev == NULL)
asm_lablist = p;
else
prev->labcdr = p;
return;
}
}
static int32 immediateval(int32 w) {
int32 shift = (w & 0xf00)>>7, val = w & 0xff;
return (val>>shift) | (val<<(32-shift));
}
static void asm_scancode(void)
{ int32 p;
int bitmapsize;
char *x;
bitmapsize = (int)((codep + 127) >> 5); /* > 1 bit per word of code */
asm_needslabel = x = (char *)BindAlloc(bitmapsize);
memclr((VoidStar)x, bitmapsize);
for (p = 0; p < codep; p += 4) {
int32 w = code_inst_(p);
int32 f = code_flag_(p);
switch (f) {
case LIT_ADCON:
{ Symstr *sym = find_extsym(codebase+p);
ExtRef *xr = symext_(sym);
if (xr->extflags & xr_defloc) setlabbit(xr->extoffset/4);
break;
}
case LIT_RELADDR:
break;
case LIT_OPCODE:
switch (w & 0x0f000000) {
case OP_B: case OP_BL:
if (w & 0x00800000L) w |= 0xff000000L; else w &= 0x00ffffffL;
w = (p / 4L) + 2L + w; /* word index */
setlabbit(w);
break;
case OP_PREN:
if (((w >> 16L) & 0xfL) == R_PC) {
int32 d = w & 0xfffL;
if ((w & F_UP)==0) d = -d;
w = (p + 8L + d) / 4L;
setlabbit(w);
killasmlabel(w);
}
break;
case 0x02000000L:
{ int32 op = w & (0xfL << 21L);
if ( (op == F_ADD || op == F_SUB) &&
(((w >> 16L) & 0xfL) == R_PC)) {
int32 val = immediateval(w);
if (op == F_SUB) val = -val;
w = (p + 8L + val) / 4L;
setlabbit(w);
killasmlabel(w);
}
}
break;
case OP_CPPRE:
if (((w >> 16L) & 0xfL) == R_PC) {
int32 d = w & 0xffL;
if ((w & F_UP)==0) d = -d;
w = (p + 8L) / 4L + d;
setlabbit(w);
killasmlabel(w);
}
break;
default:
break;
}
default:
break;
}
}
}
/* exported functions ...*/
static bool headerdone;
static void asm_areadef(char const *name, char const *attrib1, char const *attrib2)
{
newline();
indent8();
indent_18_if_annotating();
fputs("AREA ", asmstream);
pr_asmname(name);
fprintf(asmstream, "%s, %s\n", attrib1, attrib2);
}
static void asm_areaname(Symstr const *name, char const *attributes, bool export_area)
{ char const *s = symname_(name);
if (export_area) {
newline();
indent8();
indent_18_if_annotating();
fputs("EXPORT ", asmstream);
pr_asmname(s);
pr_unmangled_name(name);
}
asm_areadef(s, "", attributes);
}
void display_assembly_code(Symstr const *name)
{ uint32 q, qend;
FILE *as = asmstream;
char buf[255];
if (codep == 0)
{
new_area = YES;
return;
}
if (new_area)
{
Symstr *sym = bindsym_(codesegment);
char segname[255];
sprintf(segname, "C$$%s", symname_(sym) + 2);
if (!first_area)
asm_areadef(segname, (obj_iscommoncode() ? ", COMDEF" : ""),
"CODE, READONLY");
newline();
pr_asmname(symname_(sym));
fprintf(as, " DATA");
pr_unmangled_name(sym);
newline();
first_area = NO;
new_area = NO;
}
newline();
if (name != NULL) {
/* may be NULL for string literals from static inits */
procname = name;
if (StrEq(symname_(name), "main"))
obj_symref(libentrypoint, xr_code, 0);
indent_18_if_annotating();
pr_asmsym(name);
pr_unmangled_name(name);
newline();
}
asm_scancode();
for (q = 0, qend = codep; q < qend; q += 4) /* q is now a BYTE offset */
{ int32 w = code_inst_(q),
f = code_flag_(q);
VoidStar aux = code_aux_(q);
if (needslabel(q / 4))
{ indent_18_if_annotating();
printlabelname(buf, "", "\n", q, name);
fputs(buf, as);
}
if (annotations)
fprintf(as, "%.6lx %.8lx ", (long)(q + codebase), lx_arg(w));
if (f != LIT_FPNUM2) indent8();
switch(f)
{
case LIT_RELADDR:
{ unsigned32 oldq = q;
RelAddrRec r;
r.sym = (Symstr *)aux; r.offset = 0; r.count = 0;
r.buf = buf;
if ((w & 0x0f000000L) == 0x02000000L) {
int32 rd = (w >> 12) & 0xfL;
while (q+4 < qend && code_flag_(q+4) == LIT_OPCODE &&
!needslabel((q+4)/4)) {
int32 w1 = code_inst_(q+4);
if (((w1 ^ w) & 0xfff00000L) != 0 ||
((w1 >> 12) & 0xfL) != rd ||
((w1 >> 16) & 0xfL) != rd)
break;
q += 4;
r.count++; r.offset += immediateval(w1);
}
}
disass(w, oldq, buf, (void *)&r, disass_cb);
fputs(buf, as);
pr_unmangled_name((Symstr *)aux);
break;
}
case LIT_OPCODE:
disass(w, q, buf, (void *)0, disass_cb);
fputs(buf, as);
break;
case LIT_STRING:
NoteLiteralLabel(q);
{ int32 tmpw = w;
unsigned char *uc = (unsigned char *)&tmpw;
fprintf(as, "DCB 0x%.2x,0x%.2x,0x%.2x,0x%.2x",
uc[0], uc[1], uc[2], uc[3]);
}
if (annotations) fprintf(as, " ; "), pr_chars(w);
break;
case LIT_NUMBER:
NoteLiteralLabel(q);
fprintf(as, "DCD 0x%.8lx", lx_arg(w));
break;
case LIT_ADCON:
NoteLiteralLabel(q);
{ Symstr *sym = find_extsym(codebase+q);
fputs("DCD ", as); pr_asmsym(sym);
if (w != 0) fprintf(as, "+0x%lx", lx_arg(w));
pr_unmangled_name(sym);
}
break;
case LIT_FPNUM:
NoteLiteralLabel(q);
{ char *s = (char *)aux;
if (*s != '<') {
fprintf(as, "DCFS %s", s);
} else {
fprintf(as, "DCD 0x%.8lx", lx_arg(w));
}
}
break;
case LIT_FPNUM1:
NoteLiteralLabel(q);
{ char *s = (char *)aux;
if (*s != '<') {
fprintf(as, "DCFD %s", s);
} else {
fprintf(as, "DCD 0x%.8lx, 0x%.8lx",
lx_arg(w), lx_arg(code_inst_(q+4)) );
}
}
break;
case LIT_FPNUM2: /* all printed by the FPNUM1 */
if (annotations) break; else continue;
case LIT_INT64_1:
NoteLiteralLabel(q);
fprintf(as, "DCD 0x%.8lx, 0x%.8lx", lx_arg(w), lx_arg(code_inst_(q+4)) );
break;
case LIT_INT64_2: /* all printed by the FPNUM1 */
if (annotations) break; else continue;
default:
fputs("???", as);
}
newline();
}
}
void asm_header(void)
{
char b[64];
litlabels = NULL;
first_area = YES;
new_area = NO;
disass_sethexprefix("&");
disass_setregnames(regnames, fregnames);
headerdone = YES;
strcpy(b, "Lib$$Request$$armlib$$");
target_lib_variant(&b[22]);
obj_symref(sym_insert_id(b), xr_code+xr_weak, 0);
fprintf(asmstream, "; generated by %s\n", CC_BANNER);
if (annotations) return; /* do not bore interactive user */
asm_areadef("C$$code", (obj_iscommoncode() ? ", COMDEF" : ""),
"CODE, READONLY");
}
static void asm_outextern(void)
{
ExtRef *x;
int first;
first = 1;
for (x = obj_symlist; x != 0; x = x->extcdr) {
int32 flags = x->extflags;
if (!(flags & xr_objflg) && !(flags & xr_defloc) && (flags & xr_defext)) {
if (first) newline();
first = 0;
indent8();
indent_18_if_annotating();
fprintf(asmstream, "EXPORT ");
pr_asmsym(x->extsym);
fprintf(asmstream, "\n");
}
}
first = 1;
for (x = obj_symlist; x != 0; x = x->extcdr) {
int32 flags = x->extflags;
if (!(flags & xr_objflg) && !(flags & xr_defloc)
&& !(flags & xr_defext)
#ifdef CONST_DATA_IN_CODE
&& x->extsym != bindsym_(constdatasegment)
#endif
) {
/* COMMON data dealt with earlier */
if (!(flags & xr_code) && (x->extoffset > 0)) continue;
if (first) newline();
first = 0;
indent8();
indent_18_if_annotating();
fprintf(asmstream, "IMPORT ");
pr_asmsym(x->extsym);
if (x->extflags & xr_weak)
fprintf(asmstream, ", WEAK");
fprintf(asmstream, "\n");
}
}
}
void asm_setregname(int regno, char const *name) {
if (regno < R_F0) {
if (headerdone) fprintf(asmstream, "%s RN %d\n", name, regno);
regnames[regno] = name;
} else {
regno -= R_F0;
if (headerdone) fprintf(asmstream, "%s FN %d\n", name, regno);
fregnames[regno] = name;
}
}
static void asm_checklenandrpt(int32 len, int lenwanted, int32 rpt, int32 val) {
bool norpt = NO;
if (lenwanted < 0) norpt = YES, lenwanted = -lenwanted;
if (len != lenwanted)
syserr(syserr_asm_data, (long)len);
if (rpt != 1 && (val != 0 || norpt))
syserr(syserr_asm_trailer1, (long)rpt, (long)val);
}
static void asm_data(DataInit *p, int constdata)
{ FILE *as = asmstream;
int32 offset = 0;
for (; p != 0; p = p->datacdr)
{ int32 sort = p->sort;
IPtr rpt = p->rpt, len = p->len;
FloatCon *ptrval = (FloatCon *)p->val;
union { unsigned32 l;
unsigned16 w[2];
unsigned8 b[4];
/* FloatCon *f; may be bigger than unsigned32 */
} val;
val.l = p->val;
indent_18_if_annotating();
if (sort != LIT_LABEL) indent8();
switch (sort)
{ case LIT_LABEL:
pr_asmsym((Symstr *)rpt);
if (constdata) fprintf(as, " DATA");
pr_unmangled_name((Symstr *)rpt);
break;
default: syserr(syserr_asm_trailer, (long)sort);
case LIT_BBBB:
asm_checklenandrpt(len, -4, rpt, val.l);
fprintf(as, "DCB 0x%.2x,0x%.2x,0x%.2x,0x%.2x",
val.b[0], val.b[1], val.b[2], val.b[3]);
break;
case LIT_BBBX:
asm_checklenandrpt(len, -3, rpt, val.l);
fprintf(as, "DCB 0x%.2x,0x%.2x,0x%.2x", val.b[0], val.b[1], val.b[2]);
break;
case LIT_BBX:
asm_checklenandrpt(len, -2, rpt, val.l);
fprintf(as, "DCB 0x%.2x,0x%.2x", val.b[0], val.b[1]);
break;
case LIT_BXXX:
asm_checklenandrpt(len, -1, rpt, val.l);
fprintf(as, "DCB 0x%.2x", val.b[0]);
break;
case LIT_HH:
asm_checklenandrpt(len, -4, rpt, val.l);
fprintf(as, "DCW%c 0x%.4x,0x%.4x", offset & 1 ? 'U' : ' ',
val.w[0], val.w[1]);
break;
case LIT_HX:
asm_checklenandrpt(len, -2, rpt, val.l);
fprintf(as, "DCW%c 0x%.4x", offset & 1 ? 'U' : ' ', val.w[0]);
break;
case LIT_BBH:
asm_checklenandrpt(len, -4, rpt, val.l);
fprintf(as, "DCB 0x%.2x,0x%.2x", val.b[0], val.b[1]);
newline(); indent_18_if_annotating(); indent8();
fprintf(as, "DCW%c 0x%.4x", offset & 1 ? 'U' : ' ', val.w[1]);
break;
case LIT_HBX:
asm_checklenandrpt(len, -3, rpt, val.l);
fprintf(as, "DCW%c 0x%.4x", offset & 1 ? 'U' : ' ', val.w[0]);
newline(); indent_18_if_annotating(); indent8();
fprintf(as, "DCB 0x%.2x", val.b[2]);
break;
case LIT_HBB:
asm_checklenandrpt(len, -4, rpt, val.l);
fprintf(as, "DCW%c 0x%.4x", offset & 1 ? 'U' : ' ', val.w[0]);
newline(); indent_18_if_annotating(); indent8();
fprintf(as, "DCB 0x%.2x,0x%.2x", val.b[2], val.b[3]);
break;
case LIT_NUMBER:
asm_checklenandrpt(len, 4, rpt, val.l);
if (len != 4) syserr(syserr_asm_data, (long)len);
if (rpt == 1)
fprintf(as, "DCD%c 0x%.8lx", offset & 3 ? 'U' : ' ', lx_arg(val.l));
else /* val.l already checked to be zero */
fprintf(as, "%% %ld", (long)(rpt*len));
break;
case LIT_FPNUM:
{ FloatCon *f = ptrval;
char *s = f->floatstr;
if (*s != '<') {
fprintf(as, "DCF%c %s", (len == 8) ? 'D' : 'S', s);
} else if (len == 4) {
fprintf(as, "DCD 0x%.8lx", lx_arg(f->floatbin.fb.val));
} else {
fprintf(as, "DCD 0x%.8lx, 0x%.8lx",
lx_arg(f->floatbin.db.msd), lx_arg(f->floatbin.db.lsd));
}
break;
}
case LIT_ADCON: /* (possibly external) name + offset */
while (rpt--)
{
#if (sizeof_ptr == 2)
fputs("DCW ", as);
#else
fputs("DCD ", as);
#endif
pr_asmsym((Symstr *)len);
pr_unmangled_name((Symstr *)len);
if (val.l != 0) fprintf(as, "+0x%lx", lx_arg(val.l));
if (rpt) {newline(); indent_18_if_annotating(); indent8(); }
}
break;
}
offset = (offset + len) & 3;
newline();
}
}
typedef struct ExtRefList {
struct ExtRefList *cdr;
ExtRef *car;
} ExtRefList;
static void asm_pad(int32 len)
{ indent8();
indent_18_if_annotating();
fprintf(asmstream, "%% %ld\n", (long)len);
}
void asm_trailer(void)
{ FILE *as = asmstream;
#ifdef CONST_DATA_IN_CODE
if (constdata_size() != 0) {
asm_areadef("C$$constdata", "", "DATA, READONLY");
newline();
pr_asmsym(bindsym_(constdatasegment));
newline();
asm_data(constdata_head(), 0);
}
#endif
if (data_size() != 0)
{
asm_areaname(data_sym, "DATA", NO);
newline();
asm_data(data_head(), 0);
}
if (bss_size != 0)
{ int32 n = 0;
ExtRef *x = obj_symlist;
ExtRefList *zisyms = NULL;
asm_areaname(bss_sym, "NOINIT", NO);
newline();
for (; x != NULL; x = x->extcdr)
if (x->extflags & xr_bss) {
ExtRefList **prev = &zisyms;
ExtRefList *p;
for (; (p = *prev) != 0; prev = &cdr_(p))
if (x->extoffset < car_(p)->extoffset) break;
*prev = (ExtRefList *) syn_cons2(*prev, x);
}
for (; zisyms != NULL; zisyms = cdr_(zisyms))
{ x = car_(zisyms);
if (x->extoffset != n) asm_pad(x->extoffset-n);
n = x->extoffset;
indent_18_if_annotating();
pr_asmsym(x->extsym);
pr_unmangled_name(x->extsym);
newline();
}
if (n != bss_size) asm_pad(bss_size-n);
}
if (adconpool.size != 0) {
asm_areaname(adcon_sym, "BASED sb", NO);
asm_data(adconpool.head, 0);
}
{ CommonDef *p;
for (p = commondefs; p != NULL; p = p->next)
{ asm_areaname(p->name, "COMDEF", YES);
asm_data(p->data.head, 0);
}
}
{ ExtRef *x;
for (x = obj_symlist; x != NULL; x = x->extcdr)
{ int32 flags = x->extflags;
if ((flags & (xr_defloc + xr_defext)) == 0) {
/* not defined... */
Symstr *s = x->extsym;
int32 len = x->extoffset;
if (!(flags & xr_code) && (len > 0))
{ /* common data... */
asm_areaname(s, "COMMON, NOINIT", YES);
asm_pad(len);
}
}
}
}
if (!annotations)
asm_outextern();
newline();
indent8();
indent_18_if_annotating();
fputs("END\n", as);
headerdone = NO;
}
#endif
/* end of arm/asm.c */
|
stardot/ncc | mip/cse.h | <filename>mip/cse.h<gh_stars>0
/*
* cse.h: Common sub-expression elimination
* Copyright (C) Acorn Computers Ltd., 1988-1990.
* Copyright (C) Advanced RISC Machines Limited, 1991-92.
* SPDX-Licence-Identifier: Apache-2.0
*/
/*
* RCS $Revision$
* Checkin $Date$
* Revising $Author$
*/
/*
* This header describes the interface provided by CSE and LoopOpt combined
* (eventually, just CSE as LoopOpt is subsumed).
*/
#ifndef _cse_h
#define _cse_h 1
#ifndef _defs_LOADED
# include "defs.h"
#endif
#ifndef _cgdefs_LOADED
# include "cgdefs.h"
#endif
extern BindList *cse_eliminate(void);
extern void cse_init(void);
extern void cse_tidy(void);
#ifdef CG_FINDS_LOOPS
extern void note_loop(BlockList *b, BlockHead *c);
#endif
extern void cse_reinit(void);
#endif
|
Subsets and Splits