Bascom Precompiler: Unterschied zwischen den Versionen

Aus ProjectWiki
Wechseln zu:Navigation, Suche
(Die Seite wurde neu angelegt: „== Overview == The precompiler processes the Bascom source files (also taking includes into account), outputs the generated source files besides the original f…“)
 
K
Zeile 1: Zeile 1:
 +
== Index ==
 +
* [[TLSF Dynamic Memory Allocation|''[OOP 1a/3] Dynamic Memory Allocation using TLSF'']]
 +
* [[Static Memory Allocation|''[OOP 1b/3] Static Memory Allocation'']]
 +
* [[Object Oriented Programming in Bascom|''[OOP 2/3] Object Oriented Programming in Bascom'']]
 +
* [OOP 3/3] Bascom-Precompiler
 +
 +
 
== Overview ==
 
== Overview ==
 
The precompiler processes the Bascom source files (also taking includes into account), outputs the generated source files besides the original files and invokes ''bascomp.exe''. Original files are not touched.
 
The precompiler processes the Bascom source files (also taking includes into account), outputs the generated source files besides the original files and invokes ''bascomp.exe''. Original files are not touched.

Version vom 14. Juli 2019, 04:06 Uhr

Index


Overview

The precompiler processes the Bascom source files (also taking includes into account), outputs the generated source files besides the original files and invokes bascomp.exe. Original files are not touched. It supports the following enhancements:

  • Macros with arguments
  • RAM and ROM address data type
  • Enumerations
  • Conditional Compilation Checks: #if Subexist(""), #if Labelexist("")
  • Composed data types (structures) and OOP concepts
  • Automatic generated constants: _sourceline, _sourcefileline, _filename, _subroutinename, _precompiler, _currentdate, _currenttime, _buildnumber, _freeramstart, _isrstackcount
  • Export disassembly (optionally annotated with original source code)

Some precompiler steps involve parsing the compiler output, in that case, a second compile step is then performed using the gathered data.


Functional description

Macros with arguments

Syntax:

Macro [MacroName] ([ArgumentList])
    [Statements]
End Macro

These macros work the same as the built-in ones, but accept additional arguments, which work as a textual replacement. Therefore arguments are type-agnostic. Also supports argument concatenation using "." (argument concatenation has priority over the type-member-/enum-access qualifier "."). Nested macros are allowed.


Example 1:

Macro Mymacro(printtext)
   Print "This is my text: "; printtext
End Macro

Invoking with a string argument:

Mymacro "some characters"

Will yield in output:

Print "This is my text: "; "some characters"

Invoking with a variable as argument:

Dim Myvariable As Byte
Mymacro Myvariable

Output:

Print "This is my text: "; Myvariable


Example2:

Macro Concat (Arg1, Arg2, Arg3)
   Arg1.Arg2 Arg3
End Macro

Invoking:

Concat($reg, file, "m32def.dat")

Output:

$regfile "m32def.dat"


RAM/ROM address data type

Some devices have more than 64K program space and use 24 bit wide addresses (instead of 16 bit) for flash access, which makes porting code between the addressing schemes more tedious. The same happens with RAM addresses for devices using external memory. To support this, the precompiler introduces two new variable types: Rampointer and Rompointer. They will be assigned a Word or a Dword variable type on compilation, according to the currently used addressing schemes.

Syntax:

Dim Labeladdress As Rompointer
Dim Myramspace As Rampointer

Sub Testthis(position As Rampointer)
   Local Flashdata As Rompointer
End Sub


Enumerations

Defines a list of key-value pairs. If no value is specified, the value is either 0 for the first key entry or the value of the previous key + 1. One key/value pair per line. Usage is like constants, members are accessed using [EnumName].[MemberName].

Syntax:

Enum Myenum
   Value1,
   Value2 = 5,
   Value3
End Enum

Print Myenum.Value1; Myenum.Value2; Myenum.Value3          ' Output: 056


Conditional Compilation Checks

The precompiler adds additional symbol-checks to Bascom's conditional compilation switches (they act in the same way the as built-in Varexist("") directive).

Syntax:

#if Subexist("[SubroutineName]")
#if Labelexist("[LabelName]")


Composed Data Types

A composed data type consists of several data types (intrinsic or other composed types) grouped together in memory. It supports every available data type (bit, byte, word, integer, dword, long, single, double, string, rampointer, rompointer and composed types) and optionally supports inheritance. Composed types as member field or dimensioned using Dim, Local or as a subroutine parameter are internally referenced by the Rampointer data type.

To create an instance of the type definition, a memory block of sufficient size has to be reserved and referenced through a variable pointing to the first memory address of that block. Memberfields are accessed by the "." qualifier. Only assignments of a variable from the memberfield or assignments of the memberfield from a variable or constant are allowed (by now). Internally, these are translated to Settype/Gettype functions as found in os_memory.inc. Bit member fields internally use a byte.

Syntax:

Typedef [TypedefName]
   [Extends TypedefName]
   [MemberFieldName] As [Bit/Byte/Word/Integer/Dword/Long/Single/Double/String*N/TypedefName]
End Typedef

Sub Memberfunction(object As [TypedefName])
   Local Anotherobject As [TypedefName]
End Sub

Dim Myinstance As [TypedefName]

Myinstance = Malloc(SizeOf([TypedefName]))

Myinstance.[MemberfieldName] = [Constant/Variable]
Variable = Myinstance.[MemberfieldName]


Automatic generated constants

These keywords are replaced by their value as number or string literal, usage is like constants.


_sourceline

(Number) Returns the current line number, inclusive includes.


_sourcefileline

(Number) Returns the current line number only counting the current file


_filename

(String) Returns the current source file name


_subroutinename

(String) Returns the current sub routine name (valid inside Subs/Functions and Label-Return-pairs, empty string if not inside subroutine).


_precompiler

(Number) Actually creates a constant containing the precompiler version (current: 1), which could be checked for existence by #if Varexist("_precompiler") to check if the code is beeing processed using the precompiler.


_currenttime

(String) Contains the build time.


_currentdate

(String) Contains the build date.


_freeramstart

(Number) Returns the first unused memory position. Needs a second compile pass.


_isrstackcount

(Number) Returns the used stack size (PUSH statements) inside an ISR. Needs a second compile pass.


Const _buildnumber = 0

This constant is treated specially, in the output it will contain the current build number, incremented by 1 on each compilation. Current build count is maintained in a file besides the original source file with the extension ".bld".


Precompiler directives

$disasm

Instructs the precompiler to output a disassembly of the compilation result. Needs a second compile pass.


$disasmmapped

Instructs the precompiler to output a disassembly of the compilation result, mapped to the corresponding source lines. Needs a second compile pass.


Command Line

Syntax:

prebascomp.exe [FileName] [Options]


Options:

/disasm

Instructs the precompiler to output a disassembly of the compilation result. Needs a second compile pass.


/mapped

Instructs the precompiler to output a disassembly of the compilation result, mapped to the corresponding source lines. Needs a second compile pass.


/log

Generate a log file of the precompilation process.


Download

Bascom OOP & Precompiler Download