xref: /AOO41X/main/basic/source/inc/codegen.hxx (revision 234bd5c559aaf7abbd02d045859137b774cd8b34)
1*234bd5c5SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*234bd5c5SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*234bd5c5SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*234bd5c5SAndrew Rist  * distributed with this work for additional information
6*234bd5c5SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*234bd5c5SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*234bd5c5SAndrew Rist  * "License"); you may not use this file except in compliance
9*234bd5c5SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*234bd5c5SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*234bd5c5SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*234bd5c5SAndrew Rist  * software distributed under the License is distributed on an
15*234bd5c5SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*234bd5c5SAndrew Rist  * KIND, either express or implied.  See the License for the
17*234bd5c5SAndrew Rist  * specific language governing permissions and limitations
18*234bd5c5SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*234bd5c5SAndrew Rist  *************************************************************/
21*234bd5c5SAndrew Rist 
22*234bd5c5SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _CODEGEN_HXX
25cdf0e10cSrcweir #define _CODEGEN_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir class SbiImage;
28cdf0e10cSrcweir class SbiParser;
29cdf0e10cSrcweir class SbModule;
30cdf0e10cSrcweir #include "opcodes.hxx"
31cdf0e10cSrcweir #include "buffer.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir class SbiCodeGen { 				// Code-Erzeugung:
34cdf0e10cSrcweir 	SbiParser* pParser;			// fuer Fehlermeldungen, Line, Column etc.
35cdf0e10cSrcweir 	SbModule& rMod;				// aktuelles Modul
36cdf0e10cSrcweir 	SbiBuffer aCode;	  			// Code-Puffer
37cdf0e10cSrcweir 	short  nLine, nCol;			// Zeile, Spalte fuer Stmnt-Befehl
38cdf0e10cSrcweir 	short  nForLevel;			// #29955 for-Schleifen-Ebene
39cdf0e10cSrcweir 	sal_Bool bStmnt;				// sal_True: Statement-Opcode liegt an
40cdf0e10cSrcweir public:
41cdf0e10cSrcweir 	SbiCodeGen( SbModule&, SbiParser*, short );
GetParser()42cdf0e10cSrcweir 	SbiParser* GetParser() { return pParser; }
GetModule()43cdf0e10cSrcweir 	SbModule& GetModule() { return rMod; }
44cdf0e10cSrcweir 	sal_uInt32 Gen( SbiOpcode );
45cdf0e10cSrcweir 	sal_uInt32 Gen( SbiOpcode, sal_uInt32 );
46cdf0e10cSrcweir 	sal_uInt32 Gen( SbiOpcode, sal_uInt32, sal_uInt32 );
Patch(sal_uInt32 o,sal_uInt32 v)47cdf0e10cSrcweir 	void Patch( sal_uInt32 o, sal_uInt32 v ){ aCode.Patch( o, v ); }
BackChain(sal_uInt32 off)48cdf0e10cSrcweir 	void BackChain( sal_uInt32 off )	{ aCode.Chain( off );  }
49cdf0e10cSrcweir 	void Statement();
50cdf0e10cSrcweir 	void GenStmnt();			// evtl. Statement-Opcode erzeugen
51cdf0e10cSrcweir 	sal_uInt32 GetPC();
GetOffset()52cdf0e10cSrcweir 	sal_uInt32 GetOffset()				{ return GetPC() + 1; }
53cdf0e10cSrcweir 	void Save();
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 	// #29955 for-Schleifen-Ebene pflegen
IncForLevel(void)56cdf0e10cSrcweir 	void IncForLevel( void ) { nForLevel++; }
DecForLevel(void)57cdf0e10cSrcweir 	void DecForLevel( void ) { nForLevel--; }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	static sal_uInt32 calcNewOffSet( sal_uInt8* pCode, sal_uInt16 nOffset );
60cdf0e10cSrcweir 	static sal_uInt16 calcLegacyOffSet( sal_uInt8* pCode, sal_uInt32 nOffset );
61cdf0e10cSrcweir 
62cdf0e10cSrcweir };
63cdf0e10cSrcweir 
64cdf0e10cSrcweir template < class T, class S >
65cdf0e10cSrcweir class PCodeBuffConvertor
66cdf0e10cSrcweir {
67cdf0e10cSrcweir 	T m_nSize; //
68cdf0e10cSrcweir 	sal_uInt8* m_pStart;
69cdf0e10cSrcweir 	sal_uInt8* m_pCnvtdBuf;
70cdf0e10cSrcweir 	S m_nCnvtdSize; //
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	//  Disable usual copying symantics and bodgy default ctor
73cdf0e10cSrcweir 	PCodeBuffConvertor();
74cdf0e10cSrcweir 	PCodeBuffConvertor(const PCodeBuffConvertor& );
75cdf0e10cSrcweir 	PCodeBuffConvertor& operator = ( const PCodeBuffConvertor& );
76cdf0e10cSrcweir public:
PCodeBuffConvertor(sal_uInt8 * pCode,T nSize)77cdf0e10cSrcweir 	PCodeBuffConvertor( sal_uInt8* pCode, T nSize ): m_nSize( nSize ),  m_pStart( pCode ), m_pCnvtdBuf( NULL ), m_nCnvtdSize( 0 ){ convert(); }
GetSize()78cdf0e10cSrcweir 	S GetSize(){ return m_nCnvtdSize; }
79cdf0e10cSrcweir 	void convert();
80cdf0e10cSrcweir 	// Caller owns the buffer returned
GetBuffer()81cdf0e10cSrcweir 	sal_uInt8* GetBuffer() { return m_pCnvtdBuf; }
82cdf0e10cSrcweir };
83cdf0e10cSrcweir 
84cdf0e10cSrcweir // #111897 PARAM_INFO flags start at 0x00010000 to not
85cdf0e10cSrcweir // conflict with DefaultId in SbxParamInfo::nUserData
86cdf0e10cSrcweir #define PARAM_INFO_PARAMARRAY		0x0010000
87cdf0e10cSrcweir #define PARAM_INFO_WITHBRACKETS		0x0020000
88cdf0e10cSrcweir 
89cdf0e10cSrcweir #endif
90