News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

NewSphinxCmm

Started by Emil_halim, May 11, 2017, 04:12:46 AM

Previous topic - Next topic

Emil_halim

Hi all,

  Just want you to know that , I released the beta version of NewSphinxCmm.

here is the site , check it out and do not miss it.
   
http://newsphinxcmm.webs.com
         
Enjoy the power of NewSphinxCmm.

Emil_halim

#1
   The NewSphinxCmm is a mixing of SphinxC-- ,HJWasm , fasm , fasmg ,SmallerC , borland c++ 6.0 and alink  in one package.

So SphinxC-- ,HJWasm , fasm   always compile to Coff object file,  borland c 6.0 always compile to OMF object file  , then linked later by alink linker.

fasmg , SmallerC  always compile to asm code that inserted into SphinxC code.

also SmallerC  compiles to masm code.

see my following Examples to got it well.

Emil_halim

Hi All,

Here is the first Example that mix SphinxC and HJWasm.

some roles you have to care of.

1- masm block of code must started with term '^^' and end with the same term.
2- masm bolck will extract from sphinxc then compile and later linked with alink.
3- this process will accomplished by MasmPlgIn , you have not use the cpu directive.
4- MasmPlgIn will specify tha path of include directory.
5- take care of function call convention , it may crash your code.


the next masm code was taken from http://www.masmforum.com/board/index.php?topic=14696.105
it determines the cpu of computer.


/*************************************
*         New Sphinx Cmm             * 
*                                    *
*           masm test                *
*                                    *
*         by Emil_halim              *         
*                                    *
*************************************/

#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization

#pragma option dbg
#pragma option lst

#Entry  main
#includelib  win32.lib MSVCRT.lib ole32.lib

// $ will replaced with SphinxC-- main path
#includepath "$\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->

// tells SphinxC about masm ShowCpu function
extern stdcall ShowCpu(dword v);

^^ //start of Masm code
.nolist
include masm32rt.inc

include m32lib/dwtoa.asm
include m32lib/stdout.asm

.code
;//  masm code taken from the next link
;//  http://www.masmforum.com/board/index.php?topic=14696.105
ShowCpu proc stdcall ; mode:DWORD
COMMENT @ Usage:
  push 0, call ShowCpu ; simple, no printing, just returns SSE level
  push 1, call ShowCpu ; prints the brand string and returns SSE level @
 
  pushad
  sub esp, 80     ; create a buffer for the brand string
  mov edi, esp ; point edi to it
  xor ebp, ebp
  .Repeat
  lea eax, [ebp+80000002h]
db 0Fh, 0A2h ; cpuid 80000002h-80000004h
stosd
mov eax, ebx
stosd
mov eax, ecx
stosd
mov eax, edx
stosd
inc ebp
  .Until ebp>=3
  push 1
  pop eax
  db 0Fh, 0A2h ; cpuid 1
  xor ebx, ebx ; CpuSSE
  xor esi, esi ; add zero plus the carry flag
  bt edx, 25 ; edx bit 25, SSE1
  adc ebx, esi
  bt edx, 26 ; edx bit 26, SSE2
  adc ebx, esi
  bt ecx, esi ; ecx bit 0, SSE3
  adc ebx, esi
  bt ecx, 9 ; ecx bit 9, SSE4
  adc ebx, esi
  dec dword ptr [esp+4+32+80] ; dec mode in stack
  .if Zero?
mov edi, esp ; restore pointer to brand string
  .Repeat
.Break .if byte ptr [edi]!=32 ; mode was 1, so show a string but skip leading blanks
inc edi
.Until 0
.if byte ptr [edi]<32
print chr$("pre-P4")
.else
print edi ; CpuBrand
.endif
.if ebx
print chr$(32, 40, "SSE") ; info on SSE level, 40=(
print str$(ebx), 41, 13, 10 ; 41=)
.endif
  .endif
  add esp, 80 ; discard brand buffer (after printing!)
  mov [esp+32-4], ebx ; move ebx into eax stack position - returns eax to main for further use
  popad
  ret 4
ShowCpu endp

^^ //End of Masm code


;//***********************************************************************************//


main()
{
   ShowCpu(1); // print brand string and SSE level
     
   system("pause");   
 
}

Vortex

Hi Emil,

The compiler does not work on Windows XP SP3 :

Quotec--.exe is not a valid win32 application

Tested on XP 32-bit and 64-bit, the result is the same.

The old version 0.239 from narod.ru works fine on XP :

http://c--sphinx.narod.ru/indexe.htm

QuoteNewSphinxCmm is the opensource code of C-- . ported to MSVC2012

VC++ 2012 does not support WinXP.  Any chance to rebuild the project with VC2010 Express?

Emil_halim

Hi Vortex,

I am afraid , i have no machine with MSVC2010.

i have an idea , does MSVC2010 linker can link obj file that done by MSVC2012.

also my problem is how to import MSVC2012 project to codeblocks , so i can rebuild it with any another compiler?

TWell

https://blogs.msdn.microsoft.com/vcblog/2012/06/15/targeting-windows-xp-with-c-in-visual-studio-2012/

linker option -subsystem:console:5,1

If someone try to run bare c--.exe, it crash in WindowsXP and Windows 8.1

Emil_halim

#6
Hi TWell,

thanks for the link.

i have changed the 'platform Toolset' option in msvc2012 to be 'Visual Studio 2012 - Windows XP (v110_xp)' then rebuild the entire solution.


please download the  newSphinxCmmXP.7z then copy it's contains to the old one.

hope that will work.

Edited:

i erased newSphinxCmmXP and correct the original one for the sake of confusing.
so reload it again , please let me know if it worked well.

Vortex

Hi Emil,

I downloaded the new release and it works on Windows XP, thanks.

I am trying to compile a simple GUI example, the output is intended to be a MS COFF object module. Here is the output :


SPHINX C-- Compiler   Version 0.239c b26   May 12 2017

Extended By Emil Halim Version 1.0

Registered new Token =  13
loaded 'Bcc60PlgIn.dll' PlugIn
Registered new Token =  13
Registered new Token =  fasm
loaded 'FasmPlgIn.dll' PlugIn
Registered new Token =  56
loaded 'LinkerPlgIn.dll' PlugIn
Registered new Token =  53
Registered new Token =  3
Registered new Token =  4
Registered new Token =  86
Registered new Token =  156
Registered new Token =  align
loaded 'MacroPlgIn.dll' PlugIn
Registered new Token =  27
loaded 'MasmPlgIn.dll' PlugIn
Seems that 'porc.dll' is not a PlugIn
loaded 'smalcMasmPlgIn.dll' PlugIn
Registered new Token =  smlc
loaded 'smalcPlgIn.dll' PlugIn
Seems that 'tds2dbg.dll' is not a PlugIn
Num of PlugIn found = 7
Compiling Commenced . . .
Link . . .
COMPILING FINISHED.  Errors: 0
CPU required: 80386 or greater.
Code: 406 bytes, Data: 56 bytes, Post: 12 bytes, Stack: 4096 bytes
Run File Saved (1246 bytes).

linking..........
Loading file Menu.res
Loading Win32 Resource File
Loading file C:\newSphinxCmm\demo\Menu$6.obj
matched Externs
matched ComDefs
Unresolved external GetModuleHandleA
Unresolved external LoadIconA
Unresolved external LoadCursorA
Unresolved external RegisterClassExA
Unresolved external CreateWindowExA
Unresolved external ShowWindow
Unresolved external UpdateWindow
Unresolved external TranslateMessage
Unresolved external DispatchMessageA
Unresolved external GetMessageA
Unresolved external ExitProcess
Unresolved external PostQuitMessage
Unresolved external DefWindowProcA
Unresolved external MessageBoxA
Unresolved external DestroyWindow


The compiler should not try to link the object module and why the plugins are loaded automatically?

I get some copies of the source file after the compilation :

C:\newSphinxCmm\demo>dir /b
Build.bat
Menu$0.c--
Menu$1.c--
Menu$2.c--
Menu$3.c--
Menu$4.c--
Menu$6.c--
Menu$6.obj
Menu.c--
Menu.RC
Menu.res
warning.txt


The compiler crashes while I try to retrieve the command line options :


C:\newSphinxCmm\demo>\newSphinxCmm\c--.exe /?

SPHINX C-- Compiler   Version 0.239c b26   May 12 2017

Extended By Emil Halim Version 1.0

Registered new Token =  13
loaded 'Bcc60PlgIn.dll' PlugIn
Registered new Token =  13
Registered new Token =  fasm
loaded 'FasmPlgIn.dll' PlugIn
Registered new Token =  56
loaded 'LinkerPlgIn.dll' PlugIn
Registered new Token =  53
Registered new Token =  3
Registered new Token =  4
Registered new Token =  86
Registered new Token =  156
Registered new Token =  align
loaded 'MacroPlgIn.dll' PlugIn
Registered new Token =  27
loaded 'MasmPlgIn.dll' PlugIn
Seems that 'porc.dll' is not a PlugIn
loaded 'smalcMasmPlgIn.dll' PlugIn
Registered new Token =  smlc
loaded 'smalcPlgIn.dll' PlugIn
Seems that 'tds2dbg.dll' is not a PlugIn
Num of PlugIn found = 7


I can compile the same source code with the old compiler from narod.ru  After, the object module is linked with GoLink.

Emil_halim

Hi Vortex,

first i will explain the deferent between old c-- and the modified c--.

1- NewSphinxC always produces obj file so there is no need to  #pragma option coff   //coff format.
2- because of using alink as a default linker , there is new directive '#includelib' that tells alink which libs and objs will be linked, there is no need to put the obj name of source code.

// this links win32 library & msvcrt library
#includelib  win32.lib MSVCRT.lib

3- when using '#includepath' you just use '$' term then the path so NewSphinxC will insert the correct path automatically for you.

// $ will replaced with SphinxC-- main path
#includepath "$\winlib" 

4-there is no need to include windows header as you did , just include windows.h

// those feet my needs
#include <windows.h> 
#include <MSVCRT.H-->

5- there is no need to use '#pragma option J0' directive so NewSpinxC allows to determine the entry point with '#Entry' directive. the default is main function

// tells linker to start from main function.
#Entry  main


here is you code compiled & worked okay

#pragma option w32     //create Windows GUI EXE.
#pragma option w       //enable warning.
#pragma option 3       //386 CPU.

#includelib  win32.lib MSVCRT.lib ole32.lib

#includepath "$\winlib"
#include <windows.h> 

#include "Menu.rc"     //resource file.

dword hInst;
dword hWnd;
dword hMenu;
char classTitle="Menu demo";
char szMenuName="WinMenu";

void main()
{
    struct MSG msgStruc;
    struct WNDCLASSEX WndClassEx;
    hInst=GetModuleHandle(0);
    WndClassEx.cbSize=sizeof(WndClassEx);
    WndClassEx.style=CS_HREDRAW|CS_VREDRAW;
    WndClassEx.lpfnWndProc=#WndProc;
    WndClassEx.cbWndExtra=0;
    WndClassEx.cbClsExtra=0;
    WndClassEx.hInstance=hInst;
    WndClassEx.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    WndClassEx.hCursor=LoadCursor(0,IDC_ARROW);
    WndClassEx.hbrBackground=COLOR_WINDOW+1;
    WndClassEx.lpszMenuName=#szMenuName;
    WndClassEx.lpszClassName=#classTitle;
    WndClassEx.hIconSm=0;
    RegisterClassEx(#WndClassEx);
    hWnd=CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,#classTitle,"Demo program",
            WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
            CW_USEDEFAULT,0,0,hInst,0);
           
    ShowWindow(EAX,SW_SHOW); //show window
    UpdateWindow(hWnd); //redraw window
   
    WHILE(GetMessage(#msgStruc,0,0,0)){
    TranslateMessage(#msgStruc);
    DispatchMessage(#msgStruc);
    }
   
    ExitProcess(0);
}

dword  WndProc(dword hwnd,msg,wParam,lParam)
{
    SWITCH(msg){
       
        CASE WM_DESTROY:
       
            PostQuitMessage(0);
            EAX=0;
            BREAK;
           
            CASE WM_COMMAND:
           
                IF(lParam==0) {
               
                    switch(wParam)
                                {
                                    case IDM_ABOUT:
                                   
                                        MessageBox(hwnd,"Sphinx C-- Sample","Hello!",MB_OK);
                                        break;
                                       
                                    case IDM_EXIT:
                                   
                                        DestroyWindow(hwnd);
                                        break;
                                }
                            }
            break;
           
            default:
           
                DefWindowProc(hwnd,msg,wParam,lParam);
                }

}



Edited:
Quote
why the plugins are loaded automatically?
I get some copies of the source file after the compilation

the PlugIn System of NewSpinxC works like that , each PlugIn will delver the source code and make it's processing then pass back.
so Macro Plugin will get the original source code the process it and save it as ....$0.c-- , the second PlugIn will get ....$0.c-- then process it then save as ....$1.c--    and so on.
finaly c-- will get ...$n-1.c-- and compile it as original filename.exe

it is useful when debug the output of a certain plugin.

Vortex

Hi Emil,

Thanks for the reviewed code but yet the compiler is crashing after creating the executable. Any option to disable the plugins? I wish to use other linkers with C--  As I mentioned in my previous message the compiler crashes if I want to display the command line options with c--.exe /? Also, how to get the latest documentation of your C-- release?

Emil_halim

Hi Vortex,

Quote
Any option to disable the plugins?

No , but i will try to do that

Quote
I wish to use other linkers with

you still can use an other linker just feed the necessary libraries and original filename objet ,also any objs file produced while compiling your code.

Quote
the compiler crashes if I want to display the command line options with c--.exe

because there is no command line options , just put the source filename

Quote
how to get the latest documentation of your C-- release?

there is no documentation , sorry , later i will write it.

Emil_halim

Hi

there is a new directive  '#OnExit'  that allow you use an other linker just like golink.

here is one that i was using with alink.

#OnExit "$PATH$ALINK -oPE $FILE$.obj -L $PATH$ win32.lib MSVCRT.lib  -subsys con -entry main -o $OFILE$.exe"


the term '$PATH$' will replace with actual plugin folder path , so put you linker there.
the term '$FILE$' will replace with latest processed file name without extension
the term '$OFILE$' will replace with original file name without extension

edited

here is the ilink , borland linker

#OnExit "$PATH$\ilink32 /ap  -Gn  $FILE$.obj cns.OBJ , , , import32.lib cw32.lib , ,   "

Emil_halim

Hi Vortex,

I have modified NewSphinxC , so you can now disable the plugins except the Macro & linker which are part of C--.


c-- /NOPLGIN  yoursource.c--


the commend line will compile yoursource,c-- without plugin processing, do not use it with #pragma option in your code ,only from a command line.

also the directive '#pragma option obj'  tells NewSphinxC to only compile the source without linking.

also c-- now has a commnd line.

just redownload the new version c-- '250 c b26'

hope that help you.

Vortex

The compiler creates an executable instead of an object module :

C:\newSphinxCmm\demo>..\c--.exe /NOPLGIN Menu.c--

SPHINX C-- Compiler   Version 0.250c b26   May 13 2017

Extended By Emil Halim Version 1.0

Registered new Token =  56
loaded 'LinkerPlgIn.dll' PlugIn
Registered new Token =  53
Registered new Token =  3
Registered new Token =  4
Registered new Token =  86
Registered new Token =  156
Registered new Token =  align
loaded 'MacroPlgIn.dll' PlugIn
Num of PlugIn found = 2
Compiling Commenced . . .
Link . . .
COMPILING FINISHED.  Errors: 0
CPU required: 80386 or greater.
Code: 419 bytes, Data: 56 bytes, Post: 12 bytes, Stack: 4096 bytes
Run File Saved (1309 bytes).

linking..........
Loading file Menu.res
Loading Win32 Resource File
Loading file C:\newSphinxCmm\demo\Menu$1.obj
Loading file C:\newSphinxCmm\plugins\\Libs\win32.lib
Loading file C:\newSphinxCmm\plugins\\Libs\MSVCRT.lib
Loading file C:\newSphinxCmm\plugins\\Libs\ole32.lib
matched Externs
matched ComDefs
Generating PE file Menu.exe
Unable to open Menu.tds for reading
                     Ultimate Packer for eXecutables
            Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
UPX 1.20w        Markus F.X.J. Oberhumer & Laszlo Molnar        May 23rd 2001

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
      3736 ->      2560   68.52%    win32/pe     Menu.exe

Packed 1 file.
End of plugin



Menu.c-- :
#pragma option w32     //create Windows GUI EXE.
#pragma option w       //enable warning.
#pragma option 3       //386 CPU.
#pragma option obj

#includelib  win32.lib MSVCRT.lib ole32.lib

#includepath "$\winlib"
#include <windows.h>

#include "Menu.rc"     //resource file.

dword hInst;
dword hWnd;
dword hMenu;
char classTitle="Menu demo";
char szMenuName="WinMenu";

void main()
{
    struct MSG msgStruc;
    struct WNDCLASSEX WndClassEx;
.
.


Running the command line below, the compiler crashes :

..\c--.exe /obj Menu.c--

Emil_halim

thanks for feed back.

I have corrected it and tested it , works fine.

the new version is '251 c b26'

also i have tested with the next commend line , also works oaky.

Quote
..\..\newSphinxCmm\c--.exe /NOPLGIN /obj Menu.c--

here is the output of compiling

..\..\newSphinxCmm\c--.exe /NOPLGIN /obj Menu.c--

SPHINX C-- Compiler   Version 0.251c b26   May 14 2017

Extended By Emil Halim Version 1.0

Registered new Token =  56
loaded 'LinkerPlgIn.dll' PlugIn
Registered new Token =  53
Registered new Token =  3
Registered new Token =  4
Registered new Token =  86
Registered new Token =  156
Registered new Token =  align
loaded 'MacroPlgIn.dll' PlugIn
Num of PlugIn found = 2
Compiling Commenced . . .
Link . . .
COMPILING FINISHED.  Errors: 0
CPU required: 80386 or greater.
Code: 419 bytes, Data: 56 bytes, Post: 12 bytes, Stack: 4096 bytes
Run File Saved (1309 bytes).
End of plugin